Search in sources :

Example 71 with DisplayMetrics

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;
}
Also used : Resources(android.content.res.Resources) DisplayMetrics(android.util.DisplayMetrics)

Example 72 with DisplayMetrics

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;
    }
}
Also used : File(java.io.File) DisplayMetrics(android.util.DisplayMetrics)

Example 73 with DisplayMetrics

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;
        }
    }
}
Also used : Activity(android.app.Activity) DisplayMetrics(android.util.DisplayMetrics) Display(android.view.Display)

Example 74 with DisplayMetrics

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;
}
Also used : OAuthActivity(org.qii.weiciyuan.ui.login.OAuthActivity) SSOActivity(org.qii.weiciyuan.ui.login.SSOActivity) AccountActivity(org.qii.weiciyuan.ui.login.AccountActivity) FragmentActivity(android.support.v4.app.FragmentActivity) BlackMagicActivity(org.qii.weiciyuan.ui.blackmagic.BlackMagicActivity) Activity(android.app.Activity) DisplayMetrics(android.util.DisplayMetrics) Display(android.view.Display)

Example 75 with DisplayMetrics

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;
}
Also used : OAuthActivity(org.qii.weiciyuan.ui.login.OAuthActivity) SSOActivity(org.qii.weiciyuan.ui.login.SSOActivity) AccountActivity(org.qii.weiciyuan.ui.login.AccountActivity) FragmentActivity(android.support.v4.app.FragmentActivity) BlackMagicActivity(org.qii.weiciyuan.ui.blackmagic.BlackMagicActivity) Activity(android.app.Activity) DisplayMetrics(android.util.DisplayMetrics) Display(android.view.Display)

Aggregations

DisplayMetrics (android.util.DisplayMetrics)772 WindowManager (android.view.WindowManager)107 Resources (android.content.res.Resources)99 Display (android.view.Display)78 Configuration (android.content.res.Configuration)61 Point (android.graphics.Point)57 View (android.view.View)52 SuppressLint (android.annotation.SuppressLint)47 Bitmap (android.graphics.Bitmap)42 Paint (android.graphics.Paint)42 Activity (android.app.Activity)32 ImageView (android.widget.ImageView)27 AssetManager (android.content.res.AssetManager)25 TypedArray (android.content.res.TypedArray)25 Context (android.content.Context)23 TypedValue (android.util.TypedValue)23 ViewGroup (android.view.ViewGroup)23 TextView (android.widget.TextView)22 Intent (android.content.Intent)21 RelativeLayout (android.widget.RelativeLayout)20