當前位置: 首頁>>代碼示例>>Java>>正文


Java ColorUtils類代碼示例

本文整理匯總了Java中android.support.v4.graphics.ColorUtils的典型用法代碼示例。如果您正苦於以下問題:Java ColorUtils類的具體用法?Java ColorUtils怎麽用?Java ColorUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ColorUtils類屬於android.support.v4.graphics包,在下文中一共展示了ColorUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: update

import android.support.v4.graphics.ColorUtils; //導入依賴的package包/類
@Override
public void update(final ParticulateMatterSample sample) {
    FragmentActivity activity = getActivity();
    currentValue = sample;
    if (activity == null || sample == null) {
        return;
    }
    activity.runOnUiThread(() -> {
        pm1.setText(String.format(Locale.getDefault(), "%d", sample.getPm1_0()));
        pm25.setText(String.format(Locale.getDefault(), "%d", sample.getPm2_5()));
        AQIColor pm25Color = AQIColor.fromPM25Level(sample.getPm2_5());
        pm1Card.setCardBackgroundColor(
                ColorUtils.setAlphaComponent(pm25Color.getColor(), 136));
        pm25Card.setCardBackgroundColor(
                ColorUtils.setAlphaComponent(pm25Color.getColor(), 136));
        pm10.setText(String.format(Locale.getDefault(), "%d", sample.getPm10()));
        pm10Card.setCardBackgroundColor(
                ColorUtils.setAlphaComponent(AQIColor.fromPM10Level(sample.getPm10()).getColor(), 136));
        time.setText(Settings.dateFormat.format(sample.getDate()));
    });
}
 
開發者ID:rjaros87,項目名稱:pm-home-station,代碼行數:22,代碼來源:ValuesFragment.java

示例2: updateHotseatPalette

import android.support.v4.graphics.ColorUtils; //導入依賴的package包/類
/**
 * 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);
    }
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:29,代碼來源:ExtractedColors.java

示例3: drawBoxWithShadow

import android.support.v4.graphics.ColorUtils; //導入依賴的package包/類
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;
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:24,代碼來源:WidgetPreviewLoader.java

示例4: setup

import android.support.v4.graphics.ColorUtils; //導入依賴的package包/類
void setup(int position) {
    int color = colors[position];
    int alpha = Color.alpha(color);
    colorPanelView.setColor(color);
    imageView.setImageResource(selectedPosition == position ? R.drawable.cpv_preset_checked : 0);
    if (alpha != 255) {
        if (alpha <= ColorPickerDialog.ALPHA_THRESHOLD) {
            colorPanelView.setBorderColor(color | 0xFF000000);
            imageView.setColorFilter(/*color | 0xFF000000*/Color.BLACK, PorterDuff.Mode.SRC_IN);
        } else {
            colorPanelView.setBorderColor(originalBorderColor);

            if (ColorUtils.calculateLuminance(colors[position]) >= 0.65) {
                imageView.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_IN);
            } else {
                imageView.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
            }
        }
    } else {
        setColorFilter(position);
    }
    setOnClickListener(position);
}
 
開發者ID:nhocga1995s,項目名稱:MyCalendar,代碼行數:24,代碼來源:ColorPaletteAdapter.java

示例5: shiftBrightness

import android.support.v4.graphics.ColorUtils; //導入依賴的package包/類
/**
 * Darkens or lightens the color by the specified amount.
 *
 * @param color  Which color to change
 * @param amount Negative to darken, positive to lighten. Must be in range [-255, 255]
 * @return The brightness-shifted color
 */
@ColorInt
public static int shiftBrightness(@ColorInt final int color, @IntRange(from = -255, to = 255) final int amount) {
    if (amount == 0f) {
        return color;
    }

    // convert from RGB to HSL (hue/saturation/lightness)
    final float[] hsl = new float[] { 0f, 0f, 0f };
    ColorUtils.colorToHSL(color, hsl);

    // clamp the lightness to [0..1] range (0% - 100%)
    float lightness = hsl[2] + amount / 255f;
    if (lightness < 0f) {
        lightness = 0f;
    } else if (lightness > 1f) {
        lightness = 1f;
    }
    hsl[2] = lightness;

    final int a = Color.alpha(color);
    final int result = ColorUtils.HSLToColor(hsl);
    return ColorUtils.setAlphaComponent(result, a);
}
 
開發者ID:milosmns,項目名稱:silly-android,代碼行數:31,代碼來源:Coloring.java

示例6: setPrimaryColors

import android.support.v4.graphics.ColorUtils; //導入依賴的package包/類
@Override
public void setPrimaryColors(int... colors) {
    super.setPrimaryColors(colors);
    if (colors.length > 0) {
        mBoundaryColor = mBackColor = colors[0];
        if (mBackColor == 0 || mBackColor == 0xffffffff) {
            mBoundaryColor = 0xff606060;
        }
        if (colors.length > 1) {
            mModelColor = colors[1];
            lModelColor = ColorUtils.setAlphaComponent(colors[1], 225);
            rModelColor = ColorUtils.setAlphaComponent(colors[1], 200);
            textPaint.setColor(ColorUtils.setAlphaComponent(colors[1], 150));
        }
    }
}
 
