android imm.isAcceptingText() fix code refactoring

This commit is contained in:
Lorenzo Pichilli 2023-11-10 21:12:14 +01:00
parent fb7e025ee0
commit adcfdce7ed
2 changed files with 14 additions and 12 deletions

View File

@ -660,7 +660,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
if (plugin == null) { if (plugin == null) {
return; return;
} }
loadUrl(Util.getUrlAsset(plugin, assetFilePath)); loadUrl(Util.getUrlAsset(plugin, assetFilePath));
} }
@ -690,7 +690,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
public void takeScreenshot(final @Nullable Map<String, Object> screenshotConfiguration, final MethodChannel.Result result) { public void takeScreenshot(final @Nullable Map<String, Object> screenshotConfiguration, final MethodChannel.Result result) {
final float pixelDensity = Util.getPixelDensity(getContext()); final float pixelDensity = Util.getPixelDensity(getContext());
mainLooperHandler.post(new Runnable() { mainLooperHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1392,9 +1392,9 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
if (printManager != null) { if (printManager != null) {
PrintAttributes.Builder builder = new PrintAttributes.Builder(); PrintAttributes.Builder builder = new PrintAttributes.Builder();
String jobName = (getTitle() != null ? getTitle() : getUrl()) + " Document"; String jobName = (getTitle() != null ? getTitle() : getUrl()) + " Document";
if (settings != null) { if (settings != null) {
if (settings.jobName != null && !settings.jobName.isEmpty()) { if (settings.jobName != null && !settings.jobName.isEmpty()) {
jobName = settings.jobName; jobName = settings.jobName;
@ -1445,7 +1445,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
String id = UUID.randomUUID().toString(); String id = UUID.randomUUID().toString();
PrintJobController printJobController = new PrintJobController(id, job, settings, plugin); PrintJobController printJobController = new PrintJobController(id, job, settings, plugin);
plugin.printJobManager.jobs.put(printJobController.id, printJobController); plugin.printJobManager.jobs.put(printJobController.id, printJobController);
return id; return id;
} }
} else { } else {
Log.e(LOG_TAG, "No PrintManager available"); Log.e(LOG_TAG, "No PrintManager available");
@ -1525,14 +1525,16 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
public void run() { public void run() {
InputMethodManager imm = InputMethodManager imm =
(InputMethodManager) getContext().getSystemService(INPUT_METHOD_SERVICE); (InputMethodManager) getContext().getSystemService(INPUT_METHOD_SERVICE);
boolean isAcceptingText = false; boolean isAcceptingText = false;
try { if (imm != null) {
if (imm != null) { try {
// imm.isAcceptingText() seems to sometimes crash on some devices // imm.isAcceptingText() seems to sometimes crash on some devices
isAcceptingText = imm.isAcceptingText(); isAcceptingText = imm.isAcceptingText();
} catch (Exception ignored) {
} }
} catch (Exception ignored) {
} }
if (containerView != null && imm != null && !isAcceptingText) { if (containerView != null && imm != null && !isAcceptingText) {
imm.hideSoftInputFromWindow( imm.hideSoftInputFromWindow(
containerView.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); containerView.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
@ -1718,7 +1720,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
public void hideContextMenu() { public void hideContextMenu() {
removeView(floatingContextMenu); removeView(floatingContextMenu);
floatingContextMenu = null; floatingContextMenu = null;
if (channelDelegate != null) channelDelegate.onHideContextMenu(); if (channelDelegate != null) channelDelegate.onHideContextMenu();
} }
@ -2004,7 +2006,7 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
public WebViewChannelDelegate getChannelDelegate() { public WebViewChannelDelegate getChannelDelegate() {
return channelDelegate; return channelDelegate;
} }
@Override @Override
public void setChannelDelegate(@Nullable WebViewChannelDelegate channelDelegate) { public void setChannelDelegate(@Nullable WebViewChannelDelegate channelDelegate) {
this.channelDelegate = channelDelegate; this.channelDelegate = channelDelegate;

View File

@ -1878,7 +1878,7 @@ class InAppWebViewController {
///- MacOS ([Official API - WKWebView.canGoBack](https://developer.apple.com/documentation/webkit/wkwebview/1414966-cangoback)) ///- MacOS ([Official API - WKWebView.canGoBack](https://developer.apple.com/documentation/webkit/wkwebview/1414966-cangoback))
Future<bool> canGoBack() async { Future<bool> canGoBack() async {
Map<String, dynamic> args = <String, dynamic>{}; Map<String, dynamic> args = <String, dynamic>{};
return await _channel?.invokeMethod<bool>('canGoBack', args) ?? false; return await _channel?.invokeMethod('canGoBack', args);
} }
///Goes forward in the history of the WebView. ///Goes forward in the history of the WebView.
@ -1903,7 +1903,7 @@ class InAppWebViewController {
///- MacOS ([Official API - WKWebView.canGoForward](https://developer.apple.com/documentation/webkit/wkwebview/1414962-cangoforward)) ///- MacOS ([Official API - WKWebView.canGoForward](https://developer.apple.com/documentation/webkit/wkwebview/1414962-cangoforward))
Future<bool> canGoForward() async { Future<bool> canGoForward() async {
Map<String, dynamic> args = <String, dynamic>{}; Map<String, dynamic> args = <String, dynamic>{};
return await _channel?.invokeMethod('canGoForward', args) ?? false; return await _channel?.invokeMethod('canGoForward', args);
} }
///Goes to the history item that is the number of steps away from the current item. Steps is negative if backward and positive if forward. ///Goes to the history item that is the number of steps away from the current item. Steps is negative if backward and positive if forward.