本文整理汇总了Java中android.support.v7.graphics.Palette.getDominantSwatch方法的典型用法代码示例。如果您正苦于以下问题:Java Palette.getDominantSwatch方法的具体用法?Java Palette.getDominantSwatch怎么用?Java Palette.getDominantSwatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.graphics.Palette
的用法示例。
在下文中一共展示了Palette.getDominantSwatch方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例3: fromBitmapGetRgb
import android.support.v7.graphics.Palette; //导入方法依赖的package包/类
public int fromBitmapGetRgb(Bitmap bitmap) {
//Bitmap bitmap= BitmapFactory.decodeResource(getResources(), R.mipmap.img_video);
Palette palette = Palette.from(bitmap).generate();
//Palette.from(bitmap).maximumColorCount(32).addFilter();
if (palette.getVibrantSwatch() != null) {
Log.e(TAG, "fromBitmapGetRgb: 1"+palette.getVibrantSwatch().getRgb() );
return palette.getVibrantSwatch().getRgb();
}
if (palette.getLightMutedSwatch() != null) {
Log.e(TAG, "fromBitmapGetRgb: 2"+palette.getLightMutedSwatch().getRgb() );
return palette.getLightMutedSwatch().getRgb();
}
if (palette.getDarkVibrantSwatch() != null) {
Log.e(TAG, "fromBitmapGetRgb: 3"+palette.getDarkVibrantSwatch().getRgb() );
return palette.getDarkVibrantSwatch().getRgb();
}
if (palette.getDarkMutedSwatch() != null) {
Log.e(TAG, "fromBitmapGetRgb: 4"+palette.getDarkMutedSwatch().getRgb() );
return palette.getDarkMutedSwatch().getRgb();
}
if (palette.getDominantSwatch() != null) {
Log.e(TAG, "fromBitmapGetRgb: 5"+palette.getDominantSwatch().getRgb() );
return palette.getDominantSwatch().getRgb();
}
if (palette.getLightVibrantSwatch() != null) {
Log.e(TAG, "fromBitmapGetRgb: 6"+palette.getLightVibrantSwatch().getRgb() );
return palette.getLightVibrantSwatch().getRgb();
}
return Color.parseColor("#3F51B5");
}
示例4: applyPalette
import android.support.v7.graphics.Palette; //导入方法依赖的package包/类
private void applyPalette(Palette palette){
Palette.Swatch swatch=palette.getDarkVibrantSwatch();
if(swatch==null) swatch=palette.getDominantSwatch();
if(swatch!=null){
toggle.setBackgroundTintList(ColorStateList.valueOf(swatch.getRgb()));
}
}
示例5: getAvailableColor
import android.support.v7.graphics.Palette; //导入方法依赖的package包/类
/**
* Return Array with palette color
*
* @param context
* @param palette
* @return
*/
public static int[] getAvailableColor(Context context, Palette palette) {
int[] temp = new int[3]; //array with size 3
if (palette.getVibrantSwatch() != null) {
temp[0] = palette.getVibrantSwatch().getRgb();
temp[1] = palette.getVibrantSwatch().getTitleTextColor();
temp[2] = palette.getVibrantSwatch().getBodyTextColor();
} else if (palette.getMutedSwatch() != null) {
temp[0] = palette.getMutedSwatch().getRgb();
temp[1] = palette.getMutedSwatch().getTitleTextColor();
temp[2] = palette.getMutedSwatch().getBodyTextColor();
} else if (palette.getDarkVibrantSwatch() != null) {
temp[0] = palette.getDarkVibrantSwatch().getRgb();
temp[1] = palette.getDarkVibrantSwatch().getTitleTextColor();
temp[2] = palette.getDarkVibrantSwatch().getBodyTextColor();
} else if (palette.getDarkMutedSwatch() != null) {
temp[0] = palette.getDarkMutedSwatch().getRgb();
temp[1] = palette.getDarkMutedSwatch().getTitleTextColor();
temp[2] = palette.getDarkMutedSwatch().getBodyTextColor();
} else if (palette.getDominantSwatch() != null) {
temp[0] = palette.getDominantSwatch().getRgb();
temp[1] = palette.getDominantSwatch().getTitleTextColor();
temp[2] = palette.getDominantSwatch().getBodyTextColor();
} else {
String atkey = Helper.getATEKey(context);
int accent = Config.accentColor(context, atkey);
temp[0] = accent;
temp[1] = 0xffe5e5e5;
temp[2] = accent;
}
return temp;
}
示例6: getAvailableColor
import android.support.v7.graphics.Palette; //导入方法依赖的package包/类
public static int[] getAvailableColor(Context context, Palette palette) {
int[] temp = new int[3]; //array with size 3
if (palette.getDarkVibrantSwatch() != null) {
temp[0] = palette.getDarkVibrantSwatch().getRgb();
temp[1] = palette.getDarkVibrantSwatch().getTitleTextColor();
temp[2] = palette.getDarkVibrantSwatch().getBodyTextColor();
} else if (palette.getDarkMutedSwatch() != null) {
temp[0] = palette.getDarkMutedSwatch().getRgb();
temp[1] = palette.getDarkMutedSwatch().getTitleTextColor();
temp[2] = palette.getDarkMutedSwatch().getBodyTextColor();
} else if (palette.getVibrantSwatch() != null) {
temp[0] = palette.getVibrantSwatch().getRgb();
temp[1] = palette.getVibrantSwatch().getTitleTextColor();
temp[2] = palette.getVibrantSwatch().getBodyTextColor();
} else if (palette.getDominantSwatch() != null) {
temp[0] = palette.getDominantSwatch().getRgb();
temp[1] = palette.getDominantSwatch().getTitleTextColor();
temp[2] = palette.getDominantSwatch().getBodyTextColor();
} else if (palette.getMutedSwatch() != null) {
temp[0] = palette.getMutedSwatch().getRgb();
temp[1] = palette.getMutedSwatch().getTitleTextColor();
temp[2] = palette.getMutedSwatch().getBodyTextColor();
} else {
temp[0] = ContextCompat.getColor(context, R.color.MaterialGrey);
temp[1] = Color.WHITE;
temp[2] = Color.WHITE;
}
return temp;
}
示例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: extractSwatches
import android.support.v7.graphics.Palette; //导入方法依赖的package包/类
@NonNull
@WorkerThread
private List<Swatch> extractSwatches() {
final List<Swatch> colorSwatches = new ArrayList<>();
final List<Palette.Swatch> generatedSwatches = new ArrayList<>();
if (bitmap != null) {
final Palette palette;
if (noOfColors != 0) {
palette = Palette.from(bitmap).maximumColorCount(noOfColors).generate();
} else {
palette = Palette.from(bitmap).generate();
}
Palette.Swatch dominantSwatch = palette.getDominantSwatch();
Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
Palette.Swatch vibrantDarkSwatch = palette.getDarkVibrantSwatch();
Palette.Swatch vibrantLightSwatch = palette.getLightVibrantSwatch();
Palette.Swatch mutedSwatch = palette.getMutedSwatch();
Palette.Swatch mutedDarkSwatch = palette.getDarkMutedSwatch();
Palette.Swatch mutedLightSwatch = palette.getLightMutedSwatch();
if (vibrantSwatch != null && mutedSwatch == null) {
mutedSwatch = vibrantSwatch;
} else if (vibrantSwatch == null && mutedSwatch != null) {
vibrantSwatch = mutedSwatch;
}
if (vibrantDarkSwatch != null && mutedDarkSwatch == null) {
mutedDarkSwatch = vibrantDarkSwatch;
} else if (vibrantDarkSwatch == null && mutedDarkSwatch != null) {
vibrantDarkSwatch = mutedDarkSwatch;
}
if (vibrantLightSwatch != null && mutedLightSwatch == null) {
mutedLightSwatch = vibrantLightSwatch;
} else if (vibrantLightSwatch == null && mutedLightSwatch != null) {
vibrantLightSwatch = mutedLightSwatch;
}
generatedSwatches.add(dominantSwatch);
generatedSwatches.add(vibrantSwatch);
generatedSwatches.add(vibrantDarkSwatch);
generatedSwatches.add(vibrantLightSwatch);
generatedSwatches.add(mutedSwatch);
generatedSwatches.add(mutedDarkSwatch);
generatedSwatches.add(mutedLightSwatch);
for (final Palette.Swatch paletteSwatch : generatedSwatches) {
colorSwatches.add(paletteSwatch != null ? new Swatch(paletteSwatch) : null);
}
recycleBitmap();
}
return colorSwatches;
}
示例9: getDominantPaletteSwatch
import android.support.v7.graphics.Palette; //导入方法依赖的package包/类
private static Palette.Swatch getDominantPaletteSwatch(@NonNull final Bitmap bitmap) {
Palette palette = Palette.from(bitmap).generate();
return palette.getDominantSwatch();
}