android.graphics.drawable.LevelListDrawable Java Examples

The following examples show how to use android.graphics.drawable.LevelListDrawable. 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: 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 #2
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 #3
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 #4
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 #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: RspMsgItemView.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
protected void init(Context mContext) {
    LayoutInflater iflater = LayoutInflater.from(mContext);
    iflater.inflate(R.layout.common_bubble_dialog_left, this);
    mTextView = (TextView) findViewById(R.id.common_bubble_left_text);
    mTextView.setOnTouchListener(this);
    mListDrawable = (LevelListDrawable) mTextView.getBackground();
}
 
Example #7
Source File: ChooseSetPopupWindow.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(ChooseSetAdapter.SetHolder holder, int position) {
    int page = position + 1;
    LevelListDrawable ld = (LevelListDrawable) holder.mTvSetCount.getBackground();
    if (page == currentPage) {
        ld.setLevel(1);
        holder.mTvSetCount.setTextColor(mContext.getResources().getColor(R.color.white));
    } else {
        ld.setLevel(0);
        holder.mTvSetCount.setTextColor(mContext.getResources().getColor(R.color.new_text_color_first));
    }
    setText(holder.mTvSetCount, page);
}
 
Example #8
Source File: RealTimeUpdateSearchBox.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
private void init(AttributeSet attrs, int defStyle) {
    // Load attributes
    final TypedArray a = getContext().obtainStyledAttributes(
            attrs, R.styleable.lingju, defStyle, 0);
    LayoutInflater.from(getContext()).inflate(R.layout.search_online_box, this);
    mLlRoot = findViewById(R.id.ll_root);
    edit = (EditText) findViewById(R.id.sob_search_edit);
    stateBt = (ImageButton) findViewById(R.id.sob_state_bt);
    animate = AnimationUtils.loadAnimation(getContext(), R.anim.start_up_loading);
    animate.setInterpolator(new LinearInterpolator());
    drawable = (LevelListDrawable) stateBt.getDrawable();
    edit.addTextChangedListener(searhWatcher);
    edit.setOnEditorActionListener(editorActionListener);
    edit.setOnClickListener(editorClickListener);
    stateBt.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (stateBt.getVisibility() == View.VISIBLE && drawable.getLevel() == 1) {
                edit.setText("");
                stateBt.setVisibility(View.INVISIBLE);
            }
        }
    });
    edit.setHint(a.getString(R.styleable.lingju_hint));
    // edit.setHintTextColor(getResources().getColor(R.color.navi_search_box_color));
    edit.setHintTextColor(a.getColor(R.styleable.lingju_hintColor, getResources().getColor(R.color.navi_search_box_color)));
    edit.setTextColor(a.getColor(R.styleable.lingju_textColor, getResources().getColor(R.color.ksw_md_solid_disable)));
    mLlRoot.setBackgroundColor(a.getColor(R.styleable.lingju_search_background, getResources().getColor(R.color.green_style)));
    //edit.setTextSize(a.getFloat(com.android.internal.R.styleable.TextView_textSize,12));

    a.recycle();
}
 
Example #9
Source File: DrawableValue.java    From proteus with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(ProteusView view, Context context, ProteusLayoutInflater.ImageLoader loader, Callback callback) {
  final LevelListDrawable levelListDrawable = new LevelListDrawable();
  for (Level level : levels) {
    level.apply(view, levelListDrawable);
  }
}
 
