Java Code Examples for android.support.v4.graphics.ColorUtils

The following examples show how to use android.support.v4.graphics.ColorUtils. These examples are extracted from open source projects. 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
/**
 * 初始化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 2
/**
 * 设置一个可以自定义颜色的状态栏
 */
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 3
/**
 * 变色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 4
Source Project: android-map-sdk   Source File: PolygonOverlayActivity.java    License: 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 5
Source Project: LaunchEnr   Source File: ExtractedColors.java    License: 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 6
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 7
Source Project: MNProgressHUD   Source File: StatusBarUtils.java    License: 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 8
Source Project: ImmersionBar   Source File: ImmersionBar.java    License: 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 9
Source Project: ImmersionBar   Source File: ImmersionBar.java    License: 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 10
/**
 * @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 11
Source Project: MNImageBrowser   Source File: ImmersionBar.java    License: 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 12
Source Project: MNImageBrowser   Source File: ImmersionBar.java    License: 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 13
Source Project: andela-crypto-app   Source File: WelcomeActivity.java    License: 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 14
Source Project: glide-support   Source File: TestFragment.java    License: 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 15
Source Project: Puff-Android   Source File: IntroActivity.java    License: 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 16
Source Project: Prodigal   Source File: IntroActivity.java    License: 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 17
Source Project: SuntimesWidget   Source File: WorldMapView.java    License: 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 18
Source Project: MultiImagePicker   Source File: Picker.java    License: 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 Project: timecat   Source File: ColorStateListUtils.java    License: 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
/**
 * 解决布局与状态栏重叠问题,支持侧滑返回
 * Fits system windows immersion bar.
 *
 * @param fits                               the fits
 * @param statusBarColorContentView          the status bar color content view 状态栏颜色
 * @param statusBarColorContentViewTransform the status bar color content view transform  状态栏变色后的颜色
 * @param statusBarContentViewAlpha          the status bar content view alpha  透明度
 * @return the immersion bar
 */
public ImmersionBar fitsSystemWindows(boolean fits, @ColorRes int statusBarColorContentView
        , @ColorRes int statusBarColorContentViewTransform, @FloatRange(from = 0f, to = 1f) float statusBarContentViewAlpha) {
    mBarParams.fits = fits;
    mBarParams.statusBarColorContentView = ContextCompat.getColor(mActivity, statusBarColorContentView);
    mBarParams.statusBarColorContentViewTransform = ContextCompat.getColor(mActivity, statusBarColorContentViewTransform);
    mBarParams.statusBarContentViewAlpha = statusBarContentViewAlpha;
    mBarParams.statusBarColorContentView = ContextCompat.getColor(mActivity, statusBarColorContentView);
    mContentView.setBackgroundColor(ColorUtils.blendARGB(mBarParams.statusBarColorContentView,
            mBarParams.statusBarColorContentViewTransform, mBarParams.statusBarContentViewAlpha));
    return this;
}
 
Example 21
/**
 * 设置一个可以自定义颜色的导航栏
 */
private void setupNavBarView() {
    if (mBarParams.navigationBarView == null) {
        mBarParams.navigationBarView = new View(mActivity);
    }
    FrameLayout.LayoutParams params;
    if (mConfig.isNavigationAtBottom()) {
        params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, mConfig.getNavigationBarHeight());
        params.gravity = Gravity.BOTTOM;
    } else {
        params = new FrameLayout.LayoutParams(mConfig.getNavigationBarWidth(), FrameLayout.LayoutParams.MATCH_PARENT);
        params.gravity = Gravity.END;
    }
    mBarParams.navigationBarView.setLayoutParams(params);
    if (mBarParams.navigationBarEnable && mBarParams.navigationBarWithKitkatEnable) {
        if (!mBarParams.fullScreen && (mBarParams.navigationBarColorTransform == Color.TRANSPARENT)) {
            mBarParams.navigationBarView.setBackgroundColor(ColorUtils.blendARGB(mBarParams.navigationBarColor,
                    Color.BLACK, mBarParams.navigationBarAlpha));
        } else {
            mBarParams.navigationBarView.setBackgroundColor(ColorUtils.blendARGB(mBarParams.navigationBarColor,
                    mBarParams.navigationBarColorTransform, mBarParams.navigationBarAlpha));
        }
    } else
        mBarParams.navigationBarView.setBackgroundColor(Color.TRANSPARENT);
    mBarParams.navigationBarView.setVisibility(View.VISIBLE);
    ViewGroup viewGroup = (ViewGroup) mBarParams.navigationBarView.getParent();
    if (viewGroup != null)
        viewGroup.removeView(mBarParams.navigationBarView);
    mDecorView.addView(mBarParams.navigationBarView);
}
 
Example 22
Source Project: android-map-sdk   Source File: CircleOverlayActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onMapReady(@NonNull NaverMap naverMap) {
    int color = ResourcesCompat.getColor(getResources(), R.color.primary, getTheme());

    CircleOverlay circleOverlay = new CircleOverlay();
    circleOverlay.setCenter(new LatLng(37.5666102, 126.9783881));
    circleOverlay.setRadius(500);
    circleOverlay.setColor(ColorUtils.setAlphaComponent(color, 31));
    circleOverlay.setOutlineColor(color);
    circleOverlay.setOutlineWidth(getResources().getDimensionPixelSize(R.dimen.overlay_line_width));
    circleOverlay.setMap(naverMap);
}
 
