Java Code Examples for android.graphics.drawable.LevelListDrawable#addLevel()

The following examples show how to use android.graphics.drawable.LevelListDrawable#addLevel() . 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 File: SwitchViewHolder.java    From home-assistant-Android with GNU General Public License v3.0 6 votes vote down vote up
private void updateColor() {
    Drawable leftDrawable = name.getCompoundDrawablesRelative()[0];
    String domain = entity.getDomain();
    if (leftDrawable != null && (domain.equals(LIGHT) || domain.equals(SWITCH))) {
        if (!(leftDrawable instanceof LevelListDrawable)) {
            LevelListDrawable levelListDrawable = new LevelListDrawable();
            // Add states
            levelListDrawable.addLevel(1, 1, leftDrawable);
            BitmapDrawable enabledDrawable = (BitmapDrawable) leftDrawable.getConstantState().newDrawable().mutate();
            enabledDrawable.setTintList(ColorStateList.valueOf(ContextCompat.getColor(name.getContext(), R.color.color_activated)));
            levelListDrawable.addLevel(2, 2, enabledDrawable);
            // Restore bounds
            levelListDrawable.setBounds(0, 0, name.getResources().getDimensionPixelSize(R.dimen.icon_size), name.getResources().getDimensionPixelSize(R.dimen.icon_size));

            // Set drawable
            name.setCompoundDrawablesRelative(levelListDrawable, null, null, null);
            leftDrawable = levelListDrawable;
        }
        leftDrawable.setLevel(entity.state.equals(HassUtils.getOnState(entity, false)) ? 1 : 2);
    }
}
 
Example 2
Source File: RecentTabsGroupView.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void onFinishInflate() {
    super.onFinishInflate();
    mDeviceIcon = (ImageView) findViewById(R.id.device_icon);
    mTimeLabel = (TextView) findViewById(R.id.time_label);
    mDeviceLabel = (TextView) findViewById(R.id.device_label);
    mExpandCollapseIcon = (ImageView) findViewById(R.id.expand_collapse_icon);

    // Create drawable for expand/collapse arrow.
    LevelListDrawable collapseIcon = new LevelListDrawable();
    collapseIcon.addLevel(DRAWABLE_LEVEL_COLLAPSED, DRAWABLE_LEVEL_COLLAPSED,
            TintedDrawable.constructTintedDrawable(getResources(), R.drawable.ic_expanded));
    TintedDrawable collapse =
            TintedDrawable.constructTintedDrawable(getResources(), R.drawable.ic_collapsed);
    collapse.setTint(
            ApiCompatibilityUtils.getColorStateList(getResources(), R.color.blue_mode_tint));
    collapseIcon.addLevel(DRAWABLE_LEVEL_EXPANDED, DRAWABLE_LEVEL_EXPANDED, collapse);
    mExpandCollapseIcon.setImageDrawable(collapseIcon);
}
 
Example 3
Source File: RecentTabsGroupView.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void onFinishInflate() {
    super.onFinishInflate();
    mDeviceIcon = (ImageView) findViewById(R.id.device_icon);
    mTimeLabel = (TextView) findViewById(R.id.time_label);
    mDeviceLabel = (TextView) findViewById(R.id.device_label);
    mExpandCollapseIcon = (ImageView) findViewById(R.id.expand_collapse_icon);

    // Create drawable for expand/collapse arrow.
    LevelListDrawable collapseIcon = new LevelListDrawable();
    collapseIcon.addLevel(DRAWABLE_LEVEL_COLLAPSED, DRAWABLE_LEVEL_COLLAPSED,
            TintedDrawable.constructTintedDrawable(getResources(), R.drawable.ic_expanded));
    TintedDrawable collapse =
            TintedDrawable.constructTintedDrawable(getResources(), R.drawable.ic_collapsed);
    collapse.setTint(
            ApiCompatibilityUtils.getColorStateList(getResources(), R.color.blue_mode_tint));
    collapseIcon.addLevel(DRAWABLE_LEVEL_EXPANDED, DRAWABLE_LEVEL_EXPANDED, collapse);
    mExpandCollapseIcon.setImageDrawable(collapseIcon);
}
 
