android.support.v4.graphics.ColorUtils Java Examples

The following examples show how to use android.support.v4.graphics.ColorUtils. 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: ImmersionBar.java    From ImmersionBar with Apache License 2.0 6 votes vote down vote up
/**
 * 变色view
 * Transform view.
 */
private void transformView() {
    if (mBarParams.viewMap.size() != 0) {
        Set<Map.Entry<View, Map<Integer, Integer>>> entrySet = mBarParams.viewMap.entrySet();
        for (Map.Entry<View, Map<Integer, Integer>> entry : entrySet) {
            View view = entry.getKey();
            Map<Integer, Integer> map = entry.getValue();
            Integer colorBefore = mBarParams.statusBarColor;
            Integer colorAfter = mBarParams.statusBarColorTransform;
            for (Map.Entry<Integer, Integer> integerEntry : map.entrySet()) {
                colorBefore = integerEntry.getKey();
                colorAfter = integerEntry.getValue();
            }
            if (view != null) {
                if (Math.abs(mBarParams.viewAlpha - 0.0f) == 0) {
                    view.setBackgroundColor(ColorUtils.blendARGB(colorBefore, colorAfter, mBarParams.statusBarAlpha));
                } else {
                    view.setBackgroundColor(ColorUtils.blendARGB(colorBefore, colorAfter, mBarParams.viewAlpha));
                }
            }
        }
    }
}
 
Example #2
Source File: TestFragment.java    From glide-support with The Unlicense 6 votes vote down vote up
@Override public void onBindViewHolder(final ImageTextViewHolder holder, int position) {
	// reset color so it looks like the view was just inflated even if it was recycled
	// this is to prevent inheriting another position's colors
	holder.card.setCardBackgroundColor(defaultColor);
	holder.titleView.setBackgroundColor(defaultColor);
	holder.titleView.setTextColor(ColorUtils.setAlphaComponent(~defaultColor, 0xFF));
	String url = data.get(position);
	holder.titleView.setText(String.valueOf(url)); // explicitly show null
	if (url != null) { // simulate an optional url from the data item
		holder.imageView.setVisibility(View.VISIBLE);
		glideRequest
				.load(url)
				.into(holder.target);
	} else {
		// clear when no image is shown, don't use holder.imageView.setImageDrawable(null) to do the same
		Glide.clear(holder.imageView);
		holder.imageView.setVisibility(View.GONE);
	}
}
 
Example #3
Source File: ExtractedColors.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
/**
 * The hotseat's color is defined as follows:
 * - 12% black for super light wallpaper
 * - 18% white for super dark
 * - 25% white otherwise
 */
void updateHotseatPalette(Palette hotseatPalette) {
    int hotseatColor;
    int vibrantColor;

    if (hotseatPalette != null) {

        int extractedVibrantColor = hotseatPalette.getVibrantColor(ExtractedColors.DEFAULT_COLOR);
        if (ExtractionUtils.isSuperLight(hotseatPalette)) {
            hotseatColor = ColorUtils.setAlphaComponent(Color.BLACK, (int) (0.12f * 255));
            vibrantColor = ColorUtils.setAlphaComponent(extractedVibrantColor, (int) (0.12f * 255));

        } else if (ExtractionUtils.isSuperDark(hotseatPalette)) {
            hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.18f * 255));
            vibrantColor = ColorUtils.setAlphaComponent(extractedVibrantColor, (int) (0.18f * 255));
        } else {
            hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.25f * 255));
            vibrantColor = ColorUtils.setAlphaComponent(extractedVibrantColor, (int) (0.25f * 255));
        }
        setColorAtIndex(HOTSEAT_INDEX, hotseatColor);
        setColorAtIndex(VIBRANT_INDEX, vibrantColor);
    }
}
 
Example #4
Source File: IntroActivity.java    From Puff-Android with MIT License 6 votes vote down vote up
private void updateTaskDescription() {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
        String title = getTitle().toString();
        Drawable iconDrawable = getApplicationInfo().loadIcon(getPackageManager());
        Bitmap icon = iconDrawable instanceof BitmapDrawable ? ((BitmapDrawable) iconDrawable).getBitmap() : null;
        int colorPrimary;
        if (position < getCount()) {
            try {
                colorPrimary = ContextCompat.getColor(IntroActivity.this, getBackgroundDark(position));
            } catch (Resources.NotFoundException e) {
                colorPrimary = ContextCompat.getColor(IntroActivity.this, getBackground(position));
            }
        }
        else {
            TypedValue typedValue = new TypedValue();
            TypedArray a = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimary});
            colorPrimary = a.getColor(0, 0);
            a.recycle();
        }
        colorPrimary = ColorUtils.setAlphaComponent(colorPrimary, 0xFF);

        setTaskDescription(new ActivityManager.TaskDescription(title, icon, colorPrimary));
    }
}
 
