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

The following are Jave code examples for showing how to use setGravity() 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: Bailan   File: SubTabNavigator.java   View Source Code Vote up 7 votes
private void addTextView(Context context, int viewTag) {
    TextView tv = (TextView) View.inflate(context, R.layout.custom_textview, null);
    LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    layoutParams.weight = 1.0F;

    tv.setLayoutParams(layoutParams);
    tv.setOnClickListener(this);
    tv.setGravity(Gravity.CENTER);
    if (mTextSize > 0f)
        tv.setTextSize(0, mTextSize);

    tv.setOnClickListener(this);
    tv.setTag(viewTag);
    if (viewTag == TAG_LEFT_VIEW) {
        tv.setText(mLeftText);
        mLeftTextView = tv;
    } else if (viewTag == TAG_NONE_VIEW) {
        tv.setText(mSimpleText);
        mSimpleTextView = tv;
    } else if (viewTag == TAG_RIGHT_VIEW) {
        tv.setText(mRightText);
        mRightTextView = tv;
    }
    addView(tv);
}
 
Example 2
Project: boohee_v5.6   File: UMQQSsoHandler.java   View Source Code Vote up 6 votes
private void showDialog() {
    Builder builder = new Builder(this.mContext);
    TextView title = new TextView(this.mContext);
    title.setText("分享失败原因");
    title.setPadding(0, 20, 0, 20);
    title.setTextColor(-1);
    title.setGravity(17);
    title.setTextSize(16.0f);
    builder.setCustomTitle(title);
    TextView textView = new TextView(this.mContext);
    textView.setText("请添加QQ平台到SDK \n添加方式:\nUMQQSsoHandler qqSsoHandler = new UMQQSsoHandler" +
            "(getActivity(), \"你的APP ID\",\"你的APP KEY\");\nqqSsoHandler.addToSocialSDK(); " +
            "\n参考文档:\nhttp://dev.umeng" +
            ".com/social/android/share/quick-integration#social_qq_sso");
    textView.setTextColor(-1);
    textView.setTextSize(16.0f);
    textView.setAutoLinkMask(1);
    builder.setView(textView);
    builder.show().show();
}
 
Example 3
Project: chromium-for-android-56-debug-video   File: SavePasswordsPreferences.java   View Source Code Vote up 6 votes
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (PasswordUIView.shouldUseSmartLockBranding()) {
        getActivity().setTitle(R.string.prefs_smart_lock_for_passwords);
    } else {
        getActivity().setTitle(R.string.prefs_saved_passwords);
    }
    setPreferenceScreen(getPreferenceManager().createPreferenceScreen(getActivity()));
    mPasswordManagerHandler.addObserver(this);

    mEmptyView = new TextView(getActivity(), null);
    mEmptyView.setText(R.string.saved_passwords_none_text);
    mEmptyView.setGravity(Gravity.CENTER);
    mEmptyView.setVisibility(View.GONE);
}
 
Example 4
Project: GongXianSheng   File: CustomBottomDialog.java   View Source Code Vote up 6 votes
private View addItemView(int rid, String text) {
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setId(rid);
    linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, DensityUtil.dip2px(context, 44f)));
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setBackgroundResource(R.drawable.base_item_bg_selector);
    linearLayout.setOnClickListener(this);
    TextView textView = new TextView(context);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1));
    textView.setText(text);
    textView.setTextColor(context.getResources().getColor(R.color.bottom_dialog_textcolor));
    textView.setTextSize(16f);
    textView.setGravity(Gravity.CENTER);
    linearLayout.removeAllViews();
    linearLayout.addView(textView);
    return  linearLayout;
}
 
Example 5
Project: airgram   File: EmptyTextProgressView.java   View Source Code Vote up 6 votes
public EmptyTextProgressView(Context context) {
    super(context);

    progressBar = new ProgressBar(context);
    progressBar.setVisibility(INVISIBLE);
    addView(progressBar, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));

    textView = new TextView(context);
    textView.setTypeface(FontManager.instance().getTypeface());
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    textView.setTextColor(0xff808080);
    textView.setGravity(Gravity.CENTER);
    textView.setVisibility(INVISIBLE);
    textView.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0);
    textView.setText(LocaleController.getString("NoResult", R.string.NoResult));
    addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));

    setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
}
 
