androidx.appcompat.content.res.AppCompatResources Java Examples

The following examples show how to use androidx.appcompat.content.res.AppCompatResources. 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: ObjectStyleUtils.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #2
Source File: MarkerIconFactory.java    From ground-android with Apache License 2.0 6 votes vote down vote up
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 #3
Source File: MaterialResources.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the {@link ColorStateList} from the given {@link TintTypedArray} attributes. The
 * resource can include themeable attributes, regardless of API level.
 */
@Nullable
public static ColorStateList getColorStateList(
    @NonNull Context context, @NonNull TintTypedArray attributes, @StyleableRes int index) {
  if (attributes.hasValue(index)) {
    int resourceId = attributes.getResourceId(index, 0);
    if (resourceId != 0) {
      ColorStateList value = AppCompatResources.getColorStateList(context, resourceId);
      if (value != null) {
        return value;
      }
    }
  }

  // Reading a single color with getColorStateList() on API 15 and below doesn't always correctly
  // read the value. Instead we'll first try to read the color directly here.
  if (VERSION.SDK_INT <= VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
    int color = attributes.getColor(index, -1);
    if (color != -1) {
      return ColorStateList.valueOf(color);
    }
  }

  return attributes.getColorStateList(index);
}
 
Example #4
Source File: MaterialResources.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the {@link ColorStateList} from the given {@link TypedArray} attributes. The resource
 * can include themeable attributes, regardless of API level.
 */
@Nullable
public static ColorStateList getColorStateList(
    @NonNull Context context, @NonNull TypedArray attributes, @StyleableRes int index) {
  if (attributes.hasValue(index)) {
    int resourceId = attributes.getResourceId(index, 0);
    if (resourceId != 0) {
      ColorStateList value = AppCompatResources.getColorStateList(context, resourceId);
      if (value != null) {
        return value;
      }
    }
  }

  // Reading a single color with getColorStateList() on API 15 and below doesn't always correctly
  // read the value. Instead we'll first try to read the color directly here.
  if (VERSION.SDK_INT <= VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
    int color = attributes.getColor(index, -1);
    if (color != -1) {
      return ColorStateList.valueOf(color);
    }
  }

  return attributes.getColorStateList(index);
}
 
Example #5
Source File: TimePickerClockDelegate.java    From DateTimePicker with Apache License 2.0 6 votes vote down vote up
private void toggleRadialPickerMode() {
    if (mRadialPickerModeEnabled) {
        mRadialTimePickerView.setVisibility(View.GONE);
        mRadialTimePickerHeader.setVisibility(View.GONE);
        mTextInputPickerHeader.setVisibility(View.VISIBLE);
        mTextInputPickerView.setVisibility(View.VISIBLE);
        //mRadialTimePickerModeButton.setImageResource(R.drawable.btn_clock_material);
        mRadialTimePickerModeButton.setImageDrawable(Utils.tintDrawable(mContext, AppCompatResources.getDrawable(mContext, R.drawable.btn_clock_material), R.attr.colorControlNormal)); // fixing tinting
        mRadialTimePickerModeButton.setContentDescription(
                mRadialTimePickerModeEnabledDescription);
        mRadialPickerModeEnabled = false;
    } else {
        mRadialTimePickerView.setVisibility(View.VISIBLE);
        mRadialTimePickerHeader.setVisibility(View.VISIBLE);
        mTextInputPickerHeader.setVisibility(View.GONE);
        mTextInputPickerView.changeInputMethod(false);
        mTextInputPickerView.setVisibility(View.GONE);
        //mRadialTimePickerModeButton.setImageResource(R.drawable.btn_keyboard_key_material);
        mRadialTimePickerModeButton.setImageDrawable(Utils.tintDrawable(mContext, AppCompatResources.getDrawable(mContext, R.drawable.btn_keyboard_key_material), R.attr.colorControlNormal)); // fixing tinting
        mRadialTimePickerModeButton.setContentDescription(
                mTextInputPickerModeEnabledDescription);
        updateTextInputPicker();
        mRadialPickerModeEnabled = true;
    }
}
 