Example 23
Source Project: AdaptiveTableLayout   Source File: SampleLinkedTableAdapter.java    License: MIT License 5 votes vote down vote up
@Override
public void onBindHeaderColumnViewHolder(@NonNull ViewHolderImpl viewHolder, int column) {
    int color = COLORS[column % COLORS.length];
    TestHeaderColumnViewHolder vh = (TestHeaderColumnViewHolder) viewHolder;
    vh.tvText.setText(mTableDataSource.getColumnHeaderData(column));  // skip left top header
    GradientDrawable gd = new GradientDrawable(
            mIsRtl ? GradientDrawable.Orientation.RIGHT_LEFT : GradientDrawable.Orientation.LEFT_RIGHT,
            new int[]{ColorUtils.setAlphaComponent(color, 50), 0x00000000});
    gd.setCornerRadius(0f);
    vh.vGradient.setBackground(gd);
    vh.vLine.setBackgroundColor(color);
}
 
Example 24
/**
 * The line's color will be:
 * - mostly opaque white if the hotseat is white (ignoring alpha)
 * - mostly opaque black if the hotseat is black (ignoring alpha)
 */
public void updateColor(ExtractedColors extractedColors) {
    int originalLineAlpha = mLinePaint.getAlpha();
    int color = extractedColors.getColor(ExtractedColors.HOTSEAT_INDEX, Color.TRANSPARENT);
    if (color != Color.TRANSPARENT) {
        color = ColorUtils.setAlphaComponent(color, 255);
        if (color == Color.BLACK) {
            mActiveAlpha = BLACK_ALPHA;
        } else if (color == Color.WHITE) {
            mActiveAlpha = WHITE_ALPHA;
        }
        mLinePaint.setColor(color);
        mLinePaint.setAlpha(originalLineAlpha);
    }
}
 
Example 25
Source Project: LaunchEnr   Source File: IconPalette.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Finds a suitable color such that there's enough contrast.
 *
 * @param color the color to start searching from.
 * @param other the color to ensure contrast against. Assumed to be lighter than {@param color}
 * @param findFg if true, we assume {@param color} is a foreground, otherwise a background.
 * @param minRatio the minimum contrast ratio required.
 * @return a color with the same hue as {@param color}, potentially darkened to meet the
 *          contrast ratio.
 *
 * This was copied from com.android.internal.util.NotificationColorUtil.
 */
private static int findContrastColor(int color, int other, boolean findFg, double minRatio) {
    int fg = findFg ? color : other;
    int bg = findFg ? other : color;
    if (ColorUtils.calculateContrast(fg, bg) >= minRatio) {
        return color;
    }

    double[] lab = new double[3];
    ColorUtils.colorToLAB(findFg ? fg : bg, lab);

    double low = 0, high = lab[0];
    final double a = lab[1], b = lab[2];
    for (int i = 0; i < 15 && high - low > 0.00001; i++) {
        final double l = (low + high) / 2;
        if (findFg) {
            fg = ColorUtils.LABToColor(l, a, b);
        } else {
            bg = ColorUtils.LABToColor(l, a, b);
        }
        if (ColorUtils.calculateContrast(fg, bg) > minRatio) {
            low = l;
        } else {
            high = l;
        }
    }
    return ColorUtils.LABToColor(low, a, b);
}
 
Example 26
Source Project: LaunchEnr   Source File: IconPalette.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static int getLighterOrDarkerVersionOfColor(int color, float contrastRatio) {
    int whiteMinAlpha = ColorUtils.calculateMinimumAlpha(Color.WHITE, color, contrastRatio);
    int blackMinAlpha = ColorUtils.calculateMinimumAlpha(Color.BLACK, color, contrastRatio);
    int translucentWhiteOrBlack;
    if (whiteMinAlpha >= 0) {
        translucentWhiteOrBlack = ColorUtils.setAlphaComponent(Color.WHITE, whiteMinAlpha);
    } else if (blackMinAlpha >= 0) {
        translucentWhiteOrBlack = ColorUtils.setAlphaComponent(Color.BLACK, blackMinAlpha);
    } else {
        translucentWhiteOrBlack = Color.WHITE;
    }
    return ColorUtils.compositeColors(translucentWhiteOrBlack, color);
}
 
Example 27
Source Project: LaunchEnr   Source File: Hotseat.java    License: GNU General Public License v3.0 5 votes vote down vote up
public Hotseat(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mLauncher = Launcher.getLauncher(context);
    mHasVerticalHotseat = mLauncher.getDeviceProfile().isVerticalBarLayout();
    mBackgroundColor = ColorUtils.setAlphaComponent(
            ThemeUtils.getAttrColor(context, android.R.attr.colorPrimary), 0);
    mBackground = new ColorDrawable(mBackgroundColor);
    setBackground(mBackground);
}
 
Example 28
Source Project: Musicoco   Source File: BottomNavigationController.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void themeChange(ThemeEnum themeEnum, int[] colors) {
    themeEnum = appPreference.getTheme();
    int[] cs = com.duan.musicoco.util.ColorUtils.get10ThemeColors(activity, themeEnum);

    int accentC = cs[2];

    // ItemColor 随主题改变而变化
    playListAdapter.setSelectItemColor(accentC);

    songOption.themeChange(themeEnum, cs);
}
 
Example 29
private void setColorFilter(int position) {
    if (position == selectedPosition && ColorUtils.calculateLuminance(colors[position]) >= 0.65) {
        imageView.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_IN);
    } else {
        imageView.setColorFilter(null);
    }
}
 
Example 30
Source Project: ImmersionBar   Source File: ImmersionBar.java    License: 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;
}