下面列出了android.widget.TextView#setLineSpacing ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public AttachButton(Context context) {
super(context);
setWillNotDraw(false);
imageView = new RLottieImageView(context) {
@Override
public void setScaleX(float scaleX) {
super.setScaleX(scaleX);
AttachButton.this.invalidate();
}
};
imageView.setScaleType(ImageView.ScaleType.CENTER);
addView(imageView, LayoutHelper.createFrame(32, 32, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 18, 0, 0));
textView = new TextView(context);
textView.setMaxLines(2);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
textView.setEllipsize(TextUtils.TruncateAt.END);
textView.setTextColor(Theme.getColor(Theme.key_dialogTextGray2));
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
textView.setLineSpacing(-AndroidUtilities.dp(2), 1.0f);
addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 62, 0, 0));
}
protected void updateChildTextView(ViewGroup viewGroup) {
if (viewGroup == null || viewGroup.getChildCount() == 0) return;
for (int i = 0; i < viewGroup.getChildCount(); i++) {
View view = viewGroup.getChildAt(i);
if (view instanceof TextView) {
TextView textView = (TextView) view;
textView.setTextColor(titleColor);
textView.setTypeface(TypefaceHelper.get(context, titleFont));
textView.setLineSpacing(0, 1.1f);
textView.setIncludeFontPadding(false);
}
if (view instanceof ViewGroup) updateChildTextView((ViewGroup) view);
}
}
/**
* Setting up the top TextView and bottom TextVew
* @param context
* @param isCenterView true if the element is the centered view in the ScrollLayout
* @param topTextSize text size of the top TextView in dps
* @param bottomTextSize text size of the bottom TextView in dps
* @param lineHeight LineHeight of the top TextView
*/
protected void setupView(Context context, boolean isCenterView, int topTextSize, int bottomTextSize, float lineHeight) {
setOrientation(VERTICAL);
topView = new TextView(context);
topView.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM);
topView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, topTextSize);
bottomView = new TextView(context);
bottomView.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.TOP);
bottomView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, bottomTextSize);
topView.setLineSpacing(0, lineHeight);
if (isCenterView) {
isCenter = true;
topView.setTypeface(Typeface.DEFAULT_BOLD);
topView.setTextColor(0xFF333333);
bottomView.setTypeface(Typeface.DEFAULT_BOLD);
bottomView.setTextColor(0xFF444444);
topView.setPadding(0, 5-(int)(topTextSize/15.0), 0, 0);
} else {
topView.setPadding(0, 5, 0, 0);
topView.setTextColor(0xFF666666);
bottomView.setTextColor(0xFF666666);
}
addView(topView);addView(bottomView);
}
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);
}
public AttachButton(Context context) {
super(context);
setWillNotDraw(false);
imageView = new RLottieImageView(context) {
@Override
public void setScaleX(float scaleX) {
super.setScaleX(scaleX);
AttachButton.this.invalidate();
}
};
imageView.setScaleType(ImageView.ScaleType.CENTER);
addView(imageView, LayoutHelper.createFrame(32, 32, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 18, 0, 0));
textView = new TextView(context);
textView.setMaxLines(2);
textView.setGravity(Gravity.CENTER_HORIZONTAL);
textView.setEllipsize(TextUtils.TruncateAt.END);
textView.setTextColor(Theme.getColor(Theme.key_dialogTextGray2));
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
textView.setLineSpacing(-AndroidUtilities.dp(2), 1.0f);
addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 62, 0, 0));
}
/**
* 生成文本输入框
*/
private TextView createTextView(String hint, int paddingTop) {
TextView textView = new TextView(getContext());
LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
textView.setLayoutParams(layoutParams);
textView.setTextSize(16);
textView.setTextColor(Color.parseColor("#616161"));
textView.setTextIsSelectable(true);
textView.setBackground(null);
textView.setTag(viewTagIndex++);
textView.setPadding(editNormalPadding, paddingTop, editNormalPadding, paddingTop);
textView.setHint(hint);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, rtTextSize);
textView.setLineSpacing(rtTextLineSpace, 1.0f);
textView.setTextColor(rtTextColor);
return textView;
}
public void into(TextView target) {
if (this.target == null) {
this.target = new WeakReference<>(target);
}
if (imageGetter == null) {
WindowManager wm = (WindowManager) target.getContext()
.getSystemService(Context.WINDOW_SERVICE);
Point p = new Point();
wm.getDefaultDisplay().getSize(p);
VIEW_WIDTH = p.x - target.getPaddingStart() - target.getPaddingEnd();
imageGetter = new DefaultImageGetter(target.getContext(), VIEW_WIDTH);
}
if (clickListener == null) {
clickListener = new DefaultClickHandler(target.getContext());
}
FONT_SIZE = target.getTextSize();
spanned = SpanConverter.convert(source, imageGetter, clickListener, this);
target.setMovementMethod(LinkMovementMethod.getInstance());
target.setLinkTextColor(URL_COLOR);
target.setLineSpacing(0, LINE_HEIGHT);
target.setText(spanned);
isViewSet = true;
}
public static void setLineSpacing(TextView textView) {
float lineSpacingExtra = 2;
float lineSpacingMultiplier = 1.1f;
if (HiSettingsHelper.getInstance().getPostLineSpacing() == 1) {
lineSpacingExtra = 4;
lineSpacingMultiplier = 1.2f;
} else if (HiSettingsHelper.getInstance().getPostLineSpacing() == 2) {
lineSpacingExtra = 6;
lineSpacingMultiplier = 1.3f;
} else if (HiSettingsHelper.getInstance().getPostLineSpacing() == 3) {
lineSpacingExtra = 8;
lineSpacingMultiplier = 1.4f;
}
textView.setLineSpacing(lineSpacingExtra, lineSpacingMultiplier);
}
/**
* add text view type of tab
* <p/>
* you can set the text view attribute in here
*
* @param position position
* @param title title
*/
private void addTextTab(final int position, String title) {
TextView tab = new TextView(getContext());
tab.setText(title);
tab.setGravity(Gravity.CENTER);
// You can set the text view single line
// tab.setSingleLine();
tab.setLineSpacing(5, 1.0f);
addTab(position, tab);
}
public DialogsEmptyCell(Context context) {
super(context);
setGravity(Gravity.CENTER);
setOrientation(VERTICAL);
setOnTouchListener((v, event) -> true);
imageView = new RLottieImageView(context);
imageView.setScaleType(ImageView.ScaleType.CENTER);
addView(imageView, LayoutHelper.createFrame(100, 100, Gravity.CENTER, 52, 4, 52, 0));
imageView.setOnClickListener(v -> {
if (!imageView.isPlaying()) {
imageView.setProgress(0.0f);
imageView.playAnimation();
}
});
emptyTextView1 = new TextView(context);
emptyTextView1.setTextColor(Theme.getColor(Theme.key_chats_nameMessage_threeLines));
emptyTextView1.setText(LocaleController.getString("NoChats", R.string.NoChats));
emptyTextView1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
emptyTextView1.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
emptyTextView1.setGravity(Gravity.CENTER);
addView(emptyTextView1, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 52, 10, 52, 0));
emptyTextView2 = new TextView(context);
String help = LocaleController.getString("NoChatsHelp", R.string.NoChatsHelp);
if (AndroidUtilities.isTablet() && !AndroidUtilities.isSmallTablet()) {
help = help.replace('\n', ' ');
}
emptyTextView2.setText(help);
emptyTextView2.setTextColor(Theme.getColor(Theme.key_chats_message));
emptyTextView2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
emptyTextView2.setGravity(Gravity.CENTER);
emptyTextView2.setLineSpacing(AndroidUtilities.dp(2), 1);
addView(emptyTextView2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 52, 7, 52, 0));
}
/**
* 创建Title
*/
private void createTitle() {
if (TextUtils.isEmpty(mTitleStr)) {
return;
}
mTvTitle = new TextView(mContext);
mTvTitle.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
mTvTitle.setMinimumHeight(dp2px(20));
mTvTitle.setId(R.id.tv_titleActionSheetDialog);
mLLayoutRoot.addView(mTvTitle);
Drawable background = mStateDrawableSingle;
mTvTitle.setLineSpacing(mLineSpacingExtra, mLineSpacingMultiplier);
mTvTitle.setGravity(mTitleGravity);
mTvTitle.setPadding(mItemsTextPaddingLeft, mItemsTextPaddingTop, mItemsTextPaddingRight, mItemsTextPaddingBottom);
mTvTitle.setCompoundDrawablePadding(mTextDrawablePadding);
mTvTitle.setText(mTitleStr);
mTvTitle.setTextSize(mTextSizeUnit, mTitleTextSize);
mTvTitle.setTextColor(mTitleTextColor);
boolean hasList = mListItem != null && mListItem.size() > 0;
boolean hasCancel = !TextUtils.isEmpty(mCancelStr) && mCancelMarginTop <= 0;
if (hasList || hasCancel) {
background = mStateDrawableTop.getCurrent();
}
setViewBackground(mTvTitle, DrawableUtil.getNewDrawable(background));
setTextViewLine(mTvTitle);
}
/**
* 创建取消按钮
*/
private void createCancel() {
if (TextUtils.isEmpty(mCancelStr)) {
return;
}
mTvCancel = new TextView(mContext);
mTvCancel.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
mTvCancel.setMinimumHeight(mItemsMinHeight);
mTvCancel.setId(R.id.tv_cancelActionSheetDialog);
mLLayoutRoot.addView(mTvCancel);
mTvCancel.setLineSpacing(mLineSpacingExtra, mLineSpacingMultiplier);
mTvCancel.setGravity(mCancelGravity);
mTvCancel.setCompoundDrawablePadding(mTextDrawablePadding);
mTvCancel.setPadding(mItemsTextPaddingLeft, mItemsTextPaddingTop, mItemsTextPaddingRight, mItemsTextPaddingBottom);
mTvCancel.setText(mCancelStr);
mTvCancel.setTextSize(mTextSizeUnit, mCancelTextSize);
mTvCancel.setTextColor(mCancelTextColor);
if (mCancelMarginTop > 0) {
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mTvCancel.getLayoutParams();
if (lp != null) {
lp.topMargin = mCancelMarginTop;
mTvCancel.setLayoutParams(lp);
}
}
boolean single = mCancelMarginTop > 0 || TextUtils.isEmpty(mTitleStr) && mViewItem == null || mBottomDrawable == null;
setViewBackground(mTvCancel, DrawableUtil.getNewDrawable(single ? mStateDrawableSingle : mStateDrawableBottom));
mTvCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mDialog.dismiss();
}
});
setTextViewLine(mTvCancel);
}
@Override
protected void initView(Bundle bundle) {
int padding = getResources().getDimensionPixelSize(R.dimen.dp_margin);
mTextView = new TextView(mContext);
mTextView.setTextColor(ContextCompat.getColor(mContext, R.color.colorTextBlack));
mTextView.setPadding(padding, padding, padding, padding);
mTextView.setLineSpacing(1.5f, 1f);
mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize(R.dimen.dp_text_size_main));
mTextView.setBackgroundColor(Color.WHITE);
mAdapter.addHeaderView(mTextView);
mTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StatusBarUtil.setFullScreen(mContext, !mIsFull);
mIsFull = !mIsFull;
}
});
List<WidgetEntity> list = new ArrayList<>();
list.add(new WidgetEntity("TabLayout", "快速创建Tab控件包括CommonTabLayout、SlidingTabLayout及SegmentTabLayout三种类型Tab", SimpleTabActivity.class));
list.add(new WidgetEntity("StatusViewHelper", "支持顶部自定义标题栏沉浸效果帮助类。", StatusViewHelperActivity.class));
list.add(new WidgetEntity("KeyboardHelper", "解决软键盘遮住底部输入框问题帮助类。", TitleEditActivity.class));
list.add(new WidgetEntity("TitleBarView", "一款支持沉浸状态栏效果设置的ToolBar控件:支持xml设置是否沉浸、主标题及副标题、左边文字及icon、右边文字及icon、下划线;支持添加左边、中间及右边view方便扩展。", TitleActivity.class));
list.add(new WidgetEntity("RadiusView", "一款扩展原生TextView、EditText、LinearLayout、FrameLayout、RelativeLayout控件库:主要实现xml设置圆角、手指按下、不可操作样式-减少drawable文件创建;同时支持5.0以上水波纹效果设置。", RadiusActivity.class));
list.add(new WidgetEntity("UIAlertDialog", "一款自定义Alert效果控件:属性命名及调用方式同Android原生AlertDialog,增加样式背景及文本相关属性自定义自定义。", AlertActivity.class));
list.add(new WidgetEntity("UIActionSheetDialog", "一款底部弹框控件:支持List模式(iOS、微信及QQ样式)和Grid模式", ActionSheetActivity.class));
list.add(new WidgetEntity("UIProgressDialog", "一款仿微博、微信、MD loading控件:扩展背景及loading 样式设置。", LoadingActivity.class));
mAdapter.setNewData(list);
mAdapter.loadMoreEnd();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// titleBar.setLeftTextDrawable(0);
}
}, 5000);
}
@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);//内边距20dp
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(mActivity, 15);
mEditText.setLayoutParams(editTextLP);
layout.addView(mEditText);
TextView textView = new TextView(mContext);
textView.setLineSpacing(QMUIDisplayHelper.dp2px(mActivity, 4), 1.0f);
textView.setText("观察聚焦输入框后,键盘升起降下时 dialog 的高度自适应变化。\n\n" +
"QMUI Android 的设计目的是用于辅助快速搭建一个具备基本设计还原效果的 Android 项目," +
"同时利用自身提供的丰富控件及兼容处理,让开发者能专注于业务需求而无需耗费精力在基础代码的设计上。" +
"不管是新项目的创建,或是已有项目的维护,均可使开发效率和项目质量得到大幅度提升。");
textView.setTextColor(ContextCompat.getColor(mActivity, R.color.app_color_description));
textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
layout.addView(textView);
return layout;
}
/** Creates a text-view with a little bit of formatting. */
private static TextView createMessageText(Context context, int textResourceId) {
TextView message = new TextView(context);
message.setText(textResourceId);
LinearLayout.LayoutParams params =
new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
final int margin = 20;
params.setMargins(margin, margin, margin, margin);
message.setLayoutParams(params);
message.setLineSpacing(0.0f, 1.25f);
return message;
}
/**
* 创建自定义 Toast View
*
* @param message 文本消息
* @return View
*/
private static View createTextToastView(String message) {
// 画圆角矩形背景
float rc = dp2px(6);
RoundRectShape shape = new RoundRectShape(new float[]{rc, rc, rc, rc, rc, rc, rc, rc}, null, null);
ShapeDrawable drawable = new ShapeDrawable(shape);
drawable.getPaint().setColor(Color.argb(225, 240, 240, 240));
drawable.getPaint().setStyle(Paint.Style.FILL);
drawable.getPaint().setAntiAlias(true);
drawable.getPaint().setFlags(Paint.ANTI_ALIAS_FLAG);
// 创建View
FrameLayout layout = new FrameLayout(Utils.getContext());
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layout.setLayoutParams(layoutParams);
layout.setPadding(dp2px(16), dp2px(12), dp2px(16), dp2px(12));
layout.setBackground(drawable);
TextView textView = new TextView(Utils.getContext());
textView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT));
textView.setTextSize(15);
textView.setText(message);
textView.setLineSpacing(dp2px(4), 1f);
textView.setTextColor(Color.BLACK);
layout.addView(textView);
return layout;
}
public LoginActivityRecoverView(Context context)
{
super(context);
setOrientation(VERTICAL);
confirmTextView = new TextView(context);
confirmTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
confirmTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
confirmTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
confirmTextView.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
confirmTextView.setText(LocaleController.getString("RestoreEmailSentInfo", R.string.RestoreEmailSentInfo));
addView(confirmTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT)));
codeField = new EditTextBoldCursor(context);
codeField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
codeField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
codeField.setCursorSize(AndroidUtilities.dp(20));
codeField.setCursorWidth(1.5f);
codeField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
codeField.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
codeField.setHint(LocaleController.getString("PasswordCode", R.string.PasswordCode));
codeField.setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
codeField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
codeField.setMaxLines(1);
codeField.setPadding(0, 0, 0, 0);
codeField.setInputType(InputType.TYPE_CLASS_PHONE);
codeField.setTransformationMethod(PasswordTransformationMethod.getInstance());
codeField.setTypeface(Typeface.DEFAULT);
codeField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
addView(codeField, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, Gravity.CENTER_HORIZONTAL, 0, 20, 0, 0));
codeField.setOnEditorActionListener((textView, i, keyEvent) ->
{
if (i == EditorInfo.IME_ACTION_NEXT)
{
onNextPressed();
return true;
}
return false;
});
cancelButton = new TextView(context);
cancelButton.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM);
cancelButton.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4));
cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
cancelButton.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
cancelButton.setPadding(0, AndroidUtilities.dp(14), 0, 0);
addView(cancelButton, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 0, 0, 0, 14));
cancelButton.setOnClickListener(view ->
{
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("RestoreEmailTroubleText", R.string.RestoreEmailTroubleText));
builder.setTitle(LocaleController.getString("RestorePasswordNoEmailTitle", R.string.RestorePasswordNoEmailTitle));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> setPage(6, true, new Bundle(), true));
Dialog dialog = showDialog(builder.create());
if (dialog != null)
{
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
}
});
}
public LoginActivityResetWaitView(Context context)
{
super(context);
setOrientation(VERTICAL);
confirmTextView = new TextView(context);
confirmTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
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));
resetAccountText = new TextView(context);
resetAccountText.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
resetAccountText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
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(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
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(view ->
{
if (Math.abs(ConnectionsManager.getInstance(currentAccount).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), (dialogInterface, i) ->
{
needShowProgress(0);
TLRPC.TL_account_deleteAccount req = new TLRPC.TL_account_deleteAccount();
req.reason = "Forgot password";
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() ->
{
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());
});
}
public LoginActivityRecoverView(Context context)
{
super(context);
setOrientation(VERTICAL);
confirmTextView = new TextView(context);
confirmTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
confirmTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
confirmTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
confirmTextView.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
confirmTextView.setText(LocaleController.getString("RestoreEmailSentInfo", R.string.RestoreEmailSentInfo));
addView(confirmTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT)));
codeField = new EditTextBoldCursor(context);
codeField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
codeField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
codeField.setCursorSize(AndroidUtilities.dp(20));
codeField.setCursorWidth(1.5f);
codeField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
codeField.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
codeField.setHint(LocaleController.getString("PasswordCode", R.string.PasswordCode));
codeField.setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
codeField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
codeField.setMaxLines(1);
codeField.setPadding(0, 0, 0, 0);
codeField.setInputType(InputType.TYPE_CLASS_PHONE);
codeField.setTransformationMethod(PasswordTransformationMethod.getInstance());
codeField.setTypeface(Typeface.DEFAULT);
codeField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
addView(codeField, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, Gravity.CENTER_HORIZONTAL, 0, 20, 0, 0));
codeField.setOnEditorActionListener((textView, i, keyEvent) ->
{
if (i == EditorInfo.IME_ACTION_NEXT)
{
onNextPressed();
return true;
}
return false;
});
cancelButton = new TextView(context);
cancelButton.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM);
cancelButton.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4));
cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
cancelButton.setLineSpacing(AndroidUtilities.dp(2), 1.0f);
cancelButton.setPadding(0, AndroidUtilities.dp(14), 0, 0);
addView(cancelButton, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), 0, 0, 0, 14));
cancelButton.setOnClickListener(view ->
{
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
builder.setMessage(LocaleController.getString("RestoreEmailTroubleText", R.string.RestoreEmailTroubleText));
builder.setTitle(LocaleController.getString("RestorePasswordNoEmailTitle", R.string.RestorePasswordNoEmailTitle));
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> setPage(6, true, new Bundle(), true));
Dialog dialog = showDialog(builder.create());
if (dialog != null)
{
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
}
});
}
/**
* add text view type of tab
* <p/>
* you can set the text view attribute in here
*
* @param position position
* @param title title
* @param start start
* @param top top
* @param end end
* @param bottom bottom
*/
private void addTextTab(final int position, SpannableString title, int start, int top, int end, int bottom) {
TextView tab = new TextView(getContext());
tab.setText(title);
tab.setGravity(Gravity.CENTER);
// You can set the text view single line
// tab.setSingleLine();
tab.setCompoundDrawablesWithIntrinsicBounds(start, top, end, bottom);
tab.setLineSpacing(8, 1.0f);
addTab(position, tab);
}