Java Code Examples for android.widget.TextView.setLineSpacing()

The following are Jave code examples for showing how to use setLineSpacing() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ZhaZhaShop   File: ExpandTextView.java   View Source Code Vote up 7 votes
private void init() {
    setOrientation(VERTICAL); //设置垂直布局
    setGravity(Gravity.CENTER); //中间对齐
    //初始化textView并添加
    contentView = new TextView(getContext());
    //添加行距
    contentView.setLineSpacing(1f, 1.3f);
    addView(contentView, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    //初始化ImageView并添加
    expandView = new ImageView(getContext());
    int padding = UIUtils.dp2px(getContext(), 5);
    expandView.setPadding(padding, padding, padding, padding);
    expandView.setImageResource(R.drawable.ic_arrow_down);
    LayoutParams llp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    addView(expandView, llp);
}
 
Example 2
Project: GitHub   File: ListviewTitleLayout.java   View Source Code Vote up 6 votes
static RelativeLayout create(Context context) {
	SizeHelper.prepare(context);

	RelativeLayout root = new RelativeLayout(context);
	ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
			ViewGroup.LayoutParams.MATCH_PARENT);
	root.setLayoutParams(params);

	TextView title = new TextView(context);
	title.setId(ResHelper.getIdRes(context, "tv_title"));
	RelativeLayout.LayoutParams titleParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
			SizeHelper.fromPxWidth(40));
	titleParams.topMargin = SizeHelper.fromPxWidth(-20);
	title.setLayoutParams(titleParams);
	title.setPadding(SizeHelper.fromPxWidth(20), 0, 0, 0);
	title.setLineSpacing(SizeHelper.fromPxWidth(8), 1);
	int resid = ResHelper.getStringRes(context, "smssdk_regist");
	title.setText(resid);
	title.setTextColor(0xff999999);
	title.setTextSize(TypedValue.COMPLEX_UNIT_PX,SizeHelper.fromPxWidth(26));
	title.setGravity(Gravity.CENTER_VERTICAL);
	title.setBackgroundColor(0xffeae8ee);
	root.addView(title);

	return root;
}
 
Example 3
Project: ListItemView   File: ListItemView.java   View Source Code Vote up 6 votes
private void setupTextView(final TextView textView, final int leading, final int step) {
    // This is to make the behavior more deterministic: remove extra top/bottom padding
    textView.setIncludeFontPadding(false);

    // Get font metrics and calculate required inter-line extra
    Paint.FontMetricsInt metrics = textView.getPaint().getFontMetricsInt();
    final int extra = leading - metrics.descent + metrics.ascent;
    textView.setLineSpacing(extra, 1);

    // Determine minimum required top extra so that the view lands on the grid
    final int alignTopExtra = (step + metrics.ascent % step) % step;
    // Determine minimum required bottom extra so that view bounds are aligned with the grid
    final int alignBottomExtra = (step - metrics.descent % step) % step;

    textView.setPadding(textView.getPaddingLeft(), textView.getPaddingTop() + alignTopExtra,
            textView.getPaddingRight(), textView.getPaddingBottom() + alignBottomExtra);
}
 
Example 4
Project: qmui   File: QDPopupFragment.java   View Source Code Vote up 6 votes
private void initNormalPopupIfNeed() {
    if (mNormalPopup == null) {
        mNormalPopup = new QMUIPopup(getContext(), QMUIPopup.DIRECTION_NONE);
        TextView textView = new TextView(getContext());
        textView.setLayoutParams(mNormalPopup.generateLayoutParam(
                QMUIDisplayHelper.dp2px(getContext(), 250),
                WRAP_CONTENT
        ));
        textView.setLineSpacing(QMUIDisplayHelper.dp2px(getContext(), 4), 1.0f);
        int padding = QMUIDisplayHelper.dp2px(getContext(), 20);
        textView.setPadding(padding, padding, padding, padding);
        textView.setText("Popup 可以设置其位置以及显示和隐藏的动画");
        textView.setTextColor(ContextCompat.getColor(getContext(), R.color.app_color_description));
        mNormalPopup.setContentView(textView);
        mNormalPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                mActionButton1.setText(getContext().getResources().getString(R.string.popup_normal_action_button_text_show));
            }
        });
    }
}
 
