本文整理汇总了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");
}
}
示例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指示器的颜色
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
});
}
示例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"));
}
}
示例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());
}
}
}
示例13: Listener
import android.support.v7.graphics.Palette; //导入方法依赖的package包/类
Listener(Observer<? super List<Palette.Swatch>> observer) {
this.observer = observer;
startBitmapAnalysis();
}
示例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;
}
示例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();
}
}