開發者ID:Brave-wan,項目名稱:SmartRefresh,代碼行數:17,代碼來源:FunGameView.java

示例7: setPrimaryColor

import android.support.v4.graphics.ColorUtils; //導入依賴的package包/類
public void setPrimaryColor(int color) {
//        private int COLOR_BACKGROUND = Color.parseColor("#7ECEC9");
//        private int COLOR_MOUNTAIN_1 = Color.parseColor("#86DAD7");
//        private int COLOR_MOUNTAIN_2 = Color.parseColor("#3C929C");
//        private int COLOR_MOUNTAIN_3 = Color.parseColor("#3E5F73");
//        private int COLOR_TREE_1_BRANCH = Color.parseColor("#1F7177");
//        private int COLOR_TREE_1_BTRUNK = Color.parseColor("#0C3E48");
//        private int COLOR_TREE_2_BRANCH = Color.parseColor("#34888F");
//        private int COLOR_TREE_2_BTRUNK = Color.parseColor("#1B6169");
//        private int COLOR_TREE_3_BRANCH = Color.parseColor("#57B1AE");
//        private int COLOR_TREE_3_BTRUNK = Color.parseColor("#62A4AD");
        COLOR_BACKGROUND = color;
        COLOR_MOUNTAIN_1 = ColorUtils.compositeColors(0x99ffffff,color);
        COLOR_MOUNTAIN_2 = ColorUtils.compositeColors(0x993C929C,color);
        COLOR_MOUNTAIN_3 = ColorUtils.compositeColors(0xCC3E5F73,color);
        COLOR_TREE_1_BRANCH = ColorUtils.compositeColors(0x551F7177,color);
        COLOR_TREE_1_BTRUNK = ColorUtils.compositeColors(0xCC0C3E48,color);
        COLOR_TREE_2_BRANCH = ColorUtils.compositeColors(0x5534888F,color);
        COLOR_TREE_2_BTRUNK = ColorUtils.compositeColors(0xCC1B6169,color);
        COLOR_TREE_3_BRANCH = ColorUtils.compositeColors(0x5557B1AE,color);
        COLOR_TREE_3_BTRUNK = ColorUtils.compositeColors(0xCC62A4AD,color);
    }
 
開發者ID:Brave-wan,項目名稱:SmartRefresh,代碼行數:23,代碼來源:MountanScenceView.java

示例8: drawColorBlock

import android.support.v4.graphics.ColorUtils; //導入依賴的package包/類
/**
 * 繪製矩形色塊
 * @param canvas 默認畫布
 */
private void drawColorBlock(Canvas canvas) {
    float left, top;
    int column, row;
    for (int i = 0; i < blockHorizontalNum * BLOCK_VERTICAL_NUM; i++) {
        row = i / blockHorizontalNum;
        column = i % blockHorizontalNum;

        boolean flag = false;
        for (Point point : pointList) {
            if (point.equals(column, row)) {
                flag = true;
                break;
            }
        }
        if (flag) {
            continue;
        }

        blockPaint.setColor(ColorUtils.setAlphaComponent(lModelColor, 255 / (column + 1)));

        left = blockLeft + column * (blockWidth + DIVIDING_LINE_SIZE);
        top = DIVIDING_LINE_SIZE + row * (blockHeight + DIVIDING_LINE_SIZE);
        canvas.drawRect(left, top, left + blockWidth, top + blockHeight, blockPaint);
    }
}
 
開發者ID:Brave-wan,項目名稱:SmartRefresh,代碼行數:30,代碼來源:FunGameHitBlockHeader.java

示例9: setupStatusBarView

import android.support.v4.graphics.ColorUtils; //導入依賴的package包/類
/**
 * 設置一個可以自定義顏色的狀態欄
 */
private void setupStatusBarView() {
    if (mBarParams.statusBarView == null) {
        mBarParams.statusBarView = new View(mActivity);
    }
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, getStatusBarHeight(mActivity));
    params.gravity = Gravity.TOP;
    if (!isNavigationAtBottom(mActivity)) {
        params.rightMargin = getNavigationBarWidth(mActivity);
    }
    mBarParams.statusBarView.setLayoutParams(params);
    mBarParams.statusBarView.setBackgroundColor(ColorUtils.blendARGB(mBarParams.statusBarColor,
            mBarParams.statusBarColorTransform, mBarParams.statusBarAlpha));
    mBarParams.statusBarView.setVisibility(View.VISIBLE);
    ViewGroup viewGroup = (ViewGroup) mBarParams.statusBarView.getParent();
    if (viewGroup != null)
        viewGroup.removeView(mBarParams.statusBarView);
    mViewGroup.addView(mBarParams.statusBarView);
}
 
開發者ID:penghongru,項目名稱:Coder,代碼行數:22,代碼來源:ImmersionBar.java

示例10: setBackgroundActiveColor

