android.webkit.WebSettings#TextSize ( )源码实例Demo

下面列出了android.webkit.WebSettings#TextSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: BigApp_WordPress_Android   文件: SettingCache.java
public static void putFontSize(Context context, WebSettings.TextSize size) {
    int sizeInt = 2;
    if (size == WebSettings.TextSize.LARGER) {
        sizeInt = 3;
    } else if (size == WebSettings.TextSize.LARGEST) {
        sizeInt = 4;
    } else if (size == WebSettings.TextSize.NORMAL) {
        sizeInt = 2;
    } else if (size == WebSettings.TextSize.SMALLER) {
        sizeInt = 1;
    }
    new SpTool(context, SpTool.SP_SETTING).putInt("font_size", sizeInt);
}
 
源代码2 项目: BigApp_WordPress_Android   文件: SettingCache.java
public static WebSettings.TextSize getFontSize(Context context) {
    int size = new SpTool(context, SpTool.SP_SETTING).getInt("font_size", 2);
    if (size == 3) {
        return WebSettings.TextSize.LARGER;
    } else if (size == 4) {
        return WebSettings.TextSize.LARGEST;
    } else if (size == 2) {
        return WebSettings.TextSize.NORMAL;
    } else if (size == 1) {
        return WebSettings.TextSize.SMALLER;
    }
    return WebSettings.TextSize.NORMAL;
}
 
private void init(Context context, WebSettings.TextSize currentTextSize) {
    View view = LayoutInflater.from(context).inflate(
            R.layout.z_dialog_font_choice, null);
    dialog = new Dialog(context, R.style.Dialog_General);
    dialog.setCancelable(true);
    dialog.setCanceledOnTouchOutside(true);
    dialog.setContentView(view);

    Window window = dialog.getWindow();
    WindowManager.LayoutParams lp = window.getAttributes();
    lp.gravity = Gravity.BOTTOM;
    lp.width = LayoutParams.MATCH_PARENT;
    window.setWindowAnimations(R.style.AnimUpDown);

    view.findViewById(R.id.btn_finish).setOnClickListener(this);
    mTv_normal = view.findViewById(R.id.tv_normal);
    mTv_normal.setOnClickListener(this);
    mTv_small = view.findViewById(R.id.tv_small);
    mTv_small.setOnClickListener(this);
    mTv_large = view.findViewById(R.id.tv_big);
    mTv_large.setOnClickListener(this);
    mTv_largest = view.findViewById(R.id.tv_max);
    mTv_largest.setOnClickListener(this);
    if (currentTextSize == WebSettings.TextSize.SMALLER) {
        mTv_small.setSelected(true);
    } else if (currentTextSize == WebSettings.TextSize.NORMAL) {
        mTv_normal.setSelected(true);
    } else if (currentTextSize == WebSettings.TextSize.LARGER) {
        mTv_large.setSelected(true);
    } else if (currentTextSize == WebSettings.TextSize.LARGEST) {
        mTv_largest.setSelected(true);
    }
}
 
