List of utility methods to do Context Get
DisplayMetrics | getDefaultDisplayMetrics( @Nonnull Context context) Retrieves the DisplayMetrics for the device's default display. WindowManager manager = ((WindowManager) context .getSystemService(Context.WINDOW_SERVICE)); DisplayMetrics metrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(metrics); return metrics; |
DisplayMetrics | getDefaultDisplayMetrics( @Nonnull Context context) Retrieves the DisplayMetrics for the device's default display. WindowManager manager = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); final DisplayMetrics metrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(metrics); return metrics; |
float | getDensity(Context context) get Density final DisplayMetrics dm = context.getResources() .getDisplayMetrics(); return dm.density; |
float | getDensity(Context context) get Density float scale = context.getResources().getDisplayMetrics().density; return scale; |
int | getDensityDimen(Context context, int dimen) get Density Dimen final DisplayMetrics dm = context.getResources() .getDisplayMetrics(); return ((int) (dimen * dm.density)); |
File | getDiskCacheDir(Context context, String uniqueName) get Disk Cache Dir final String cachePath = Environment.MEDIA_MOUNTED .equals(Environment.getExternalStorageState()) ? getExternalCacheDir( context).getPath() : context.getCacheDir().getPath(); return new File(cachePath + File.separator + uniqueName); |
DisplayMetrics | getDisplayMetrics(Context context) get Display Metrics Resources mResources; if (context == null) { mResources = Resources.getSystem(); } else { mResources = context.getResources(); DisplayMetrics mDisplayMetrics = mResources.getDisplayMetrics(); return mDisplayMetrics; ... |
byte[] | getDisplayPhoto(Context context, long photoFileId) get Display Photo Uri displayPhotoUri = ContentUris.withAppendedId( DisplayPhoto.CONTENT_URI, photoFileId); AssetFileDescriptor fd = null; byte[] photo = null; try { fd = context.getContentResolver().openAssetFileDescriptor( displayPhotoUri, "r"); long len = fd.getLength(); ... |
float | getDpiToPix(Context ctx) Converts 1 dip (device independent pixel) into its equivalent physical pixels return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1,
ctx.getResources().getDisplayMetrics());
|
SharedPreferences.Editor | getEditor( Context ctx) get Editor return getDefaultSharedPreferences(ctx).edit();
|