Example 5
Project: qmui   File: QDDialogFragment.java   View Source Code Vote up 6 votes
@Override
public View onBuildContent(QMUIDialog dialog, ScrollView parent) {
    LinearLayout layout = new LinearLayout(mContext);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setLayoutParams(new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    int padding = QMUIDisplayHelper.dp2px(mContext, 20);
    layout.setPadding(padding, padding, padding, padding);
    mEditText = new EditText(mContext);
    QMUIViewHelper.setBackgroundKeepingPadding(mEditText, QMUIResHelper.getAttrDrawable(mContext, R.attr.qmui_list_item_bg_with_border_bottom));
    mEditText.setHint("输入框");
    LinearLayout.LayoutParams editTextLP = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, QMUIDisplayHelper.dpToPx(50));
    editTextLP.bottomMargin = QMUIDisplayHelper.dp2px(getContext(), 15);
    mEditText.setLayoutParams(editTextLP);
    layout.addView(mEditText);
    TextView textView = new TextView(mContext);
    textView.setLineSpacing(QMUIDisplayHelper.dp2px(getContext(), 4), 1.0f);
    textView.setText("观察聚焦输入框后,键盘升起降下时 dialog 的高度自适应变化。\n\n" +
            "QMUI Android 的设计目的是用于辅助快速搭建一个具备基本设计还原效果的 Android 项目," +
            "同时利用自身提供的丰富控件及兼容处理,让开发者能专注于业务需求而无需耗费精力在基础代码的设计上。" +
            "不管是新项目的创建,或是已有项目的维护,均可使开发效率和项目质量得到大幅度提升。");
    textView.setTextColor(ContextCompat.getColor(getContext(), R.color.app_color_description));
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    layout.addView(textView);
    return layout;
}
 
Example 6
Project: OSchina_resources_android   File: CommonDialog.java   View Source Code Vote up 6 votes
public void setMessage(Spanned spanned) {
    ScrollView scrollView = new ScrollView(getContext());
    scrollView.setLayoutParams(new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.WRAP_CONTENT));
    TextView tvMessage = new TextView(getContext(), null,
            R.style.dialog_pinterest_text);
    tvMessage.setLayoutParams(new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.WRAP_CONTENT));
    tvMessage.setPadding(contentPadding, contentPadding, contentPadding,
            contentPadding);
    tvMessage.setLineSpacing(0.0F, 1.3F);
    tvMessage.setText(spanned);
    tvMessage.setTextColor(getContext().getResources().getColor(
            R.color.black));

    ScrollView.LayoutParams lp = new ScrollView.LayoutParams(
            ScrollView.LayoutParams.MATCH_PARENT,
            ScrollView.LayoutParams.WRAP_CONTENT);
    scrollView.addView(tvMessage, lp);
    setContent(scrollView, 0);
}
 
Example 7
Project: dynamic-toasts   File: AboutDialogFragment.java   View Source Code Vote up 6 votes
@Override
protected @NonNull DynamicDialog onCustomiseDialog(@NonNull DynamicDialog alertDialog,
                                                   @Nullable Bundle savedInstanceState) {
    View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_about,
            new LinearLayout(getContext()), false);
    TextView message = view.findViewById(R.id.dialog_about_text);

    message.setText(Html.fromHtml(getString(R.string.about_content)
            .replace("\n", "<br/>")));
    message.setTextSize(TypedValue.COMPLEX_UNIT_SP, TEXT_SIZE);
    message.setLineSpacing(0f, 1.2f);
    message.setMovementMethod(LinkMovementMethod.getInstance());
    message.setLinkTextColor(ContextCompat.getColor(getContext(), R.color.colorPrimary));

    alertDialog.setView(view);
    return alertDialog;
}
 
Example 8
Project: dynamic-dialogs   File: AboutDialogFragment.java   View Source Code Vote up 6 votes
@Override
protected @NonNull DynamicDialog onCustomiseDialog(@NonNull DynamicDialog alertDialog,
                                                   @Nullable Bundle savedInstanceState) {
    View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_about,
            new LinearLayout(getContext()), false);
    TextView message = view.findViewById(R.id.dialog_about_text);

    message.setText(Html.fromHtml(getString(R.string.about_content)
            .replace("\n", "<br/>")));
    message.setTextSize(TypedValue.COMPLEX_UNIT_SP, TEXT_SIZE);
    message.setLineSpacing(0f, 1.2f);
    message.setMovementMethod(LinkMovementMethod.getInstance());
    message.setLinkTextColor(ContextCompat.getColor(getContext(), R.color.colorPrimary));

    alertDialog.setView(view);
    return alertDialog;
}
 
