mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-08 14:52:13 -04:00
Fix long click selection of WebView
The read aloud feature was crashing the app when long clicking the WebView, ultimativly making it impossible to copy text.
This commit is contained in:
parent
ece6217f7b
commit
eab0b39c08
@ -20,7 +20,6 @@
|
||||
<item
|
||||
android:id="@+id/menu_speak_text"
|
||||
android:icon="@drawable/action_voice"
|
||||
android:onClick="onContextMenuClicked"
|
||||
android:title="@string/menu_read_aloud"
|
||||
app:showAsAction="always"/>
|
||||
</menu>
|
||||
|
@ -164,6 +164,7 @@ public class KiwixMobileActivity extends AppCompatActivity
|
||||
Menu menu = mode.getMenu();
|
||||
// Inflate custom menu icon.
|
||||
getMenuInflater().inflate(R.menu.menu_webview_action, menu);
|
||||
readAloudSelection(menu);
|
||||
}
|
||||
super.onActionModeStarted(mode);
|
||||
}
|
||||
@ -174,18 +175,19 @@ public class KiwixMobileActivity extends AppCompatActivity
|
||||
super.onActionModeFinished(mode);
|
||||
}
|
||||
|
||||
public void onContextMenuClicked(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_speak_text:
|
||||
Log.i(TAG_KIWIX, "Speaking selection.");
|
||||
tts.readSelection();
|
||||
break;
|
||||
default:
|
||||
Log.e(TAG_KIWIX, "Unexpected context menu click.");
|
||||
break;
|
||||
}
|
||||
if (mActionMode != null) {
|
||||
mActionMode.finish();
|
||||
private void readAloudSelection(Menu menu) {
|
||||
if (menu != null) {
|
||||
menu.findItem(R.id.menu_speak_text).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
Log.i(TAG_KIWIX, "Speaking selection.");
|
||||
tts.readSelection();
|
||||
if (mActionMode != null) {
|
||||
mActionMode.finish();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user