List of usage examples for android.content.res Resources getSystem
public static Resources getSystem()
From source file:Main.java
public static Bitmap addLabelToBitmap(Bitmap src, String label) { float densityFactor = Resources.getSystem().getDisplayMetrics().density; final float textPadding = src.getWidth() * 0.05f; Bitmap result = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); Paint textPaint = new Paint(); textPaint.setAntiAlias(true);/* w w w.j a v a 2 s . co m*/ textPaint.setTextSize(12 * densityFactor); textPaint.setColor(Color.WHITE); textPaint.setStrokeWidth(2 * densityFactor); textPaint.setShadowLayer(1 * densityFactor, 0, 0, Color.BLACK); float textWidth = textPaint.measureText(label); float scaleFactor = (src.getWidth() - textPadding * 2) / textWidth; canvas.drawBitmap(src, 0, 0, textPaint); canvas.save(); canvas.scale(scaleFactor, scaleFactor); float textPosX = (src.getWidth() / scaleFactor - textWidth) / 2; float textPosY = (src.getHeight() - textPadding) / scaleFactor; canvas.drawText(label, textPosX, textPosY, textPaint); canvas.restore(); return result; }
From source file:Main.java
public static Drawable resizeToIcon(final Bitmap bitmap, final int width, final int height) { final Bitmap b = Bitmap.createScaledBitmap(bitmap, width, height, true); final Drawable d = new BitmapDrawable(Resources.getSystem(), b); return d;/*from ww w . jav a2 s .c o m*/ }
From source file:Main.java
private static DisplayMetrics getDisplayMetrics() { return Resources.getSystem().getDisplayMetrics(); }
From source file:Main.java
public static Bitmap scaleBitmapForDevice(Bitmap bitmap) { if (bitmap == null) { return null; }//from w w w.j a v a2 s .c o m float density = Resources.getSystem().getDisplayMetrics().density; int newWidth = (int) (bitmap.getWidth() * density); int newHeight = (int) (bitmap.getHeight() * density); /* Bitmap resizeBitmap = Bitmap.createScaledBitmap(bitmap, width, height, true); */ /** * http://stackoverflow.com/questions/4821488/bad-image-quality-after-resizing-scaling-bitmap#7468636 */ Bitmap scaledBitmap = Bitmap.createBitmap(newWidth, newHeight, Config.ARGB_8888); float ratioX = newWidth / (float) bitmap.getWidth(); float ratioY = newHeight / (float) bitmap.getHeight(); float middleX = newWidth / 2.0f; float middleY = newHeight / 2.0f; Matrix scaleMatrix = new Matrix(); scaleMatrix.setScale(ratioX, ratioY, middleX, middleY); Canvas canvas = new Canvas(scaledBitmap); canvas.setMatrix(scaleMatrix); canvas.drawBitmap(bitmap, middleX - bitmap.getWidth() / 2, middleY - bitmap.getHeight() / 2, new Paint(Paint.FILTER_BITMAP_FLAG)); bitmap.recycle(); return scaledBitmap; }
From source file:Main.java
public static void updateApplicationResourceLocale(Context context, Locale locale) { Resources resources = context.getResources(); Configuration configuration = resources.getConfiguration(); if (!configuration.locale.equals(locale)) { android.util.DisplayMetrics displaymetrics = resources.getDisplayMetrics(); configuration.locale = locale;/*from w w w .jav a 2 s .co m*/ resources.updateConfiguration(configuration, displaymetrics); Resources.getSystem().updateConfiguration(configuration, displaymetrics); } }
From source file:Main.java
public static int sp2px(float value, Context context) { Resources r;//ww w. ja v a 2 s. co m if (context == null) { r = Resources.getSystem(); } else { r = context.getResources(); } float spvalue = value * r.getDisplayMetrics().scaledDensity; return (int) (spvalue + 0.5f); }
From source file:Main.java
public static float pxToDp(int px) { return px / Resources.getSystem().getDisplayMetrics().density; }
From source file:Main.java
public static int dip2px(float dipValue) { final float scale = Resources.getSystem().getDisplayMetrics().density; return (int) (dipValue * scale + 0.5f); }
From source file:Main.java
public static boolean isChineseLanguage() { return Resources.getSystem().getConfiguration().locale.getLanguage() .startsWith(Locale.CHINESE.getLanguage()); }
From source file:Main.java
public static void setLocale(Context paramContext, Locale paramLocale) { Resources localResources = paramContext.getResources(); Configuration localConfiguration = localResources.getConfiguration(); if (localConfiguration.locale.equals(paramLocale)) { } else {/*w w w .ja va 2 s . c o m*/ DisplayMetrics localDisplayMetrics = localResources.getDisplayMetrics(); localConfiguration.locale = paramLocale; localResources.updateConfiguration(localConfiguration, localDisplayMetrics); Resources.getSystem().updateConfiguration(localConfiguration, localDisplayMetrics); } }