Java Code Examples for android.widget.TextView#setMinWidth()
The following examples show how to use
android.widget.TextView#setMinWidth() .
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: httplite File: LeftMenuAdapter.java License: Apache License 2.0 | 6 votes |
@Override public MenuViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { TextView textView = new TextView(parent.getContext()); textView.setTextColor(parent.getResources().getColor(R.color.black)); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); textView.setGravity(Gravity.CENTER); textView.setMinWidth(parent.getWidth()); textView.setMinHeight(parent.getHeight()/10); textView.setPadding(0,10,0,10); final MenuViewHolder holder = new MenuViewHolder(textView); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mItemClickListener.onItemClick(mList.get(holder.postion)); } }); return holder; }
Example 2
Source Project: MaterialDrawer-Xamarin File: BadgeStyle.java License: Apache License 2.0 | 6 votes |
public void style(TextView badgeTextView, ColorStateList colorStateList) { Context ctx = badgeTextView.getContext(); //set background for badge if (mBadgeBackground == null) { UIUtils.setBackground(badgeTextView, new BadgeDrawableBuilder(this).build(ctx)); } else { UIUtils.setBackground(badgeTextView, mBadgeBackground); } //set the badge text color if (mTextColor != null) { ColorHolder.applyToOr(mTextColor, badgeTextView, null); } else if (colorStateList != null) { badgeTextView.setTextColor(colorStateList); } //set the padding int paddingLeftRight = mPaddingLeftRight.asPixel(ctx); int paddingTopBottom = mPaddingTopBottom.asPixel(ctx); badgeTextView.setPadding(paddingLeftRight, paddingTopBottom, paddingLeftRight, paddingTopBottom); //set the min width badgeTextView.setMinWidth(mMinWidth.asPixel(ctx)); }
Example 3
Source Project: SmartTablayout File: SmartTabLayout.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(CharSequence title) { TextView textView = new TextView(getContext()); textView.setGravity(Gravity.CENTER); textView.setText(title); textView.setTextColor(tabViewTextColors); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); if (tabViewBackgroundResId != NO_ID) { textView.setBackgroundResource(tabViewBackgroundResId); } else 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(tabViewTextAllCaps); } textView.setPadding( tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0); if (tabViewTextMinWidth > 0) { textView.setMinWidth(tabViewTextMinWidth); } return textView; }
Example 4
Source Project: narrate-android File: ButtonPreference.java License: Apache License 2.0 | 5 votes |
@Override public void init() { super.init(); mButton = new TextView(getContext()); mButton.setId(R.id.settings_button); mButton.setClickable(true); mButton.setBackgroundResource(R.drawable.default_selector); mButton.setTypeface(null, Typeface.BOLD); mButton.setTextColor(getResources().getColor(R.color.accent)); RelativeLayout.LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); mButton.setGravity(Gravity.RIGHT); mButton.setLayoutParams(lp); mButton.setMinWidth(getResources().getDimensionPixelOffset(R.dimen.default_gap)*3/2); mButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); mButton.setOnClickListener(this); lp = (LayoutParams) mTextView.getLayoutParams(); lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT); lp.addRule(RelativeLayout.LEFT_OF, mButton.getId()); mTextView.setLayoutParams(lp); int p = getResources().getDimensionPixelOffset(R.dimen.eight_dp) / 4; mButton.setPadding(p, p, p, p); addView(mButton); setBackgroundResource(R.drawable.default_selector); setClickable(true); setOnClickListener(this); }
Example 5
Source Project: Telegram-FOSS File: PickerBottomLayoutViewer.java License: GNU General Public License v2.0 | 5 votes |
public PickerBottomLayoutViewer(Context context, boolean darkTheme) { super(context); isDarkTheme = darkTheme; setBackgroundColor(isDarkTheme ? 0xff1a1a1a : 0xffffffff); cancelButton = new TextView(context); cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); cancelButton.setTextColor(isDarkTheme ? 0xffffffff : 0xff19a7e8); cancelButton.setGravity(Gravity.CENTER); cancelButton.setBackgroundDrawable(Theme.createSelectorDrawable(isDarkTheme ? Theme.ACTION_BAR_PICKER_SELECTOR_COLOR : Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, 0)); cancelButton.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0); cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase()); cancelButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); addView(cancelButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); doneButton = new TextView(context); doneButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); doneButton.setTextColor(isDarkTheme ? 0xffffffff : 0xff19a7e8); doneButton.setGravity(Gravity.CENTER); doneButton.setBackgroundDrawable(Theme.createSelectorDrawable(isDarkTheme ? Theme.ACTION_BAR_PICKER_SELECTOR_COLOR : Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, 0)); doneButton.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0); doneButton.setText(LocaleController.getString("Send", R.string.Send).toUpperCase()); doneButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); addView(doneButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT)); doneButtonBadgeTextView = new TextView(context); doneButtonBadgeTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); doneButtonBadgeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13); doneButtonBadgeTextView.setTextColor(0xffffffff); doneButtonBadgeTextView.setGravity(Gravity.CENTER); doneButtonBadgeTextView.setBackgroundResource(isDarkTheme ? R.drawable.photobadge : R.drawable.bluecounter); doneButtonBadgeTextView.setMinWidth(AndroidUtilities.dp(23)); doneButtonBadgeTextView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), AndroidUtilities.dp(1)); addView(doneButtonBadgeTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 23, Gravity.TOP | Gravity.RIGHT, 0, 0, 7, 0)); }
Example 6
Source Project: TableRecyclerView File: TextViewUtils.java License: MIT License | 5 votes |
public static void setTextView( TextView textView, String text, int gravity, int minWidth, int padding) { textView.setText(text); textView.setGravity(gravity); textView.setMinWidth(minWidth); textView.setPadding(0, padding / 2, 0, padding / 2); }
Example 7
Source Project: SmartTabLayout File: SmartTabLayout.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(CharSequence title) { TextView textView = new TextView(getContext()); textView.setGravity(Gravity.CENTER); textView.setText(title); textView.setTextColor(tabViewTextColors); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); if (tabViewBackgroundResId != NO_ID) { textView.setBackgroundResource(tabViewBackgroundResId); } else { // 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(tabViewTextAllCaps); } textView.setPadding( tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0); if (tabViewTextMinWidth > 0) { textView.setMinWidth(tabViewTextMinWidth); } return textView; }
Example 8
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 9
Source Project: KUtils File: SmartTabLayout.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(CharSequence title) { TextView textView = new TextView(getContext()); textView.setGravity(Gravity.CENTER); textView.setText(title); textView.setTextColor(tabViewTextColors); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); if (tabViewBackgroundResId != NO_ID) { textView.setBackgroundResource(tabViewBackgroundResId); } else 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(tabViewTextAllCaps); } textView.setPadding( tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0); if (tabViewTextMinWidth > 0) { textView.setMinWidth(tabViewTextMinWidth); } return textView; }
Example 10
Source Project: Telegram File: PickerBottomLayoutViewer.java License: GNU General Public License v2.0 | 5 votes |
public PickerBottomLayoutViewer(Context context, boolean darkTheme) { super(context); isDarkTheme = darkTheme; setBackgroundColor(isDarkTheme ? 0xff1a1a1a : 0xffffffff); cancelButton = new TextView(context); cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); cancelButton.setTextColor(isDarkTheme ? 0xffffffff : 0xff19a7e8); cancelButton.setGravity(Gravity.CENTER); cancelButton.setBackgroundDrawable(Theme.createSelectorDrawable(isDarkTheme ? Theme.ACTION_BAR_PICKER_SELECTOR_COLOR : Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, 0)); cancelButton.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0); cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase()); cancelButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); addView(cancelButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); doneButton = new TextView(context); doneButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); doneButton.setTextColor(isDarkTheme ? 0xffffffff : 0xff19a7e8); doneButton.setGravity(Gravity.CENTER); doneButton.setBackgroundDrawable(Theme.createSelectorDrawable(isDarkTheme ? Theme.ACTION_BAR_PICKER_SELECTOR_COLOR : Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, 0)); doneButton.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0); doneButton.setText(LocaleController.getString("Send", R.string.Send).toUpperCase()); doneButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); addView(doneButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT)); doneButtonBadgeTextView = new TextView(context); doneButtonBadgeTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); doneButtonBadgeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13); doneButtonBadgeTextView.setTextColor(0xffffffff); doneButtonBadgeTextView.setGravity(Gravity.CENTER); doneButtonBadgeTextView.setBackgroundResource(isDarkTheme ? R.drawable.photobadge : R.drawable.bluecounter); doneButtonBadgeTextView.setMinWidth(AndroidUtilities.dp(23)); doneButtonBadgeTextView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), AndroidUtilities.dp(1)); addView(doneButtonBadgeTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 23, Gravity.TOP | Gravity.RIGHT, 0, 0, 7, 0)); }
Example 11
Source Project: KUtils-master File: SmartTabLayout.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(CharSequence title) { TextView textView = new TextView(getContext()); textView.setGravity(Gravity.CENTER); textView.setText(title); textView.setTextColor(tabViewTextColors); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); if (tabViewBackgroundResId != NO_ID) { textView.setBackgroundResource(tabViewBackgroundResId); } else 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(tabViewTextAllCaps); } textView.setPadding( tabViewTextHorizontalPadding, 0, tabViewTextHorizontalPadding, 0); if (tabViewTextMinWidth > 0) { textView.setMinWidth(tabViewTextMinWidth); } return textView; }
Example 12
Source Project: SimplifyReader File: SmartTabLayout.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.setTextColor(mTabViewTextColor); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTabViewTextSize); textView.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT)); 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(mTabViewTextAllCaps); } textView.setPadding( mTabViewTextHorizontalPadding, 0, mTabViewTextHorizontalPadding, 0); if (mTabViewTextMinWidth > 0) { textView.setMinWidth(mTabViewTextMinWidth); } return textView; }
Example 13
Source Project: sctalk File: PinkToast.java License: Apache License 2.0 | 5 votes |
public static Toast makeText(Context context, int id, int duration) { Toast result = Toast.makeText(context, id, duration); result.getView().setBackgroundResource(R.drawable.tt_waterfall_refresh_bg); result.setGravity(Gravity.CENTER, 0, 0); TextView tv = (TextView) ((ViewGroup) result.getView()).getChildAt(0); ScreenTools tools = ScreenTools.instance(context); tv.setPadding(tools.dip2px(5), tools.dip2px(8), tools.dip2px(5), tools.dip2px(8)); tv.setShadowLayer(0, 0, 0, Color.TRANSPARENT); tv.setMinWidth(tools.dip2px(180)); tv.setGravity(Gravity.CENTER); tv.setTextColor(context.getResources().getColor(android.R.color.white)); return result; }
Example 14
Source Project: TelePlus-Android File: TabsPagerTitleStrip.java License: GNU General Public License v2.0 | 4 votes |
public void addTabWithCounter(final int position, View view) { RelativeLayout tab = new RelativeLayout(getContext()); tab.setFocusable(true); tabsContainer.addView(tab, FeaturedSettings.tabSettings.tabsShouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams); view.setBackgroundResource(btnBgRes); view.setOnClickListener(v -> { if (position == pager.getCurrentItem()) { if (delegate != null) delegate.onTabClick(); } else { if (pager != null) pager.setCurrentItem(position); } }); tab.addView(view, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT)); tab.setSelected(position == currentPosition); TextView textView = new TextView(getContext()); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, FeaturedSettings.tabSettings.chatsTabCounterSize); textView.setTextColor(Theme.getColor(Theme.key_dialogBadgeText)); textView.setGravity(Gravity.CENTER); GradientDrawable shape = new GradientDrawable(); shape.setShape(GradientDrawable.RECTANGLE); shape.setCornerRadius(AndroidUtilities.dp(32)); //noinspection deprecation textView.setBackgroundDrawable(shape); textView.setMinWidth(AndroidUtilities.dp(18)); textView.setPadding(AndroidUtilities.dp(FeaturedSettings.tabSettings.chatsTabCounterSize > 10 ? FeaturedSettings.tabSettings.chatsTabCounterSize - 7 : 4), 0, AndroidUtilities.dp(FeaturedSettings.tabSettings.chatsTabCounterSize > 10 ? FeaturedSettings.tabSettings.chatsTabCounterSize - 7 : 4), 0); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); params.setMargins(AndroidUtilities.dp(3), AndroidUtilities.dp(5), AndroidUtilities.dp(3), AndroidUtilities.dp(5)); params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); tab.addView(textView, params); }
Example 15
Source Project: Telegram-FOSS File: PickerBottomLayout.java License: GNU General Public License v2.0 | 4 votes |
public PickerBottomLayout(Context context, boolean darkTheme) { super(context); setBackgroundColor(Theme.getColor(darkTheme ? Theme.key_dialogBackground : Theme.key_windowBackgroundWhite)); cancelButton = new TextView(context); cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); cancelButton.setTextColor(Theme.getColor(Theme.key_picker_enabledButton)); cancelButton.setGravity(Gravity.CENTER); cancelButton.setBackgroundDrawable(Theme.createSelectorDrawable(0x0f000000, 0)); cancelButton.setPadding(AndroidUtilities.dp(33), 0, AndroidUtilities.dp(33), 0); cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase()); cancelButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); addView(cancelButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); doneButton = new LinearLayout(context); doneButton.setOrientation(LinearLayout.HORIZONTAL); doneButton.setBackgroundDrawable(Theme.createSelectorDrawable(0x0f000000, 0)); doneButton.setPadding(AndroidUtilities.dp(33), 0, AndroidUtilities.dp(33), 0); addView(doneButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT)); doneButtonBadgeTextView = new TextView(context); doneButtonBadgeTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); doneButtonBadgeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13); doneButtonBadgeTextView.setTextColor(Theme.getColor(Theme.key_picker_badgeText)); doneButtonBadgeTextView.setGravity(Gravity.CENTER); Drawable drawable = Theme.createRoundRectDrawable(AndroidUtilities.dp(11), Theme.getColor(Theme.key_picker_badge)); doneButtonBadgeTextView.setBackgroundDrawable(drawable); doneButtonBadgeTextView.setMinWidth(AndroidUtilities.dp(23)); doneButtonBadgeTextView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), AndroidUtilities.dp(1)); doneButton.addView(doneButtonBadgeTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 23, Gravity.CENTER_VERTICAL, 0, 0, 10, 0)); doneButtonTextView = new TextView(context); doneButtonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); doneButtonTextView.setTextColor(Theme.getColor(Theme.key_picker_enabledButton)); doneButtonTextView.setGravity(Gravity.CENTER); doneButtonTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8)); doneButtonTextView.setText(LocaleController.getString("Send", R.string.Send).toUpperCase()); doneButtonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); doneButton.addView(doneButtonTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL)); }
Example 16
Source Project: Telegram-FOSS File: ActionBarMenuItem.java License: GNU General Public License v2.0 | 4 votes |
public TextView addSubItem(int id, CharSequence text) { createPopupLayout(); TextView textView = new TextView(getContext()); textView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuItem)); textView.setBackgroundDrawable(Theme.getSelectorDrawable(false)); if (!LocaleController.isRTL) { textView.setGravity(Gravity.CENTER_VERTICAL); } else { textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT); } textView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); textView.setMinWidth(AndroidUtilities.dp(196)); textView.setSingleLine(true); textView.setEllipsize(TextUtils.TruncateAt.END); textView.setTag(id); textView.setText(text); popupLayout.addView(textView); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams(); if (LocaleController.isRTL) { layoutParams.gravity = Gravity.RIGHT; } layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = AndroidUtilities.dp(48); textView.setLayoutParams(layoutParams); textView.setOnClickListener(view -> { if (popupWindow != null && popupWindow.isShowing()) { if (processedPopupClick) { return; } processedPopupClick = true; if (!allowCloseAnimation) { popupWindow.setAnimationStyle(R.style.PopupAnimation); } popupWindow.dismiss(allowCloseAnimation); } if (parentMenu != null) { parentMenu.onItemClick((Integer) view.getTag()); } else if (delegate != null) { delegate.onItemClick((Integer) view.getTag()); } }); return textView; }
Example 17
Source Project: Telegram File: ActionBarMenuItem.java License: GNU General Public License v2.0 | 4 votes |
public TextView addSubItem(int id, CharSequence text) { createPopupLayout(); TextView textView = new TextView(getContext()); textView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuItem)); textView.setBackgroundDrawable(Theme.getSelectorDrawable(false)); if (!LocaleController.isRTL) { textView.setGravity(Gravity.CENTER_VERTICAL); } else { textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT); } textView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); textView.setMinWidth(AndroidUtilities.dp(196)); textView.setSingleLine(true); textView.setEllipsize(TextUtils.TruncateAt.END); textView.setTag(id); textView.setText(text); popupLayout.addView(textView); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams(); if (LocaleController.isRTL) { layoutParams.gravity = Gravity.RIGHT; } layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = AndroidUtilities.dp(48); textView.setLayoutParams(layoutParams); textView.setOnClickListener(view -> { if (popupWindow != null && popupWindow.isShowing()) { if (processedPopupClick) { return; } processedPopupClick = true; if (!allowCloseAnimation) { popupWindow.setAnimationStyle(R.style.PopupAnimation); } popupWindow.dismiss(allowCloseAnimation); } if (parentMenu != null) { parentMenu.onItemClick((Integer) view.getTag()); } else if (delegate != null) { delegate.onItemClick((Integer) view.getTag()); } }); return textView; }
Example 18
Source Project: TelePlus-Android File: PickerBottomLayout.java License: GNU General Public License v2.0 | 4 votes |
public PickerBottomLayout(Context context, boolean darkTheme) { super(context); isDarkTheme = darkTheme; setBackgroundColor(isDarkTheme ? 0xff1a1a1a : Theme.getColor(Theme.key_windowBackgroundWhite)); cancelButton = new TextView(context); cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); cancelButton.setTextColor(isDarkTheme ? 0xffffffff : Theme.getColor(Theme.key_picker_enabledButton)); cancelButton.setGravity(Gravity.CENTER); cancelButton.setBackgroundDrawable(Theme.createSelectorDrawable(isDarkTheme ? Theme.ACTION_BAR_PICKER_SELECTOR_COLOR : Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, 0)); cancelButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0); cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase()); cancelButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); addView(cancelButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); doneButton = new LinearLayout(context); doneButton.setOrientation(LinearLayout.HORIZONTAL); doneButton.setBackgroundDrawable(Theme.createSelectorDrawable(isDarkTheme ? Theme.ACTION_BAR_PICKER_SELECTOR_COLOR : Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, 0)); doneButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0); addView(doneButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT)); doneButtonBadgeTextView = new TextView(context); doneButtonBadgeTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); doneButtonBadgeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13); doneButtonBadgeTextView.setTextColor(isDarkTheme ? 0xffffffff : Theme.getColor(Theme.key_picker_badgeText)); doneButtonBadgeTextView.setGravity(Gravity.CENTER); Drawable drawable; if (isDarkTheme) { drawable = Theme.createRoundRectDrawable(AndroidUtilities.dp(11), 0xff66bffa); } else { drawable = Theme.createRoundRectDrawable(AndroidUtilities.dp(11), Theme.getColor(Theme.key_picker_badge)); } doneButtonBadgeTextView.setBackgroundDrawable(drawable); doneButtonBadgeTextView.setMinWidth(AndroidUtilities.dp(23)); doneButtonBadgeTextView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), AndroidUtilities.dp(1)); doneButton.addView(doneButtonBadgeTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 23, Gravity.CENTER_VERTICAL, 0, 0, 10, 0)); doneButtonTextView = new TextView(context); doneButtonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); doneButtonTextView.setTextColor(isDarkTheme ? 0xffffffff : Theme.getColor(Theme.key_picker_enabledButton)); doneButtonTextView.setGravity(Gravity.CENTER); doneButtonTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8)); doneButtonTextView.setText(LocaleController.getString("Send", R.string.Send).toUpperCase()); doneButtonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); doneButton.addView(doneButtonTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL)); }
Example 19
Source Project: AppCompat-Extension-Library File: AppCompatTimePickerDelegate.java License: Apache License 2.0 | 4 votes |
public AppCompatTimePickerDelegate(AppCompatTimePicker delegator, Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(delegator, context); // process style attributes final TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.TimePickerDialog, defStyleAttr, defStyleRes); final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE); final Resources res = mContext.getResources(); mSelectHours = res.getString(R.string.select_hours); mSelectMinutes = res.getString(R.string.select_minutes); String[] amPmStrings = getAmPmStrings(context); mAmText = amPmStrings[0]; mPmText = amPmStrings[1]; final View mainView = inflater.inflate(R.layout.time_picker_material, delegator); mHeaderView = mainView.findViewById(R.id.time_header); // Set up hour/minute labels. mHourView = (TextView) mainView.findViewById(R.id.hours); mHourView.setOnClickListener(mClickListener); ViewCompat.setAccessibilityDelegate(mHourView, new ClickActionDelegate(context, R.string.select_hours)); mSeparatorView = (TextView) mainView.findViewById(R.id.separator); mMinuteView = (TextView) mainView.findViewById(R.id.minutes); mMinuteView.setOnClickListener(mClickListener); ViewCompat.setAccessibilityDelegate(mMinuteView, new ClickActionDelegate(context, R.string.select_minutes)); // Now that we have text appearances out of the way, make sure the hour // and minute views are correctly sized. mHourView.setMinWidth(computeStableWidth(mHourView, 24)); mMinuteView.setMinWidth(computeStableWidth(mMinuteView, 60)); // Set up AM/PM labels. mAmPmLayout = mainView.findViewById(R.id.ampm_layout); mAmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.am_label); mAmLabel.setText(obtainVerbatim(amPmStrings[0])); mAmLabel.setOnClickListener(mClickListener); mPmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.pm_label); mPmLabel.setText(obtainVerbatim(amPmStrings[1])); mPmLabel.setOnClickListener(mClickListener); // Set up header text color, if available. ColorStateList headerTextColor; if (a.hasValue(R.styleable.TimePickerDialog_headerTextColor)) { headerTextColor = a.getColorStateList(R.styleable.DatePickerDialog_headerTextColor); } else { headerTextColor = PickerThemeUtils.getHeaderTextColorStateList(mContext); } mHourView.setTextColor(headerTextColor); mSeparatorView.setTextColor(headerTextColor); mMinuteView.setTextColor(headerTextColor); mAmLabel.setTextColor(headerTextColor); mPmLabel.setTextColor(headerTextColor); // Set up header background, if available. ViewCompatUtils.setBackground(mHeaderView, PickerThemeUtils.getHeaderBackground(mContext, a.getColor(R.styleable.DatePickerDialog_headerBackground, ThemeUtils.getThemeAttrColor(mContext, R.attr.colorAccent)))); a.recycle(); mRadialTimePickerView = (RadialTimePickerView) mainView.findViewById( R.id.radial_picker); setupListeners(); mAllowAutoAdvance = true; // Set up for keyboard mode. mDoublePlaceholderText = res.getString(R.string.time_placeholder); mDeletedKeyFormat = res.getString(R.string.deleted_key); mPlaceholderText = mDoublePlaceholderText.charAt(0); mAmKeyCode = mPmKeyCode = -1; generateLegalTimesTree(); // Initialize with current time final Calendar calendar = Calendar.getInstance(mCurrentLocale); final int currentHour = calendar.get(Calendar.HOUR_OF_DAY); final int currentMinute = calendar.get(Calendar.MINUTE); initialize(currentHour, currentMinute, false /* 12h */, HOUR_INDEX); }
Example 20
Source Project: KrGallery File: ActionBarMenuItem.java License: GNU General Public License v2.0 | 4 votes |
public TextView addSubItem(int id, String text, int icon) { if (popupLayout == null) { rect = new Rect(); location = new int[2]; popupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getContext()); popupLayout.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { if (popupWindow != null && popupWindow.isShowing()) { v.getHitRect(rect); if (!rect.contains((int) event.getX(), (int) event.getY())) { popupWindow.dismiss(); } } } return false; } }); popupLayout.setDispatchKeyEventListener(new ActionBarPopupWindow.OnDispatchKeyEventListener() { @Override public void onDispatchKeyEvent(KeyEvent keyEvent) { if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0 && popupWindow != null && popupWindow.isShowing()) { popupWindow.dismiss(); } } }); } TextView textView = new TextView(getContext()); textView.setTextColor(0xff212121); textView.setBackgroundResource(R.drawable.list_selector); if (!AndroidUtilities.isRTL()) { textView.setGravity(Gravity.CENTER_VERTICAL); } else { textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT); } textView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); textView.setMinWidth(AndroidUtilities.dp(196)); textView.setTag(id); textView.setText(text); if (icon != 0) { textView.setCompoundDrawablePadding(AndroidUtilities.dp(12)); if (!AndroidUtilities.isRTL()) { textView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(icon), null, null, null); } else { textView.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(icon), null); } } popupLayout.setShowedFromBotton(showFromBottom); popupLayout.addView(textView); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams(); if (AndroidUtilities.isRTL()) { layoutParams.gravity = Gravity.RIGHT; } layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = AndroidUtilities.dp(48); textView.setLayoutParams(layoutParams); textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (popupWindow != null && popupWindow.isShowing()) { if (processedPopupClick) { return; } processedPopupClick = true; popupWindow.dismiss(allowCloseAnimation); } if (parentMenu != null) { parentMenu.onItemClick((Integer) view.getTag()); } else if (delegate != null) { delegate.onItemClick((Integer) view.getTag()); } } }); menuHeight += layoutParams.height; return textView; }