Example usage for android.util DisplayMetrics DENSITY_HIGH

List of usage examples for android.util DisplayMetrics DENSITY_HIGH

Introduction

In this page you can find the example usage for android.util DisplayMetrics DENSITY_HIGH.

Prototype

int DENSITY_HIGH

To view the source code for android.util DisplayMetrics DENSITY_HIGH.

Click Source Link

Document

Standard quantized DPI for high-density screens.

Usage

From source file:Main.java

public static String getDensity(Context ctx) {
    String densityStr = null;/*from ww w .j  av  a2  s. c o  m*/
    final int density = ctx.getResources().getDisplayMetrics().densityDpi;
    switch (density) {
    case DisplayMetrics.DENSITY_LOW:
        densityStr = "LDPI";
        break;
    case DisplayMetrics.DENSITY_MEDIUM:
        densityStr = "MDPI";
        break;
    case DisplayMetrics.DENSITY_TV:
        densityStr = "TVDPI";
        break;
    case DisplayMetrics.DENSITY_HIGH:
        densityStr = "HDPI";
        break;
    case DisplayMetrics.DENSITY_XHIGH:
        densityStr = "XHDPI";
        break;
    case DisplayMetrics.DENSITY_400:
        densityStr = "XMHDPI";
        break;
    case DisplayMetrics.DENSITY_XXHIGH:
        densityStr = "XXHDPI";
        break;
    case DisplayMetrics.DENSITY_XXXHIGH:
        densityStr = "XXXHDPI";
        break;
    }
    return densityStr;
}

From source file:Main.java

/**
 * Get the required size of the favicon, depending on current screen density.
 * @param activity The current activity.
 * @return The size of the favicon, in pixels.
 *///from www  .j av  a 2s  . co m
public static int getFaviconSize(Activity activity) {
    if (mFaviconSize == -1) {
        DisplayMetrics metrics = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

        switch (metrics.densityDpi) {
        case DisplayMetrics.DENSITY_LOW:
            mFaviconSize = 12;
            break;
        case DisplayMetrics.DENSITY_MEDIUM:
            mFaviconSize = 24;
            break;
        case DisplayMetrics.DENSITY_HIGH:
            mFaviconSize = 32;
            break;
        default:
            mFaviconSize = 24;
        }
    }

    return mFaviconSize;
}

From source file:Main.java

/**
 * Get the required size of the favicon, depending on current screen density.
 * @param activity The current activity.
 * @return The size of the favicon, in pixels.
 *///w ww  .jav  a 2 s. c  om
public static int getFaviconSizeForBookmarks(Activity activity) {
    if (mFaviconSizeForBookmarks == -1) {
        DisplayMetrics metrics = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

        switch (metrics.densityDpi) {
        case DisplayMetrics.DENSITY_LOW:
            mFaviconSizeForBookmarks = 12;
            break;
        case DisplayMetrics.DENSITY_MEDIUM:
            mFaviconSizeForBookmarks = 16;
            break;
        case DisplayMetrics.DENSITY_HIGH:
            mFaviconSizeForBookmarks = 24;
            break;
        default:
            mFaviconSizeForBookmarks = 16;
        }
    }

    return mFaviconSizeForBookmarks;
}

From source file:Main.java

/**
 * Checks if the device is a tablet or a phone
 *
 * @param activityContext//from  ww w . j av a 2  s  .c  o m
 *          The Activity Context.
 * @return Returns true if the device is a Tablet
 */
public static boolean isTabletDevice(Context activityContext) {
    // Verifies if the Generalized Size of the device is XLARGE to be
    // considered a Tablet
    boolean xlarge = ((activityContext.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE);
    // If XLarge, checks if the Generalized Density is at least MDPI
    // (160dpi)
    if (xlarge) {
        DisplayMetrics metrics = new DisplayMetrics();
        Activity activity = (Activity) activityContext;
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
        // MDPI=160, DEFAULT=160, DENSITY_HIGH=240, DENSITY_MEDIUM=160,
        // DENSITY_TV=213, DENSITY_XHIGH=320
        if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT
                || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH
                || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM
                || metrics.densityDpi == DisplayMetrics.DENSITY_TV
                || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) {
            // Yes, this is a tablet!
            return true;
        }
    }
    // No, this is not a tablet!
    return false;
}

From source file:com.mruddy.devdataviewer.DevDataListFragment.java

@SuppressLint("InlinedApi")
private static void initMaps() {
    DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_LOW, "LDPI");
    DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_MEDIUM, "MDPI");
    DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_HIGH, "HDPI");
    DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_XHIGH, "XHDPI");
    DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_XXHIGH, "XXHDPI");
    DevDataListFragment.DENSITY_BUCKETS.append(DisplayMetrics.DENSITY_XXXHIGH, "XXXHDPI");
    DevDataListFragment.ROTATION.append(Surface.ROTATION_0, "0");
    DevDataListFragment.ROTATION.append(Surface.ROTATION_90, "90");
    DevDataListFragment.ROTATION.append(Surface.ROTATION_180, "180");
    DevDataListFragment.ROTATION.append(Surface.ROTATION_270, "270");
    DevDataListFragment.ORIENTATION.append(Configuration.ORIENTATION_UNDEFINED, "undefined");
    DevDataListFragment.ORIENTATION.append(Configuration.ORIENTATION_PORTRAIT, "portrait");
    DevDataListFragment.ORIENTATION.append(Configuration.ORIENTATION_LANDSCAPE, "landscape");
    DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_UNDEFINED, "undefined");
    DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_SMALL, "small");
    DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_NORMAL, "normal");
    DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_LARGE, "large");
    DevDataListFragment.SCREEN_SIZE_BUCKETS.append(Configuration.SCREENLAYOUT_SIZE_XLARGE, "xlarge");
}

