Example usage for android.view Display getWidth

List of usage examples for android.view Display getWidth

Introduction

In this page you can find the example usage for android.view Display getWidth.

Prototype

@Deprecated
public int getWidth() 

Source Link

Usage

From source file:Main.java

@SuppressWarnings("deprecation")
private static Point getDefaultDisplaySize(Activity activity, Point size) {
    Display d = activity.getWindowManager().getDefaultDisplay();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        d.getSize(size);/*from  www . jav a2s  .c  om*/
    } else {
        size.set(d.getWidth(), d.getHeight());
    }
    return size;
}

From source file:Main.java

public static Point getWindowSize(Display defaultDisplay) {
    Point windowSize = new Point();
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {
        defaultDisplay.getSize(windowSize);
    } else {/*from  ww w. ja  va 2s.  c  om*/
        windowSize.x = defaultDisplay.getWidth();
        windowSize.y = defaultDisplay.getHeight();
    }
    return windowSize;
}

From source file:Main.java

public static void showAsPopup(Activity activity) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        return;/*from  ww  w  .j av  a2s  .co m*/
    }
    activity.requestWindowFeature(Window.FEATURE_ACTION_BAR);

    //To show activity as dialog and dim the background, you need to declare android:theme="@style/PopupTheme" on for the chosen activity on the manifest
    Window window = activity.getWindow();
    window.setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND, WindowManager.LayoutParams.FLAG_DIM_BEHIND);

    Display display = activity.getWindowManager().getDefaultDisplay();
    WindowManager.LayoutParams params = window.getAttributes();
    params.height = (int) (display.getHeight() * 0.95);
    params.width = Math.min((int) (display.getWidth() * 0.9), (int) (params.height * 0.85));
    params.gravity = Gravity.BOTTOM;
    params.alpha = 1.0f;
    params.dimAmount = 0.5f;
    window.setAttributes(params);
}

From source file:Main.java

public static Point getDisplaySize(Activity context) {
    Display display = context.getWindowManager().getDefaultDisplay();
    final Point point = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        display.getSize(point);//from w  w w  . jav a  2  s .c  o m
    } else {
        point.x = display.getWidth();
        point.y = display.getHeight();
    }
    return point;
}

From source file:Main.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static Point getScreenSize(Context mContext) {
    WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);/*from w ww  . jav a 2  s .c o m*/
        return size;
    } else {
        size.x = display.getWidth();
        size.y = display.getHeight();
        return size;
    }
}

From source file:Main.java

public static int getScreenWidth(Activity activity) {
    Display display = activity.getWindowManager().getDefaultDisplay();
    Point size = new Point();
    int width = 800;
    if (Build.VERSION.SDK_INT > 13) {
        display.getSize(size);/*from  w  ww.java 2s . c om*/
        width = size.x;
    } else {
        width = display.getWidth();
    }
    return width;
}

From source file:Main.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static int getWidth(Context context) {

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        Point size = new Point();
        display.getSize(size);/*from   w  ww  .  j av  a2s  .c  om*/
        return size.x;
    } else
        return display.getWidth();
}

From source file:Main.java

public static int[] getWindowSize(Context context) {
    final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    final Display display = wm.getDefaultDisplay();
    if (android.os.Build.VERSION.SDK_INT >= 13) {
        Point point = new Point();
        display.getSize(point);//ww w.  j  a  v a  2  s  . c o m
        return new int[] { point.x, point.y };
    } else {
        return new int[] { display.getWidth(), display.getHeight() };
    }
}

From source file:Main.java

/**
 * Gets the screen size in pixels in a backwards compatible way
 *
 * @param caller        Activity calling; needed to get access to the {@link android.view.WindowManager}
 * @return              Size in pixels of the screen, or default {@link Point} if caller is null
 *///from ww w .j av a2  s . c o m
public static Point getScreenSize(Activity caller) {
    Point size = new Point();
    if (caller != null) {
        Display display = caller.getWindowManager().getDefaultDisplay();
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {
            display.getSize(size);
        } else {
            size.set(display.getWidth(), display.getHeight());
        }
    }
    return size;
}

From source file:com.wwtv.player.utils.Utils.java

@SuppressWarnings("deprecation")
/**// w w  w. java2s. c  o  m
 * Returns the screen/display size
 */
public static Point getDisplaySize(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    return new Point(width, height);
}