Java Code Examples for android.content.res.Resources#getDrawable()

The following examples show how to use android.content.res.Resources#getDrawable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownloadButtonProgress.java    From AndroidButtonProgress with Apache License 2.0 6 votes vote down vote up
private void initBackgroundDrawableFromAttribs(Resources res, TypedArray attrs) {
    int idleResId = attrs.getResourceId(R.styleable.DownloadButtonProgress_idleBackgroundDrawable, -1);
    int finishResId = attrs.getResourceId(R.styleable.DownloadButtonProgress_finishBackgroundDrawable, -1);
    int indeterminateResId = attrs.getResourceId(R.styleable.DownloadButtonProgress_indeterminateBackgroundDrawable, -1);
    int determinateResId = attrs.getResourceId(R.styleable.DownloadButtonProgress_determinateBackgroundDrawable, -1);

    if (idleResId != -1) mIdleBgDrawable = res.getDrawable(idleResId);
    if (finishResId != -1) mFinishBgDrawable = res.getDrawable(finishResId);
    if (indeterminateResId != -1) mIndeterminateBgDrawable = res.getDrawable(indeterminateResId);
    if (determinateResId != -1) mDeterminateBgDrawable = res.getDrawable(determinateResId);

    mIdleBgColor = attrs.getColor(R.styleable.DownloadButtonProgress_idleBackgroundColor, DEF_BG_COLOR);
    mFinishBgColor = attrs.getColor(R.styleable.DownloadButtonProgress_finishBackgroundColor, DEF_BG_COLOR);
    mIndeterminateBgColor = attrs.getColor(R.styleable.DownloadButtonProgress_indeterminateBackgroundColor, DEF_BG_COLOR);
    mDeterminateBgColor = attrs.getColor(R.styleable.DownloadButtonProgress_determinateBackgroundColor, DEF_BG_COLOR);
}
 
Example 2
Source File: TwitterLoginButton.java    From twitter-kit-android with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setupButton() {
    final Resources res = getResources();
    super.setCompoundDrawablesWithIntrinsicBounds(
            res.getDrawable(R.drawable.tw__ic_logo_default), null, null, null);
    super.setCompoundDrawablePadding(
            res.getDimensionPixelSize(R.dimen.tw__login_btn_drawable_padding));
    super.setText(R.string.tw__login_btn_txt);
    super.setTextColor(res.getColor(R.color.tw__solid_white));
    super.setTextSize(TypedValue.COMPLEX_UNIT_PX,
            res.getDimensionPixelSize(R.dimen.tw__login_btn_text_size));
    super.setTypeface(Typeface.DEFAULT_BOLD);
    super.setPadding(res.getDimensionPixelSize(R.dimen.tw__login_btn_left_padding), 0,
            res.getDimensionPixelSize(R.dimen.tw__login_btn_right_padding), 0);
    super.setBackgroundResource(R.drawable.tw__login_btn);
    super.setOnClickListener(new LoginClickListener());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        super.setAllCaps(false);
    }
}
 
Example 3
Source File: SuggestionsAdapter.java    From zen4android with MIT License 5 votes vote down vote up
public Drawable getTheDrawable(Uri uri) throws FileNotFoundException {
    String authority = uri.getAuthority();
    Resources r;
    if (TextUtils.isEmpty(authority)) {
        throw new FileNotFoundException("No authority: " + uri);
    } else {
        try {
            r = mContext.getPackageManager().getResourcesForApplication(authority);
        } catch (NameNotFoundException ex) {
            throw new FileNotFoundException("No package found for authority: " + uri);
        }
    }
    List<String> path = uri.getPathSegments();
    if (path == null) {
        throw new FileNotFoundException("No path: " + uri);
    }
    int len = path.size();
    int id;
    if (len == 1) {
        try {
            id = Integer.parseInt(path.get(0));
        } catch (NumberFormatException e) {
            throw new FileNotFoundException("Single path segment is not a resource ID: " + uri);
        }
    } else if (len == 2) {
        id = r.getIdentifier(path.get(1), path.get(0), authority);
    } else {
        throw new FileNotFoundException("More than two path segments: " + uri);
    }
    if (id == 0) {
        throw new FileNotFoundException("No resource found for: " + uri);
    }
    return r.getDrawable(id);
}
 
