use of com.waz.zclient.ui.theme.OptionsLightTheme in project wire-android by wireapp.
the class OptionsMenu method setMenuItems.
public void setMenuItems(List<OptionsMenuItem> optionsMenuItems, @NonNull final OptionsTheme optionsTheme) {
titleTextView.setTextColor(optionsTheme.getTextColorPrimary());
backgroundView.setBackgroundColor(optionsTheme.getOverlayColor());
//important that items are in order
Collections.sort(optionsMenuItems);
// add regular items
menuLayout.removeAllViews();
final int rows = (int) Math.ceil(optionsMenuItems.size() / 3f);
int itemNumber = 0;
for (int i = 0; i < rows; i++) {
LinearLayout row = new LinearLayout(getContext());
row.setOrientation(LinearLayout.HORIZONTAL);
row.setGravity(Gravity.CENTER);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
//int sideMargin = getResources().getDimensionPixelSize(R.dimen.options_menu_row_side_margin);
int topMargin = getResources().getDimensionPixelSize(R.dimen.options_menu_row_top_margin);
params.setMargins(0, topMargin, 0, 0);
row.setLayoutParams(params);
while (row.getChildCount() < MAX_ITEMS_PER_ROW) {
if (itemNumber >= optionsMenuItems.size()) {
break;
}
//logic for keeping the first row at 2 items if there are 4/5 total
if ((optionsMenuItems.size() == TOTAL_ITEMS_FIVE || optionsMenuItems.size() == TOTAL_ITEMS_FOUR) && i == 0 && row.getChildCount() == MAX_ITEMS_PER_ROW - 1) {
break;
}
final OptionsMenuItem item = optionsMenuItems.get(itemNumber);
final View optionsMenuItemContainer = LayoutInflater.from(getContext()).inflate(R.layout.options_menu__item, this, false);
final FrameLayout optionsMenuButton = ViewUtils.getView(optionsMenuItemContainer, R.id.fl_options_menu_button);
final GlyphTextView optionsMenuItemGlyph = ViewUtils.getView(optionsMenuItemContainer, R.id.gtv__options_menu_button__glyph);
optionsMenuItemGlyph.setText(item.resGlyphId);
final TextView optionsMenuItemText = ViewUtils.getView(optionsMenuItemContainer, R.id.ttv__settings_box__item);
optionsMenuItemText.setText(item.resTextId);
optionsMenuItemText.setTextColor(optionsTheme.getTextColorPrimary());
if (item.isToggled()) {
if (optionsTheme.getType() == OptionsTheme.Type.DARK) {
optionsMenuItemGlyph.setTextColor(new OptionsLightTheme(getContext()).getTextColorPrimarySelector());
optionsMenuButton.setBackground(getResources().getDrawable(R.drawable.selector__icon_button__background__dark_toggled));
} else {
optionsMenuItemGlyph.setTextColor(new OptionsDarkTheme(getContext()).getTextColorPrimarySelector());
optionsMenuButton.setBackground(getResources().getDrawable(R.drawable.selector__icon_button__background__light_toggled));
}
} else {
if (optionsTheme.getType() == OptionsTheme.Type.DARK) {
optionsMenuButton.setBackground(getResources().getDrawable(R.drawable.selector__icon_button__background__dark));
} else {
optionsMenuButton.setBackground(getResources().getDrawable(R.drawable.selector__icon_button__background__light));
}
optionsMenuItemGlyph.setTextColor(optionsTheme.getTextColorPrimarySelector());
}
optionsMenuItemText.setTextColor(optionsTheme.getTextColorPrimarySelector());
optionsMenuItemContainer.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
notifyOptionsMenuItemClicked(item);
}
});
optionsMenuItemContainer.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return notifyOptionsMenuItemLongClicked(item);
}
});
row.addView(optionsMenuItemContainer);
itemNumber++;
}
menuLayout.addView(row);
}
//set cancel button
cancelView.setText(getResources().getString(R.string.confirmation_menu__cancel));
cancelView.setTextColor(optionsTheme.getTextColorPrimarySelector());
cancelView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
close();
}
});
menuLayout.addView(cancelView);
notifyOptionsMenuStateHasChanged(State.CLOSED);
setVisibility(View.INVISIBLE);
}
Aggregations