From 4680019da3588bf726602e11f87a861514713edc Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Fri, 28 Aug 2020 16:05:12 +0700 Subject: [PATCH 1/2] fix(android): Fix overflow menu for hdpi devices Cherrypick of #3532 to stable-13.0 --- android/KMAPro/kMAPro/build.gradle | 2 +- .../com/tavultesoft/kmapro/MainActivity.java | 87 +++++------------- .../ic_light_action_overflow.png | Bin 0 -> 453 bytes .../kMAPro/src/main/res/layout/titlebar.xml | 3 +- .../KMAPro/kMAPro/src/main/res/menu/main.xml | 43 ++++++++- .../src/main/res/menu/overflow_menu.xml | 43 --------- android/KMEA/app/build.gradle | 2 +- 7 files changed, 71 insertions(+), 109 deletions(-) create mode 100644 android/KMAPro/kMAPro/src/main/res/drawable-xxxhdpi/ic_light_action_overflow.png delete mode 100644 android/KMAPro/kMAPro/src/main/res/menu/overflow_menu.xml diff --git a/android/KMAPro/kMAPro/build.gradle b/android/KMAPro/kMAPro/build.gradle index ba17b41084..1c04bf6ce6 100644 --- a/android/KMAPro/kMAPro/build.gradle +++ b/android/KMAPro/kMAPro/build.gradle @@ -117,7 +117,7 @@ repositories { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.appcompat:appcompat:1.2.0-alpha02' + implementation 'androidx.appcompat:appcompat:1.3.0-alpha02' implementation 'com.google.android.material:material:1.0.0' api(name: 'keyman-engine', ext: 'aar') implementation "com.google.firebase:firebase-analytics:17.2.1" 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 df8d185d20..0716ac2f53 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 @@ -386,92 +386,54 @@ public class MainActivity extends AppCompatActivity implements OnKeyboardEventLi invalidateOptionsMenu(); } - + @SuppressLint("RestrictedApi") @Override public boolean onPrepareOptionsMenu(final Menu menu) { final MenuItem _overflowMenuItem = menu.findItem(R.id.action_overflow); - - if(_overflowMenuItem!=null) { - final ViewGroup _rootView = (ViewGroup) _overflowMenuItem.getActionView(); - - _rootView.findViewById(R.id.counterBackground).setBackground( - this.getResources().getDrawable(R.drawable.ic_light_action_overflow)); - - _rootView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - PopupMenu _popup = new PopupMenu(context, _rootView); - getMenuInflater().inflate(R.menu.overflow_menu, _popup.getMenu()); - - updateUpdateCountIndicator( - _popup.getMenu().findItem(R.id.action_update_keyboards), - KMManager.getUpdateTool().getOpenUpdateCount(),true); - - _popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - public boolean onMenuItemClick(MenuItem theItem) { - return onOptionsItemSelected(theItem); - } - }); - - MenuPopupHelper _menuHelper = new MenuPopupHelper(context, (MenuBuilder) _popup.getMenu(), _rootView); - _menuHelper.setForceShowIcon(true); - _menuHelper.show(); - } - }); - return super.onPrepareOptionsMenu(menu); + if (_overflowMenuItem != null) { + MenuItem updateKeyboards = this.menu.findItem(R.id.action_update_keyboards); + updateUpdateCountIndicator(updateKeyboards, + KMManager.getUpdateTool().getOpenUpdateCount(), true); } - - final MenuItem _keyboardupdate = menu.findItem(R.id.action_update_keyboards); - if(_keyboardupdate==null) - return super.onPrepareOptionsMenu(menu); - - final ViewGroup _rootView = (ViewGroup) _keyboardupdate.getActionView(); - - _rootView.findViewById(R.id.counterBackground).setBackground( - this.getResources().getDrawable(R.drawable.ic_cloud_download)); - - _rootView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - onOptionsItemSelected(_keyboardupdate); - } - }); return super.onPrepareOptionsMenu(menu); } private void updateUpdateCountIndicator(int anUpdateCount) { - if (menu == null) + if (menu == null) { return; + } final MenuItem _overflowMenuItem = menu.findItem(R.id.action_overflow); - if (_overflowMenuItem != null) - updateUpdateCountIndicator(_overflowMenuItem,anUpdateCount,false); + if (_overflowMenuItem != null) { + updateUpdateCountIndicator(_overflowMenuItem, anUpdateCount, false); + } final MenuItem _keyboardupdate = menu.findItem(R.id.action_update_keyboards); - if (_keyboardupdate != null) - updateUpdateCountIndicator(_keyboardupdate,anUpdateCount,true); - + if (_keyboardupdate != null) { + updateUpdateCountIndicator(_keyboardupdate, anUpdateCount, true); + } } private void updateUpdateCountIndicator(MenuItem theItem, int anUpdateCount, boolean aHideMenuitem) { final ViewGroup _rootView = (ViewGroup) theItem.getActionView(); - if(anUpdateCount==0) - { - if(aHideMenuitem) + if(anUpdateCount==0) { + if (aHideMenuitem) { theItem.setVisible(false); - else if(_rootView!=null) + } else if (_rootView != null) { _rootView.findViewById(R.id.update_count_indicator).setVisibility(View.GONE); - } - else { - if(aHideMenuitem) + } + } else { + if(aHideMenuitem) { theItem.setVisible(true); - else if(_rootView!=null) - _rootView.findViewById(R.id.update_count_indicator).setVisibility(View.VISIBLE); + } else if(_rootView!=null) { + _rootView.findViewById(R.id.update_count_indicator).setVisibility(View.VISIBLE); + } } - if(_rootView==null) + if(_rootView==null) { return; + } TextView _t = _rootView.findViewById(R.id.update_count_indicator); _t.setText(String.valueOf(anUpdateCount)); @@ -778,6 +740,7 @@ public class MainActivity extends AppCompatActivity implements OnKeyboardEventLi @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == PERMISSION_REQUEST_STORAGE) { // Request for storage permission if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { diff --git a/android/KMAPro/kMAPro/src/main/res/drawable-xxxhdpi/ic_light_action_overflow.png b/android/KMAPro/kMAPro/src/main/res/drawable-xxxhdpi/ic_light_action_overflow.png new file mode 100644 index 0000000000000000000000000000000000000000..c32d61b388a4b401eb4c9432681feb1dd40c4c9e GIT binary patch literal 453 zcmeAS@N?(olHy`uVBq!ia0vp^6F``Q8Ax83A=Cw=k^_7~T!A#LL0U%1J)j+mB|(0{ z3?lKXkKaGMIGm^d_y5oJ?(ZL)WCwf8%vULYe%fHYMsoWcO`|lR;t!rKjv*C{Zw|U9 zF*^z{JLn$Hn09u`|9Yb{FLx*HUj1NB@j1)qbBf=+Qq7zu?izWO_h0i8-Wu`UY(;+$ z*v&|Km3^t&n7FNG|E=yJ%?TcKn5e>|!A2q+wZ6 lPoE$|0je-W4F?0mfjGwVJZ^iJpYH|7ho`Hb%Q~loCIA95kih@| literal 0 HcmV?d00001 diff --git a/android/KMAPro/kMAPro/src/main/res/layout/titlebar.xml b/android/KMAPro/kMAPro/src/main/res/layout/titlebar.xml index e76d908e9f..f5165568dc 100644 --- a/android/KMAPro/kMAPro/src/main/res/layout/titlebar.xml +++ b/android/KMAPro/kMAPro/src/main/res/layout/titlebar.xml @@ -5,4 +5,5 @@ android:id="@+id/titlebar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" - android:layout_alignParentTop="true" /> + android:layout_alignParentTop="true" + app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> diff --git a/android/KMAPro/kMAPro/src/main/res/menu/main.xml b/android/KMAPro/kMAPro/src/main/res/menu/main.xml index cc407ea789..a8c587ece6 100644 --- a/android/KMAPro/kMAPro/src/main/res/menu/main.xml +++ b/android/KMAPro/kMAPro/src/main/res/menu/main.xml @@ -20,6 +20,47 @@ android:id="@+id/action_overflow" app:showAsAction="ifRoom" android:title="@string/action_overflow" - app:actionLayout="@layout/update_count_view" /> + android:icon="@drawable/ic_light_action_overflow" > + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/KMAPro/kMAPro/src/main/res/menu/overflow_menu.xml b/android/KMAPro/kMAPro/src/main/res/menu/overflow_menu.xml deleted file mode 100644 index bd04923669..0000000000 --- a/android/KMAPro/kMAPro/src/main/res/menu/overflow_menu.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/android/KMEA/app/build.gradle b/android/KMEA/app/build.gradle index 2b8aed7919..2ef76b57d1 100644 --- a/android/KMEA/app/build.gradle +++ b/android/KMEA/app/build.gradle @@ -66,7 +66,7 @@ android { } dependencies { - implementation 'androidx.appcompat:appcompat:1.2.0-alpha02' + implementation 'androidx.appcompat:appcompat:1.3.0-alpha02' implementation 'com.google.android.material:material:1.0.0' implementation 'commons-io:commons-io:2.6' From ec22ae9fac4d72a51493a7aeff04292f580eba9b Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Fri, 28 Aug 2020 16:11:26 +0700 Subject: [PATCH 2/2] chore(android): Update history.md --- android/history.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/android/history.md b/android/history.md index 7eb9150e98..217363fbd9 100644 --- a/android/history.md +++ b/android/history.md @@ -1,5 +1,9 @@ # Keyman for Android Version History +## 2020-08-31 13.0.6217 stable +* Bug fix: + * Fix overflow menu for hdpi devices (#3536) + ## 2020-07-17 13.0.6216 stable * Bug fix: * Make sure switch to system keyboard works on lock screen for Android P (#3358)