下面列出了android.widget.TextView#setCompoundDrawablePadding ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Object item = getItem(position);
View v;
if (item instanceof Database.HistoryEntry) {
v = convertView == null ? inflater.inflate(android.R.layout.simple_list_item_2, parent, false) : convertView;
TextView tv1 = (TextView) v.findViewById(android.R.id.text1);
TextView tv2 = (TextView) v.findViewById(android.R.id.text2);
tv1.setSingleLine();
tv2.setSingleLine();
tv1.setEllipsize(TextUtils.TruncateAt.END);
tv2.setEllipsize(TextUtils.TruncateAt.START);
tv1.setText(((Database.HistoryEntry) item).title);
tv2.setText(((Database.HistoryEntry) item).url);
ChanModule chan = MainApplication.getInstance().getChanModule(((Database.HistoryEntry) item).chan);
if (chan != null) {
tv1.setCompoundDrawablesWithIntrinsicBounds(chan.getChanFavicon(), null, null, null);
tv1.setCompoundDrawablePadding(drawablePadding);
}
} else {
v = convertView == null ? inflater.inflate(R.layout.list_separator, parent, false) : convertView;
TextView tv = (TextView) v;
tv.setText((String) item);
}
return v;
}
/**
* 设置TextView(@+id/snackbar_text)左右两侧的图片
* @param leftDrawable
* @param rightDrawable
* @return
*/
public SnackbarUtils leftAndRightDrawable(@Nullable Drawable leftDrawable, @Nullable Drawable rightDrawable){
if(getSnackbar()!=null){
TextView message = (TextView) getSnackbar().getView().findViewById(R.id.snackbar_text);
LinearLayout.LayoutParams paramsMessage = (LinearLayout.LayoutParams) message.getLayoutParams();
paramsMessage = new LinearLayout.LayoutParams(paramsMessage.width, paramsMessage.height,0.0f);
message.setLayoutParams(paramsMessage);
message.setCompoundDrawablePadding(message.getPaddingLeft());
int textSize = (int) message.getTextSize();
Log.e("Jet","textSize:"+textSize);
if(leftDrawable!=null){
leftDrawable.setBounds(0,0,textSize,textSize);
}
if(rightDrawable!=null){
rightDrawable.setBounds(0,0,textSize,textSize);
}
message.setCompoundDrawables(leftDrawable,null,rightDrawable,null);
LinearLayout.LayoutParams paramsSpace = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT,1.0f);
((Snackbar.SnackbarLayout)getSnackbar().getView()).addView(new Space(getSnackbar().getView().getContext()),1,paramsSpace);
}
return this;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
QuickAccess.Entry entry = getItem(position);
View view = (convertView == null ? inflater.inflate(R.layout.newtab_quickaccess_item, parent, false) : convertView);
TextView tv = (TextView) view.findViewById(R.id.newtab_quickaccess_text);
if (entry.chan != null) {
tv.setText(entry.boardName == null ?
entry.chan.getDisplayingName() : resources.getString(R.string.boardslist_format, entry.boardName, entry.boardDescription));
tv.setCompoundDrawablesWithIntrinsicBounds(entry.chan.getChanFavicon(), null, null, null);
tv.setCompoundDrawablePadding(drawablePadding);
} else {
tv.setText(R.string.newtab_quickaccess_all_boards);
tv.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
}
View dragHandler = view.findViewById(R.id.newtab_quickaccess_drag_handle);
dragHandler.getLayoutParams().width = position == draggingItem ? ViewGroup.LayoutParams.WRAP_CONTENT : 0;
dragHandler.setLayoutParams(dragHandler.getLayoutParams());
return view;
}
private void setUpTitle() {
requestWindowFeature(Window.FEATURE_NO_TITLE);
Drawable icon = getContext().getResources().getDrawable(R.drawable.twitter_icon);
mTitle = new TextView(getContext());
mTitle.setText("Twitter");
mTitle.setTextColor(Color.WHITE);
mTitle.setTypeface(Typeface.DEFAULT_BOLD);
mTitle.setBackgroundColor(0xFFbbd7e9);
mTitle.setPadding(MARGIN + PADDING, MARGIN, MARGIN, MARGIN);
mTitle.setCompoundDrawablePadding(MARGIN + PADDING);
mTitle.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
mContent.addView(mTitle);
}
/**
* 设置TextView(@+id/snackbar_text)左右两侧的图片
* @param leftDrawable
* @param rightDrawable
* @return
*/
public SnackbarUtils leftAndRightDrawable(@Nullable Drawable leftDrawable, @Nullable Drawable rightDrawable){
if(getSnackbar()!=null){
TextView message = (TextView) getSnackbar().getView().findViewById(R.id.snackbar_text);
LinearLayout.LayoutParams paramsMessage = (LinearLayout.LayoutParams) message.getLayoutParams();
paramsMessage = new LinearLayout.LayoutParams(paramsMessage.width, paramsMessage.height,0.0f);
message.setLayoutParams(paramsMessage);
message.setCompoundDrawablePadding(message.getPaddingLeft());
int textSize = (int) message.getTextSize();
Log.e("Jet","textSize:"+textSize);
if(leftDrawable!=null){
leftDrawable.setBounds(0,0,textSize,textSize);
}
if(rightDrawable!=null){
rightDrawable.setBounds(0,0,textSize,textSize);
}
message.setCompoundDrawables(leftDrawable,null,rightDrawable,null);
LinearLayout.LayoutParams paramsSpace = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT,1.0f);
((SweetSnackbar.SnackbarLayout)getSnackbar().getView()).addView(new Space(getSnackbar().getView().getContext()),1,paramsSpace);
}
return this;
}
/**
* Sets title and icon of provider
*
*/
private void setUpTitle() {
requestWindowFeature(Window.FEATURE_NO_TITLE);
mTitle = new TextView(getContext());
int res = getContext().getResources().getIdentifier(mProviderName.toString(), "drawable",
getContext().getPackageName());
icon = getContext().getResources().getDrawable(res);
StringBuilder sb = new StringBuilder();
sb.append(mProviderName.toString().substring(0, 1).toUpperCase());
sb.append(mProviderName.toString().substring(1, mProviderName.toString().length()));
mTitle.setText(sb.toString());
mTitle.setGravity(Gravity.CENTER_VERTICAL);
mTitle.setTextColor(Color.WHITE);
mTitle.setTypeface(Typeface.DEFAULT_BOLD);
mTitle.setBackgroundColor(BLUE);
mTitle.setPadding(MARGIN + PADDING, MARGIN, MARGIN, MARGIN);
mTitle.setCompoundDrawablePadding(MARGIN + PADDING);
mTitle.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
if (!titleStatus)
mContent.addView(mTitle);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final DialogMenuItem item = dialogMenuItemList.get(position);
TextView menuItemView = new TextView(context);
menuItemView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
menuItemView.setSingleLine(true);
menuItemView.setTextColor(contentTextColor);
menuItemView.setTextSize(TypedValue.COMPLEX_UNIT_SP, contentTextSize);
menuItemView.setBackgroundDrawable(getButtonBackground(false, false, false));
if (item.icon != 0) {
Drawable drawable = context.getResources().getDrawable(item.icon);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
menuItemView.setCompoundDrawables(drawable, null, null, null);
menuItemView.setCompoundDrawablePadding(dp2px(5));
}
menuItemView.setPadding(dp2px(3), dp2px(3), dp2px(3), dp2px(3));
menuItemView.setText(item.itemName);
return menuItemView;
}
public TextView createListItem() {
TextView view = new TextView(mContext);
view.setFadingEdgeLength(mFadeEdgeLength);
view.setHorizontalFadingEdgeEnabled(true);
view.setSingleLine();
view.setTextSize(TEXT_SIZE_SP);
view.setMinimumHeight(mListItemHeight);
view.setGravity(Gravity.CENTER_VERTICAL);
view.setCompoundDrawablePadding(mPadding);
if (!mIsLayoutDirectionRTL) {
view.setPadding(mPadding, 0, mPadding + mFadePadding , 0);
} else {
view.setPadding(mPadding + mFadePadding, 0, mPadding, 0);
}
return view;
}
private TextView newTextView() {
TextView textView = new TextView(getContext());
textView.setLayoutParams(new LayoutParams(-1, -1, 16));
textView.setCompoundDrawablePadding(10);
textView.setPadding(10, 0, 0, 0);
textView.setGravity(16);
textView.setLines(2);
textView.setEllipsize(TruncateAt.END);
textView.setTextColor(Color.parseColor("#FFFFFF"));
textView.setTextSize(1, 14.0f);
return textView;
}
public DrawerAddCell(Context context) {
super(context);
textView = new TextView(context);
textView.setTextColor(Theme.getColor(Theme.key_chats_menuItemText));
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
textView.setLines(1);
textView.setMaxLines(1);
textView.setSingleLine(true);
textView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
textView.setCompoundDrawablePadding(AndroidUtilities.dp(34));
addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 23, 0, 16, 0));
}
private void showDirectoryPicker() {
final Item[] items = new Item[files.size() + 2];
for(int i = 0;i<files.size();i++){
items[i + 2] = new Item(files.get(i).getName(), R.drawable.ic_action_collection);
}
items[0] = new Item(path.getAbsolutePath(), R.drawable.ic_pgmp_launcher);
//items[0] = new Item(activity.getResources().getString(R.string.directorydialoghere), R.drawable.ic_pgmp_launcher);
items[1] = new Item(activity.getResources().getString(R.string.directorydialogup), android.R.drawable.ic_menu_upload);
ListAdapter adapter = new ArrayAdapter<Item>(
activity,
android.R.layout.select_dialog_item,
android.R.id.text1, items){
public View getView(int position, View convertView, ViewGroup parent) {
//User super class to create the View
View v = super.getView(position, convertView, parent);
TextView tv = (TextView)v.findViewById(android.R.id.text1);
//Put the image on the TextView
tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0);
//Add margin between image and text (support various screen densities)
int dp5 = (int) (5 * activity.getResources().getDisplayMetrics().density + 0.5f);
tv.setCompoundDrawablePadding(dp5);
return v;
}
};
new AlertDialog.Builder(activity).setTitle(activity.getResources().getString(R.string.directorydialogprompt))
.setIcon(android.R.drawable.ic_menu_zoom)
.setAdapter(adapter, this).show();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
IconContextMenuItem item = (IconContextMenuItem) getItem(position);
Resources res = parentActivity.getResources();
if (convertView == null) {
TextView temp = new TextView(context);
AbsListView.LayoutParams param = new AbsListView.LayoutParams(AbsListView.LayoutParams.FILL_PARENT,
AbsListView.LayoutParams.WRAP_CONTENT);
temp.setLayoutParams(param);
temp.setPadding((int)toPixel(res, 20), 2, (int)toPixel(res, 20), 2);
temp.setGravity(android.view.Gravity.CENTER_VERTICAL);
Theme th = context.getTheme();
TypedValue tv = new TypedValue();
if (th.resolveAttribute(android.R.attr.textAppearanceLargeInverse, tv, true)) {
temp.setTextAppearance(context, tv.resourceId);
}
temp.setMinHeight(LIST_PREFERED_HEIGHT);
temp.setCompoundDrawablePadding((int)toPixel(res, 14));
convertView = temp;
}
TextView textView = (TextView) convertView;
textView.setTag(item);
textView.setText(item.text);
textView.setTextColor(Color.WHITE);
textView.setTypeface(typeface);
Bitmap bitmap = ((BitmapDrawable) item.image).getBitmap();
Drawable d = new BitmapDrawable(parent.getResources(), Bitmap.createScaledBitmap(bitmap, LIST_PREFERED_HEIGHT, LIST_PREFERED_HEIGHT, true));
textView.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);
return textView;
}
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;
}
public PickerBottomLayout(Context context, boolean darkTheme) {
super(context);
isDarkTheme = darkTheme;
setBackgroundColor(isDarkTheme ? 0xff1a1a1a : 0xffffffff);
cancelButton = new TextView(context);
cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
cancelButton.setTextColor(isDarkTheme ? 0xffffffff : 0xff007aff);
cancelButton.setGravity(Gravity.CENTER);
cancelButton.setBackgroundDrawable(
Theme.createBarSelectorDrawable(isDarkTheme ? Theme.ACTION_BAR_PICKER_SELECTOR_COLOR
: Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, false));
cancelButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0);
cancelButton.setText(R.string.Preview);
// cancelButton.getPaint().setFakeBoldText(true);
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.createBarSelectorDrawable(isDarkTheme ? Theme.ACTION_BAR_PICKER_SELECTOR_COLOR
: Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, false));
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.getPaint().setFakeBoldText(true);
doneButtonBadgeTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
doneButtonBadgeTextView.setTextColor(0xffffffff);
doneButtonBadgeTextView.setGravity(Gravity.CENTER);
doneButtonBadgeTextView.setBackgroundResource(
isDarkTheme ? R.drawable.photobadge_new : R.drawable.photobadge_new);
doneButtonBadgeTextView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8),
AndroidUtilities.dp(1));
doneButton.addView(doneButtonBadgeTextView,
LayoutHelper.createLinear(26, 26, Gravity.CENTER_VERTICAL, 0, 0, 10, 0));
doneButtonTextView = new TextView(context);
doneButtonTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
doneButtonTextView.setTextColor(isDarkTheme ? 0xffffffff : 0xff007aff);
doneButtonTextView.setGravity(Gravity.CENTER);
doneButtonTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8));
doneButtonTextView.setText(R.string.Send);
// doneButtonTextView.getPaint().setFakeBoldText(true);
doneButton.addView(doneButtonTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL));
}
@Override
protected void initView(int layoutID) {
super.initView(layoutID);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (null != getSupportActionBar()) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
mCheckNearby = getView(R.id.check_nearby);
mEditSearch = getView(R.id.edit_search);
mGridHot = getView(R.id.grid_hot);
mListResult = getView(R.id.list_result);
mListHistory = getView(R.id.list_history);
mLayMyCity = getView(R.id.lay_my_city);
mTextCity = getView(R.id.text_city);
mRecycleCity = getView(R.id.recycler_city);
TextView textHeader = new TextView(this);
textHeader.setText("历史记录");
textHeader.setPadding(AppUtils.dip2Px(this, 10), AppUtils.dip2Px(this, 10), AppUtils.dip2Px(this, 10), AppUtils.dip2Px(this, 10));
textHeader.setTextColor(Color.parseColor("#999999"));
textHeader.setTextSize(12);
Drawable drawable = getResources().getDrawable(R.drawable.ic_history_18dp);
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
textHeader.setCompoundDrawables(drawable, null, null, null);
textHeader.setCompoundDrawablePadding(AppUtils.dip2Px(this, 5));
mListHistory.addHeaderView(textHeader, null, false);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
mRecycleCity.setLayoutManager(layoutManager);
mTextCity.setOnClickListener(this);
mEditSearch.setOnEditorActionListener(this);
mEditSearch.addTextChangedListener(this);
mListResult.setOnLoadMoreListener(this);
mListResult.setOnItemClickListener(this);
mListHistory.setOnItemClickListener(this);
mGridHot.setOnItemClickListener(this);
mCheckNearby.setOnClickListener(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
webBox = findViewById(R.id.web);
webBox.setOnEditorActionListener(this);
ImageButton go = findViewById(R.id.go);
go.setOnClickListener(this);
if ((browserManager = (BrowserManager) getFragmentManager().findFragmentByTag("BM")) == null) {
getFragmentManager().beginTransaction().add(browserManager = new BrowserManager(),
"BM").commit();
}
// ATTENTION: This was auto-generated to handle app links.
Intent appLinkIntent = getIntent();
//String appLinkAction = appLinkIntent.getAction();
appLinkData = appLinkIntent.getData();
layout = findViewById(R.id.drawer);
ImageView menu = findViewById(R.id.menuButton);
menu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
layout.openDrawer(GravityCompat.START);
}
});
ListView listView = findViewById(R.id.menu);
String[] menuItems = new String[]{"Home", "Browser", "Downloads", "Bookmarks",
"History", "About", "Options"};
ArrayAdapter listAdapter = new ArrayAdapter<String>(this, android.R.layout
.simple_list_item_1, menuItems) {
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView textView = view.findViewById(android.R.id.text1);
textView.setTextColor(Color.WHITE);
int iconId = 0;
switch (position) {
case 0:
iconId = R.drawable.ic_home_white_24dp;
break;
case 1:
iconId = R.drawable.ic_globe_white_24dp;
break;
case 2:
iconId = R.drawable.ic_download_white_24dp;
break;
case 3:
iconId = R.drawable.ic_star_white_24dp;
break;
case 4:
iconId = R.drawable.ic_history_white_24dp;
break;
case 5:
iconId = R.drawable.ic_info_outline_white_24dp;
break;
case 6:
iconId = R.drawable.ic_settings_white_24dp;
}
if (iconId != 0) {
Drawable icon = AppCompatResources.getDrawable(getContext(), iconId);
textView.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
textView.setCompoundDrawablePadding((int) (16 * getResources().getDisplayMetrics().density));
}
return view;
}
};
listView.setAdapter(listAdapter);
listView.setOnItemClickListener(this);
RecyclerView videoSites = findViewById(R.id.homeSites);
videoSites.setAdapter(new VideoStreamingSitesList(this));
videoSites.setLayoutManager(new LinearLayoutManager(this));
}
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));
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = super.getView(position, convertView, parent);
TextView tv = (TextView) v.findViewById(android.R.id.text1);
Object handler = getItem(position);
int iconSize = UIHelpers.dpToPx(32, getContext());
if (handler instanceof IOrganization) {
IOrganization org = (IOrganization) handler;
tv.setText(org.organizationName);
//todo load the org's icon from bundle or remote site
//Drawable icon = a.getResources().getDrawable(
// R.drawable.ic_share_iba);
//icon.setBounds(0, 0, iconSize, iconSize);
//tv.setCompoundDrawables(icon, null, null, null);
tv.setCompoundDrawablePadding(UIHelpers.dpToPx(10, getContext()));
} else if (handler instanceof HandlerIntent) {
HandlerIntent handlerIntent = (HandlerIntent) handler;
ResolveInfo info = handlerIntent.resolveInfo;
PackageManager pm = getContext().getPackageManager();
tv.setText(info.loadLabel(pm));
Drawable icon = info.loadIcon(pm);
icon.setBounds(0, 0, iconSize, iconSize);
// Put the image on the TextView
tv.setCompoundDrawables(icon, null, null, null);
tv.setCompoundDrawablePadding(UIHelpers.dpToPx(10, getContext()));
}
// Add margin between image and text (support various screen
// densities)
int dp5 = (int) (5 * a.getResources().getDisplayMetrics().density + 0.5f);
tv.setCompoundDrawablePadding(dp5);
return v;
}
void updateFlowLayout(RecurrenceOption recurrenceOption) {
// Currently selected recurrence option
int viewIdToSelect;
switch (recurrenceOption) {
case DOES_NOT_REPEAT:
viewIdToSelect = R.id.tvDoesNotRepeat;
break;
case DAILY:
viewIdToSelect = R.id.tvDaily;
break;
case WEEKLY:
viewIdToSelect = R.id.tvWeekly;
break;
case MONTHLY:
viewIdToSelect = R.id.tvMonthly;
break;
case YEARLY:
viewIdToSelect = R.id.tvYearly;
break;
case CUSTOM:
viewIdToSelect = R.id.tvChosenCustomOption;
break;
default:
viewIdToSelect = R.id.tvDoesNotRepeat;
}
for (TextView tv : mRepeatOptionTextViews) {
tv.setOnClickListener(this);
// If we have a non-empty recurrence rule,
// display it for easy re-selection
if (tv.getId() == R.id.tvChosenCustomOption) {
if (!TextUtils.isEmpty(mRecurrenceRule)) {
EventRecurrence eventRecurrence = new EventRecurrence();
eventRecurrence.parse(mRecurrenceRule);
Time startDate = new Time(TimeZone.getDefault().getID());
startDate.set(mCurrentlyChosenTime);
eventRecurrence.setStartDate(startDate);
tv.setVisibility(View.VISIBLE);
tv.setText(EventRecurrenceFormatter.getRepeatString(
getContext(), getContext().getResources(),
eventRecurrence, true));
} else { // hide this TextView since 'mRecurrenceRule' is not available
tv.setVisibility(View.GONE);
continue;
}
}
// Selected option
if (tv.getId() == viewIdToSelect) {
// Set checkmark drawable & drawable-padding
tv.setCompoundDrawablesWithIntrinsicBounds(null, null,
mCheckmarkDrawable, null);
tv.setCompoundDrawablePadding(mSelectedOptionDrawablePadding);
tv.setTextColor(mSelectedStateTextColor);
continue;
}
// Unselected options
tv.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
tv.setTextColor(mUnselectedStateTextColor);
}
}
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));
}