Example #6
Source File: SearchRelationshipViewHolder.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void bind(SearchTEContractsModule.Presenter presenter, SearchTeiModel teiModel) {
    binding.setPresenter(presenter);

    setTEIData(teiModel.getAttributeValues());
    binding.executePendingBindings();
    itemView.setOnClickListener(view -> presenter.addRelationship(teiModel.getTei().uid(), null, teiModel.isOnline()));

    binding.trackedEntityImage.setBackground(AppCompatResources.getDrawable(itemView.getContext(), R.drawable.photo_temp_gray));
    File file = new File(teiModel.getProfilePicturePath());
    Drawable placeHolderId = ObjectStyleUtils.getIconResource(itemView.getContext(), teiModel.getDefaultTypeIcon(), R.drawable.photo_temp_gray);
    Glide.with(itemView.getContext())
            .load(file)
            .placeholder(placeHolderId)
            .error(placeHolderId)
            .transition(withCrossFade())
            .transform(new CircleCrop())
            .into(binding.trackedEntityImage);
}
 
Example #7
Source File: PromotionsFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
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 #8
Source File: ThemeUtils.java    From TwistyTimer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Tints a drawable with {@param colorAttrRes} and returns it.
 * @param context {@link Context}
 * @param drawableRes drawableRes to be tinted
 * @param colorAttrRes attr res id for the tint
 * @return a tinted drawable
 */
public static Drawable tintDrawable(Context context, @DrawableRes int drawableRes, @AttrRes int colorAttrRes) {
    Drawable drawable = AppCompatResources.getDrawable(context, drawableRes).mutate();
    Drawable wrap = DrawableCompat.wrap(drawable).mutate();
    DrawableCompat.setTint(wrap, ThemeUtils.fetchAttrColor(context, colorAttrRes));
    DrawableCompat.setTintMode(wrap, PorterDuff.Mode.SRC_IN);

    return wrap;
}
 
Example #9
Source File: StatusEventFilterHolder.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void bind() {
    super.bind();
    filterTitle.setText(R.string.filters_title_status);
    filterIcon.setImageDrawable(AppCompatResources.getDrawable(itemView.getContext(), R.drawable.ic_status));

    ItemFilterStatusBinding localBinding = (ItemFilterStatusBinding) binding;

    if (programType == FiltersAdapter.ProgramType.EVENT) {
        localBinding.filterStatus.layoutScheduled.setVisibility(View.GONE);
        localBinding.filterStatus.layoutOverdue.setVisibility(View.GONE);
        localBinding.filterStatus.layoutSkipped.setVisibility(View.GONE);
    }

    localBinding.filterStatus.stateOpen.setChecked(FilterManager.getInstance().getEventStatusFilters().contains(EventStatus.ACTIVE) ||
            FilterManager.getInstance().getEventStatusFilters().contains(EventStatus.VISITED));
    localBinding.filterStatus.stateScheduled.setChecked(FilterManager.getInstance().getEventStatusFilters().contains(EventStatus.SCHEDULE));
    localBinding.filterStatus.stateOverdue.setChecked(FilterManager.getInstance().getEventStatusFilters().contains(EventStatus.OVERDUE));
    localBinding.filterStatus.stateCompleted.setChecked(FilterManager.getInstance().getEventStatusFilters().contains(EventStatus.COMPLETED));
    localBinding.filterStatus.stateSkipped.setChecked(FilterManager.getInstance().getEventStatusFilters().contains(EventStatus.SKIPPED));

    localBinding.filterStatus.stateOpen.setOnCheckedChangeListener((compoundButton, b) -> FilterManager.getInstance().addEventStatus(!b, EventStatus.ACTIVE, EventStatus.VISITED));
    localBinding.filterStatus.stateScheduled.setOnCheckedChangeListener((compoundButton, b) -> FilterManager.getInstance().addEventStatus(!b, EventStatus.SCHEDULE));
    localBinding.filterStatus.stateOverdue.setOnCheckedChangeListener((compoundButton, b) -> FilterManager.getInstance().addEventStatus(!b, EventStatus.OVERDUE));
    localBinding.filterStatus.stateCompleted.setOnCheckedChangeListener((compoundButton, b) -> FilterManager.getInstance().addEventStatus(!b, EventStatus.COMPLETED));
    localBinding.filterStatus.stateSkipped.setOnCheckedChangeListener((compoundButton, b) -> FilterManager.getInstance().addEventStatus(!b, EventStatus.SKIPPED));
}
 
