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

The following examples show how to use android.widget.ProgressBar#getIndeterminateDrawable() . 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: ProgressSpec.java    From litho with Apache License 2.0 6 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext c,
    ProgressBar progressBar,
    @Prop(optional = true, resType = ResType.COLOR) int color,
    @FromPrepare Drawable resolvedIndeterminateDrawable) {

  if (resolvedIndeterminateDrawable != null) {
    progressBar.setIndeterminateDrawable(resolvedIndeterminateDrawable);
  }

  if (color != Color.TRANSPARENT && progressBar.getIndeterminateDrawable() != null) {
    progressBar
        .getIndeterminateDrawable()
        .mutate()
        .setColorFilter(color, PorterDuff.Mode.MULTIPLY);
  }
}
 
Example 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
Source File: ProgressSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnUnmount
static void onUnmount(
    ComponentContext c,
    ProgressBar progressBar,
    @Prop(optional = true, resType = ResType.COLOR) int color,
    @FromPrepare Drawable resolvedIndeterminateDrawable) {

  // restore the color first, since it acts on the indeterminateDrawable
  if (color != Color.TRANSPARENT && progressBar.getIndeterminateDrawable() != null) {
    progressBar.getIndeterminateDrawable().mutate().clearColorFilter();
  }

  progressBar.setIndeterminateDrawable(null);
}
 
Example 12
Source File: LoadingFragment.java    From leanback-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
	View view = inflater.inflate(R.layout.fragment_loading, container, false);

	FrameLayout loadingContainer = (FrameLayout) view.findViewById(R.id.fragment_loading_container);
	loadingContainer.setBackgroundColor(backgroundColor);

	progressBar = new ProgressBar(container.getContext());
	if (container instanceof FrameLayout) {
		FrameLayout.LayoutParams layoutParams =
				new FrameLayout.LayoutParams(progressWidth, progressHeight, Gravity.CENTER);
		progressBar.setLayoutParams(layoutParams);
	}

	if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
		if (progressBar.getIndeterminateDrawable() != null) {
			progressBar.getIndeterminateDrawable().setColorFilter(getResources().getColor(progressColor),
					PorterDuff.Mode.SRC_IN);
		}
	} else {
		ColorStateList stateList = ColorStateList.valueOf(progressColor);
		progressBar.setIndeterminateTintMode(PorterDuff.Mode.SRC_IN);
		progressBar.setIndeterminateTintList(stateList);
		progressBar.setProgressBackgroundTintMode(PorterDuff.Mode.SRC_IN);
		progressBar.setProgressBackgroundTintList(stateList);
		progressBar.setIndeterminate(true);
	}

	loadingContainer.addView(progressBar);

	return view;
}