Example 4
Source File: IconContextMenu.java    From screenstandby with GNU General Public License v2.0 5 votes vote down vote up
public IconContextMenuItem(Resources res, CharSequence title,
		int imageResourceId, int actionTag) {
	text = title;
	if (imageResourceId != -1) {
		image = res.getDrawable(imageResourceId);
	} else {
		image = null;
	}
	this.actionTag = actionTag;
}
 
Example 5
Source File: FrescoConfig.java    From BlueBoard with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static void init(final Resources resources) {
    if (sPlaceholderDrawable == null) {
        sPlaceholderDrawable = resources.getDrawable(R.color.black);
    }
    if (sErrorDrawable == null) {
        sErrorDrawable = resources.getDrawable(R.color.md_yellow_300);
    }
}
 
Example 6
Source File: HandsOverlay.java    From custom-analog-clock-view with GNU General Public License v3.0 5 votes vote down vote up
public HandsOverlay(Context context, int hourHandRes, int minuteHandRes) {
    final Resources r = context.getResources();

    mUseLargeFace = false;

    mHour = r.getDrawable(hourHandRes);
    mMinute = r.getDrawable(minuteHandRes);
}
 
Example 7
Source File: Compat.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
static Drawable getDrawable(Resources resources, int id, Resources.Theme theme) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return resources.getDrawable(id, theme);
    }
    //noinspection deprecation
    return resources.getDrawable(id);
}
 
Example 8
Source File: SelectInstalledAppsActivity.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem menuItem = menu.add(R.string.menu_select_for_wipe);
    menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    checkId = menuItem.getItemId();
    if (FDroidApp.isAppThemeLight()) {
        Resources resources = getResources();
        Drawable icon = resources.getDrawable(R.drawable.check);
        icon.setColorFilter(new LightingColorFilter(0xffffffff, resources.getColor(android.R.color.white)));
        menuItem.setIcon(icon);
    } else {
        menuItem.setIcon(R.drawable.check);
    }
    return true;
}
 
Example 9
Source File: LatinKeyboard.java    From hackerskeyboard with Apache License 2.0 4 votes vote down vote up
void setImeOptions(Resources res, int mode, int options) {
    mMode = mode;
    // TODO should clean up this method
    if (mEnterKey != null) {
        // Reset some of the rarely used attributes.
        mEnterKey.popupCharacters = null;
        mEnterKey.popupResId = 0;
        mEnterKey.text = null;
        switch (options&(EditorInfo.IME_MASK_ACTION|EditorInfo.IME_FLAG_NO_ENTER_ACTION)) {
            case EditorInfo.IME_ACTION_GO:
                mEnterKey.iconPreview = null;
                mEnterKey.icon = null;
                mEnterKey.label = res.getText(R.string.label_go_key);
                break;
            case EditorInfo.IME_ACTION_NEXT:
                mEnterKey.iconPreview = null;
                mEnterKey.icon = null;
                mEnterKey.label = res.getText(R.string.label_next_key);
                break;
            case EditorInfo.IME_ACTION_DONE:
                mEnterKey.iconPreview = null;
                mEnterKey.icon = null;
                mEnterKey.label = res.getText(R.string.label_done_key);
                break;
            case EditorInfo.IME_ACTION_SEARCH:
                mEnterKey.iconPreview = res.getDrawable(
                        R.drawable.sym_keyboard_feedback_search);
                mEnterKey.icon = res.getDrawable(R.drawable.sym_keyboard_search);
                mEnterKey.label = null;
                break;
            case EditorInfo.IME_ACTION_SEND:
                mEnterKey.iconPreview = null;
                mEnterKey.icon = null;
                mEnterKey.label = res.getText(R.string.label_send_key);
                break;
            default:
                // Keep Return key in IM mode, we have a dedicated smiley key.
                mEnterKey.iconPreview = res.getDrawable(
                        R.drawable.sym_keyboard_feedback_return);
                mEnterKey.icon = res.getDrawable(R.drawable.sym_keyboard_return);
                mEnterKey.label = null;
                break;
        }
        // Set the initial size of the preview icon
        if (mEnterKey.iconPreview != null) {
            setDefaultBounds(mEnterKey.iconPreview);
        }
    }
}
 
