android.content.Context#getDrawable ( )源码实例Demo

下面列出了android.content.Context#getDrawable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: odyssey   文件: ListViewItem.java
/**
 * Extracts the information from a playlist model.
 *
 * @param playlist The current playlist model.
 */
public void setPlaylist(final PlaylistModel playlist) {
    final Context context = getContext();

    // title
    String playlistTitle = playlist.getPlaylistName();

    // get icon
    Drawable icon = context.getDrawable(R.drawable.ic_queue_music_48dp);

    if (icon != null) {
        // get tint color
        int tintColor = ThemeUtils.getThemeColor(context, R.attr.odyssey_color_text_background_secondary);
        // tint the icon
        DrawableCompat.setTint(icon, tintColor);
    }

    setTitle(playlistTitle);
    setIcon(icon);
}
 
源代码2 项目: wearmouse   文件: MouseFragment.java
@Override
public Drawable getItemDrawable(int i) {
    Context context = getContext();
    switch (i) {
        case HandMode.LEFT:
            return context.getDrawable(R.drawable.ic_am_hand_left);
        case HandMode.CENTER:
            return context.getDrawable(R.drawable.ic_am_hand_center);
        case HandMode.RIGHT:
            return context.getDrawable(R.drawable.ic_am_hand_right);
        default:
            break;
    }
    return null;
}
 
源代码3 项目: smartcoins-wallet   文件: SendScreen.java
public static Drawable getDrawable(Context context, int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //>= API 21
        return context.getDrawable(id);
    } else {
        return context.getResources().getDrawable(id);
    }
}
 
源代码4 项目: fdroidclient   文件: SeekBarForegroundThumb.java
private void init(Context context) {
    this.context = context;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tickMark = context.getDrawable(R.drawable.seekbar_tickmark);
    } else {
        tickMark = context.getResources().getDrawable(R.drawable.seekbar_tickmark);
    }
}
 
源代码5 项目: NanoIconPack   文件: DividerItemDecoration.java
/**
     * Creates a divider {@link RecyclerView.ItemDecoration} that can be used with a
     * {@link LinearLayoutManager}.
     *
     * @param context Current context, it will be used to access resources.
     * @param orientation Divider orientation. Should be {@link #HORIZONTAL} or {@link #VERTICAL}.
     */
    public DividerItemDecoration(Context context, int orientation) {
//        final TypedArray a = context.obtainStyledAttributes(ATTRS);
//        mDivider = a.getDrawable(0);
//        a.recycle();
        // @By_syk
        mDivider = context.getDrawable(R.drawable.app_list_divider);
        setOrientation(orientation);
    }
 
public void setDefaultComplicationDrawable(int resourceId) {
    Context context = mWatchFaceArmsAndTicksView.getContext();
    mDefaultComplicationDrawable = context.getDrawable(resourceId);

    mLeftComplication.setImageDrawable(mDefaultComplicationDrawable);
    mLeftComplicationBackground.setVisibility(View.INVISIBLE);

    mRightComplication.setImageDrawable(mDefaultComplicationDrawable);
    mRightComplicationBackground.setVisibility(View.INVISIBLE);
}
 
源代码7 项目: revolution-irc   文件: TextSelectionHandleView.java
public static Drawable getDrawable(Context context, boolean rightHandle) {
    int resId = StyledAttributesHelper.getResourceId(context, rightHandle ?
            android.R.attr.textSelectHandleRight : android.R.attr.textSelectHandleLeft, -1);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        return context.getDrawable(resId);
    else
        return context.getResources().getDrawable(resId);
}
 
源代码8 项目: edx-app-android   文件: UiUtil.java
@Nullable
@SuppressWarnings("deprecation")
public static Drawable getDrawable(@NonNull Context context, @DrawableRes int drawableId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        return context.getDrawable(drawableId);

    //noinspection deprecation
    return context.getResources().getDrawable(drawableId);
}
 
源代码9 项目: AndroidPicker   文件: CompatUtils.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static Drawable getDrawable(Context context, @DrawableRes int drawableRes) {
    if (Build.VERSION.SDK_INT < 21) {
        //noinspection deprecation
        return context.getResources().getDrawable(drawableRes);
    } else {
        return context.getDrawable(drawableRes);
    }
}
 
源代码10 项目: android_9.0.0_r45   文件: AppSecurityPermissions.java
public Drawable loadGroupIcon(Context context, PackageManager pm) {
    if (icon != 0) {
        return loadUnbadgedIcon(pm);
    } else {
        return context.getDrawable(R.drawable.ic_perm_device_info);
    }
}
 
源代码11 项目: ChangeTabLayout   文件: DrawableUtils.java
static Drawable getDrawable(Context context, int drawableResId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return context.getDrawable(drawableResId);
    } else {
        try {
            return VectorDrawableCompat.create(context.getResources(), drawableResId, null);
        }catch (Resources.NotFoundException e){
            return ContextCompat.getDrawable(context, drawableResId);
        }
    }
}
 
源代码12 项目: picasso-transformations   文件: Utils.java
public static Drawable getMaskDrawable(Context context, int maskId) {
  Drawable drawable;
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    drawable = context.getDrawable(maskId);
  } else {
    drawable = context.getResources().getDrawable(maskId);
  }

  if (drawable == null) {
    throw new IllegalArgumentException("maskId is invalid");
  }

  return drawable;
}
 
