Java Code Examples for android.widget.TextView#setGravity()
The following examples show how to use
android.widget.TextView#setGravity() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: views-widgets-samples File: SlidingTabLayout.java License: Apache License 2.0 | 6 votes |
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}. */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
Example 2
Source Project: blog-nested-fragments-backstack File: HostActivity.java License: Apache License 2.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { TextView text = new TextView(getActivity()); text.setGravity(Gravity.CENTER); text.setText("Fragment "+getArguments().getInt(ARG_SECTION_NUMBER)); text.setTextSize(20 * getResources().getDisplayMetrics().density); text.setPadding(20, 20, 20, 20); LinearLayout layout = new LinearLayout(getActivity()); layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); layout.setGravity(Gravity.CENTER); layout.addView(text); return layout; }
Example 3
Source Project: 365browser File: ReaderModeInfoBar.java License: Apache License 2.0 | 6 votes |
@Override protected void createCompactLayoutContent(InfoBarCompactLayout layout) { TextView prompt = new TextView(getContext()); prompt.setText(R.string.reader_view_text); prompt.setSingleLine(); prompt.setTextSize(TypedValue.COMPLEX_UNIT_PX, getContext().getResources().getDimension(R.dimen.infobar_text_size)); prompt.setTextColor( ApiCompatibilityUtils.getColor(layout.getResources(), R.color.default_text_color)); prompt.setGravity(Gravity.CENTER_VERTICAL); prompt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO(mdjones): Trigger navigation from manager. } }); layout.addContent(prompt, 1f); }
Example 4
Source Project: LoveTalkClient File: BlogAdapter.java License: Apache License 2.0 | 6 votes |
TextView getTextView() { //设置TextView的样式 AbsListView.LayoutParams lp = new AbsListView.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, 64); TextView textView = new TextView( mContext); textView.setLayoutParams(lp); textView.setGravity(Gravity.CENTER_VERTICAL); //设置TextView的Padding值 textView.setPadding(16, -10, 0, 32); //设置TextView的字体大小 textView.setTextSize(14); //设置TextView的字体颜色 textView.setTextColor(Color.WHITE); //设置字体加粗 TextPaint txt = textView.getPaint(); txt.setFakeBoldText(true); return textView; }
Example 5
Source Project: TabPager File: NavPager.java License: Apache License 2.0 | 6 votes |
@Override public View getSuccessView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // mArgs = getArguments(); mArgs = getParams(); mIsHybrid = mArgs.getBoolean("isHybrid"); if (mIsHybrid) { View view = LayoutInflater.from(mActivity).inflate(R.layout.activity_tpg, null); tpgView = (TpgView) view.findViewById(R.id.tv_content); return view; } TextView tv = new TextView(getContext()); tv.setText("Nav页面加载成功"); tv.setTextColor(Color.RED); tv.setTextSize(32); tv.setGravity(Gravity.CENTER); return tv; }
Example 6
Source Project: TelePlus-Android File: ProxySettingsActivity.java License: GNU General Public License v2.0 | 6 votes |
public TypeCell(Context context) { super(context); setWillNotDraw(false); textView = new TextView(context); textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); textView.setLines(1); textView.setMaxLines(1); textView.setSingleLine(true); textView.setEllipsize(TextUtils.TruncateAt.END); textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL); addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 23 + 48 : 17, 0, LocaleController.isRTL ? 17 : 23, 0)); checkImage = new ImageView(context); checkImage.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_featuredStickers_addedIcon), PorterDuff.Mode.MULTIPLY)); checkImage.setImageResource(R.drawable.sticker_added); addView(checkImage, LayoutHelper.createFrame(19, 14, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL, 18, 0, 18, 0)); }
Example 7
Source Project: satstat File: LegendActivity.java License: GNU General Public License v3.0 | 5 votes |
protected void addLocationProvider(String title, String styleName) { Resources res = this.getBaseContext().getResources(); TypedArray style = res.obtainTypedArray(res.getIdentifier(styleName, "array", this.getBaseContext().getPackageName())); Drawable drawable = style.getDrawable(STYLE_MARKER); style.recycle(); LinearLayout lpLayout = new LinearLayout(legendMapContainer.getContext()); lpLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); lpLayout.setOrientation(LinearLayout.HORIZONTAL); lpLayout.setWeightSum(22); lpLayout.setMeasureWithLargestChildEnabled(false); ImageView lpMarker = new ImageView(legendMapContainer.getContext()); LinearLayout.LayoutParams lpMarkerParams = new LinearLayout.LayoutParams(0, getResources().getDimensionPixelSize(R.dimen.legend_rowheight), 3); int margin = getResources().getDimensionPixelSize(R.dimen.bitmap_padding); lpMarkerParams.gravity = Gravity.CENTER; lpMarker.setLayoutParams(lpMarkerParams); lpMarker.setPadding(margin, 0, margin, 0); lpMarker.setImageDrawable(drawable); lpMarker.setScaleType(ScaleType.CENTER); lpLayout.addView(lpMarker); TextView lpDesc = new TextView(legendMapContainer.getContext()); LinearLayout.LayoutParams lpDescParams = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 19); lpDescParams.gravity = Gravity.CENTER_VERTICAL; lpDesc.setLayoutParams(lpDescParams); lpDesc.setGravity(Gravity.CENTER_VERTICAL); lpDesc.setTextAppearance(this, R.style.TextAppearance_AppCompat_Medium); lpDesc.setText(title); lpLayout.addView(lpDesc); legendMapContainer.addView(lpLayout); }
Example 8
Source Project: AlarmOn File: Slider.java License: Apache License 2.0 | 5 votes |
public Slider(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Setup the background which 'holds' the slider. tray = new TextView(getContext()); tray.setBackgroundResource(R.drawable.slider_background); tray.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); tray.setGravity(Gravity.CENTER); if (Build.VERSION.SDK_INT < 23) { tray.setTextAppearance(getContext(), R.style.SliderText); } else { tray.setTextAppearance(R.style.SliderText); } tray.setText(R.string.dismiss); addView(tray); // Setup the object which will be slid. dot = new ImageView(getContext()); dot.setImageResource(R.drawable.ic_forward); dot.setBackgroundResource(R.drawable.slider_btn); dot.setScaleType(ScaleType.CENTER); dot.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); dot.setPadding(30, 10, 25, 15); addView(dot); reset(); }
Example 9
Source Project: prayer-times-android File: PagerSlidingTabStrip.java License: Apache License 2.0 | 5 votes |
private void addTextTab(int position, CharSequence title) { TextView tab = new TextView(getContext()); tab.setText(title); tab.setGravity(Gravity.CENTER); tab.setSingleLine(); addTab(position, tab); }
Example 10
Source Project: android-tv-leanback File: SlidingTabLayout.java License: Apache License 2.0 | 5 votes |
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}. */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setTextColor(getResources().getColor(android.R.color.white)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
Example 11
Source Project: TelePlus-Android File: ScrollSlidingTabStrip.java License: GNU General Public License v2.0 | 5 votes |
public TextView addIconTabWithCounter(Drawable drawable) { final int position = tabCount++; FrameLayout tab = new FrameLayout(getContext()); tab.setFocusable(true); tabsContainer.addView(tab); ImageView imageView = new ImageView(getContext()); imageView.setImageDrawable(drawable); imageView.setScaleType(ImageView.ScaleType.CENTER); tab.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { delegate.onPageSelected(position); } }); tab.addView(imageView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); tab.setSelected(position == currentPosition); TextView textView = new TextView(getContext()); textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); textView.setTextColor(Theme.getColor(Theme.key_chat_emojiPanelBadgeText)); textView.setGravity(Gravity.CENTER); textView.setBackgroundDrawable(Theme.createRoundRectDrawable(AndroidUtilities.dp(9), Theme.getColor(Theme.key_chat_emojiPanelBadgeBackground))); textView.setMinWidth(AndroidUtilities.dp(18)); textView.setPadding(AndroidUtilities.dp(5), 0, AndroidUtilities.dp(5), AndroidUtilities.dp(1)); tab.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 18, Gravity.TOP | Gravity.LEFT, 26, 6, 0, 0)); return textView; }
Example 12
Source Project: DropDownMenu File: DropDownMenu.java License: Apache License 2.0 | 5 votes |
private void addTab(@NonNull List<String> tabTexts, int i) { final TextView tab = new TextView(getContext()); tab.setSingleLine(); tab.setEllipsize(TextUtils.TruncateAt.END); tab.setGravity(Gravity.CENTER); tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, menuTextSize); tab.setLayoutParams(new LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f)); tab.setTextColor(textUnselectedColor); tab.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(menuUnselectedIcon), null); tab.setText(tabTexts.get(i)); tab.setPadding(dpTpPx(5), dpTpPx(12), dpTpPx(5), dpTpPx(12)); //添加点击事件 tab.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { switchMenu(tab); } }); tabMenuView.addView(tab); tabMenuView.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE); tabMenuView.setDividerDrawable(getResources().getDrawable(R.drawable.divider_line)); //添加分割线 /* if (i < tabTexts.size() - 1) { View view = new View(getContext()); view.setLayoutParams(new LayoutParams(dpTpPx(0.5f), ViewGroup.LayoutParams.MATCH_PARENT)); view.setBackgroundColor(dividerColor); tabMenuView.addView(view); }*/ }
Example 13
Source Project: InkPageIndicator File: TestFragmentAdapter.java License: Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { TextView text = new TextView(getActivity()); text.setGravity(Gravity.CENTER); text.setText(mContent); text.setTextSize(20 * getResources().getDisplayMetrics().density); text.setPadding(20, 20, 20, 20); LinearLayout layout = new LinearLayout(getActivity()); layout.setLayoutParams(new ViewGroup.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT)); layout.setGravity(Gravity.CENTER); layout.addView(text); return layout; }
Example 14
Source Project: proguard File: HelloWorldActivity.java License: GNU General Public License v2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Display the message. TextView view = new TextView(this); view.setText("Hello World"); view.setGravity(Gravity.CENTER); setContentView(view); }
Example 15
Source Project: VideoOS-Android-SDK File: ImageScannerDialogLayout.java License: GNU General Public License v3.0 | 5 votes |
private View createTitleView() { mTitleView = new TextView(mContext); LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); params.gravity = Gravity.CENTER; mTitleView.setLayoutParams(params); mTitleView.setTextColor(Color.WHITE); mTitleView.setGravity(Gravity.CENTER); mTitleView.setText("选择相册"); mTitleView.setTextSize(20); return mTitleView; }
Example 16
Source Project: Social File: FriendListPage.java License: Apache License 2.0 | 4 votes |
private void initTitle(RelativeLayout rlTitle, float ratio) { tvCancel = new TextView(activity); tvCancel.setTextColor(0xff3b3b3b); tvCancel.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); tvCancel.setGravity(Gravity.CENTER); int resId = R.getStringRes(activity, "ssdk_oks_cancel"); if (resId > 0) { tvCancel.setText(resId); } int padding = (int) (DESIGN_LEFT_PADDING * ratio); tvCancel.setPadding(padding, 0, padding, 0); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); rlTitle.addView(tvCancel, lp); tvCancel.setOnClickListener(this); TextView tvTitle = new TextView(activity); tvTitle.setTextColor(0xff3b3b3b); tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22); tvTitle.setGravity(Gravity.CENTER); resId = R.getStringRes(activity, "ssdk_oks_contacts"); if (resId > 0) { tvTitle.setText(resId); } lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); lp.addRule(RelativeLayout.CENTER_IN_PARENT); rlTitle.addView(tvTitle, lp); tvConfirm = new TextView(activity); tvConfirm.setTextColor(0xffff6d11); tvConfirm.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); tvConfirm.setGravity(Gravity.CENTER); resId = R.getStringRes(activity, "ssdk_oks_confirm"); if (resId > 0) { tvConfirm.setText(resId); } tvConfirm.setPadding(padding, 0, padding, 0); lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); rlTitle.addView(tvConfirm, lp); tvConfirm.setOnClickListener(this); }
Example 17
Source Project: NetCloud_android File: MainWindow.java License: GNU General Public License v2.0 | 4 votes |
public ItemView(Context context) { super(context); setOrientation(HORIZONTAL); setGravity(Gravity.CENTER_VERTICAL); mIcon = new ImageView(context); int iconSize = (int)ResTools.getDimen(R.dimen.icon_size); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(iconSize, iconSize); lp.rightMargin = (int)ResTools.getDimen(R.dimen.hor_padding); mIcon.setLayoutParams(lp); addView(mIcon); mInfo = new LinearLayout(context); mInfo.setOrientation(VERTICAL); lp = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp.weight = 1; addView(mInfo,lp); int textsize = (int)ResTools.getDimen(R.dimen.textsize2); int textsize1 = (int)ResTools.getDimen(R.dimen.textsize3); mAppName = new TextView(context); mAppName.setTextSize(TypedValue.COMPLEX_UNIT_PX, textsize); mAppName.setTextColor(ResTools.getColor(R.color.text)); mInfo.addView(mAppName); mDetails1 = new TextView(context); mDetails1.setTextSize(TypedValue.COMPLEX_UNIT_PX, textsize1); mDetails1.setTextColor(ResTools.getColor(R.color.text1)); lp = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp.topMargin = ScreenUtils.dp2px(8); mInfo.addView(mDetails1,lp); mConnNum = new TextView(context); mConnNum.setTextSize(TypedValue.COMPLEX_UNIT_PX, textsize); mConnNum.setGravity(Gravity.TOP|Gravity.RIGHT); mConnNum.setTextColor(ResTools.getColor(R.color.text)); lp = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.RIGHT; addView(mConnNum,lp); setBackgroundResource(R.drawable.list_item_bg); setMinimumHeight((int)ResTools.getDimen(R.dimen.item_height)); int hp = (int)ResTools.getDimen(R.dimen.hor_padding); int vp = (int)ResTools.getDimen(R.dimen.vtl_padding); setPadding(hp,vp,hp,vp); setOnClickListener(this); }
Example 18
Source Project: redalert-android File: RTLSupport.java License: Apache License 2.0 | 4 votes |
@SuppressLint("NewApi") public static void mirrorDialog(Dialog dialog, Context context) { // Hebrew only if (!Localization.isHebrewLocale(context)) { return; } try { // Get message text view TextView message = (TextView) dialog.findViewById(android.R.id.message); // Defy gravity if (message != null) { message.setGravity(Gravity.RIGHT); } // Get the title of text view TextView title = (TextView) dialog.findViewById(context.getResources().getIdentifier("alertTitle", "id", "android")); // Defy gravity title.setGravity(Gravity.RIGHT); // Get list view (may not exist) ListView listView = (ListView) dialog.findViewById(context.getResources().getIdentifier("select_dialog_listview", "id", "android")); // Check if list & set RTL mode if (listView != null) { listView.setLayoutDirection(View.LAYOUT_DIRECTION_RTL); } // Get title's parent layout LinearLayout parent = ((LinearLayout) title.getParent()); // Get layout params LinearLayout.LayoutParams originalParams = (LinearLayout.LayoutParams) parent.getLayoutParams(); // Set width to WRAP_CONTENT originalParams.width = LinearLayout.LayoutParams.WRAP_CONTENT; // Defy gravity originalParams.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL; // Set layout params parent.setLayoutParams(originalParams); } catch (Exception exc) { // Log failure to logcat Log.d(Logging.TAG, "RTL failed", exc); } }
Example 19
Source Project: NetCloud_android File: HostInputDialog.java License: GNU General Public License v2.0 | 4 votes |
public void show(int inputType){ if(mHostInputDialog != null){ return; } AlertDialog.Builder builder = new AlertDialog.Builder(mContext); LinearLayout cnt = new LinearLayout(mContext); cnt.setBackgroundResource(R.drawable.list_item_bg); cnt.setOrientation(LinearLayout.VERTICAL); cnt.setGravity(Gravity.CENTER_HORIZONTAL); int vp = ScreenUtils.dp2px(12); int hp = (int) ResTools.getDimen(R.dimen.hor_padding); cnt.setPadding(hp, vp, hp, vp); final EditText editText = new EditText(mContext); editText.setBackgroundColor(ResTools.getColor(R.color.background)); editText.setMaxLines(1); editText.setSingleLine(); if(mOriginContent != null){ editText.setText(mOriginContent); } editText.setFilters(new InputFilter[] {new InputFilter.LengthFilter(60)}); InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); if(inputType > 0){ editText.setInputType(inputType); } cnt.addView(editText); TextView ok = new TextView(mContext); ok.setText(R.string.add); ok.setGravity(Gravity.CENTER); ok.setBackgroundResource(R.drawable.button_blue); ok.setTextColor(ResTools.getColor(R.color.blue)); ok.setTextSize(TypedValue.COMPLEX_UNIT_PX, (int)ResTools.getDimen(R.dimen.textsize1)); ok.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String host = editText.getText().toString(); mCallback.onHostInput(host); } }); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ScreenUtils.dp2px(80), ScreenUtils.dp2px(32)); lp.gravity = Gravity.CENTER_HORIZONTAL; lp.topMargin = ScreenUtils.dp2px(16); cnt.addView(ok, lp); builder.setView(cnt); mHostInputDialog = builder.create(); mHostInputDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { mHostInputDialog = null; mCallback.onDismiss(); } }); mHostInputDialog.show(); editText.requestFocus(); }
Example 20
Source Project: Telegram File: AndroidUtilities.java License: GNU General Public License v2.0 | 4 votes |
public static void showProxyAlert(Activity activity, final String address, final String port, final String user, final String password, final String secret) { BottomSheet.Builder builder = new BottomSheet.Builder(activity); final Runnable dismissRunnable = builder.getDismissRunnable(); builder.setApplyTopPadding(false); builder.setApplyBottomPadding(false); LinearLayout linearLayout = new LinearLayout(activity); builder.setCustomView(linearLayout); linearLayout.setOrientation(LinearLayout.VERTICAL); if (!TextUtils.isEmpty(secret)) { TextView titleTextView = new TextView(activity); titleTextView.setText(LocaleController.getString("UseProxyTelegramInfo2", R.string.UseProxyTelegramInfo2)); titleTextView.setTextColor(Theme.getColor(Theme.key_dialogTextGray4)); titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); titleTextView.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL); linearLayout.addView(titleTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 17, 8, 17, 8)); View lineView = new View(activity); lineView.setBackgroundColor(Theme.getColor(Theme.key_divider)); linearLayout.addView(lineView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1)); } for (int a = 0; a < 5; a++) { String text = null; String detail = null; if (a == 0) { text = address; detail = LocaleController.getString("UseProxyAddress", R.string.UseProxyAddress); } else if (a == 1) { text = "" + port; detail = LocaleController.getString("UseProxyPort", R.string.UseProxyPort); } else if (a == 2) { text = secret; detail = LocaleController.getString("UseProxySecret", R.string.UseProxySecret); } else if (a == 3) { text = user; detail = LocaleController.getString("UseProxyUsername", R.string.UseProxyUsername); } else if (a == 4) { text = password; detail = LocaleController.getString("UseProxyPassword", R.string.UseProxyPassword); } if (TextUtils.isEmpty(text)) { continue; } TextDetailSettingsCell cell = new TextDetailSettingsCell(activity); cell.setTextAndValue(text, detail, true); cell.getTextView().setTextColor(Theme.getColor(Theme.key_dialogTextBlack)); cell.getValueTextView().setTextColor(Theme.getColor(Theme.key_dialogTextGray3)); linearLayout.addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); if (a == 2) { break; } } PickerBottomLayout pickerBottomLayout = new PickerBottomLayout(activity, false); pickerBottomLayout.setBackgroundColor(Theme.getColor(Theme.key_dialogBackground)); linearLayout.addView(pickerBottomLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM)); pickerBottomLayout.cancelButton.setPadding(AndroidUtilities.dp(18), 0, AndroidUtilities.dp(18), 0); pickerBottomLayout.cancelButton.setTextColor(Theme.getColor(Theme.key_dialogTextBlue2)); pickerBottomLayout.cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase()); pickerBottomLayout.cancelButton.setOnClickListener(view -> dismissRunnable.run()); pickerBottomLayout.doneButtonTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlue2)); pickerBottomLayout.doneButton.setPadding(AndroidUtilities.dp(18), 0, AndroidUtilities.dp(18), 0); pickerBottomLayout.doneButtonBadgeTextView.setVisibility(View.GONE); pickerBottomLayout.doneButtonTextView.setText(LocaleController.getString("ConnectingConnectProxy", R.string.ConnectingConnectProxy).toUpperCase()); pickerBottomLayout.doneButton.setOnClickListener(v -> { SharedPreferences.Editor editor = MessagesController.getGlobalMainSettings().edit(); editor.putBoolean("proxy_enabled", true); editor.putString("proxy_ip", address); int p = Utilities.parseInt(port); editor.putInt("proxy_port", p); SharedConfig.ProxyInfo info; if (TextUtils.isEmpty(secret)) { editor.remove("proxy_secret"); if (TextUtils.isEmpty(password)) { editor.remove("proxy_pass"); } else { editor.putString("proxy_pass", password); } if (TextUtils.isEmpty(user)) { editor.remove("proxy_user"); } else { editor.putString("proxy_user", user); } info = new SharedConfig.ProxyInfo(address, p, user, password, ""); } else { editor.remove("proxy_pass"); editor.remove("proxy_user"); editor.putString("proxy_secret", secret); info = new SharedConfig.ProxyInfo(address, p, "", "", secret); } editor.commit(); SharedConfig.currentProxy = SharedConfig.addProxy(info); ConnectionsManager.setProxySettings(true, address, p, user, password, secret); NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.proxySettingsChanged); dismissRunnable.run(); }); builder.show(); }