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


Java Palette.Swatch方法代碼示例

本文整理匯總了Java中android.support.v7.graphics.Palette.Swatch方法的典型用法代碼示例。如果您正苦於以下問題:Java Palette.Swatch方法的具體用法?Java Palette.Swatch怎麽用?Java Palette.Swatch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v7.graphics.Palette的用法示例。


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

示例1: getColor

import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
public static int getColor (Palette p){
    Palette.Swatch s1 = p.getVibrantSwatch();
    Palette.Swatch s3 = p.getDarkVibrantSwatch();
    Palette.Swatch s2 = p.getMutedSwatch();
    Palette.Swatch s6 = p.getDarkMutedSwatch();
    Palette.Swatch s4 = p.getLightVibrantSwatch();
    Palette.Swatch s5 = p.getLightMutedSwatch();
    Palette.Swatch s7 = p.getDominantSwatch();
    if (s1 != null) {
        return s1.getRgb();
    } else if (s2 != null) {
        return s2.getRgb();
    } else if (s3 != null) {
        return s3.getRgb();
    } else if (s4 != null) {
        return s4.getRgb();
    } else if (s5 != null) {
        return s5.getRgb();
    } else if (s6 != null) {
        return s6.getRgb();
    } else if (s7 != null) {
        return s7.getRgb();
    } else {
        return Color.parseColor("#009688");
    }
}
 
開發者ID:htqqdd,項目名稱:music_player,代碼行數:27,代碼來源:ColorUtil.java

示例2: setColor

import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
/**
 * 設置顏色
 * @param vibrant
 */