@Override
    public void onViewClick(View v) {
        int vId = v.getId();
        switch (vId) {
            case R.id.iv_right:
                if (dialogFontSizeChoice == null) {
                    dialogFontSizeChoice = new DialogFontSizeChoice(mContext, mWebContent.getSettings().getTextSize(), new DialogFontSizeChoice.OnFontChangedLisener() {
                        @Override
                        public void onFontChanged(WebSettings.TextSize size) {
                            mWebContent.getSettings().setTextSize(size);
                        }
                    });
                }
                dialogFontSizeChoice.show();
                break;
            case R.id.tv_edit:
                if (mTopicNew == null) {
                    return;
                }
                if (mTopicNew.comment_type == 0) {
                    ZToastUtils.toastMessage(mContext.getApplicationContext(), R.string.z_toast_not_allow_commit);
                    return;
                }
                if (BaseApplication.getUserId() == null) {
                    if (mTopicNew.comment_type == 1 || mTopicNew.comment_type == 2) {
                        ActivityUser.gotoFragmentCommitAnony(mContext, mTopicNew.ID, mTopicNew.comment_type);
                        return;
                    }
                    ActivityLogin.gotoFragmentLogin(getActivity());
//                    ZToastUtils.toastMessage(mContext.getApplicationContext(), R.string.z_toast_not_allow_anony_commit);
                    return;
                }
                if (mTopicNew.comment_type == 3) {
                    if (BaseApplication.getUserId().equals("-1")) { //TODO 考虑第三方登录的情况
                        ZToastUtils.toastMessage(mContext.getApplicationContext(), R.string.z_toast_not_allow_3rd_party);
                        return;
                    }
                }
                showDialogReply(v);
                break;
            case R.id.iv_msg:
                if (mTopicNew == null) {
                    return;
                }
                mScrollView.scrollTo(mLl_comment.getLeft(), mLl_comment.getTop());
                break;
            case R.id.iv_collect:
                if (mTopicNew == null) {
                    return;
                }
                if (BaseApplication.getUserId() == null) {
                    //TODO 匿名收藏
                    if (v.isSelected()) {
                        if (new DbTableAnonyCollect(mContext.getContentResolver()).delete(mTopicNew.ID)) {
                            getActivity().setResult(Activity.RESULT_OK);
                            ZToastUtils.toastMessage(mContext.getApplicationContext(), R.string.z_toast_cancel_success);
                            mIv_collect.setSelected(false);
                            return;
                        }
                        ZToastUtils.toastMessage(mContext.getApplicationContext(), R.string.z_toast_cancel_fail);
                    } else {
                        if (new DbTableAnonyCollect(mContext.getContentResolver()).saveOrReplace(mTopicNew)) {
                            getActivity().setResult(Activity.RESULT_OK);
                            ZToastUtils.toastMessage(mContext.getApplicationContext(), R.string.z_toast_collect_add_success);
                            mIv_collect.setSelected(true);
                            return;
                        }
                        ZToastUtils.toastMessage(mContext.getApplicationContext(), R.string.z_toast_collect_add_fail);
                    }
                    return;
                }
                if (v.isSelected()) {
                    sendDelCollectRequest();
                } else {
                    sendAddCollectRequest();
                }
                break;
            case R.id.iv_share:
                showShareDialog();
                break;
            case R.id.tv_end:
                loadCommits(mCurrentPage + 1, false);
                break;
            case R.id.tv_show_orgin:
                //TODO
                if (mTopicNew != null) {
                    ActivityDetails.gotoFragmentDetailsTopic(mContext, mTopicNew);
                }
                break;
        }
    }
 
@Override
public void onViewClick(View v) {
    int vId = v.getId();
    switch (vId) {
        case R.id.item_clear_cache:
            if (mDialogSearching == null) {
                mDialogSearching = new DialogSearching(mContext);
            }
            mDialogSearching.setContent(R.string.v_toast_clean_cache_ing);
            mDialogSearching.show();
            TaskExecutor.execute(new Runnable() {
                @Override
                public void run() {
                    DataManager.clearMyCache(mContext.getApplicationContext());
                    mHandler.sendEmptyMessage(0);
                }
            });
            break;
        case R.id.item_offline_download:
            if (!CommonUtils.checkNetworkEnable(mContext.getApplicationContext())) {
                return;
            }
            if (mContext != null) {
                mContext.startService(new Intent(mContext, ServiceOfflineDownload.class));
            }
            break;
        case R.id.item_about:
            ActivityUserMore.gotoFragmentAbout(getActivity());
            break;
        case R.id.item_font_size:
            if (mDialogFontSizeChoice == null) {
                mDialogFontSizeChoice = new DialogFontSizeChoice(mContext, SettingCache.getFontSize(mContext), new DialogFontSizeChoice.OnFontChangedLisener() {
                    @Override
                    public void onFontChanged(WebSettings.TextSize size) {
                        SettingCache.putFontSize(mContext, size);
                        EventBus.getDefault().post(new WebTxtChangedEvent(size));
                    }
                });
            }
            mDialogFontSizeChoice.show();
            break;
        case R.id.item_img_mode:
            if (mDialogImgMode == null) {
                mDialogImgMode = new DialogImgMode(mContext, new DialogImgMode.OnModeChangedLisener() {
                    @Override
                    public void onModeChanged(int mode) {
                        SettingCache.putImgMode(mContext, mode);
                        setImgMode(mode);
                    }
                });
            }
            mDialogImgMode.show(mImgMode);
            break;
    }
}
 
public DialogFontSizeChoice(Context context, WebSettings.TextSize currentTextSize, OnFontChangedLisener lisener) {
    mLisener = lisener;
    init(context, currentTextSize);
}
 
public WebTxtChangedEvent(WebSettings.TextSize textSize) {
    this.textSize = textSize;
}
 
void onFontChanged(WebSettings.TextSize size);