From d4fd18cd09dfd94efb11c403ec75894b01923d55 Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Thu, 19 Aug 2021 11:11:27 +0700 Subject: [PATCH] feat(android/app): Add menu to adjust keyboard height --- .../kMAPro/src/main/AndroidManifest.xml | 5 + .../kmapro/AdjustKeyboardHeightActivity.java | 147 ++++++++++++++++++ .../kmapro/KeymanSettingsFragment.java | 11 +- .../com/tavultesoft/kmapro/MainActivity.java | 3 +- .../src/main/res/drawable-hdpi/ic_height.png | Bin 0 -> 159 bytes .../main/res/drawable-hdpi/ic_keyboard.png | Bin 0 -> 201 bytes .../src/main/res/drawable-mdpi/ic_height.png | Bin 0 -> 159 bytes .../main/res/drawable-mdpi/ic_keyboard.png | Bin 0 -> 201 bytes .../src/main/res/drawable-xhdpi/ic_height.png | Bin 0 -> 164 bytes .../main/res/drawable-xhdpi/ic_keyboard.png | Bin 0 -> 189 bytes .../main/res/drawable-xxhdpi/ic_height.png | Bin 0 -> 336 bytes .../main/res/drawable-xxhdpi/ic_keyboard.png | Bin 0 -> 392 bytes .../main/res/drawable-xxxhdpi/ic_height.png | Bin 0 -> 396 bytes .../main/res/drawable-xxxhdpi/ic_keyboard.png | Bin 0 -> 494 bytes .../src/main/res/drawable/dash_border.xml | 11 ++ .../activity_adjust_keyboard_height.xml | 59 +++++++ .../layout/preference_height_icon_layout.xml | 14 ++ .../kMAPro/src/main/res/values/strings.xml | 12 ++ .../java/com/tavultesoft/kmea/KMManager.java | 26 +++- 19 files changed, 285 insertions(+), 3 deletions(-) create mode 100644 android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java create mode 100644 android/KMAPro/kMAPro/src/main/res/drawable-hdpi/ic_height.png create mode 100644 android/KMAPro/kMAPro/src/main/res/drawable-hdpi/ic_keyboard.png create mode 100644 android/KMAPro/kMAPro/src/main/res/drawable-mdpi/ic_height.png create mode 100644 android/KMAPro/kMAPro/src/main/res/drawable-mdpi/ic_keyboard.png create mode 100644 android/KMAPro/kMAPro/src/main/res/drawable-xhdpi/ic_height.png create mode 100644 android/KMAPro/kMAPro/src/main/res/drawable-xhdpi/ic_keyboard.png create mode 100644 android/KMAPro/kMAPro/src/main/res/drawable-xxhdpi/ic_height.png create mode 100644 android/KMAPro/kMAPro/src/main/res/drawable-xxhdpi/ic_keyboard.png create mode 100644 android/KMAPro/kMAPro/src/main/res/drawable-xxxhdpi/ic_height.png create mode 100644 android/KMAPro/kMAPro/src/main/res/drawable-xxxhdpi/ic_keyboard.png create mode 100644 android/KMAPro/kMAPro/src/main/res/drawable/dash_border.xml create mode 100644 android/KMAPro/kMAPro/src/main/res/layout/activity_adjust_keyboard_height.xml create mode 100644 android/KMAPro/kMAPro/src/main/res/layout/preference_height_icon_layout.xml diff --git a/android/KMAPro/kMAPro/src/main/AndroidManifest.xml b/android/KMAPro/kMAPro/src/main/AndroidManifest.xml index bf328d040d..d06bfc8422 100644 --- a/android/KMAPro/kMAPro/src/main/AndroidManifest.xml +++ b/android/KMAPro/kMAPro/src/main/AndroidManifest.xml @@ -294,6 +294,11 @@ android:parentActivityName=".SelectPackageActivity" android:launchMode="singleTask" android:theme="@style/AppTheme.Base" /> + diff --git a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java new file mode 100644 index 0000000000..972165efdb --- /dev/null +++ b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/AdjustKeyboardHeightActivity.java @@ -0,0 +1,147 @@ +/** + * Copyright (C) SIL International. All rights reserved. + */ +package com.tavultesoft.kmapro; + +import android.content.Context; +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.graphics.drawable.ColorDrawable; +import android.os.Bundle; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.widget.Toolbar; +import androidx.core.content.ContextCompat; + +import com.tavultesoft.kmea.BaseActivity; +import com.tavultesoft.kmea.KMManager; + +/** + * Settings menu for adjusting the keyboard height. The value for the current device orientation + * is saved in shared preferences. + */ +public class AdjustKeyboardHeightActivity extends BaseActivity { + private static final String TAG = "AdjustKbdHeight"; + public static final String adjustKeyboardHeightKey = "AdjustKeyboardHeight"; + + private static Button resetButton = null; + private static ImageView sampleKeyboard = null; + + // Keeps track of the adjusted keyboard height for saving + private static SharedPreferences.Editor editor = null; + private static int currentHeight = 0; + private static ViewGroup.LayoutParams layoutParams; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + final Context context = this; + + setContentView(R.layout.activity_adjust_keyboard_height); + + Toolbar toolbar = (Toolbar) findViewById(R.id.titlebar); + setSupportActionBar(toolbar); + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setTitle(null); + actionBar.setDisplayUseLogoEnabled(false); + actionBar.setDisplayShowHomeEnabled(false); + actionBar.setDisplayShowTitleEnabled(false); + actionBar.setDisplayShowCustomEnabled(true); + actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.keyman_blue))); + } + + TextView adjustKeyboardHeightActivityTitle = (TextView) findViewById(R.id.bar_title); + adjustKeyboardHeightActivityTitle.setWidth((int) getResources().getDimension(R.dimen.package_label_width)); + + String titleStr = getString(R.string.adjust_keyboard_height); + adjustKeyboardHeightActivityTitle.setTextColor(ContextCompat.getColor(this, R.color.ms_white)); + adjustKeyboardHeightActivityTitle.setText(titleStr); + + SharedPreferences prefs = context.getSharedPreferences(context.getString(R.string.kma_prefs_name), Context.MODE_PRIVATE); + editor = prefs.edit(); + + sampleKeyboard = (ImageView) findViewById(R.id.sample_keyboard); + layoutParams = sampleKeyboard.getLayoutParams(); + refreshSampleKeyboard(context, true); + + resetButton = (Button) findViewById(R.id.reset_to_defaults); + resetButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + // Clear the keyboard height preferences to reset + editor.remove(KMManager.KMKey_KeyboardHeightPortrait); + editor.remove(KMManager.KMKey_KeyboardHeightLandscape); + editor.commit(); + + // Restore default height + refreshSampleKeyboard(context, true); + } + }); + + sampleKeyboard.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent event) { + int y = (int)event.getY(); + + switch(event.getAction()) { + case MotionEvent.ACTION_MOVE: + // Update currentHeight as the user drags (moves) + // Increasing the keyboard height is a negative y + currentHeight -= y; + + refreshSampleKeyboard(context, false); + break; + case MotionEvent.ACTION_UP: + // Save the currentHeight when the user releases + int orientation = context.getResources().getConfiguration().orientation; + String keyboardHeightKey = (orientation == Configuration.ORIENTATION_LANDSCAPE) ? + KMManager.KMKey_KeyboardHeightLandscape : KMManager.KMKey_KeyboardHeightPortrait; + editor.putInt(keyboardHeightKey, currentHeight); + editor.commit(); + break; + } + return true; + } + }); + } + + /** + * Refresh the layout for the sample keyboard + * @param context + * @param updateCurrentHeight - boolean if true, updates currentHeight + */ + private void refreshSampleKeyboard(Context context, boolean updateCurrentHeight) { + if (updateCurrentHeight) { + currentHeight = KMManager.getKeyboardHeight(context); + } + + layoutParams.height = currentHeight; + sampleKeyboard.setLayoutParams(layoutParams); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + + layoutParams = sampleKeyboard.getLayoutParams(); + + // When the user rotates the device, restore currentHeight + refreshSampleKeyboard(this,true); + } + + @Override + public void onBackPressed() { + // Apply the adjusted height on exit + KMManager.setKeyboardHeight(this, currentHeight); + + super.onBackPressed(); + } + +} \ No newline at end of file diff --git a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/KeymanSettingsFragment.java b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/KeymanSettingsFragment.java index 09a57a02e6..89e6cb29ed 100644 --- a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/KeymanSettingsFragment.java +++ b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/KeymanSettingsFragment.java @@ -27,7 +27,8 @@ public class KeymanSettingsFragment extends PreferenceFragmentCompat { private static final String TAG = "SettingsFragment"; private static Context context; - private Preference languagesPreference, installKeyboardOrDictionary, displayLanguagePreference; + private Preference languagesPreference, installKeyboardOrDictionary, displayLanguagePreference, + adjustKeyboardHeight; private ListPreference spacebarTextPreference; private CheckBoxPreference setSystemKeyboardPreference; private CheckBoxPreference setDefaultKeyboardPreference; @@ -62,6 +63,13 @@ public class KeymanSettingsFragment extends PreferenceFragmentCompat { Intent displayLanguageIntent = new Intent(context, KeymanSettingsLocalizeActivity.class); displayLanguagePreference.setIntent(displayLanguageIntent); + adjustKeyboardHeight = new Preference(context); + adjustKeyboardHeight.setKey(AdjustKeyboardHeightActivity.adjustKeyboardHeightKey); + adjustKeyboardHeight.setTitle(getString(R.string.adjust_keyboard_height)); + adjustKeyboardHeight.setWidgetLayoutResource(R.layout.preference_height_icon_layout); + Intent adjustKeyboardHeightIntent = new Intent(context, AdjustKeyboardHeightActivity.class); + adjustKeyboardHeight.setIntent(adjustKeyboardHeightIntent); + /* Spacebar Caption Preference */ spacebarTextPreference = new ListPreference(context); @@ -168,6 +176,7 @@ public class KeymanSettingsFragment extends PreferenceFragmentCompat { screen.addPreference(languagesPreference); screen.addPreference(installKeyboardOrDictionary); screen.addPreference(displayLanguagePreference); + screen.addPreference(adjustKeyboardHeight); screen.addPreference(spacebarTextPreference); screen.addPreference(setSystemKeyboardPreference); diff --git a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/MainActivity.java b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/MainActivity.java index ba0a93744e..5fc6e1d0b7 100644 --- a/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/MainActivity.java +++ b/android/KMAPro/kMAPro/src/main/java/com/tavultesoft/kmapro/MainActivity.java @@ -260,6 +260,7 @@ public class MainActivity extends BaseActivity implements OnKeyboardEventListene super.onResume(); KMManager.onResume(); KMManager.hideSystemKeyboard(); + resizeTextView(textView.isKeyboardVisible()); KMManager.addKeyboardEventListener(this); KMKeyboardDownloaderActivity.addKeyboardDownloadEventListener(this); @@ -576,7 +577,7 @@ public class MainActivity extends BaseActivity implements OnKeyboardEventListene } } - private void resizeTextView(boolean isKeyboardVisible) { + public void resizeTextView(boolean isKeyboardVisible) { int bannerHeight = 0; int keyboardHeight = 0; if (isKeyboardVisible) { diff --git a/android/KMAPro/kMAPro/src/main/res/drawable-hdpi/ic_height.png b/android/KMAPro/kMAPro/src/main/res/drawable-hdpi/ic_height.png new file mode 100644 index 0000000000000000000000000000000000000000..a515e98f0377c4448e71260136f458548720aadf GIT binary patch literal 159 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B8K8nx~6nh{y4_S2yx9DDpU8wCCzM zrXtxJm>?YQT&h~wEE0Ti50i?tR-ehN_Q*9hS0gx5SDtfwp0lgjGob$2EGZU81Hq(u zw|CSpcj!1#U+>5&`h_E9wP5tdo2#xx{5xi8#J8kyleT=&nv$ua2NYKTZDjCt^>bP0 Hl+XkKH`q0t literal 0 HcmV?d00001 diff --git a/android/KMAPro/kMAPro/src/main/res/drawable-hdpi/ic_keyboard.png b/android/KMAPro/kMAPro/src/main/res/drawable-hdpi/ic_keyboard.png new file mode 100644 index 0000000000000000000000000000000000000000..2468a51829120db747eeb1ae19a297c5b84f039b GIT binary patch literal 201 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B8Lp1Wy;o5Rc=@2@uY>6eb0Fnz`hq`XgWQ?b?cR^Y zC4<-kW!&l)HvK-xnQMRJUe$)RKU_XYxNN+>B2VCG+;8`_2bL{#+|k81iT4mIhs2lp yQEYz|Zf9p4Jt3GSnxl3_D{E!gkNze>PKI^iZ!ITU9(n+D8-u5-pUXO@geCykeM|k0wldT1B8K8nx~6nh{y4_S2yx9DDpU8wCCzM zrXtxJm>?YQT&h~wEE0Ti50i?tR-ehN_Q*9hS0gx5SDtfwp0lgjGob$2EGZU81Hq(u zw|CSpcj!1#U+>5&`h_E9wP5tdo2#xx{5xi8#J8kyleT=&nv$ua2NYKTZDjCt^>bP0 Hl+XkKH`q0t literal 0 HcmV?d00001 diff --git a/android/KMAPro/kMAPro/src/main/res/drawable-mdpi/ic_keyboard.png b/android/KMAPro/kMAPro/src/main/res/drawable-mdpi/ic_keyboard.png new file mode 100644 index 0000000000000000000000000000000000000000..2468a51829120db747eeb1ae19a297c5b84f039b GIT binary patch literal 201 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k0wldT1B8Lp1Wy;o5Rc=@2@uY>6eb0Fnz`hq`XgWQ?b?cR^Y zC4<-kW!&l)HvK-xnQMRJUe$)RKU_XYxNN+>B2VCG+;8`_2bL{#+|k81iT4mIhs2lp yQEYz|Zf9p4Jt3GSnxl3_D{E!gkNze>PKI^iZ!ITU9(n+D8-u5-pUXO@geCykeMXThrk7?N0r|9)wo#VpAcEM!rS{@ynB_ApxX59I~m;CWVg;U>))xF{z zIb1xUjMJHdLmlGSlFIk-H%2yUGd!I%U7hii{vzh=U?BVDfonPi*UA}w+CI3^zb|#Y lE?eX7ii_dyzL)>q=93P}&3bQr*%#;@22WQ%mvv4FO#rH@MV$o1K;Zwi0~1cpn(--vS=e>yMYB08 z&ljgnKEbu9Hof)2wwSavi*{`AO)*_=n{2x5?GC$C(W6sil~yah4GlBCHShLmp!7!n z6w`&eiKYu=cjzaH9-Zr~lzntddF1M)vXb(1F7p&r{dl|a@>;WV3CYL)&oD?l)WRvO z=0k{awo6v1TlRIg?2(%3+mghN@LB6GZS}inp6K|7>qLCU!rvaekpjCVzDw(tcyG4k zPP*P&zo_-yI`)kU-vnFrZ%z5N$X(_186e0}t!2oSl8XGu=Fb5PDF#nhKbLh*2~7aZ CtBeo; literal 0 HcmV?d00001 diff --git a/android/KMAPro/kMAPro/src/main/res/drawable-xxhdpi/ic_keyboard.png b/android/KMAPro/kMAPro/src/main/res/drawable-xxhdpi/ic_keyboard.png new file mode 100644 index 0000000000000000000000000000000000000000..6d3f0e3dc8d7cbbef5ab3def535d9ed47809234e GIT binary patch literal 392 zcmeAS@N?(olHy`uVBq!ia0vp^IUvlz0wh)Q=esd5F#3DCIEGZ*dVAZ@kI7M_{bT)- z?F%Qb7T|ltx<$E#`3+-+MWd+shIGqz+o`N#T}|5E!3jMs#=CDCevaGseyh&I@B?`# zq&qvHK;!$mlC>+l&ZPbNxsvT|p!3vK#`C7SoedP9mD+1{HfC?y25aFp2Hk3FqK(%W zJdU`wRL=LH*{kCR^L#cQ@_Cf-{aM0kiyO_BH>~)+rSOFvJvi^|!K{P>J_qCK_U^H$ z&i!~idiicH34_}kbPW zo`|3uauOTvBp%DZ@IFp{Wdq}BmM}(UHXY43i?2qPZ)KP!yJmF*l#-`?$*0%PJ&aUpB-aaXD7Y(57XHOT$kP61Pw~sP1Gx9JWR5@k%Jw9i~Mg80T zce$1^WV-4J0>Qvx<=Du8=1mrtAt;`@BRTv}#q?w<}dE{ho1( znf?lxd`4I!>+4dpW0zlM$L>*&yYf1H@AmWy^V=%?mt;&?c=5dP$txo7I|a`gnO9ec z-Mswh*+=o4mz}leGcYo-a0n<@h8>iy3#_}|Iti!)ByOP{e{QzF89^VrTa z)9bse)IMyR%wW!S_@YW&NO73a-JKSDB=s8SsPS$O>f8SBdWsSdEVA8EBFUPfd-yIW OOg&xwT-G@yGywo2MudX^ literal 0 HcmV?d00001 diff --git a/android/KMAPro/kMAPro/src/main/res/drawable-xxxhdpi/ic_keyboard.png b/android/KMAPro/kMAPro/src/main/res/drawable-xxxhdpi/ic_keyboard.png new file mode 100644 index 0000000000000000000000000000000000000000..cfa9545e2ff9405eee2bdc19bfbe954b9a53e9c5 GIT binary patch literal 494 zcmeAS@N?(olHy`uVBq!ia0vp^6F``Q1xWh(YZ)^zFmCm9aSW-r_4bafA5)-6!^Q2a zx;>n`4L2t8hJ|es&o-+ap{RNH>X%#Fi>Iu+^!(o8Kl3tIT`H8eS^jckvBm33 zufNM|o^!vfY)_xY=3C)sb#AlLseRpimz|$iPBT7ND;C@KAkuH@;o=Eui4Dsv+y6yM z%zK(*vueFFBdn}?M@Nxjf zSR3atGBUBOP`JRY;Lza3+*%h|%gVwbu%O8yzhM@0tKBn3#w<1yMu^b+1_nl^5P=uW z0mTb0=&x>IFlGM50+9-K0Lp1`m@t2_ceu@WVI5N~&{&QD#|8ON33ir@*Z(cvoJ-L$ zmuzJ^713|Z!#ZVSLZ$$hMzU+T{sr@+nfKDJYw-k3EpL!xkDO?HF23qE|A*A7YdH_! zE_m$1JN@pucZ=TT31ub5etH!dQu@IqJNMzYUl+D-ibVvlil_B;ex2_ROY8q + + + + + + + + + + diff --git a/android/KMAPro/kMAPro/src/main/res/layout/activity_adjust_keyboard_height.xml b/android/KMAPro/kMAPro/src/main/res/layout/activity_adjust_keyboard_height.xml new file mode 100644 index 0000000000..96b6d15746 --- /dev/null +++ b/android/KMAPro/kMAPro/src/main/res/layout/activity_adjust_keyboard_height.xml @@ -0,0 +1,59 @@ + + + + + + + + + +