List of usage examples for android.content Context WINDOW_SERVICE
String WINDOW_SERVICE
To view the source code for android.content Context WINDOW_SERVICE.
Click Source Link
From source file:com.example.ultravisualdemo.NearFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); WindowManager wm = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE); mScreenWidth = wm.getDefaultDisplay().getWidth(); ITEM_HEIGHT = getResources().getDimensionPixelSize(R.dimen.item_height); mAdapter = new FirstItemMaxAdapter(); mListView.setAdapter(mAdapter);//from w ww .j ava 2 s. c o m mListView.setItemHeight(ITEM_HEIGHT); mListView.setItemMaxHeight(mScreenWidth); }
From source file:net.genus.plugins.screensize.ScreenSize.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("getSize")) { Log.d("ScreenSizeDebug", "getSize"); DisplayMetrics metrics = new DisplayMetrics(); Context context = this.cordova.getActivity().getApplicationContext(); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); windowManager.getDefaultDisplay().getMetrics(metrics); Log.d("ScreenSizeDebug", "Pixles wide: " + metrics.widthPixels); Log.d("ScreenSizeDebug", "Pixels high: " + metrics.heightPixels); Log.d("ScreenSizeDebug", "DPI Density: " + metrics.densityDpi); int width = metrics.widthPixels; int height = metrics.heightPixels; int dens = metrics.densityDpi; double wi = (double) width / (double) dens; double hi = (double) height / (double) dens; Log.d("ScreenSizeDebug", "Width: " + wi); Log.d("ScreenSizeDebug", "Height: " + hi); double x = Math.pow(wi, 2); double y = Math.pow(hi, 2); double screenInches = Math.sqrt(x + y); Log.d("ScreenSizeDebug", "Screen size: " + screenInches); screenInches = screenInches * 1000; int result = (int) screenInches; Log.d("ScreenSizeDebug", "" + result); callbackContext.success(result); return true; }/*from w w w .j av a2 s. c om*/ return false; }
From source file:com.charon.materialsample.view.ScrollingTabs.java
public static 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:com.bobomee.android.common.util.ScreenUtil.java
/** * ?/*from w w w .j a va 2 s. co m*/ */ public static int getScreenWidth(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics outMetrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(outMetrics); return outMetrics.widthPixels; }
From source file:count.ly.messaging.DeviceInfo.java
/** * Returns the non-scaled pixel resolution of the current default display being used by the * WindowManager in the specified context. * @param context context to use to retrieve the current WindowManager * @return a string in the format "WxH", or the empty string "" if resolution cannot be determined *//*from www. j a va2s . co m*/ static String getResolution(final Context context) { // user reported NPE in this method; that means either getSystemService or getDefaultDisplay // were returning null, even though the documentation doesn't say they should do so; so now // we catch Throwable and return empty string if that happens String resolution = ""; try { final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); final Display display = wm.getDefaultDisplay(); final DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); resolution = metrics.widthPixels + "x" + metrics.heightPixels; } catch (Throwable t) { if (Countly.sharedInstance().isLoggingEnabled()) { Log.i(Countly.TAG, "Device resolution cannot be determined"); } } return resolution; }
From source file:com.acious.android.paginationseekbar.internal.PopupIndicator.java
public PopupIndicator(Context context, AttributeSet attrs, int defStyleAttr, String maxValue, String prevText, String nextText) {/*from w ww. java 2 s .c o m*/ mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); mPopupView = new Floater(context, attrs, defStyleAttr, maxValue); DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); screenSize.set(displayMetrics.widthPixels, displayMetrics.heightPixels); mPrevPageText = prevText; mNextPageText = nextText; }
From source file:ly.count.android.api.DeviceInfoTests.java
public void testGetResolution() { final DisplayMetrics metrics = new DisplayMetrics(); ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay() .getMetrics(metrics);/*from www.j a va 2 s .c o m*/ final String expected = metrics.widthPixels + "x" + metrics.heightPixels; assertEquals(expected, DeviceInfo.getResolution(getContext())); }
From source file:com.example.textviewsample.MainActivityFragment.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @Override// ww w . j a v a 2 s .c o m public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); sourceCodeText = (TextView) view.findViewById(R.id.textView7); DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); display.getMetrics(metrics); int widthInPixels = metrics.widthPixels; int heightInPixels = metrics.heightPixels; float scaleFactor = metrics.density; float widthDp = widthInPixels / scaleFactor; float heightDp = heightInPixels / scaleFactor; TextView tv1 = (TextView) view.findViewById(R.id.textView1); tv1.setText(String.format(Locale.getDefault(), "Density: %s, sw%s, w%s\nDevice year: " + "%d\nCPU " + "Cores: %d, " + "MaxFreq: %d", getString(R.string.density), DisplayUtils.getSmallestWidth(getActivity()), widthDp, YearClass.get(getActivity()), DeviceInfo.getNumberOfCPUCores(), DeviceInfo.getCPUMaxFreqKHz())); ExpandableTextView etv = (ExpandableTextView) view.findViewById(R.id.textView6); etv.setContracted(true); new Shimmer().setDuration(1500).setStartDelay(4000).setRepeatDelay(5000) .start((ShimmerTextView) view.findViewById(R.id.textView12)); }
From source file:com.itime.team.itime.fragments.QRCodeFragment.java
@NonNull @Override//from w w w . j av a 2 s . com public Dialog onCreateDialog(Bundle savedInstanceState) { final Dialog dialog = super.onCreateDialog(savedInstanceState); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.fragment_profile_qrcode); ImageView imageView = (ImageView) dialog.findViewById(R.id.setting_profile_qrcode_img); final Bundle arguments = getArguments(); if (!arguments.isEmpty()) { mUserId = arguments.getString(QRCODE_STRING); } Bitmap qrCodeBitmap; // method1: change a fix dip to pixel //final int dim = DensityUtil.dip2px(getContext(), 600); // method2: get the display size and scale into 7/8 // This assumes the view is full screen, which is a good assumption WindowManager manager = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); Point displaySize = new Point(); display.getSize(displaySize); int width = displaySize.x; int height = displaySize.y; int smallerDimension = width < height ? width : height; final int dim = smallerDimension * 7 / 8; try { qrCodeBitmap = barcodeEncoder.encodeBitmap(mUserId, BarcodeFormat.QR_CODE, dim, dim); imageView.setImageBitmap(qrCodeBitmap); } catch (WriterException e) { Toast.makeText(getActivity(), "QRCode text can not be empty", Toast.LENGTH_SHORT).show(); } return dialog; }
From source file:com.doomy.library.Internal.PopupIndicator.java
public PopupIndicator(Context context, AttributeSet attrs, int defStyleAttr, String maxValue) { mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); mPopupView = new Floater(context, attrs, defStyleAttr, maxValue); DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); screenSize.set(displayMetrics.widthPixels, displayMetrics.heightPixels); }