Example #10
Source File: SyncStateFilterHolder.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void bind() {
    super.bind();
    filterIcon.setImageDrawable(AppCompatResources.getDrawable(itemView.getContext(), R.drawable.ic_filter_sync));
    filterTitle.setText(R.string.filters_title_state);
    ItemFilterStateBinding localBinding = (ItemFilterStateBinding) binding;

    localBinding.filterState.stateSynced.setChecked(
            FilterManager.getInstance().getStateFilters().contains(State.SYNCED)
    );
    localBinding.filterState.stateNotSynced.setChecked(
            FilterManager.getInstance().getStateFilters().contains(State.TO_UPDATE) ||
                    FilterManager.getInstance().getStateFilters().contains(State.TO_POST) ||
                    FilterManager.getInstance().getStateFilters().contains(State.UPLOADING)
    );
    localBinding.filterState.stateError.setChecked(
            FilterManager.getInstance().getStateFilters().contains(State.ERROR) ||
                    FilterManager.getInstance().getStateFilters().contains(State.WARNING)
    );
    localBinding.filterState.stateSMS.setChecked(
            FilterManager.getInstance().getStateFilters().contains(State.SENT_VIA_SMS) ||
                    FilterManager.getInstance().getStateFilters().contains(State.SYNCED_VIA_SMS)
    );

    localBinding.filterState.stateSynced.setOnCheckedChangeListener((compoundButton, b) ->
            FilterManager.getInstance().addState(!b, State.SYNCED));
    localBinding.filterState.stateNotSynced.setOnCheckedChangeListener((compoundButton, b) ->{
                FilterManager.getInstance().addState(!b, State.TO_UPDATE);
                FilterManager.getInstance().addState(!b, State.TO_POST);
                FilterManager.getInstance().addState(!b, State.UPLOADING);
            });
    localBinding.filterState.stateError.setOnCheckedChangeListener((compoundButton, b) ->
            FilterManager.getInstance().addState(!b, State.ERROR));
    localBinding.filterState.stateSMS.setOnCheckedChangeListener((compoundButton, b) ->
            FilterManager.getInstance().addState(!b, State.SYNCED_VIA_SMS));
}
 
Example #11
Source File: FormViewHolder.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void initFieldFocus() {
    if (currentUid != null) {
        currentUid.observeForever(fieldUid -> {
            if (Objects.equals(fieldUid, this.fieldUid)) {
                Drawable bgDrawable = AppCompatResources.getDrawable(itemView.getContext(), R.drawable.item_selected_bg);
                itemView.setBackground(bgDrawable);
            } else {
                itemView.setBackgroundResource(R.color.form_field_background);
            }
        });

    }
}
 
Example #12
Source File: EmojiView.java    From Emoji with Apache License 2.0 5 votes vote down vote up
private ImageButton inflateButton(final Context context, @DrawableRes final int icon, @StringRes final int categoryName, final ViewGroup parent) {
  final ImageButton button = (ImageButton) LayoutInflater.from(context).inflate(R.layout.emoji_view_category, parent, false);

  button.setImageDrawable(AppCompatResources.getDrawable(context, icon));
  button.setColorFilter(themeIconColor, PorterDuff.Mode.SRC_IN);
  button.setContentDescription(context.getString(categoryName));

  parent.addView(button);

  return button;
}
 
Example #13
Source File: OrgUnitFilterHolder.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void bind() {
    super.bind();
    filterIcon.setImageDrawable(AppCompatResources.getDrawable(itemView.getContext(), R.drawable.ic_filter_ou));
    filterTitle.setText(R.string.filters_title_org_unit);

    setUpAdapter();

}
 