Example 6
Project: airgram   File: PhotoPickerSearchCell.java   View Source Code Vote up 6 votes
public SearchButton(Context context) {
    super(context);

    setBackgroundColor(0xff1a1a1a);

    selector = new View(context);
    selector.setBackgroundResource(R.drawable.list_selector);
    addView(selector, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    imageView = new ImageView(context);
    imageView.setScaleType(ImageView.ScaleType.CENTER);
    addView(imageView, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));

    textView1 = new TextView(context);
    textView1.setTypeface(FontManager.instance().getTypeface());
    textView1.setGravity(Gravity.CENTER_VERTICAL);
    textView1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    textView1.setTypeface(FontManager.instance().getTypeface());
    textView1.setTextColor(0xffffffff);
    textView1.setSingleLine(true);
    textView1.setEllipsize(TextUtils.TruncateAt.END);
    addView(textView1, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 51, 8, 4, 0));

    textView2 = new TextView(context);
    textView2.setTypeface(FontManager.instance().getTypeface());
    textView2.setGravity(Gravity.CENTER_VERTICAL);
    textView2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
    textView2.setTypeface(FontManager.instance().getTypeface());
    textView2.setTextColor(0xff666666);
    textView2.setSingleLine(true);
    textView2.setEllipsize(TextUtils.TruncateAt.END);
    addView(textView2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 51, 26, 4, 0));
}
 
Example 7
Project: planetcon   File: DialogPreferenceSeekBar.java   View Source Code Vote up 6 votes
@Override
protected View onCreateDialogView() {
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);

    // Layout returned as dialog view
    LinearLayout layout = new LinearLayout(mContext);
    layout.setOrientation(LinearLayout.VERTICAL);

    // Add text view to show the current value
    mViewValue = new TextView(mContext);
    mViewValue.setGravity(Gravity.CENTER_HORIZONTAL);
    mViewValue.setText(String.valueOf(mValue));
    layout.addView(mViewValue, params);

    // Add seek bar
    mSeekBar = new SeekBar(mContext);
    mSeekBar.setMax(mMax);
    mSeekBar.setProgress(mValue);
    // Set progress before change listener
    mSeekBar.setOnSeekBarChangeListener(this);
    layout.addView(mSeekBar, params);

    return layout;
}
 
Example 8
Project: Multi-SwipeToRefreshLayout   File: IndicatorsRefreshHeader.java   View Source Code Vote up 6 votes
private void init(Context context) {
    if (isInEditMode()) return;
    mIndicatorView = new AVLoadingIndicatorView(context);
    mIndicatorView.setIndicatorId(AVLoadingIndicatorView.Pacman);
    mIndicatorView.setIndicatorColor(Color.WHITE);
    mIndicatorView.setId(R.id.left);
    RelativeLayout.LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.addRule(CENTER_IN_PARENT);
    addView(mIndicatorView, layoutParams);

    mText = new TextView(context);
    mText.setEms(6);
    mText.setGravity(Gravity.CENTER);
    RelativeLayout.LayoutParams textLayoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    textLayoutParams.addRule(CENTER_IN_PARENT);
    textLayoutParams.addRule(BELOW, mIndicatorView.getId());
    addView(mText, textLayoutParams);
}
 
Example 9
Project: EsperantoRadio   File: PagerSlidingTabStrip.java   View Source Code Vote up 6 votes
private void addIconTabBådeTekstOgBillede(final int position, int resId, String url, String title) {
  FrameLayout tabfl = new FrameLayout(getContext());
  ImageView tabi = new ImageView(getContext());
  tabi.setContentDescription(title);
  //Log.d(title+" "+resId + " Kanallogo URL="+url);
  if (resId==0) {
    Picasso.with(tabi.getContext())
            .load(url).placeholder(null)
            .into(tabi);

    tabi.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    tabi.setAdjustViewBounds(true);
    tabi.setVisibility(View.GONE);
  } else {
    tabi.setImageResource(resId);
    tabi.setVisibility(View.INVISIBLE);
  }
  TextView tabt = new TextView(getContext());
  tabt.setText(title);
  tabt.setTypeface(App.skrift_gibson);
  tabt.setGravity(Gravity.CENTER);
  tabt.setSingleLine();

  tabfl.addView(tabi);
  tabfl.addView(tabt);

  LayoutParams lp = (LayoutParams) tabi.getLayoutParams();
  lp.gravity=Gravity.CENTER;
  lp.width=lp.height=ViewGroup.LayoutParams.MATCH_PARENT;
  lp = (LayoutParams) tabt.getLayoutParams();
  lp.width=lp.height=ViewGroup.LayoutParams.MATCH_PARENT;
  lp.gravity=Gravity.CENTER;

  addTab(position, tabfl);
}
 