源代码13 项目: geopaparazzi   文件: Compat.java
public static Drawable getDrawable(Context context, int id) {
        Drawable drawable = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            drawable = context.getDrawable(id);
        } else {
            drawable = AppCompatResources.getDrawable(context, id);
//            drawable = context.getResources().getDrawable(id);
        }
        return drawable;
    }
 
源代码14 项目: droidconat-2016   文件: Views.java
@TargetApi(LOLLIPOP)
@SuppressWarnings("deprecation")
public static Drawable getDrawable(Context context, @DrawableRes int id) {
    if (App.isCompatible(LOLLIPOP)) {
        return context.getDrawable(id);
    } else {
        return context.getResources().getDrawable(id);
    }
}
 
源代码15 项目: LaunchEnr   文件: TintedDrawableSpan.java
public TintedDrawableSpan(Context context, int resourceId) {
    super(ALIGN_BOTTOM);
    mDrawable = context.getDrawable(resourceId);
    mOldTint = 0;
}
 
源代码16 项目: FCM-for-Mojo   文件: ServerStatusPreference.java
private void updateStatus(String error) {
    Context context = getContext();
    Drawable icon = context.getDrawable(R.drawable.ic_status_error_24dp);
    updateStatus(context.getString(R.string.status_cannot_connect_server_error, error), R.attr.colorAlert, icon);
}
 
源代码17 项目: FirefoxReality   文件: CustomKeyboardView.java
public CustomKeyboardView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    LayoutInflater inflate =
            (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    int previewLayout = 0;
    int keyTextSize = 0;
    mKeyBackground = context.getDrawable(R.drawable.keyboard_key_background);
    mKeyCapStartBackground = context.getDrawable(R.drawable.keyboard_key_background);
    mVerticalCorrection = 0;
    previewLayout = 0;
    mPreviewOffset = 0;
    mPreviewHeight = 80;
    mKeyTextSize = context.getResources().getDimensionPixelSize(R.dimen.keyboard_key_text_size);
    mKeyTextColor = 0xFFFFFFFF;
    mLabelTextSize = context.getResources().getDimensionPixelSize(R.dimen.keyboard_key_longtext_size);
    mPopupLayout = R.layout.keyboard;
    mShadowColor = 0;
    mShadowRadius = 0;
    mBackgroundDimAmount = 0.5f;
    clearHover();

    mPreviewPopup = new PopupWindow(context);
    if (previewLayout != 0) {
        mPreviewText = (TextView) inflate.inflate(previewLayout, null);
        mPreviewTextSizeLarge = (int) mPreviewText.getTextSize();
        mPreviewPopup.setContentView(mPreviewText);
        mPreviewPopup.setBackgroundDrawable(null);
    } else {
        mShowPreview = false;
    }

    mPreviewPopup.setTouchable(false);

    mPopupKeyboard = new PopupWindow(context);
    mPopupKeyboard.setBackgroundDrawable(null);
    //mPopupKeyboard.setClippingEnabled(false);

    mPopupParent = this;
    //mPredicting = true;

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setTextSize(keyTextSize);
    mPaint.setTextAlign(Align.CENTER);
    mPaint.setAlpha(255);
    mPaint.setTypeface(Typeface.create("sans-serif",Typeface.NORMAL));

    mPadding = new Rect(0, 0, 0, 0);
    mMiniKeyboardCache = new HashMap<>();
    mKeyBackground.getPadding(mPadding);
    mKeyboardHoveredPadding = getResources().getDimensionPixelSize(R.dimen.keyboard_key_hovered_padding);
    mKeyboardPressedPadding = getResources().getDimensionPixelSize(R.dimen.keyboard_key_pressed_padding);

    mSwipeThreshold = (int) (500 * getResources().getDisplayMetrics().density);
    mDisambiguateSwipe = false;

    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    resetMultiTap();

    mForegroundColor = context.getColor(R.color.asphalt);
    mSelectedForegroundColor = context.getColor(R.color.fog);
}
 
源代码18 项目: Bus-Tracking-Parent   文件: ToastyUtils.java
static Drawable getDrawable(@NonNull Context context, @DrawableRes int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        return context.getDrawable(id);
    else
        return context.getResources().getDrawable(id);
}
 
源代码19 项目: MyBookshelf   文件: DividerGridItemDecoration.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public DividerGridItemDecoration(Context context, @DrawableRes int widthDividerRes, @DrawableRes int heightDividerRes) {
    mWidthDivider = context.getDrawable(widthDividerRes);
    mHeightDivider = context.getDrawable(heightDividerRes);
}
 
源代码20 项目: MaterialSpinner   文件: Utils.java
/**
 * Return a drawable object associated with a particular resource ID.
 *
 * <p>Starting in {@link android.os.Build.VERSION_CODES#LOLLIPOP}, the returned drawable will be styled for the
 * specified Context's theme.</p>
 *
 * @param id The desired resource identifier, as generated by the aapt tool.
 * This integer encodes the package, type, and resource entry.
 * The value 0 is an invalid identifier.
 * @return Drawable An object that can be used to draw this resource.
 */
static Drawable getDrawable(Context context, int id) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    return context.getDrawable(id);
  }
  return context.getResources().getDrawable(id);
}
 
 方法所在类
 同类方法