use of android.util.DisplayMetrics in project JamsMusicPlayer by psaravan.
the class Common method convertDpToPixels.
/**
* Converts dp unit to equivalent pixels, depending on device density.
*
* @param dp A value in dp (density independent pixels) unit. Which we need to convert into pixels
* @param context Context to get resources and device specific display metrics
* @return A float value to represent px equivalent to dp depending on device density
*/
public float convertDpToPixels(float dp, Context context) {
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
float px = dp * (metrics.densityDpi / 160f);
return px;
}
use of android.util.DisplayMetrics in project weiciyuan by qii.
the class ImageUtility method getMiddlePictureInBrowserMSGActivity.
public static Bitmap getMiddlePictureInBrowserMSGActivity(String url, FileLocationMethod method, FileDownloaderHttpHelper.DownloadListener downloadListener) {
try {
String filePath = FileManager.getFilePathFromUrl(url, method);
File file = new File(filePath);
if (!file.exists() && !SettingUtility.isEnablePic()) {
return null;
}
if (!isThisBitmapCanRead(filePath)) {
getBitmapFromNetWork(url, filePath, downloadListener);
}
file = new File(filePath);
if (file.exists()) {
DisplayMetrics displayMetrics = GlobalContext.getInstance().getDisplayMetrics();
return decodeBitmapFromSDCard(filePath, displayMetrics.widthPixels, 900);
}
return null;
} catch (OutOfMemoryError ignored) {
return null;
}
}
use of android.util.DisplayMetrics in project weiciyuan by qii.
the class GlobalContext method getDisplayMetrics.
public DisplayMetrics getDisplayMetrics() {
if (displayMetrics != null) {
return displayMetrics;
} else {
Activity a = getActivity();
if (a != null) {
Display display = getActivity().getWindowManager().getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
this.displayMetrics = metrics;
return metrics;
} else {
//default screen is 800x480
DisplayMetrics metrics = new DisplayMetrics();
metrics.widthPixels = 480;
metrics.heightPixels = 800;
return metrics;
}
}
}
use of android.util.DisplayMetrics in project weiciyuan by qii.
the class Utility method getScreenWidth.
public static int getScreenWidth() {
Activity activity = GlobalContext.getInstance().getActivity();
if (activity != null) {
Display display = activity.getWindowManager().getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
return metrics.widthPixels;
}
return 480;
}
use of android.util.DisplayMetrics in project weiciyuan by qii.
the class Utility method getScreenHeight.
public static int getScreenHeight() {
Activity activity = GlobalContext.getInstance().getActivity();
if (activity != null) {
Display display = activity.getWindowManager().getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
return metrics.heightPixels;
}
return 800;
}
Aggregations