Java Code Examples for android.app.Activity#getWindowManager()
The following examples show how to use
android.app.Activity#getWindowManager() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java From BatteryFu with GNU General Public License v2.0 | 6 votes |
/** * Returns true if device screen width is as specified * * @param activity * @param orBigger * @return */ public static boolean isScreenWidth(Activity activity, int width, boolean orBigger) { boolean retVal = false; if (activity == null || activity.getWindowManager() == null) return retVal; Display d = activity.getWindowManager().getDefaultDisplay(); if (orBigger) { if (d.getWidth() < d.getHeight()) { if (d.getWidth() >= width) retVal = true; } else { if (d.getHeight() >= width) retVal = true; } } else { if (d.getWidth() < d.getHeight()) { if (d.getWidth() == width) retVal = true; } else { if (d.getHeight() == width) retVal = true; } } return retVal; }
Example 2
Source File: AppUtils.java From YCWebView with Apache License 2.0 | 6 votes |
/** * 截屏,截取activity的可见区域的视图 * @param activity * @return */ public static Bitmap activityShot(Activity activity) { /*获取windows中最顶层的view*/ View view = activity.getWindow().getDecorView(); //允许当前窗口保存缓存信息 view.setDrawingCacheEnabled(true); view.buildDrawingCache(); //获取状态栏高度 Rect rect = new Rect(); view.getWindowVisibleDisplayFrame(rect); int statusBarHeight = rect.top; WindowManager windowManager = activity.getWindowManager(); //获取屏幕宽和高 DisplayMetrics outMetrics = new DisplayMetrics(); windowManager.getDefaultDisplay().getMetrics(outMetrics); int width = outMetrics.widthPixels; int height = outMetrics.heightPixels; //去掉状态栏 Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache(), 0, statusBarHeight, width, height - statusBarHeight); //销毁缓存信息 view.destroyDrawingCache(); view.setDrawingCacheEnabled(false); return bitmap; }
Example 3
Source File: AndroidBarUtils.java From AndroidBarUtils with Apache License 2.0 | 6 votes |
/** * 是否有NavigationBar * * @param activity 上下文 * @return 是否有NavigationBar */ private static boolean hasNavBar(Activity activity) { WindowManager windowManager = activity.getWindowManager(); Display d = windowManager.getDefaultDisplay(); DisplayMetrics realDisplayMetrics = new DisplayMetrics(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { d.getRealMetrics(realDisplayMetrics); } int realHeight = realDisplayMetrics.heightPixels; int realWidth = realDisplayMetrics.widthPixels; DisplayMetrics displayMetrics = new DisplayMetrics(); d.getMetrics(displayMetrics); int displayHeight = displayMetrics.heightPixels; int displayWidth = displayMetrics.widthPixels; return (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; }
Example 4
Source File: BarConfig.java From MyBookshelf with GNU General Public License v3.0 | 6 votes |
@TargetApi(14) private static boolean hasNavBar(Activity activity) { WindowManager windowManager = activity.getWindowManager(); Display d = windowManager.getDefaultDisplay(); DisplayMetrics realDisplayMetrics = new DisplayMetrics(); d.getRealMetrics(realDisplayMetrics); int realHeight = realDisplayMetrics.heightPixels; int realWidth = realDisplayMetrics.widthPixels; DisplayMetrics displayMetrics = new DisplayMetrics(); d.getMetrics(displayMetrics); int displayHeight = displayMetrics.heightPixels; int displayWidth = displayMetrics.widthPixels; return (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; }
Example 5
Source File: BarConfig.java From PocketEOS-Android with GNU Lesser General Public License v3.0 | 6 votes |
@TargetApi(14) private static boolean hasNavBar(Activity activity) { WindowManager windowManager = activity.getWindowManager(); Display d = windowManager.getDefaultDisplay(); DisplayMetrics realDisplayMetrics = new DisplayMetrics(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { d.getRealMetrics(realDisplayMetrics); } int realHeight = realDisplayMetrics.heightPixels; int realWidth = realDisplayMetrics.widthPixels; DisplayMetrics displayMetrics = new DisplayMetrics(); d.getMetrics(displayMetrics); int displayHeight = displayMetrics.heightPixels; int displayWidth = displayMetrics.widthPixels; return (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; }
Example 6
Source File: BarConfig.java From a with GNU General Public License v3.0 | 6 votes |
@TargetApi(14) private static boolean hasNavBar(Activity activity) { WindowManager windowManager = activity.getWindowManager(); Display d = windowManager.getDefaultDisplay(); DisplayMetrics realDisplayMetrics = new DisplayMetrics(); d.getRealMetrics(realDisplayMetrics); int realHeight = realDisplayMetrics.heightPixels; int realWidth = realDisplayMetrics.widthPixels; DisplayMetrics displayMetrics = new DisplayMetrics(); d.getMetrics(displayMetrics); int displayHeight = displayMetrics.heightPixels; int displayWidth = displayMetrics.widthPixels; return (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; }
Example 7
Source File: BaseKeyboard.java From actor-platform with GNU Affero General Public License v3.0 | 6 votes |
public BaseKeyboard(Activity activity, EditText messageBody) { this.activity = activity; this.windowManager = activity.getWindowManager(); this.inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); this.decorView = activity.getWindow().getDecorView(); decorView.getViewTreeObserver().addOnGlobalLayoutListener(this); //setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); //default size keyboardHeight = (int) activity.getResources().getDimension(R.dimen.keyboard_height); keyboardHelper = new KeyboardHelper(activity); this.messageBody = messageBody; messageBody.setOnClickListener(view -> { if (showing) { dismiss(); } }); messageBody.setOnFocusChangeListener((view, b) -> { if (b && showing) { dismiss(); } }); }
Example 8
Source File: CommonUtils.java From yanxuan-weex-demo with MIT License | 5 votes |
public static int getDisplayWidth(Activity activity){ int width=0; if (activity != null && activity.getWindowManager() != null && activity.getWindowManager().getDefaultDisplay() != null) { Point point=new Point(); activity.getWindowManager().getDefaultDisplay().getSize(point); width = point.x; } return width; }
Example 9
Source File: NavigationUtil.java From UIWidget with Apache License 2.0 | 5 votes |
/** * 获取屏幕宽度,不包括右侧导航栏 */ public static int getRealScreenWidth(Activity activity) { WindowManager windowManager = activity.getWindowManager(); Display display = windowManager.getDefaultDisplay(); DisplayMetrics displayMetrics = new DisplayMetrics(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { display.getRealMetrics(displayMetrics); } else { display.getMetrics(displayMetrics); } return displayMetrics.widthPixels; }
Example 10
Source File: NavigationUtil.java From UIWidget with Apache License 2.0 | 5 votes |
/** * 获取屏幕高度,包括底部导航栏 */ public static int getRealScreenHeight(Activity activity) { WindowManager windowManager = activity.getWindowManager(); Display display = windowManager.getDefaultDisplay(); DisplayMetrics displayMetrics = new DisplayMetrics(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { display.getRealMetrics(displayMetrics); } else { display.getMetrics(displayMetrics); } return displayMetrics.heightPixels; }
Example 11
Source File: ImageUtils.java From LQRWeChat with MIT License | 5 votes |
public static Bitmap zoomForFilePath(Activity context, String filePath) { Bitmap bitmap = BitmapFactory.decodeFile(filePath); BitmapFactory.Options opt = new BitmapFactory.Options(); //这个isjustdecodebounds很重要 opt.inJustDecodeBounds = true; //获取到这个图片的原始宽度和高度 int picWidth = bitmap.getWidth(); int picHeight = bitmap.getHeight(); //获取屏的宽度和高度 WindowManager windowManager = context.getWindowManager(); Display display = windowManager.getDefaultDisplay(); int screenWidth = display.getWidth(); int screenHeight = display.getHeight(); //isSampleSize是表示对图片的缩放程度,比如值为2图片的宽度和高度都变为以前的1/2 opt.inSampleSize = 1; //根据屏的大小和图片大小计算出缩放比例 if (picWidth > picHeight) { if (picWidth > screenWidth) opt.inSampleSize = picWidth / screenWidth; } else { if (picHeight > screenHeight) opt.inSampleSize = picHeight / screenHeight; } //这次再真正地生成一个有像素的,经过缩放了的bitmap opt.inJustDecodeBounds = false; bitmap = BitmapFactory.decodeFile(filePath, opt); return bitmap; }
Example 12
Source File: X5WebUtils.java From YCWebView with Apache License 2.0 | 5 votes |
/** * 截屏,截取activity的可见区域的视图 * @param activity 上下文 * @return bitmap图片 */ public static Bitmap activityShot(Activity activity) { /*获取windows中最顶层的view*/ View view = activity.getWindow().getDecorView(); //允许当前窗口保存缓存信息 view.setDrawingCacheEnabled(true); view.buildDrawingCache(); //获取状态栏高度 Rect rect = new Rect(); view.getWindowVisibleDisplayFrame(rect); int statusBarHeight = rect.top; WindowManager windowManager = activity.getWindowManager(); //获取屏幕宽和高 DisplayMetrics outMetrics = new DisplayMetrics(); windowManager.getDefaultDisplay().getMetrics(outMetrics); int width = outMetrics.widthPixels; int height = outMetrics.heightPixels; //获取view的缓存位图 Bitmap drawingCache = view.getDrawingCache(); //去掉状态栏 Bitmap bitmap = Bitmap.createBitmap(drawingCache, 0, statusBarHeight, width, height - statusBarHeight); //销毁缓存信息 view.destroyDrawingCache(); view.setDrawingCacheEnabled(false); return bitmap; }
Example 13
Source File: ViewUtil.java From android-utils with Apache License 2.0 | 5 votes |
/** * Get the screen dimensions * * @param activity the activity * @return the int [ ] */ public static int[] getScreenSize(Activity activity) { Point size = new Point(); WindowManager w = activity.getWindowManager(); w.getDefaultDisplay().getSize(size); return new int[]{size.x, size.y}; }
Example 14
Source File: CommonUtils.java From yanxuan-weex-demo with MIT License | 5 votes |
public static int getDisplayHeight(Activity activity) { int height = 0; if (activity != null && activity.getWindowManager() != null && activity.getWindowManager().getDefaultDisplay() != null) { Point point=new Point(); activity.getWindowManager().getDefaultDisplay().getSize(point); height=point.y; } Log.e(TAG, "isSupportSmartBar:" + isSupportSmartBar); if (isSupportSmartBar) { int smartBarHeight = getSmartBarHeight(activity); Log.e(TAG, "smartBarHeight:" + smartBarHeight); height -= smartBarHeight; } if (activity != null && activity.getActionBar() != null) { int actionbar= activity.getActionBar().getHeight(); if(actionbar==0){ TypedArray actionbarSizeTypedArray=activity.obtainStyledAttributes(new int[]{android.R.attr.actionBarSize}); actionbar= (int) actionbarSizeTypedArray.getDimension(0,0); } Log.d(TAG, "actionbar:" + actionbar); height -= actionbar; } int status = getStatusBarHeight(activity); Log.d(TAG, "status:" + status); height -= status; Log.d(TAG,"height:"+height); return height; }
Example 15
Source File: CommonUtils.java From ucar-weex-core with Apache License 2.0 | 5 votes |
public static int getDisplayHeight(Activity activity) { int height = 0; if (activity != null && activity.getWindowManager() != null && activity.getWindowManager().getDefaultDisplay() != null) { Point point=new Point(); activity.getWindowManager().getDefaultDisplay().getSize(point); height=point.y; } Log.e(TAG, "isSupportSmartBar:" + isSupportSmartBar); if (isSupportSmartBar) { int smartBarHeight = getSmartBarHeight(activity); Log.e(TAG, "smartBarHeight:" + smartBarHeight); height -= smartBarHeight; } if (activity != null && activity.getActionBar() != null) { int actionbar= activity.getActionBar().getHeight(); if(actionbar==0){ TypedArray actionbarSizeTypedArray=activity.obtainStyledAttributes(new int[]{android.R.attr.actionBarSize}); actionbar= (int) actionbarSizeTypedArray.getDimension(0,0); } Log.d(TAG, "actionbar:" + actionbar); height -= actionbar; } int status = getStatusBarHeight(activity); Log.d(TAG, "status:" + status); height -= status; Log.d(TAG,"height:"+height); return height; }
Example 16
Source File: CommonUtils.java From ucar-weex-core with Apache License 2.0 | 5 votes |
public static int getDisplayWidth(Activity activity){ int width=0; if (activity != null && activity.getWindowManager() != null && activity.getWindowManager().getDefaultDisplay() != null) { Point point=new Point(); activity.getWindowManager().getDefaultDisplay().getSize(point); width = point.x; } return width; }
Example 17
Source File: OsUtils.java From PopupWindowCompat with Apache License 2.0 | 5 votes |
/** * 检测是否具有底部导航栏 * * @param activity * @return */ private static boolean checkDeviceHasNavigationBar(Activity activity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { WindowManager windowManager = activity.getWindowManager(); Display display = windowManager.getDefaultDisplay(); DisplayMetrics realDisplayMetrics = new DisplayMetrics(); display.getRealMetrics(realDisplayMetrics); int realHeight = realDisplayMetrics.heightPixels; int realWidth = realDisplayMetrics.widthPixels; DisplayMetrics displayMetrics = new DisplayMetrics(); display.getMetrics(displayMetrics); int displayHeight = displayMetrics.heightPixels; int displayWidth = displayMetrics.widthPixels; return (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; } else { boolean hasNavigationBar = false; Resources resources = activity.getResources(); int id = resources.getIdentifier("config_showNavigationBar", "bool", "android"); if (id > 0) { hasNavigationBar = resources.getBoolean(id); } try { Class systemPropertiesClass = Class.forName("android.os.SystemProperties"); Method m = systemPropertiesClass.getMethod("get", String.class); String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys"); if ("1".equals(navBarOverride)) { hasNavigationBar = false; } else if ("0".equals(navBarOverride)) { hasNavigationBar = true; } } catch (Exception e) { } return hasNavigationBar; } }
Example 18
Source File: Utils.java From mine-android-repository with Apache License 2.0 | 4 votes |
public static int getDisplayWHHeigth(Activity context){ WindowManager wm = context.getWindowManager(); int height = wm.getDefaultDisplay().getHeight(); return height; }
Example 19
Source File: Utils.java From mine-android-repository with Apache License 2.0 | 4 votes |
public static int getDisplayWidth(Activity context){ WindowManager wm = context.getWindowManager(); int width = wm.getDefaultDisplay().getWidth(); return width; }
Example 20
Source File: HWUtils.java From RePlugin-GameSdk with Apache License 2.0 | 4 votes |
/** * 设置窗口模式 */ public static void setWindowDisplayMode(Activity context, int height, float hRate, float wRate) { WindowManager m = context.getWindowManager(); Display d = m.getDefaultDisplay(); // 为获取屏幕宽、高 android.view.WindowManager.LayoutParams p = context.getWindow() .getAttributes(); // 获取对话框当前的参数值 if (FunCellPlatformSdkApi.getInstance().isWindowMode()) { if (d.getHeight() < d.getWidth()) { if (HWUtils.dip2px(context, height) < d.getHeight()) { p.height = HWUtils.dip2px(context, height); } else { p.height = (int) (d.getHeight() * hRate); } p.width = (int) (d.getHeight() * wRate); // getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); } else { if (HWUtils.dip2px(context, height) < d.getWidth()) { p.height = HWUtils.dip2px(context, height); } else { p.height = (int) (d.getWidth() * hRate); } p.width = (int) (d.getWidth() * wRate); } // p.height=HWUtils.dip2px(context,280); p.alpha = 0.98f; // 设置本身透明度 p.dimAmount = 0.0f; // 设置黑暗度 } else { p.height = d.getHeight(); p.width = d.getWidth(); } context.getWindow().setAttributes(p); // 设置生效 // context.getWindow().setGravity(Gravity.CENTER); // 设置居中对齐 }