本文整理汇总了Java中android.graphics.drawable.PaintDrawable.setIntrinsicWidth方法的典型用法代码示例。如果您正苦于以下问题:Java PaintDrawable.setIntrinsicWidth方法的具体用法?Java PaintDrawable.setIntrinsicWidth怎么用?Java PaintDrawable.setIntrinsicWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.graphics.drawable.PaintDrawable
的用法示例。
在下文中一共展示了PaintDrawable.setIntrinsicWidth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getView
import android.graphics.drawable.PaintDrawable; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ApplicationInfo info = mApplications.get(position);
if (convertView == null) {
final LayoutInflater inflater = getLayoutInflater();
convertView = inflater.inflate(R.layout.application, parent, false);
}
Drawable icon = info.icon;
if (!info.filtered) {
//final Resources resources = getContext().getResources();
int width = 42;//(int) resources.getDimension(android.R.dimen.app_icon_size);
int height = 42;//(int) resources.getDimension(android.R.dimen.app_icon_size);
final int iconWidth = icon.getIntrinsicWidth();
final int iconHeight = icon.getIntrinsicHeight();
if (icon instanceof PaintDrawable) {
PaintDrawable painter = (PaintDrawable) icon;
painter.setIntrinsicWidth(width);
painter.setIntrinsicHeight(height);
}
if (width > 0 && height > 0 && (width < iconWidth || height < iconHeight)) {
final float ratio = (float) iconWidth / iconHeight;
if (iconWidth > iconHeight) {
height = (int) (width / ratio);
} else if (iconHeight > iconWidth) {
width = (int) (height * ratio);
}
final Bitmap.Config c =
icon.getOpacity() != PixelFormat.OPAQUE ?
Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
final Bitmap thumb = Bitmap.createBitmap(width, height, c);
final Canvas canvas = new Canvas(thumb);
canvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, 0));
// Copy the old bounds to restore them later
// If we were to do oldBounds = icon.getBounds(),
// the call to setBounds() that follows would
// change the same instance and we would lose the
// old bounds
mOldBounds.set(icon.getBounds());
icon.setBounds(0, 0, width, height);
icon.draw(canvas);
icon.setBounds(mOldBounds);
icon = info.icon = new BitmapDrawable(thumb);
info.filtered = true;
}
}
final TextView textView = (TextView) convertView.findViewById(R.id.label);
textView.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null);
textView.setText(info.title);
return convertView;
}
示例2: init
import android.graphics.drawable.PaintDrawable; //导入方法依赖的package包/类
private void init(AttributeSet attrs) {
if (attributes == null)
attributes = new Attributes(this, getResources());
if (attrs != null) {
TypedArray a = getContext().obtainStyledAttributes(attrs, com.cengalabs.flatui.R.styleable.fl_FlatSeekBar);
// getting common attributes
int customTheme = a.getResourceId(com.cengalabs.flatui.R.styleable.fl_FlatSeekBar_fl_theme, Attributes.DEFAULT_THEME);
attributes.setThemeSilent(customTheme, getResources());
attributes.setSize(a.getDimensionPixelSize(com.cengalabs.flatui.R.styleable.fl_FlatSeekBar_fl_size, Attributes.DEFAULT_SIZE_PX));
a.recycle();
}
// setting thumb
PaintDrawable thumb = new PaintDrawable(attributes.getColor(0));
thumb.setCornerRadius(attributes.getSize() * 9 / 8);
thumb.setIntrinsicWidth(attributes.getSize() * 9 / 4);
thumb.setIntrinsicHeight(attributes.getSize() * 9 / 4);
setThumb(thumb);
// progress
PaintDrawable progress = new PaintDrawable(attributes.getColor(1));
progress.setCornerRadius(attributes.getSize());
progress.setIntrinsicHeight(attributes.getSize());
progress.setIntrinsicWidth(attributes.getSize());
progress.setDither(true);
ClipDrawable progressClip = new ClipDrawable(progress, Gravity.LEFT, ClipDrawable.HORIZONTAL);
// secondary progress
PaintDrawable secondary = new PaintDrawable(attributes.getColor(2));
secondary.setCornerRadius(attributes.getSize());
secondary.setIntrinsicHeight(attributes.getSize());
ClipDrawable secondaryProgressClip = new ClipDrawable(secondary, Gravity.LEFT, ClipDrawable.HORIZONTAL);
// background
PaintDrawable background = new PaintDrawable(attributes.getColor(3));
background.setCornerRadius(attributes.getSize());
background.setIntrinsicHeight(attributes.getSize());
// applying drawable
LayerDrawable ld = (LayerDrawable) getProgressDrawable();
ld.setDrawableByLayerId(R.id.background, background);
ld.setDrawableByLayerId(R.id.progress, progressClip);
ld.setDrawableByLayerId(R.id.secondaryProgress, secondaryProgressClip);
}
示例3: init
import android.graphics.drawable.PaintDrawable; //导入方法依赖的package包/类
private void init(AttributeSet attrs) {
if (attributes == null)
attributes = new Attributes(this, getResources());
if (attrs != null) {
TypedArray a = getContext().obtainStyledAttributes(attrs,
R.styleable.fl_FlatSeekBar);
// getting common attributes
int customTheme = a.getResourceId(
R.styleable.fl_FlatSeekBar_fl_theme,
Attributes.DEFAULT_THEME);
attributes.setThemeSilent(customTheme, getResources());
attributes.setSize(a.getDimensionPixelSize(
R.styleable.fl_FlatSeekBar_fl_size,
Attributes.DEFAULT_SIZE_PX));
a.recycle();
}
// setting thumb
PaintDrawable thumb = new PaintDrawable(attributes.getColor(0));
thumb.setCornerRadius(attributes.getSize() * 9 / 8);
thumb.setIntrinsicWidth(attributes.getSize() * 9 / 4);
thumb.setIntrinsicHeight(attributes.getSize() * 9 / 4);
setThumb(thumb);
// progress
PaintDrawable progress = new PaintDrawable(attributes.getColor(1));
progress.setCornerRadius(attributes.getSize());
progress.setIntrinsicHeight(attributes.getSize());
progress.setIntrinsicWidth(attributes.getSize());
progress.setDither(true);
ClipDrawable progressClip = new ClipDrawable(progress, Gravity.LEFT,
ClipDrawable.HORIZONTAL);
// secondary progress
PaintDrawable secondary = new PaintDrawable(attributes.getColor(2));
secondary.setCornerRadius(attributes.getSize());
secondary.setIntrinsicHeight(attributes.getSize());
ClipDrawable secondaryProgressClip = new ClipDrawable(secondary,
Gravity.LEFT, ClipDrawable.HORIZONTAL);
// background
PaintDrawable background = new PaintDrawable(attributes.getColor(3));
background.setCornerRadius(attributes.getSize());
background.setIntrinsicHeight(attributes.getSize());
// applying drawable
LayerDrawable ld = (LayerDrawable) getProgressDrawable();
ld.setDrawableByLayerId(android.R.id.background, background);
ld.setDrawableByLayerId(android.R.id.progress, progressClip);
ld.setDrawableByLayerId(android.R.id.secondaryProgress,
secondaryProgressClip);
}
示例4: getView
import android.graphics.drawable.PaintDrawable; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ApplicationInfo info = mApplications.get(position);
if (convertView == null) {
final LayoutInflater inflater = getLayoutInflater();
convertView = inflater.inflate(R.layout.application, parent, false);
}
Drawable icon = info.icon;
if (!info.filtered) {
final Resources resources = getContext().getResources(); //
int width = (int) resources.getDimension(android.R.dimen.app_icon_size); // 42;
int height = (int) resources.getDimension(android.R.dimen.app_icon_size); // 42;
final int iconWidth = icon.getIntrinsicWidth();
final int iconHeight = icon.getIntrinsicHeight();
if (icon instanceof PaintDrawable) {
PaintDrawable painter = (PaintDrawable) icon;
painter.setIntrinsicWidth(width);
painter.setIntrinsicHeight(height);
}
if (width > 0 && height > 0 && (width < iconWidth || height < iconHeight)) {
final float ratio = (float) iconWidth / iconHeight;
if (iconWidth > iconHeight) {
height = (int) (width / ratio);
} else if (iconHeight > iconWidth) {
width = (int) (height * ratio);
}
final Bitmap.Config c =
icon.getOpacity() != PixelFormat.OPAQUE ?
Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
final Bitmap thumb = Bitmap.createBitmap(width, height, c);
final Canvas canvas = new Canvas(thumb);
canvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, 0));
// Copy the old bounds to restore them later
// If we were to do oldBounds = icon.getBounds(),
// the call to setBounds() that follows would
// change the same instance and we would lose the
// old bounds
mOldBounds.set(icon.getBounds());
icon.setBounds(0, 0, width, height);
icon.draw(canvas);
icon.setBounds(mOldBounds);
icon = info.icon = new BitmapDrawable(thumb);
info.filtered = true;
}
}
final TextView textView = (TextView) convertView.findViewById(R.id.label);
textView.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null);
textView.setText(info.title);
return convertView;
}