List of usage examples for android.webkit WebView isFocusableInTouchMode
@ViewDebug.ExportedProperty(category = "focus") public final boolean isFocusableInTouchMode()
From source file:com.ichi2.anki.AbstractFlashcardViewer.java
@SuppressLint({ "NewApi", "SetJavaScriptEnabled" })
// because of setDisplayZoomControls.
private WebView createWebView() {
WebView webView = new MyWebView(this);
webView.setWillNotCacheDrawing(true);
webView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
if (CompatHelper.isHoneycomb()) {
// Disable the on-screen zoom buttons for API > 11
webView.getSettings().setDisplayZoomControls(false);
}//from w w w . j a v a 2s . co m
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSupportZoom(true);
// Start at the most zoomed-out level
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new AnkiDroidWebChromeClient());
// Problems with focus and input tags is the reason we keep the old type answer mechanism for old Androids.
webView.setFocusableInTouchMode(mUseInputTag);
webView.setScrollbarFadingEnabled(true);
Timber.d("Focusable = %s, Focusable in touch mode = %s", webView.isFocusable(),
webView.isFocusableInTouchMode());
webView.setWebViewClient(new WebViewClient() {
// Filter any links using the custom "playsound" protocol defined in Sound.java.
// We play sounds through these links when a user taps the sound icon.
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("playsound:")) {
// Send a message that will be handled on the UI thread.
Message msg = Message.obtain();
String soundPath = url.replaceFirst("playsound:", "");
msg.obj = soundPath;
mHandler.sendMessage(msg);
return true;
}
if (url.startsWith("file") || url.startsWith("data:")) {
return false; // Let the webview load files, i.e. local images.
}
if (url.startsWith("typeblurtext:")) {
// Store the text the javascript has send us
mTypeInput = URLDecoder.decode(url.replaceFirst("typeblurtext:", ""));
// and show the SHOW ANSWER? button again.
mFlipCardLayout.setVisibility(View.VISIBLE);
return true;
}
if (url.startsWith("typeentertext:")) {
// Store the text the javascript has send us
mTypeInput = URLDecoder.decode(url.replaceFirst("typeentertext:", ""));
// and show the answer.
mFlipCardLayout.performClick();
return true;
}
if (url.equals("signal:typefocus")) {
// Hide the SHOW ANSWER? button when the input has focus. The soft keyboard takes up enough space
// by itself.
mFlipCardLayout.setVisibility(View.GONE);
return true;
}
Timber.d("Opening external link \"%s\" with an Intent", url);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
try {
startActivityWithoutAnimation(intent);
} catch (ActivityNotFoundException e) {
e.printStackTrace(); // Don't crash if the intent is not handled
}
return true;
}
// Run any post-load events in javascript that rely on the window being completely loaded.
@Override
public void onPageFinished(WebView view, String url) {
Timber.d("onPageFinished triggered");
view.loadUrl("javascript:onPageFinished();");
}
});
// Set transparent color to prevent flashing white when night mode enabled
webView.setBackgroundColor(Color.argb(1, 0, 0, 0));
return webView;
}
From source file:com.ichi2.anki2.Reviewer.java
private WebView createWebView() { WebView webView = new MyWebView(this); webView.setWillNotCacheDrawing(true); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); if (mZoomEnabled) { webView.getSettings().setBuiltInZoomControls(true); }/*from w ww .jav a2 s . c om*/ webView.getSettings().setJavaScriptEnabled(true); webView.setWebChromeClient(new AnkiDroidWebChromeClient()); webView.addJavascriptInterface(new JavaScriptInterface(this), "ankidroid"); if (AnkiDroidApp.SDK_VERSION > 7) { webView.setFocusableInTouchMode(false); } AnkiDroidApp.getCompat().setScrollbarFadingEnabled(webView, mPrefFadeScrollbars); Log.i(AnkiDroidApp.TAG, "Focusable = " + webView.isFocusable() + ", Focusable in touch mode = " + webView.isFocusableInTouchMode()); return webView; }