Example 9
Project: QMUI_Android   File: QDPopupFragment.java   View Source Code Vote up 6 votes
private void initNormalPopupIfNeed() {
    if (mNormalPopup == null) {
        mNormalPopup = new QMUIPopup(getContext(), QMUIPopup.DIRECTION_NONE);
        TextView textView = new TextView(getContext());
        textView.setLayoutParams(mNormalPopup.generateLayoutParam(
                QMUIDisplayHelper.dp2px(getContext(), 250),
                WRAP_CONTENT
        ));
        textView.setLineSpacing(QMUIDisplayHelper.dp2px(getContext(), 4), 1.0f);
        int padding = QMUIDisplayHelper.dp2px(getContext(), 20);
        textView.setPadding(padding, padding, padding, padding);
        textView.setText("Popup 可以设置其位置以及显示和隐藏的动画");
        textView.setTextColor(ContextCompat.getColor(getContext(), R.color.app_color_description));
        mNormalPopup.setContentView(textView);
        mNormalPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                mActionButton1.setText(getContext().getResources().getString(R.string.popup_normal_action_button_text_show));
            }
        });
    }
}
 
Example 10
Project: QMUI_Android   File: QDDialogFragment.java   View Source Code Vote up 6 votes
@Override
public View onBuildContent(QMUIDialog dialog, ScrollView parent) {
    LinearLayout layout = new LinearLayout(mContext);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setLayoutParams(new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    int padding = QMUIDisplayHelper.dp2px(mContext, 20);
    layout.setPadding(padding, padding, padding, padding);
    mEditText = new EditText(mContext);
    QMUIViewHelper.setBackgroundKeepingPadding(mEditText, QMUIResHelper.getAttrDrawable(mContext, R.attr.qmui_list_item_bg_with_border_bottom));
    mEditText.setHint("输入框");
    LinearLayout.LayoutParams editTextLP = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, QMUIDisplayHelper.dpToPx(50));
    editTextLP.bottomMargin = QMUIDisplayHelper.dp2px(getContext(), 15);
    mEditText.setLayoutParams(editTextLP);
    layout.addView(mEditText);
    TextView textView = new TextView(mContext);
    textView.setLineSpacing(QMUIDisplayHelper.dp2px(getContext(), 4), 1.0f);
    textView.setText("观察聚焦输入框后,键盘升起降下时 dialog 的高度自适应变化。\n\n" +
            "QMUI Android 的设计目的是用于辅助快速搭建一个具备基本设计还原效果的 Android 项目," +
            "同时利用自身提供的丰富控件及兼容处理,让开发者能专注于业务需求而无需耗费精力在基础代码的设计上。" +
            "不管是新项目的创建,或是已有项目的维护,均可使开发效率和项目质量得到大幅度提升。");
    textView.setTextColor(ContextCompat.getColor(getContext(), R.color.app_color_description));
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    layout.addView(textView);
    return layout;
}
 
Example 11
Project: qmui   File: QMUIDialog.java   View Source Code Vote up 5 votes
public MessageDialogBuilder(Context context) {
    super(context);
    mTextView = new TextView(mContext);
    mTextView.setTextColor(QMUIResHelper.getAttrColor(mContext, R.attr.qmui_config_color_gray_4));
    mTextView.setLineSpacing(QMUIDisplayHelper.dpToPx(2), 1.0f);
    mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_content_message_text_size));
}
 
Example 12
Project: qmui   File: QMUIDialog.java   View Source Code Vote up 5 votes
public CheckBoxMessageDialogBuilder(Context context) {
    super(context);
    mCheckMarkDrawable = QMUIResHelper.getAttrDrawable(context, R.attr.qmui_s_checkbox);

    mTextView = new TextView(mContext);
    mTextView.setTextColor(QMUIResHelper.getAttrColor(mContext, R.attr.qmui_config_color_gray_4));
    mTextView.setLineSpacing(QMUIDisplayHelper.dpToPx(2), 1.0f);
    mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_content_message_text_size));
}
 
Example 13
Project: qmui   File: QMUIDialogBlockBuilder.java   View Source Code Vote up 5 votes
@Override
protected void onCreateContent(QMUIDialog dialog, ViewGroup parent) {
    TextView contentTv = new TextView(mContext);
    contentTv.setTextColor(QMUIResHelper.getAttrColor(mContext, R.attr.qmui_config_color_gray_4));
    contentTv.setText(mContent);
    contentTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_block_content_text_size));
    contentTv.setLineSpacing(QMUIDisplayHelper.dpToPx(2), 1.0f);
    contentTv.setPadding(
            QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_padding_horizontal),
            QMUIResHelper.getAttrDimen(mContext, hasTitle() ? R.attr.qmui_dialog_content_padding_top : R.attr.qmui_dialog_content_padding_top_when_no_title),
            QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_padding_horizontal),
            QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_content_padding_bottom_when_action_block)
    );
    parent.addView(contentTv);
}
 
