androidx.annotation.DrawableRes Java Examples

The following examples show how to use androidx.annotation.DrawableRes. 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: TransportOption.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public TransportOption(@NonNull  Type type,
                       @DrawableRes int drawable,
                       int backgroundColor,
                       @NonNull String text,
                       @NonNull String composeHint,
                       @NonNull CharacterCalculator characterCalculator,
                       @NonNull Optional<CharSequence> simName,
                       @NonNull Optional<Integer> simSubscriptionId)
{
  this.type                = type;
  this.drawable            = drawable;
  this.backgroundColor     = backgroundColor;
  this.text                = text;
  this.composeHint         = composeHint;
  this.characterCalculator = characterCalculator;
  this.simName             = simName;
  this.simSubscriptionId   = simSubscriptionId;
}
 
Example #2
Source File: MaterialMultiAutoCompleteTextView.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
private Bitmap[] generateIconBitmaps(@DrawableRes int origin) {
  if (origin == -1) {
    return null;
  }
  BitmapFactory.Options options = new BitmapFactory.Options();
  options.inJustDecodeBounds = true;
  BitmapFactory.decodeResource(getResources(), origin, options);
  int size = Math.max(options.outWidth, options.outHeight);
  options.inSampleSize = size > iconSize ? size / iconSize : 1;
  options.inJustDecodeBounds = false;
  return generateIconBitmaps(BitmapFactory.decodeResource(getResources(), origin, options));
}
 
Example #3
Source File: AvatarUtil.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static GlideRequest<Drawable> getSelfAvatarOrFallbackIcon(@NonNull Context context, @DrawableRes int fallbackIcon) {
  return GlideApp.with(context)
                 .asDrawable()
                 .load(new ProfileContactPhoto(Recipient.self(), Recipient.self().getProfileAvatar()))
                 .error(fallbackIcon)
                 .circleCrop()
                 .diskCacheStrategy(DiskCacheStrategy.ALL);
}
 
Example #4
Source File: CallNotificationBuilder.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static NotificationCompat.Action getActivityNotificationAction(@NonNull Context context, @NonNull String action,
                                                                       @DrawableRes int iconResId, @StringRes int titleResId)
{
  Intent intent = new Intent(context, WebRtcCallActivity.class);
  intent.setAction(action);

  PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

  return new NotificationCompat.Action(iconResId, context.getString(titleResId), pendingIntent);
}
 
Example #5
Source File: TransportOption.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public TransportOption(@NonNull  Type type,
                       @DrawableRes int drawable,
                       int backgroundColor,
                       @NonNull String text,
                       @NonNull String composeHint,
                       @NonNull CharacterCalculator characterCalculator)
{
  this(type, drawable, backgroundColor, text, composeHint, characterCalculator,
       Optional.<CharSequence>absent(), Optional.<Integer>absent());
}
 
Example #6
Source File: VerifyIdentityActivity.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private Bitmap createVerifiedBitmap(int width, int height, @DrawableRes int id) {
  Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  Canvas canvas = new Canvas(bitmap);
  Bitmap check  = BitmapFactory.decodeResource(getResources(), id);
  float  offset = (width - check.getWidth()) / 2;

  canvas.drawBitmap(check, offset, offset, null);

  return bitmap;
}
 
Example #7
Source File: GenericForegroundService.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static NotificationController startForegroundTask(@NonNull Context context, @NonNull String task, @NonNull String channelId, @DrawableRes int iconRes) {
  final int id = NEXT_ID.getAndIncrement();

  Intent intent = new Intent(context, GenericForegroundService.class);
  intent.setAction(ACTION_START);
  intent.putExtra(EXTRA_TITLE, task);
  intent.putExtra(EXTRA_CHANNEL_ID, channelId);
  intent.putExtra(EXTRA_ICON_RES, iconRes);
  intent.putExtra(EXTRA_ID, id);

  ContextCompat.startForegroundService(context, intent);

  return new NotificationController(context, id);
}
 
Example #8
Source File: AbstractSetting.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
public AbstractSetting(String title, String description, @Nullable @DrawableRes Integer abstractIcon, int layoutId) {
    this.title = title;
    this.description = description;
    this.layoutId = layoutId;
    this.selectionAbstract = null;
    this.abstractIconResource = abstractIcon;
}
 