Example #10
Source File: ChatListAdapter.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
@OnClick({R.id.tv_subscribe, R.id.tv_choose_set, R.id.ll_play_track_box, R.id.iv_ting_switch})
public void onClick(View view) {
    TingAlbumMsg albumMsg = (TingAlbumMsg) datas.get(getAdapterPosition());
    Album album = albumMsg.getAlbums().get(0);
    switch (view.getId()) {
        case R.id.tv_subscribe:
            LevelListDrawable ld = (LevelListDrawable) mTvSubscribe.getBackground();
            if (ld.getLevel() == 0) {      //订阅
                ld.setLevel(1);
                mTvSubscribe.setText("已订阅");
                TingAlbumDao.getInstance().insertSubscribe(album);
            } else {
                ld.setLevel(0);
                mTvSubscribe.setText("订阅");
                TingAlbumDao.getInstance().delSubscribeById(album.getId());
            }
            break;
        case R.id.tv_choose_set:
            Intent intent = new Intent(mContext, TingAlbumDetailActivity.class);
            intent.putExtra(TingAlbumDetailActivity.ALBUM_ID, album.getId());
            int type = album.getCoverUrlMiddle().contains(TingPlayProcessor.KAOLA_FM) ? TingAlbumDetailActivity.KAOLA : TingAlbumDetailActivity.XIMALAYA;
            intent.putExtra(TingAlbumDetailActivity.ALBUM_TYPE, type);
            mContext.startActivity(intent);
            ((Activity) mContext).overridePendingTransition(R.anim.activity_start_in, R.anim.activity_start_out);
            break;
        case R.id.ll_play_track_box:
        case R.id.iv_ting_switch:
            boolean isPlaying = XmlyManager.get().isPlaying();
            if (isPlaying) {
                XmPlayerManager.getInstance(mContext).pause();
            } else {
                XmPlayerManager.getInstance(mContext).play();
            }
            break;
    }
}
 
Example #11
Source File: TrafficShowPresenter.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
@Override
public Object instantiateItem(ViewGroup container, int position) {
    Log.i(TAG, "instantiateItem>>>" + position);
    View child = chilren.get(position);
    if (child == null) {
        child = inflater.inflate(R.layout.target_poi_item_detail, null);
        chilren.put(position, child);
    }
    child.findViewById(R.id.tpid_target_confirm_bt).setOnClickListener(clickListener);
    child.findViewById(R.id.tpid_target_confirm_bt).setTag(position);
    ((TextView) child.findViewById(R.id.tpid_name_text)).setText((position + 1) + "." + aList.get(position).getName());
    ((TextView) child.findViewById(R.id.tpid_address_text)).setText(aList.get(position).getAddress());
    Double distance = DistanceUtil.getDistance(new LatLng(address.getLatitude(), address.getLongitude()),
            poiInfoList.get(position).location) / 1000;
    ((TextView) child.findViewById(R.id.tpid_distance_text)).setText(String.format("%.1f", distance) + "km");
    child.findViewById(R.id.tpid_set_target_bt).setOnClickListener(clickListener);
    child.findViewById(R.id.tpid_set_target_bt).setTag(position);
    TextView ft = (TextView) child.findViewById(R.id.tpid_favorite_bt);
    ft.setOnClickListener(clickListener);
    ft.setTag(position);
    if (aList.get(position).getFavoritedTime() != null) {
        ft.setText("已收藏");
        ((LevelListDrawable) ft.getBackground()).setLevel(1);
    }
    container.addView(child, 0);
    return chilren.get(position);
}
 
Example #12
Source File: GuideActivity.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
public void setDot(int position) {
    mBeginBt.setVisibility(View.GONE);
    for (int i = 0; i < mllDot.getChildCount(); i++) {
        View dotView = mllDot.getChildAt(i);
        LevelListDrawable ld = (LevelListDrawable) dotView.getBackground();
        ld.setLevel(position == i ? 1 : 0);
    }
}
 
