下面列出了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();
}
}
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);
}
}
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);
}
}
@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);
}
}
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);
}
}
}
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);
}
}
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);
}
}
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);
}
}
@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;
}
@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();
}
@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;
}