Example #9
Source File: GenericForegroundService.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private Entry(@NonNull String title, @NonNull String channelId, @DrawableRes int iconRes, int id, int progressMax, int progress, boolean indeterminate) {
  this.title         = title;
  this.channelId     = channelId;
  this.iconRes       = iconRes;
  this.id            = id;
  this.progress      = progress;
  this.progressMax   = progressMax;
  this.indeterminate = indeterminate;
}
 
Example #10
Source File: RationaleDialog.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
public static AlertDialog.Builder createFor(@NonNull Context context, @NonNull String message, @DrawableRes int... drawables) {
  View      view   = LayoutInflater.from(context).inflate(R.layout.permissions_rationale_dialog, null);
  ViewGroup header = view.findViewById(R.id.header_container);
  TextView  text   = view.findViewById(R.id.message);

  for (int i=0;i<drawables.length;i++) {
    Drawable drawable = ContextCompat.getDrawable(context, drawables[i]);
    DrawableCompat.setTint(drawable, ContextCompat.getColor(context, R.color.white));
    ImageView imageView = new ImageView(context);
    imageView.setImageDrawable(drawable);
    imageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    header.addView(imageView);

    if (i != drawables.length - 1) {
      TextView plus = new TextView(context);
      plus.setText("+");
      plus.setTextSize(TypedValue.COMPLEX_UNIT_SP, 40);
      plus.setTextColor(Color.WHITE);

      LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
      layoutParams.setMargins(ViewUtil.dpToPx(context, 20), 0, ViewUtil.dpToPx(context, 20), 0);

      plus.setLayoutParams(layoutParams);
      header.addView(plus);
    }
  }

  text.setText(message);

  return new AlertDialog.Builder(context, ThemeUtil.isDarkTheme(context) ? R.style.Theme_Signal_AlertDialog_Dark_Cornered : R.style.Theme_Signal_AlertDialog_Light_Cornered)
                        .setView(view);
}
 
Example #11
Source File: BatteryView.java    From BaldPhone with Apache License 2.0 5 votes vote down vote up
public void setLevel(int level, boolean charged) {
    percentage = level;
    @DrawableRes int drawableRes = R.drawable.battery_unknown_on_background;
    if (charged) {
        if (level < 20) {
            drawableRes = R.drawable.battery_20_c_on_background;
        } else if (level < 30) {
            drawableRes = R.drawable.battery_30_c_on_background;
        } else if (level < 50) {
            drawableRes = R.drawable.battery_50_c_on_background;
        } else if (level < 60) {
            drawableRes = R.drawable.battery_60_c_on_background;
        } else if (level < 80) {
            drawableRes = R.drawable.battery_80_c_on_background;
        } else if (level < 90) {
            drawableRes = R.drawable.battery_90_c_on_background;
        } else if (level < 100) {
            drawableRes = R.drawable.battery_100_charging;
        } else
            drawableRes = R.drawable.battery_full_on_background;
    } else {
        if (level < D.LOW_BATTERY_LEVEL) {
            drawableRes = R.drawable.battery_20_on_background;
        } else if (level < 30) {
            drawableRes = R.drawable.battery_30_on_background;
        } else if (level < 50) {
            drawableRes = R.drawable.battery_50_on_background;
        } else if (level < 60) {
            drawableRes = R.drawable.battery_60_on_background;
        } else if (level < 80) {
            drawableRes = R.drawable.battery_80_on_background;
        } else if (level < 90) {
            drawableRes = R.drawable.battery_90_on_background;
        } else if (level <= 100) {
            drawableRes = R.drawable.battery_full_on_background;
        }

    }
    setImageResource(drawableRes);
}
 
Example #12
Source File: ArcusFloatingFragment.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
public void setCloseButtonIcon(@DrawableRes int buttonIcon) {
    if (closeBtn == null) {
        return;
    }

    closeBtn.setImageResource(buttonIcon);
}
 