Example 14
Project: buildAPKsApps   File: Main.java   View Source Code Vote up 5 votes
public void showAboutDialog()
{
	Dialog dialog = new Dialog(this);
	/*dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
			WindowManager.LayoutParams.FLAG_BLUR_BEHIND);*/
	
	LinearLayout mDialogLayout = new LinearLayout(this);

	TextView mTextView = new TextView(this);
	mTextView.setPadding(20, 0, 20, 20);
	mTextView.setLineSpacing(8, 1);
	mTextView.setText(Html.fromHtml(
			"<p>" +
			"Author: Rémy Böhler<br />" +
			"E-Mail: [email protected]" +
			"</p>" +
			
			"Version: 0.2<br />" +
			"License: GPLv3<br />" + 
			"Source: github.com/rrelmy/BatteryLevel"
	));
	// TODO better way for that?
	// link mail
	Pattern patternMail = Pattern.compile("[email protected]");
	Linkify.addLinks(mTextView, patternMail, "mailto://");
	// link source link
	Pattern patternLink = Pattern.compile("github.com/rrelmy/BatteryLevel");
	Linkify.addLinks(mTextView, patternLink, "https://");
	
	mDialogLayout.addView(mTextView);
	
	dialog.setContentView(mDialogLayout);
	dialog.setTitle("About");
	dialog.show();
}
 
Example 15
Project: QMUI_Android   File: QMUIDialogBlockBuilder.java   View Source Code Vote up 5 votes
@Override
protected void onCreateContent(QMUIDialog dialog, ViewGroup parent) {
    TextView contentTv = new TextView(mContext);
    contentTv.setTextColor(QMUIResHelper.getAttrColor(mContext, R.attr.qmui_config_color_gray_4));
    contentTv.setText(mContent);
    contentTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_block_content_text_size));
    contentTv.setLineSpacing(QMUIDisplayHelper.dpToPx(2), 1.0f);
    contentTv.setPadding(
            QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_padding_horizontal),
            QMUIResHelper.getAttrDimen(mContext, hasTitle() ? R.attr.qmui_dialog_content_padding_top : R.attr.qmui_dialog_content_padding_top_when_no_title),
            QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_padding_horizontal),
            QMUIResHelper.getAttrDimen(mContext, R.attr.qmui_dialog_content_padding_bottom_when_action_block)
    );
    parent.addView(contentTv);
}
 
