Android DisplayMetrics - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android DisplayMetrics class.

This code example shows how to use the following methods:getMetrics
	 */ 
	public TapjoyDisplayMetricsUtil(Context theContext)
	{ 
		context = theContext;
		 
		metrics = new DisplayMetrics();
		WindowManager windowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
		windowManager.getDefaultDisplay().getMetrics(metrics);
		 
		configuration = context.getResources().getConfiguration();
	} 
	 
	 
	/** 
	 * Gets the screen density. 
	 * @return								Screen density in DPI. 
	 */ 
	public int getScreenDensity() 
	{ 
		return metrics.densityDpi;
8
CodeRank
This code example shows how to use the following methods:
        shadow.setWidth(1024);
        shadow.setHeight(600);
        shadow.setXdpi(183.0f);
        shadow.setYdpi(184.0f);
 
        DisplayMetrics metrics = new DisplayMetrics();
 
        display.getMetrics(metrics);
 
        assertEquals(1.5f, metrics.density, 0.05);
        assertEquals(DisplayMetrics.DENSITY_MEDIUM, metrics.densityDpi);
        assertEquals(1.6f, metrics.scaledDensity, 0.05);
        assertEquals(1024, metrics.widthPixels);
        assertEquals(600, metrics.heightPixels);
        assertEquals(183.0f, metrics.xdpi, 0.05);
        assertEquals(184.0f, metrics.ydpi, 0.05);
    } 
 
    /** 
     * The {@link android.view.Display#getOrientation()} method is deprecated, but for 
7
CodeRank
This code example shows how to use the following methods:applyDimension
@RunWith(TestRunners.WithDefaults.class) 
public class TypedValueTest { 
 
    @Test 
    public void testApplyDimensionIsWired() throws Exception { 
        DisplayMetrics metrics = new DisplayMetrics();
        metrics.density = 0.5f;
        float convertedValue = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, metrics);
        assertThat(convertedValue).isEqualTo(50f);
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getMetrics
	 * @return The corresponding display pixel value. 
	 */ 
	public int toDisplayPixels(float densityIndependentPixels)
	{ 
		// Get display metrics. 
		DisplayMetrics metrics = new DisplayMetrics();
		mActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
		 
		// Return the actual pixel value calculated from the density. 
		return (int) (densityIndependentPixels * metrics.density);
	} 
} 
8
CodeRank
This code example shows how to use the following methods:
		Float toX = new Float(args[1]); 
		Float fromY = new Float(args[2]); 
		Float toY = new Float(args[3]); 
		Integer stepCount = new Integer(args[4]); 
 
		DisplayMetrics dm = new DisplayMetrics(); 
		InstrumentationBackend.solo.getCurrentActivity().getWindowManager() 
				.getDefaultDisplay().getMetrics(dm); 
		Integer windowWidth = dm.widthPixels; 
		Integer windowHeight = dm.heightPixels; 
 
		InstrumentationBackend.solo.drag(fromX / 100 * windowWidth,  
				toX / 100 * windowWidth,  
				fromY / 100 * windowHeight,  
				toY / 100 * windowHeight,  
				stepCount); 
 
		return Result.successResult(); 
	} 
 
7
CodeRank
This code example shows how to use the following methods:
	protected static DisplayMetrics getDisplayMetrics(View parent)
	{ 
		if (metrics == null) {
			WindowManager windowManager = (WindowManager) parent.getContext().getSystemService(Context.WINDOW_SERVICE);
			Display display = windowManager.getDefaultDisplay();
			metrics = new DisplayMetrics();
			display.getMetrics(metrics);
		} 
		return metrics;
	} 
 
	protected double getScaledPixels(View parent)
	{ 
		DisplayMetrics metrics = getDisplayMetrics(parent);
		if (units == TypedValue.COMPLEX_UNIT_DIP) {
			return (metrics.density * this.value);
		} else if (units == TypedValue.COMPLEX_UNIT_SP) {
			return (metrics.scaledDensity * this.value);
		} 
		return -1; 
7
CodeRank
This code example shows how to use the following methods:getMetrics
			//enableZoning(usingSmallScreen()); 
		} 
 
		@Override 
		protected void getDPI(float[] values) {
			DisplayMetrics metrics = new DisplayMetrics();
			getWindowManager().getDefaultDisplay().getMetrics(metrics);
 
			values[0] = metrics.xdpi;
			values[1] = metrics.ydpi;
		} 
 
		@Override 
		protected void displayMessageOnOSD(String msg) {
			Log.i(LOG_TAG, "OSD: " + msg);
			Toast.makeText(ScummVMActivity.this, msg, Toast.LENGTH_LONG).show();
		} 
 
		@Override 
		protected void setWindowCaption(final String caption) {
8
CodeRank
This code example shows how to use the following methods:getMetrics
 
public class PreyUtils { 
	 
	public static String getDeviceType(Activity act){
		 
		DisplayMetrics dm = new DisplayMetrics();
		act.getWindowManager().getDefaultDisplay().getMetrics(dm);
		int width = dm.widthPixels; //320
		int height = dm.heightPixels; //480
		if (width >= 800 && height >= 480)
			return "Tablet"; 
		else 
			return "Phone"; 
	} 
	 
	public static boolean supportSMS(Context ctx){
		//Froyo or above!! 
		TelephonyManager telephonyManager1 = (TelephonyManager)ctx.getSystemService(Context.TELEPHONY_SERVICE);
        boolean isPhone = !(telephonyManager1.getPhoneType()==TelephonyManager.PHONE_TYPE_NONE);
        boolean featureTelephony = ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
8
CodeRank
This code example shows how to use the following methods:
		 if ( magneticFieldSensor == null )
			 return rv;
		 return (float[]) magneticFieldSensor.readSensor();
	 } 
 
     static public DisplayMetrics metrics = new DisplayMetrics();
 
     /** 
      * Get display DPI. 
      */ 
     public static int getDPI() { 
         return metrics.densityDpi;
     } 
 
     /** 
      * Show the soft keyboard. 
      */ 
     public static void showKeyboard() { 
         InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
         imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
7
CodeRank
This code example shows how to use the following methods:getMetrics
            super.onCreate(surfaceHolder);
            setTouchEventsEnabled(true);
            surfaceHolder.setSizeFromLayout();
            surfaceHolder.setFormat(PixelFormat.RGB_888);
 
            DisplayMetrics metrics = new DisplayMetrics();
            ((WindowManager) getApplication().getSystemService(Service.WINDOW_SERVICE))
                    .getDefaultDisplay().getMetrics(metrics);
            mDensityDPI = metrics.densityDpi;
        } 
 
        @Override 
        public void onDestroy() { 
            super.onDestroy(); 
            destroyRenderer(); 
        } 
 
        public void destroyRenderer() { 
            if (mWallpaperRS != null) {
                mWallpaperRS.stop();
8
CodeRank

Related Android DisplayMetrics Questions & Answers:

See Code Examples for Android DisplayMetrics Methods: