Example usage for android.util DisplayMetrics DENSITY_XXHIGH

List of usage examples for android.util DisplayMetrics DENSITY_XXHIGH

Introduction

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

Prototype

int DENSITY_XXHIGH

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

Click Source Link

Document

Standard quantized DPI for extra-extra-high-density screens.

Usage

From source file:Main.java

public static final float getNormalTextSize(Context context) {
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    switch (metrics.densityDpi) {
    case DisplayMetrics.DENSITY_HIGH:
        return 18;
    case DisplayMetrics.DENSITY_XHIGH:
        return 24;
    case DisplayMetrics.DENSITY_XXHIGH:
        return 32;
    case DisplayMetrics.DENSITY_XXXHIGH:
        return 48;
    default://from   www . j av a  2  s.c  om
        return 12;
    }
}

From source file:Main.java

/**
 * Gets device's display density.//from   w w  w. jav a2 s. c  om
 * @since   0.1.0
 * @param   aContext The context from which the display metrics information is retrieved.
 * @return   The density in String or an empty String if display metrics is not retrievable.
 */
public static String getScreenDpi(Context aContext) {
    DisplayMetrics metrics = aContext.getResources().getDisplayMetrics();
    switch (metrics.densityDpi) {
    case DisplayMetrics.DENSITY_LOW:
        return "ldpi";
    case DisplayMetrics.DENSITY_MEDIUM:
        return "mdpi";
    case DisplayMetrics.DENSITY_HIGH:
        return "hdpi";
    case DisplayMetrics.DENSITY_XHIGH:
        return "xhdpi";
    case DisplayMetrics.DENSITY_XXHIGH:
        return "xxhdpi";
    case DisplayMetrics.DENSITY_XXXHIGH:
        return "xxxhdpi";
    default:
        return "";
    }
}

From source file:Main.java

public static Drawable getIconFromPackageName(String packageName, Context context) {
    PackageManager pm = context.getPackageManager();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
        try {/*from  w w  w  .j  a va  2  s  .  com*/
            PackageInfo pi = pm.getPackageInfo(packageName, 0);
            Context otherAppCtx = context.createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY);

            int displayMetrics[] = { DisplayMetrics.DENSITY_XXXHIGH, DisplayMetrics.DENSITY_XXHIGH,
                    DisplayMetrics.DENSITY_XHIGH, DisplayMetrics.DENSITY_HIGH, DisplayMetrics.DENSITY_MEDIUM,
                    DisplayMetrics.DENSITY_TV };

            for (int displayMetric : displayMetrics) {
                try {
                    Drawable d = otherAppCtx.getResources().getDrawableForDensity(pi.applicationInfo.icon,
                            displayMetric);
                    if (d != null) {

                        return d;
                    }
                } catch (Resources.NotFoundException e) {
                }
            }

        } catch (Exception e) {
            // Handle Error here
        }
    }

    ApplicationInfo appInfo = null;
    try {
        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException e) {
        return null;
    }

    return appInfo.loadIcon(pm);
}

From source file:Main.java

/**
 * The screen density expressed as dots-per-inch.
 * @param density_dpi "densityDpi"/*  w w w . j a  va  2 s.co m*/
 */
public static String getDensityDPIStr(int density_dpi) {
    switch (density_dpi) {
    case DisplayMetrics.DENSITY_LOW://120
        return "DENSITY_LOW";
    case DisplayMetrics.DENSITY_MEDIUM://160
        return "DENSITY_MEDIUM/DENSITY_DEFAULT";
    //case DisplayMetrics.DENSITY_DEFAULT://160
    //    return "DENSITY_DEFAULT";
    case DisplayMetrics.DENSITY_TV://213
        return "DENSITY_TV";
    case DisplayMetrics.DENSITY_HIGH://240
        return "DENSITY_HIGH";
    case DisplayMetrics.DENSITY_280://280
        return "DENSITY_280";
    case DisplayMetrics.DENSITY_XHIGH://320
        return "DENSITY_XHIGH";
    case DisplayMetrics.DENSITY_360://360
        return "DENSITY_360";
    case DisplayMetrics.DENSITY_400://400
        return "DENSITY_400";
    case DisplayMetrics.DENSITY_420://420
        return "DENSITY_420";
    case DisplayMetrics.DENSITY_XXHIGH://480
        return "DENSITY_XXHDPI";
    case DisplayMetrics.DENSITY_560://560
        return "DENSITY_560";
    case DisplayMetrics.DENSITY_XXXHIGH://640
        return "DENSITY_XXXHDPI";
    default:
        return UNKNOWN;
    }
}

From source file:Main.java

public static String getDensity(Context ctx) {
    String densityStr = null;/*  w  w w. j a v  a  2 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: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: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;
        }/*from ww w .  j a  va2s .com*/
    }
    Log.d(LOG_TAG, "Is NOT Tablet Device");
    return false;
}

From source file:com.iangclifton.auid.appendixc.sections.VariousDemosFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.various_demos, container, false);

    final StringBuilder sb = new StringBuilder();

    // Create a String for the device physical size
    switch (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) {
    case Configuration.SCREENLAYOUT_SIZE_XLARGE:
        // Extra large (most 10" tablets)
        sb.append(getString(R.string.configuration_xlarge));
        break;// w w  w  .  j a  v  a  2s.com
    case Configuration.SCREENLAYOUT_SIZE_LARGE:
        // Large (most 7" tablets)
        sb.append(getString(R.string.configuration_large));
        break;
    case Configuration.SCREENLAYOUT_SIZE_NORMAL:
        // Normal (most phones)
        sb.append(getString(R.string.configuration_normal));
        break;
    case Configuration.SCREENLAYOUT_SIZE_SMALL:
        // Small (very uncommon)
        sb.append(getString(R.string.configuration_small));
        break;
    default:
        sb.append(getString(R.string.configuration_unknown));
        break;
    }
    sb.append('\n');

    // Create a String for the display density
    switch (getResources().getDisplayMetrics().densityDpi) {
    case DisplayMetrics.DENSITY_XXHIGH:
        // Display is around 480 pixels per inch
        sb.append(getString(R.string.density_xxhdpi));
        break;
    case DisplayMetrics.DENSITY_XHIGH:
        // Display is around 320 pixels per inch
        sb.append(getString(R.string.density_xhdpi));
        break;
    case DisplayMetrics.DENSITY_HIGH:
        // Display is around 240 pixels per inch
        sb.append(getString(R.string.density_hdpi));
        break;
    case DisplayMetrics.DENSITY_MEDIUM:
        // Display is around 160 pixels per inch
        sb.append(getString(R.string.density_mdpi));
        break;
    case DisplayMetrics.DENSITY_LOW:
        // Display is around 120 pixels per inch
        sb.append(getString(R.string.density_ldpi));
        break;
    case DisplayMetrics.DENSITY_TV:
        // Display is a 720p TV screen
        // Sometimes also used for 1280x720 7" tablets
        // Rarely should you ever specifically target this density
        sb.append(getString(R.string.density_tv));
        break;
    default:
        sb.append(getString(R.string.density_unknown));
        break;
    }
    sb.append('\n');

    // Create a String for the thread we're on
    // Obviously this method is always called on the main thread but this technique can be used anywhere.
    if (Utils.isUiThread()) {
        // UI Thread
        sb.append(getString(R.string.main_thread_true));
    } else {
        // Other Thread
        sb.append(getString(R.string.main_thread_false));
    }
    sb.append(" (Thread name: ").append(Thread.currentThread().getName()).append(')');

    // Set text
    final TextView tv = (TextView) rootView.findViewById(R.id.main_text);
    tv.setText(sb);

    return rootView;
}

From source file:io.mapsquare.osmcontributor.utils.core.ArpiInitializer.java

/**
 * Pre-compute the different PoiTypes bitmaps icons for the ArpiGL fragment and view.
 *//*from   w  w w . j  a  v  a  2 s .  c om*/
public void precomputeArpiBitmaps() {
    try {
        if (!ArpiGlInstaller.getInstance(application.getApplicationContext()).isInstalled()) {
            ArpiGlInstaller.getInstance(application.getApplicationContext()).install();

            Map<Long, PoiType> poiTypes = poiManager.loadPoiTypes();

            for (Map.Entry<Long, PoiType> entry : poiTypes.entrySet()) {
                Integer id = bitmapHandler.getIconDrawableId(entry.getValue());
                if (id != null && id > 0) {
                    Drawable d = application.getApplicationContext().getResources().getDrawableForDensity(id,
                            DisplayMetrics.DENSITY_XXHIGH);
                    int width = d.getIntrinsicWidth();
                    int height = d.getIntrinsicHeight();
                    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
                    Canvas c = new Canvas(bitmap);
                    d.setBounds(0, 0, width, height);
                    d.draw(c);

                    File dest = new File(application.getApplicationContext().getFilesDir(),
                            ArpiGlInstaller.INSTALLATION_DIR + "/" + ArpiGlInstaller.TEXTURE_ICONS_SUBDIR + "/"
                                    + entry.getValue().getIcon() + ".png");
                    dest.getParentFile().mkdirs();

                    if (dest.exists()) {
                        dest.delete();
                    }
                    dest.createNewFile();
                    OutputStream stream = new FileOutputStream(dest);
                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                    stream.close();
                    bitmap.recycle();
                }
            }
        }
    } catch (IOException | JSONException e) {
        Timber.e("Error while initializing ArpiGl library: {}", e.getMessage());
    }
}

From source file:count.ly.messaging.DeviceInfo.java

/**
 * Maps the current display density to a string constant.
 * @param context context to use to retrieve the current display metrics
 * @return a string constant representing the current display density, or the
 *         empty string if the density is unknown
 */// www.  ja v a2s. c  o m
static String getDensity(final Context context) {
    String densityStr = "";
    final int density = context.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;
}