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

The following examples show how to use android.graphics.drawable.LevelListDrawable#setLevel() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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;
}