Example #13
Source File: TingAlbumDetailAdapter.java    From AssistantBySDK with Apache License 2.0 4 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (position == 0) {
        HeaderHolder headerHolder = (HeaderHolder) holder;
        //专辑详情
        Glide.with(mContext).load(mAlbum.getCoverUrlMiddle()).into(headerHolder.mIvAlbum);
        headerHolder.mTvAlbumTitle.setText(mAlbum.getAlbumTitle());
        LastUpTrack lastUptrack = mAlbum.getLastUptrack();
        StringBuilder sb = new StringBuilder();
        headerHolder.mTvLastTrack.setText(sb.append("更新至").append(TimeUtils.formatDate(new Date(lastUptrack.getCreatedAt()))).append("  ").append(lastUptrack.getTrackTitle()).toString());
        sb.setLength(0);
        headerHolder.mTvPlayCount.setText(sb.append(StringUtils.formPlayCount(mAlbum.getPlayCount())).append("次播放").toString());
        sb.setLength(0);
        headerHolder.mTvTrackCount.setText(sb.append(mAlbum.getIncludeTrackCount()).append("集").toString());
        //订阅状态
        boolean isSubscribe = mAlbumDao.isSubscribe(mAlbumId);
        headerHolder.mTvSubscribe.setText(isSubscribe ? "已订阅" : "订阅");
        LevelListDrawable ld = (LevelListDrawable) headerHolder.mTvSubscribe.getBackground();
        ld.setLevel(isSubscribe ? 1 : 0);

        if (mHistory != null) {
            headerHolder.mRlHistoryBox.setVisibility(View.VISIBLE);
            sb.setLength(0);
            headerHolder.mTvHistoryTitle.setText(sb.append("继续播放:").append(mHistory.getTrackTitle()).toString());
            sb.setLength(0);
            NumberFormat nf = NumberFormat.getPercentInstance();
            //返回数的整数部分所允许的最大位数
            nf.setMaximumIntegerDigits(3);
            //返回数的小数部分所允许的最大位数
            nf.setMaximumFractionDigits(0);
            headerHolder.mTvProgress.setText(sb.append("已播  ").append(nf.format(mHistory.getBreakPos() / (double) mHistory.getDuration())).toString());
            headerHolder.mIvTingSwitch.setImageLevel((XmlyManager.get().isPlaying() && playTrackId == mHistory.getTrackId()) ? 1 : 0);
        } else {
            headerHolder.mRlHistoryBox.setVisibility(View.GONE);
        }

    } else {
        Track track = mTracks.get(position);
        TrackDetailHolder detailHolder = (TrackDetailHolder) holder;
        detailHolder.mTvTrackTitle.setText(track.getTrackTitle());
        detailHolder.mTvTrackTitle.setTextColor(track.getDataId() == playTrackId
                ? mContext.getResources().getColor(R.color.second_base_color)
                : mContext.getResources().getColor(R.color.new_text_color_first));
        detailHolder.mIvTingSwitch.setImageLevel(0);
        if (track.getDataId() == playTrackId)
            detailHolder.mIvTingSwitch.setImageLevel(XmlyManager.get().isPlaying() ? 1 : 0);
        detailHolder.mTvCreated.setText(TimeUtils.getInstance().getDateString(new Date(track.getCreatedAt())));
        detailHolder.mTvDuration.setText(new SimpleDate().formDuration(track.getDuration()));
    }
}
 
Example #14
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));
}
 
Example #15
Source File: ImageViewSensorAnimationBehavior.java    From science-journal with Apache License 2.0 4 votes vote down vote up
private Drawable getLevelDrawable(Context context) {
  LevelListDrawable drawable =
      (LevelListDrawable) context.getResources().getDrawable(levelDrawableId);
  drawable.setLevel(0);
  return drawable;
}
 
Example #16
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 #17
Source File: PlayerHeaderFragment.java    From AssistantBySDK with Apache License 2.0 4 votes vote down vote up
private void updatePlayBar(boolean playing) {
    LevelListDrawable drawable = (LevelListDrawable) mPlayBt.getDrawable();
    drawable.setLevel(playing ? 0 : 1);
}
 
Example #18
Source File: AccountingEditActivity.java    From AssistantBySDK with Apache License 2.0 4 votes vote down vote up
@Override
public void switchAccountType(int type) {
    LevelListDrawable ld = (LevelListDrawable) mAibType1.getBackground();
    ld.setLevel(type);
}
 
Example #19
Source File: RepoParser.java    From EdXposedManager with GNU General Public License v3.0 4 votes vote down vote up
ImageGetterAsyncTask(Context context, String source, LevelListDrawable levelListDrawable) {
    this.context = context;
    this.source = source;
    this.levelListDrawable = levelListDrawable;
}