@Override
    public boolean onCreateActionMode(ActionMode mode, Menu menu) {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow()
            .setStatusBarColor(
                UIUtils.getThemeColorFromAttrOrRes(
                    BRTDrawerActivity.this,
                    R.attr.colorPrimaryDark,
                    R.color.material_drawer_primary_dark));
      }

      mode.getMenuInflater().inflate(R.menu.cab, menu);
      return true;
    }
Beispiel #2
0
  @Override
  public View convertView(LayoutInflater inflater, View convertView, ViewGroup parent) {
    Context ctx = parent.getContext();

    // get the viewHolder
    ViewHolder viewHolder;
    if (convertView == null) {
      convertView = inflater.inflate(getLayoutRes(), parent, false);
      viewHolder = new ViewHolder(convertView);
      convertView.setTag(viewHolder);
    } else {
      viewHolder = (ViewHolder) convertView.getTag();
    }

    // get the correct color for the background
    int selectedColor =
        UIUtils.decideColor(
            ctx,
            getSelectedColor(),
            getSelectedColorRes(),
            R.attr.material_drawer_selected,
            R.color.material_drawer_selected);
    // get the correct color for the text
    int color;
    if (this.isEnabled()) {
      color =
          UIUtils.decideColor(
              ctx,
              getTextColor(),
              getTextColorRes(),
              R.attr.material_drawer_secondary_text,
              R.color.material_drawer_secondary_text);
    } else {
      color =
          UIUtils.decideColor(
              ctx,
              getDisabledTextColor(),
              getDisabledTextColorRes(),
              R.attr.material_drawer_hint_text,
              R.color.material_drawer_hint_text);
    }
    int selectedTextColor =
        UIUtils.decideColor(
            ctx,
            getSelectedTextColor(),
            getSelectedTextColorRes(),
            R.attr.material_drawer_selected_text,
            R.color.material_drawer_selected_text);
    // get the correct color for the icon
    int iconColor;
    if (this.isEnabled()) {
      iconColor =
          UIUtils.decideColor(
              ctx,
              getIconColor(),
              getIconColorRes(),
              R.attr.material_drawer_primary_icon,
              R.color.material_drawer_primary_icon);
    } else {
      iconColor =
          UIUtils.decideColor(
              ctx,
              getDisabledIconColor(),
              getDisabledIconColorRes(),
              R.attr.material_drawer_hint_text,
              R.color.material_drawer_hint_text);
    }
    int selectedIconColor =
        UIUtils.decideColor(
            ctx,
            getSelectedIconColor(),
            getSelectedColorRes(),
            R.attr.material_drawer_selected_text,
            R.color.material_drawer_selected_text);

    // set the background for the item
    UIUtils.setBackground(viewHolder.view, UIUtils.getDrawerItemBackground(selectedColor));

    // set the text for the name
    if (this.getNameRes() != -1) {
      viewHolder.name.setText(this.getNameRes());
    } else {
      viewHolder.name.setText(this.getName());
    }

    // set the text for the badge or hide
    if (getBadge() != null) {
      viewHolder.badge.setText(getBadge());
      viewHolder.badge.setVisibility(View.VISIBLE);
    } else {
      viewHolder.badge.setVisibility(View.GONE);
    }

    // set the colors for textViews
    viewHolder.name.setTextColor(UIUtils.getTextColorStateList(color, selectedTextColor));
    if (badgeTextColor != 0) {
      viewHolder.badge.setTextColor(badgeTextColor);
    } else {
      viewHolder.badge.setTextColor(UIUtils.getTextColorStateList(color, selectedTextColor));
    }

    // define the typeface for our textViews
    if (getTypeface() != null) {
      viewHolder.name.setTypeface(getTypeface());
      viewHolder.badge.setTypeface(getTypeface());
    }

    // get the drawables for our icon
    Drawable icon =
        UIUtils.decideIcon(ctx, getIcon(), getIIcon(), getIconRes(), iconColor, isIconTinted());
    Drawable selectedIcon =
        UIUtils.decideIcon(
            ctx,
            getSelectedIcon(),
            getIIcon(),
            getSelectedIconRes(),
            selectedIconColor,
            isIconTinted());

    // if we have an icon then we want to set it
    if (icon != null) {
      // if we got a different color for the selectedIcon we need a StateList
      if (selectedIcon != null) {
        viewHolder.icon.setImageDrawable(UIUtils.getIconStateList(icon, selectedIcon));
      } else if (isIconTinted()) {
        viewHolder.icon.setImageDrawable(
            new PressedEffectStateListDrawable(icon, iconColor, selectedIconColor));
      } else {
        viewHolder.icon.setImageDrawable(icon);
      }
      // make sure we display the icon
      viewHolder.icon.setVisibility(View.VISIBLE);
    } else {
      // hide the icon
      viewHolder.icon.setVisibility(View.GONE);
    }

    return convertView;
  }