Example 4
Source File: RecentTabsGroupView.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onFinishInflate() {
    super.onFinishInflate();
    mDeviceIcon = (ImageView) findViewById(R.id.device_icon);
    mTimeLabel = (TextView) findViewById(R.id.time_label);
    mDeviceLabel = (TextView) findViewById(R.id.device_label);
    mExpandCollapseIcon = (ImageView) findViewById(R.id.expand_collapse_icon);

    // Create drawable for expand/collapse arrow.
    LevelListDrawable collapseIcon = new LevelListDrawable();
    collapseIcon.addLevel(DRAWABLE_LEVEL_COLLAPSED, DRAWABLE_LEVEL_COLLAPSED,
            TintedDrawable.constructTintedDrawable(getResources(), R.drawable.ic_expanded));
    TintedDrawable collapse =
            TintedDrawable.constructTintedDrawable(getResources(), R.drawable.ic_collapsed);
    collapse.setTint(
            ApiCompatibilityUtils.getColorStateList(getResources(), R.color.blue_mode_tint));
    collapseIcon.addLevel(DRAWABLE_LEVEL_EXPANDED, DRAWABLE_LEVEL_EXPANDED, collapse);
    mExpandCollapseIcon.setImageDrawable(collapseIcon);
}
 
Example 5
Source File: TextViewImageGetter.java    From 1Rramp-Android with MIT License 5 votes vote down vote up
@Override
public Drawable getDrawable(String source) {
  LevelListDrawable d = new LevelListDrawable();
  Drawable empty = context.getResources().getDrawable(R.drawable.hapcoin_icon_bg);
  d.addLevel(0, 0, empty);
  d.setBounds(0, 0, empty.getIntrinsicWidth(), empty.getIntrinsicHeight());
  new LoadImage().execute(source, d);
  return d;
}
 
Example 6
Source File: DrawableParser.java    From Folivora with Apache License 2.0 4 votes vote down vote up
@Override
public Drawable parse(ParseRequest request) {
  final Context ctx = request.context();
  final AttributeSet attrs = request.attrs();
  LevelListDrawable lld = new LevelListDrawable();
  TypedArray a = ctx.obtainStyledAttributes(attrs, R.styleable.Folivora_Level);
  if (a.hasValue(R.styleable.Folivora_Level_levelItem0Drawable)) {
    lld.addLevel(
      a.getInt(R.styleable.Folivora_Level_levelItem0MinLevel, 0),
      a.getInt(R.styleable.Folivora_Level_levelItem0MaxLevel, 0),
      getDrawable(ctx, a, attrs, R.styleable.Folivora_Level_levelItem0Drawable)
    );
  }
  if (a.hasValue(R.styleable.Folivora_Level_levelItem1Drawable)) {
    lld.addLevel(
      a.getInt(R.styleable.Folivora_Level_levelItem1MinLevel, 0),
      a.getInt(R.styleable.Folivora_Level_levelItem1MaxLevel, 0),
      getDrawable(ctx, a, attrs, R.styleable.Folivora_Level_levelItem1Drawable)
    );
  }
  if (a.hasValue(R.styleable.Folivora_Level_levelItem2Drawable)) {
    lld.addLevel(
      a.getInt(R.styleable.Folivora_Level_levelItem2MinLevel, 0),
      a.getInt(R.styleable.Folivora_Level_levelItem2MaxLevel, 0),
      getDrawable(ctx, a, attrs, R.styleable.Folivora_Level_levelItem2Drawable)
    );
  }
  if (a.hasValue(R.styleable.Folivora_Level_levelItem3Drawable)) {
    lld.addLevel(
      a.getInt(R.styleable.Folivora_Level_levelItem3MinLevel, 0),
      a.getInt(R.styleable.Folivora_Level_levelItem3MaxLevel, 0),
      getDrawable(ctx, a, attrs, R.styleable.Folivora_Level_levelItem3Drawable)
    );
  }
  if (a.hasValue(R.styleable.Folivora_Level_levelItem4Drawable)) {
    lld.addLevel(
      a.getInt(R.styleable.Folivora_Level_levelItem4MinLevel, 0),
      a.getInt(R.styleable.Folivora_Level_levelItem4MaxLevel, 0),
      getDrawable(ctx, a, attrs, R.styleable.Folivora_Level_levelItem4Drawable)
    );
  }
  lld.setLevel(a.getInt(R.styleable.Folivora_Level_levelCurrentLevel, 0));
  a.recycle();
  return lld;
}
 
Example 7
Source File: DrawableValue.java    From proteus with Apache License 2.0 4 votes vote down vote up
public void apply(ProteusView view, final LevelListDrawable levelListDrawable) {
  levelListDrawable.addLevel(minLevel, maxLevel, DrawableResourceProcessor.evaluate(drawable, view));
}