List of usage examples for android.app Activity getWindowManager
public WindowManager getWindowManager()
From source file:com.gm.goldencity.util.Utils.java
/** * Get display height/*from w ww. ja v a2s . c o m*/ * * @param context Application context * @return */ @SuppressLint("NewApi") @SuppressWarnings("deprecation") public static int getDisplayHeight(Context context) { Activity activity = (Activity) context; if (Integer.valueOf(Build.VERSION.SDK_INT) < 13) { Display display = activity.getWindowManager().getDefaultDisplay(); return display.getHeight(); } else { Display display = activity.getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); return size.y; } }
From source file:ch.rts.cordova.is.tablet.IsTablet.java
private boolean isTabletDevice(Context applicationContext) { boolean device_large = ((applicationContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE); if (device_large) { DisplayMetrics metrics = new DisplayMetrics(); Activity activity = this.cordova.getActivity(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM || metrics.densityDpi == DisplayMetrics.DENSITY_TV || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH) { Log.d(LOG_TAG, "Is Tablet Device"); return true; }/*w w w.j a v a 2 s . co m*/ } Log.d(LOG_TAG, "Is NOT Tablet Device"); return false; }
From source file:uk.co.workingedge.phonegap.plugin.IsTablet.java
private boolean isTabletDevice(Context applicationContext) { boolean device_large = ((applicationContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE); if (device_large) { DisplayMetrics metrics = new DisplayMetrics(); Activity activity = this.cordova.getActivity(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); if (metrics.densityDpi == DisplayMetrics.DENSITY_DEFAULT || metrics.densityDpi == DisplayMetrics.DENSITY_HIGH || metrics.densityDpi == DisplayMetrics.DENSITY_MEDIUM || metrics.densityDpi == DisplayMetrics.DENSITY_TV || metrics.densityDpi == DisplayMetrics.DENSITY_XHIGH || metrics.densityDpi == DisplayMetrics.DENSITY_XXHIGH) { Log.d(LOG_TAG, "Is Tablet Device"); return true; }//w ww .ja va 2 s .c o m } Log.d(LOG_TAG, "Is NOT Tablet Device"); return false; }
From source file:tr.com.turkcellteknoloji.turkcellupdater.Utilities.java
@SuppressLint("NewApi") static int getScreenOrientation(Activity activity) { if (Build.VERSION.SDK_INT < 8) { switch (activity.getResources().getConfiguration().orientation) { case Configuration.ORIENTATION_PORTRAIT: return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; case Configuration.ORIENTATION_LANDSCAPE: return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; default:/*from w ww . j a v a 2 s . c o m*/ return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } } int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); DisplayMetrics dm = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(dm); int width = dm.widthPixels; int height = dm.heightPixels; int orientation; // if the device's natural orientation is portrait: if ((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) && height > width || (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) && width > height) { switch (rotation) { case Surface.ROTATION_0: orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; case Surface.ROTATION_90: orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; case Surface.ROTATION_180: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; break; case Surface.ROTATION_270: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; default: orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; } } // if the device's natural orientation is landscape or if the device // is square: else { switch (rotation) { case Surface.ROTATION_0: orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; case Surface.ROTATION_90: orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; case Surface.ROTATION_180: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; case Surface.ROTATION_270: orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; break; default: orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; } } return orientation; }
From source file:me.kaidul.uhunt.MainActivity.java
@SuppressLint("NewApi") static int getDeviceWidth(Activity activity) { int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { Display display = activity.getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size);//w w w . j ava 2s. c o m return size.x; } else { Display display = activity.getWindowManager().getDefaultDisplay(); return display.getWidth(); } }
From source file:com.example.android.screencapture.ScreenCaptureFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Activity activity = getActivity(); DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); mScreenDensity = metrics.densityDpi; mMediaProjectionManager = (MediaProjectionManager) activity .getSystemService(Context.MEDIA_PROJECTION_SERVICE); }
From source file:com.example.aula20141117.util.AmUtil.java
public Bundle getDeviceResolutionPixels(Activity origemDoPedido) { Bundle ret = new Bundle(); DisplayMetrics dm = new DisplayMetrics(); origemDoPedido.getWindowManager().getDefaultDisplay().getMetrics(dm); ret.putInt("widthPixels", dm.widthPixels); ret.putInt("heightPixels", dm.heightPixels); return ret;/* w w w .jav a 2 s.co m*/ }
From source file:com.streaming.sweetplayer.MainActivity.java
/** * For Android fragmentation, it's so important to know the device details like width, height and densityDpi. *//*from w w w . j ava 2 s.co m*/ private void getDensityDpi(Activity activity) { DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); Config.deviceDensityDpi = metrics.densityDpi; Config.deviceHeight = metrics.heightPixels; Config.deviceWidth = metrics.widthPixels; }
From source file:com.readystatesoftware.ghostlog.ServerlessLogScreen.java
private void removeSystemWindow(Activity activity, ListView listView) { if (listView != null && listView.getParent() != null) { final WindowManager wm = activity.getWindowManager(); wm.removeViewImmediate(listView); }/*from w w w. j a v a 2s . c om*/ }
From source file:edu.berkeley.boinc.ProjectDetailsFragment.java
@SuppressWarnings("deprecation") @Override//from w w w .j ava 2s.c o m public void onAttach(Activity activity) { // first time fragment can get a valid context (before this, getActivity() will return null!) Display display = activity.getWindowManager().getDefaultDisplay(); width = display.getWidth(); height = display.getHeight(); super.onAttach(activity); }