List of usage examples for android.webkit WebSettings setDefaultFontSize
public abstract void setDefaultFontSize(int size);
From source file:com.pursuer.reader.easyrss.WebpageItemViewCtrl.java
@SuppressLint("SetJavaScriptEnabled") public WebpageItemViewCtrl(final DataMgr dataMgr, final Context context, final String uid, final boolean isMobilized) { super(dataMgr, R.layout.webpage_item, context); this.item = dataMgr.getItemByUid(uid, ITEM_PROJECTION); this.theme = new SettingTheme(dataMgr).getData(); this.fontSize = new SettingFontSize(dataMgr).getData(); // Disable hardware acceleration on Android 3.0-4.1 devices. if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1 && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); }/*from w w w. j av a2 s .c om*/ { mobilizedView = (WebView) view.findViewById(R.id.MobilizedContent); mobilizedView.setBackgroundColor(context.getResources().getColor( theme == SettingTheme.THEME_NORMAL ? R.color.NormalBackground : R.color.DarkBackground)); mobilizedView.setFocusable(false); final WebSettings settings = mobilizedView.getSettings(); settings.setDefaultTextEncodingName(HTTP.UTF_8); settings.setJavaScriptEnabled(false); settings.setDefaultFontSize(fontSize); } { originalView = (WebView) view.findViewById(R.id.OriginalContent); originalView.setFocusable(false); originalView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); final WebSettings settings = originalView.getSettings(); settings.setJavaScriptEnabled(true); settings.setSupportZoom(true); settings.setBuiltInZoomControls(true); originalView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(final WebView webView, final String url) { view.findViewById(R.id.OriginalProgress).setVisibility(View.GONE); } @Override public void onPageStarted(final WebView webView, final String url, final Bitmap favicon) { if (!showMobilized) { view.findViewById(R.id.OriginalProgress).setVisibility(View.VISIBLE); } } @Override public boolean shouldOverrideUrlLoading(final WebView webView, final String url) { webView.loadUrl(url); return false; } }); } if (isMobilized) { showMobilizedPage(); } else { showOriginalPage(); } view.findViewById(R.id.BtnMobilzedPage).setOnClickListener(new OnClickListener() { @Override public void onClick(final View view) { showMobilizedPage(); } }); view.findViewById(R.id.BtnOriginalPage).setOnClickListener(new OnClickListener() { @Override public void onClick(final View view) { showOriginalPage(); } }); view.findViewById(R.id.BtnClose).setOnClickListener(new OnClickListener() { @Override public void onClick(final View view) { if (listener != null) { listener.onBackNeeded(); } } }); }
From source file:ch.gianulli.flashcards.ui.Flashcard.java
/** * Set the font size measured in sp//from ww w . ja v a 2s .co m * * @param fontSize */ public void setFontSize(int fontSize) { mFontSize = Math.min(64, Math.max(6, fontSize)); // Update views WebSettings settings = mQuestion.getSettings(); settings.setDefaultFontSize(mFontSize); settings = mAnswer.getSettings(); settings.setDefaultFontSize(mFontSize); }
From source file:ch.gianulli.flashcards.ui.Flashcard.java
/** * @param view Instance of flashcard.xml *//*from ww w . j a va 2s. c o m*/ 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; } }); }
From source file:com.pursuer.reader.easyrss.VerticalSingleItemView.java
@SuppressLint("SetJavaScriptEnabled") public void loadContent() { final WebSettings settings = webView.getSettings(); settings.setDefaultTextEncodingName(HTTP.UTF_8); settings.setJavaScriptEnabled(true); settings.setDefaultFontSize(fontSize); settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); settings.setRenderPriority(RenderPriority.LOW); final StringBuffer content = new StringBuffer(); if (item.getState().isCached()) { settings.setBlockNetworkImage(true); content.append(DataUtils.readFromFile(new File(item.getFullContentStoragePath()))); } else {/*w w w. j ava2 s. c o m*/ final SettingImageFetching sImgFetch = new SettingImageFetching(dataMgr); if (NetworkUtils.checkImageFetchingNetworkStatus(context, sImgFetch.getData())) { settings.setBlockNetworkImage(false); content.append(DataUtils.readFromFile(new File(item.getOriginalContentStoragePath()))); } else { settings.setBlockNetworkImage(true); content.append(DataUtils.readFromFile(new File(item.getStrippedContentStoragePath()))); } } content.append(DataUtils.DEFAULT_JS); content.append( theme == SettingTheme.THEME_NORMAL ? DataUtils.DEFAULT_NORMAL_CSS : DataUtils.DEFAULT_DARK_CSS); webView.loadDataWithBaseURL("file://" + item.getStoragePath() + "/", content.toString(), null, "utf-8", null); }
From source file:org.freshrss.easyrss.VerticalSingleItemView.java
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" }) public void loadContent() { final WebSettings settings = webView.getSettings(); settings.setDefaultTextEncodingName(HTTP.UTF_8); settings.setJavaScriptEnabled(true); settings.setDefaultFontSize(fontSize); settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //settings.setRenderPriority(RenderPriority.LOW); final StringBuffer content = new StringBuffer(); if (item.getState().isCached()) { content.append(DataUtils.readFromFile(new File(item.getFullContentStoragePath()))); } else {//from w ww .j a v a2s . c o m final SettingImageFetching sImgFetch = new SettingImageFetching(dataMgr); if (NetworkUtils.checkImageFetchingNetworkStatus(context, sImgFetch.getData())) { content.append(DataUtils.readFromFile(new File(item.getOriginalContentStoragePath()))); } else { content.append(DataUtils.readFromFile(new File(item.getStrippedContentStoragePath()))); } } content.append(DataUtils.DEFAULT_JS); content.append( theme == SettingTheme.THEME_NORMAL ? DataUtils.DEFAULT_NORMAL_CSS : DataUtils.DEFAULT_DARK_CSS); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } webView.loadDataWithBaseURL("file://" + item.getStoragePath() + "/", content.toString(), null, "utf-8", null); }
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 ww. j a v a 2 s.co m 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); }