List of usage examples for android.graphics Paint setXfermode
public Xfermode setXfermode(Xfermode xfermode)
From source file:com.android.mms.ui.MessageUtils.java
public static Bitmap getCircularBitmap(Bitmap bitmap) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = bitmap.getWidth() / 2; paint.setAntiAlias(true);/*www . j a v a 2s. c o m*/ canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; }
From source file:g7.bluesky.launcher3.Launcher.java
public void loadIconPack(List<ShortcutInfo> shortcuts) { //theming vars----------------------------------------------- PackageManager pm = getPackageManager(); final int ICONSIZE = Tools.numtodp(128, Launcher.this); Resources themeRes = null;/*from www. jav a 2s . c o m*/ String resPacName = defaultSharedPref.getString(SettingConstants.ICON_THEME_PREF_KEY, ""); String iconResource = null; int intres = 0; int intresiconback = 0; int intresiconfront = 0; int intresiconmask = 0; float scaleFactor = 1.0f; Paint p = new Paint(Paint.FILTER_BITMAP_FLAG); p.setAntiAlias(true); Paint origP = new Paint(Paint.FILTER_BITMAP_FLAG); origP.setAntiAlias(true); Paint maskp = new Paint(Paint.FILTER_BITMAP_FLAG); maskp.setAntiAlias(true); maskp.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); if (resPacName.compareTo("") != 0) { try { themeRes = pm.getResourcesForApplication(resPacName); } catch (Exception e) { } ; if (themeRes != null) { String[] backAndMaskAndFront = ThemeTools.getIconBackAndMaskResourceName(themeRes, resPacName); if (backAndMaskAndFront[0] != null) intresiconback = themeRes.getIdentifier(backAndMaskAndFront[0], "drawable", resPacName); if (backAndMaskAndFront[1] != null) intresiconmask = themeRes.getIdentifier(backAndMaskAndFront[1], "drawable", resPacName); if (backAndMaskAndFront[2] != null) intresiconfront = themeRes.getIdentifier(backAndMaskAndFront[2], "drawable", resPacName); } } BitmapFactory.Options uniformOptions = new BitmapFactory.Options(); uniformOptions.inScaled = false; uniformOptions.inDither = false; uniformOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; Canvas origCanv; Canvas canvas; scaleFactor = ThemeTools.getScaleFactor(themeRes, resPacName); Bitmap back = null; Bitmap mask = null; Bitmap front = null; Bitmap scaledBitmap = null; Bitmap scaledOrig = null; Bitmap orig = null; if (resPacName.compareTo("") != 0 && themeRes != null) { try { if (intresiconback != 0) back = BitmapFactory.decodeResource(themeRes, intresiconback, uniformOptions); } catch (Exception e) { } try { if (intresiconmask != 0) mask = BitmapFactory.decodeResource(themeRes, intresiconmask, uniformOptions); } catch (Exception e) { } try { if (intresiconfront != 0) front = BitmapFactory.decodeResource(themeRes, intresiconfront, uniformOptions); } catch (Exception e) { } } //theming vars----------------------------------------------- BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = false; options.inPreferredConfig = Bitmap.Config.RGB_565; options.inDither = true; for (int i = 0; i < shortcuts.size(); i++) { if (themeRes != null) { iconResource = null; intres = 0; iconResource = ThemeTools.getResourceName(themeRes, resPacName, shortcuts.get(i).getTargetComponent().toString()); if (iconResource != null) { intres = themeRes.getIdentifier(iconResource, "drawable", resPacName); } if (intres != 0) {//has single drawable for app shortcuts.get(i).setIcon(BitmapFactory.decodeResource(themeRes, intres, uniformOptions)); } else { Drawable drawable = Utilities.createIconDrawable(shortcuts.get(i).getIcon(mIconCache)); orig = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(new Canvas(orig)); scaledOrig = Bitmap.createBitmap(ICONSIZE, ICONSIZE, Bitmap.Config.ARGB_8888); scaledBitmap = Bitmap.createBitmap(ICONSIZE, ICONSIZE, Bitmap.Config.ARGB_8888); canvas = new Canvas(scaledBitmap); if (back != null) { canvas.drawBitmap(back, Tools.getResizedMatrix(back, ICONSIZE, ICONSIZE), p); } origCanv = new Canvas(scaledOrig); orig = Tools.getResizedBitmap(orig, ((int) (ICONSIZE * scaleFactor)), ((int) (ICONSIZE * scaleFactor))); origCanv.drawBitmap(orig, scaledOrig.getWidth() - (orig.getWidth() / 2) - scaledOrig.getWidth() / 2, scaledOrig.getWidth() - (orig.getWidth() / 2) - scaledOrig.getWidth() / 2, origP); if (mask != null) { origCanv.drawBitmap(mask, Tools.getResizedMatrix(mask, ICONSIZE, ICONSIZE), maskp); } if (back != null) { canvas.drawBitmap(Tools.getResizedBitmap(scaledOrig, ICONSIZE, ICONSIZE), 0, 0, p); } else canvas.drawBitmap(Tools.getResizedBitmap(scaledOrig, ICONSIZE, ICONSIZE), 0, 0, p); if (front != null) canvas.drawBitmap(front, Tools.getResizedMatrix(front, ICONSIZE, ICONSIZE), p); shortcuts.get(i).setIcon(scaledBitmap); } } } }
From source file:g7.bluesky.launcher3.Launcher.java
public void loadIconPack() { //theming vars----------------------------------------------- PackageManager pm = getPackageManager(); final int ICONSIZE = Tools.numtodp(64, Launcher.this); Resources themeRes = null;//ww w . ja va2 s . c o m String resPacName = defaultSharedPref.getString(SettingConstants.ICON_THEME_PREF_KEY, ""); String iconResource = null; int intres = 0; int intresiconback = 0; int intresiconfront = 0; int intresiconmask = 0; float scaleFactor = 1.0f; Paint p = new Paint(Paint.FILTER_BITMAP_FLAG); p.setAntiAlias(true); Paint origP = new Paint(Paint.FILTER_BITMAP_FLAG); origP.setAntiAlias(true); Paint maskp = new Paint(Paint.FILTER_BITMAP_FLAG); maskp.setAntiAlias(true); maskp.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); if (resPacName.compareTo("") != 0) { try { themeRes = pm.getResourcesForApplication(resPacName); } catch (Exception e) { } ; if (themeRes != null) { String[] backAndMaskAndFront = ThemeTools.getIconBackAndMaskResourceName(themeRes, resPacName); if (backAndMaskAndFront[0] != null) intresiconback = themeRes.getIdentifier(backAndMaskAndFront[0], "drawable", resPacName); if (backAndMaskAndFront[1] != null) intresiconmask = themeRes.getIdentifier(backAndMaskAndFront[1], "drawable", resPacName); if (backAndMaskAndFront[2] != null) intresiconfront = themeRes.getIdentifier(backAndMaskAndFront[2], "drawable", resPacName); } } BitmapFactory.Options uniformOptions = new BitmapFactory.Options(); uniformOptions.inScaled = false; uniformOptions.inDither = false; uniformOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; Canvas origCanv; Canvas canvas; scaleFactor = ThemeTools.getScaleFactor(themeRes, resPacName); Bitmap back = null; Bitmap mask = null; Bitmap front = null; Bitmap scaledBitmap = null; Bitmap scaledOrig = null; Bitmap orig = null; if (resPacName.compareTo("") != 0 && themeRes != null) { try { if (intresiconback != 0) back = BitmapFactory.decodeResource(themeRes, intresiconback, uniformOptions); } catch (Exception e) { } try { if (intresiconmask != 0) mask = BitmapFactory.decodeResource(themeRes, intresiconmask, uniformOptions); } catch (Exception e) { } try { if (intresiconfront != 0) front = BitmapFactory.decodeResource(themeRes, intresiconfront, uniformOptions); } catch (Exception e) { } } //theming vars----------------------------------------------- BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = false; options.inPreferredConfig = Bitmap.Config.RGB_565; options.inDither = true; for (int i = 0; i < listApps.size(); i++) { if (themeRes != null) { iconResource = null; intres = 0; iconResource = ThemeTools.getResourceName(themeRes, resPacName, listApps.get(i).getComponentName().toString()); if (iconResource != null) { intres = themeRes.getIdentifier(iconResource, "drawable", resPacName); } if (intres != 0) {//has single drawable for app listApps.get(i).setIconBitmap(BitmapFactory.decodeResource(themeRes, intres, uniformOptions)); } else { Drawable drawable = listApps.get(i).getIconDrawable(); if (drawable == null) { drawable = Utilities.createIconDrawable(listApps.get(i).getIconBitmap()); } orig = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(new Canvas(orig)); scaledOrig = Bitmap.createBitmap(ICONSIZE, ICONSIZE, Bitmap.Config.ARGB_8888); scaledBitmap = Bitmap.createBitmap(ICONSIZE, ICONSIZE, Bitmap.Config.ARGB_8888); canvas = new Canvas(scaledBitmap); if (back != null) { canvas.drawBitmap(back, Tools.getResizedMatrix(back, ICONSIZE, ICONSIZE), p); } origCanv = new Canvas(scaledOrig); orig = Tools.getResizedBitmap(orig, ((int) (ICONSIZE * scaleFactor)), ((int) (ICONSIZE * scaleFactor))); origCanv.drawBitmap(orig, scaledOrig.getWidth() - (orig.getWidth() / 2) - scaledOrig.getWidth() / 2, scaledOrig.getWidth() - (orig.getWidth() / 2) - scaledOrig.getWidth() / 2, origP); if (mask != null) { origCanv.drawBitmap(mask, Tools.getResizedMatrix(mask, ICONSIZE, ICONSIZE), maskp); } if (back != null) { canvas.drawBitmap(Tools.getResizedBitmap(scaledOrig, ICONSIZE, ICONSIZE), 0, 0, p); } else canvas.drawBitmap(Tools.getResizedBitmap(scaledOrig, ICONSIZE, ICONSIZE), 0, 0, p); if (front != null) canvas.drawBitmap(front, Tools.getResizedMatrix(front, ICONSIZE, ICONSIZE), p); listApps.get(i).setIconBitmap(scaledBitmap); } } } }