Example #14
Source File: FastScrollerBuilder.java    From AndroidFastScroll with Apache License 2.0 5 votes vote down vote up
@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 vote down vote up
/**
 * 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: RecyclerViewListStatefulFragment.java    From AndroidFastScroll with Apache License 2.0 5 votes vote down vote up
@NonNull
protected FastScroller createFastScroller(@NonNull RecyclerView recyclerView) {
    return new FastScrollerBuilder(recyclerView)
            .setThumbDrawable(AppCompatResources.getDrawable(recyclerView.getContext(),
                    R.drawable.afs_thumb_stateful))
            .build();
}
 
Example #17
Source File: TabLayout.java    From a with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the icon displayed on this tab.
 *
 * @param resId A resource ID referring to the icon that should be displayed
 * @return The current instance for call chaining
 */
@NonNull
public Tab setIcon(@DrawableRes int resId) {
    if (mParent == null) {
        throw new IllegalArgumentException("Tab not attached to a TabLayout");
    }
    return setIcon(AppCompatResources.getDrawable(mParent.getContext(), resId));
}
 
Example #18
Source File: Utils.java    From DateTimePicker with Apache License 2.0 5 votes vote down vote up
@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 #19
Source File: MaterialDatePicker.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@NonNull
private static Drawable createHeaderToggleDrawable(Context context) {
  StateListDrawable toggleDrawable = new StateListDrawable();
  toggleDrawable.addState(
      new int[] {android.R.attr.state_checked},
      AppCompatResources.getDrawable(context, R.drawable.material_ic_calendar_black_24dp));
  toggleDrawable.addState(
      new int[] {},
      AppCompatResources.getDrawable(context, R.drawable.material_ic_edit_black_24dp));
  return toggleDrawable;
}
 
Example #20
Source File: WormDotsIndicator.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ViewGroup buildDot(boolean stroke) {
    ViewGroup dot = (ViewGroup) LayoutInflater.from(getContext()).inflate(R.layout.worm_dot_layout, this, false);
    View dotImageView = dot.findViewById(R.id.worm_dot);
    dotImageView.setBackground(
            AppCompatResources.getDrawable(getContext(), stroke ? R.drawable.worm_dot_stroke_background : R.drawable.worm_dot_background));
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) dotImageView.getLayoutParams();
    params.width = params.height = dotsSize;
    params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);

    params.setMargins(dotsSpacing, 0, dotsSpacing, 0);

    setUpDotBackground(stroke, dotImageView);
    return dot;
}
 
Example #21
Source File: SpringDotsIndicator.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private ViewGroup buildDot(boolean stroke) {
    ViewGroup dot = (ViewGroup) LayoutInflater.from(getContext()).inflate(R.layout.spring_dot_layout, this, false);
    ImageView dotView = dot.findViewById(R.id.spring_dot);
    dotView.setBackground(
            AppCompatResources.getDrawable(getContext(), stroke ? R.drawable.spring_dot_stroke_background : R.drawable.spring_dot_background));
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) dotView.getLayoutParams();
    params.width = params.height = stroke ? dotsStrokeSize : dotIndicatorSize;
    params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);

    params.setMargins(dotsSpacing, 0, dotsSpacing, 0);

    setUpDotBackground(stroke, dotView);
    return dot;
}
 
Example #22
Source File: IntroWelcomeFragment.java    From natrium-android-wallet with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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 #23
Source File: Utils.java    From DateTimePicker with Apache License 2.0 5 votes vote down vote up
@Nullable
public static ColorStateList getColorStateList(Context context, TypedArray original, int index) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return original.getColorStateList(index);
    }

    int resId = original.getResourceId(index, 0);
    return AppCompatResources.getColorStateList(context, resId);
}
 