Example #5
Source File: WidgetPreviewLoader.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
private RectF drawBoxWithShadow(Canvas c, Paint p, int width, int height) {
    Resources res = mContext.getResources();
    float shadowBlur = res.getDimension(R.dimen.widget_preview_shadow_blur);
    float keyShadowDistance = res.getDimension(R.dimen.widget_preview_key_shadow_distance);
    float corner = res.getDimension(R.dimen.widget_preview_corner_radius);

    RectF bounds = new RectF(shadowBlur, shadowBlur,
            width - shadowBlur, height - shadowBlur - keyShadowDistance);
    p.setColor(Color.WHITE);

    // Key shadow
    p.setShadowLayer(shadowBlur, 0, keyShadowDistance,
            ShadowGenerator.KEY_SHADOW_ALPHA << 24);
    c.drawRoundRect(bounds, corner, corner, p);

    // Ambient shadow
    p.setShadowLayer(shadowBlur, 0, 0,
            ColorUtils.setAlphaComponent(Color.BLACK, ShadowGenerator.AMBIENT_SHADOW_ALPHA));
    c.drawRoundRect(bounds, corner, corner, p);

    p.clearShadowLayer();
    return bounds;
}
 
Example #6
Source File: WelcomeActivity.java    From andela-crypto-app with Apache License 2.0 6 votes vote down vote up
private void updateTaskDescription(int position) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        String title = getTitle().toString();
        Drawable iconDrawable = getApplicationInfo().loadIcon(getPackageManager());
        Bitmap icon = iconDrawable instanceof BitmapDrawable
                ? ((BitmapDrawable) iconDrawable).getBitmap()
                : null;
        int colorPrimary;
        if (position < slidesAdapter.getCount()) {
            colorPrimary = ContextCompat.getColor(this,
                    slidesAdapter.slides.get(position).backgroundColor);
        } else {
            TypedValue typedValue = new TypedValue();
            TypedArray a = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimary});
            colorPrimary = a.getColor(0, 0);
            a.recycle();
        }
        colorPrimary = ColorUtils.setAlphaComponent(colorPrimary, 0xFF);
        setTaskDescription(new ActivityManager.TaskDescription(title, icon, colorPrimary));
    }
}
 
Example #7
Source File: IntroActivity.java    From Prodigal with Apache License 2.0 6 votes vote down vote up
private void updateTaskDescription() {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
        String title = getTitle().toString();
        Drawable iconDrawable = getApplicationInfo().loadIcon(getPackageManager());
        Bitmap icon = iconDrawable instanceof BitmapDrawable ? ((BitmapDrawable) iconDrawable).getBitmap() : null;
        int colorPrimary;
        if (position < getCount()) {
            try {
                colorPrimary = ContextCompat.getColor(IntroActivity.this, getBackgroundDark(position));
            } catch (Resources.NotFoundException e) {
                colorPrimary = ContextCompat.getColor(IntroActivity.this, getBackground(position));
            }
        }
        else {
            TypedValue typedValue = new TypedValue();
            TypedArray a = obtainStyledAttributes(typedValue.data, new int[]{R.attr.colorPrimary});
            colorPrimary = a.getColor(0, 0);
            a.recycle();
        }
        colorPrimary = ColorUtils.setAlphaComponent(colorPrimary, 0xFF);

        setTaskDescription(new ActivityManager.TaskDescription(title, icon, colorPrimary));
    }
}
 
Example #8
Source File: ImmersionBar.java    From MNImageBrowser with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 变色view
 * Transform view.
 */
private void transformView() {
    if (mBarParams.viewMap.size() != 0) {
        Set<Map.Entry<View, Map<Integer, Integer>>> entrySet = mBarParams.viewMap.entrySet();
        for (Map.Entry<View, Map<Integer, Integer>> entry : entrySet) {
            View view = entry.getKey();
            Map<Integer, Integer> map = entry.getValue();
            Integer colorBefore = mBarParams.statusBarColor;
            Integer colorAfter = mBarParams.statusBarColorTransform;
            for (Map.Entry<Integer, Integer> integerEntry : map.entrySet()) {
                colorBefore = integerEntry.getKey();
                colorAfter = integerEntry.getValue();
            }
            if (view != null) {
                if (Math.abs(mBarParams.viewAlpha - 0.0f) == 0) {
                    view.setBackgroundColor(ColorUtils.blendARGB(colorBefore, colorAfter, mBarParams.statusBarAlpha));
                } else {
                    view.setBackgroundColor(ColorUtils.blendARGB(colorBefore, colorAfter, mBarParams.viewAlpha));
                }
            }
        }
    }
}
 
