本文整理匯總了Java中android.graphics.drawable.Drawable類的典型用法代碼示例。如果您正苦於以下問題:Java Drawable類的具體用法?Java Drawable怎麽用?Java Drawable使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Drawable類屬於android.graphics.drawable包,在下文中一共展示了Drawable類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setupStandardMenuItemViewHolder
import android.graphics.drawable.Drawable; //導入依賴的package包/類
private void setupStandardMenuItemViewHolder(StandardMenuItemViewHolder holder,
View convertView, final MenuItem item) {
// Set up the icon.
Drawable icon = item.getIcon();
holder.image.setImageDrawable(icon);
holder.image.setVisibility(icon == null ? View.GONE : View.VISIBLE);
holder.image.setChecked(item.isChecked());
holder.text.setText(item.getTitle());
holder.text.setContentDescription(item.getTitleCondensed());
boolean isEnabled = item.isEnabled();
// Set the text color (using a color state list).
holder.text.setEnabled(isEnabled);
// This will ensure that the item is not highlighted when selected.
convertView.setEnabled(isEnabled);
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mAppMenu.onItemClick(item);
}
});
}
示例2: getFullResIcon
import android.graphics.drawable.Drawable; //導入依賴的package包/類
/**
* 根據ActivityInfo繪製圖標
* @param info
* @return
*/
public Drawable getFullResIcon(ActivityInfo info) {
Resources resources;
try {
resources = mPackageManager.getResourcesForApplication(
info.applicationInfo);
} catch (PackageManager.NameNotFoundException e) {
resources = null;
}
if (resources != null) {
int iconId = info.getIconResource();
if (iconId != 0) {
return getFullResIcon(resources, iconId);
}
}
return getFullResDefaultActivityIcon();
}
示例3: showDetails
import android.graphics.drawable.Drawable; //導入依賴的package包/類
/**
* Hide list, show details and instruct the details view to show the selected book.
*/
@Override
public void showDetails(Book book, Drawable thumb) {
final FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction ft = fragmentManager.beginTransaction();
BookDetailsFragment details = (BookDetailsFragment) fragmentManager.findFragmentById(R.id.book_details);
if (book != null) {
// If null passed, we only configure fragment transaction here.
details.showDetails(book, thumb);
}
ft.show(details);
ft.hide(fragmentManager.findFragmentById(R.id.book_list));
ft.addToBackStack("details"); // Use the back button to return to the search list view.
ft.commit();
}
示例4: constructItem
import android.graphics.drawable.Drawable; //導入依賴的package包/類
private PieItem constructItem(int width, ButtonType type, Drawable image, int minimumImageSize) {
ImageView view = new ImageView(mContext);
view.setImageDrawable(image);
view.setMinimumWidth(minimumImageSize);
view.setMinimumHeight(minimumImageSize);
LayoutParams lp = new LayoutParams(minimumImageSize, minimumImageSize);
view.setLayoutParams(lp);
PieItem item = new PieItem(mContext, mGbContext, mPieContainer, 0, width, type, view, mColorInfo);
item.setOnClickListener(this);
item.setOnLongPressListener(mLongPressHandler);
return item;
}
示例5: keyPressed
import android.graphics.drawable.Drawable; //導入依賴的package包/類
protected void keyPressed() {
if (isEnabled() && isClickable()) {
Drawable selector = this.mSelector;
Rect selectorRect = this.mSelectorRect;
if (selector == null) {
return;
}
if ((isFocused() || touchModeDrawsInPressedState()) && !selectorRect.isEmpty()) {
View v = getChildAt(this.mSelectedPosition - this.mFirstPosition);
if (v != null) {
if (!v.hasFocusable()) {
v.setPressed(true);
} else {
return;
}
}
setPressed(true);
boolean longClickable = isLongClickable();
Drawable d = selector.getCurrent();
if (d != null && (d instanceof TransitionDrawable)) {
if (longClickable) {
((TransitionDrawable) d).startTransition(ViewConfiguration.getLongPressTimeout());
} else {
((TransitionDrawable) d).resetTransition();
}
}
if (longClickable && !this.mDataChanged) {
if (this.mPendingCheckForKeyLongPress == null) {
this.mPendingCheckForKeyLongPress = new CheckForKeyLongPress(this, null);
}
this.mPendingCheckForKeyLongPress.rememberWindowAttachCount();
postDelayed(this.mPendingCheckForKeyLongPress, (long) ViewConfiguration.getLongPressTimeout());
}
}
}
}
示例6: getEmojiDrawable
import android.graphics.drawable.Drawable; //導入依賴的package包/類
private @Nullable Drawable getEmojiDrawable(@Nullable EmojiDrawInfo drawInfo) {
if (drawInfo == null) {
return null;
}
final EmojiDrawable drawable = new EmojiDrawable(drawInfo, decodeScale);
drawInfo.getPage().get().addListener(new FutureTaskListener<Bitmap>() {
@Override public void onSuccess(final Bitmap result) {
Util.runOnMain(new Runnable() {
@Override public void run() {
drawable.setBitmap(result);
}
});
}
@Override public void onFailure(ExecutionException error) {
Log.w(TAG, error);
}
});
return drawable;
}
示例7: loadAlbumCover
import android.graphics.drawable.Drawable; //導入依賴的package包/類
protected void loadAlbumCover(Song song, final ViewHolder holder) {
if (holder.image == null) return;
SongGlideRequest.Builder.from(Glide.with(activity), song)
.checkIgnoreMediaStore(activity)
.generatePalette(activity).build()
.into(new PhonographColoredTarget(holder.image) {
@Override
public void onLoadCleared(Drawable placeholder) {
super.onLoadCleared(placeholder);
setColors(getDefaultFooterColor(), holder);
}
@Override
public void onColorReady(int color) {
if (usePalette)
setColors(color, holder);
else
setColors(getDefaultFooterColor(), holder);
}
});
}
示例8: loadMimeIcon
import android.graphics.drawable.Drawable; //導入依賴的package包/類
public static Drawable loadMimeIcon(
Context context, String mimeType, String authority, String docId, int mode) {
if (Document.MIME_TYPE_DIR.equals(mimeType)) {
if (MediaDocumentsProvider.AUTHORITY.equals(authority)) {
if(docId.startsWith(MediaDocumentsProvider.TYPE_ALBUM)){
return ContextCompat.getDrawable(context, R.drawable.ic_doc_album);
}
else if(docId.startsWith(MediaDocumentsProvider.TYPE_IMAGES_BUCKET)){
return ContextCompat.getDrawable(context, R.drawable.ic_doc_folder);
}
else if(docId.startsWith(MediaDocumentsProvider.TYPE_VIDEOS_BUCKET)){
return ContextCompat.getDrawable(context, R.drawable.ic_doc_folder);
}
}
if (mode == DocumentsActivity.State.MODE_GRID) {
return ContextCompat.getDrawable(context, R.drawable.ic_grid_folder);
} else {
return ContextCompat.getDrawable(context, R.drawable.ic_doc_folder);
}
}
return loadMimeIcon(context, mimeType);
}
示例9: onDraw
import android.graphics.drawable.Drawable; //導入依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
Drawable[] drawables = getCompoundDrawables();
if (drawables != null) {
Drawable drawableLeft = drawables[0];
if (drawableLeft != null) {
float textWidth = getPaint().measureText(getText().toString());
int drawablePadding = getCompoundDrawablePadding();
int drawableWidth = 0;
drawableWidth = drawableLeft.getIntrinsicWidth();
float bodyWidth = textWidth + drawableWidth + drawablePadding;
canvas.translate((getWidth() - bodyWidth) / 2 -20, 0);
}
}
super.onDraw(canvas);
}
示例10: onViewClicked
import android.graphics.drawable.Drawable; //導入依賴的package包/類
@OnClick({R.id.start, R.id.red_line, R.id.gray_line})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.start:
Bitmap bp = pint1.createSnapshoot();
Drawable dw = new BitmapDrawable(getResources(),bp);
im.setImageDrawable(dw);
break;
case R.id.red_line:
break;
case R.id.gray_line:
break;
}
}
示例11: draw
import android.graphics.drawable.Drawable; //導入依賴的package包/類
public void draw(@NonNull Canvas canvas) {
super.draw(canvas);
if (this.mForeground != null) {
Drawable foreground = this.mForeground;
if (this.mForegroundBoundsChanged) {
this.mForegroundBoundsChanged = false;
Rect selfBounds = this.mSelfBounds;
Rect overlayBounds = this.mOverlayBounds;
int w = getRight() - getLeft();
int h = getBottom() - getTop();
if (this.mForegroundInPadding) {
selfBounds.set(0, 0, w, h);
} else {
selfBounds.set(getPaddingLeft(), getPaddingTop(), w - getPaddingRight(), h - getPaddingBottom());
}
Gravity.apply(this.mForegroundGravity, foreground.getIntrinsicWidth(), foreground.getIntrinsicHeight(), selfBounds, overlayBounds);
foreground.setBounds(overlayBounds);
}
foreground.draw(canvas);
}
}
示例12: getOtherButtonBg
import android.graphics.drawable.Drawable; //導入依賴的package包/類
private Drawable getOtherButtonBg(String[] titles, int i) {
if (titles.length == 1) {
return mAttrs.otherButtonSingleBackground;
}
if (titles.length == 2) {
switch (i) {
case 0:
return mAttrs.otherButtonTopBackground;
case 1:
return mAttrs.otherButtonBottomBackground;
}
}
if (titles.length > 2) {
if (i == 0) {
return mAttrs.otherButtonTopBackground;
}
if (i == (titles.length - 1)) {
return mAttrs.otherButtonBottomBackground;
}
return mAttrs.getOtherButtonMiddleBackground();
}
return null;
}
示例13: createFillDrawable
import android.graphics.drawable.Drawable; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[]{-android.R.attr.state_enabled}, createCircleDrawable(mColorDisabled));
drawable.addState(new int[]{android.R.attr.state_pressed}, createCircleDrawable(mColorPressed));
drawable.addState(new int[]{}, createCircleDrawable(mColorNormal));
if (Util.hasLollipop()) {
RippleDrawable ripple = new RippleDrawable(new ColorStateList(new int[][]{{}},
new int[]{mColorRipple}), drawable, null);
setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, view.getWidth(), view.getHeight());
}
});
setClipToOutline(true);
mBackgroundDrawable = ripple;
return ripple;
}
mBackgroundDrawable = drawable;
return drawable;
}
示例14: styleSeekBar
import android.graphics.drawable.Drawable; //導入依賴的package包/類
private void styleSeekBar() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
final Drawable progressDrawable = mSeekBar.getProgressDrawable();
if (progressDrawable != null) {
if (progressDrawable instanceof LayerDrawable) {
LayerDrawable ld = (LayerDrawable) progressDrawable;
int layers = ld.getNumberOfLayers();
for (int i = 0; i < layers; i++) {
ld.getDrawable(i).mutate().setColorFilter(mTintColor, PorterDuff.Mode.SRC_ATOP);
}
} else {
progressDrawable.mutate().setColorFilter(mTintColor, PorterDuff.Mode.SRC_ATOP);
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
final Drawable thumb = mSeekBar.getThumb();
if (thumb != null) {
thumb.mutate().setColorFilter(mTintColor, PorterDuff.Mode.SRC_ATOP);
}
}
}
}
示例15: setSelected
import android.graphics.drawable.Drawable; //導入依賴的package包/類
private void setSelected(boolean selected) {
final View imageView = itemView.findViewById(R.id.image);
if (selected) {
final Drawable selectorOverlay = Util
.getAlbumItemSelectorOverlay(imageView.getContext());
imageView.post(new Runnable() {
@Override
public void run() {
imageView.getOverlay().clear();
if (selectorOverlay != null) {
selectorOverlay.setBounds(0, 0,
imageView.getWidth(),
imageView.getHeight());
imageView.getOverlay().add(selectorOverlay);
}
}
});
} else {
imageView.post(new Runnable() {
@Override
public void run() {
imageView.getOverlay().clear();
}
});
}
}