Display getWidth - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Display getWidth method.

This code example shows how to use the following methods:getDisplayId, getHeight, getMetrics, getOrientation, getPixelFormat
        return result.toString();
    } 
 
    private static Object collectDisplayData(Display display) {
        final DisplayMetrics metrics = new DisplayMetrics();
        display.getMetrics(metrics);
 
        final StringBuilder result = new StringBuilder();
 
        result.append(collectCurrentSizeRange(display));
        result.append(collectFlags(display));
        result.append(display.getDisplayId()).append(".height=").append(display.getHeight()).append('\n');
        result.append(collectMetrics(display, "getMetrics"));
        result.append(collectName(display));
        result.append(display.getDisplayId()).append(".orientation=").append(display.getOrientation()).append('\n');
        result.append(display.getDisplayId()).append(".pixelFormat=").append(display.getPixelFormat()).append('\n');
        result.append(collectMetrics(display, "getRealMetrics"));
        result.append(collectSize(display, "getRealSize"));
        result.append(collectRectSize(display));
        result.append(display.getDisplayId()).append(".refreshRate=").append(display.getRefreshRate()).append('\n');

9
CodeRank
This code example shows how to use the following methods:getHeight, getWidth
	 
	private void initEnv(Context context) {
		// 获得屏幕大小 
		WindowManager windowManager = ((Activity)context).getWindowManager();
		Display display = windowManager.getDefaultDisplay();
		DISPLAY_WINDOW_WIDTH = display.getWidth();
		DISPLAY_WINDOW_HEIGHT = display.getHeight();
		 
		SLIDE_MIN_DISTANCE_X = (int)(DISPLAY_WINDOW_WIDTH * FACTOR_PORTRAIT);
		SLIDE_MAX_DISTANCE_Y = (int)(DISPLAY_WINDOW_HEIGHT * FACTOR_LANDSCAPE);
		SLIDE_MAX_DISTANCE_Y = 120;
		//orientation = context.getResources().getConfiguration().orientation; 
	} 
	 
	@Override 
	public boolean onDown(MotionEvent e) {
		return false; 
	} 
 
	@Override 
7
CodeRank
This code example shows how to use the following methods:getHeight, getWidth
 
	private void initEnv(Context context) {
		// 获得屏幕大小 
		WindowManager windowManager = ((Activity)context).getWindowManager();
		Display display = windowManager.getDefaultDisplay();
		DISPLAY_WINDOW_WIDTH = display.getWidth();
		DISPLAY_WINDOW_HEIGHT = display.getHeight();
 
		SLIDE_MIN_DISTANCE_X = (int)(DISPLAY_WINDOW_WIDTH * FACTOR_PORTRAIT);
		SLIDE_MAX_DISTANCE_Y = (int)(DISPLAY_WINDOW_HEIGHT * FACTOR_LANDSCAPE);
		//orientation = context.getResources().getConfiguration().orientation; 
	} 
 
	@Override 
	public boolean onDown(MotionEvent e) {
		return false; 
	} 
 
	@Override 
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
7
CodeRank
This code example shows how to use the following methods:getHeight, getWidth
 
	private void initEnv(Context context) {
		// 获得屏幕大小 
		WindowManager windowManager = ((Activity)context).getWindowManager();
		Display display = windowManager.getDefaultDisplay();
		DISPLAY_WINDOW_WIDTH = display.getWidth();
		DISPLAY_WINDOW_HEIGHT = display.getHeight();
 
		SLIDE_MIN_DISTANCE_X = (int)(DISPLAY_WINDOW_WIDTH * FACTOR_PORTRAIT);
		SLIDE_MAX_DISTANCE_Y = (int)(DISPLAY_WINDOW_HEIGHT * FACTOR_LANDSCAPE);
		//orientation = context.getResources().getConfiguration().orientation; 
	} 
 
	@Override 
	public boolean onDown(MotionEvent e) {
		return false; 
	} 
 
	@Override 
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
7
CodeRank
This code example shows how to use the following methods:getHeight, getWidth
This code example shows how to use the following methods:getWidth
	@SuppressWarnings("deprecation") 
	public static int getScreenWidth(Context context) {
		WindowManager wm = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		Display display = wm.getDefaultDisplay();
		return display.getWidth();
	} 
 
	@SuppressWarnings("deprecation") 
	public static int getScreenHeight(Context context) {
		WindowManager wm = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		Display display = wm.getDefaultDisplay();
		return display.getHeight();
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:getHeight, getMetrics, getOrientation, getPixelFormat, getRefreshRate
        DebugUtils2.d("", "displayCheck() Start"); 
        String retInfo = "";
        //ディスプレイ情報 
        WindowManager wm = (WindowManager) act.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        Log.i(className, "width="+ String.valueOf(display.getWidth()));
        retInfo = retInfo.concat("width="+ String.valueOf(display.getWidth()) + BR);  
        Log.i(className, "height="+ String.valueOf(display.getHeight()));
        retInfo = retInfo.concat("height="+ String.valueOf(display.getHeight()) + BR);  
        Log.i(className, "orientation="+ String.valueOf(display.getOrientation()));
        retInfo = retInfo.concat("orientation="+ String.valueOf(display.getOrientation()) + BR);  
        Log.i(className, "refreshRate="+ String.valueOf(display.getRefreshRate()));
        retInfo = retInfo.concat("refreshRate="+ String.valueOf(display.getRefreshRate()) + BR);  
        Log.i(className, "pixelFormat="+ String.valueOf(display.getPixelFormat()));
        retInfo = retInfo.concat("pixelFormat="+ String.valueOf(display.getPixelFormat()) + BR);  
        retInfo = retInfo.concat(BR);  
 
        DisplayMetrics metrics = new DisplayMetrics(); 
        display.getMetrics(metrics);  
        Log.i(className, "density=" + metrics.density);

6
CodeRank
This code example shows how to use the following methods:getHeight, getWidth
   } 
 
   private static QuranScreenInfo initialize(Activity activity){
      WindowManager w = activity.getWindowManager();
      Display d = w.getDefaultDisplay();
      return new QuranScreenInfo(d.getWidth(), d.getHeight());
   } 
 
	public static void initialize(int width, int height){
		instance = new QuranScreenInfo(width, height);
	} 
 
	public int getHeight(){ return this.height; }
 
	public String getWidthParam(){
		return "_" + getWidthParamNoUnderScore(); 
	} 
	 
	public String getWidthParamNoUnderScore(){
		if (this.max_width <= 320) return "320";
7
CodeRank
This code example shows how to use the following methods:getHeight, getMetrics, getOrientation, getPixelFormat, getRefreshRate
        // Screen Size classification 
		mSizeClass = mConfig.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
 
		// Usable Screen dimensions 
		try { 
			Method getSizeMethod = mDisplay.getClass().getMethod("getSize", Point.class);
			Point pt = new Point();
			getSizeMethod.invoke( mDisplay, pt );
			widthPx = pt.x;
			heightPx = pt.y;
		} catch (Exception ignore) {
			// Use older APIs 
			widthPx = mDisplay.getWidth();
			heightPx = mDisplay.getHeight();
		} 
		 
		// Total (real) screen dimensions (as of Android 4.2, API 17) 
		realWidthPx = UNSUPPORTED;
		realHeightPx = UNSUPPORTED;
		if ( Build.VERSION.SDK_INT >= 17 ) {

6
CodeRank
This code example shows how to use the following methods:getHeight, getOrientation, getWidth
     * Calculate Dimensions 
     *  
     *********************************/ 
    private void calcViewWidths(Display display){
		 
		if(display.getOrientation() == 0){
			viewWidth = (int) Math.floor(
				display.getWidth() * 
				NAVIGATOR_SCREEN_FRACTION
				); 
		 
			viewWidthNormal = (int) Math.floor(
				display.getWidth() * 
				(1-NAVIGATOR_SCREEN_FRACTION)
				); 
			viewWidthBig = (int) Math.min(
				display.getWidth(),
				display.getHeight()
				); 
		}else{     

6
CodeRank

Related Display getWidth Questions & Answers:

Other Display getWidth Examples

24:	    super.onCreate(savedInstanceState);
25:	    setContentView(R.layout.target);
26:	    width = getWindowManager().getDefaultDisplay().getWidth();
27:	    height = getWindowManager().getDefaultDisplay().getHeight();
28:	    randon = new Random();

Read More

getWidth Method Overview
This method was deprecated in API level 13. Use getSize(Point) instead.
See Code Examples for other Android Display Methods: