android.widget.ProgressBar#getProgressDrawable ( )源码实例Demo

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

private void setColor(ProgressBar progressBar) {
  Drawable drawable;
  if (progressBar.isIndeterminate()) {
    drawable = progressBar.getIndeterminateDrawable();
  } else {
    drawable = progressBar.getProgressDrawable();
  }

  if (drawable == null) {
    return;
  }

  if (mColor != null) {
    drawable.setColorFilter(mColor, PorterDuff.Mode.SRC_IN);
  } else {
    drawable.clearColorFilter();
  }
}
 
private void setColor(ProgressBar progressBar) {
  Drawable drawable;
  if (progressBar.isIndeterminate()) {
    drawable = progressBar.getIndeterminateDrawable();
  } else {
    drawable = progressBar.getProgressDrawable();
  }

  if (drawable == null) {
    return;
  }

  if (mColor != null) {
    drawable.setColorFilter(mColor, PorterDuff.Mode.SRC_IN);
  } else {
    drawable.clearColorFilter();
  }
}
 
源代码3 项目: andela-crypto-app   文件: Easel.java
public static void tint(@NonNull ProgressBar progressBar, @ColorInt int color, boolean skipIndeterminate) {
    ColorStateList sl = ColorStateList.valueOf(color);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        progressBar.setProgressTintList(sl);
        progressBar.setSecondaryProgressTintList(sl);
        if (!skipIndeterminate)
            progressBar.setIndeterminateTintList(sl);
    } else {
        PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
            mode = PorterDuff.Mode.MULTIPLY;
        }
        if (!skipIndeterminate && progressBar.getIndeterminateDrawable() != null)
            progressBar.getIndeterminateDrawable().setColorFilter(color, mode);
        if (progressBar.getProgressDrawable() != null)
            progressBar.getProgressDrawable().setColorFilter(color, mode);
    }
}
 
源代码4 项目: NewsMe   文件: MDTintHelper.java
public static void setTint(@NonNull ProgressBar progressBar, @ColorInt int color, boolean skipIndeterminate) {
    ColorStateList sl = ColorStateList.valueOf(color);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        progressBar.setProgressTintList(sl);
        progressBar.setSecondaryProgressTintList(sl);
        if (!skipIndeterminate)
            progressBar.setIndeterminateTintList(sl);
    } else {
        PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
            mode = PorterDuff.Mode.MULTIPLY;
        }
        if (!skipIndeterminate && progressBar.getIndeterminateDrawable() != null)
            progressBar.getIndeterminateDrawable().setColorFilter(color, mode);
        if (progressBar.getProgressDrawable() != null)
            progressBar.getProgressDrawable().setColorFilter(color, mode);
    }
}
 
源代码5 项目: talk-android   文件: MDTintHelper.java
@SuppressLint("NewApi")
public static void setTint(ProgressBar progressBar, int color, boolean skipIndeterminate) {
    ColorStateList sl = ColorStateList.valueOf(color);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        progressBar.setProgressTintList(sl);
        progressBar.setSecondaryProgressTintList(sl);
        if (!skipIndeterminate)
            progressBar.setIndeterminateTintList(sl);
    } else {
        PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
            mode = PorterDuff.Mode.MULTIPLY;
        }
        if (!skipIndeterminate && progressBar.getIndeterminateDrawable() != null)
            progressBar.getIndeterminateDrawable().setColorFilter(color, mode);
        if (progressBar.getProgressDrawable() != null)
            progressBar.getProgressDrawable().setColorFilter(color, mode);
    }
}
 
源代码6 项目: APlayer   文件: TintHelper.java
public static void setTint(@NonNull ProgressBar progressBar, @ColorInt int color,
    boolean skipIndeterminate) {
  ColorStateList sl = ColorStateList.valueOf(color);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    progressBar.setProgressTintList(sl);
    progressBar.setSecondaryProgressTintList(sl);
    if (!skipIndeterminate) {
      progressBar.setIndeterminateTintList(sl);
    }
  } else {
    PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
      mode = PorterDuff.Mode.MULTIPLY;
    }
    if (!skipIndeterminate && progressBar.getIndeterminateDrawable() != null) {
      progressBar.getIndeterminateDrawable().setColorFilter(color, mode);
    }
    if (progressBar.getProgressDrawable() != null) {
      progressBar.getProgressDrawable().setColorFilter(color, mode);
    }
  }
}
 
源代码7 项目: AndroidTint   文件: EmTintUtils.java
public static void setTint(@NonNull ProgressBar progressBar, @ColorInt int color, boolean skipIndeterminate) {
    ColorStateList sl = ColorStateList.valueOf(color);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        progressBar.setProgressTintList(sl);
        progressBar.setSecondaryProgressTintList(sl);
        if (!skipIndeterminate)
            progressBar.setIndeterminateTintList(sl);
    } else {
        PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
            mode = PorterDuff.Mode.MULTIPLY;
        }
        if (!skipIndeterminate && progressBar.getIndeterminateDrawable() != null)
            progressBar.getIndeterminateDrawable().setColorFilter(color, mode);
        if (progressBar.getProgressDrawable() != null)
            progressBar.getProgressDrawable().setColorFilter(color, mode);
    }
}
 
源代码8 项目: a   文件: TintHelper.java
public static void setTint(@NonNull ProgressBar progressBar, @ColorInt int color, boolean skipIndeterminate) {
    ColorStateList sl = ColorStateList.valueOf(color);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        progressBar.setProgressTintList(sl);
        progressBar.setSecondaryProgressTintList(sl);
        if (!skipIndeterminate)
            progressBar.setIndeterminateTintList(sl);
    } else {
        PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
        if (!skipIndeterminate && progressBar.getIndeterminateDrawable() != null)
            progressBar.getIndeterminateDrawable().setColorFilter(color, mode);
        if (progressBar.getProgressDrawable() != null)
            progressBar.getProgressDrawable().setColorFilter(color, mode);
    }
}
 
源代码9 项目: MyBookshelf   文件: TintHelper.java
public static void setTint(@NonNull ProgressBar progressBar, @ColorInt int color, boolean skipIndeterminate) {
    ColorStateList sl = ColorStateList.valueOf(color);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        progressBar.setProgressTintList(sl);
        progressBar.setSecondaryProgressTintList(sl);
        if (!skipIndeterminate)
            progressBar.setIndeterminateTintList(sl);
    } else {
        PorterDuff.Mode mode = PorterDuff.Mode.SRC_IN;
        if (!skipIndeterminate && progressBar.getIndeterminateDrawable() != null)
            progressBar.getIndeterminateDrawable().setColorFilter(color, mode);
        if (progressBar.getProgressDrawable() != null)
            progressBar.getProgressDrawable().setColorFilter(color, mode);
    }
}
 
源代码10 项目: Noyze   文件: UberVolumePanel.java
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public void onCreate() {
    super.onCreate();
    Context context = getContext();
    transition = TransitionCompat.get();

    boolean darkColor = ColorPreference.isColorDark(color);
    int theme = (darkColor) ? android.R.style.Theme_Holo_Light : android.R.style.Theme_Holo;
    Context themeContext = new ContextThemeWrapper(context, theme);
    context.getApplicationContext().setTheme(theme);
    LayoutInflater inflater = LayoutInflater.from(themeContext);
    FrameLayout parent = new FrameLayout(themeContext);
    root = (ViewGroup) inflater.inflate(R.layout.uber_volume_adjust, parent, false);
    context.getApplicationContext().setTheme(R.style.AppTheme);

    visiblePanel = (ViewGroup) root.findViewById(R.id.visible_panel);
    seekBar = (ProgressBar) root.findViewById(android.R.id.progress);
    spinner = (Spinner) root.findViewById(R.id.stream_icon);
    album = (ImageView) root.findViewById(R.id.album_art);
    artist = (TextView) root.findViewById(R.id.track_artist);
    song = (TextView) root.findViewById(R.id.track_song);
    musicPanel = (ViewGroup) root.findViewById(R.id.music_panel);
    divider = root.findViewById(R.id.divider);
    playPause = (ImageButton) root.findViewById(R.id.media_play_pause);
    mBtnNext = (ImageButton) root.findViewById(R.id.media_next);

    album.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openMusic();
        }
    });

    LayerDrawable layer = (LayerDrawable) seekBar.getProgressDrawable();
    layer.findDrawableByLayerId(android.R.id.progress).mutate()
            .setColorFilter(HeadsUpVolumePanel._COLOR, PorterDuff.Mode.MULTIPLY);
    attachPlaybackListeners(root, new MediaButtonClickListener());

    toggleSeekBar(seek);
    setEnableMarquee(true);

    initSpinner();
    updateMediaIcons();

    transition.beginDelayedTransition((ViewGroup) root.findViewById(R.id.slider_group));
    mLayout = root;
}
 