Example #9
Source File: StatusBarUtils.java    From MNProgressHUD with Apache License 2.0 6 votes vote down vote up
/**
 * Flag只有在使用了FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
 * 并且没有使用 FLAG_TRANSLUCENT_STATUS 的时候才有效,也就是只有在状态栏全透明的时候才有效。
 *
 * @param window
 * @param bDark   bDark为true时是黑色的字,为false时是白色的字
 */
private static void setStatusBarModeDefault(Window window, boolean bDark) {
    //6.0以上
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (window == null) {
            return;
        }
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(ColorUtils.blendARGB(Color.TRANSPARENT, Color.BLACK, 0.0f));
        View decorView = window.getDecorView();
        if (decorView != null) {
            int vis = decorView.getSystemUiVisibility();
            vis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            if (bDark) {
                vis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
            } else {
                vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
            }
            decorView.setSystemUiVisibility(vis);
        }
    }
}
 
Example #10
Source File: PolygonOverlayActivity.java    From android-map-sdk with Apache License 2.0 6 votes vote down vote up
@Override
public void onMapReady(@NonNull NaverMap naverMap) {
    int color = ResourcesCompat.getColor(getResources(), R.color.primary, getTheme());

    PolygonOverlay polygon = new PolygonOverlay();
    polygon.setCoords(COORDS_1);
    polygon.setColor(ColorUtils.setAlphaComponent(color, 31));
    polygon.setOutlineColor(color);
    polygon.setOutlineWidth(getResources().getDimensionPixelSize(R.dimen.overlay_line_width));
    polygon.setMap(naverMap);

    PolygonOverlay polygonWithHole = new PolygonOverlay();
    polygonWithHole.setCoords(COORDS_2);
    polygonWithHole.setHoles(HOLES);
    polygonWithHole.setColor(
        ColorUtils.setAlphaComponent(ResourcesCompat.getColor(getResources(), R.color.gray, getTheme()), 127));
    polygonWithHole.setMap(naverMap);
}
 
Example #11
Source File: WorldMapView.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
public void themeViews(Context context, SuntimesTheme theme)
{
    options.backgroundColor = theme.getMapBackgroundColor();
    options.sunShadowColor = theme.getMapShadowColor();
    options.moonLightColor = theme.getMapHighlightColor();
    options.gridXColor = options.moonLightColor;
    options.gridYColor = options.moonLightColor;
    options.latitudeColors[0] = ColorUtils.setAlphaComponent(options.sunShadowColor, 255);
    options.latitudeColors[1] = ColorUtils.setAlphaComponent(options.moonLightColor, 255);
    options.latitudeColors[2] = ColorUtils.setAlphaComponent(options.moonLightColor, 255);
    options.locationFillColor = theme.getActionColor();
    options.sunFillColor = theme.getNoonIconColor();
    options.sunStrokeColor = theme.getNoonIconStrokeColor();
    options.moonFillColor = theme.getMoonFullColor();
    options.moonStrokeColor = theme.getMoonWaningColor();

    foregroundColor = theme.getMapForegroundColor();
    setMapMode(context, mode);    // options.foregroundColor is assigned with the mapMode
}
 
Example #12
Source File: ImmersionBar.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 变色view
 * <p>
 * Transform view.
 */
private void transformView() {
    if (mBarParams.viewMap.size() != 0) {
        Set<Map.Entry<View, Map<Integer, Integer>>> entrySet = mBarParams.viewMap.entrySet();
        for (Map.Entry<View, Map<Integer, Integer>> entry : entrySet) {
            View view = entry.getKey();
            Map<Integer, Integer> map = entry.getValue();
            Integer colorBefore = mBarParams.statusBarColor;
            Integer colorAfter = mBarParams.statusBarColorTransform;
            for (Map.Entry<Integer, Integer> integerEntry : map.entrySet()) {
                colorBefore = integerEntry.getKey();
                colorAfter = integerEntry.getValue();
            }
            if (view != null) {
                if (Math.abs(mBarParams.viewAlpha - 0.0f) == 0)
                    view.setBackgroundColor(ColorUtils.blendARGB(colorBefore, colorAfter, mBarParams.statusBarAlpha));
                else
                    view.setBackgroundColor(ColorUtils.blendARGB(colorBefore, colorAfter, mBarParams.viewAlpha));
            }
        }
    }
}
 