Example #24
Source File: NumberPicker.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
private void restyleViews() {
    for (Button number : mNumbers) {
        if (number != null) {
            number.setTextColor(mTextColor);
            number.setBackgroundResource(mKeyBackgroundResId);
        }
    }
    if (mDivider != null) {
        mDivider.setBackgroundColor(mDividerColor);
    }
    if (mLeft != null) {
        mLeft.setTextColor(mTextColor);
        mLeft.setBackgroundResource(mKeyBackgroundResId);
    }
    if (mRight != null) {
        mRight.setTextColor(mTextColor);
        mRight.setBackgroundResource(mKeyBackgroundResId);
    }
    if (mBackspace != null) {
        //mBackspace.setBackgroundResource(mButtonBackgroundResId);
        mBackspace.setImageDrawable(AppCompatResources.getDrawable(mContext, mBackspaceDrawableSrcResId));
    }
    if (mClear != null) {
        //mDelete.setBackgroundResource(mButtonBackgroundResId);
        mClear.setImageDrawable(AppCompatResources.getDrawable(mContext, mClearDrawableSrcResId));
    }
    if (mEnteredNumber != null) {
        mEnteredNumber.setTheme(mTheme);
    }
    if (mLabel != null) {
        mLabel.setTextColor(mTextColor);
    }
}
 
Example #25
Source File: NavigationPreference.java    From AndroidPreferenceActivity with Apache License 2.0 5 votes vote down vote up
/**
 * 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.NavigationPreference_android_icon, -1);

    if (resourceId != -1) {
        Drawable icon = AppCompatResources.getDrawable(getContext(), resourceId);
        setIcon(icon);
    }
}
 
Example #26
Source File: SendFundsFragment.java    From adamant-android with GNU General Public License v3.0 5 votes vote down vote up
private Drawable getIcon(Context context, int resourceId) {
    Drawable drawable = AppCompatResources.getDrawable(context, resourceId);
    if (drawable == null) {return null;}
    int h = drawable.getIntrinsicHeight();
    int w = drawable.getIntrinsicWidth();
    drawable.setBounds( 0, 0, w, h );

    return drawable;
}
 
Example #27
Source File: MaterialDialogDecorator.java    From AndroidMaterialDialog with Apache License 2.0 5 votes vote down vote up
@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 #28
Source File: DynamicResourceUtils.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
/**
 * Get the drawable from the supplied resource.
 *
 * @param context The context to retrieve resources.
 * @param drawableRes The drawable resource to get the drawable.
 *
 * @return The drawable retrieved from the resource.
 */
public static @Nullable Drawable getDrawable(@NonNull Context context,
        @DrawableRes int drawableRes) {
    try {
        return AppCompatResources.getDrawable(context, drawableRes);
    } catch (Exception e) {
        return null;
    }
}
 
Example #29
Source File: EntryThumbnail.java    From andOTP with MIT License 5 votes vote down vote up
public static Bitmap getThumbnailGraphic(Context context, String issuer, String label, int size, EntryThumbnails thumbnail) {
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);

    if (thumbnail == EntryThumbnails.Default && size > 0) {
        LetterBitmap letterBitmap = new LetterBitmap(context);
        String letterSrc = issuer.isEmpty() ? label : issuer;
        return letterBitmap.getLetterTile(letterSrc, letterSrc, size, size);
    } else if (thumbnail != EntryThumbnails.Default) {

        try {
            if (thumbnail.getAssetType() == AssetType.Vector) {
                Drawable drawable = AppCompatResources.getDrawable(context, thumbnail.getResource());
                Bitmap bitmap = Bitmap.createBitmap(drawable.getMinimumWidth(), drawable.getMinimumHeight(), Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(bitmap);
                drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                drawable.draw(canvas);
                return bitmap;
            } else {
                return BitmapFactory.decodeResource(context.getResources(), thumbnail.getResource());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher_round);
}
 
Example #30
Source File: TabLayout.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/**
 * Set the icon displayed on this tab.
 *
 * @param resId A resource ID referring to the icon that should be displayed
 * @return The current instance for call chaining
 */
@NonNull
public Tab setIcon(@DrawableRes int resId) {
  if (parent == null) {
    throw new IllegalArgumentException("Tab not attached to a TabLayout");
  }
  return setIcon(AppCompatResources.getDrawable(parent.getContext(), resId));
}