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


Java ColorUtils.calculateLuminance方法代碼示例

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


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

示例1: setup

import android.support.v4.graphics.ColorUtils; //導入方法依賴的package包/類
void setup(int position) {
    int color = colors[position];
    int alpha = Color.alpha(color);
    colorPanelView.setColor(color);
    imageView.setImageResource(selectedPosition == position ? R.drawable.cpv_preset_checked : 0);
    if (alpha != 255) {
        if (alpha <= ColorPickerDialog.ALPHA_THRESHOLD) {
            colorPanelView.setBorderColor(color | 0xFF000000);
            imageView.setColorFilter(/*color | 0xFF000000*/Color.BLACK, PorterDuff.Mode.SRC_IN);
        } else {
            colorPanelView.setBorderColor(originalBorderColor);

            if (ColorUtils.calculateLuminance(colors[position]) >= 0.65) {
                imageView.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_IN);
            } else {
                imageView.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
            }
        }
    } else {
        setColorFilter(position);
    }
    setOnClickListener(position);
}
 
開發者ID:nhocga1995s,項目名稱:MyCalendar,代碼行數:24,代碼來源:ColorPaletteAdapter.java

示例2: setColorFilter

import android.support.v4.graphics.ColorUtils; //導入方法依賴的package包/類
private void setColorFilter(int position) {
    if (position == selectedPosition) {
        if (ColorUtils.calculateLuminance(colors[position]) >= 0.65) {
            imageView.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_IN);
        } else {
            imageView.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN);
        }
    } else {
        imageView.setColorFilter(null);
    }
}
 
開發者ID:nhocga1995s,項目名稱:MyCalendar,代碼行數:12,代碼來源:ColorPaletteAdapter.java

示例3: setColorFilter

import android.support.v4.graphics.ColorUtils; //導入方法依賴的package包/類
private void setColorFilter(int position) {
  if (position == selectedPosition && ColorUtils.calculateLuminance(colors[position]) >= 0.65) {
    imageView.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_IN);
  } else {
    imageView.setColorFilter(null);
  }
}
 
開發者ID:Blankeer,項目名稱:MDWechat,代碼行數:8,代碼來源:ColorPaletteAdapter.java

示例4: setInnerColor

import android.support.v4.graphics.ColorUtils; //導入方法依賴的package包/類
private void setInnerColor(int color, boolean needsColorReset) {
    if (mInnerColor == (mInnerColor = color) && !needsColorReset) return;

    // Inverse the drawable if needed
    boolean isBright = ColorUtils.calculateLuminance(color) > 0.5;
    mDrawable.setColorFilter(isBright ? mInverseColorFilter : null);
}
 
開發者ID:AChep,項目名稱:AcDisplay,代碼行數:8,代碼來源:CircleView.java

示例5: setCurrentColor

import android.support.v4.graphics.ColorUtils; //導入方法依賴的package包/類
public void setCurrentColor(@ColorInt int currentColor) {
	this.currentColor = currentColor;
	currentColorLuminance = ColorUtils.calculateLuminance(this.currentColor);
}
 
開發者ID:ShamylZakariya,項目名稱:FlyoutMenus,代碼行數:5,代碼來源:PaletteFlyoutMenu.java

示例6: onCreateView

import android.support.v4.graphics.ColorUtils; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    Bundle arguments = getArguments();

    View fragment = inflater.inflate(arguments.getInt(ARGUMENT_LAYOUT_RES,
            R.layout.fragment_simple_slide), container, false);

    TextView titleView = (TextView) fragment.findViewById(R.id.mi_title);
    TextView descriptionView = (TextView) fragment.findViewById(R.id.mi_description);
    ImageView imageView = (ImageView) fragment.findViewById(R.id.mi_image);

    CharSequence title = arguments.getCharSequence(ARGUMENT_TITLE);
    int titleRes = arguments.getInt(ARGUMENT_TITLE_RES);
    CharSequence description = arguments.getCharSequence(ARGUMENT_DESCRIPTION);
    int descriptionRes = arguments.getInt(ARGUMENT_DESCRIPTION_RES);
    int imageRes = arguments.getInt(ARGUMENT_IMAGE_RES);
    int backgroundRes = arguments.getInt(ARGUMENT_BACKGROUND_RES);

    //Title
    if (titleView != null) {
        if (title != null) {
            titleView.setText(title);
            titleView.setVisibility(View.VISIBLE);
        } else if (titleRes != 0) {
            titleView.setText(titleRes);
            titleView.setVisibility(View.VISIBLE);
        } else {
            titleView.setVisibility(View.GONE);
        }
    }

    //Description
    if (descriptionView != null) {
        if (description != null) {
            descriptionView.setText(description);
            descriptionView.setVisibility(View.VISIBLE);
        } else if (descriptionRes != 0) {
            descriptionView.setText(descriptionRes);
            descriptionView.setVisibility(View.VISIBLE);
        } else {
            descriptionView.setVisibility(View.GONE);
        }
    }

    //Image
    if (imageView != null) {
        if (imageRes != 0) {
            imageView.setImageResource(imageRes);
            imageView.setVisibility(View.VISIBLE);
        } else {
            imageView.setVisibility(View.GONE);
        }
    }
    
    @ColorInt
    int textColorPrimary;
    @ColorInt
    int textColorSecondary;

    if (backgroundRes != 0 &&
            ColorUtils.calculateLuminance(ContextCompat.getColor(getContext(), backgroundRes)) < 0.6) {
        //Use light text color
        textColorPrimary = ContextCompat.getColor(getContext(), R.color.mi_text_color_primary_dark);
        textColorSecondary = ContextCompat.getColor(getContext(), R.color.mi_text_color_secondary_dark);
    } else {
        //Use dark text color
        textColorPrimary = ContextCompat.getColor(getContext(), R.color.mi_text_color_primary_light);
        textColorSecondary = ContextCompat.getColor(getContext(), R.color.mi_text_color_secondary_light);
    }
    
    if (titleView != null) {
        titleView.setTextColor(textColorPrimary);
    }
    if (descriptionView != null) {
        descriptionView.setTextColor(textColorSecondary);
    }

    return fragment;
}
 
開發者ID:SpongeBobSun,項目名稱:Prodigal,代碼行數:81,代碼來源:SimpleSlide.java


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