From source file:Main.java

/**
 * Reports to the log information about the device's display. This information includes
 * the width and height, and density (low, medium, high). 
 * @param activity The Activity to report on.
 *//*from  w  ww .  j a va  2  s  .c  o m*/
public static void reportDisplayInformation(Activity activity) {

    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

    int displayWidth = metrics.widthPixels;
    int displayHeight = metrics.heightPixels;

    String density = "unknown";
    switch (metrics.densityDpi) {
    case DisplayMetrics.DENSITY_LOW:
        density = "Low";
        break;
    case DisplayMetrics.DENSITY_MEDIUM:
        density = "Medium";
        break;
    case DisplayMetrics.DENSITY_HIGH:
        density = "High";
        break;
    }

    Log.i(TAG, "Display is " + displayWidth + "x" + displayHeight + ", Density: " + density);

}

From source file:Main.java

public static void getDisplayDpi(Context ctx) {
    DisplayMetrics dm = new DisplayMetrics();
    WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(dm);
    double x = Math.pow(dm.widthPixels / dm.xdpi, 2);
    double y = Math.pow(dm.heightPixels / dm.ydpi, 2);
    double screenInches = Math.sqrt(x + y);
    int screenInch = (int) Math.round(screenInches);
    Log.d("screeninch", String.valueOf(screenInch));
    int dapi = dm.densityDpi;
    Log.d("dapi", String.valueOf(dapi));
    try {//w w  w. ja v a  2  s.  co  m
        switch (dm.densityDpi) {

        case DisplayMetrics.DENSITY_LOW:
            UI_DENSITY = 120;
            if (screenInch <= 7) {
                UI_SIZE = 4;

            } else {
                UI_SIZE = 10;
            }
            break;
        case DisplayMetrics.DENSITY_MEDIUM:
            UI_DENSITY = 160;
            if (screenInch <= 7) {
                UI_SIZE = 4;
            } else {
                UI_SIZE = 10;
            }
            break;
        case DisplayMetrics.DENSITY_HIGH:
            UI_DENSITY = 240;
            if (screenInch <= 7) {
                UI_SIZE = 4;
            } else {
                UI_SIZE = 10;
            }
            break;

        default:
            break;
        }
    } catch (Exception e) {
        // Caught exception here
    }
}

From source file:ch.rts.cordova.is.tablet.IsTablet.java

private boolean isTabletDevice(Context applicationContext) {
    boolean device_large = ((applicationContext.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE);

    if (device_large) {
        DisplayMetrics metrics = new DisplayMetrics();
        Activity activity = this.cordova.getActivity();
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

        if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT
                || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH
                || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM
                || metrics.densityDpi == DisplayMetrics.DENSITY_TV
                || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) {
            Log.d(LOG_TAG, "Is Tablet Device");
            return true;
        }/* w  ww. j  av a  2s .  co m*/
    }
    Log.d(LOG_TAG, "Is NOT Tablet Device");
    return false;
}

From source file:uk.co.workingedge.phonegap.plugin.IsTablet.java

private boolean isTabletDevice(Context applicationContext) {
    boolean device_large = ((applicationContext.getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE);

    if (device_large) {
        DisplayMetrics metrics = new DisplayMetrics();
        Activity activity = this.cordova.getActivity();
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

        if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT
                || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH
                || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM
                || metrics.densityDpi == DisplayMetrics.DENSITY_TV
                || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH
                || metrics.densityDpi == DisplayMetrics.DENSITY_XXHIGH) {
            Log.d(LOG_TAG, "Is Tablet Device");
            return true;
        }//www.  j av a2  s .  c  o m
    }
    Log.d(LOG_TAG, "Is NOT Tablet Device");
    return false;
}

From source file:transponders.transmob.TutorialFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout containing a title and body text.
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.tutorial_fragment, container, false);

    Button button = (Button) rootView.findViewById(R.id.finish_tut_button);

    int density = getResources().getDisplayMetrics().densityDpi;
    if (density <= DisplayMetrics.DENSITY_HIGH) {
        button.setMinimumHeight(60);//from  ww w  .ja va  2 s.  c  om
    }

    ImageView previousArrow = (ImageView) rootView.findViewById(R.id.previous_arrow);
    previousArrow.setVisibility(View.INVISIBLE);
    previousArrow.setOnClickListener(this);

    ImageView nextArrow = (ImageView) rootView.findViewById(R.id.next_arrow);
    nextArrow.setOnClickListener(this);

    // Set the title view to show the page number.
    ((TextView) rootView.findViewById(R.id.tutorial_title))
            .setText(getString(R.string.title_template_step, mPageNumber + 1));

    ImageView tutorialImage = (ImageView) rootView.findViewById(R.id.tutorial_image);

    switch (mPageNumber + 1) {
    case 1:
        break;
    case 2:
        tutorialImage.setImageResource(R.drawable.tut3);
        break;
    case 3:
        tutorialImage.setImageResource(R.drawable.tut4);
        break;
    case 4:
        tutorialImage.setImageResource(R.drawable.tut5);
        break;
    case 5:
        tutorialImage.setImageResource(R.drawable.tut1);
        break;
    default:
        break;
    }

    if (mPageNumber + 1 > 1) {
        previousArrow.setVisibility(View.VISIBLE);
    }

    if (mPageNumber + 1 == NearbyStops.NUM_PAGES) {
        button.setVisibility(View.VISIBLE);
        nextArrow.setVisibility(View.INVISIBLE);
        button.setOnClickListener(this);
    }

    return rootView;
}