Example 10
Project: MenuSet   File: Utils.java   View Source Code Vote up 5 votes
public static TextView getItemTextView(Context context, MenuObject menuItem, int menuItemSize,
                                       View.OnClickListener onCLick, View.OnLongClickListener onLongClick) {
    TextView itemTextView = new TextView(context);
    RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, menuItemSize);
    itemTextView.setLayoutParams(textLayoutParams);
    itemTextView.setOnClickListener(onCLick);
    itemTextView.setOnLongClickListener(onLongClick);
    itemTextView.setText(menuItem.getTitle());
    itemTextView.setPadding(0, 0, (int) context.getResources().getDimension(R.dimen.text_right_padding), 0);
    itemTextView.setGravity(Gravity.CENTER_VERTICAL);
    int textColor = menuItem.getTextColor() == 0 ?
            android.R.color.white :
            menuItem.getTextColor();

    itemTextView.setTextColor(ContextCompat.getColor(context, textColor));

    int styleResId = menuItem.getMenuTextAppearanceStyle() > 0
            ? menuItem.getMenuTextAppearanceStyle()
            : R.style.TextView_DefaultStyle;

    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) {
        itemTextView.setTextAppearance(context, styleResId);
    } else {
        itemTextView.setTextAppearance(styleResId);
    }

    return itemTextView;
}
 
Example 11
Project: Widgets   File: HelperActivity.java   View Source Code Vote up 5 votes
private View getLoadingView() {
    TextView tv = new TextView(this);
    tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    tv.setText("Helper中定义的加载中");
    tv.setGravity(Gravity.CENTER);
    tv.setTextSize(18);
    tv.setTextColor(Color.RED);
    // 设置tag为loading
    tv.setTag(StatusLayout.Status.LOADING.getStatus());
    return tv;
}
 
Example 12
Project: boohee_v5.6   File: MeasureCurveActivity.java   View Source Code Vote up 5 votes
private void setSpinnerText(View view) {
    view.setBackgroundColor(getResources().getColor(R.color.in));
    TextView textView = (TextView) view;
    textView.setTextColor(getResources().getColor(R.color.ax));
    textView.setTextSize(16.0f);
    textView.setGravity(19);
}
 
Example 13
Project: browser   File: CCPTabView.java   View Source Code Vote up 5 votes
/**
 *
 */
private void init() {

    int dip2px = DensityUtil.dip2px(2.0F);

    padding = getResources().getDimensionPixelSize(R.dimen.SmallestPadding);
    TextView description = new TextView(getContext());
    description.setSingleLine();
    description.setEllipsize(TextUtils.TruncateAt.END);
    description.setTextColor(getResources().getColor(R.color.ccp_green));
    description.setTextSize(TypedValue.COMPLEX_UNIT_PX , getResources().getDimensionPixelSize(R.dimen.HintTextSize) + dip2px);
    description.setText(R.string.tab_view_name);
    description.setTypeface(null, Typeface.NORMAL);
    addView(mTabDescription = description);

    ImageView descriptionImage = new ImageView(getContext());
    descriptionImage.setImageResource(R.drawable.unread_dot);
    descriptionImage.setVisibility(View.INVISIBLE);
    addView(mTabImage = descriptionImage);

    TextView tips = new TextView(getContext());
    tips.setTextColor(getResources().getColor(android.R.color.white));
    tips.setTextSize(0, getResources().getDimensionPixelSize(R.dimen.SmallestTextSize));
    tips.setBackgroundResource(R.drawable.to_read_tips_onbackbtn);
    tips.setGravity(Gravity.CENTER);
    tips.setVisibility(View.INVISIBLE);

    addView(mTabUnreadTips = tips);

    setBackgroundResource(R.drawable.tab_item_bg);

}
 
