本文整理汇总了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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例5: setCurrentColor
import android.support.v4.graphics.ColorUtils; //导入方法依赖的package包/类
public void setCurrentColor(@ColorInt int currentColor) {
this.currentColor = currentColor;
currentColorLuminance = ColorUtils.calculateLuminance(this.currentColor);
}
示例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;
}