Java Code Examples for androidx.core.content.ContextCompat#getDrawable()
The following examples show how to use
androidx.core.content.ContextCompat#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: NavigationBarControlUtil.java From UIWidget with Apache License 2.0 | 6 votes |
public static NavigationBarControl getNavigationBarControl(boolean isNavigation,boolean isNavigationPlus){ return new NavigationBarControl() { @Override public boolean setNavigationBar(Dialog dialog, NavigationViewHelper helper, View bottomView) { Drawable drawableTop = ContextCompat.getDrawable(dialog.getContext(), R.color.colorLineGray); DrawableUtil.setDrawableWidthHeight(drawableTop, SizeUtil.getScreenWidth(), SizeUtil.dp2px(0.5f)); helper.setNavigationViewDrawableTop(drawableTop) .setPlusNavigationViewEnable(isNavigationPlus) .setNavigationBarLightMode(true) .setNavigationViewColor(Color.argb(isDialogDarkIcon() ? 0 : 60, 0, 0, 0)) .setNavigationLayoutColor(Color.WHITE); //导航栏在底部控制才有意义,不然会很丑;开发者自己决定;这里仅供参考 return NavigationBarUtil.isNavigationAtBottom(dialog.getWindow()) && isNavigation; } }; }
Example 2
Source File: Utils.java From AirMapSDK-Android with Apache License 2.0 | 6 votes |
public static Bitmap getBitmapForDrawable(Context context, @DrawableRes int id) { Drawable drawable = ContextCompat.getDrawable(context, id); Bitmap bitmap; if (drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; bitmap = bitmapDrawable.getBitmap(); } else { if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); } else { bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); } return bitmap; }
Example 3
Source File: SquareButtonAdapter.java From commcare-android with Apache License 2.0 | 6 votes |
private static void setupViewHolder(Context context, HomeCardDisplayData cardDisplayData, SquareButtonViewHolder squareButtonViewHolder) { final Drawable buttonDrawable = ContextCompat.getDrawable(context, cardDisplayData.imageResource); squareButtonViewHolder.imageView.setImageDrawable(buttonDrawable); squareButtonViewHolder.cardView.setOnClickListener(cardDisplayData.listener); StateListDrawable bgDrawable = bgDrawStates(context, cardDisplayData.bgColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { squareButtonViewHolder.cardView.setBackground(bgDrawable); } else { squareButtonViewHolder.cardView.setBackgroundDrawable(bgDrawable); } }
Example 4
Source File: BaseRatingBar.java From SSForms with GNU General Public License v3.0 | 6 votes |
private void verifyParamsValue() { if (mNumStars <= 0) { mNumStars = 5; } if (mPadding < 0) { mPadding = 0; } if (mEmptyDrawable == null) { mEmptyDrawable = ContextCompat.getDrawable(getContext(), R.drawable.empty); } if (mFilledDrawable == null) { mFilledDrawable = ContextCompat.getDrawable(getContext(), R.drawable.filled); } }
Example 5
Source File: AppViewFragment.java From aptoide-client-v8 with GNU General Public License v3.0 | 6 votes |
@Override public void setupAppcAppView() { TypedValue value = new TypedValue(); this.getContext() .getTheme() .resolveAttribute(R.attr.appview_toolbar_bg_appc, value, true); int drawableId = value.resourceId; TransitionDrawable transition = (TransitionDrawable) ContextCompat.getDrawable(getContext(), drawableId); collapsingToolbarLayout.setBackgroundDrawable(transition); transition.startTransition(APPC_TRANSITION_MS); AlphaAnimation animation1 = new AlphaAnimation(0f, 1.0f); animation1.setDuration(APPC_TRANSITION_MS); collapsingAppcBackground.setAlpha(1f); collapsingAppcBackground.setVisibility(View.VISIBLE); collapsingAppcBackground.startAnimation(animation1); install.setBackgroundDrawable(getContext().getResources() .getDrawable(R.drawable.appc_gradient_rounded)); downloadProgressBar.setProgressDrawable( ContextCompat.getDrawable(getContext(), R.drawable.appc_progress)); flagThisAppSection.setVisibility(View.GONE); }
Example 6
Source File: BottomSheet.java From AndroidBottomSheet with Apache License 2.0 | 5 votes |
/** * Sets the background of the bottom sheet. * * @param resourceId * The resource id of the background, which should be set, as an {@link Integer} value. * The resource id must correspond to a valid drawable resource */ public final void setBackground(@DrawableRes final int resourceId) { this.background = ContextCompat.getDrawable(getContext(), resourceId); this.backgroundBitmap = null; this.backgroundId = -1; this.backgroundColor = -1; adaptBackground(); }
Example 7
Source File: PageNavigationView.java From PagerBottomTabStrip with Apache License 2.0 | 5 votes |
/** * 添加一个导航按钮 * * @param drawableRes 图标资源 * @param checkedDrawableRes 选中时的图标资源 * @param title 显示文字内容.尽量简短 * @param chekedColor 选中的颜色 * @return {@link MaterialBuilder} * @throws Resources.NotFoundException drawable 资源获取异常 */ public MaterialBuilder addItem(@DrawableRes int drawableRes, @DrawableRes int checkedDrawableRes, @NonNull String title, @ColorInt int chekedColor) { Drawable defaultDrawable = ContextCompat.getDrawable(getContext(), drawableRes); Drawable checkDrawable = ContextCompat.getDrawable(getContext(), checkedDrawableRes); if (defaultDrawable == null) { throw new Resources.NotFoundException("Resource ID " + Integer.toHexString(drawableRes)); } if (checkDrawable == null) { throw new Resources.NotFoundException("Resource ID " + Integer.toHexString(checkedDrawableRes)); } addItem(defaultDrawable, checkDrawable, title, chekedColor); return MaterialBuilder.this; }
Example 8
Source File: MaterialDialogDecorator.java From AndroidMaterialDialog with Apache License 2.0 | 5 votes |
@Override public final void setWindowBackground(@DrawableRes final int resourceId) { this.windowBackgroundId = resourceId; this.windowBackgroundBitmap = null; this.windowBackground = ContextCompat.getDrawable(getContext(), resourceId); this.windowInsets = new Rect(); this.windowBackground.getPadding(this.windowInsets); adaptWindowBackgroundAndInset(); }
Example 9
Source File: AwesomeToolbar.java From AndroidNavigation with MIT License | 5 votes |
private Drawable drawableFromBarButtonItem(ToolbarButtonItem barButtonItem) { if (getContext() == null) { return null; } Drawable drawable = null; if (barButtonItem.iconUri != null) { drawable = DrawableUtils.fromUri(getContext(), barButtonItem.iconUri); } else if (barButtonItem.iconRes != 0) { drawable = ContextCompat.getDrawable(getContext(), barButtonItem.iconRes); } if (drawable != null) { drawable = DrawableCompat.wrap(drawable.mutate()); } return drawable; }
Example 10
Source File: MapFragment.java From nearby-android with Apache License 2.0 | 5 votes |
/** * If any places are found, * add them to the map as graphics. * @param places List of Place items */ @Override public final void showNearbyPlaces(final List<Place> places) { // Clear out any existing graphics mGraphicOverlay.getGraphics().clear(); if (!mInitialLocationLoaded){ setNavigationChangeListener(); } mInitialLocationLoaded = true; if (places == null || places.isEmpty()){ Toast.makeText(getContext(),getString(R.string.no_places_found),Toast.LENGTH_SHORT).show(); if (mProgressDialog != null){ mProgressDialog.dismiss(); } return; } // Create a graphic for every place for (final Place place : places){ final BitmapDrawable pin = (BitmapDrawable) ContextCompat.getDrawable(getActivity(),getDrawableForPlace(place)) ; addGraphicToMap(pin, place.getLocation()); } // If a centered place name is not null, // show detail view if (mCenteredPlaceName != null){ for (final Place p: places){ if (p.getName().equalsIgnoreCase(mCenteredPlaceName)){ showDetail(p); mCenteredPlaceName = null; break; } } } if (mProgressDialog != null){ mProgressDialog.dismiss(); } }
Example 11
Source File: BottomNavigationItem.java From BottomNavigation with Apache License 2.0 | 5 votes |
/** * @param context to fetch resources * @return in-active icon drawable */ Drawable getInactiveIcon(Context context) { if (this.mInactiveIconResource != 0) { return ContextCompat.getDrawable(context, this.mInactiveIconResource); } else { return this.mInactiveIcon; } }
Example 12
Source File: NowPlayingArtworkViewModel.java From Jockey with Apache License 2.0 | 5 votes |
@Bindable public Drawable getNowPlayingArtwork() { if (mArtwork == null) { return ContextCompat.getDrawable(mContext, R.drawable.art_default_xl); } else { return new BitmapDrawable(mContext.getResources(), mArtwork); } }
Example 13
Source File: QueueFragment.java From Jockey with Apache License 2.0 | 5 votes |
private void setupRecyclerView() { Drawable shadow = ContextCompat.getDrawable(getContext(), R.drawable.list_drag_shadow); ItemDecoration background = new DragBackgroundDecoration(R.id.song_drag_root); ItemDecoration divider = new DragDividerDecoration(getContext(), true, R.id.instance_blank); ItemDecoration dragShadow = new DragDropDecoration((NinePatchDrawable) shadow); mRecyclerView.addItemDecoration(background); mRecyclerView.addItemDecoration(divider); mRecyclerView.addItemDecoration(dragShadow); mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); boolean portrait = getResources().getConfiguration().orientation != ORIENTATION_LANDSCAPE; boolean tablet = getResources().getConfiguration().smallestScreenWidthDp >= 600; if (portrait || !tablet) { // Add an inner shadow at the top of the list mRecyclerView.addItemDecoration(new InsetDecoration( ContextCompat.getDrawable(getContext(), R.drawable.inset_top_shadow), (int) getResources().getDimension(R.dimen.inset_top_shadow_height), Gravity.TOP)); } else { // Add an inner shadow at the bottom of the list mRecyclerView.addItemDecoration(new InsetDecoration( ContextCompat.getDrawable(getContext(), R.drawable.inset_bottom_shadow), getResources().getDimensionPixelSize(R.dimen.inset_bottom_shadow_height), Gravity.BOTTOM)); } }
Example 14
Source File: ChartHeaderView.java From Telegram with GNU General Public License v2.0 | 4 votes |
public ChartHeaderView(Context context) { super(context); TextPaint textPaint = new TextPaint(); textPaint.setTextSize(14); textPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); textMargin = (int) textPaint.measureText("00 MMM 0000 - 00 MMM 000"); title = new TextView(context); title.setTextSize(15); title.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); addView(title, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL, 16, 0, textMargin, 0)); back = new TextView(context); back.setTextSize(15); back.setTypeface(Typeface.DEFAULT_BOLD); back.setGravity(Gravity.START | Gravity.CENTER_VERTICAL); addView(back, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL, 8, 0, 8, 0)); dates = new TextView(context); dates.setTextSize(13); dates.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); dates.setGravity(Gravity.END | Gravity.CENTER_VERTICAL); addView(dates, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.END | Gravity.CENTER_VERTICAL, 16, 0, 16, 0)); datesTmp = new TextView(context); datesTmp.setTextSize(13); datesTmp.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); datesTmp.setGravity(Gravity.END | Gravity.CENTER_VERTICAL); addView(datesTmp, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.END | Gravity.CENTER_VERTICAL, 16, 0, 16, 0)); datesTmp.setVisibility(View.GONE); back.setVisibility(View.GONE); back.setText(LocaleController.getString("ZoomOut", R.string.ZoomOut)); zoomIcon = ContextCompat.getDrawable(getContext(), R.drawable.stats_zoom); back.setCompoundDrawablesWithIntrinsicBounds(zoomIcon, null, null, null); back.setCompoundDrawablePadding(AndroidUtilities.dp(4)); back.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(4), AndroidUtilities.dp(8), AndroidUtilities.dp(4)); back.setBackground(Theme.getRoundRectSelectorDrawable(Theme.getColor(Theme.key_featuredStickers_removeButtonText))); datesTmp.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> { datesTmp.setPivotX(datesTmp.getMeasuredWidth() * 0.7f); dates.setPivotX(dates.getMeasuredWidth() * 0.7f); }); recolor(); }
Example 15
Source File: SunriseSunsetPicker.java From arcusandroid with Apache License 2.0 | 4 votes |
private void initializeSelectionOutlines() { blackOutline = ContextCompat.getDrawable(getActivity(), R.drawable.outline_button_style_black); whiteOutline = ContextCompat.getDrawable(getActivity(), R.drawable.outline_button_style); }
Example 16
Source File: AMPMTimePopupWithHeader.java From arcusandroid with Apache License 2.0 | 4 votes |
private void initializeSelectionOutlines() { blackOutline = ContextCompat.getDrawable(getActivity(), R.drawable.outline_button_style_black); whiteOutline = ContextCompat.getDrawable(getActivity(), R.drawable.outline_button_style); }
Example 17
Source File: MainActivity.java From arcgis-runtime-samples-android with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // inflate address search view mAddressSearchView = (SearchView) findViewById(R.id.addressSearchView); mAddressSearchView.setIconified(false); mAddressSearchView.setFocusable(false); mAddressSearchView.setQueryHint(getResources().getString(R.string.address_search_hint)); // define pin drawable BitmapDrawable pinDrawable = (BitmapDrawable) ContextCompat.getDrawable(this, R.drawable.pin); try { mPinSourceSymbol = PictureMarkerSymbol.createAsync(pinDrawable).get(); } catch (InterruptedException | ExecutionException e) { Log.e(TAG, "Picture Marker Symbol error: " + e.getMessage()); Toast.makeText(getApplicationContext(), "Failed to load pin drawable.", Toast.LENGTH_LONG).show(); } // set pin to half of native size mPinSourceSymbol.setWidth(19f); mPinSourceSymbol.setHeight(72f); // create a LocatorTask from an online service mLocatorTask = new LocatorTask("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"); // inflate MapView from layout mMapView = (MapView) findViewById(R.id.mapView); // create a map with the BasemapType topographic final ArcGISMap map = new ArcGISMap(Basemap.createStreetsVector()); // set the map to be displayed in this view mMapView.setMap(map); // set the map viewpoint to start over North America mMapView.setViewpoint(new Viewpoint(40, -100, 100000000)); // add listener to handle screen taps mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, mMapView) { @Override public boolean onSingleTapConfirmed(MotionEvent motionEvent) { identifyGraphic(motionEvent); return true; } }); // define the graphics overlay mGraphicsOverlay = new GraphicsOverlay(); setupAddressSearchView(); }
Example 18
Source File: Carbon.java From Carbon with Apache License 2.0 | 4 votes |
public static Drawable getThemeDrawable(Context context, int attr) { Resources.Theme theme = context.getTheme(); TypedValue typedValue = new TypedValue(); theme.resolveAttribute(attr, typedValue, true); return typedValue.resourceId != 0 ? ContextCompat.getDrawable(context, typedValue.resourceId) : null; }
Example 19
Source File: NovelReviewReplyListActivity.java From light-novel-library_Wenku8_Android with GNU General Public License v2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_novel_review_reply_list); // fetch values rid = getIntent().getIntExtra("rid", 1); reviewTitle = getIntent().getStringExtra("title"); // set indicator enable Toolbar mToolbar = findViewById(R.id.toolbar_actionbar); setSupportActionBar(mToolbar); final Drawable upArrow = getResources().getDrawable(R.drawable.ic_svg_back); if(getSupportActionBar() != null && upArrow != null) { getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); upArrow.setColorFilter(getResources().getColor(R.color.default_white), PorterDuff.Mode.SRC_ATOP); getSupportActionBar().setHomeAsUpIndicator(upArrow); } // change status bar color tint, and this require SDK16 if (Build.VERSION.SDK_INT >= 16 ) { // create our manager instance after the content view is set SystemBarTintManager tintManager = new SystemBarTintManager(this); // enable all tint tintManager.setStatusBarTintEnabled(true); tintManager.setNavigationBarTintEnabled(true); tintManager.setTintAlpha(0.15f); tintManager.setNavigationBarAlpha(0.0f); // set all color tintManager.setTintColor(getResources().getColor(android.R.color.black)); // set Navigation bar color if(Build.VERSION.SDK_INT >= 21) getWindow().setNavigationBarColor(getResources().getColor(R.color.myNavigationColor)); } // get views and set title // get views mLoadingLayout = findViewById(R.id.list_loading); mSwipeRefreshLayout = findViewById(R.id.swipe_refresh_layout); mRecyclerView = findViewById(R.id.review_item_list); mLoadingStatusTextView = findViewById(R.id.list_loading_status); mLoadingButton = findViewById(R.id.btn_loading); etReplyText = findViewById(R.id.review_reply_edit_text); LinearLayout llReplyButton = findViewById(R.id.review_reply_send); mRecyclerView.setHasFixedSize(false); DividerItemDecoration horizontalDecoration = new DividerItemDecoration(mRecyclerView.getContext(), DividerItemDecoration.VERTICAL); Drawable horizontalDivider = ContextCompat.getDrawable(getApplication(), R.drawable.divider_horizontal); if (horizontalDivider != null) { horizontalDecoration.setDrawable(horizontalDivider); mRecyclerView.addItemDecoration(horizontalDecoration); } // use a linear layout manager mLayoutManager = new LinearLayoutManager(this); mRecyclerView.setLayoutManager(mLayoutManager); // Listener mRecyclerView.addOnScrollListener(new MyOnScrollListener()); // set click event for retry and cancel loading mLoadingButton.setOnClickListener(v -> new AsyncReviewReplyListLoader(this, mSwipeRefreshLayout, rid, reviewReplyList).execute()); // retry loading mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.myAccentColor)); mSwipeRefreshLayout.setOnRefreshListener(this::refreshReviewReplyList); llReplyButton.setOnClickListener(ignored -> { // FIXME: enable these Toast.makeText(getApplication(), getResources().getString(R.string.system_api_error), Toast.LENGTH_SHORT).show(); // String temp = etReplyText.getText().toString(); // String badWord = Wenku8API.searchBadWords(temp); // if (badWord != null) { // Toast.makeText(getApplication(), String.format(getResources().getString(R.string.system_containing_bad_word), badWord), Toast.LENGTH_SHORT).show(); // } else if (temp.length() < Wenku8API.MIN_REPLY_TEXT) { // Toast.makeText(getApplication(), getResources().getString(R.string.system_review_too_short), Toast.LENGTH_SHORT).show(); // } else { // // hide ime // InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE); // View view = getCurrentFocus(); // if (view == null) view = new View(this); // if (imm != null) imm.hideSoftInputFromWindow(view.getWindowToken(), 0); // // // submit // new AsyncPublishReply(etReplyText, this, rid, temp).execute(); // } }); // load initial content new AsyncReviewReplyListLoader(this, mSwipeRefreshLayout, rid, reviewReplyList).execute(); }
Example 20
Source File: FullscreenVideoView.java From fullscreen-video-view with Apache License 2.0 | 2 votes |
/** * Gets a drawable by it's resource id. * * @param drawableResId the drawable resource id * @return the fullscreenVideoView instance */ private Drawable getDrawable(int drawableResId) { return ContextCompat.getDrawable(getContext(), drawableResId); }