Example 14
Project: decoy   File: AbstractWheelTextAdapter.java   View Source Code Vote up 5 votes
/**
     * Configures text view. Is called for the TEXT_VIEW_ITEM_RESOURCE views.
     * @param view the text view to be configured
     */
    protected void configureTextView(TextView view) {
        view.setTextColor(textColor);
        view.setGravity(Gravity.CENTER);
        view.setTextSize(textSize);
        view.setEllipsize(TextUtils.TruncateAt.END);
        view.setLines(1);
//        view.setCompoundDrawablePadding(20);
//        view.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);
    }
 
Example 15
Project: PagerSlidingTabStrip   File: PagerSlidingTabStrip.java   View Source Code Vote up 5 votes
private void addTextTab(final int position, String title) {
    View layoutView = View.inflate(getContext(), R.layout.layout_tv, null);
    TextView tab = (TextView) layoutView.findViewById(R.id.tv_content);
    tab.setText(title);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    addTab(position, tab, layoutView);
}
 
Example 16
Project: GitHub   File: RVPIndicator.java   View Source Code Vote up 5 votes
/**
 * 创建标题view
 *
 * @param text
 * @return
 */
private TextView createTextView(String text) {
    TextView tv = new TextView(getContext());
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    lp.width = getWidth() / mTabVisibleCount;
    tv.setGravity(Gravity.CENTER);
    tv.setTextColor(mTextColorNormal);
    tv.setText(text);
    tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTextSize);
    tv.setLayoutParams(lp);
    return tv;
}
 
Example 17
Project: lqrwechatrongcloud   File: EditPageLand.java   View Source Code Vote up 5 votes
private void initBottom(LinearLayout llBottom, float ratio) {
	LinearLayout llAt = new LinearLayout(activity);
	llAt.setPadding(0, 0, 0, 5);
	llAt.setBackgroundColor(0xffffffff);
	int bottomHeight = (int) (DESIGN_BOTTOM_HEIGHT * ratio);
	LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, bottomHeight);
	llBottom.addView(llAt, lp);

	tvAt = new TextView(activity);
	tvAt.setTextColor(0xff3b3b3b);
	tvAt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21);
	tvAt.setGravity(Gravity.BOTTOM);
	tvAt.setText("@");
	int padding = (int) (DESIGN_LEFT_PADDING * ratio);
	tvAt.setPadding(padding, 0, padding, 0);
	lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
	llAt.addView(tvAt, lp);
	tvAt.setOnClickListener(this);
	if (isShowAtUserLayout(platform.getName())) {
		tvAt.setVisibility(View.VISIBLE);
	} else {
		tvAt.setVisibility(View.INVISIBLE);
	}

	tvTextCouter = new TextView(activity);
	tvTextCouter.setTextColor(0xff3b3b3b);
	tvTextCouter.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
	tvTextCouter.setGravity(Gravity.BOTTOM | Gravity.RIGHT);
	onTextChanged(etContent.getText(), 0, 0, 0);
	tvTextCouter.setPadding(padding, 0, padding, 0);
	lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
	lp.weight = 1;
	llAt.addView(tvTextCouter, lp);

	View v = new View(activity);
	v.setBackgroundColor(0xffcccccc);
	int px1 = ratio > 1 ? ((int) ratio) : 1;
	lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, px1);
	llBottom.addView(v, lp);
}
 
