List of usage examples for android.webkit WebSettings setDisplayZoomControls
public abstract void setDisplayZoomControls(boolean enabled);
From source file:com.zbrown.droidsteal.activities.HijackActivity.java
private void setupWebView() { webview = (WebView) findViewById(R.id.webviewhijack); webview.setWebViewClient(new MyWebViewClient()); WebSettings webSettings = webview.getSettings(); webSettings.setUserAgentString(/*w w w. ja v a2 s . c o m*/ "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36"); webSettings.setJavaScriptEnabled(true); //Blah blah JavaScript is scary blah blah webSettings.setAppCacheEnabled(false); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); webview.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int progress) { HijackActivity.this.setProgress(progress * 100); int fprogress = (Window.PROGRESS_END) / 100 * progress; setProgress(fprogress); if (progress == 100) { setProgressBarIndeterminateVisibility(false); } } }); }
From source file:io.github.calvinmikael.anymanga.WebViewFragment.java
@SuppressLint("SetJavaScriptEnabled") @Override/*from www.j a v a 2s. com*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_web_view, container, false); mProgressBar = (ProgressBar) view.findViewById(R.id.progressBar); mProgressBar.setVisibility(View.GONE); mWebView = (ObservableWebView) view.findViewById(R.id.webView); mWebView.setScrollViewCallbacks(this); WebSettings settings = mWebView.getSettings(); settings.setLoadsImagesAutomatically(true); settings.setJavaScriptEnabled(true); settings.setDomStorageEnabled(true); mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); if (!mProgressBar.isShown()) { mProgressBar.setVisibility(View.VISIBLE); } } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if (mProgressBar.isShown()) { mProgressBar.setVisibility(View.GONE); } } }); mWebView.setWebChromeClient(new WebChromeClient() { @Override public void onShowCustomView(View view, CustomViewCallback callback) { // if a view already exists then immediately terminate the new one if (mCustomView != null) { onHideCustomView(); return; } // Save the current state mCustomView = view; mOriginalSystemUiVisibility = getActivity().getWindow().getDecorView().getSystemUiVisibility(); // Save the custom view callback mCustomViewCallback = callback; // Add the custom view to the view hierarchy FrameLayout decorView = (FrameLayout) getActivity().getWindow().getDecorView(); decorView.addView(mCustomView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); mTabStrip = (PagerSlidingTabStrip) getActivity().findViewById(R.id.tabs); mTabStrip.setVisibility(View.GONE); // Go fullscreen if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { getActivity().getWindow().getDecorView() .setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getActivity().getWindow().getDecorView() .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } } @Override public void onHideCustomView() { // Remove the custom view FrameLayout decorView = (FrameLayout) getActivity().getWindow().getDecorView(); decorView.removeView(mCustomView); mCustomView = null; mTabStrip.setVisibility(View.VISIBLE); // Restore the original form getActivity().getWindow().getDecorView().setSystemUiVisibility(mOriginalSystemUiVisibility); // Call the custom view callback mCustomViewCallback.onCustomViewHidden(); mCustomViewCallback = null; } }); // The back button must be handled within the mWebView for the // mWebView to have back behavior based on the current mPage // if back behavior is not handled with this listener then // back behavior will be entirely dependent on the first mPage mWebView.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack() && keyEvent.getAction() == KeyEvent.ACTION_DOWN) { mWebView.goBack(); return true; } return false; } }); if (savedInstanceState != null) { mWebView.restoreState(savedInstanceState); } else { if (mPage == 1) { mWebView.loadUrl(getString(R.string.website_kissmanga)); } else if (mPage == 2) { mWebView.loadUrl(getString(R.string.website_mangapark)); } else if (mPage == 3) { mWebView.loadUrl(getString(R.string.website_line_webtoon)); } } return view; }
From source file:no.digipost.android.gui.metadata.ExternalLinkWebview.java
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); ((DigipostApplication) getApplication()).getTracker(DigipostApplication.TrackerName.APP_TRACKER); setContentView(R.layout.activity_externallink_webview); Bundle bundle = getIntent().getExtras(); fileUrl = bundle.getString("url", "https://www.digipost.no"); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//from w ww.j a v a2s . c o m actionBar = getSupportActionBar(); if (actionBar != null) { setActionBarTitle(fileUrl); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setBackgroundDrawable(new ColorDrawable(0xff2E2E2E)); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = this.getWindow(); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor( ContextCompat.getColor(this, R.color.metadata_externalbrowser_top_background)); } } progressSpinner = (ProgressBar) findViewById(R.id.externallink_spinner); webView = (WebView) findViewById(R.id.externallink_webview); WebSettings settings = webView.getSettings(); settings.setJavaScriptEnabled(true); settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); settings.setDomStorageEnabled(true); settings.setLoadWithOverviewMode(true); settings.setUseWideViewPort(true); settings.setSupportZoom(true); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); settings.setCacheMode(WebSettings.LOAD_NO_CACHE); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.setScrollbarFadingEnabled(true); enableCookies(webView); webView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if (firstLoad) { progressSpinner.setVisibility(View.GONE); webView.setVisibility(View.VISIBLE); firstLoad = false; } setActionBarTitle(view.getUrl()); } }); webView.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(final String url, final String userAgent, final String content, final String mimeType, final long contentLength) { fileName = URLUtil.guessFileName(url, content, mimeType); fileUrl = url; onComplete = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { showDownloadSuccessDialog(context); } } }; registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); if (!mimeType.equals("text/html")) { if (FileUtilities.isStorageWriteAllowed(getApplicationContext())) { showDownloadDialog(userAgent, content, mimeType, contentLength); } else { showMissingPermissionsDialog(); } } } }); if (FileUtilities.isStorageWriteAllowed(this)) { webView.loadUrl(fileUrl); } else { showPermissionsDialog(); } }
From source file:au.com.wallaceit.reddinator.TabCommentsFragment.java
@SuppressLint({ "SetJavaScriptEnabled", "AddJavascriptInterface" }) public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this.getActivity(); SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); global = (GlobalObjects) mContext.getApplicationContext(); final boolean load = getArguments().getBoolean("load"); // get needed activity values articleId = getActivity().getIntent().getStringExtra(WidgetProvider.ITEM_ID); permalink = getActivity().getIntent().getStringExtra(WidgetProvider.ITEM_PERMALINK); ll = new LinearLayout(mContext); ll.setLayoutParams(new WebView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 0, 0)); // fixes for webview not taking keyboard input on some devices mWebView = new WebView(mContext); mWebView.setLayoutParams(new WebView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 0, 0)); ll.addView(mWebView);/*from w w w . j a v a2 s . c om*/ WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); // enable ecmascript webSettings.setDomStorageEnabled(true); // some video sites require dom storage webSettings.setSupportZoom(false); webSettings.setBuiltInZoomControls(false); webSettings.setDisplayZoomControls(false); int fontSize = Integer.parseInt(mSharedPreferences.getString("commentfontpref", "18")); webSettings.setDefaultFontSize(fontSize); webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); mSharedPreferences.getString("titlefontpref", "16"); final String themeStr = global.mThemeManager.getActiveTheme("appthemepref").getValuesString(); mWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { boolean redditLink = false; System.out.println(url); if (url.indexOf("file://") == 0) { // fix for short sub and user links url = url.replace("file://", "https://www.reddit.com") + "/.compact"; redditLink = true; } if (redditLink || url.indexOf("https://www.reddit.com/") == 0) { Intent i = new Intent(mContext, WebViewActivity.class); i.putExtra("url", url); startActivity(i); } else { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(i); } return true; // always override url } public void onPageFinished(WebView view, String url) { mWebView.loadUrl("javascript:init(\"" + StringEscapeUtils.escapeJavaScript(themeStr) + "\", \"" + global.mRedditData.getUsername() + "\")"); if (load) load(); } }); mWebView.setWebChromeClient(new WebChromeClient()); mWebView.requestFocus(View.FOCUS_DOWN); WebInterface webInterface = new WebInterface(mContext); mWebView.addJavascriptInterface(webInterface, "Reddinator"); mWebView.loadUrl("file:///android_asset/comments.html#" + articleId); }
From source file:com.wellsandwhistles.android.redditsp.fragments.WebViewFragment.java
@SuppressLint("NewApi") @Override// www .j av a 2 s .c o m public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { mActivity = (AppCompatActivity) getActivity(); CookieSyncManager.createInstance(mActivity); outer = (FrameLayout) inflater.inflate(R.layout.web_view_fragment, null); webView = (WebViewFixed) outer.findViewById(R.id.web_view_fragment_webviewfixed); final FrameLayout loadingViewFrame = (FrameLayout) outer .findViewById(R.id.web_view_fragment_loadingview_frame); /*handle download links show an alert box to load this outside the internal browser*/ webView.setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(final String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { { new AlertDialog.Builder(mActivity).setTitle(R.string.download_link_title) .setMessage(R.string.download_link_message) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); getContext().startActivity(i); mActivity.onBackPressed(); //get back from internal browser } }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { mActivity.onBackPressed(); //get back from internal browser } }).setIcon(android.R.drawable.ic_dialog_alert).show(); } } }); /*handle download links end*/ progressView = new ProgressBar(mActivity, null, android.R.attr.progressBarStyleHorizontal); loadingViewFrame.addView(progressView); loadingViewFrame.setPadding(General.dpToPixels(mActivity, 10), 0, General.dpToPixels(mActivity, 10), 0); final WebSettings settings = webView.getSettings(); settings.setBuiltInZoomControls(true); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(false); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); settings.setDomStorageEnabled(true); settings.setDisplayZoomControls(false); // TODO handle long clicks webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, final int newProgress) { super.onProgressChanged(view, newProgress); General.UI_THREAD_HANDLER.post(new Runnable() { @Override public void run() { progressView.setProgress(newProgress); progressView.setVisibility(newProgress == 100 ? View.GONE : View.VISIBLE); } }); } }); if (mUrl != null) { webView.loadUrl(mUrl); } else { webView.loadDataWithBaseURL("https://reddit.com/", html, "text/html; charset=UTF-8", null, null); } webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(final WebView view, final String url) { if (url == null) return false; if (url.startsWith("data:")) { // Prevent imgur bug where we're directed to some random data URI return true; } // Go back if loading same page to prevent redirect loops. if (goingBack && currentUrl != null && url.equals(currentUrl)) { General.quickToast(mActivity, String.format(Locale.US, "Handling redirect loop (level %d)", -lastBackDepthAttempt), Toast.LENGTH_SHORT); lastBackDepthAttempt--; if (webView.canGoBackOrForward(lastBackDepthAttempt)) { webView.goBackOrForward(lastBackDepthAttempt); } else { mActivity.finish(); } } else { if (RedditURLParser.parse(Uri.parse(url)) != null) { LinkHandler.onLinkClicked(mActivity, url, false); } else { webView.loadUrl(url); currentUrl = url; } } return true; } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); if (mUrl != null && url != null) { final AppCompatActivity activity = mActivity; if (activity != null) { activity.setTitle(url); } } } @Override public void onPageFinished(final WebView view, final String url) { super.onPageFinished(view, url); new Timer().schedule(new TimerTask() { @Override public void run() { General.UI_THREAD_HANDLER.post(new Runnable() { @Override public void run() { if (currentUrl == null || url == null) return; if (!url.equals(view.getUrl())) return; if (goingBack && url.equals(currentUrl)) { General.quickToast(mActivity, String.format(Locale.US, "Handling redirect loop (level %d)", -lastBackDepthAttempt)); lastBackDepthAttempt--; if (webView.canGoBackOrForward(lastBackDepthAttempt)) { webView.goBackOrForward(lastBackDepthAttempt); } else { mActivity.finish(); } } else { goingBack = false; } } }); } }, 1000); } @Override public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) { super.doUpdateVisitedHistory(view, url, isReload); } }); final FrameLayout outerFrame = new FrameLayout(mActivity); outerFrame.addView(outer); return outerFrame; }
From source file:com.owncloud.android.ui.activity.ExternalSiteWebView.java
@Override protected void onCreate(Bundle savedInstanceState) { Log_OC.v(TAG, "onCreate() start"); Bundle extras = getIntent().getExtras(); String title = extras.getString(EXTRA_TITLE); String url = extras.getString(EXTRA_URL); menuItemId = extras.getInt(EXTRA_MENU_ITEM_ID); showSidebar = extras.getBoolean(EXTRA_SHOW_SIDEBAR); // show progress getWindow().requestFeature(Window.FEATURE_PROGRESS); super.onCreate(savedInstanceState); setContentView(R.layout.externalsite_webview); WebView webview = (WebView) findViewById(R.id.webView); WebSettings webSettings = webview.getSettings(); webview.setFocusable(true);/*w w w. jav a 2 s .c o m*/ webview.setFocusableInTouchMode(true); webview.setClickable(true); // setup toolbar setupToolbar(); // setup drawer setupDrawer(menuItemId); if (!showSidebar) { setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); } getSupportActionBar().setTitle(title); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // enable zoom webSettings.setSupportZoom(true); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); // Non-responsive webs are zoomed out when loaded webSettings.setUseWideViewPort(true); webSettings.setLoadWithOverviewMode(true); // user agent webSettings.setUserAgentString(MainApp.getUserAgent()); // no private data storing webSettings.setSavePassword(false); webSettings.setSaveFormData(false); // disable local file access webSettings.setAllowFileAccess(false); // enable javascript webview.getSettings().setJavaScriptEnabled(true); final Activity activity = this; final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar); webview.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { progressBar.setProgress(progress * 1000); } }); webview.setWebViewClient(new WebViewClient() { public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Toast.makeText(activity, getString(R.string.webview_error) + ": " + description, Toast.LENGTH_SHORT) .show(); } }); webview.loadUrl(url); }
From source file:com.antew.redditinpictures.library.ui.ImageViewerFragment.java
public void initializeWebView() { assert mWebView != null : "WebView should not be null!"; WebSettings settings = mWebView.getSettings(); settings.setSupportZoom(true);//from w w w .j a va 2 s.c o m settings.setBuiltInZoomControls(true); settings.setLoadWithOverviewMode(true); settings.setUseWideViewPort(true); settings.setDisplayZoomControls(false); // Before loading the actual content, let's let the WebView initialize everything. mWebView.loadData("<html></html>", "text/html", "utf-8"); mWebView.setBackgroundColor(Color.BLACK); mWebView.setWebViewClient(new WebViewClient() { /** * Notify the host application that a page has finished loading. This method * is called only for main frame. When onPageFinished() is called, the * rendering picture may not be updated yet. To get the notification for the * new Picture, use {@link android.webkit.WebView.PictureListener#onNewPicture}. * * @param view * The WebView that is initiating the callback. * @param url * The url of the page. */ @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); // We first initialize the webview with mostly blank HTML content, so don't want to show it until we get to the image. if (mWebView != null && mWebViewInitialized) { mWebView.setVisibility(View.VISIBLE); } else if (!mWebViewInitialized) { mWebViewInitialized = true; } } }); mWebView.setOnTouchListener(getWebViewOnTouchListener()); }
From source file:it.rignanese.leo.slimfacebook.MessagesActivity.java
private void SetupMessagesWebView() { webViewMessages = (AdvancedWebView) findViewById(R.id.webViewMessages); webViewMessages.setListener(this, this); webViewMessages.addPermittedHostname("mbasic.facebook.com"); WebSettings settings = webViewMessages.getSettings(); webViewMessages.setDesktopMode(false); webViewMessages.requestFocus(View.FOCUS_DOWN); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);//remove the keyboard issue //set text zoom int zoom = Integer.parseInt(savedPreferences.getString("pref_textSize", "100")); settings.setTextZoom(zoom);//w w w . j a v a 2 s. c om // Use WideViewport and Zoom out if there is no viewport defined settings.setUseWideViewPort(false); settings.setLoadWithOverviewMode(false); // better image sizing support settings.setSupportZoom(false); settings.setDisplayZoomControls(false); settings.setBuiltInZoomControls(false); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { // Hide the zoom controls for HONEYCOMB+ settings.setDisplayZoomControls(false); } }
From source file:it.rignanese.leo.slimtwitter.MainActivity.java
private void setUpWebViewDefaults(WebView webView) { WebSettings settings = webView.getSettings(); // Enable Javascript settings.setJavaScriptEnabled(true); // Use WideViewport and Zoom out if there is no viewport defined settings.setUseWideViewPort(true);// w w w . jav a 2 s. c o m settings.setLoadWithOverviewMode(true); // Enable pinch to zoom without the zoom buttons settings.setBuiltInZoomControls(true); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { // Hide the zoom controls for HONEYCOMB+ settings.setDisplayZoomControls(false); } // Enable remote debugging via chrome://inspect if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } }
From source file:ch.gianulli.flashcards.ui.Flashcard.java
/** * @param view Instance of flashcard.xml *///from w ww . java 2 s .com public Flashcard(View view, OnCardAnsweredListener listener) { mListener = listener; mView = view; mQuestion = (StyledMarkdownView) view.findViewById(R.id.question); mAnswer = (StyledMarkdownView) view.findViewById(R.id.answer); mCardView = (CardView) view.findViewById(R.id.card); mButtonBar = view.findViewById(R.id.button_bar); mCorrectButton = (Button) view.findViewById(R.id.correct_button); mWrongButton = (Button) view.findViewById(R.id.wrong_button); mContext = mView.getContext(); // Load colors int[] attrs = { android.R.attr.textColorSecondary, android.R.attr.textColorPrimary }; TypedArray ta = mView.getContext().obtainStyledAttributes(R.style.AppTheme, attrs); sDeactivatedTextColor = colorToCSSString(ta.getColor(0, 0)); sDefaultTextColor = colorToCSSString(ta.getColor(1, 0)); ta.recycle(); sGreenTextColor = colorToCSSString(ContextCompat.getColor(mContext, R.color.green)); mQuestionColor = sDefaultTextColor; mAnswerColor = sGreenTextColor; // Make question visible mQuestion.setAlpha(1.0f); mAnswer.setAlpha(0.0f); // Setup WebViews WebSettings settings = mQuestion.getSettings(); settings.setDefaultFontSize(mFontSize); settings.setLoadsImagesAutomatically(true); settings.setGeolocationEnabled(false); settings.setAllowFileAccess(false); settings.setDisplayZoomControls(false); settings.setNeedInitialFocus(false); settings.setSupportZoom(false); settings.setSaveFormData(false); settings.setJavaScriptEnabled(true); mQuestion.setHorizontalScrollBarEnabled(false); mQuestion.setVerticalScrollBarEnabled(false); settings = mAnswer.getSettings(); settings.setDefaultFontSize(mFontSize); settings.setLoadsImagesAutomatically(true); settings.setGeolocationEnabled(false); settings.setAllowFileAccess(false); settings.setDisplayZoomControls(false); settings.setNeedInitialFocus(false); settings.setSupportZoom(false); settings.setSaveFormData(false); settings.setJavaScriptEnabled(true); mAnswer.setHorizontalScrollBarEnabled(false); mAnswer.setVerticalScrollBarEnabled(false); // Hack to disable text selection in WebViews mQuestion.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View v) { return true; } }); mAnswer.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View v) { return true; } }); // Card should "turn" on click final FrameLayout questionLayout = (FrameLayout) view.findViewById(R.id.question_layout); questionLayout.setClickable(true); questionLayout.setOnTouchListener(mTurnCardListener); mQuestion.setOnTouchListener(mTurnCardListener); mAnswer.setOnTouchListener(mTurnCardListener); // Deactivate card when user answers it mCorrectButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { deactivateCard(true); mListener.onCardAnswered(mCard, true); } }); mWrongButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { deactivateCard(false); mListener.onCardAnswered(mCard, false); } }); // Limit card width to 400dp ViewTreeObserver observer = mCardView.getViewTreeObserver(); final int width480dp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 400, view.getContext().getResources().getDisplayMetrics()); observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { if (mCardView.getWidth() > width480dp) { ViewGroup.LayoutParams layoutParams = mCardView.getLayoutParams(); layoutParams.width = width480dp; mCardView.setLayoutParams(layoutParams); mCardView.requestLayout(); return false; } return true; } }); }