Example 10
Source File: TeslaWatchFaceService.java    From rnd-android-wear-tesla with MIT License 4 votes vote down vote up
@Override
public void onCreate(SurfaceHolder holder) {
    super.onCreate(holder);

    mBgPaint = new Paint();
    mBgPaint.setARGB(255, 0, 0, 0);

    mTimePaint = new Paint();
    mTimePaint.setARGB(255, 255, 255, 255);
    mTimePaint.setAntiAlias(true);
    Typeface tf = Typeface.createFromAsset(getAssets(), "RobotoCondensed-Light.ttf");
    mTimePaint.setTypeface(tf);

    mMaxRangePaint = new Paint();
    mMaxRangePaint.setARGB(120, 255, 255, 255);
    mMaxRangePaint.setAntiAlias(true);

    mRangeValuePaint = new Paint();
    mRangeValuePaint.setARGB(190, 255, 255, 255);
    mRangeValuePaint.setAntiAlias(true);
    mRangeValuePaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));

    mDotsPaint = new Paint();
    mDotsPaint.setAntiAlias(true);

    mTime = new Time();

    Resources resources = TeslaWatchFaceService.this.getResources();

    Drawable chargingDrawable = resources.getDrawable(R.drawable.charging);
    mChargingBitmap = ((BitmapDrawable) chargingDrawable).getBitmap();

    Drawable mLockedBitmapDrawable = resources.getDrawable(R.drawable.locked_small);
    mLockedBitmap = ((BitmapDrawable) mLockedBitmapDrawable).getBitmap();

    Drawable unlockedDrawable = resources.getDrawable(R.drawable.unlocked_small);
    mUnLockedBitmap = ((BitmapDrawable) unlockedDrawable).getBitmap();

    configureStyle();

    initGoogleApiClient();
}
 
Example 11
Source File: DisplayImageOptions.java    From letv with Apache License 2.0 4 votes vote down vote up
public Drawable getImageForEmptyUri(Resources res) {
    return this.imageResForEmptyUri != 0 ? res.getDrawable(this.imageResForEmptyUri) : this.imageForEmptyUri;
}
 
Example 12
Source File: DisplayImageOptions.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
public Drawable getImageForEmptyUri(Resources res) {
	return imageResForEmptyUri != 0 ? res.getDrawable(imageResForEmptyUri) : imageForEmptyUri;
}
 
