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


Java Palette類代碼示例

本文整理匯總了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);//保存對應位置的樣本對象
        }
    });
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:25,代碼來源:PaletteActivity2.java

示例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));
    }
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:28,代碼來源:ExtractedColors.java

示例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);
    }
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:29,代碼來源:ExtractedColors.java

示例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();
        }
    }
}
 
開發者ID:RajneeshSingh007,項目名稱:MusicX-music-player,代碼行數:26,代碼來源:PlayPauseButton.java

示例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);
        }
    });

}
 
開發者ID:anwarcse12028,項目名稱:Traveler-List,代碼行數:17,代碼來源:TravelListAdapter.java

示例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);
        }
    });

}
 
開發者ID:architjn,項目名稱:YAAB,代碼行數:27,代碼來源:PlayerPresenter.java

示例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;
}
 
開發者ID:h4h13,項目名稱:RetroMusicPlayer,代碼行數:22,代碼來源:RetroMusicColorUtil.java

示例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 {

            }
        }
    });

}
 
開發者ID:yuukidach,項目名稱:Ucount,代碼行數:25,代碼來源:EarnFragment.java

示例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: ");
            }
        }
    });
}
 
開發者ID:yuukidach,項目名稱:Ucount,代碼行數:25,代碼來源:CostFragment.java

示例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;

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

示例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;
}
 
開發者ID:TheAndroidMaster,項目名稱:MediaNotification,代碼行數:20,代碼來源:PaletteUtils.java

示例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);
}
 
開發者ID:an-garcia,項目名稱:MovieGuide,代碼行數:26,代碼來源:TVShowActivity.java

示例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);
    }
}
 
開發者ID:wax911,項目名稱:anitrend-app,代碼行數:22,代碼來源:PreviewImageAdapter.java

示例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;
}
 
開發者ID:hu9osaez,項目名稱:react-native-dominant-color,代碼行數:19,代碼來源:RNDominantColorModule.java

示例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};
}
 
開發者ID:jathak,項目名稱:musicwidget,代碼行數:27,代碼來源:StandardWidget.java


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