Example #13
Source File: QueryItemTouchHelper.java    From lttrs-android with Apache License 2.0 5 votes vote down vote up
@Override
public int getSwipeDirs(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
    if (viewHolder instanceof ThreadOverviewAdapter.ThreadOverviewViewHolder) {
        final ThreadOverviewAdapter.ThreadOverviewViewHolder threadOverviewViewHolder = (ThreadOverviewAdapter.ThreadOverviewViewHolder) viewHolder;
        if (onQueryItemSwipe != null) {
            final Swipable swipable = onQueryItemSwipe.onQueryItemSwipe(viewHolder.getAdapterPosition());
            if (swipable == Swipable.NO) {
                return 0;
            }
            @DrawableRes final int resource;
            switch (swipable) {
                case ARCHIVE:
                    resource = R.drawable.ic_archive_white_24dp;
                    break;
                case REMOVE_FLAGGED:
                    resource = R.drawable.ic_star_border_white_24dp;
                    break;
                default:
                    resource = R.drawable.ic_label_off_white_24dp;
                    break;

            }
            threadOverviewViewHolder.binding.endSwipeActionIndicator.setImageResource(resource);
            threadOverviewViewHolder.binding.startSwipeActionIndicator.setImageResource(resource);
            return ItemTouchHelper.RIGHT | ItemTouchHelper.LEFT;
        }
    }
    return 0;
}
 
Example #14
Source File: DrawableManager.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
public static Drawable getVectorDrawable(@NonNull Resources res,
        @DrawableRes int resId, @Nullable Resources.Theme theme) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return res.getDrawable(resId, theme);
    } else {
        return VectorDrawableCompat.create(res, resId, theme);
    }
}
 
Example #15
Source File: RichEditText.java    From RichEditor with MIT License 5 votes vote down vote up
public void insertBlockImage(@DrawableRes int resourceId, @NonNull BlockImageSpanVm blockImageSpanVm,
                             OnImageClickListener onImageClickListener) {
    try {
        Drawable drawable = AppCompatResources.getDrawable(mActivity, resourceId);
        insertBlockImage(drawable, blockImageSpanVm, onImageClickListener);
    } catch (Exception e) {
        LogUtil.e(TAG, "Unable to find resource: " + resourceId);
    }
}
 
Example #16
Source File: Setting.java    From candybar with Apache License 2.0 5 votes vote down vote up
public Setting(@DrawableRes int icon, String title, String subtitle, String content, String footer,
               @NonNull Setting.Type type, @IntRange(from = -1, to = 1) int checkState) {
    mIcon = icon;
    mTitle = title;
    mSubtitle = subtitle;
    mContent = content;
    mFooter = footer;
    mType = type;
    mCheckState = checkState;
}
 
Example #17
Source File: DialogService.java    From Twire with GNU General Public License v3.0 5 votes vote down vote up
private static MaterialSimpleListItem getThemeDialogAdapterItem(@StringRes int title, @DrawableRes int icon, Activity activity) {
    MaterialSimpleListItem.Builder builder = new MaterialSimpleListItem.Builder(activity)
            .content(title)
            .icon(icon);

    return builder.build();
}
 
Example #18
Source File: ImageFragment.java    From animation-samples with Apache License 2.0 5 votes vote down vote up
public static ImageFragment newInstance(@DrawableRes int drawableRes) {
  ImageFragment fragment = new ImageFragment();
  Bundle argument = new Bundle();
  argument.putInt(KEY_IMAGE_RES, drawableRes);
  fragment.setArguments(argument);
  return fragment;
}
 
Example #19
Source File: AppearanceSettingsFragment.java    From Twire with GNU General Public License v3.0 5 votes vote down vote up
private Drawable getColorPreviewFromTheme(String themeTitle) {
    @DrawableRes int drawableRes = R.drawable.circle_theme_blue_chooser;

    if (themeTitle.equals(getString(R.string.purple_theme_name))) {
        drawableRes = R.drawable.circle_theme_purple_chooser;
    } else if (themeTitle.equals(getString(R.string.black_theme_name))) {
        drawableRes = R.drawable.circle_theme_black_chooser;
    } else if (themeTitle.equals(getString(R.string.night_theme_name))) {
        drawableRes = R.drawable.circle_theme_night_chooser;
    }

    return ContextCompat.getDrawable(getContext(), drawableRes);
}
 