Example #13
Source File: ImmersionBar.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 设置一个可以自定义颜色的状态栏
 */
private void setupStatusBarView() {
    if (mBarParams.statusBarView == null) {
        mBarParams.statusBarView = new View(mActivity);
    }
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            mConfig.getStatusBarHeight());
    params.gravity = Gravity.TOP;
    mBarParams.statusBarView.setLayoutParams(params);
    if (mBarParams.statusBarFlag)
        mBarParams.statusBarView.setBackgroundColor(ColorUtils.blendARGB(mBarParams.statusBarColor,
                mBarParams.statusBarColorTransform, mBarParams.statusBarAlpha));
    else
        mBarParams.statusBarView.setBackgroundColor(ColorUtils.blendARGB(mBarParams.statusBarColor,
                Color.TRANSPARENT, mBarParams.statusBarAlpha));
    mBarParams.statusBarView.setVisibility(View.VISIBLE);
    ViewGroup viewGroup = (ViewGroup) mBarParams.statusBarView.getParent();
    if (viewGroup != null)
        viewGroup.removeView(mBarParams.statusBarView);
    mDecorView.addView(mBarParams.statusBarView);
}
 
Example #14
Source File: ImmersionBar.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 初始化android 5.0以上状态栏和导航栏
 *
 * @param uiFlags the ui flags
 * @return the int
 */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private int initBarAboveLOLLIPOP(int uiFlags) {
    uiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;  //Activity全屏显示,但状态栏不会被隐藏覆盖,状态栏依然可见,Activity顶端布局部分会被状态栏遮住。
    if (mBarParams.fullScreen && mBarParams.navigationBarEnable) {
        uiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; //Activity全屏显示,但导航栏不会被隐藏覆盖,导航栏依然可见,Activity底部布局部分会被导航栏遮住。
    }
    mWindow.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    if (mConfig.hasNavigtionBar()) {  //判断是否存在导航栏
        mWindow.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    }
    mWindow.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);  //需要设置这个才能设置状态栏颜色
    if (mBarParams.statusBarFlag)
        mWindow.setStatusBarColor(ColorUtils.blendARGB(mBarParams.statusBarColor,
                mBarParams.statusBarColorTransform, mBarParams.statusBarAlpha));  //设置状态栏颜色
    else
        mWindow.setStatusBarColor(ColorUtils.blendARGB(mBarParams.statusBarColor,
                Color.TRANSPARENT, mBarParams.statusBarAlpha));  //设置状态栏颜色
    if (mBarParams.navigationBarEnable)
        mWindow.setNavigationBarColor(ColorUtils.blendARGB(mBarParams.navigationBarColor,
                mBarParams.navigationBarColorTransform, mBarParams.navigationBarAlpha));  //设置导航栏颜色
    return uiFlags;
}
 
Example #15
Source File: ImmersionBar.java    From MNImageBrowser with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 解决布局与状态栏重叠问题,支持侧滑返回
 * Fits system windows int immersion bar.
 *
 * @param fits                  the fits
 * @param contentColor          the content color 整体界面背景色
 * @param contentColorTransform the content color transform 整体界面变换后的背景色
 * @param contentAlpha          the content alpha 整体界面透明度
 * @return the immersion bar
 */
public ImmersionBar fitsSystemWindowsInt(boolean fits, @ColorInt int contentColor
        , @ColorInt int contentColorTransform, @FloatRange(from = 0f, to = 1f) float contentAlpha) {
    mBarParams.fits = fits;
    mBarParams.contentColor = contentColor;
    mBarParams.contentColorTransform = contentColorTransform;
    mBarParams.contentAlpha = contentAlpha;
    if (mBarParams.fits) {
        if (mFitsStatusBarType == FLAG_FITS_DEFAULT) {
            mFitsStatusBarType = FLAG_FITS_SYSTEM_WINDOWS;
        }
    } else {
        mFitsStatusBarType = FLAG_FITS_DEFAULT;
    }
    mContentView.setBackgroundColor(ColorUtils.blendARGB(mBarParams.contentColor,
            mBarParams.contentColorTransform, mBarParams.contentAlpha));
    return this;
}
 
Example #16
Source File: NotificationController.java    From MiPushFramework with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param ctx context
 * @param pkg packageName
 * @return 0 if not processed
 */
