From 9a3695d5a899c2cfd5745f8f18f0cf7de862d84a Mon Sep 17 00:00:00 2001 From: Klaus Weidner Date: Tue, 20 Nov 2018 23:01:59 -0800 Subject: [PATCH] Bump version, add version display to settings menu --- app/build.gradle | 4 +-- .../pckeyboard/LatinIMESettings.java | 31 +++++++++++++++++++ .../pckeyboard/PrefScreenView.java | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 200aa7d83..10f1f9c7f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId 'org.pocketworkstation.pckeyboard' minSdkVersion 14 targetSdkVersion 26 - versionCode 1040001 - versionName "v1.40.1" + versionCode 1040002 + versionName "v1.40.2" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { diff --git a/app/src/main/java/org/pocketworkstation/pckeyboard/LatinIMESettings.java b/app/src/main/java/org/pocketworkstation/pckeyboard/LatinIMESettings.java index bb5d33562..c5a40020e 100644 --- a/app/src/main/java/org/pocketworkstation/pckeyboard/LatinIMESettings.java +++ b/app/src/main/java/org/pocketworkstation/pckeyboard/LatinIMESettings.java @@ -23,6 +23,9 @@ import android.app.backup.BackupManager; import android.content.DialogInterface; import android.content.SharedPreferences; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.content.pm.Signature; import android.content.res.Resources; import android.os.Bundle; import android.preference.CheckBoxPreference; @@ -55,6 +58,8 @@ public class LatinIMESettings extends PreferenceActivity private ListPreference mKeyboardModePortraitPreference; private ListPreference mKeyboardModeLandscapePreference; private Preference mInputConnectionInfo; + private Preference mLabelVersion; + private boolean mVoiceOn; private boolean mOkClicked = false; @@ -68,6 +73,8 @@ protected void onCreate(Bundle icicle) { mVoicePreference = (ListPreference) findPreference(VOICE_SETTINGS_KEY); mSettingsKeyPreference = (ListPreference) findPreference(PREF_SETTINGS_KEY); mInputConnectionInfo = (Preference) findPreference(INPUT_CONNECTION_INFO); + mLabelVersion = (Preference) findPreference("label_version"); + // TODO(klausw): remove these when no longer needed mKeyboardModePortraitPreference = (ListPreference) findPreference("pref_keyboard_mode_portrait"); @@ -105,6 +112,30 @@ protected void onResume() { } updateSummaries(); + + String version = ""; + try { + PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES); + version = info.versionName; + boolean isOfficial = false; + for (Signature sig : info.signatures) { + byte[] b = sig.toByteArray(); + int out = 0; + for (int i = 0; i < b.length; ++i) { + int pos = i % 4; + out ^= b[i] << (pos * 4); + } + if (out == -466825) { + isOfficial = true; + } + //version += " [" + Integer.toHexString(out) + "]"; + } + version += isOfficial ? " official" : " custom"; + } catch (PackageManager.NameNotFoundException e) { + Log.e(TAG, "Could not find version info."); + } + + mLabelVersion.setSummary(version); } @Override diff --git a/app/src/main/java/org/pocketworkstation/pckeyboard/PrefScreenView.java b/app/src/main/java/org/pocketworkstation/pckeyboard/PrefScreenView.java index 580ecd8a7..c52ad03e5 100644 --- a/app/src/main/java/org/pocketworkstation/pckeyboard/PrefScreenView.java +++ b/app/src/main/java/org/pocketworkstation/pckeyboard/PrefScreenView.java @@ -20,6 +20,7 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.preference.ListPreference; +import android.preference.Preference; import android.preference.PreferenceActivity; public class PrefScreenView extends PreferenceActivity @@ -54,6 +55,5 @@ protected void onResume() { mRenderModePreference.setEnabled(false); mRenderModePreference.setSummary(R.string.render_mode_unavailable); } - } }