Example #20
Source File: MainActivity.java    From media-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Update the state of pause/resume action item in Picture-in-Picture mode.
 *
 * @param iconId The icon to be used.
 * @param title The title text.
 * @param controlType The type of the action. either {@link #CONTROL_TYPE_PLAY} or {@link
 *     #CONTROL_TYPE_PAUSE}.
 * @param requestCode The request code for the {@link PendingIntent}.
 */
void updatePictureInPictureActions(
        @DrawableRes int iconId, String title, int controlType, int requestCode) {
    final ArrayList<RemoteAction> actions = new ArrayList<>();

    // This is the PendingIntent that is invoked when a user clicks on the action item.
    // You need to use distinct request codes for play and pause, or the PendingIntent won't
    // be properly updated.
    final PendingIntent intent =
            PendingIntent.getBroadcast(
                    MainActivity.this,
                    requestCode,
                    new Intent(ACTION_MEDIA_CONTROL).putExtra(EXTRA_CONTROL_TYPE, controlType),
                    0);
    final Icon icon = Icon.createWithResource(MainActivity.this, iconId);
    actions.add(new RemoteAction(icon, title, title, intent));

    // Another action item. This is a fixed action.
    actions.add(
            new RemoteAction(
                    Icon.createWithResource(MainActivity.this, R.drawable.ic_info_24dp),
                    getString(R.string.info),
                    getString(R.string.info_description),
                    PendingIntent.getActivity(
                            MainActivity.this,
                            REQUEST_INFO,
                            new Intent(
                                    Intent.ACTION_VIEW,
                                    Uri.parse(getString(R.string.info_uri))),
                            0)));

    mPictureInPictureParamsBuilder.setActions(actions);

    // This is how you can update action items (or aspect ratio) for Picture-in-Picture mode.
    // Note this call can happen even when the app is not in PiP mode. In that case, the
    // arguments will be used for at the next call of #enterPictureInPictureMode.
    setPictureInPictureParams(mPictureInPictureParamsBuilder.build());
}
 
Example #21
Source File: PDFImageView.java    From PDFCreatorAndroid with MIT License 4 votes vote down vote up
public PDFImageView setImageResource(@DrawableRes int resId) {
    ((ImageView) super.getView()).setImageResource(resId);
    return this;
}
 
Example #22
Source File: Contributor.java    From leafpicrevived with GNU General Public License v3.0 4 votes vote down vote up
public Contributor(String name, String description, @DrawableRes int profileImage) {
    this.name = name;
    this.description = description;
    this.profileImage = profileImage;
    this.contacts = new ArrayList<>();
}
 
Example #23
Source File: SelectorFactory.java    From monero-wallet-android-app with MIT License 4 votes vote down vote up
public GeneralSelector setFocusedDrawable(Context context, @DrawableRes int drawableRes) {
    return setFocusedDrawable(ContextCompat.getDrawable(context, drawableRes));
}
 
Example #24
Source File: LoadImageView.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
public void load(@DrawableRes int id) {
    unload();
    onPreSetImageResource(id, true);
    setImageResource(id);
}
 
Example #25
Source File: BaldPictureTextButton.java    From BaldPhone with Apache License 2.0 4 votes vote down vote up
public void setImageResource(@DrawableRes int resId) {
    imageView.setImageResource(resId);
}
 
Example #26
Source File: MaterialEditText.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
public void setIconRight(@DrawableRes int res) {
  iconRightBitmaps = generateIconBitmaps(res);
  initPadding();
}
 
Example #27
Source File: SettingsActivity.java    From BaldPhone with Apache License 2.0 4 votes vote down vote up
RunnableSettingsItem(@StringRes int textResId, View.OnClickListener onClickListener, @DrawableRes int drawableResId) {
    super(textResId, drawableResId);
    this.onClickListener = onClickListener;
}
 
Example #28
Source File: MaterialMultiAutoCompleteTextView.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
public void setIconLeft(@DrawableRes int res) {
  iconLeftBitmaps = generateIconBitmaps(res);
  initPadding();
}
 
Example #29
Source File: SettingsActivity.java    From BaldPhone with Apache License 2.0 4 votes vote down vote up
protected SettingsItem(@StringRes int textResId, @DrawableRes int drawableResId) {
    this.textResId = textResId;
    this.drawableResId = drawableResId;
}
 
Example #30
Source File: MaterialAutoCompleteTextView.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
public void setIconRight(@DrawableRes int res) {
  iconRightBitmaps = generateIconBitmaps(res);
  initPadding();
}