public static int getIconColor(final Context ctx, final String pkg) {
    return IconCache.getInstance().getAppColor(ctx, pkg, (ctx1, iconBitmap) -> {
        if (iconBitmap == null) {
            return Notification.COLOR_DEFAULT;
        }
        int color = ColorUtil.getIconColor(iconBitmap);
        if (color != Notification.COLOR_DEFAULT) {
            final float[] hsl = new float[3];
            ColorUtils.colorToHSL(color, hsl);
            hsl[1] = 0.94f;
            hsl[2] = Math.min(hsl[2] * 0.6f, 0.31f);
            return ColorUtils.HSLToColor(hsl);
        } else {
            return Notification.COLOR_DEFAULT;
        }
    });
}
 
Example #17
Source File: ImmersionBar.java    From ImmersionBar with Apache License 2.0 6 votes vote down vote up
/**
 * 解决布局与状态栏重叠问题,支持侧滑返回
 * Fits system windows int immersion bar.
 *
 * @param fits                  the fits
 * @param contentColor          the content color 整体界面背景色
 * @param contentColorTransform the content color transform 整体界面变换后的背景色
 * @param contentAlpha          the content alpha 整体界面透明度
 * @return the immersion bar
 */
public ImmersionBar fitsSystemWindowsInt(boolean fits, @ColorInt int contentColor
        , @ColorInt int contentColorTransform, @FloatRange(from = 0f, to = 1f) float contentAlpha) {
    mBarParams.fits = fits;
    mBarParams.contentColor = contentColor;
    mBarParams.contentColorTransform = contentColorTransform;
    mBarParams.contentAlpha = contentAlpha;
    if (mBarParams.fits) {
        if (mFitsStatusBarType == FLAG_FITS_DEFAULT) {
            mFitsStatusBarType = FLAG_FITS_SYSTEM_WINDOWS;
        }
    } else {
        mFitsStatusBarType = FLAG_FITS_DEFAULT;
    }
    mContentView.setBackgroundColor(ColorUtils.blendARGB(mBarParams.contentColor,
            mBarParams.contentColorTransform, mBarParams.contentAlpha));
    return this;
}
 
Example #18
Source File: Picker.java    From MultiImagePicker with MIT License 6 votes vote down vote up
private void init() {
    final TypedValue typedValue = new TypedValue();
    initUsingColorAccent(typedValue);

    mImageBackgroundColor = getColor(R.color.alter_unchecked_image_background);
    mImageCheckColor = getColor(R.color.alter_image_check_color);
    mCheckedImageOverlayColor = getColor(R.color.alter_checked_photo_overlay);
    mAlbumBackgroundColor = getColor(R.color.alter_album_background);
    mAlbumNameTextColor = getColor(R.color.alter_album_name_text_color);
    mAlbumImagesCountTextColor = getColor(R.color.alter_album_images_count_text_color);
    mFabBackgroundColorWhenPressed = ColorUtils.setAlphaComponent(mFabBackgroundColor, (int) (android.graphics.Color.alpha(mFabBackgroundColor) * 0.8f));
    mPickMode = PickMode.MULTIPLE_IMAGES;

    mPopupThemeResId = Util.getDefaultPopupTheme(mContext);
    mCaptureItemIconTintColor = mDoneFabIconTintColor = Util.getDefaultIconTintColor(mContext);

    mShouldShowCaptureMenuItem = true;

    mCheckIconTintColor = Color.WHITE;
    mVideosEnabled = false;
    mVideoLengthLimit = 0; // No limit

    mVideoThumbnailOverlayColor = getColor(R.color.alter_video_thumbnail_overlay);
    mVideoIconTintColor = Color.WHITE;
}
 
Example #19
Source File: ColorStateListUtils.java    From MagicaSakura with Apache License 2.0 5 votes vote down vote up
static ColorStateList inflateColorStateList(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException {
    final int innerDepth = parser.getDepth() + 1;
    int depth;
    int type;

    LinkedList<int[]> stateList = new LinkedList<>();
    LinkedList<Integer> colorList = new LinkedList<>();

    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
        if (type != XmlPullParser.START_TAG || depth > innerDepth
                || !parser.getName().equals("item")) {
            continue;
        }

        TypedArray a1 = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.color});
        final int value = a1.getResourceId(0, Color.MAGENTA);
        final int baseColor = value == Color.MAGENTA ? Color.MAGENTA : ThemeUtils.replaceColorById(context, value);
        a1.recycle();
        TypedArray a2 = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.alpha});
        final float alphaMod = a2.getFloat(0, 1.0f);
        a2.recycle();
        colorList.add(alphaMod != 1.0f
                ? ColorUtils.setAlphaComponent(baseColor, Math.round(Color.alpha(baseColor) * alphaMod))
                : baseColor);

        stateList.add(extractStateSet(attrs));
    }

    if (stateList.size() > 0 && stateList.size() == colorList.size()) {
        int[] colors = new int[colorList.size()];
        for (int i = 0; i < colorList.size(); i++) {
            colors[i] = colorList.get(i);
        }
        return new ColorStateList(stateList.toArray(new int[stateList.size()][]), colors);
    }
    return null;
}
 
