android.graphics.drawable.LevelListDrawable#addLevel()源码实例Demo

下面列出了android.graphics.drawable.LevelListDrawable#addLevel() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: home-assistant-Android   文件: SwitchViewHolder.java
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);
    }
}
 
源代码2 项目: delion   文件: RecentTabsGroupView.java
@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);
}
 
源代码3 项目: AndroidChromium   文件: RecentTabsGroupView.java
@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);
}
 
源代码4 项目: 365browser   文件: RecentTabsGroupView.java
@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);
}
 
源代码5 项目: 1Rramp-Android   文件: TextViewImageGetter.java
@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;
}
 
源代码6 项目: Folivora   文件: DrawableParser.java
@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;
}
 
源代码7 项目: proteus   文件: DrawableValue.java
public void apply(ProteusView view, final LevelListDrawable levelListDrawable) {
  levelListDrawable.addLevel(minLevel, maxLevel, DrawableResourceProcessor.evaluate(drawable, view));
}