Example 18
Project: LucaHome-AndroidApplication   File: MapContentViewBuilder.java   View Source Code Vote up 4 votes
public void CreateMapContentViewList(@NonNull SerializableList<MapContent> mapContentList) {
    _mapContentViewList.clear();
    _relativeLayoutMapPaint.removeAllViews();

    if (_size == null) {
        Logger.getInstance().Error(TAG, "_size is null!");
        _tempMapContentList = mapContentList;
        return;
    }

    for (int index = 0; index < mapContentList.getSize(); index++) {
        final MapContent mapContent = mapContentList.getValue(index);

        final TextView newTextView = new TextView(_context);

        newTextView.setVisibility(mapContent.IsVisible() ? View.VISIBLE : View.GONE);

        newTextView.setGravity(Gravity.CENTER);
        newTextView.setTextSize(10);
        newTextView.setTextColor(mapContent.GetTextColor());
        newTextView.setText(mapContent.GetShortName());

        newTextView.setBackgroundResource(mapContent.GetDrawable());

        newTextView.setOnClickListener(view -> {
            if (mapContent.GetButtonClick(_context) != null) {
                mapContent.GetButtonClick(_context).run();
            } else {
                switch (mapContent.GetDrawingType()) {
                    case Meter:
                        Bundle meterData = new Bundle();
                        meterData.putSerializable(MeterListService.MeterDataIntent, mapContent.GetDrawingTypeId());
                        NavigationService.getInstance().NavigateToActivityWithData(_context, MeterDataActivity.class, meterData);
                        break;

                    case PuckJS:
                        /* TODO
                        Bundle puckJsData = new Bundle();
                        puckJsData.putSerializable(PuckJsListService.PuckJsIntent, mapContent.GetDrawingTypeId());
                        NavigationService.getInstance().NavigateToActivityWithData(_context, PuckJsActivity.class, puckJsData);*/
                        NavigationService.getInstance().NavigateToActivity(_context, PuckJsActivity.class);
                        break;

                    case Temperature:
                        Bundle temperatureData = new Bundle();
                        temperatureData.putSerializable(TemperatureService.TemperatureDataIntent, mapContent.GetDrawingTypeId());
                        NavigationService.getInstance().NavigateToActivityWithData(_context, TemperatureActivity.class, temperatureData);
                        break;

                    default:
                        Toasty.warning(_context, String.format(Locale.getDefault(), "No button action for %s", mapContent.GetShortName()), Toast.LENGTH_LONG).show();
                        break;
                }
            }
        });

        int positionX = _size.x * mapContent.GetPosition()[0] / 100;
        int positionY = _size.y - (_size.y * mapContent.GetPosition()[1] / 100);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(positionX, positionY, 0, 0);
        newTextView.setLayoutParams(layoutParams);

        newTextView.setTag(mapContent.GetId());

        Logger.getInstance().Information(TAG, String.format(Locale.getDefault(), "Created new TextView: %s", newTextView));

        _mapContentViewList.add(newTextView);
    }

    _tempMapContentList = null;
}
 
Example 19
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 20
Project: ywApplication   File: EditPage.java   View Source Code Vote up 4 votes
private LinearLayout getAtLine(String platform) {
	if (!isShowAtUserLayout(platform)) {
		return null;
	}
	LinearLayout llAt = new LinearLayout(getContext());
	LayoutParams lpAt = new LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpAt.rightMargin = dipToPx(getContext(), 4);
	lpAt.gravity = Gravity.LEFT | Gravity.BOTTOM;
	lpAt.weight = 1;
	llAt.setLayoutParams(lpAt);
	llAt.setOnClickListener(new OnClickListener() {
		public void onClick(View v) {
			FollowListPage subPage = new FollowListPage();
			subPage.setPlatform(platforms.get(0));
			subPage.showForResult(activity, null, EditPage.this);
		}
	});

	TextView tvAt = new TextView(getContext());
	int resId = getBitmapRes(activity, "btn_back_nor");
	if (resId > 0) {
		tvAt.setBackgroundResource(resId);
	}
	int dp_32 = dipToPx(getContext(), 32);
	tvAt.setLayoutParams(new LayoutParams(dp_32, dp_32));
	tvAt.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
	tvAt.setText(getAtUserButtonText(platform));
	int dp_2 = dipToPx(getContext(), 2);
	tvAt.setPadding(0, 0, 0, dp_2);
	tvAt.setTypeface(Typeface.DEFAULT_BOLD);
	tvAt.setTextColor(0xff000000);
	tvAt.setGravity(Gravity.CENTER);
	llAt.addView(tvAt);

	TextView tvName = new TextView(getContext());
	tvName.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
	tvName.setTextColor(0xff000000);
	resId = getStringRes(activity, "list_friends");
	String text = getContext().getString(resId, getName(platform));
	tvName.setText(text);
	LayoutParams lpName = new LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpName.gravity = Gravity.CENTER_VERTICAL;
	tvName.setLayoutParams(lpName);
	llAt.addView(tvName);

	return llAt;
}