import android.support.v4.graphics.ColorUtils; //導入依賴的package包/類
public static void setBackgroundActiveColor(View editText, int accentColor) {
    if (editText.getBackground() == null)
        return;
    int normalColor = StyledAttributesHelper.getColor(editText.getContext(),
            R.attr.colorControlNormal, 0);
    int disabledColor = ColorUtils.setAlphaComponent(normalColor, (int) (255.f *
            StyledAttributesHelper.getFloat(editText.getContext(), android.R.attr.disabledAlpha, 1.f)));
    int[][] states = new int[][]{
            new int[]{-android.R.attr.state_enabled},
            new int[]{-android.R.attr.state_pressed, -android.R.attr.state_focused},
            new int[]{}
    };
    int[] colors = new int[]{
            disabledColor,
            normalColor,
            accentColor
    };
    ColorStateList list = new ColorStateList(states, colors);
    editText.setBackground(new ColorFilterWorkaroundDrawable(editText.getBackground()));
    ViewCompat.setBackgroundTintList(editText, list);
}
 
開發者ID:MCMrARM,項目名稱:revolution-irc,代碼行數:22,代碼來源:ThemedEditText.java

示例11: animateTint

import android.support.v4.graphics.ColorUtils; //導入依賴的package包/類
public static void animateTint(ImageView view, int from, int to, int duration) {
    final float[] fromHSL = new float[3];
    final float[] toHSL = new float[3];
    float[] currentHSL = new float[3];
    ColorUtils.colorToHSL(from, fromHSL);
    ColorUtils.colorToHSL(to, toHSL);
    int fromAlpha = Color.alpha(from);
    int toAlpha = Color.alpha(to);

    final ValueAnimator anim = ObjectAnimator.ofFloat(0f, 1f);
    anim.addUpdateListener((ValueAnimator animation) -> {
        float mul = (Float) animation.getAnimatedValue();
        ColorUtils.blendHSL(fromHSL, toHSL, mul, currentHSL);
        int color = ColorUtils.HSLToColor(currentHSL);
        color = ColorUtils.setAlphaComponent(color, fromAlpha +
                (int) ((toAlpha - fromAlpha) * mul));
        setTint(view, color);
    });
    anim.setDuration(duration);
    anim.setInterpolator(new AccelerateDecelerateInterpolator());
    anim.start();
}
 
開發者ID:MCMrARM,項目名稱:revolution-irc,代碼行數:23,代碼來源:ImageViewTintUtils.java

示例12: createButtonColorStateList

import android.support.v4.graphics.ColorUtils; //導入依賴的package包/類
private ColorStateList createButtonColorStateList(Context context, int baseColorAttr) {
    states = new int[4][];
    colors = new int[4];
    int baseColor = ThemeUtils.getThemeAttrColor(context, baseColorAttr);
    int colorControlHighlight = ThemeUtils.getThemeAttrColor(context, R.attr.colorControlHighlight);
    states[0] = ThemeUtils.DISABLED_STATE_SET;
    colors[0] = ThemeUtils.getDisabledThemeAttrColor(context, R.attr.colorButtonNormal);
    int i = 0 + 1;
    states[i] = ThemeUtils.PRESSED_STATE_SET;
    colors[i] = ColorUtils.compositeColors(colorControlHighlight, baseColor);
    i++;
    states[i] = ThemeUtils.FOCUSED_STATE_SET;
    colors[i] = ColorUtils.compositeColors(colorControlHighlight, baseColor);
    i++;
    states[i] = ThemeUtils.EMPTY_STATE_SET;
    colors[i] = baseColor;
    i++;
    return new ColorStateList(states, colors);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:20,代碼來源:AppCompatDrawableManager.java

示例13: updateTaskDescription

import android.support.v4.graphics.ColorUtils; //導入依賴的package包/類
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));
    }
}
 
開發者ID:jumaallan,項目名稱:AndelaTrackChallenge,代碼行數:22,代碼來源:WelcomeActivity.java

示例14: updateColor

import android.support.v4.graphics.ColorUtils; //導入依賴的package包/類
/**
 * 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;
        } else {
            Log.e(TAG, "Setting workspace page indicators to an unsupported color: #"
                    + Integer.toHexString(color));
        }
        mLinePaint.setColor(color);
        mLinePaint.setAlpha(originalLineAlpha);
    }
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:23,代碼來源:PageIndicatorLineCaret.java

示例15: run

import android.support.v4.graphics.ColorUtils; //導入依賴的package包/類
@Override
public void run() {
    // set to coloralpha
    Log.e("happily", "Setting alpha to " + colorAlpha);
    int newColor = ColorUtils.setAlphaComponent(backgroundColor, colorAlpha);
    changeBackground(previousColor, newColor);
    previousColor = newColor;
    if (smileProbability > 0.8) {
        progressBar.setProgress(progressBar.getProgress() + 8);
    }
    if (progressBar.getProgress() == 100) {
        showQuote();
    } else {
        mHandler.postDelayed(mStatusChecker, mInterval);
    }
}
 
開發者ID:paolorotolo,項目名稱:happily,代碼行數:17,代碼來源:MainActivity.java


注:本文中的android.support.v4.graphics.ColorUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。