Java Code Examples for android.graphics.drawable.GradientDrawable#setColorFilter()

The following examples show how to use android.graphics.drawable.GradientDrawable#setColorFilter() . 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: GuidanceStreetLabelView.java    From msdkui-android with Apache License 2.0 5 votes vote down vote up
/**
 * Refresh the view to re-calculate the radius of view.
 */
public void refresh()  {
    Drawable backgroundDrawable = getBackground();
    if (backgroundDrawable instanceof GradientDrawable) {
        GradientDrawable drawable = (GradientDrawable) backgroundDrawable;
        post(() -> drawable.setCornerRadius(getHeight() >> 1));
        drawable.setColorFilter(mGuidanceStreetLabelData.getBackgroundColor(), PorterDuff.Mode.SRC);
    }
}
 
Example 2
Source File: RecentMostPlayController.java    From Musicoco with Apache License 2.0 5 votes vote down vote up
private void updateColors(@NonNull int[] colors) {

        int startC = colors[0];
        int endC = colors[2];

        GradientDrawable drawable = new GradientDrawable(
                GradientDrawable.Orientation.LEFT_RIGHT,
                new int[]{startC, endC});
        mContainer.setBackground(drawable);

        drawable.setAlpha(170);
        int colorFilter = 0;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
            colorFilter = activity.getColor(R.color.main_rmp_image_filter);
        } else {
            colorFilter = activity.getResources().getColor(R.color.main_rmp_image_filter);
        }

        drawable.setColorFilter(colorFilter, PorterDuff.Mode.MULTIPLY);
        mInfoContainer.setBackground(drawable);


        int textC = colors[3];
        int textBC = colors[0];
        GradientDrawable td = new GradientDrawable();
        td.setColor(textBC);
        td.setCornerRadius(mArts.getHeight() / 2);
        mArts.setBackground(td);
        mArts.setTextColor(textC);

    }
 
Example 3
Source File: SdkUtils.java    From box-android-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the the background thumb color for the account view to one of the material colors
 *
 * @param initialsView view where the thumbs will be shown
 */
public static void setColorsThumb(TextView initialsView, int backgroundColor, int strokeColor) {
    GradientDrawable drawable = (GradientDrawable) initialsView.getResources().getDrawable(R.drawable.boxsdk_thumb_background);
    drawable.setColorFilter(backgroundColor, PorterDuff.Mode.MULTIPLY);
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        drawable.setStroke(3, strokeColor);
        initialsView.setBackground(drawable);
    } else {
        drawable.setStroke(3, strokeColor);
        initialsView.setBackgroundDrawable(drawable);
    }
}
 
Example 4
Source File: MainActivity.java    From Torch with GNU General Public License v3.0 4 votes vote down vote up
private void setFlashOn() {

        String mPrefColor = mPreferences.getString(SettingsActivity.KEY_COLOR, getString(R.string.red));
        Boolean mPrefScreen = mPreferences.getBoolean(SettingsActivity.KEY_SCREEN, false);
        Boolean mPrefDevice = mPreferences.getBoolean("mPrefDevice", false);
        Boolean mPrefBright = mPreferences.getBoolean("mPrefBright", false);

        Window mWindow = getWindow();
        WindowManager.LayoutParams mSettings = mWindow.getAttributes();
        GradientDrawable mShape = (GradientDrawable) mImageViewShape.getDrawable();

        if (mImageViewShape == null) {
            return;
        }
        if (!mPrefDevice||mPrefScreen) {
            hideSystemUi(mImageViewOff);
            mWindow.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            mSettings.screenBrightness = 1f; // Set 100% brightness
            if (mPrefBright) {
                mShape.setColorFilter(Utils.getPrefColor(mContext, mPrefColor), PorterDuff.Mode.SRC_ATOP);
            } else {
                mShape.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
            }
            getWindow().setAttributes(mSettings);
            mImageViewOff.animate()
                    .alpha(0f)
                    .setDuration(DEMI_DURATION);
        } else {
            mImageViewOn.animate()
                    .alpha(1f)
                    .setStartDelay(DEMI_DURATION)
                    .setDuration(DEMI_DURATION);
            mImageViewOff.animate()
                    .alpha(0f)
                    .setDuration(DEMI_DURATION);
        }
        if (mFullScreenScale <= 0.0f) {
            mFullScreenScale = getMeasureScale();
        }
        mImageViewShape.animate()
                .scaleX(mFullScreenScale)
                .scaleY(mFullScreenScale)
                .setDuration(ANIMATION_DURATION);
    }