private void setColor(Palette.Swatch vibrant) {
    // 將顏色設置給狀態欄
    if (android.os.Build.VERSION.SDK_INT >= 21) {
        Window window = getWindow();
        window.setStatusBarColor(deepenColor(vibrant.getRgb()));//設置狀態欄的顏色,設置顏色之前對顏色進行加深處理
        window.setNavigationBarColor(deepenColor(vibrant.getRgb()));//設置導航欄的顏色,設置顏色之前對顏色進行加深處理
    }

    mToolbar.setBackgroundColor(vibrant.getRgb());//設置Toolbar背景色
    mTabLayout.setBackgroundColor(vibrant.getRgb());//設置TabLayout背景色
    mTabLayout.setSelectedTabIndicatorColor(deepenColor(vibrant.getRgb()));//設置TabLayout指示器的顏色
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:PaletteActivity2.java

示例3: isLegibleOnWallpaper

import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
/**
 * Given a color, returns true if that color is legible on
 * the given wallpaper color swatches, else returns false.
 */
private static boolean isLegibleOnWallpaper(int color, List<Palette.Swatch> wallpaperSwatches) {
    int legiblePopulation = 0;
    int illegiblePopulation = 0;
    for (Palette.Swatch swatch : wallpaperSwatches) {
        if (isLegible(color, swatch.getRgb())) {
            legiblePopulation += swatch.getPopulation();
        } else {
            illegiblePopulation += swatch.getPopulation();
        }
    }
    return legiblePopulation > illegiblePopulation;
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:17,代碼來源:ExtractionUtils.java

示例4: getMostPopulousSwatch

import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
public static
@Nullable
Palette.Swatch getMostPopulousSwatch(Palette palette) {
    Palette.Swatch mostPopulous = null;
    if (palette != null) {
        for (Palette.Swatch swatch : palette.getSwatches()) {
            if (mostPopulous == null || swatch.getPopulation() > mostPopulous.getPopulation()) {
                mostPopulous = swatch;
            }
        }
    }
    return mostPopulous;
}
 
開發者ID:haihaio,項目名稱:AmenEye,代碼行數:14,代碼來源:ColorUtil.java

示例5: getColor

import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
protected static int getColor(Palette.Swatch swatch, @Swatch int paletteSwatch) {
    if (swatch != null) {
        switch (paletteSwatch) {
            case Swatch.RGB:
                return swatch.getRgb();
            case Swatch.TITLE_TEXT_COLOR:
                return swatch.getTitleTextColor();
            case Swatch.BODY_TEXT_COLOR:
                return swatch.getBodyTextColor();
        }
    } else {
        Log.e(TAG, "error while generating Palette, null palette returned");
    }
    return 0;
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:16,代碼來源:BitmapPalette.java

示例6: isDark

import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
/**
 * Checks if the most populous color in the given palette is dark
 * <p/>
 * Annoyingly we have to return this Lightness 'enum' rather than a boolean as palette isn't
 * guaranteed to find the most populous color.
 */
public static
@Lightness
int isDark(Palette palette) {
    Palette.Swatch mostPopulous = getMostPopulousSwatch(palette);
    if (mostPopulous == null) return LIGHTNESS_UNKNOWN;
    return isDark(mostPopulous.getHsl()) ? IS_DARK : IS_LIGHT;
}
 
開發者ID:gejiaheng,項目名稱:Protein,代碼行數:14,代碼來源:ColorUtils.java

示例7: getDominantColor

import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
/**
 * Get dominant color of bitmap
 * @param bitmap Bitmap
 * @return int
 */
public static int getDominantColor(Bitmap bitmap){
    Palette palette = Palette.from(bitmap).generate();
    Palette.Swatch dominantSwatch = palette.getDominantSwatch();
    if(dominantSwatch != null){
        return dominantSwatch.getRgb();
    }
    return 0;
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:14,代碼來源:Utils.java

示例8: getSwatch

import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
public static Palette.Swatch getSwatch(Context context, Palette palette) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    if (palette == null)
        return new Palette.Swatch(prefs.getInt(PreferenceUtils.PREF_CUSTOM_COLOR, Color.WHITE), 1);

    Palette.Swatch swatch = null;
    switch (prefs.getInt(PreferenceUtils.PREF_COLOR_METHOD, PreferenceUtils.COLOR_METHOD_DOMINANT)) {
        case PreferenceUtils.COLOR_METHOD_DOMINANT:
            swatch = palette.getDominantSwatch();
            break;
        case PreferenceUtils.COLOR_METHOD_PRIMARY:
            swatch = getBestPaletteSwatchFrom(palette);
            break;
        case PreferenceUtils.COLOR_METHOD_VIBRANT:
            swatch = palette.getVibrantSwatch();
            break;
        case PreferenceUtils.COLOR_METHOD_MUTED:
            swatch = palette.getMutedSwatch();
            break;
    }

    if (swatch == null)
        swatch = new Palette.Swatch(prefs.getInt(PreferenceUtils.PREF_CUSTOM_COLOR, Color.WHITE), 1);

    return swatch;
}
 
開發者ID:TheAndroidMaster,項目名稱:MediaNotification,代碼行數:28,代碼來源:PaletteUtils.java

示例9: dispatchDraw

import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
@Override
protected void dispatchDraw(Canvas canvas) {

    if (mInvalidat) {

        mInvalidat = false;

        View view = getChildAt(0);

        Paint shadowPaint = new Paint();

        shadowPaint.setColor(Color.WHITE);
        shadowPaint.setStyle(Paint.Style.FILL);
        shadowPaint.setAntiAlias(true);

        int radius = view.getHeight() / 12 > 40 ? 40 : view.getHeight() / 12;
        int shadowDimen = view.getHeight() / 16 > 28 ? 28 : view.getHeight() / 16;

        Bitmap bitmap;
        int rgb;

        if (((ImageView) view).getDrawable() instanceof ColorDrawable) {
            rgb = ((ColorDrawable) ((ImageView) view).getDrawable()).getColor();
            shadowPaint.setShadowLayer(40, 0, 28, getDarkerColor(rgb));
        } else if (((ImageView) view).getDrawable() instanceof BitmapDrawable) {
            bitmap = ((BitmapDrawable) ((ImageView) view).getDrawable()).getBitmap();
            Palette.Swatch mSwatch = Palette.from(bitmap).generate().getDominantSwatch();

            if (null != mSwatch) {
                rgb = mSwatch.getRgb();
            } else {
                rgb = Color.parseColor("#8D8D8D");
            }

            shadowPaint.setShadowLayer(radius, 0, shadowDimen, getDarkerColor(rgb));
            Bitmap bitmapT = Bitmap.createBitmap(bitmap, 0, bitmap.getHeight() / 4 * 3,
                    bitmap.getWidth(), bitmap.getHeight() / 4);

            if (null != Palette.from(bitmapT).generate().getDominantSwatch()) {
                rgb = Palette.from(bitmapT).generate().getDominantSwatch().getRgb();
                shadowPaint.setShadowLayer(radius, 0, shadowDimen, rgb);
            }
        } else {
            rgb = Color.parseColor("#8D8D8D");
            shadowPaint.setShadowLayer(radius, 0, shadowDimen, getDarkerColor(rgb));
        }

        if (this.shadowColor != -147483648) {
            shadowPaint.setShadowLayer(radius, 0, shadowDimen, this.shadowColor);
        }

        RectF rectF = new RectF(view.getX() + (view.getWidth() / 20), view.getY(), view.getX() + view.getWidth() - (view.getWidth() / 20), view.getY() + view.getHeight() - ((view.getHeight() / 40)));

        canvas.drawRoundRect(rectF, shadowRound, shadowRound, shadowPaint);

        canvas.save();
    }
    super.dispatchDraw(canvas);
}
 
開發者ID:yingLanNull,項目名稱:ShadowImageView,代碼行數:60,代碼來源:ShadowImageView.java

示例10: getBestPaletteSwatchFrom

import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
private static Palette.Swatch getBestPaletteSwatchFrom(List<Palette.Swatch> swatches) {
    if (swatches == null) return null;
    return Collections.max(swatches, new Comparator<Palette.Swatch>() {
        @Override
        public int compare(Palette.Swatch opt1, Palette.Swatch opt2) {
            int a = opt1 == null ? 0 : opt1.getPopulation();
            int b = opt2 == null ? 0 : opt2.getPopulation();
            return a - b;
        }
    });
}
 
開發者ID:TheAndroidMaster,項目名稱:MediaNotification,代碼行數:12,代碼來源:PaletteUtils.java

示例11: startBitmapAnalysis

import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
private void startBitmapAnalysis() {
    if(!isDisposed()){
        Palette palette = Palette.from(bitmap).generate();

        List<Palette.Swatch> swatches = palette.getSwatches();

        if(!swatches.isEmpty()) {
            this.observer.onNext(swatches);
            this.observer.onComplete();
        }else
            this.observer.onError(new Throwable("couldn't get colors from bitmap"));
    }
}
 
開發者ID:ahmed-basyouni,項目名稱:RxPalette,代碼行數:14,代碼來源:BitmapAnalyzer.java

示例12: setSwatch

import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
public void setSwatch(final Palette.Swatch swatch) {
    setCardBackgroundColor(swatch.getRgb());

    final Collection<TextView> textViews = findTextViews(
            this, new ArrayList<TextView>()
    );

    if (!textViews.isEmpty()) {
        for (final TextView textView : textViews) {
            textView.setTextColor(swatch.getBodyTextColor());
        }
    }
}
 
開發者ID:PacktPublishing,項目名稱:Hands-On-Android-UI-Development,代碼行數:14,代碼來源:ColorizedCardView.java

示例13: Listener

import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
Listener(Observer<? super List<Palette.Swatch>> observer) {
    this.observer = observer;
    startBitmapAnalysis();
}
 
開發者ID:ahmed-basyouni,項目名稱:RxPalette,代碼行數:5,代碼來源:BitmapAnalyzer.java

示例14: get6ColorFormBitmap

import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
/**
 * 獲得圖片中出現最多的顏色
 * 0 活力顏色<br>
 * 1 亮的活力顏色<br>
 * 2 暗的活力顏色<br>
 * 3 柔和顏色<br>
 * 4 亮的柔和顏色<br>
 * 5 暗的柔和顏色<br>
 */
public static void get6ColorFormBitmap(@NonNull Bitmap bitmap, int defaultColor, int[] colors) {

    if (colors.length != 6)
        return;

    Palette palette;
    palette = new Palette.Builder(bitmap).generate();

    Palette.Swatch swatch;
    int color;

    if ((swatch = palette.getVibrantSwatch()) != null)
        color = swatch.getRgb();
    else color = defaultColor;
    colors[0] = color;

    if ((swatch = palette.getLightVibrantSwatch()) != null)
        color = swatch.getRgb();
    else color = defaultColor;
    colors[1] = color;

    if ((swatch = palette.getDarkVibrantSwatch()) != null)
        color = swatch.getRgb();
    else color = defaultColor;
    colors[2] = color;

    if ((swatch = palette.getMutedSwatch()) != null)
        color = swatch.getRgb();
    else color = defaultColor;
    colors[3] = color;

    if ((swatch = palette.getLightMutedSwatch()) != null)
        color = swatch.getRgb();
    else color = defaultColor;
    colors[4] = color;

    if ((swatch = palette.getDarkMutedSwatch()) != null)
        color = swatch.getRgb();
    else color = defaultColor;
    colors[5] = color;

}
 
開發者ID:DuanJiaNing,項目名稱:Musicoco,代碼行數:52,代碼來源:ColorUtils.java

示例15: Swatch

import android.support.v7.graphics.Palette; //導入方法依賴的package包/類
Swatch(@Nullable Palette.Swatch paletteSwatch) {
    if (paletteSwatch != null) {
        this.backgroundColor = paletteSwatch.getRgb();
        this.foregroundColor = paletteSwatch.getTitleTextColor();
    }
}
 
開發者ID:arunkumar9t2,項目名稱:chameleon-live-wallpaper,代碼行數:7,代碼來源:Swatch.java


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