Example #20
Source File: ImmersionBar.java    From ImmersionBar with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化android 5.0以上状态栏和导航栏
 *
 * @param uiFlags the ui flags
 * @return the int
 */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private int initBarAboveLOLLIPOP(int uiFlags) {
    //获得默认导航栏颜色
    if (!mInitialized) {
        mBarParams.defaultNavigationBarColor = mWindow.getNavigationBarColor();
    }
    //Activity全屏显示,但状态栏不会被隐藏覆盖,状态栏依然可见,Activity顶端布局部分会被状态栏遮住。
    uiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
    if (mBarParams.fullScreen && mBarParams.navigationBarEnable) {
        //Activity全屏显示,但导航栏不会被隐藏覆盖,导航栏依然可见,Activity底部布局部分会被导航栏遮住。
        uiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
    }
    mWindow.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    //判断是否存在导航栏
    if (mBarConfig.hasNavigationBar()) {
        mWindow.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    }
    //需要设置这个才能设置状态栏和导航栏颜色
    mWindow.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    //设置状态栏颜色
    if (mBarParams.statusBarColorEnabled) {
        mWindow.setStatusBarColor(ColorUtils.blendARGB(mBarParams.statusBarColor,
                mBarParams.statusBarColorTransform, mBarParams.statusBarAlpha));
    } else {
        mWindow.setStatusBarColor(ColorUtils.blendARGB(mBarParams.statusBarColor,
                Color.TRANSPARENT, mBarParams.statusBarAlpha));
    }
    //设置导航栏颜色
    if (mBarParams.navigationBarEnable) {
        mWindow.setNavigationBarColor(ColorUtils.blendARGB(mBarParams.navigationBarColor,
                mBarParams.navigationBarColorTransform, mBarParams.navigationBarAlpha));
    } else {
        mWindow.setNavigationBarColor(mBarParams.defaultNavigationBarColor);
    }
    return uiFlags;
}
 
Example #21
Source File: AllAngleExpandableButton.java    From AllAngleExpandableButton with Apache License 2.0 5 votes vote down vote up
private Bitmap getButtonShadowBitmap(ButtonData buttonData) {
    if (buttonData.isMainButton()) {
        if (mainShadowBitmap != null) {
            return mainShadowBitmap;
        }
    } else {
        if (subShadowBitmap != null) {
            return subShadowBitmap;
        }
    }

    int buttonSizePx = buttonData.isMainButton() ? mainButtonSizePx : subButtonSizePx;
    int buttonRadius = buttonSizePx / 2;
    int bitmapRadius = buttonRadius + buttonElevationPx;
    int bitmapSize = bitmapRadius * 2;
    Bitmap bitmap = Bitmap.createBitmap(bitmapSize, bitmapSize, Bitmap.Config.ARGB_8888);
    bitmap.eraseColor(0x0);
    int colors[] = {ColorUtils.setAlphaComponent(BUTTON_SHADOW_COLOR, BUTTON_SHADOW_ALPHA),
            ColorUtils.setAlphaComponent(BUTTON_SHADOW_COLOR, 0)};
    float stops[] = {(float) (buttonRadius - buttonElevationPx) / (float) bitmapRadius, 1};
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(new RadialGradient(bitmapRadius, bitmapRadius, bitmapRadius, colors, stops, Shader.TileMode.CLAMP));
    Canvas canvas = new Canvas(bitmap);
    canvas.drawRect(0, 0, bitmapSize, bitmapSize, paint);
    if (buttonData.isMainButton()) {
        mainShadowBitmap = bitmap;
        return mainShadowBitmap;
    } else {
        subShadowBitmap = bitmap;
        return subShadowBitmap;
    }
}
 
