Java Code Examples for androidx.appcompat.content.res.AppCompatResources#getDrawable()
The following examples show how to use
androidx.appcompat.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: SearchPreferenceResult.java From SearchPreference with MIT License | 6 votes |
/** * Alternative (old) highlight method if ripple does not work */ private void highlightFallback(PreferenceFragmentCompat prefsFragment, final Preference prefResult) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = prefsFragment.getActivity().getTheme(); theme.resolveAttribute(android.R.attr.textColorPrimary, typedValue, true); TypedArray arr = prefsFragment.getActivity().obtainStyledAttributes(typedValue.data, new int[]{ android.R.attr.textColorPrimary}); int color = arr.getColor(0, 0xff3F51B5); arr.recycle(); final Drawable oldIcon = prefResult.getIcon(); final boolean oldSpaceReserved = prefResult.isIconSpaceReserved(); Drawable arrow = AppCompatResources.getDrawable(prefsFragment.getContext(), R.drawable.searchpreference_ic_arrow_right); arrow.setColorFilter(color, PorterDuff.Mode.SRC_IN); prefResult.setIcon(arrow); prefsFragment.scrollToPreference(prefResult); new Handler().postDelayed(() -> { prefResult.setIcon(oldIcon); prefResult.setIconSpaceReserved(oldSpaceReserved); }, 1000); }
Example 2
Source File: ObjectStyleUtils.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static Drawable getIconResource(Context context, String resourceName, int defaultResource) { if (defaultResource == -1) { return null; } Drawable defaultDrawable = AppCompatResources.getDrawable(context, defaultResource); if (!isEmpty(resourceName)) { Resources resources = context.getResources(); String iconName = resourceName.startsWith("ic_") ? resourceName : "ic_" + resourceName; int iconResource = resources.getIdentifier(iconName, "drawable", context.getPackageName()); Drawable drawable = AppCompatResources.getDrawable(context, iconResource); if (drawable != null) drawable.mutate(); return drawable != null ? drawable : defaultDrawable; } else return defaultDrawable; }
Example 3
Source File: MarkerIconFactory.java From ground-android with Apache License 2.0 | 6 votes |
public BitmapDescriptor getMarkerIcon(int color) { Drawable outline = AppCompatResources.getDrawable(context, R.drawable.ic_marker_outline); Drawable fill = AppCompatResources.getDrawable(context, R.drawable.ic_marker_fill); Drawable overlay = AppCompatResources.getDrawable(context, R.drawable.ic_marker_overlay); // TODO: Define scale in resources. // TODO: Adjust size based on zoom level and selection state. float scale = 1.8f; int width = (int) (outline.getIntrinsicWidth() * scale); int height = (int) (outline.getIntrinsicHeight() * scale); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); outline.setBounds(0, 0, width, height); outline.draw(canvas); fill.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); fill.setBounds(0, 0, width, height); fill.draw(canvas); overlay.setBounds(0, 0, width, height); overlay.draw(canvas); // TODO: Cache rendered bitmaps. return BitmapDescriptorFactory.fromBitmap(bitmap); }
Example 4
Source File: PromotionsFragment.java From aptoide-client-v8 with GNU General Public License v3.0 | 6 votes |
private void setClaimedButton() { promotionAction.setEnabled(false); promotionAction.setBackgroundColor(getResources().getColor(R.color.grey_fog_light)); promotionAction.setTextColor(getResources().getColor(R.color.black)); SpannableString string = new SpannableString( " " + getResources().getString(R.string.holidayspromotion_button_claimed) .toUpperCase()); Drawable image = AppCompatResources.getDrawable(getContext(), R.drawable.ic_promotion_claimed_check); image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight()); ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BASELINE); string.setSpan(imageSpan, 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE); promotionAction.setTransformationMethod(null); promotionAction.setText(string); }
Example 5
Source File: Bindings.java From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License | 5 votes |
@BindingAdapter("searchOrAdd") public static void setFabIcoin(FloatingActionButton fab, boolean needSearch) { Drawable drawable; if (needSearch) { drawable = AppCompatResources.getDrawable(fab.getContext(), R.drawable.ic_search); } else { drawable = AppCompatResources.getDrawable(fab.getContext(), R.drawable.ic_add_accent); } fab.setColorFilter(Color.WHITE); fab.setImageDrawable(drawable); }
Example 6
Source File: Tab.java From ChromeLikeTabSwitcher with Apache License 2.0 | 5 votes |
/** * Returns the icon of the tab's close button. * * @param context * The context, which should be used to retrieve the icon, as an instance of the class * {@link Context}. The context may not be null * @return The icon of the tab's close button as an instance of the class {@link Drawable} or * null, if no custom icon is set */ @Nullable public final Drawable getCloseButtonIcon(@NonNull final Context context) { Condition.INSTANCE.ensureNotNull(context, "The context may not be null"); if (closeButtonIconId != -1) { return AppCompatResources.getDrawable(context, closeButtonIconId); } else { return closeButtonIconBitmap != null ? new BitmapDrawable(context.getResources(), closeButtonIconBitmap) : null; } }
Example 7
Source File: MaterialDialogDecorator.java From AndroidMaterialDialog with Apache License 2.0 | 5 votes |
@Override public final void setIcon(@DrawableRes final int resourceId) { this.iconBitmap = null; this.iconId = resourceId; this.iconAttributeId = -1; this.icon = AppCompatResources.getDrawable(getContext(), resourceId); adaptIcon(); }
Example 8
Source File: IntroWelcomeFragment.java From natrium-android-wallet with BSD 2-Clause "Simplified" License | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // init dependency injection if (getActivity() instanceof ActivityWithComponent) { ((ActivityWithComponent) getActivity()).getActivityComponent().inject(this); } // inflate the view binding = DataBindingUtil.inflate( inflater, R.layout.fragment_intro_welcome, container, false); view = binding.getRoot(); binding.welcomeAnimation.setScale(1.1f); // bind data to view binding.setHandlers(new ClickHandlers()); // Set drawable left (programatically for compat) Drawable startPlusDrawable = AppCompatResources.getDrawable(getContext(), R.drawable.ic_plus_icon); binding.introWelcomeButtonNewWallet.setCompoundDrawablesRelativeWithIntrinsicBounds(startPlusDrawable, null, null, null); binding.introWelcomeButtonNewWallet.setCompoundDrawablePadding((int) (UIUtil.convertDpToPixel(34, getContext()) * -1)); Drawable startImportDrawable = AppCompatResources.getDrawable(getContext(), R.drawable.ic_import_wallet); binding.introWelcomeButtonHaveWallet.setCompoundDrawablesRelativeWithIntrinsicBounds(startImportDrawable, null, null, null); binding.introWelcomeButtonHaveWallet.setCompoundDrawablePadding((int) (UIUtil.convertDpToPixel(34, getContext()) * -1)); // Lottie hardware acceleration if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { binding.welcomeAnimation.useHardwareAcceleration(true); } return view; }
Example 9
Source File: MaterialResources.java From material-components-android with Apache License 2.0 | 5 votes |
/** * Returns the drawable object from the given attributes. * * <p>This method supports inflation of {@code <vector>} and {@code <animated-vector>} resources * on devices where platform support is not available. */ @Nullable public static Drawable getDrawable( @NonNull Context context, @NonNull TypedArray attributes, @StyleableRes int index) { if (attributes.hasValue(index)) { int resourceId = attributes.getResourceId(index, 0); if (resourceId != 0) { Drawable value = AppCompatResources.getDrawable(context, resourceId); if (value != null) { return value; } } } return attributes.getDrawable(index); }
Example 10
Source File: HeaderDialogDecorator.java From AndroidMaterialDialog with Apache License 2.0 | 5 votes |
@Override public final void setHeaderIcon(@DrawableRes final int resourceId, @Nullable final DrawableAnimation animation) { this.headerIconBitmap = null; this.headerIconId = resourceId; this.headerIcon = AppCompatResources.getDrawable(getContext(), resourceId); adaptHeaderIcon(animation); }
Example 11
Source File: TabSwitcher.java From ChromeLikeTabSwitcher with Apache License 2.0 | 5 votes |
/** * Obtains the navigation icon of the toolbar, which is shown, when the tab switcher is shown, * from a specific typed array. * * @param typedArray * The typed array, the navigation icon should be obtained from, as an instance of the * class {@link TypedArray}. The typed array may not be null */ private void obtainToolbarNavigationIcon(@NonNull final TypedArray typedArray) { int resourceId = typedArray.getResourceId(R.styleable.TabSwitcher_toolbarNavigationIcon, -1); Drawable navigationIcon = null; if (resourceId != -1) { navigationIcon = AppCompatResources.getDrawable(getContext(), resourceId); } setToolbarNavigationIcon(navigationIcon, null); }
Example 12
Source File: Utils.java From DateTimePicker with Apache License 2.0 | 5 votes |
@Nullable public static Drawable getDrawable(Context context, TypedArray original, int index, int tintResId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return original.getDrawable(index); } int resId = original.getResourceId(index, 0); Drawable drawable = AppCompatResources.getDrawable(context, resId); if (drawable != null) { Drawable wrapped = DrawableCompat.wrap(drawable); DrawableCompat.applyTheme(wrapped, context.getTheme()); TypedArray a = context.obtainStyledAttributes(new int[]{tintResId}); ColorStateList tintList = a.getColorStateList(0); if (tintList != null) { DrawableCompat.setTintList(wrapped, tintList); } drawable = wrapped; a.recycle(); } return drawable; }
Example 13
Source File: MaterialButton.java From material-components-android with Apache License 2.0 | 5 votes |
@Override public void setBackgroundResource(@DrawableRes int backgroundResourceId) { Drawable background = null; if (backgroundResourceId != 0) { background = AppCompatResources.getDrawable(getContext(), backgroundResourceId); } setBackgroundDrawable(background); }
Example 14
Source File: FastScrollerBuilder.java From AndroidFastScroll with Apache License 2.0 | 5 votes |
@NonNull public FastScrollerBuilder useDefaultStyle() { Context context = mView.getContext(); mTrackDrawable = AppCompatResources.getDrawable(context, R.drawable.afs_track); mThumbDrawable = AppCompatResources.getDrawable(context, R.drawable.afs_thumb); mPopupStyle = PopupStyles.DEFAULT; return this; }
Example 15
Source File: Preference.java From AndroidMaterialPreferences with Apache License 2.0 | 5 votes |
/** * Obtains the preference's icon from a specific typed array. * * @param typedArray * The typed array, the icon should be obtained from, as an instance of the class {@link * TypedArray}. The typed array may not be null */ private void obtainIcon(@NonNull final TypedArray typedArray) { int resourceId = typedArray.getResourceId(R.styleable.Preference_android_icon, -1); if (resourceId != -1) { Drawable icon = AppCompatResources.getDrawable(getContext(), resourceId); setIcon(icon); } }
Example 16
Source File: Compat.java From geopaparazzi with GNU General Public License v3.0 | 5 votes |
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; }
Example 17
Source File: ResourceContactPhoto.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
@Override public Drawable asCallCard(Context context) { return AppCompatResources.getDrawable(context, callCardResourceId); }
Example 18
Source File: LMvdActivity.java From Beedio with GNU General Public License v2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.home); webBox = findViewById(R.id.web); webBox.setOnEditorActionListener(this); ImageButton go = findViewById(R.id.go); go.setOnClickListener(this); if ((browserManager = (BrowserManager) getFragmentManager().findFragmentByTag("BM")) == null) { getFragmentManager().beginTransaction().add(browserManager = new BrowserManager(), "BM").commit(); } // ATTENTION: This was auto-generated to handle app links. Intent appLinkIntent = getIntent(); //String appLinkAction = appLinkIntent.getAction(); appLinkData = appLinkIntent.getData(); layout = findViewById(R.id.drawer); ImageView menu = findViewById(R.id.menuButton); menu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { layout.openDrawer(GravityCompat.START); } }); ListView listView = findViewById(R.id.menu); String[] menuItems = new String[]{"Home", "Browser", "Downloads", "Bookmarks", "History", "About", "Options"}; ArrayAdapter listAdapter = new ArrayAdapter<String>(this, android.R.layout .simple_list_item_1, menuItems) { @NonNull @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { View view = super.getView(position, convertView, parent); TextView textView = view.findViewById(android.R.id.text1); textView.setTextColor(Color.WHITE); int iconId = 0; switch (position) { case 0: iconId = R.drawable.ic_home_white_24dp; break; case 1: iconId = R.drawable.ic_globe_white_24dp; break; case 2: iconId = R.drawable.ic_download_white_24dp; break; case 3: iconId = R.drawable.ic_star_white_24dp; break; case 4: iconId = R.drawable.ic_history_white_24dp; break; case 5: iconId = R.drawable.ic_info_outline_white_24dp; break; case 6: iconId = R.drawable.ic_settings_white_24dp; } if (iconId != 0) { Drawable icon = AppCompatResources.getDrawable(getContext(), iconId); textView.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); textView.setCompoundDrawablePadding((int) (16 * getResources().getDisplayMetrics().density)); } return view; } }; listView.setAdapter(listAdapter); listView.setOnItemClickListener(this); RecyclerView videoSites = findViewById(R.id.homeSites); videoSites.setAdapter(new VideoStreamingSitesList(this)); videoSites.setLayoutManager(new LinearLayoutManager(this)); }
Example 19
Source File: MaterialButton.java From material-components-android with Apache License 2.0 | 3 votes |
/** * Sets the icon drawable resource to show for this button. By default, this icon will be shown on * the left side of the button. * * @param iconResourceId Drawable resource ID to use for the button's icon. * @attr ref com.google.android.material.R.styleable#MaterialButton_icon * @see #setIcon(Drawable) * @see #getIcon() */ public void setIconResource(@DrawableRes int iconResourceId) { Drawable icon = null; if (iconResourceId != 0) { icon = AppCompatResources.getDrawable(getContext(), iconResourceId); } setIcon(icon); }
Example 20
Source File: DialogPreference.java From AndroidMaterialPreferences with Apache License 2.0 | 2 votes |
/** * Sets the icon of the header of the preference's dialog. * * @param resourceId * The resource id of the icon, which should be set, as an {@link Integer} value. The * resource id must correspond to a valid drawable resource */ public final void setDialogHeaderIcon(@DrawableRes final int resourceId) { this.dialogHeaderIcon = AppCompatResources.getDrawable(getContext(), resourceId); this.dialogHeaderIconBitmap = null; this.dialogHeaderIconId = resourceId; }