Example 13
Source File: RecipientEditTextView.java    From talk-android with MIT License 4 votes vote down vote up
private void setChipDimensions(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecipientEditTextView, 0,
            0);
    Resources r = getContext().getResources();

    mChipBackground = a.getDrawable(R.styleable.RecipientEditTextView_chipBackground);
    if (mChipBackground == null) {
        mChipBackground = r.getDrawable(R.drawable.chip_background);
    }
    mChipBackgroundPressed = a
            .getDrawable(R.styleable.RecipientEditTextView_chipBackgroundPressed);
    if (mChipBackgroundPressed == null) {
        mChipBackgroundPressed = r.getDrawable(R.drawable.chip_background_selected);
    }
    mChipDelete = a.getDrawable(R.styleable.RecipientEditTextView_chipDelete);
    if (mChipDelete == null) {
        mChipDelete = r.getDrawable(R.drawable.chip_delete);
    }
    mChipPadding = a.getDimensionPixelSize(R.styleable.RecipientEditTextView_chipPadding, -1);
    if (mChipPadding == -1) {
        mChipPadding = (int) r.getDimension(R.dimen.chip_padding);
    }

    mDefaultContactPhoto = BitmapFactory.decodeResource(r, R.drawable.ic_contact_picture);

    mMoreItem = (TextView) LayoutInflater.from(getContext()).inflate(R.layout.more_item, null);

    mChipHeight = a.getDimensionPixelSize(R.styleable.RecipientEditTextView_chipHeight, -1);
    if (mChipHeight == -1) {
        mChipHeight = r.getDimension(R.dimen.chip_height);
    }
    mChipFontSize = a.getDimensionPixelSize(R.styleable.RecipientEditTextView_chipFontSize, -1);
    if (mChipFontSize == -1) {
        mChipFontSize = r.getDimension(R.dimen.chip_text_size);
    }
    mInvalidChipBackground = a
            .getDrawable(R.styleable.RecipientEditTextView_invalidChipBackground);
    if (mInvalidChipBackground == null) {
        mInvalidChipBackground = r.getDrawable(R.drawable.chip_background_invalid);
    }
    mAvatarPosition = a.getInt(R.styleable.RecipientEditTextView_avatarPosition, 1);
    mImageSpanAlignment = a.getInt(R.styleable.RecipientEditTextView_imageSpanAlignment, 0);
    mDisableDelete = a.getBoolean(R.styleable.RecipientEditTextView_disableDelete, false);

    mLineSpacingExtra = r.getDimension(R.dimen.line_spacing_extra);
    mMaxLines = r.getInteger(R.integer.chips_max_lines);
    TypedValue tv = new TypedValue();
    if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources()
                .getDisplayMetrics());
    }

    a.recycle();
}
 
Example 14
Source File: DisplayImageOptions.java    From android-project-wo2b with Apache License 2.0 4 votes vote down vote up
public Drawable getImageOnFail(Resources res) {
	return imageResOnFail != 0 ? res.getDrawable(imageResOnFail) : imageOnFail;
}
 
Example 15
Source File: Clock.java    From ScrollBarPanelWithClock with Apache License 2.0 4 votes vote down vote up
public Clock(Context context, AttributeSet attrs, int defStyle) {
	super(context, attrs, defStyle);
	
	mContext = context;
	Resources resource = mContext.getResources();
	final TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.Clock);
	
	/*mDial = resource.getDrawable(R.drawable.ic_timer_clock_dialer);
	mHourHand = resource.getDrawable(R.drawable.ic_timer_clock_hour_hand);
	mMinuteHand = resource.getDrawable(R.drawable.ic_timer_clock_minute_hand);
	mSecondHand = resource.getDrawable(R.drawable.ic_timer_clock_minute_hand);*/
	final int scrollBarPanelLayoutId = a.getResourceId(R.styleable.Clock_scrollBarPanel, -1);
	
	System.out.println("***** scrollBarPanelLayoutId ***********"+scrollBarPanelLayoutId);
	/**
	 * dialer background
	 */
	int dialerRes = a.getResourceId(R.styleable.Clock_hand_dial, -1);
	if (dialerRes != -1) {
		setDialDrawable(dialerRes);
	}else{
		mDial = resource.getDrawable(R.drawable.ic_timer_clock_dialer);
	}
	
	/**
	 * hour hand background
	 */
	int hourRes = a.getResourceId(R.styleable.Clock_hand_hour, -1);
	if (hourRes != -1) {
		setHourDrawable(hourRes);
	}else{
		mHourHand = resource.getDrawable(R.drawable.ic_timer_clock_hour_hand);
	}
	
	/**
	 * minute hand background
	 */
	int minuteRes = a.getResourceId(R.styleable.Clock_hand_minute, -1);
	if (minuteRes != -1) {
		setMinuteDrawable(minuteRes);
	}else{
		mMinuteHand = resource.getDrawable(R.drawable.ic_timer_clock_minute_hand);
	}
	
	/**
	 * second hand background
	 */
	int secondRes = a.getResourceId(R.styleable.Clock_hand_second, -1);
	if (secondRes != -1) {
		System.out.println("+++++if +++++"+secondRes);
		setSecondDrawable(secondRes);
	}else{
		System.out.println("+++++ else +++++"+secondRes);
		mSecondHand = resource.getDrawable(R.drawable.ic_timer_clock_minute_hand);
	}

	mDialWidth = mDial.getIntrinsicWidth();
	mDialHeight = mDial.getIntrinsicHeight();
}
 