Example #22
Source File: MainActivity.java    From Prodigal with Apache License 2.0 5 votes vote down vote up
public void loadBackground(SongBean bean) {
    if (bean == null ) {
        backgroundImage.setImageBitmap(null);
        return;
    }
    final Uri image = Uri.parse(MediaLibrary.getStaticInstance(getApplicationContext())
            .getCoverUriByAlbumId(bean.getAlbumId()));
    Picasso.with(this).load(image).resize(windowSize.x, windowSize.y)
            .centerCrop()
            .transform(new Transformation() {
                @Override
                public Bitmap transform(Bitmap source) {
                    BlurFactor factor = new BlurFactor();
                    factor.radius = 25;
                    factor.sampling = 4;
                    factor.width = windowSize.x;
                    factor.height = windowSize.y;
                    factor.color = ColorUtils.setAlphaComponent(
                            ThemeManager.getInstance(getApplicationContext())
                            .loadCurrentTheme().getBackgroundColor(), 20);
                    Bitmap ret = Blur.of(getApplicationContext(), source, factor);
                    source.recycle();
                    return ret;
                }

                @Override
                public String key() {
                    return image.toString() + "/blured";
                }
            })
            .config(Bitmap.Config.RGB_565).into(backgroundImage);

}
 
Example #23
Source File: MoonPhasesView1.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("ResourceType")
protected void initTheme(Context context)
{
    int[] colorAttrs = { android.R.attr.textColorPrimary, R.attr.buttonPressColor, R.attr.text_disabledColor, R.attr.colorBackgroundFloating, R.attr.text_accentColor };
    TypedArray typedArray = context.obtainStyledAttributes(colorAttrs);
    int def = R.color.transparent;
    colorEnabled = ContextCompat.getColor(context, typedArray.getResourceId(0, def));
    colorPressed = ContextCompat.getColor(context, typedArray.getResourceId(1, def));
    colorDisabled = ContextCompat.getColor(context, typedArray.getResourceId(2, def));
    colorBackground = ColorUtils.setAlphaComponent(ContextCompat.getColor(context, typedArray.getResourceId(3, def)), (int)(9d * (254d / 10d)));
    colorAccent = ContextCompat.getColor(context, typedArray.getResourceId(4, def));
    typedArray.recycle();

    themeDrawables();
}
 
Example #24
Source File: CardAdapter.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
private void initTheme(Context context)
{
    int[] attrs = new int[] { android.R.attr.textColorPrimary, R.attr.buttonPressColor, R.attr.text_disabledColor, R.attr.tagColor_warning, R.attr.text_accentColor, R.attr.colorBackgroundFloating };
    TypedArray a = context.obtainStyledAttributes(attrs);
    options.color_textTimeDelta = ContextCompat.getColor(context, a.getResourceId(0, Color.WHITE));
    options.color_enabled = options.color_textTimeDelta;
    options.color_pressed = ContextCompat.getColor(context, a.getResourceId(1, R.color.btn_tint_pressed_dark));
    options.color_disabled = ContextCompat.getColor(context, a.getResourceId(2, R.color.text_disabled_dark));
    options.color_warning = ContextCompat.getColor(context, a.getResourceId(3, R.color.warningTag_dark));
    options.color_accent = ContextCompat.getColor(context, a.getResourceId(4, R.color.text_accent_dark));
    options.color_background = ColorUtils.setAlphaComponent(ContextCompat.getColor(context, a.getResourceId(5, R.color.transparent)), (int)(9d * (254d / 10d)));
    a.recycle();
}
 
Example #25
Source File: MdCompat.java    From android-md-core with Apache License 2.0 5 votes vote down vote up
public static int modulateColorAlpha(int baseColor, float alphaMod) {
  if (alphaMod == 1.0f) {
    return baseColor;
  }
  int alpha = (int) (Color.alpha(baseColor) * alphaMod + 0.5f);
  alpha = Math.min(Math.max(alpha, 0), 255);
  return ColorUtils.setAlphaComponent(baseColor, alpha);
}
 
Example #26
Source File: CircleView.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
private void setInnerColor(int color, boolean needsColorReset) {
    if (mInnerColor == (mInnerColor = color) && !needsColorReset) return;

    // Inverse the drawable if needed
    boolean isBright = ColorUtils.calculateLuminance(color) > 0.5;
    mDrawable.setColorFilter(isBright ? mInverseColorFilter : null);
}
 
