Example usage for android.content Context WINDOW_SERVICE

List of usage examples for android.content Context WINDOW_SERVICE

Introduction

In this page you can find the example usage for android.content Context WINDOW_SERVICE.

Prototype

String WINDOW_SERVICE

To view the source code for android.content Context WINDOW_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.view.WindowManager for accessing the system's window manager.

Usage

From source file:com.bobomee.android.common.util.ScreenUtil.java

/**
 * get the height of screen *//  ww  w  .  j a v  a 2  s .c o  m
 */
public static int getScreenH(Context ctx) {
    int h = 0;
    if (Build.VERSION.SDK_INT > 13) {
        Point p = new Point();
        ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getSize(p);
        h = p.y;
    } else {
        h = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getHeight();
    }
    return h;
}

From source file:com.pickr.tasks.PhotoLoader.java

@Override
protected Bitmap doInBackground() {
    try {//w ww. j  a  v a  2 s .  c o m
        WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();

        int resolution = display.getWidth() * display.getHeight();

        Flickr flickr = FlickrHandler.getFlickr();
        List<PhotoSize> sizes = flickr.getPhotosService().getSizes(mPhoto);

        return loadBitmap(PhotoSizeWeight.getOptimalPhotoSize(sizes, resolution), display);

    } catch (Throwable ex) {
        ex.printStackTrace();
        LOGGER.e("Error loading photo", ex);
    }
    return null;
}

From source file:com.example.michaelg.myapplication.Item.discreteseekbar.internal.PopupIndicator.java

public PopupIndicator(Context context, AttributeSet attrs, int defStyleAttr, String maxValue, int thumbSize,
        int separation) {
    mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    mPopupView = new Floater(context, attrs, defStyleAttr, maxValue, thumbSize, separation);
}

From source file:com.tencent.wetest.common.util.DeviceUtil.java

/**
 * ??//from   www.  j ava2s .  co  m
 * @param cx 
 * @return ? ( width x height )
 */

public static String getDisplayMetrics(Context cx) {

    WindowManager mWindowManager = (WindowManager) cx.getSystemService(Context.WINDOW_SERVICE);
    Display display = mWindowManager.getDefaultDisplay();
    DisplayMetrics metric = new DisplayMetrics();

    Point size = new Point();

    String str = "";

    try {

        if (Build.VERSION.SDK_INT >= 11) {

            display.getRealSize(size);

            str += String.valueOf(size.x) + " x " + String.valueOf(size.y);

        } else {

            Method method = Class.forName("android.view.Display").getMethod("getRealMetrics",
                    DisplayMetrics.class);
            method.invoke(display, metric);

            str += String.valueOf(metric.widthPixels) + " x " + String.valueOf(metric.heightPixels);

        }

    } catch (Exception e) {

        display.getMetrics(metric);
        str += String.valueOf(metric.widthPixels) + " x " + String.valueOf(metric.heightPixels);
        Logger.error("getDeviceRealMetric Exception : " + e.toString());

    }

    return str;

}

From source file:ly.count.android.api.DeviceInfoTests.java

public void testGetResolution_getWindowManagerReturnsNull() {
    final Context mockContext = mock(Context.class);
    when(mockContext.getSystemService(Context.WINDOW_SERVICE)).thenReturn(null);
    assertEquals("", DeviceInfo.getResolution(mockContext));
}

From source file:com.devbrackets.android.exomedia.ui.animation.BottomViewHideShowAnimation.java

private int getHideShowDelta(View view) {
    DisplayMetrics displayMetrics = new DisplayMetrics();
    Display display = ((WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay();//from  w ww  .jav a  2s .  co m
    display.getMetrics(displayMetrics);

    int screenHeight = displayMetrics.heightPixels;
    return screenHeight - view.getTop();
}

From source file:com.example.snowball.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTitle = mDrawerTitle = getTitle();/*from  w ww  .  ja v a 2 s.c om*/
    mPlanetTitles = getResources().getStringArray(R.array.menu_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    WindowManager manager = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics dm = new DisplayMetrics();
    manager.getDefaultDisplay().getMetrics(dm);
    width = dm.widthPixels;
    height = dm.heightPixels;
    // set a custom shadow that overlays the main content when the drawer
    //       opens
    //      mDrawerLayout.setDrawerShadow(R.drawable.nav_icon_menu,
    //            GravityCompat.START);
    //      mDrawerLayout.setContentDescription("");
    // set up the drawer's list view with items and click listener
    MyListAdapter myAdapter = new MyListAdapter(this, mPlanetTitles);
    mDrawerList.setAdapter(myAdapter);
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.nav_icon_menu, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            actionStyle(menuitem);
            invalidateOptionsMenu(); // creates call to
            // onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            getActionBar().setNavigationMode(0);
            invalidateOptionsMenu(); // creates call to
            // onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        menuitem = 1;
        selectItem(1);
        actionStyle(1);
    }
}

From source file:com.orange.labs.sdk.RestUtils.java

public RestUtils(Context context) {
    // Create Volley Request Queue thanks to context
    mRequestQueue = Volley.newRequestQueue(context);

    // Fix maxWidth & maxHeight of screen
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);/*w ww. jav a2 s  . c  o m*/
    maxWidth = size.x;
    maxHeight = size.y;
}

From source file:io.selendroid.server.model.internal.execute_native.IsElementDisplayedInViewport.java

@SuppressWarnings("deprecation")
public boolean isDisplayedOnViewport(View view) {
    int coordinates[] = { -1, -1 };
    int width = 0, height = 0;

    view.getLocationOnScreen(coordinates);
    if (coordinates[0] + view.getWidth() < 0)
        return false;
    if (coordinates[1] + view.getHeight() < 0)
        return false;

    if (width == 0 || height == 0) {
        if (instrumentation.getContext() == null)
            return false;
        Display display = ((WindowManager) instrumentation.getContext()
                .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        try {/* w ww .  j a  va  2 s.  c  o  m*/
            android.graphics.Point screenSize = new android.graphics.Point();
            display.getSize(screenSize);
            width = screenSize.x;
            height = screenSize.y;
        } catch (NoSuchMethodError e) {
            width = display.getWidth();
            height = display.getHeight();
        }
    }

    if (coordinates[0] > width)
        return false;
    if (coordinates[1] > height)
        return false;

    return true;
}

From source file:com.dm.material.dashboard.candybar.helpers.ViewHelper.java

private static Point getAppUsableScreenSize(@NonNull Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);//from   w w  w  . j a  v  a2  s  .co m
    return size;
}