Java Code Examples for android.widget.ProgressBar#getProgressDrawable()

The following examples show how to use android.widget.ProgressBar#getProgressDrawable() . 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: ProgressBarContainerView.java    From progress-bar-android with MIT License 6 votes vote down vote up
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();
  }
}
 
Example 2
Source File: ProgressBarContainerView.java    From react-native-GPay with MIT License 6 votes vote down vote up
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();
  }
}
 
Example 3
Source File: Easel.java    From andela-crypto-app with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 4
Source File: MDTintHelper.java    From NewsMe with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 5
Source File: MDTintHelper.java    From talk-android with MIT License 6 votes vote down vote up
@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);
    }
}
 
Example 6
Source File: TintHelper.java    From APlayer with GNU General Public License v3.0 6 votes vote down vote up
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);
    }
  }
}
 
Example 7
Source File: EmTintUtils.java    From AndroidTint with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 8
Source File: TintHelper.java    From a with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example 9
Source File: TintHelper.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example 10
Source File: UberVolumePanel.java    From Noyze with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 11
Source File: MiniplayerFragment.java    From Jockey with Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example 12
Source File: UberVolumePanel.java    From Noyze with Apache License 2.0 4 votes vote down vote up
@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;
}