Example #27
Source File: WorldMapView.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("ResourceType")
private void themeViews(Context context)
{
    foregroundColor = ContextCompat.getColor(context, R.color.map_foreground);
    options.backgroundColor = ContextCompat.getColor(context, R.color.map_background);
    options.sunShadowColor = ContextCompat.getColor(context, R.color.map_sunshadow);
    options.moonLightColor = ContextCompat.getColor(context, R.color.map_moonlight);
    options.gridXColor = options.moonLightColor;
    options.gridYColor = options.moonLightColor;
    options.latitudeColors[0] = ColorUtils.setAlphaComponent(options.sunShadowColor, 255);
    options.latitudeColors[1] = ColorUtils.setAlphaComponent(options.moonLightColor, 255);
    options.latitudeColors[2] = ColorUtils.setAlphaComponent(options.sunShadowColor, 255);
    options.locationFillColor = ContextCompat.getColor(context, R.color.map_location);

    int[] attrs = {
            R.attr.graphColor_pointFill,            // 0
            R.attr.graphColor_pointStroke,          // 1
            R.attr.moonriseColor,                   // 2
            R.attr.moonsetColor,                    // 3
            R.attr.icActionPlace                    // 4
    };
    TypedArray typedArray = context.obtainStyledAttributes(attrs);
    int def = R.color.transparent;
    options.sunFillColor = ContextCompat.getColor(context, typedArray.getResourceId(0, def));
    options.sunStrokeColor = ContextCompat.getColor(context, typedArray.getResourceId(1, def));
    options.moonFillColor = ContextCompat.getColor(context, typedArray.getResourceId(2, def));
    options.moonStrokeColor = ContextCompat.getColor(context, typedArray.getResourceId(3, def));
    typedArray.recycle();
}
 
Example #28
Source File: SamplesNtbActivity.java    From NavigationTabBar with Apache License 2.0 5 votes vote down vote up
private int randomColor() {
    float[] TEMP_HSL = new float[]{0, 0, 0};
    float[] hsl = TEMP_HSL;
    hsl[0] = (float) (Math.random() * 360);
    hsl[1] = (float) (40 + (Math.random() * 60));
    hsl[2] = (float) (40 + (Math.random() * 60));
    return ColorUtils.HSLToColor(hsl);
}
 
Example #29
Source File: LabelView.java    From AppCompat-Extension-Library with Apache License 2.0 5 votes vote down vote up
private static ColorStateList createColorStateList(int rippleColor, int backgroundColor) {
    final int compositeColor = ColorUtils.compositeColors(rippleColor, backgroundColor);
    return new ColorStateList(new int[][]{ // states
            new int[]{android.R.attr.state_focused},
            new int[]{android.R.attr.state_pressed},
            new int[]{} // state_default
    }, new int[]{ // colors
            compositeColor,
            compositeColor,
            backgroundColor
    });
}
 
Example #30
Source File: ImmersionBar.java    From MNImageBrowser with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 初始化android 5.0以上状态栏和导航栏
 *
 * @param uiFlags the ui flags
 * @return the int
 */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private int initBarAboveLOLLIPOP(int uiFlags) {
    //获得默认导航栏颜色
    if (!initialized()) {
        mBarParams.defaultNavigationBarColor = mWindow.getNavigationBarColor();
    }
    //Activity全屏显示,但状态栏不会被隐藏覆盖,状态栏依然可见,Activity顶端布局部分会被状态栏遮住。
    uiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
    if (mBarParams.fullScreen && mBarParams.navigationBarEnable) {
        //Activity全屏显示,但导航栏不会被隐藏覆盖,导航栏依然可见,Activity底部布局部分会被导航栏遮住。
        uiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
    }
    mWindow.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    //判断是否存在导航栏
    if (mBarConfig.hasNavigationBar()) {
        mWindow.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    }
    //需要设置这个才能设置状态栏和导航栏颜色
    mWindow.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    //设置状态栏颜色
    if (mBarParams.statusBarColorEnabled) {
        mWindow.setStatusBarColor(ColorUtils.blendARGB(mBarParams.statusBarColor,
                mBarParams.statusBarColorTransform, mBarParams.statusBarAlpha));
    } else {
        mWindow.setStatusBarColor(ColorUtils.blendARGB(mBarParams.statusBarColor,
                Color.TRANSPARENT, mBarParams.statusBarAlpha));
    }
    //设置导航栏颜色
    if (mBarParams.navigationBarEnable) {
        mWindow.setNavigationBarColor(ColorUtils.blendARGB(mBarParams.navigationBarColor,
                mBarParams.navigationBarColorTransform, mBarParams.navigationBarAlpha));
    } else {
        mWindow.setNavigationBarColor(mBarParams.defaultNavigationBarColor);
    }
    return uiFlags;
}