源代码11 项目: Jockey   文件: MiniplayerFragment.java
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {

    FragmentMiniplayerBinding mBinding = FragmentMiniplayerBinding.inflate(inflater, container, false);
    MiniplayerViewModel viewModel = new MiniplayerViewModel(getContext(), mPlayerController);

    mPlayerController.getNowPlaying()
            .compose(bindToLifecycle())
            .subscribe(viewModel::setSong, throwable -> {
                Timber.e(throwable, "Failed to set song");
            });

    mPlayerController.isPlaying()
            .compose(bindToLifecycle())
            .subscribe(viewModel::setPlaying, throwable -> {
                Timber.e(throwable, "Failed to set playing state");
            });

    mPlayerController.getCurrentPosition()
            .compose(bindToLifecycle())
            .subscribe(viewModel::setCurrentPosition, throwable -> {
                Timber.e(throwable, "Failed to set progress");
            });

    mPlayerController.getDuration()
            .compose(bindToLifecycle())
            .subscribe(viewModel::setDuration, throwable -> {
                Timber.e(throwable, "Failed to set duration");
            });

    mPlayerController.getArtwork()
            .compose(bindToLifecycle())
            .map(artwork -> {
                if (artwork == null) {
                    return ViewUtils.drawableToBitmap(
                            ContextCompat.getDrawable(getContext(), R.drawable.art_default));
                } else {
                    return artwork;
                }
            })
            .subscribe(viewModel::setArtwork, throwable -> {
                Timber.e(throwable, "Failed to set artwork");
            });

    mBinding.setViewModel(viewModel);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        ProgressBar progressBar = mBinding.miniplayerProgress;
        LayerDrawable progressBarDrawable = (LayerDrawable) progressBar.getProgressDrawable();

        Drawable progress = progressBarDrawable.findDrawableByLayerId(android.R.id.progress);
        progress.setColorFilter(mThemeStore.getAccentColor(), PorterDuff.Mode.SRC_ATOP);
    }

    return mBinding.getRoot();
}
 
源代码12 项目: Noyze   文件: UberVolumePanel.java
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public void onCreate() {
    super.onCreate();
    Context context = getContext();
    transition = TransitionCompat.get();

    boolean darkColor = ColorPreference.isColorDark(color);
    int theme = (darkColor) ? android.R.style.Theme_Holo_Light : android.R.style.Theme_Holo;
    Context themeContext = new ContextThemeWrapper(context, theme);
    context.getApplicationContext().setTheme(theme);
    LayoutInflater inflater = LayoutInflater.from(themeContext);
    FrameLayout parent = new FrameLayout(themeContext);
    root = (ViewGroup) inflater.inflate(R.layout.uber_volume_adjust, parent, false);
    context.getApplicationContext().setTheme(R.style.AppTheme);

    visiblePanel = (ViewGroup) root.findViewById(R.id.visible_panel);
    seekBar = (ProgressBar) root.findViewById(android.R.id.progress);
    spinner = (Spinner) root.findViewById(R.id.stream_icon);
    album = (ImageView) root.findViewById(R.id.album_art);
    artist = (TextView) root.findViewById(R.id.track_artist);
    song = (TextView) root.findViewById(R.id.track_song);
    musicPanel = (ViewGroup) root.findViewById(R.id.music_panel);
    divider = root.findViewById(R.id.divider);
    playPause = (ImageButton) root.findViewById(R.id.media_play_pause);
    mBtnNext = (ImageButton) root.findViewById(R.id.media_next);

    album.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openMusic();
        }
    });

    LayerDrawable layer = (LayerDrawable) seekBar.getProgressDrawable();
    layer.findDrawableByLayerId(android.R.id.progress).mutate()
            .setColorFilter(HeadsUpVolumePanel._COLOR, PorterDuff.Mode.MULTIPLY);
    attachPlaybackListeners(root, new MediaButtonClickListener());

    toggleSeekBar(seek);
    setEnableMarquee(true);

    initSpinner();
    updateMediaIcons();

    transition.beginDelayedTransition((ViewGroup) root.findViewById(R.id.slider_group));
    mLayout = root;
}