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 width of screen **//  w w w  .  ja  v a2  s  .  co m
 */
public static int getScreenW(Context ctx) {
    int w = 0;
    if (Build.VERSION.SDK_INT > 13) {
        Point p = new Point();
        ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getSize(p);
        w = p.x;
    } else {
        w = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth();
    }
    return w;
}

From source file:com.charon.video.view.ScrollingTabs.java

private int getWindowWidth(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    manager.getDefaultDisplay().getMetrics(outMetrics);
    return outMetrics.widthPixels;
}

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

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

From source file:com.uzmap.pkg.uzmodules.UIMediaScanner.UIMediaScanner.java

@UzJavascriptMethod
@SuppressWarnings("deprecation")
public void jsmethod_open(UZModuleContext moduleContext) {

    mMContext = moduleContext;/*  www.  j a  v  a 2s.  co  m*/

    final ConfigInfo config = new ConfigInfo();
    if (!moduleContext.isNull("column")) {
        config.col = moduleContext.optInt("column");
        if (config.col == 0) {
            config.col = 4;
        }
    }

    if (!moduleContext.isNull("max")) {
        config.selectedMax = moduleContext.optInt("max");
    }

    if (!moduleContext.isNull("classify")) {
        config.classify = moduleContext.optBoolean("classify");
    }

    if (!moduleContext.isNull("type")) {
        config.filterType = moduleContext.optString("type");
    }

    if (!moduleContext.isNull("rotation")) {
        config.rotation = moduleContext.optBoolean("rotation");
    }

    /**
     * screen width
     */
    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    int width = wm.getDefaultDisplay().getWidth();

    config.mark_size = UZCoreUtil.pixToDip(width / config.col / 3);

    if (!moduleContext.isNull("bounces")) {
        config.isBounces = moduleContext.optBoolean("bounces");
    }

    JSONObject scrollToBottomObj = moduleContext.optJSONObject("scrollToBottom");
    if (scrollToBottomObj != null && !scrollToBottomObj.isNull("intervalTime")) {
        config.intervalTime = scrollToBottomObj.optInt("intervalTime");
    }

    if (!moduleContext.isNull("exchange")) {
        config.exchange = moduleContext.optBoolean("exchange");
    }

    JSONObject sortObj = moduleContext.optJSONObject("sort");
    if (sortObj != null) {
        if (!sortObj.isNull("key")) {
            config.key = sortObj.optString("key");
        }
        if (!sortObj.isNull("order")) {
            config.order = sortObj.optString("order");
        }
    }

    JSONObject dataObj = moduleContext.optJSONObject("texts");
    if (dataObj != null) {
        if (!dataObj.isNull("stateText")) {
            config.navi_title = dataObj.optString("stateText");
        }
        if (!dataObj.isNull("cancelText")) {
            config.cancel_title = dataObj.optString("cancelText");
        }
        if (!dataObj.isNull("finishText")) {
            config.finish_title = dataObj.optString("finishText");
        }
    }

    JSONObject stylesObj = moduleContext.optJSONObject("styles");
    if (stylesObj != null) {
        // bg
        if (!stylesObj.isNull("bg")) {
            config.bgColor = UZUtility.parseCssColor(stylesObj.optString("bg"));
        }
        // mark
        JSONObject markObj = stylesObj.optJSONObject("mark");
        if (markObj != null) {
            if (!markObj.isNull("position")) {
                config.mark_position = markObj.optString("position");
            }
            if (!markObj.isNull("icon")) {
                config.mark_icon = makeRealPath(markObj.optString("icon"));
            }
            if (!markObj.isNull("size")) {
                config.mark_size = markObj.optInt("size");
            }
        }
        // nav
        JSONObject navObj = stylesObj.optJSONObject("nav");
        if (navObj != null) {
            if (!navObj.isNull("bg")) {
                Bitmap naviBgBitmap = getBitmap(makeRealPath(navObj.optString("bg")));
                if (naviBgBitmap != null) {
                    ConfigInfo.navBgBitmap = naviBgBitmap;
                } else {
                    config.navi_bg = UZUtility.parseCssColor(navObj.optString("bg"));
                }
            }

            if (!navObj.isNull("stateColor")) {
                config.navi_title_color = UZUtility.parseCssColor(navObj.optString("stateColor"));
            }

            if (!navObj.isNull("stateSize")) {
                config.navi_title_size = navObj.optInt("stateSize");
            }

            if (!navObj.isNull("cancleBg")) {
                Bitmap cancelBgBitmap = getBitmap(makeRealPath(navObj.optString("cancleBg")));
                if (cancelBgBitmap != null) {
                    ConfigInfo.cancelBgBitmap = getBitmap(makeRealPath(navObj.optString("cancleBg")));
                } else {
                    config.cancel_bg = UZUtility.parseCssColor(navObj.optString("cancleBg"));
                }
            }

            if (!navObj.isNull("cancelColor")) {
                config.cancel_title_color = UZUtility.parseCssColor(navObj.optString("cancelColor"));
            }

            if (!navObj.isNull("cancelSize")) {
                config.cancel_title_size = navObj.optInt("cancelSize");
            }

            // finish button setting
            if (!navObj.isNull("finishBg")) {
                Bitmap finishBgBitmap = getBitmap(makeRealPath(navObj.optString("finishBg")));
                if (finishBgBitmap != null) {
                    ConfigInfo.finishBgBitmap = finishBgBitmap;
                } else {
                    config.finish_bg = UZUtility.parseCssColor(navObj.optString("finishBg"));
                }
            }

            if (!navObj.isNull("finishColor")) {
                config.finish_title_color = UZUtility.parseCssColor(navObj.optString("finishColor"));
            }

            if (!navObj.isNull("finishSize")) {
                config.finish_title_size = navObj.optInt("finishSize");
            }
        }
    }

    Intent intent = new Intent();
    if (config.classify) {
        intent.setClass(getContext(), UzImgFileListActivity.class);
    } else {
        intent.setClass(getContext(), UzImgsActivity.class);
    }
    intent.putExtra(CONFIG_TAG, config);
    startActivityForResult(intent, REQUEST_CODE);
}

From source file:com.daiv.android.twitter.manipulations.EmojiKeyboard.java

@Override
protected void onFinishInflate() {
    try {//from   www  .ja va  2  s  . c om
        try {
            getContext().getPackageManager().getPackageInfo("com.daiv.android.emoji_keyboard_trial",
                    PackageManager.GET_META_DATA);
        } catch (Exception e) {
            getContext().getPackageManager().getPackageInfo("com.daiv.android.emoji_keyboard_trial_ios",
                    PackageManager.GET_META_DATA);
        }

        emojiPager = (ViewPager) findViewById(R.id.emojiKeyboardPager);
        backspace = (ImageButton) findViewById(R.id.delete);
        Display d = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        keyboardHeight = (int) (d.getHeight() / 3.0);

        dataSource = new EmojiDataSource(getContext());
        dataSource.open();
        recents = (ArrayList<Recent>) dataSource.getAllRecents();

        emojiPager.setLayoutParams(
                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, keyboardHeight));

        tabs = (PagerSlidingTabStrip) findViewById(R.id.emojiTabs);
        tabs.setIndicatorColor(getResources().getColor(R.color.app_color));

        emojiPagerAdapter = new EmojiPagerAdapter(getContext(), emojiPager);
        emojiPager.setAdapter(emojiPagerAdapter);

        tabs.setViewPager(emojiPager);
        emojiPager.setCurrentItem(1);

        backspace.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                removeText();
            }
        });
    } catch (Exception e) {
    }
}

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

public static Point getRealScreenSize(@NonNull Context context) {
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        display.getRealSize(size);//from  w  w  w.  j av  a2s .co  m
    } else {
        try {
            size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
            size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
        } catch (Exception e) {
            size.x = display.getWidth();
            size.y = display.getHeight();
        }
    }
    return size;
}

From source file:com.klinker.android.twitter.manipulations.EmojiKeyboard.java

@Override
protected void onFinishInflate() {
    try {/*from  w  w w.  j av a2  s .c om*/
        try {
            getContext().getPackageManager().getPackageInfo("com.klinker.android.emoji_keyboard_trial",
                    PackageManager.GET_META_DATA);
        } catch (Exception e) {
            getContext().getPackageManager().getPackageInfo("com.klinker.android.emoji_keyboard_trial_ios",
                    PackageManager.GET_META_DATA);
        }

        emojiPager = (ViewPager) findViewById(R.id.emojiKeyboardPager);
        backspace = (ImageButton) findViewById(R.id.delete);
        Display d = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        keyboardHeight = (int) (d.getHeight() / 3.0);

        dataSource = new EmojiDataSource(getContext());
        dataSource.open();
        recents = (ArrayList<Recent>) dataSource.getAllRecents();

        emojiPager.setLayoutParams(
                new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, keyboardHeight));

        tabs = (PagerSlidingTabStrip) findViewById(R.id.emojiTabs);
        tabs.setIndicatorColor(getResources().getColor(R.color.app_color));

        emojiPagerAdapter = new EmojiPagerAdapter(getContext(), emojiPager);
        emojiPager.setAdapter(emojiPagerAdapter);

        tabs.setViewPager(emojiPager);
        emojiPager.setCurrentItem(1);

        backspace.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                removeText();
            }
        });
    } catch (Exception e) {
    }
}

From source file:com.example.androidmillgame.GamePanel.java

public GamePanel(Context context, long period) {
    super(context);
    this.period = period;

    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display wsize = wm.getDefaultDisplay();
    Point size = new Point();
    wsize.getSize(size);/*from   www . j  a  v a  2  s  . c om*/
    DisplayMetrics displayMetrics = new DisplayMetrics();
    wsize.getMetrics(displayMetrics);
    this.dpi = displayMetrics.densityDpi;
    this.PWIDTH = size.x;
    this.PHEIGHT = size.y;

    setFocusable(true);
    requestFocus();// ...............................................the.JPane.now.has.focus,.so.receives.key.events
    imgres = new Images(context);// ..............................................................preload.resources
    generatedJoints = new SmartJointFactory(context);
    DraggablePoint = new DragPlayer();
    backgroundRect = new Rect(PWIDTH / 2 - PHEIGHT / 2, 0, PWIDTH / 2 + PHEIGHT / 2, PHEIGHT);
    background = new Rect(0, 0, imgres.getImage("background").getWidth(),
            imgres.getImage("background").getHeight());
    scale = imgres.getImage("background").getHeight() / PHEIGHT;
    int resumescaled = imgres.getImage("resumenop").getWidth();
    resumeRect = new Rect(PWIDTH / 2 - resumescaled / 2, PHEIGHT / 2 - resumescaled / 2 + Pd2px.pd2px(50),
            PWIDTH / 2 + resumescaled / 2, PHEIGHT / 2 + resumescaled / 2 + Pd2px.pd2px(50));
    GC = new GameController(generatedJoints.Joints, DraggablePoint, context);
    Display = new HUD(PWIDTH / 2, PHEIGHT / 2, imgres.getImage("hud"));
    this.startGame();
}

From source file:com.almalence.util.Util.java

public static void initialize(Context context) {
    sIsTabletUI = false;/*from   w w  w.  j  a va  2s.  c  o  m*/

    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(metrics);
    sPixelDensity = metrics.density;
}

From source file:com.breadwallet.BreadWalletApp.java

@Override
public void onCreate() {
    super.onCreate();

    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);/*from  w  w w  .  j av a 2  s .c o  m*/
    int DISPLAY_WIDTH_PX = size.x;
    DISPLAY_HEIGHT_PX = size.y;
    mFingerprintManager = (FingerprintManager) getSystemService(Context.FINGERPRINT_SERVICE);

}