Example 16
Source File: HighlightView.java    From memoir with Apache License 2.0 4 votes vote down vote up
private void init() {
    Resources resources = mContext.getResources();
    mResizeDrawableWidth = resources.getDrawable(R.drawable.camera_crop_width);
    mResizeDrawableHeight = resources.getDrawable(R.drawable.camera_crop_height);
    mResizeDrawableDiagonal = resources.getDrawable(R.drawable.indicator_autocrop);
}
 
Example 17
Source File: ImageUtil.java    From Music-Player with GNU General Public License v3.0 4 votes vote down vote up
public static Drawable getVectorDrawable(@NonNull Resources res, @DrawableRes int resId, @Nullable Resources.Theme theme) {
    if (Build.VERSION.SDK_INT >= 21) {
        return res.getDrawable(resId, theme);
    }
    return VectorDrawableCompat.create(res, resId, theme);
}
 
Example 18
Source File: ResourcesCompatApi21.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public static Drawable getDrawable(Resources res, int id, Theme theme) {
    return res.getDrawable(id, theme);
}
 
Example 19
Source File: DownloadButtonProgress.java    From AndroidButtonProgress with Apache License 2.0 4 votes vote down vote up
public DownloadButtonProgress(Context context, AttributeSet attrs) {
    super(context, attrs);
    super.setOnClickListener(this);

    initIndeterminateAnimator();

    mClickListeners = new ArrayList<>();

    mBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBgRect = new RectF();

    mProgressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mProgressPaint.setStyle(Paint.Style.STROKE);
    mProgressPaint.setDither(true);
    mProgressPaint.setStrokeJoin(Paint.Join.ROUND);
    mProgressPaint.setStrokeCap(Paint.Cap.ROUND);
    mProgressPaint.setPathEffect(new CornerPathEffect(50f));

    mProgressRect = new RectF();

    Resources res = context.getResources();
    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DownloadButtonProgress, 0, 0);

        initBackgroundDrawableFromAttribs(res, a);

        mCurrState = a.getInt(R.styleable.DownloadButtonProgress_state, STATE_IDLE);
        mCancelable = a.getBoolean(R.styleable.DownloadButtonProgress_cancelable, DEF_CANCELABLE);
        mHideOnFinish = a.getBoolean(R.styleable.DownloadButtonProgress_hideOnFinish, false);
        mProgressIndeterminateSweepAngle = a.getInteger(R.styleable.DownloadButtonProgress_progressIndeterminateSweepAngle, DEF_PROGRESS_INDETERMINATE_WIDTH);
        mProgressDeterminateColor = a.getColor(R.styleable.DownloadButtonProgress_progressDeterminateColor, DEF_DETERMINATE_COLOR);
        mProgressIndeterminateColor = a.getColor(R.styleable.DownloadButtonProgress_progressIndeterminateColor, DEF_INDETERMINATE_COLOR);
        mProgressPaint.setStrokeWidth(
                a.getDimensionPixelSize(R.styleable.DownloadButtonProgress_progressWidth, DEF_PROGRESS_WIDTH)
        );
        mProgressMargin = a.getDimensionPixelSize(R.styleable.DownloadButtonProgress_progressMargin, DEF_PROGRESS_MARGIN);
        mCurrProgress = a.getInteger(R.styleable.DownloadButtonProgress_currentProgress, 0);
        mMaxProgress = a.getInteger(R.styleable.DownloadButtonProgress_maxProgress, 100);

        int icIdleDrawableId = a.getResourceId(R.styleable.DownloadButtonProgress_idleIconDrawable, R.drawable.ic_default_download);
        mIdleIcon = res.getDrawable(icIdleDrawableId);
        mIdleIconWidth = a.getDimensionPixelSize(R.styleable.DownloadButtonProgress_idleIconWidth, mIdleIcon.getMinimumWidth());
        mIdleIconHeight = a.getDimensionPixelSize(R.styleable.DownloadButtonProgress_idleIconHeight, mIdleIcon.getMinimumHeight());

        int icCancelDrawableId = a.getResourceId(R.styleable.DownloadButtonProgress_cancelIconDrawable, R.drawable.ic_default_cancel);
        mCancelIcon = res.getDrawable(icCancelDrawableId);
        mCancelIconWidth = a.getDimensionPixelSize(R.styleable.DownloadButtonProgress_cancelIconWidth, mCancelIcon.getMinimumWidth());
        mCancelIconHeight = a.getDimensionPixelSize(R.styleable.DownloadButtonProgress_cancelIconHeight, mCancelIcon.getMinimumHeight());

        int icFinishDrawableId = a.getResourceId(R.styleable.DownloadButtonProgress_finishIconDrawable, R.drawable.ic_default_finish);
        mFinishIcon = res.getDrawable(icFinishDrawableId);
        mFinishIconWidth = a.getDimensionPixelSize(R.styleable.DownloadButtonProgress_finishIconWidth, mFinishIcon.getMinimumWidth());
        mFinishIconHeight = a.getDimensionPixelSize(R.styleable.DownloadButtonProgress_finishIconHeight, mFinishIcon.getMinimumHeight());

        a.recycle();
    } else {
        mCurrState = STATE_IDLE;
        mCancelable = DEF_CANCELABLE;
        mHideOnFinish = false;
        mProgressIndeterminateSweepAngle = DEF_PROGRESS_INDETERMINATE_WIDTH;
        mProgressDeterminateColor = DEF_DETERMINATE_COLOR;
        mProgressIndeterminateColor = DEF_INDETERMINATE_COLOR;
        mProgressPaint.setStrokeWidth(DEF_PROGRESS_WIDTH);
        mProgressMargin = DEF_PROGRESS_MARGIN;
        mCurrProgress = 0;
        mMaxProgress = 100;

        mIdleBgColor = DEF_BG_COLOR;
        mFinishBgColor = DEF_BG_COLOR;
        mIndeterminateBgColor = DEF_BG_COLOR;
        mDeterminateBgColor = DEF_BG_COLOR;

        mIdleIcon = res.getDrawable(R.drawable.ic_default_download);
        mIdleIconWidth = mIdleIcon.getMinimumWidth();
        mIdleIconHeight = mIdleIcon.getMinimumHeight();

        mCancelIcon = res.getDrawable(R.drawable.ic_default_cancel);
        mCancelIconWidth = mCancelIcon.getMinimumWidth();
        mCancelIconHeight = mCancelIcon.getMinimumHeight();

        mFinishIcon = res.getDrawable(R.drawable.ic_default_finish);
        mFinishIconWidth = mFinishIcon.getMinimumWidth();
        mFinishIconHeight = mFinishIcon.getMinimumHeight();
    }

    if (mCurrState == STATE_INDETERMINATE)
        setIndeterminate();
    if (mCurrState == STATE_FINISHED && mHideOnFinish)
        setVisibility(GONE);
}
 
Example 20
Source File: DisplayImageOptions.java    From candybar with Apache License 2.0 4 votes vote down vote up
/**
 * @deprecated use {@link #getImageOnLoading(Context)} instead
 */
@Deprecated
public Drawable getImageOnLoading(Resources res) {
    return imageResOnLoading != 0 ? res.getDrawable(imageResOnLoading) : imageOnLoading;
}