Example 16
Project: GitHub   File: BackVerifyDialogLayout.java   View Source Code Vote up 4 votes
/**验证返回对话框布局*/
public static LinearLayout create(Context context) {
	SizeHelper.prepare(context);

	LinearLayout root = new LinearLayout(context);
	ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
	root.setLayoutParams(params);
	root.setOrientation(LinearLayout.VERTICAL);

	TextView dialogHint = new TextView(context);
	dialogHint.setId(ResHelper.getIdRes(context, "tv_dialog_hint"));
	LinearLayout.LayoutParams hintParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
			LinearLayout.LayoutParams.WRAP_CONTENT);
	hintParams.topMargin = SizeHelper.fromPxWidth(32);
	hintParams.bottomMargin = SizeHelper.fromPxWidth(32);
	dialogHint.setLayoutParams(hintParams);
	dialogHint.setPadding(SizeHelper.fromPxWidth(18), 0, SizeHelper.fromPxWidth(18), 0);
	dialogHint.setLineSpacing(SizeHelper.fromPxWidth(8), 1);
	int resid = ResHelper.getStringRes(context, "smssdk_make_sure_mobile_detail");
	dialogHint.setText(resid);
	dialogHint.setTextColor(0xffffffff);
	dialogHint.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(26));
	dialogHint.setGravity(Gravity.CENTER);
	root.addView(dialogHint);

	View line = new View(context);
	LinearLayout.LayoutParams lineParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
			SizeHelper.fromPxWidth(1));
	line.setLayoutParams(lineParams);
	line.setBackgroundColor(0xff737373);
	root.addView(line);

	LinearLayout wrapper = new LinearLayout(context);
	LinearLayout.LayoutParams wrapperParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
			LinearLayout.LayoutParams.WRAP_CONTENT);
	wrapper.setLayoutParams(wrapperParams);


	Button ok = new Button(context);
	ok.setId(ResHelper.getIdRes(context, "btn_dialog_ok"));
	LinearLayout.LayoutParams okParams = new LinearLayout.LayoutParams(0,SizeHelper.fromPxWidth(78),1);
	okParams.leftMargin = SizeHelper.fromPxWidth(3);
	ok.setLayoutParams(okParams);
	resid = ResHelper.getBitmapRes(context, "smssdk_dialog_btn_back");
	ok.setBackgroundResource(resid);
	int padding = SizeHelper.fromPxWidth(8);
	ok.setPadding(padding, padding, padding, padding);
	resid = ResHelper.getStringRes(context, "smssdk_ok");
	ok.setText(resid);
	ok.setTextSize(TypedValue.COMPLEX_UNIT_PX,SizeHelper.fromPxWidth(22));
	ok.setTextColor(0xffffffff);
	wrapper.addView(ok);

	View line2 = new View(context);
	LinearLayout.LayoutParams line2Params = new LinearLayout.LayoutParams(SizeHelper.fromPxWidth(1),
			LinearLayout.LayoutParams.MATCH_PARENT);
	line2.setLayoutParams(line2Params);
	line2.setBackgroundColor(0xff737373);
	wrapper.addView(line2);

	Button cancel = new Button(context);
	cancel.setId(ResHelper.getIdRes(context, "btn_dialog_cancel"));
	LinearLayout.LayoutParams cancelParams = new LinearLayout.LayoutParams(0,SizeHelper.fromPxWidth(78),1);
	cancelParams.rightMargin = SizeHelper.fromPxWidth(3);
	cancel.setLayoutParams(cancelParams);
	resid = ResHelper.getBitmapRes(context, "smssdk_dialog_btn_back");
	cancel.setBackgroundResource(resid);
	cancel.setPadding(padding, padding, padding, padding);
	resid = ResHelper.getStringRes(context, "smssdk_cancel");
	cancel.setText(resid);
	cancel.setTextSize(TypedValue.COMPLEX_UNIT_PX,SizeHelper.fromPxWidth(22));
	cancel.setTextColor(0xffffffff);
	wrapper.addView(cancel);

	root.addView(wrapper);
	return root;
}
 
Example 17
Project: PlusGram   File: LoginActivity.java   View Source Code Vote up 4 votes
public LoginActivityResetWaitView(Context context) {
    super(context);

    setOrientation(VERTICAL);

    confirmTextView = new TextView(context);
    confirmTextView.setTextColor(0xff757575);
    confirmTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    confirmTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    confirmTextView.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
    addView(confirmTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));

    TextView resetAccountText = new TextView(context);
    resetAccountText.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    resetAccountText.setTextColor(0xff757575);
    resetAccountText.setText(LocaleController.getString("ResetAccountStatus", R.string.ResetAccountStatus));
    resetAccountText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    resetAccountText.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
    addView(resetAccountText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 0, 24, 0, 0));

    resetAccountTime = new TextView(context);
    resetAccountTime.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    resetAccountTime.setTextColor(0xff757575);
    resetAccountTime.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    resetAccountTime.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
    addView(resetAccountTime, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 0, 2, 0, 0));

    resetAccountButton = new TextView(context);
    resetAccountButton.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    resetAccountButton.setText(LocaleController.getString("ResetAccountButton", R.string.ResetAccountButton));
    resetAccountButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    resetAccountButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    resetAccountButton.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
    resetAccountButton.setPadding(0, AndroidUtilities.dp(14), 0, 0);
    addView(resetAccountButton, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 0, 7, 0, 0));
    resetAccountButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (Math.abs(ConnectionsManager.getInstance().getCurrentTime() - startTime) < waitTime) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setMessage(LocaleController.getString("ResetMyAccountWarningText", R.string.ResetMyAccountWarningText));
            builder.setTitle(LocaleController.getString("ResetMyAccountWarning", R.string.ResetMyAccountWarning));
            builder.setPositiveButton(LocaleController.getString("ResetMyAccountWarningReset", R.string.ResetMyAccountWarningReset), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    needShowProgress();
                    TLRPC.TL_account_deleteAccount req = new TLRPC.TL_account_deleteAccount();
                    req.reason = "Forgot password";
                    ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
                        @Override
                        public void run(TLObject response, final TLRPC.TL_error error) {
                            AndroidUtilities.runOnUIThread(new Runnable() {
                                @Override
                                public void run() {
                                    needHideProgress();
                                    if (error == null) {
                                        Bundle params = new Bundle();
                                        params.putString("phoneFormated", requestPhone);
                                        params.putString("phoneHash", phoneHash);
                                        params.putString("code", phoneCode);
                                        setPage(5, true, params, false);
                                    } else {
                                        if (error.text.equals("2FA_RECENT_CONFIRM")) {
                                            needShowAlert(LocaleController.getString("AppName", R.string.AppName), LocaleController.getString("ResetAccountCancelledAlert", R.string.ResetAccountCancelledAlert));
                                        } else {
                                            needShowAlert(LocaleController.getString("AppName", R.string.AppName), error.text);
                                        }
                                    }
                                }
                            });
                        }
                    }, ConnectionsManager.RequestFlagWithoutLogin | ConnectionsManager.RequestFlagFailOnServerErrors);
                }
            });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            showDialog(builder.create());
        }
    });
}
 
