mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-19 22:27:39 +00:00
Merge pull request #3536 from keymanapp/fix/android/cherrypick-overflow-menu
fix(android): Fix overflow menu for hdpi devices
This commit is contained in:
commit
cf858950b6
8 changed files with 75 additions and 109 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 453 B |
|
|
@ -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" />
|
||||
|
|
|
|||
|
|
@ -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" >
|
||||
|
||||
<menu>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_text_size"
|
||||
android:title="@string/action_text_size"
|
||||
app:showAsAction="always"
|
||||
android:icon="@drawable/ic_light_action_textsize" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_clear_text"
|
||||
android:title="@string/action_clear_text"
|
||||
app:showAsAction="always"
|
||||
android:icon="@drawable/ic_light_action_trash" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_info"
|
||||
android:title="@string/action_info"
|
||||
app:showAsAction="always"
|
||||
android:icon="@drawable/ic_light_action_info" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_get_started"
|
||||
android:title="@string/get_started"
|
||||
app:showAsAction="always"
|
||||
android:icon="@drawable/ic_action_get_started" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:title="@string/action_settings"
|
||||
app:showAsAction="always"
|
||||
android:icon="@drawable/ic_settings" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_update_keyboards"
|
||||
android:title="@string/action_install_updates"
|
||||
app:showAsAction="always"
|
||||
android:icon="@drawable/ic_cloud_download"
|
||||
app:actionLayout="@layout/update_count_view"/>
|
||||
|
||||
</menu>
|
||||
</item>
|
||||
</menu>
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_text_size"
|
||||
android:title="@string/action_text_size"
|
||||
app:showAsAction="never"
|
||||
android:icon="@drawable/ic_light_action_textsize" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_clear_text"
|
||||
android:title="@string/action_clear_text"
|
||||
app:showAsAction="never"
|
||||
android:icon="@drawable/ic_light_action_trash" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_info"
|
||||
android:title="@string/action_info"
|
||||
app:showAsAction="never"
|
||||
android:icon="@drawable/ic_light_action_info" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_get_started"
|
||||
android:title="@string/get_started"
|
||||
app:showAsAction="never"
|
||||
android:icon="@drawable/ic_action_get_started" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:title="@string/action_settings"
|
||||
app:showAsAction="never"
|
||||
android:icon="@drawable/ic_settings" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_update_keyboards"
|
||||
android:title="@string/action_install_updates"
|
||||
app:showAsAction="never"
|
||||
android:icon="@drawable/ic_cloud_download"/>
|
||||
|
||||
</menu>
|
||||
|
|
@ -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'
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue