本文整理汇总了Java中android.support.v7.graphics.Palette类的典型用法代码示例。如果您正苦于以下问题:Java Palette类的具体用法?Java Palette怎么用?Java Palette使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Palette类属于android.support.v7.graphics包,在下文中一共展示了Palette类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changeColor
import android.support.v7.graphics.Palette; //导入依赖的package包/类
/**
* 改变各部分的颜色
* @param position 下标
*/
private void changeColor(final int position) {
Palette.Swatch swatch = mSwatchMap.get(position);
if (swatch != null){
setColor(swatch);//设置颜色
return;
}
// 用来提取颜色的Bitmap
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),mImgResources[position]);
// Palette的部分
Palette.Builder builder = Palette.from(bitmap);
builder.generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
//获取到充满活力的样本
Palette.Swatch vibrant = palette.getVibrantSwatch();
setColor(vibrant);//设置颜色
mSwatchMap.put(position,vibrant);//保存对应位置的样本对象
}
});
}
示例2: updatePalette
import android.support.v7.graphics.Palette; //导入依赖的package包/类
/**
* Updates colors based on the palette.
* If the palette is null, the default color is used in all cases.
*/
public void updatePalette(Palette palette) {
if (palette == null) {
for (int i = 0; i < NUM_COLOR_PROFILES; i++) {
setColorAtIndex(i, ExtractedColors.DEFAULT_COLOR);
}
} else {
// We currently don't use any of the colors defined by the Palette API,
// but this is how we would add them if we ever need them.
// setColorAtIndex(ExtractedColors.VIBRANT_INDEX,
// palette.getVibrantColor(ExtractedColors.DEFAULT_COLOR));
// setColorAtIndex(ExtractedColors.VIBRANT_DARK_INDEX,
// palette.getDarkVibrantColor(ExtractedColors.DEFAULT_DARK));
// setColorAtIndex(ExtractedColors.VIBRANT_LIGHT_INDEX,
// palette.getLightVibrantColor(ExtractedColors.DEFAULT_LIGHT));
// setColorAtIndex(ExtractedColors.MUTED_INDEX,
// palette.getMutedColor(DEFAULT_COLOR));
// setColorAtIndex(ExtractedColors.MUTED_DARK_INDEX,
// palette.getDarkMutedColor(ExtractedColors.DEFAULT_DARK));
// setColorAtIndex(ExtractedColors.MUTED_LIGHT_INDEX,
// palette.getLightVibrantColor(ExtractedColors.DEFAULT_LIGHT));
}
}
示例3: updateHotseatPalette
import android.support.v7.graphics.Palette; //导入依赖的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);
}
}
示例4: albumCover
import android.support.v7.graphics.Palette; //导入依赖的package包/类
public void albumCover(Drawable newAlbumCover) {
if (this.albumCover == newAlbumCover) return;
this.albumCover = newAlbumCover;
if (albumCover.hashCode() == 0) {
return;
}
if (!isNeedToFillAlbumCoverMap.containsKey(albumCover.hashCode())) {
//Bitmap bitmap = ((BitmapDrawable) albumCover).getBitmap();
Bitmap bitmap = DrawableUtils.drawableToBitmap(albumCover);
if (bitmap != null && !bitmap.isRecycled()) {
if (lastPaletteAsyncTask != null && !lastPaletteAsyncTask.isCancelled()) {
lastPaletteAsyncTask.cancel(true);
}
lastPaletteAsyncTask = Palette.from(bitmap).generate(palette -> {
int dominantColor = palette.getLightVibrantColor(Integer.MAX_VALUE);
if (dominantColor != Integer.MAX_VALUE) {
Color.colorToHSV(dominantColor, hsvArray);
isNeedToFillAlbumCoverMap.put(albumCover.hashCode(), hsvArray[2] > 0.65f);
postInvalidate();
}
});
// postInvalidate();
}
}
}
示例5: onBindViewHolder
import android.support.v7.graphics.Palette; //导入依赖的package包/类
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
final Place place = new PlaceData().placeList().get(position);
holder.placeName.setText(place.name);
Picasso.with(mContext).load(place.getImageResourceId(mContext)).into(holder.placeImage);
Bitmap photo = BitmapFactory.decodeResource(mContext.getResources(),
place.getImageResourceId(mContext));
Palette.generateAsync(photo, new Palette.PaletteAsyncListener(){
public void onGenerated(Palette palette){
int bgColor = palette.getMutedColor(mContext.getResources().getColor(android.R.color.black));
holder.placeNameHolder.setBackgroundColor(bgColor);
}
});
}
示例6: fetchColors
import android.support.v7.graphics.Palette; //导入依赖的package包/类
private void fetchColors(Bitmap img) {
Palette.from(img).generate(new Palette.PaletteAsyncListener() {
public void onGenerated(Palette palette) {
Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
Palette.Swatch mutedSwatch = palette.getMutedSwatch();
int bodyText = 0, titleText = 0, background = 0,
dominantColor = palette.getDominantColor(context.getResources().getColor(R.color.colorAccent));
if (vibrantSwatch != null && view != null) {
background = vibrantSwatch.getRgb();
bodyText = vibrantSwatch.getBodyTextColor();
titleText = vibrantSwatch.getTitleTextColor();
} else if (mutedSwatch != null && view != null) {
background = mutedSwatch.getRgb();
bodyText = mutedSwatch.getBodyTextColor();
titleText = mutedSwatch.getTitleTextColor();
}
if (bodyText == 0 || view == null)
return;
bodyTextAnimator(bodyText);
titleTextAnimator(titleText);
backgroundAnimator(background);
view.onDominantColorLoad(dominantColor);
}
});
}
示例7: getColor
import android.support.v7.graphics.Palette; //导入依赖的package包/类
@ColorInt
public static int getColor(@Nullable Palette palette, int fallback) {
if (palette != null) {
if (palette.getVibrantSwatch() != null) {
return palette.getVibrantSwatch().getRgb();
} else if (palette.getMutedSwatch() != null) {
return palette.getMutedSwatch().getRgb();
} else if (palette.getDarkVibrantSwatch() != null) {
return palette.getDarkVibrantSwatch().getRgb();
} else if (palette.getDarkMutedSwatch() != null) {
return palette.getDarkMutedSwatch().getRgb();
} else if (palette.getLightVibrantSwatch() != null) {
return palette.getLightVibrantSwatch().getRgb();
} else if (palette.getLightMutedSwatch() != null) {
return palette.getLightMutedSwatch().getRgb();
} else if (!palette.getSwatches().isEmpty()) {
return Collections.max(palette.getSwatches(), SwatchComparator.getInstance()).getRgb();
}
}
return fallback;
}
示例8: changeBanner
import android.support.v7.graphics.Palette; //导入依赖的package包/类
public void changeBanner(IOItem tmpItem) {
Bitmap bm = BitmapFactory.decodeResource(getResources(), tmpItem.getSrcId());
Palette.Builder pb = new Palette.Builder(bm);
pb.maximumColorCount(1);
itemImage.setImageResource(tmpItem.getSrcId());
itemTitle.setText(tmpItem.getName());
itemImage.setTag(1); // 保留图片资源属性,1表示收入
itemTitle.setTag(tmpItem.getSrcName()); // 保留图片资源名称作为标签,方便以后调用
// 获取图片颜色并改变上方banner的背景色
pb.generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
Palette.Swatch swatch = palette.getSwatches().get(0);
if (swatch != null) {
itemLayout.setBackgroundColor(swatch.getRgb());
} else {
}
}
});
}
示例9: changeBanner
import android.support.v7.graphics.Palette; //导入依赖的package包/类
public void changeBanner(IOItem tmpItem) {
Bitmap bm = BitmapFactory.decodeResource(getResources(), tmpItem.getSrcId());
Palette.Builder pb = new Palette.Builder(bm);
pb.maximumColorCount(1);
itemImage.setImageResource(tmpItem.getSrcId());
itemTitle.setText(tmpItem.getName());
itemImage.setTag(-1); // 保留图片资源属性,-1表示支出
itemTitle.setTag(tmpItem.getSrcName()); // 保留图片资源名称作为标签,方便以后调用
// 获取图片颜色并改变上方banner的背景色
pb.generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
Palette.Swatch swatch = palette.getSwatches().get(0);
if (swatch != null) {
itemLayout.setBackgroundColor(swatch.getRgb());
} else {
Log.d(TAG, "changeBanner: ");
}
}
});
}
示例10: get2ColorFormBitmap
import android.support.v7.graphics.Palette; //导入依赖的package包/类
/**
* 获得图片中出现最多的颜色
* 0 亮的活力颜色
* 1 亮的柔和颜色
*/
public static void get2ColorFormBitmap(@NonNull Bitmap bitmap, int defaultColor, int[] colors) {
if (colors.length != 2)
return;
Palette palette;
palette = new Palette.Builder(bitmap).generate();
Palette.Swatch swatch;
int color;
if ((swatch = palette.getLightVibrantSwatch()) != null)
color = swatch.getRgb();
else color = defaultColor;
colors[0] = color;
if ((swatch = palette.getLightMutedSwatch()) != null)
color = swatch.getRgb();
else color = defaultColor;
colors[1] = color;
}
示例11: getBestPaletteSwatchFrom
import android.support.v7.graphics.Palette; //导入依赖的package包/类
private static Palette.Swatch getBestPaletteSwatchFrom(Palette palette) {
if (palette != null) {
if (palette.getVibrantSwatch() != null)
return palette.getVibrantSwatch();
else if (palette.getMutedSwatch() != null)
return palette.getMutedSwatch();
else if (palette.getDarkVibrantSwatch() != null)
return palette.getDarkVibrantSwatch();
else if (palette.getDarkMutedSwatch() != null)
return palette.getDarkMutedSwatch();
else if (palette.getLightVibrantSwatch() != null)
return palette.getLightVibrantSwatch();
else if (palette.getLightMutedSwatch() != null)
return palette.getLightMutedSwatch();
else if (!palette.getSwatches().isEmpty())
return getBestPaletteSwatchFrom(palette.getSwatches());
}
return null;
}
示例12: populateDetails
import android.support.v7.graphics.Palette; //导入依赖的package包/类
/**
* Fills the TV Show Details in screen.
* @param container TVShowData
*/
private void populateDetails(final TVShowData container) {
if (container == null) {
return;
}
final Palette.PaletteAsyncListener paletteAsyncListener =
ActivityUtils.definePaletteAsyncListener(this, title, textRating, rating, starRating);
Callback callback =
ActivityUtils.defineCallback(paletteAsyncListener, backgroundPoster, tvShowPoster);
PopulateDetailsTitle(container);
PopulateDetailsPoster(container, callback);
PopulateDetailsGenresCountries(container);
PopulateDetailsProdCompanies(container);
PopulateDetailsStatus(container);
PopulateDetailsDates(container);
defineClickFavoriteButtons(container);
ActivityUtils.firebaseAnalyticsLogEventViewItem(
mFirebaseAnalytics, "" + tvShowId, tvShowTitle[0], TV_SHOWS);
}
示例13: onGenerated
import android.support.v7.graphics.Palette; //导入依赖的package包/类
/**
* Called when the {@link Palette} has been generated.
*
* @param palette
*/
@Override
public void onGenerated(Palette palette) {
int color;
if((color = palette.getDominantColor(0)) != 0) {
mFrameLayout.setBackgroundColor(color);
}
else if((color = palette.getVibrantColor(0)) != 0) {
mFrameLayout.setBackgroundColor(color);
}
else if((color = palette.getDarkVibrantColor(0)) != 0) {
mFrameLayout.setBackgroundColor(color);
}
else if((color = palette.getDarkMutedColor(0)) != 0) {
mFrameLayout.setBackgroundColor(color);
}
}
示例14: mapColors
import android.support.v7.graphics.Palette; //导入依赖的package包/类
private WritableMap mapColors(Bitmap bm) {
Palette palette = Palette.from(bm).generate();
WritableMap map = Arguments.createMap();
String averageColor = intColorToHex(calculateAvgColor(bm, 5));
String dominantColor = intColorToHex(palette.getDominantColor(defaultColor));
String vibrantColor = intColorToHex(palette.getVibrantColor(defaultColor));
String darkVibrantColor = intColorToHex(palette.getDarkVibrantColor(defaultColor));
String lightVibrantColor = intColorToHex(palette.getLightVibrantColor(defaultColor));
map.putString("averageColor", averageColor);
map.putString("dominantColor", dominantColor);
map.putString("vibrantColor", vibrantColor);
map.putString("darkVibrantColor", darkVibrantColor);
map.putString("lightVibrantColor", lightVibrantColor);
return map;
}
示例15: getPaletteColors
import android.support.v7.graphics.Palette; //导入依赖的package包/类
public static int[] getPaletteColors(Bitmap art){
int color = Color.TRANSPARENT;
int textColor = Color.WHITE;
int isLight = 0;
if(art != null){
Palette lastPalette = Palette.generate(currentArt);
color = lastPalette.getDarkVibrantColor(color);
if(color==Color.TRANSPARENT){
color = lastPalette.getLightVibrantColor(color);
if(color!=Color.TRANSPARENT){
textColor = Color.BLACK;
isLight = 1;
}else{
color = lastPalette.getLightMutedColor(color);
if(color!=Color.TRANSPARENT){
textColor = Color.BLACK;
isLight = 1;
}else{
color = lastPalette.getDarkMutedColor(color);
isLight = 0;
}
}
}
}
return new int[]{color,textColor,isLight};
}