public static Drawable getDrawableWithNumber(Drawable baseDrawable, int number, int iconSize, Context context) { if (number < 0 || number > 9) { number = 0; } Drawable numberDrawable = context.Resources.getDrawable(R.drawable.number_round); if (numberDrawable == null) { return baseDrawable; } int appIconShift = context.Resources.getDimensionPixelOffset(R.dimen.ord_app_icon_shift); Bitmap bitmap = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); int textSize = context.Resources.getDimensionPixelSize(R.dimen.number_icon_text_size); int textColor = context.Resources.getColor(R.color.fc_app_icon_number_color); TextDrawable textDrawable = new TextDrawable(number.ToString(), textSize, textColor); baseDrawable.setBounds(0, 0, iconSize, iconSize); baseDrawable.draw(canvas); numberDrawable.setBounds(iconSize - (appIconShift + numberDrawable.IntrinsicWidth), appIconShift, iconSize - (appIconShift), appIconShift + numberDrawable.IntrinsicHeight); numberDrawable.draw(canvas); textDrawable.setBounds(iconSize - (appIconShift + numberDrawable.IntrinsicWidth), appIconShift, iconSize - (appIconShift), appIconShift + numberDrawable.IntrinsicHeight); textDrawable.draw(canvas); return new BitmapDrawable(context.Resources, bitmap); }
public static Drawable getDrawableWithNumber(Drawable baseDrawable, int number, int iconSize, Context context) { if (number < 0 || number > 9) { number = 0; } Drawable numberDrawable = context.Resources.getDrawable(R.drawable.number_round); if (numberDrawable == null) { return(baseDrawable); } int appIconShift = context.Resources.getDimensionPixelOffset(R.dimen.ord_app_icon_shift); Bitmap bitmap = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); int textSize = context.Resources.getDimensionPixelSize(R.dimen.number_icon_text_size); int textColor = context.Resources.getColor(R.color.fc_app_icon_number_color); TextDrawable textDrawable = new TextDrawable(number.ToString(), textSize, textColor); baseDrawable.setBounds(0, 0, iconSize, iconSize); baseDrawable.draw(canvas); numberDrawable.setBounds(iconSize - (appIconShift + numberDrawable.IntrinsicWidth), appIconShift, iconSize - (appIconShift), appIconShift + numberDrawable.IntrinsicHeight); numberDrawable.draw(canvas); textDrawable.setBounds(iconSize - (appIconShift + numberDrawable.IntrinsicWidth), appIconShift, iconSize - (appIconShift), appIconShift + numberDrawable.IntrinsicHeight); textDrawable.draw(canvas); return(new BitmapDrawable(context.Resources, bitmap)); }
/// /// <summary> /// This method returns the given drawable with a number on it. /// </summary> /// <param name="baseDrawable"> /// Drawable to which number will be added </param> /// <param name="number"> /// An integer which will be expressed by the drawable </param> /// <param name="shiftFromLeft"> /// Left margin of number drawable </param> /// <param name="shiftFromBottom"> /// Bottom margin of number drawable </param> /// <param name="context"> /// The base context </param> /// <returns> Drawable with number </returns> public static Drawable getDrawableWithNumber(Drawable baseDrawable, int number, int shiftFromLeft, int shiftFromBottom, Context context) { if (number < 0 || number > 9) { number = 0; } int textSize = context.Resources.getDimensionPixelSize(R.dimen.number_icon_text_size); // TODO: Remove hardcoded text drawable color TextDrawable textDrawable = new TextDrawable(number.ToString(), textSize, Color.WHITE); Drawable numberDrawable = context.Resources.getDrawable(R.drawable.number_round); textDrawable.setBounds(0, 0, numberDrawable.IntrinsicWidth, numberDrawable.IntrinsicHeight); Drawable[] drawables = new Drawable[] {baseDrawable, numberDrawable, textDrawable}; LayerDrawable layerDrawable = new LayerDrawable(drawables); layerDrawable.setLayerInset(1, shiftFromLeft, 0, 0, shiftFromBottom); layerDrawable.setLayerInset(2, shiftFromLeft, 0, 0, shiftFromBottom); return layerDrawable; }
/// /// <summary> /// This method returns the given drawable with a number on it. /// </summary> /// <param name="baseDrawable"> /// Drawable to which number will be added </param> /// <param name="number"> /// An integer which will be expressed by the drawable </param> /// <param name="shiftFromLeft"> /// Left margin of number drawable </param> /// <param name="shiftFromBottom"> /// Bottom margin of number drawable </param> /// <param name="context"> /// The base context </param> /// <returns> Drawable with number </returns> public static Drawable getDrawableWithNumber(Drawable baseDrawable, int number, int shiftFromLeft, int shiftFromBottom, Context context) { if (number < 0 || number > 9) { number = 0; } int textSize = context.Resources.getDimensionPixelSize(R.dimen.number_icon_text_size); // TODO: Remove hardcoded text drawable color TextDrawable textDrawable = new TextDrawable(number.ToString(), textSize, Color.WHITE); Drawable numberDrawable = context.Resources.getDrawable(R.drawable.number_round); textDrawable.setBounds(0, 0, numberDrawable.IntrinsicWidth, numberDrawable.IntrinsicHeight); Drawable[] drawables = new Drawable[] { baseDrawable, numberDrawable, textDrawable }; LayerDrawable layerDrawable = new LayerDrawable(drawables); layerDrawable.setLayerInset(1, shiftFromLeft, 0, 0, shiftFromBottom); layerDrawable.setLayerInset(2, shiftFromLeft, 0, 0, shiftFromBottom); return(layerDrawable); }