Java Code Examples for android.support.v7.content.res.AppCompatResources#getDrawable()
The following examples show how to use
android.support.v7.content.res.AppCompatResources#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: ScatterChart2Model.java From JZAndroidChart with Apache License 2.0 | 6 votes |
@Override protected void setDataBindingVariables(ViewDataBinding binding) { if (binding instanceof LayoutScatterChartBinding) { Drawable drawable = AppCompatResources.getDrawable(binding.getRoot().getContext(), R.drawable.shape_circle); scatterDataSet.setShape(drawable); LayoutScatterChartBinding bd = (LayoutScatterChartBinding) binding; bd.combineChart.getAxisBottom().setGridCount(1); bd.combineChart.getAxisLeft().setGridCount(1); bd.combineChart.addDataSet(scatterDataSet); bd.combineChart.setOnEntryClickListener(new OnEntryClickListener() { @Override public void onEntryClick(Chart chart, int position) { if (position >= 0) { Toast.makeText(chart.getContext(), textList.get(position), Toast.LENGTH_SHORT).show(); } } }); } }
Example 2
Source File: AboutActivity.java From Capstone-Project with MIT License | 6 votes |
/** * Add left drawables on buttons. This is done programmatically because on pre lollipop devices * vector drawables cannot be directly accessed in buttons(xml). */ private void addIconsToButtons() { boolean isLightTheme = PredatorSharedPreferences.getCurrentTheme(getApplicationContext()) == PredatorSharedPreferences.THEME_TYPE.LIGHT; Drawable githubDrawable = AppCompatResources.getDrawable(getApplicationContext(), isLightTheme ? R.drawable.ic_github_24dp : R.drawable.ic_github_inverse_24dp); btnGithub.setCompoundDrawablesWithIntrinsicBounds(githubDrawable, null, null, null); Drawable googlePlusDrawable = AppCompatResources.getDrawable(getApplicationContext(), isLightTheme ? R.drawable.ic_google_plus_24dp : R.drawable.ic_google_plus_inverse_24dp); btnGooglePlus.setCompoundDrawablesWithIntrinsicBounds(googlePlusDrawable, null, null, null); Drawable mailDrawable = AppCompatResources.getDrawable(getApplicationContext(), isLightTheme ? R.drawable.ic_mail_24dp : R.drawable.ic_mail_inverse_24dp); btnMail.setCompoundDrawablesWithIntrinsicBounds(mailDrawable, null, null, null); }
Example 3
Source File: AttrTypeImageSrcCompat.java From NightModel with Apache License 2.0 | 6 votes |
@Override public void apply(View view, String resName) { if (TextUtils.isEmpty(resName)) return; if (view instanceof ImageView) { Drawable drawable; if (((ImageView) view).getDrawable() != null && ((ImageView) view).getDrawable().getClass().getName().toLowerCase().contains("vector")) { int resId = view.getResources().getIdentifier(resName, DEFTYPE_DRAWABLE, view.getContext().getPackageName()); drawable = AppCompatResources.getDrawable(view.getContext(), resId); } else { drawable = getDrawable(view.getContext(), resName); } if (drawable == null) return; ((ImageView) view).setImageDrawable(drawable); } }
Example 4
Source File: MaskableFrameLayout.java From android_maskable_layout with Apache License 2.0 | 5 votes |
@Nullable private Drawable loadMask(@NonNull TypedArray a) { final int drawableResId = a.getResourceId(R.styleable.MaskableLayout_mask, -1); if (drawableResId == -1) { return null; } return AppCompatResources.getDrawable(getContext(), drawableResId); }
Example 5
Source File: App.java From ForPDA with GNU General Public License v3.0 | 5 votes |
public static Drawable getVecDrawable(Context context, @DrawableRes int id) { Drawable drawable = AppCompatResources.getDrawable(context, id); if (!(drawable instanceof VectorDrawableCompat || drawable instanceof VectorDrawable)) { throw new RuntimeException(); } return drawable; }
Example 6
Source File: BitmapLoader.java From xDrip with GNU General Public License v3.0 | 5 votes |
private static Bitmap getBitmapFromVectorDrawable(int drawableId) { Drawable drawable = AppCompatResources.getDrawable(xdrip.getAppContext(), drawableId); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { drawable = (DrawableCompat.wrap(drawable)).mutate(); } final Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; }
Example 7
Source File: BitmapLoader.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private static Bitmap getBitmapFromVectorDrawable(int drawableId) { Drawable drawable = AppCompatResources.getDrawable(xdrip.getAppContext(), drawableId); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { drawable = (DrawableCompat.wrap(drawable)).mutate(); } final Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; }
Example 8
Source File: EmoticonSpan.java From EmoticonGIFKeyboard with Apache License 2.0 | 5 votes |
@SuppressWarnings("ConstantConditions") @Override public Drawable getDrawable() { if (mDeferredDrawable == null) { mDeferredDrawable = AppCompatResources.getDrawable(mContext, mEmoticonIcon); mDeferredDrawable.setBounds(0, 0, (int) mEmoticonSize, (int) mEmoticonSize); } return mDeferredDrawable; }
Example 9
Source File: VectorCompatHelper.java From pandroid with Apache License 2.0 | 5 votes |
private static Drawable getDrawableInternal(Context context, @DrawableRes int drawableRes, Integer tintColor) { if (drawableRes == 0) { return null; } Drawable drawable = AppCompatResources.getDrawable(context, drawableRes); if (drawable != null && tintColor != null) { Drawable tintDrawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(tintDrawable, tintColor); return tintDrawable; } return drawable; }
Example 10
Source File: RoundedImageViewWithBorder.java From ImageLetterIcon with Apache License 2.0 | 5 votes |
private Drawable resolveResource() { Drawable d = null; if (mResource != 0) { try { d = AppCompatResources.getDrawable(getContext(), mResource); } catch (Exception e) { mResource = 0; } } return RoundedDrawable.fromDrawable(d); }
Example 11
Source File: Util.java From Camera-Roll-Android-App with Apache License 2.0 | 5 votes |
public static Drawable getErrorPlaceholder(Context context) { Drawable errorPlaceholder = AppCompatResources.getDrawable(context, R.drawable.error_placeholder); if (errorPlaceholder == null) { return null; } return tintDrawableWithAccentColor(context, errorPlaceholder); }
Example 12
Source File: PlacesAutocompleteTextView.java From android-PlacesAutocompleteTextView with BSD 2-Clause "Simplified" License | 5 votes |
private void enableClearButton(boolean value){ if(!value) { this.setCompoundDrawables(null, null, null, null); return; } if(imgClearButton == null) { imgClearButton = AppCompatResources.getDrawable(getContext(), R.drawable.ic_clear_black_24dp); } // Set the bounds of the clear button this.setCompoundDrawablesWithIntrinsicBounds(null, null, imgClearButton, null); // if the clear button is pressed fire up the handler Otherwise do nothing final Drawable finalImgClearButton = imgClearButton; this.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { PlacesAutocompleteTextView et = PlacesAutocompleteTextView.this; if (et.getCompoundDrawables()[2] == null) return false; if (event.getAction() != MotionEvent.ACTION_UP) return false; if (event.getX() > et.getWidth() - et.getPaddingRight() - finalImgClearButton.getIntrinsicWidth()) { onClearListener.onClear(); } return false; } }); }
Example 13
Source File: StatusView.java From GracefulMovies with Apache License 2.0 | 4 votes |
public void show(@NonNull ViewGroup viewContainer, @Status int status, int marginDp) { if (getParent() == null) { MarginLayoutParams lp; if (viewContainer instanceof FrameLayout) { lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); } else { lp = new MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); } lp.topMargin = marginDp; viewContainer.addView(this, lp); } if (status == LOADING) { setBackgroundColor(Color.TRANSPARENT); mLoadingIv.setVisibility(View.VISIBLE); mHintTv.setVisibility(View.INVISIBLE); mReloadBtn.setVisibility(View.INVISIBLE); mAnimator = ObjectAnimator.ofFloat(mLoadingIv, View.ROTATION, 0, 360); mAnimator.setDuration(1000); mAnimator.setInterpolator(new LinearInterpolator()); mAnimator.setRepeatCount(ValueAnimator.INFINITE); mAnimator.setRepeatMode(ValueAnimator.RESTART); mAnimator.start(); } else { if (mBgColor != 0) { setBackgroundColor(mBgColor); } else { setBackground(mBgDrawable); } mLoadingIv.setVisibility(View.INVISIBLE); mHintTv.setVisibility(View.VISIBLE); if (mAnimator != null) mAnimator.cancel(); Drawable drawable = null; if (status == NO_DATA) { mHintTv.setText("空空如也"); drawable = AppCompatResources.getDrawable(getContext(), R.drawable.ic_status_no_data); mReloadBtn.setVisibility(View.INVISIBLE); } else if (status == CONNECTION_ERROR) { mHintTv.setText("网络连接错误"); drawable = AppCompatResources.getDrawable(getContext(), R.drawable.ic_status_connection_error); mReloadBtn.setVisibility(View.VISIBLE); } else if (status == CONNECTION_TIME_OUT) { mHintTv.setText("网络请求超时"); drawable = AppCompatResources.getDrawable(getContext(), R.drawable.ic_status_connection_time_out); mReloadBtn.setVisibility(View.VISIBLE); } mHintTv.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null); } }
Example 14
Source File: App.java From ForPDA with GNU General Public License v3.0 | 4 votes |
public static Drawable getDrawableAttr(Context context, @AttrRes int attr) { return AppCompatResources.getDrawable(context, getDrawableResAttr(context, attr)); }
Example 15
Source File: RecordButton.java From RecordView with Apache License 2.0 | 4 votes |
private void setTheImageResource(int imageResource) { Drawable image = AppCompatResources.getDrawable(getContext(), imageResource); setImageDrawable(image); }
Example 16
Source File: ScatterChart2Model.java From JZAndroidChart with Apache License 2.0 | 4 votes |
@Override protected void setDataBindingVariables(ViewDataBinding binding) { if (binding instanceof LayoutScatterChartBinding) { Drawable drawable = AppCompatResources.getDrawable(binding.getRoot().getContext(), R.drawable.shape_circle); scatterDataSet.setShape(drawable); LayoutScatterChartBinding bd = (LayoutScatterChartBinding) binding; bd.combineChart.getAxisBottom().setGridCount(1); bd.combineChart.getAxisLeft().setGridCount(1); bd.combineChart.addDataSet(scatterDataSet); } }
Example 17
Source File: VectorAnalogClock.java From vector-analog-clock with MIT License | 4 votes |
private void main(Context ctx) { Drawable face = AppCompatResources.getDrawable(ctx, faceId); Drawable hour = AppCompatResources.getDrawable(ctx, hourId); Drawable minute = AppCompatResources.getDrawable(ctx, minuteId); Drawable second = AppCompatResources.getDrawable(ctx, secondId); int alpha255 = (int)(opacity * 255); face.setAlpha(alpha255); hour.setAlpha(alpha255); minute.setAlpha(alpha255); second.setAlpha(alpha255); face = DrawableCompat.wrap(face); hour = DrawableCompat.wrap(hour); minute = DrawableCompat.wrap(minute); second = DrawableCompat.wrap(second); DrawableCompat.setTint(face.mutate(),color); DrawableCompat.setTint(hour.mutate(),color); DrawableCompat.setTint(minute.mutate(),color); DrawableCompat.setTint(second.mutate(),color); inflate(ctx,R.layout.analog_clock,this); analogFace = findViewById(R.id.face); analogHour = findViewById(R.id.hour); analogMinute = findViewById(R.id.minute); analogSecond = findViewById(R.id.second); if(!showSeconds){ analogSecond.setVisibility(GONE); } //square it analogFace.setAdjustViewBounds(true); analogHour.setAdjustViewBounds(true); analogMinute.setAdjustViewBounds(true); analogSecond.setAdjustViewBounds(true); analogHour.setScaleType(ImageView.ScaleType.FIT_END); analogMinute.setScaleType(ImageView.ScaleType.FIT_END); analogSecond.setScaleType(ImageView.ScaleType.FIT_END); sizeInDp = 40;//why 40 ? cause it works. sizeInDp = (sizeInDp + 25) * 4; sizeInPixels = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,sizeInDp,getResources().getDisplayMetrics()); ViewGroup.LayoutParams layoutParams = analogFace.getLayoutParams(); layoutParams.width = sizeInPixels; layoutParams.height = sizeInPixels; analogFace.setLayoutParams(layoutParams); layoutParams = analogSecond.getLayoutParams(); float minutesHeight = (sizeInPixels/2) - (sizeInPixels/5.5f); layoutParams.height = (int)minutesHeight; analogSecond.setLayoutParams(layoutParams); layoutParams = analogMinute.getLayoutParams(); layoutParams.height = (int)minutesHeight; analogMinute.setLayoutParams(layoutParams); layoutParams = analogHour.getLayoutParams(); layoutParams.height = (sizeInPixels) / 5; analogHour.setLayoutParams(layoutParams); analogFace.setImageDrawable(face); analogHour.setImageDrawable(hour); analogMinute.setImageDrawable(minute); analogSecond.setImageDrawable(second); dp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,3.5f,getResources().getDisplayMetrics()); layoutListener = new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { setPositionFor(analogSecond); setPositionFor(analogMinute); setPositionFor(analogHour); tickTick(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { getViewTreeObserver().removeOnGlobalLayoutListener(layoutListener); }else{ getViewTreeObserver().removeGlobalOnLayoutListener(layoutListener); } } }; //the coolest line getViewTreeObserver().addOnGlobalLayoutListener(layoutListener); }
Example 18
Source File: ScatterChartModel.java From JZAndroidChart with Apache License 2.0 | 3 votes |
@Override protected void setDataBindingVariables(ViewDataBinding binding) { if (binding instanceof LayoutCombineChartBinding) { Drawable drawable = AppCompatResources.getDrawable(binding.getRoot().getContext(), R.drawable.ic_example); scatterDataSet.setShape(drawable); LayoutCombineChartBinding bd = (LayoutCombineChartBinding) binding; bd.combineChart.addDataSet(scatterDataSet); } }
Example 19
Source File: ScatterChartModel.java From JZAndroidChart with Apache License 2.0 | 3 votes |
@Override protected void setDataBindingVariables(ViewDataBinding binding) { if (binding instanceof LayoutCombineChartBinding) { Drawable drawable = AppCompatResources.getDrawable(binding.getRoot().getContext(), R.drawable.ic_example); scatterDataSet.setShape(drawable); LayoutCombineChartBinding bd = (LayoutCombineChartBinding) binding; bd.combineChart.addDataSet(scatterDataSet); } }
Example 20
Source File: RecordView.java From RecordView with Apache License 2.0 | 2 votes |
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { View view = View.inflate(context, R.layout.record_view_layout, null); addView(view); ViewGroup viewGroup = (ViewGroup) view.getParent(); viewGroup.setClipChildren(false); arrow = view.findViewById(R.id.arrow); slideToCancel = view.findViewById(R.id.slide_to_cancel); smallBlinkingMic = view.findViewById(R.id.glowing_mic); counterTime = view.findViewById(R.id.counter_tv); basketImg = view.findViewById(R.id.basket_img); slideToCancelLayout = view.findViewById(R.id.shimmer_layout); hideViews(true); if (attrs != null && defStyleAttr == -1 && defStyleRes == -1) { TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RecordView, defStyleAttr, defStyleRes); int slideArrowResource = typedArray.getResourceId(R.styleable.RecordView_slide_to_cancel_arrow, -1); String slideToCancelText = typedArray.getString(R.styleable.RecordView_slide_to_cancel_text); int slideMarginRight = (int) typedArray.getDimension(R.styleable.RecordView_slide_to_cancel_margin_right, 30); int counterTimeColor = typedArray.getColor(R.styleable.RecordView_counter_time_color, -1); int arrowColor = typedArray.getColor(R.styleable.RecordView_slide_to_cancel_arrow_color, -1); int cancelBounds = typedArray.getDimensionPixelSize(R.styleable.RecordView_slide_to_cancel_bounds, -1); if (cancelBounds != -1) setCancelBounds(cancelBounds, false);//don't convert it to pixels since it's already in pixels if (slideArrowResource != -1) { Drawable slideArrow = AppCompatResources.getDrawable(getContext(), slideArrowResource); arrow.setImageDrawable(slideArrow); } if (slideToCancelText != null) slideToCancel.setText(slideToCancelText); if (counterTimeColor != -1) setCounterTimeColor(counterTimeColor); if (arrowColor != -1) setSlideToCancelArrowColor(arrowColor); setMarginRight(slideMarginRight, true); typedArray.recycle(); } animationHelper = new AnimationHelper(context, basketImg, smallBlinkingMic); }