Example 18
Project: UIWidget   File: UIActionSheetView.java   View Source Code Vote up 4 votes
/**
 * 生成条目
 */
private void setSheetItems() {
    if (listSheetItem == null || listSheetItem.size() <= 0) {
        return;
    }
    lLayoutItem.setGravity(STYLE == STYLE_WEI_XIN ? Gravity.LEFT | Gravity.CENTER_VERTICAL : Gravity.CENTER);
    lLayoutItem.removeAllViews();
    // 循环添加条目
    for (int i = 0; i <= listSheetItem.size() - 1; i++) {
        final int item = i;
        SheetItem sheetItem = listSheetItem.get(i);
        final OnSheetItemListener listener = sheetItem.itemClickListener;
        View view = new View(context);

        TextView textView = new TextView(context);
        textView.setText(sheetItem.name);
        textView.setTextSize(unitItems, textSizeItems);
        textView.setGravity(STYLE == STYLE_WEI_XIN ? Gravity.LEFT | Gravity.CENTER_VERTICAL : Gravity.CENTER);
        textView.setPadding(dip2px(mPaddingLeft), dip2px(mPaddingTop), dip2px(mPaddingLeft), dip2px(mPaddingTop));
        vLineTitle.setVisibility(showTitle && STYLE == STYLE_NORMAL ? View.VISIBLE : View.GONE);
        // 背景图片
        if (STYLE == STYLE_IOS) {
            if (listSheetItem.size() == 1) {
                if (showTitle) {
                    textView.setBackgroundResource(R.drawable.action_sheet_bottom);
                } else {
                    textView.setBackgroundResource(R.drawable.action_sheet_single);
                }
            } else {
                if (showTitle) {
                    if (i >= 0 && i < listSheetItem.size() - 1) {
                        textView.setBackgroundResource(R.drawable.action_sheet_middle);
                    } else {
                        textView.setBackgroundResource(R.drawable.action_sheet_bottom);
                    }
                } else {
                    if (i == 0) {
                        textView.setBackgroundResource(R.drawable.action_sheet_top);
                    } else if (i < listSheetItem.size() - 1) {
                        textView.setBackgroundResource(R.drawable.action_sheet_middle);
                    } else {
                        textView.setBackgroundResource(R.drawable.action_sheet_bottom);
                    }
                }
            }
        } else {
            textView.setBackgroundResource(R.drawable.action_sheet_edge);
            tvCancel.setBackgroundResource(R.drawable.action_sheet_edge);
            tvTitle.setBackgroundResource(R.color.colorActionSheetEdge);
            view.setBackgroundResource(R.color.colorActionSheetEdgeLineGray);
        }
        // 字体颜色
        textView.setTextColor(sheetItem.color);
        LinearLayout.LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        // 高度
        textView.setLayoutParams(params);
        textView.setMinimumHeight(getItemHeight());
        tvTitle.setMinimumHeight(STYLE != STYLE_IOS ? getItemHeight() : dip2px(20));
        textView.setLineSpacing(mLineSpacingExtra, mLineSpacingMultiplier);
        // 点击事件
        textView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick(item);
                }
                dialog.dismiss();
            }
        });
        lLayoutItem.addView(textView);
        if (STYLE == STYLE_NORMAL) {
            view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, (int) context.getResources().getDimension(R.dimen.dp_line_size)));
            lLayoutItem.addView(view);
        }
    }
}