Here are the examples of the java api class android.view.WindowManager taken from open source projects.
1. WebActivity#createView()
Project: ZhuanLan
File: WebActivity.java
File: WebActivity.java
private void createView() { FloatView view = new FloatView(getApplicationContext()); WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE); WindowManager.LayoutParams wmParams = new WindowManager.LayoutParams(); wmParams.type = WindowManager.LayoutParams.TYPE_PHONE; wmParams.format = PixelFormat.RGBA_8888; wmParams.flags |= 8; wmParams.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL; wmParams.x = 0; wmParams.y = 80; wmParams.width = ViewGroup.LayoutParams.WRAP_CONTENT; wmParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ZhuanlanApplication.getInstance().startActivity(new Intent("com.bxbxbai.zhuanlan.ui.activity.AboutActivity")); Log.i(TAG, "onclick"); } }); wm.addView(view, wmParams); }
2. GalgoService#onCreate()
Project: RxAndroidBootstrap
File: GalgoService.java
File: GalgoService.java
@Override public void onCreate() { super.onCreate(); mTextView = new TextView(this); WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); wm.addView(mTextView, params); }
3. QuickActionView#display()
Project: QuickActionView
File: QuickActionView.java
File: QuickActionView.java
private void display(Point point) { if (mActions == null) { throw new IllegalStateException("You need to give the QuickActionView actions before calling show!"); } WindowManager manager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL); params.format = PixelFormat.TRANSLUCENT; mQuickActionViewLayout = new QuickActionViewLayout(mContext, mActions, point); manager.addView(mQuickActionViewLayout, params); if (mOnShowListener != null) { mOnShowListener.onShow(this); } }
4. GalgoService#onCreate()
Project: MVPAndroidBootstrap
File: GalgoService.java
File: GalgoService.java
@Override public void onCreate() { super.onCreate(); mTextView = new TextView(this); WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); wm.addView(mTextView, params); }
5. GalgoService#onCreate()
Project: galgo
File: GalgoService.java
File: GalgoService.java
@Override public void onCreate() { super.onCreate(); mTextView = new TextView(this); WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT); WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); wm.addView(mTextView, params); }
6. TextOverlayService#onCreate()
Project: android-textoverlay
File: TextOverlayService.java
File: TextOverlayService.java
@Override public void onCreate() { Log.d(TAG, "onCreate: Starting service"); super.onCreate(); int colorId = getResources().getIdentifier("red", "color", getPackageName()); textView = new TextView(this); textView.setTextColor(ContextCompat.getColor(this, colorId)); textView.setText(lastUsedOverlayText); WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, PixelFormat.TRANSLUCENT); params.gravity = Gravity.CENTER | Gravity.BOTTOM; params.setTitle("Text Overlay"); WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); wm.addView(textView, params); LocalBroadcastManager.getInstance(this).registerReceiver(messageReceiver, new IntentFilter(ACTION_SET_TEXT)); }
7. GridOverlayService#showGrid()
Project: android-grid-wichterle
File: GridOverlayService.java
File: GridOverlayService.java
private void showGrid() { Log.d(Constants.TAG, "GridOverlayService.showGrid()"); GridOverlayService.sIsGridShown = true; final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, PixelFormat.TRANSLUCENT); final WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); mGridOverlay = new GridOverlay(this); wm.addView(mGridOverlay, lp); }
8. Utils#getDisplaySize()
Project: CastVideos-android
File: Utils.java
File: Utils.java
@SuppressWarnings("deprecation") public static /** * Returns the screen/display size * */ Point getDisplaySize(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); return new Point(width, height); }
9. Utils#getDisplaySize()
Project: cast-videos-android
File: Utils.java
File: Utils.java
@SuppressWarnings("deprecation") public static /** * Returns the screen/display size * */ Point getDisplaySize(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); return new Point(width, height); }
10. Utils#getDisplaySize()
Project: cast-videos-android
File: Utils.java
File: Utils.java
@SuppressWarnings("deprecation") public static /** * Returns the screen/display size * */ Point getDisplaySize(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); return new Point(width, height); }
11. SeekBarPopup#show()
Project: Carbon
File: SeekBarPopup.java
File: SeekBarPopup.java
public boolean show(View anchor) { super.showAtLocation(anchor, Gravity.START | Gravity.TOP, 0, 0); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); contentView.measure(View.MeasureSpec.makeMeasureSpec(wm.getDefaultDisplay().getWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); super.update(wm.getDefaultDisplay().getWidth(), contentView.getMeasuredHeight()); bubble.setVisibility(View.VISIBLE); return true; }
12. TileBitmapDrawable#getDisplayMetrics()
Project: ByakuGallery
File: TileBitmapDrawable.java
File: TileBitmapDrawable.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) private static void getDisplayMetrics(Context context, DisplayMetrics outMetrics) { final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); final Display display = wm.getDefaultDisplay(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { display.getRealMetrics(outMetrics); } else { display.getMetrics(outMetrics); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { try { outMetrics.widthPixels = (Integer) Display.class.getMethod("getRawWidth").invoke(display); outMetrics.heightPixels = (Integer) Display.class.getMethod("getRawHeight").invoke(display); return; } catch (Exception e) { } } } }
13. BubbleFlowDraggable#onOrientationChanged()
Project: browser-android
File: BubbleFlowDraggable.java
File: BubbleFlowDraggable.java
@Override public void onOrientationChanged() { clearTargetPos(); WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getSize(mTempSize); configure(mTempSize.x, mItemWidth, mItemHeight); updatePositions(); updateScales(getScrollX()); setExactPos(0, 0); if (null != mCurrentTab) { mCurrentTab.getContentView().onOrientationChanged(); } }
14. Config#init()
Project: browser-android
File: Config.java
File: Config.java
public static void init(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(mDm); mBubbleWidth = mBubbleHeight = context.getResources().getDimensionPixelSize(R.dimen.bubble_size); mScreenCenterX = (int) (mDm.widthPixels * 0.5f); mScreenHeight = mDm.heightPixels - getStatusBarHeight(context); mScreenWidth = mDm.widthPixels; mBubbleSnapLeftX = (int) (-mBubbleWidth * 0.2f); mBubbleSnapRightX = (int) (mDm.widthPixels - mBubbleWidth * 0.8f); //(mContentOffset + mBubbleHeight * 0.15f); mBubbleMinY = 0; //(mDm.heightPixels - 1.15f * mBubbleHeight); mBubbleMaxY = (int) (mDm.heightPixels - mBubbleHeight); mContentViewBubbleX = (int) (mDm.widthPixels - mBubbleWidth - mBubbleWidth * 0.5f); mContentViewBubbleY = context.getResources().getDimensionPixelSize(R.dimen.content_bubble_y_offset); mContentOffset = context.getResources().getDimensionPixelSize(R.dimen.content_offset); sDensityDpi = mDm.densityDpi; sIsTablet = context.getResources().getBoolean(R.bool.is_tablet); }
15. ManagerSuperToast#removeSuperToast()
Project: Bitocle
File: ManagerSuperToast.java
File: ManagerSuperToast.java
/* Hide and remove the SuperToast */ protected void removeSuperToast(SuperToast superToast) { final WindowManager windowManager = superToast.getWindowManager(); final View toastView = superToast.getView(); if (windowManager != null) { mQueue.poll(); windowManager.removeView(toastView); sendMessageDelayed(superToast, Messages.DISPLAY_SUPERTOAST, 500); if (superToast.getOnDismissListener() != null) { superToast.getOnDismissListener().onDismiss(superToast.getView()); } } }
16. ManagerSuperToast#removeSuperToast()
Project: Bitocle
File: ManagerSuperToast.java
File: ManagerSuperToast.java
/* Hide and remove the SuperToast */ protected void removeSuperToast(SuperToast superToast) { final WindowManager windowManager = superToast.getWindowManager(); final View toastView = superToast.getView(); if (windowManager != null) { mQueue.poll(); windowManager.removeView(toastView); sendMessageDelayed(superToast, Messages.DISPLAY_SUPERTOAST, 500); if (superToast.getOnDismissListener() != null) { superToast.getOnDismissListener().onDismiss(superToast.getView()); } } }
17. CameraConfigurationManager#initFromCameraParameters()
Project: bitcoin-android
File: CameraConfigurationManager.java
File: CameraConfigurationManager.java
/** * Reads, one time, values from the camera that are needed by the app. */ void initFromCameraParameters(Camera camera) { Camera.Parameters parameters = camera.getParameters(); previewFormat = parameters.getPreviewFormat(); previewFormatString = parameters.get("preview-format"); Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); screenResolution = new Point(display.getWidth(), display.getHeight()); Log.d(TAG, "Screen resolution: " + screenResolution); cameraResolution = getCameraResolution(parameters, screenResolution); Log.d(TAG, "Camera resolution: " + screenResolution); }
18. ABTwitterLogInDialog#createCloseImage()
Project: appiaries-sdk-android
File: ABTwitterLogInDialog.java
File: ABTwitterLogInDialog.java
private void createCloseImage() { this.closeImage = new ImageView(getContext()); this.closeImage.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ABTwitterLogInDialog.this.cancel(); } }); Drawable closeDrawable = getContext().getResources().getDrawable(android.R.drawable.btn_dialog); // Drawable closeDrawable = getContext().getResources().getDrawable(android.R.drawable.ic_menu_close_clear_cancel); // Drawable closeDrawable = getContext().getResources().getDrawable(android.R.drawable.ic_notification_clear_all); this.closeImage.setImageDrawable(closeDrawable); WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); Display disp = wm.getDefaultDisplay(); int width = disp.getWidth(); int closeImageWidth = this.closeImage.getDrawable().getIntrinsicWidth(); // this.closeImage.setPadding(width - closeImageWidth, 0, 0, 0); this.closeImage.setPadding(0, 0, 0, 0); this.closeImage.setVisibility(View.INVISIBLE); }
19. Sound#configureVideo()
Project: Anki-Android
File: Sound.java
File: Sound.java
private static void configureVideo(VideoView videoView, int videoWidth, int videoHeight) { // get the display Context context = AnkiDroidApp.getInstance().getApplicationContext(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); // adjust the size of the video so it fits on the screen float videoProportion = (float) videoWidth / (float) videoHeight; int screenWidth = display.getWidth(); int screenHeight = display.getHeight(); float screenProportion = (float) screenWidth / (float) screenHeight; android.view.ViewGroup.LayoutParams lp = videoView.getLayoutParams(); if (videoProportion > screenProportion) { lp.width = screenWidth; lp.height = (int) ((float) screenWidth / videoProportion); } else { lp.width = (int) (videoProportion * (float) screenHeight); lp.height = screenHeight; } videoView.setLayoutParams(lp); }
20. FllowerAnimation#init()
Project: AndroidStudyDemo
File: FllowerAnimation.java
File: FllowerAnimation.java
private void init(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); width = wm.getDefaultDisplay().getWidth(); height = (int) (wm.getDefaultDisplay().getHeight() * 3 / 2f); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setStrokeWidth(2); mPaint.setColor(Color.BLUE); mPaint.setStyle(Paint.Style.STROKE); pathMeasure = new PathMeasure(); builderFollower(fllowerCount, fllowers1); builderFollower(fllowerCount, fllowers2); builderFollower(fllowerCount, fllowers3); }
21. SystemUtils#getDisplaySize()
Project: androidclient
File: SystemUtils.java
File: SystemUtils.java
public static Point getDisplaySize(Context context) { Point displaySize = null; WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); if (display != null) { displaySize = new Point(); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { displaySize.set(display.getWidth(), display.getHeight()); } else { display.getSize(displaySize); } } return displaySize; }
22. KeyboardAwareRelativeLayout#getKeyboardHeight()
Project: androidclient
File: KeyboardAwareRelativeLayout.java
File: KeyboardAwareRelativeLayout.java
public int getKeyboardHeight() { WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); if (wm == null || wm.getDefaultDisplay() == null) { throw new AssertionError("WindowManager was null or there is no default display"); } int rotation = wm.getDefaultDisplay().getRotation(); switch(rotation) { case Surface.ROTATION_270: case Surface.ROTATION_90: return getKeyboardLandscapeHeight(); case Surface.ROTATION_0: case Surface.ROTATION_180: default: return getKeyboardPortraitHeight(); } }
23. KeyboardAwareRelativeLayout#onKeyboardShown()
Project: androidclient
File: KeyboardAwareRelativeLayout.java
File: KeyboardAwareRelativeLayout.java
protected void onKeyboardShown(int keyboardHeight) { WindowManager wm = (WindowManager) getContext().getSystemService(Activity.WINDOW_SERVICE); if (wm == null || wm.getDefaultDisplay() == null) { return; } int rotation = wm.getDefaultDisplay().getRotation(); switch(rotation) { case Surface.ROTATION_270: case Surface.ROTATION_90: setKeyboardLandscapeHeight(keyboardHeight); break; case Surface.ROTATION_0: case Surface.ROTATION_180: setKeyboardPortraitHeight(keyboardHeight); } }
24. PtrLocalDisplay#init()
Project: android-Ultra-Pull-To-Refresh
File: PtrLocalDisplay.java
File: PtrLocalDisplay.java
public static void init(Context context) { if (context == null) { return; } DisplayMetrics dm = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(dm); SCREEN_WIDTH_PIXELS = dm.widthPixels; SCREEN_HEIGHT_PIXELS = dm.heightPixels; SCREEN_DENSITY = dm.density; SCREEN_WIDTH_DP = (int) (SCREEN_WIDTH_PIXELS / dm.density); SCREEN_HEIGHT_DP = (int) (SCREEN_HEIGHT_PIXELS / dm.density); }
25. CameraConfigurationManager#initFromCameraParameters()
Project: android-quick-response-code
File: CameraConfigurationManager.java
File: CameraConfigurationManager.java
/** * Reads, one time, values from the camera that are needed by the app. */ void initFromCameraParameters(Camera camera) { Camera.Parameters parameters = camera.getParameters(); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); // and reverse them: if (width < height) { Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect"); int temp = width; width = height; height = temp; } screenResolution = new Point(width, height); Log.i(TAG, "Screen resolution: " + screenResolution); cameraResolution = findBestPreviewSizeValue(parameters, screenResolution, false); Log.i(TAG, "Camera resolution: " + cameraResolution); }
26. DefaultCardStreamAnimator#getAppearingAnimator()
Project: android-play-places
File: DefaultCardStreamAnimator.java
File: DefaultCardStreamAnimator.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) @Override public ObjectAnimator getAppearingAnimator(Context context) { final Point outPoint = new Point(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getSize(outPoint); ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(new Object(), PropertyValuesHolder.ofFloat("alpha", 0.f, 1.f), PropertyValuesHolder.ofFloat("translationY", outPoint.y / 2.f, 0.f), PropertyValuesHolder.ofFloat("rotation", -45.f, 0.f)); animator.setDuration((long) (200 * mSpeedFactor)); return animator; }
27. DisplayUtil#init()
Project: android-open-project-demo
File: DisplayUtil.java
File: DisplayUtil.java
public static void init(Context context) { if (sInitialed || context == null) { return; } sInitialed = true; DisplayMetrics dm = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(dm); SCREEN_WIDTH_PIXELS = dm.widthPixels; SCREEN_HEIGHT_PIXELS = dm.heightPixels; SCREEN_DENSITY = dm.density; SCREEN_WIDTH_DP = (int) (SCREEN_WIDTH_PIXELS / dm.density); SCREEN_HEIGHT_DP = (int) (SCREEN_HEIGHT_PIXELS / dm.density); }
28. CameraConfigurationManager#initFromCameraParameters()
Project: android-ocr
File: CameraConfigurationManager.java
File: CameraConfigurationManager.java
/** * Reads, one time, values from the camera that are needed by the app. */ void initFromCameraParameters(Camera camera) { Camera.Parameters parameters = camera.getParameters(); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); // when waking from sleep. If it's not landscape, assume it's mistaken and reverse them: if (width < height) { Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect"); int temp = width; width = height; height = temp; } screenResolution = new Point(width, height); Log.i(TAG, "Screen resolution: " + screenResolution); cameraResolution = findBestPreviewSizeValue(parameters, screenResolution); Log.i(TAG, "Camera resolution: " + cameraResolution); }
29. TileBitmapDrawable#getDisplayMetrics()
Project: AcFun-Area63
File: TileBitmapDrawable.java
File: TileBitmapDrawable.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) private static void getDisplayMetrics(Context context, DisplayMetrics outMetrics) { final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); final Display display = wm.getDefaultDisplay(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { display.getRealMetrics(outMetrics); } else { display.getMetrics(outMetrics); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { try { outMetrics.widthPixels = (Integer) Display.class.getMethod("getRawWidth").invoke(display); outMetrics.heightPixels = (Integer) Display.class.getMethod("getRawHeight").invoke(display); return; } catch (Exception e) { } } } }
30. CameraConfigurationManager#initFromCameraParameters()
Project: ZXingProject
File: CameraConfigurationManager.java
File: CameraConfigurationManager.java
public void initFromCameraParameters(Camera camera) { Camera.Parameters parameters = camera.getParameters(); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); Point theScreenResolution = new Point(); theScreenResolution = getDisplaySize(display); screenResolution = theScreenResolution; Log.i(TAG, "Screen resolution: " + screenResolution); /** ????????????????????????????? */ Point screenResolutionForCamera = new Point(); screenResolutionForCamera.x = screenResolution.x; screenResolutionForCamera.y = screenResolution.y; if (screenResolution.x < screenResolution.y) { screenResolutionForCamera.x = screenResolution.y; screenResolutionForCamera.y = screenResolution.x; } cameraResolution = findBestPreviewSizeValue(parameters, screenResolutionForCamera); Log.i(TAG, "Camera resolution x: " + cameraResolution.x); Log.i(TAG, "Camera resolution y: " + cameraResolution.y); }
31. HomePageOnGestureListener#initEnv()
Project: YiBo
File: HomePageOnGestureListener.java
File: HomePageOnGestureListener.java
private void initEnv(Context context) { // ?????? WindowManager windowManager = ((Activity) context).getWindowManager(); Display display = windowManager.getDefaultDisplay(); DISPLAY_WINDOW_WIDTH = display.getWidth(); DISPLAY_WINDOW_HEIGHT = display.getHeight(); SLIDE_MIN_DISTANCE_X = (int) (DISPLAY_WINDOW_WIDTH * FACTOR_PORTRAIT); SLIDE_MAX_DISTANCE_Y = (int) (DISPLAY_WINDOW_HEIGHT * FACTOR_LANDSCAPE); SLIDE_MAX_DISTANCE_Y = 120; //orientation = context.getResources().getConfiguration().orientation; }
32. VideoPlayerActivity#getScreenRotation()
Project: VCL-Android
File: VideoPlayerActivity.java
File: VideoPlayerActivity.java
@SuppressWarnings("deprecation") private int getScreenRotation() { WindowManager wm = (WindowManager) VLCApplication.getAppContext().getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) /* Android 2.2 has getRotation */ { try { Method m = display.getClass().getDeclaredMethod("getRotation"); return (Integer) m.invoke(display); } catch (Exception e) { return Surface.ROTATION_0; } } else { return display.getOrientation(); } }
33. FloatingActionButton#init()
Project: UltimateRecyclerView
File: FloatingActionButton.java
File: FloatingActionButton.java
protected void init(Context context, AttributeSet attributeSet) { mColorNormal = getColor(android.R.color.holo_blue_dark); mColorPressed = getColor(android.R.color.holo_blue_light); mIcon = 0; mSize = SIZE_NORMAL; if (attributeSet != null) { initAttributes(context, attributeSet); } mCircleSize = getCircleSize(mSize); mShadowRadius = getDimension(R.dimen.fab_shadow_radius); mShadowOffset = getDimension(R.dimen.fab_shadow_offset); mDrawableSize = (int) (mCircleSize + 2 * mShadowRadius); //point size overhead WindowManager mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = mWindowManager.getDefaultDisplay(); Point size = new Point(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { display.getSize(size); mYHidden = size.y; } else mYHidden = display.getHeight(); updateBackground(); }
34. PullDoorView#setupView()
Project: UltimateAndroid
File: PullDoorView.java
File: PullDoorView.java
@SuppressLint("NewApi") private void setupView() { // ??Interpolator??????? ?????????????Interpolator Interpolator polator = new BounceInterpolator(); mScroller = new Scroller(mContext, polator); // ??????? WindowManager wm = (WindowManager) (mContext.getSystemService(Context.WINDOW_SERVICE)); DisplayMetrics dm = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(dm); mScreenHeigh = dm.heightPixels; mScreenWidth = dm.widthPixels; // ?????????????,???????????? this.setBackgroundColor(Color.argb(0, 0, 0, 0)); mImgView = new ImageView(mContext); mImgView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); // ?????? mImgView.setScaleType(ImageView.ScaleType.FIT_XY); // ???? mImgView.setImageResource(R.drawable.test); addView(mImgView); }
35. PullDoorView#setupView()
Project: UltimateAndroid
File: PullDoorView.java
File: PullDoorView.java
@SuppressLint("NewApi") private void setupView() { Interpolator polator = new BounceInterpolator(); mScroller = new Scroller(mContext, polator); WindowManager wm = (WindowManager) (mContext.getSystemService(Context.WINDOW_SERVICE)); DisplayMetrics dm = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(dm); mScreenHeigh = dm.heightPixels; mScreenWidth = dm.widthPixels; this.setBackgroundColor(Color.argb(0, 0, 0, 0)); mImgView = new ImageView(mContext); mImgView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); mImgView.setScaleType(ImageView.ScaleType.FIT_XY); mImgView.setImageResource(R.drawable.circle_button_ic_action_tick); addView(mImgView); }
36. Utils#init()
Project: UltimateAndroid
File: Utils.java
File: Utils.java
public static void init(Context context) { if (sInitialed || context == null) { return; } sInitialed = true; DisplayMetrics dm = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(dm); SCREEN_WIDTH_PIXELS = dm.widthPixels; SCREEN_HEIGHT_PIXELS = dm.heightPixels; SCREEN_DENSITY = dm.density; SCREEN_WIDTH_DP = (int) (SCREEN_WIDTH_PIXELS / dm.density); SCREEN_HEIGHT_DP = (int) (SCREEN_HEIGHT_PIXELS / dm.density); }
37. PictureUnit#fixBitmap()
Project: Tweetin
File: PictureUnit.java
File: PictureUnit.java
public static Bitmap fixBitmap(Context context, Bitmap bitmap) { WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics metrics = new DisplayMetrics(); manager.getDefaultDisplay().getMetrics(metrics); int screenWidth = metrics.widthPixels; int screenHeight = metrics.heightPixels; int bitmapWidth = bitmap.getWidth(); int bitmapHeight = bitmap.getHeight(); if (bitmapWidth > screenWidth || bitmapHeight > screenHeight) { float percentW = ((float) screenWidth) / ((float) bitmapWidth); float percentH = ((float) screenHeight) / ((float) bitmapHeight); float percent = percentW < percentH ? percentW : percentH; Matrix matrix = new Matrix(); matrix.postScale(percent, percent); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmapWidth, bitmapHeight, matrix, true); } return bitmap; }
38. CameraConfigurationManager#initFromCameraParameters()
Project: titanium-barcode
File: CameraConfigurationManager.java
File: CameraConfigurationManager.java
/** * Reads, one time, values from the camera that are needed by the app. */ void initFromCameraParameters(Camera camera) { Camera.Parameters parameters = camera.getParameters(); previewFormat = parameters.getPreviewFormat(); previewFormatString = parameters.get("preview-format"); Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); screenResolution = new Point(display.getWidth(), display.getHeight()); Log.d(TAG, "Screen resolution: " + screenResolution); cameraResolution = getCameraResolution(parameters, screenResolution); Log.d(TAG, "Camera resolution: " + screenResolution); }
39. OverlayController#configureOverlayBeforeShow()
Project: talkback
File: OverlayController.java
File: OverlayController.java
private void configureOverlayBeforeShow() { // The overlay shouldn't capture touch events final WindowManager.LayoutParams params = mOverlay.getParams(); params.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; params.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; params.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; /* The overlay covers the entire screen. However, there is a left, top, right, and * bottom margin. */ final WindowManager wm = (WindowManager) mOverlay.getContext().getSystemService(Context.WINDOW_SERVICE); final Point size = new Point(); wm.getDefaultDisplay().getRealSize(size); params.height = size.y; params.width = size.x; params.x = 0; params.y = 0; mOverlay.setParams(params); }
40. OverlayController#configureOverlayBeforeShow()
Project: talkback
File: OverlayController.java
File: OverlayController.java
private void configureOverlayBeforeShow() { // The overlay shouldn't capture touch events final WindowManager.LayoutParams params = mOverlay.getParams(); params.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; params.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; params.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; /* The overlay covers the entire screen. However, there is a left, top, right, and * bottom margin. */ final WindowManager wm = (WindowManager) mOverlay.getContext().getSystemService(Context.WINDOW_SERVICE); final Point size = new Point(); wm.getDefaultDisplay().getRealSize(size); params.height = size.y; params.width = size.x; params.x = 0; params.y = 0; mOverlay.setParams(params); }
41. ManagerSuperToast#removeSuperToast()
Project: SuperToasts
File: ManagerSuperToast.java
File: ManagerSuperToast.java
/* Hide and remove the SuperToast */ protected void removeSuperToast(SuperToast superToast) { final WindowManager windowManager = superToast.getWindowManager(); final View toastView = superToast.getView(); if (windowManager != null) { mQueue.poll(); windowManager.removeView(toastView); sendMessageDelayed(superToast, Messages.DISPLAY_SUPERTOAST, 500); if (superToast.getOnDismissListener() != null) { superToast.getOnDismissListener().onDismiss(superToast.getView()); } } }
42. CameraConfigurationManager#initFromCameraParameters()
Project: SimplifyReader
File: CameraConfigurationManager.java
File: CameraConfigurationManager.java
/** * Reads, one time, values from the camera that are needed by the app. */ void initFromCameraParameters(Camera camera) { Camera.Parameters parameters = camera.getParameters(); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); Point theScreenResolution = new Point(); theScreenResolution = getDisplaySize(display); screenResolution = theScreenResolution; Log.i(TAG, "Screen resolution: " + screenResolution); Point screenResolutionForCamera = new Point(); screenResolutionForCamera.x = screenResolution.x; screenResolutionForCamera.y = screenResolution.y; if (screenResolution.x < screenResolution.y) { screenResolutionForCamera.x = screenResolution.y; screenResolutionForCamera.y = screenResolution.x; } cameraResolution = CameraConfigurationUtils.findBestPreviewSizeValue(parameters, screenResolution); Log.i(TAG, "Camera resolution x: " + cameraResolution.x); Log.i(TAG, "Camera resolution y: " + cameraResolution.y); }
43. ApplicationTest#clickBottomMiddleScreen()
Project: RxActivityResult
File: ApplicationTest.java
File: ApplicationTest.java
private void clickBottomMiddleScreen() { WindowManager wm = (WindowManager) InstrumentationRegistry.getTargetContext().getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); int width = size.x; int height = size.y; uiDevice.click(width / 2, height - 100); waitTime(); }
44. Scroller#scrollToSide()
Project: robotium
File: Scroller.java
File: Scroller.java
/** * Scrolls horizontally. * * @param side the side to which to scroll; {@link Side#RIGHT} or {@link Side#LEFT} * @param scrollPosition the position to scroll to, from 0 to 1 where 1 is all the way. Example is: 0.55. * @param stepCount how many move steps to include in the scroll. Less steps results in a faster scroll */ @SuppressWarnings("deprecation") public void scrollToSide(Side side, float scrollPosition, int stepCount) { WindowManager windowManager = (WindowManager) inst.getTargetContext().getSystemService(Context.WINDOW_SERVICE); int screenHeight = windowManager.getDefaultDisplay().getHeight(); int screenWidth = windowManager.getDefaultDisplay().getWidth(); float x = screenWidth * scrollPosition; float y = screenHeight / 2.0f; if (side == Side.LEFT) drag(70, x, y, y, stepCount); else if (side == Side.RIGHT) drag(x, 0, y, y, stepCount); }
45. CameraPreview#getDisplayOrientation()
Project: react-native-barcodescanner
File: CameraPreview.java
File: CameraPreview.java
public int getDisplayOrientation() { Camera.CameraInfo info = new Camera.CameraInfo(); Camera.getCameraInfo(Camera.CameraInfo.CAMERA_FACING_BACK, info); WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int rotation = display.getRotation(); int degrees = 0; switch(rotation) { case Surface.ROTATION_0: degrees = 0; break; case Surface.ROTATION_90: degrees = 90; break; case Surface.ROTATION_180: degrees = 180; break; case Surface.ROTATION_270: degrees = 270; break; } int result; if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { result = (info.orientation + degrees) % 360; // compensate the mirror result = (360 - result) % 360; } else { // back-facing result = (info.orientation - degrees + 360) % 360; } return result; }
46. ModalHostShadowNode#addChildAt()
Project: react-native
File: ModalHostShadowNode.java
File: ModalHostShadowNode.java
/** * We need to set the styleWidth and styleHeight of the one child (represented by the <View/> * within the <RCTModalHostView/> in Modal.js. This needs to fill the entire window. */ @Override @TargetApi(16) public void addChildAt(CSSNode child, int i) { super.addChildAt(child, i); Context context = getThemedContext(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); // getCurrentSizeRange will return the min and max width and height that the window can be display.getCurrentSizeRange(mMinPoint, mMaxPoint); int width, height; int rotation = display.getRotation(); if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) { // If we are vertical the width value comes from min width and height comes from max height width = mMinPoint.x; height = mMaxPoint.y; } else { // If we are horizontal the width value comes from max width and height comes from min height width = mMaxPoint.x; height = mMinPoint.y; } child.setStyleWidth(width); child.setStyleHeight(height); }
47. CameraConfigurationManager#initFromCameraParameters()
Project: QiLi
File: CameraConfigurationManager.java
File: CameraConfigurationManager.java
/** * Reads, one time, values from the camera that are needed by the app. */ void initFromCameraParameters(Camera camera) { Camera.Parameters parameters = camera.getParameters(); previewFormat = parameters.getPreviewFormat(); previewFormatString = parameters.get("preview-format"); Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); screenResolution = new Point(display.getWidth(), display.getHeight()); Log.d(TAG, "Screen resolution: " + screenResolution); cameraResolution = getCameraResolution(parameters, screenResolution); Log.d(TAG, "Camera resolution: " + screenResolution); }
48. PXActionBarStyleAdapter#getActionBarBounds()
Project: pixate-freestyle-android
File: PXActionBarStyleAdapter.java
File: PXActionBarStyleAdapter.java
/** * Compute the {@link ActionBar} bounds. The computation is taking the * action-bar height value from the theme (in case the ActionBar does not * hold height information), and the actual screen width, to compute and * return the bounds. * * @param ab An {@link ActionBar} * @return A {@link RectF} description of the {@link ActionBar} bounds * (dimensions) */ public static RectF getActionBarBounds(ActionBar ab) { float height = ab.getHeight(); if (height <= 0) { // Unfortunately, we have to compute the ActionBar dimensions. Even // the height we get from the ActionBar styleable instance via // getHeight() is returned as zero. We get the height value from the // theme, and the width value from the screen. final TypedArray styledAttributes = PixateFreestyle.getAppContext().getTheme().obtainStyledAttributes(new int[] { android.R.attr.actionBarSize }); height = (int) styledAttributes.getDimension(0, 0); } // compute the width of the screen. Context context = PixateFreestyle.getAppContext(); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics dimension = new DisplayMetrics(); windowManager.getDefaultDisplay().getMetrics(dimension); return new RectF(0, 0, dimension.widthPixels, height); }
49. AnimateDialog#windowDeploy()
Project: phphub-android
File: AnimateDialog.java
File: AnimateDialog.java
public void windowDeploy() { window = getWindow(); window.setWindowAnimations(R.style.dialogWindow); //?????????? window.setBackgroundDrawableResource(R.drawable.bg_dialog); WindowManager.LayoutParams wl = window.getAttributes(); //??x?y????????????? //x??0?????0?? wl.x = 0; //y??0?????0?? wl.y = 0; // wl.alpha = 0.6f; //????? // wl.gravity = Gravity.BOTTOM; //???? window.setAttributes(wl); WindowManager m = window.getWindowManager(); Display d = m.getDefaultDisplay(); WindowManager.LayoutParams params = window.getAttributes(); params.width = (int) (d.getWidth() * this.widthProportion); params.height = (int) (d.getHeight() * this.heightProportion); window.setAttributes(params); }
50. Utility#getHorizontalCardCountInScreen()
Project: NHentai-android
File: Utility.java
File: Utility.java
public static int getHorizontalCardCountInScreen(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics dm = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(dm); float scale = context.getResources().getDisplayMetrics().density; int widthDps = (int) (dm.widthPixels / scale + 0.5f); int count = 2; Log.i("CardCount", "widthDps:" + widthDps); while (widthDps / count > 260) count++; while (widthDps / count < 180) count--; return count; }
51. VDVideoViewController#getScreen()
Project: NewsMe
File: VDVideoViewController.java
File: VDVideoViewController.java
/** * ???? * * @return */ public int[] getScreen() { if (mContext == null) { return mTmpArr; } WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); if (VDUtility.getSDKInt() > 13) { } DisplayMetrics metrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(metrics); int[] rect = { metrics.widthPixels, metrics.heightPixels }; return rect; }
52. ScreenUtils#getScreenSize()
Project: MultiImageSelector
File: ScreenUtils.java
File: ScreenUtils.java
public static Point getScreenSize(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point out = new Point(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { display.getSize(out); } else { int width = display.getWidth(); int height = display.getHeight(); out.set(width, height); } return out; }
53. AbstractMapOverlay#setDisplayBasedMinimumZoomLevel()
Project: MozStumbler
File: AbstractMapOverlay.java
File: AbstractMapOverlay.java
public static void setDisplayBasedMinimumZoomLevel(Context c) { WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); DisplayMetrics outMetrics = new DisplayMetrics(); display.getMetrics(outMetrics); if (outMetrics.widthPixels > 700) { sMinZoomLevelOfMapDisplaySizeBased = LARGE_SCREEN_MIN_ZOOM; } else if (outMetrics.widthPixels < 500) { sMinZoomLevelOfMapDisplaySizeBased = SMALL_SCREEN_MIN_ZOOM; } else { sMinZoomLevelOfMapDisplaySizeBased = MEDIUM_SCREEN_MIN_ZOOM; } }
54. CameraConfigurationManager#initFromCameraParameters()
Project: mobilot
File: CameraConfigurationManager.java
File: CameraConfigurationManager.java
/** * Reads, one time, values from the camera that are needed by the app. */ void initFromCameraParameters(Camera camera) { Camera.Parameters parameters = camera.getParameters(); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); // when waking from sleep. If it's not landscape, assume it's mistaken and reverse them: if (width < height) { Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect"); int temp = width; width = height; height = temp; } screenResolution = new Point(width, height); Log.i(TAG, "Screen resolution: " + screenResolution); cameraResolution = findBestPreviewSizeValue(parameters, screenResolution); Log.i(TAG, "Camera resolution: " + cameraResolution); }
55. CameraConfigurationManager#initFromCameraParameters()
Project: mobilot
File: CameraConfigurationManager.java
File: CameraConfigurationManager.java
/** * Reads, one time, values from the camera that are needed by the app. */ void initFromCameraParameters(Camera camera) { Camera.Parameters parameters = camera.getParameters(); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); // when waking from sleep. If it's not landscape, assume it's mistaken and reverse them: if (width < height) { Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect"); int temp = width; width = height; height = temp; } screenResolution = new Point(width, height); Log.i(TAG, "Screen resolution: " + screenResolution); cameraResolution = findBestPreviewSizeValue(parameters, screenResolution); Log.i(TAG, "Camera resolution: " + cameraResolution); }
56. CameraConfigurationManager#initFromCameraParameters()
Project: mobilot
File: CameraConfigurationManager.java
File: CameraConfigurationManager.java
/** * Reads, one time, values from the camera that are needed by the app. */ void initFromCameraParameters(Camera camera) { Camera.Parameters parameters = camera.getParameters(); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); // when waking from sleep. If it's not landscape, assume it's mistaken and reverse them: if (width < height) { Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect"); int temp = width; width = height; height = temp; } screenResolution = new Point(width, height); Log.i(TAG, "Screen resolution: " + screenResolution); cameraResolution = findBestPreviewSizeValue(parameters, screenResolution); Log.i(TAG, "Camera resolution: " + cameraResolution); }
57. MizLib#getActorUrlSize()
Project: Mizuu
File: MizLib.java
File: MizLib.java
public static String getActorUrlSize(Context c) { final int mImageThumbSize = c.getResources().getDimensionPixelSize(R.dimen.image_thumbnail_size); final int mImageThumbSpacing = c.getResources().getDimensionPixelSize(R.dimen.image_thumbnail_spacing); WindowManager window = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE); Display d = window.getDefaultDisplay(); Point size = new Point(); d.getSize(size); final int numColumns = (int) Math.floor(Math.max(size.x, size.y) / (mImageThumbSize + mImageThumbSpacing)); if (numColumns > 0) { final int columnWidth = (Math.max(size.x, size.y) / numColumns) - mImageThumbSpacing; if (columnWidth > 400) return "h632"; if (columnWidth >= 300) return "w300"; } return "w185"; }
58. MizLib#getBackdropThumbUrlSize()
Project: Mizuu
File: MizLib.java
File: MizLib.java
public static String getBackdropThumbUrlSize(Context c) { WindowManager window = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE); Display d = window.getDefaultDisplay(); Point size = new Point(); d.getSize(size); final int width = Math.min(size.x, size.y); if (width >= 780) return "w780"; if (width >= 400) return "w500"; return "w300"; }
59. MizLib#getBackdropUrlSize()
Project: Mizuu
File: MizLib.java
File: MizLib.java
public static String getBackdropUrlSize(Context c) { WindowManager window = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE); Display d = window.getDefaultDisplay(); Point size = new Point(); d.getSize(size); final int width = Math.max(size.x, size.y); if (// We only want to download full size images on tablets, as these are the only devices where you can see the difference width > 1280 && isTablet(c)) return "original"; else if (width > 780) return "w1280"; return "w780"; }
60. MizLib#getImageUrlSize()
Project: Mizuu
File: MizLib.java
File: MizLib.java
public static String getImageUrlSize(Context c) { final int mImageThumbSize = c.getResources().getDimensionPixelSize(R.dimen.image_thumbnail_size); final int mImageThumbSpacing = c.getResources().getDimensionPixelSize(R.dimen.image_thumbnail_spacing); WindowManager window = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE); Display d = window.getDefaultDisplay(); Point size = new Point(); d.getSize(size); final int numColumns = (int) Math.floor(Math.max(size.x, size.y) / (mImageThumbSize + mImageThumbSpacing)); if (numColumns > 0) { final int columnWidth = (Math.max(size.x, size.y) / numColumns) - mImageThumbSpacing; if (columnWidth > 300) return "w500"; else if (columnWidth > 185) return "w300"; } return "w185"; }
61. MizLib#getThumbnailSize()
Project: Mizuu
File: MizLib.java
File: MizLib.java
public static int getThumbnailSize(Context c) { final int mImageThumbSize = c.getResources().getDimensionPixelSize(R.dimen.image_thumbnail_size); final int mImageThumbSpacing = c.getResources().getDimensionPixelSize(R.dimen.image_thumbnail_spacing); WindowManager window = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE); Display d = window.getDefaultDisplay(); Point size = new Point(); d.getSize(size); final int numColumns = (int) Math.floor(Math.max(size.x, size.y) / (mImageThumbSize + mImageThumbSpacing)); if (numColumns > 0) { final int columnWidth = (Math.max(size.x, size.y) / numColumns) - mImageThumbSpacing; if (columnWidth > 320) return 440; else if (columnWidth > 240) return 320; else if (columnWidth > 180) return 240; } return 180; }
62. DecideChecker#getNotificationImage()
Project: mixpanel-android
File: DecideChecker.java
File: DecideChecker.java
private Bitmap getNotificationImage(InAppNotification notification, Context context, RemoteService poster) throws RemoteService.ServiceUnavailableException { String[] urls = { notification.getImage2xUrl(), notification.getImageUrl() }; final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); final Display display = wm.getDefaultDisplay(); final int displayWidth = getDisplayWidth(display); if (notification.getType() == InAppNotification.Type.TAKEOVER && displayWidth >= 720) { urls = new String[] { notification.getImage4xUrl(), notification.getImage2xUrl(), notification.getImageUrl() }; } for (String url : urls) { try { return mImageStore.getImage(url); } catch (ImageStore.CantGetImageException e) { Log.v(LOGTAG, "Can't load image " + url + " for a notification", e); } } return null; }
63. ResourceHelper#getScreenWidth()
Project: MaterialDesignSupport
File: ResourceHelper.java
File: ResourceHelper.java
public static int getScreenWidth() { Context context = CoreMaterialApplication.getContext(); if (context == null) { return -1; } WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); if (windowManager == null) { return -1; } Display display = windowManager.getDefaultDisplay(); if (display == null) { return -1; } DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); int width = metrics.widthPixels; return width; }
64. ResourceHelper#getScreenHeight()
Project: MaterialDesignSupport
File: ResourceHelper.java
File: ResourceHelper.java
public static int getScreenHeight() { Context context = CoreMaterialApplication.getContext(); if (context == null) { return -1; } WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); if (windowManager == null) { return -1; } Display display = windowManager.getDefaultDisplay(); if (display == null) { return -1; } DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); int height = metrics.heightPixels; return height; }
65. Degrees#getDisplayRotation()
Project: material-camera
File: Degrees.java
File: Degrees.java
@DegreeUnits public static int getDisplayRotation(Context context) { WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); int rotation = windowManager.getDefaultDisplay().getRotation(); switch(rotation) { case Surface.ROTATION_0: return DEGREES_0; case Surface.ROTATION_90: return DEGREES_90; case Surface.ROTATION_180: return DEGREES_180; case Surface.ROTATION_270: return DEGREES_270; } return DEGREES_0; }
66. PrefStore#getScreenHeight()
Project: linuxdeploy
File: PrefStore.java
File: PrefStore.java
/** * Get height of device screen * * @param c context * @return screen height */ @SuppressLint("NewApi") public static Integer getScreenHeight(Context c) { int height = 0; WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); if (Build.VERSION.SDK_INT > 12) { Point size = new Point(); display.getSize(size); height = size.y; } else { // deprecated height = display.getHeight(); } return height; }
67. PrefStore#getScreenWidth()
Project: linuxdeploy
File: PrefStore.java
File: PrefStore.java
/** * Get width of device screen * * @param c context * @return screen width */ @SuppressLint("NewApi") public static Integer getScreenWidth(Context c) { int width = 0; WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); if (Build.VERSION.SDK_INT > 12) { Point size = new Point(); display.getSize(size); width = size.x; } else { // deprecated width = display.getWidth(); } return width; }
68. LightTool#getRealScreenSize()
Project: light-novel-library_Wenku8_Android
File: LightTool.java
File: LightTool.java
public static Point getRealScreenSize(Context context) { WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = windowManager.getDefaultDisplay(); Point size = new Point(); if (Build.VERSION.SDK_INT >= 17) { display.getRealSize(size); } else if (Build.VERSION.SDK_INT >= 14) { try { size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display); size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display); } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } catch (NoSuchMethodException e) { } } return size; }
69. DisplayUtil#getScreenHeight()
Project: Leisure
File: DisplayUtil.java
File: DisplayUtil.java
public static int getScreenHeight(Context context) { if (screenHeight != -1) { return screenHeight; } WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics dm = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(dm); screenHeight = dm.heightPixels; return screenHeight; }
70. DisplayUtil#getScreenWidth()
Project: Leisure
File: DisplayUtil.java
File: DisplayUtil.java
public static int getScreenWidth(Context context) { if (screenWidth != -1) { return screenWidth; } WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics dm = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(dm); screenWidth = dm.widthPixels; return screenWidth; }
71. MainFragment#initImageLine()
Project: KJMusic
File: MainFragment.java
File: MainFragment.java
/** * ??????????????? * * @param pagers * viewpager???? */ private void initImageLine(View parentView, int pagers) { mImgLine = (ImageView) parentView.findViewById(R.id.collect_cursor); // ???????bitmap Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_collect_line); // ???????? WindowManager window = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE); int screenW = DensityUtils.getScreenW(getActivity()); Matrix matrix = new Matrix(); // ????(????/???)??????????????1 matrix.postScale((screenW / pagers) / bitmap.getWidth(), 1); // ??????? bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); // matrix.postTranslate(offset, 0);//?????? // mImgLine.setImageMatrix(matrix);// ???????? // ??ImageView??? mImgLine.setImageBitmap(bitmap); bitmap = null; }
72. Explode#setupVariables()
Project: intent-intercept
File: Explode.java
File: Explode.java
private void setupVariables() { action = (EditText) findViewById(R.id.action); data = (EditText) findViewById(R.id.data); type = (EditText) findViewById(R.id.type); uri = (EditText) findViewById(R.id.uri); categoriesHeader = (TextView) findViewById(R.id.categories_header); categoriesLayout = (LinearLayout) findViewById(R.id.categories_layout); flagsLayout = (LinearLayout) findViewById(R.id.flags_layout); extrasLayout = (LinearLayout) findViewById(R.id.extras_layout); activitiesHeader = (TextView) findViewById(R.id.activities_header); activitiesLayout = (LinearLayout) findViewById(R.id.activities_layout); resendIntentButton = (Button) findViewById(R.id.resend_intent_button); resetIntentButton = (Button) findViewById(R.id.reset_intent_button); DisplayMetrics metrics = new DisplayMetrics(); WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(metrics); density = metrics.density; }
73. Compatibility#getScreenDimensions()
Project: hosts-editor-android
File: Compatibility.java
File: Compatibility.java
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) public static Point getScreenDimensions(Context context) { Point size = new Point(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); if (Compatibility.isCompatible(Build.VERSION_CODES.HONEYCOMB_MR2)) { display.getSize(size); } else { size.set(display.getWidth(), display.getHeight()); } return size; }
74. ScreenUtils#getScreenSize()
Project: HeartBeat
File: ScreenUtils.java
File: ScreenUtils.java
public static Point getScreenSize(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point out = new Point(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { display.getSize(out); } else { int width = display.getWidth(); int height = display.getHeight(); out.set(width, height); } return out; }
75. ScreenHelper#calculateScreenDimensions()
Project: ExpandableButtonMenu
File: ScreenHelper.java
File: ScreenHelper.java
private static void calculateScreenDimensions(Context context) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { final Point point = new Point(); display.getSize(point); mWidth = point.x; mHeight = point.y; } else { mWidth = display.getWidth(); mHeight = display.getHeight(); } }
76. VideoFormatSelectorUtil#getViewportSize()
Project: ExoPlayer
File: VideoFormatSelectorUtil.java
File: VideoFormatSelectorUtil.java
private static Point getViewportSize(Context context) { // See also https://developer.sony.com/develop/tvs/android-tv/design-guide/. if (Util.SDK_INT < 23 && Util.MODEL != null && Util.MODEL.startsWith("BRAVIA") && context.getPackageManager().hasSystemFeature("com.sony.dtv.hardware.panel.qfhd")) { return new Point(3840, 2160); } WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); return getDisplaySize(windowManager.getDefaultDisplay()); }
77. CameraConfigurationManager#initFromCameraParameters()
Project: ExhibitionCenter
File: CameraConfigurationManager.java
File: CameraConfigurationManager.java
/** * Reads, one time, values from the camera that are needed by the app. */ @SuppressLint("NewApi") void initFromCameraParameters(Camera camera) { Camera.Parameters parameters = camera.getParameters(); WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display display = manager.getDefaultDisplay(); Point theScreenResolution = new Point(display.getWidth(), display.getHeight()); screenResolution = theScreenResolution; Log.i(TAG, "Screen resolution: " + screenResolution); /************** ???? ******************/ Point screenResolutionForCamera = new Point(); screenResolutionForCamera.x = screenResolution.x; screenResolutionForCamera.y = screenResolution.y; cameraResolution = CameraConfigurationUtils.findBestPreviewSizeValue(parameters, screenResolutionForCamera); Log.i(TAG, "Camera resolution: " + cameraResolution); }
78. LocalDisplay#init()
Project: cube-sdk
File: LocalDisplay.java
File: LocalDisplay.java
public static void init(Context context) { if (sInitialed || context == null) { return; } sInitialed = true; DisplayMetrics dm = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(dm); SCREEN_WIDTH_PIXELS = dm.widthPixels; SCREEN_HEIGHT_PIXELS = dm.heightPixels; SCREEN_DENSITY = dm.density; SCREEN_WIDTH_DP = (int) (SCREEN_WIDTH_PIXELS / dm.density); SCREEN_HEIGHT_DP = (int) (SCREEN_HEIGHT_PIXELS / dm.density); }
79. PtrLocalDisplay#init()
Project: CommonPullToRefresh
File: PtrLocalDisplay.java
File: PtrLocalDisplay.java
public static void init(Context context) { if (context == null) { return; } DisplayMetrics dm = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(dm); SCREEN_WIDTH_PIXELS = dm.widthPixels; SCREEN_HEIGHT_PIXELS = dm.heightPixels; SCREEN_DENSITY = dm.density; SCREEN_WIDTH_DP = (int) (SCREEN_WIDTH_PIXELS / dm.density); SCREEN_HEIGHT_DP = (int) (SCREEN_HEIGHT_PIXELS / dm.density); }
80. PtrLocalDisplay#init()
Project: CommonPullToRefresh
File: PtrLocalDisplay.java
File: PtrLocalDisplay.java
public static void init(Context context) { if (context == null) { return; } DisplayMetrics dm = new DisplayMetrics(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); wm.getDefaultDisplay().getMetrics(dm); SCREEN_WIDTH_PIXELS = dm.widthPixels; SCREEN_HEIGHT_PIXELS = dm.heightPixels; SCREEN_DENSITY = dm.density; SCREEN_WIDTH_DP = (int) (SCREEN_WIDTH_PIXELS / dm.density); SCREEN_HEIGHT_DP = (int) (SCREEN_HEIGHT_PIXELS / dm.density); }
81. CCDirector#getAppFrameRect()
Project: cocos2d
File: CCDirector.java
File: CCDirector.java
private CGRect getAppFrameRect(float targetRatio) { WindowManager w = theApp.getWindowManager(); CGSize size = CGSize.make(w.getDefaultDisplay().getWidth(), w.getDefaultDisplay().getHeight()); float currentRation = size.width / size.height; CGSize newSize = CGSize.make(size.width, size.height); CGPoint offset = CGPoint.make(0, 0); if (currentRation > targetRatio) { newSize.width = targetRatio * size.height; offset.x = (size.width - newSize.width) / 2; } else if (currentRation < targetRatio) { newSize.height = size.width / targetRatio; offset.y = (size.height - newSize.height) / 2; } CGRect rect = CGRect.make(offset, newSize); return rect; }
82. CCDirector#attachInView()
Project: cocos2d
File: CCDirector.java
File: CCDirector.java
/** attach in UIView using the full frame. It will create a EAGLView. deprecated set setOpenGLView instead. Will be removed in v1.0 */ public boolean attachInView(View view) { // CCRect rect = new CCRect(view.getScrollX(), view.getScrollY(), view.getWidth(), view.getHeight()); WindowManager w = theApp.getWindowManager(); CGRect rect = CGRect.make(0, 0, w.getDefaultDisplay().getWidth(), w.getDefaultDisplay().getHeight()); return initOpenGLViewWithView(view, rect); /* if([self initOpenGLViewWithView:view withFrame:[view bounds]]) { return YES; } return NO; */ }
83. ContentViewCore#sendOrientationChangeEvent()
Project: chromium_webview
File: ContentViewCore.java
File: ContentViewCore.java
/** * Get the screen orientation from the OS and push it to WebKit. * * TODO(husky): Add a hook for mock orientations. */ private void sendOrientationChangeEvent() { if (mNativeContentViewCore == 0) return; WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); switch(windowManager.getDefaultDisplay().getRotation()) { case Surface.ROTATION_90: nativeSendOrientationChangeEvent(mNativeContentViewCore, 90); break; case Surface.ROTATION_180: nativeSendOrientationChangeEvent(mNativeContentViewCore, 180); break; case Surface.ROTATION_270: nativeSendOrientationChangeEvent(mNativeContentViewCore, -90); break; case Surface.ROTATION_0: nativeSendOrientationChangeEvent(mNativeContentViewCore, 0); break; default: Log.w(TAG, "Unknown rotation!"); break; } }
84. MainNativeActivity#setupControlViews()
Project: android-openslmediaplayer
File: MainNativeActivity.java
File: MainNativeActivity.java
@SuppressLint({ "InflateParams", "RtlHardcoded" }) private void setupControlViews() { // Create overlay window final WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); final LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); final Rect rectangle = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(rectangle); final int StatusBarHeight = rectangle.top; RelativeLayout controls = (RelativeLayout) inflater.inflate(R.layout.controls, null, true); WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_APPLICATION_PANEL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, PixelFormat.TRANSLUCENT); params.y = StatusBarHeight; params.width = WindowManager.LayoutParams.WRAP_CONTENT; params.height = WindowManager.LayoutParams.WRAP_CONTENT; params.gravity = Gravity.RIGHT | Gravity.TOP; wm.addView(controls, params); mControlsView = controls; mButtonOpenMedia = (Button) controls.findViewById(R.id.buttonOpenMedia); mButtonPlay = (Button) controls.findViewById(R.id.buttonPlay); mButtonPause = (Button) controls.findViewById(R.id.buttonPause); mButtonAbout = (Button) controls.findViewById(R.id.buttonAbout); mButtonOpenMedia.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MainNativeActivity.this.onOpenMediaButtonClicked(); } }); mButtonPlay.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MainNativeActivity.this.onPlayButtonClicked(); } }); mButtonPause.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MainNativeActivity.this.onPauseButtonClicked(); } }); mButtonAbout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MainNativeActivity.this.onAboutButtonClicked(); } }); }
85. FloatingWindowActivity#addWindow()
Project: PracticeDemo
File: FloatingWindowActivity.java
File: FloatingWindowActivity.java
private void addWindow() { //WindowManager manager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); WindowManager manager = getWindowManager(); // Point point = new Point(); // manager.getDefaultDisplay().getSize(point); //??????? int w = WindowManager.LayoutParams.MATCH_PARENT; int h = WindowManager.LayoutParams.MATCH_PARENT; WindowManager.LayoutParams lp = new WindowManager.LayoutParams(w, h, WindowManager.LayoutParams.TYPE_TOAST, 0, PixelFormat.TRANSLUCENT); // lp.height = 100; // lp.width = 100; // lp.horizontalMargin = 20; // lp.verticalMargin = 20; lp.gravity = Gravity.TOP; // lp.x = 50; // lp.y = 50; View v = new View(FloatingWindowActivity.this); v.setBackgroundColor(Color.rgb(122, 121, 122)); v.setOnClickListener( view -> { Toast.makeText(FloatingWindowActivity.this, "CLicked", Toast.LENGTH_SHORT).show(); manager.removeView(view); }); manager.addView(v, lp); }
86. PlumbleOverlay#show()
Project: Plumble
File: PlumbleOverlay.java
File: PlumbleOverlay.java
public void show() { if (mShown) return; mShown = true; mChannelAdapter = new ChannelAdapter(mService, mService.getSessionChannel()); mOverlayList.setAdapter(mChannelAdapter); mService.registerObserver(mObserver); WindowManager windowManager = (WindowManager) mService.getSystemService(Context.WINDOW_SERVICE); windowManager.addView(mOverlayView, mOverlayParams); }
87. RemoveViewConstructorTest#testConstructor()
Project: Magnet
File: RemoveViewConstructorTest.java
File: RemoveViewConstructorTest.java
@Test public void testConstructor() throws Exception { // given Context contextMock = mock(Context.class); LayoutInflater layoutInflaterMock = mock(LayoutInflater.class); mockStatic(LayoutInflater.class); when(LayoutInflater.from(contextMock)).thenReturn(layoutInflaterMock); View layoutMock = mock(View.class); View buttonMock = mock(View.class); View shadowMock = mock(View.class); ImageView buttonImageMock = mock(ImageView.class); WindowManager windowManagerMock = mock(WindowManager.class); SimpleAnimator simpleAnimatorMock = mock(SimpleAnimator.class); int buttonBottomPaddingTest = 10; whenNew(SimpleAnimator.class).withAnyArguments().thenReturn(simpleAnimatorMock); doReturn(layoutMock).when(layoutInflaterMock).inflate(R.layout.x_button_holder, null); doReturn(buttonMock).when(layoutMock).findViewById(R.id.xButton); doReturn(shadowMock).when(layoutMock).findViewById(R.id.shadow); doReturn(buttonImageMock).when(layoutMock).findViewById(R.id.xButtonImg); doReturn(windowManagerMock).when(contextMock).getSystemService(Context.WINDOW_SERVICE); doReturn(buttonBottomPaddingTest).when(buttonMock).getPaddingBottom(); WindowManager.LayoutParams paramsMock = mock(WindowManager.LayoutParams.class); whenNew(WindowManager.LayoutParams.class).withAnyArguments().thenReturn(paramsMock); // when RemoveView removeView = new RemoveView(contextMock); // then View mLayout = getInternalState(removeView, "mLayout"); View mButton = getInternalState(removeView, "mButton"); View mShadow = getInternalState(removeView, "mShadow"); View mButtonImage = getInternalState(removeView, "mButtonImage"); WindowManager mWindowManager = getInternalState(removeView, "mWindowManager"); int buttonBottomPadding = getInternalState(removeView, "buttonBottomPadding"); // Verify all the fields set and view added to window assertEquals("RemoveView's mLayout field must be equal to the return value of LayoutInflater.from() method.", layoutMock, mLayout); assertEquals("RemoveView's mButton field must be equal to the return value of mLayout.findViewById(R.id.xButton) method.", buttonMock, mButton); assertEquals("RemoveView's mShadow field must be equal to the return value of mLayout.findViewById(R.id.shadow) method.", shadowMock, mShadow); assertEquals("RemoveView's mButtonImage field must be equal to the return value of mLayout.findViewById(R.id.xButtonImg) method.", buttonImageMock, mButtonImage); assertEquals("RemoveView's mWindowManager field must be equal to the return value of contextMock.getSystemService(Context.WINDOW_SERVICE) method.", windowManagerMock, mWindowManager); assertEquals("RemoveView's buttonBottomPadding field must be equal to the return value of mButton.getPaddingBottom() method.", buttonBottomPaddingTest, buttonBottomPadding); verify(mWindowManager).addView(layoutMock, paramsMock); }
88. Mixture#show()
Project: frenchtoast
File: Mixture.java
File: Mixture.java
@MainThread public void show() { assertMainThread(); View view = toast.getView(); if (view == null) { throw new IllegalStateException("Can't show a Toast with no View."); } Context context = toast.getView().getContext(); WindowManager windowManager = (WindowManager) context.getSystemService(WINDOW_SERVICE); // We can resolve the Gravity here by using the Locale for getting // the layout direction Configuration config = view.getContext().getResources().getConfiguration(); int gravity = toast.getGravity(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { gravity = Gravity.getAbsoluteGravity(gravity, config.getLayoutDirection()); } params.gravity = gravity; if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) { params.horizontalWeight = 1.0f; } if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) { params.verticalWeight = 1.0f; } params.x = toast.getXOffset(); params.y = toast.getYOffset(); params.verticalMargin = toast.getVerticalMargin(); params.horizontalMargin = toast.getHorizontalMargin(); params.packageName = context.getPackageName(); if (view.getParent() != null) { windowManager.removeView(view); } windowManager.addView(view, params); trySendAccessibilityEvent(view); }
89. NotifyUtils#showGoudaToast()
Project: Conquer
File: NotifyUtils.java
File: NotifyUtils.java
/** * ????????????????????????? * @param context * @param card */ public static void showGoudaToast(final Context context, final Card card) { /** ???????????????User??BmobChatUser???????????? */ final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); final View view = View.inflate(context, R.layout.toast_gouda_notify, null); ImageView iv_bell = (ImageView) view.findViewById(R.id.iv_bell); TextView tv_type = (TextView) view.findViewById(R.id.tv_type); TextView tv_from = (TextView) view.findViewById(R.id.tv_from); SimpleDraweeView iv_avatar = (SimpleDraweeView) view.findViewById(R.id.iv_avatar); TextView tv_zixitime = (TextView) view.findViewById(R.id.tv_zixitime); TextView tv_zixiname = (TextView) view.findViewById(R.id.tv_zixiname); TextView tv_content = (TextView) view.findViewById(R.id.tv_content); tv_type.setText("????"); tv_from.setText("??:" + card.getFnick()); tv_zixitime.setText(TaskUtil.getZixiDateS(card.getTime()) + " " + TaskUtil.getZixiTimeS(card.getTime())); tv_zixiname.setText(card.getZixiName()); tv_content.setText(card.getContent()); iv_avatar.setImageURI(Uri.parse(card.getFavatar())); // ???? iv_bell.setBackgroundResource(R.drawable.alert_bell_anim); AnimationDrawable draw = (AnimationDrawable) iv_bell.getBackground(); draw.start(); final WindowManager.LayoutParams params = new WindowManager.LayoutParams(); DisplayMetrics metrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(metrics); params.height = metrics.heightPixels / 2; params.width = WindowManager.LayoutParams.MATCH_PARENT; params.gravity = Gravity.BOTTOM; params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; // params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | // WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE // | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; params.format = PixelFormat.TRANSLUCENT; params.type = WindowManager.LayoutParams.TYPE_PHONE; params.windowAnimations = android.R.style.Animation_InputMethod; wm.addView(view, params); // ?????? // ???? view.findViewById(R.id.ib_decline).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { removeMyToast(wm, view); } }); // ???? view.findViewById(R.id.iv_add_black).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { removeMyToast(wm, view); BmobUserManager.getInstance(context).addBlack(card.getFusername(), new UpdateListener() { @Override public void onSuccess() { T.show(context, "???????!"); // ??????????????? CustomApplication.getInstance().setContactList(CollectionUtils.list2map(BmobDB.create(context).getContactList())); BmobDB.create(context).addBlack(card.getFusername()); } @Override public void onFailure(int arg0, String arg1) { T.show(context, "???????:" + arg1); } }); } }); // ???? view.findViewById(R.id.iv_accept).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { removeMyToast(wm, view); final BmobInvitation invitation = new BmobInvitation(card.getFid(), card.getFusername(), "", "", System.currentTimeMillis(), 1); BmobUserManager.getInstance(context).agreeAddContact(invitation, new UpdateListener() { @Override public void onSuccess() { saveCard(context, card); BmobUserManager.getInstance(context).queryCurrentContactList(new FindListener<BmobChatUser>() { @Override public void onError(int arg0, String arg1) { L.i("?????????" + arg1); } @Override public void onSuccess(List<BmobChatUser> arg0) { T.show(context, "??" + card.getFnick() + "?????"); // ???application????? CustomApplication.getInstance().setContactList(CollectionUtils.list2map(arg0)); } }); // BmobDB.create(context).saveContact(invitation); // CustomApplication.getInstance().setContactList(CollectionUtils.list2map(BmobDB.create(context).getContactList())); } @Override public void onFailure(int arg0, String arg1) { T.show(context, "????????:" + arg1); } }); } }); }
90. NotifyUtils#showZixiAlertToast()
Project: Conquer
File: NotifyUtils.java
File: NotifyUtils.java
/** * ???????????? * @param context * @param card */ public static void showZixiAlertToast(final Context context, final Card card) { final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); final View view = View.inflate(context, R.layout.toast_alert_notify, null); ImageView iv_bell = (ImageView) view.findViewById(R.id.iv_bell); ImageView iv_photo = (ImageView) view.findViewById(R.id.iv_photo); TextView tv_type = (TextView) view.findViewById(R.id.tv_type); TextView tv_from = (TextView) view.findViewById(R.id.tv_from); TextView tv_zixitime = (TextView) view.findViewById(R.id.tv_zixitime); TextView tv_zixiname = (TextView) view.findViewById(R.id.tv_zixiname); TextView tv_content = (TextView) view.findViewById(R.id.tv_content); ViewGroup ll_audio = (ViewGroup) view.findViewById(R.id.ll_audio); final ImageButton ib_play = (ImageButton) view.findViewById(R.id.ib_play); final ProgressBar pb = (ProgressBar) view.findViewById(R.id.pb); ImageLoader.getInstance().displayImage(card.getFavatar(), iv_photo, ImageLoadOptions.getOptions()); tv_type.setText("????"); tv_from.setText("???" + card.getFnick()); tv_zixitime.setText(TaskUtil.getZixiTimeS(card.getTime()) + " " + TaskUtil.getZixiDateS(card.getTime())); tv_zixiname.setText(card.getZixiName()); tv_content.setText(card.getContent()); ll_audio.setVisibility(card.getAudioUrl() != null ? View.VISIBLE : View.GONE); // ?????????????????? TaskUtil.setZixiHasAlerted(context, card.getZixiId()); ib_play.setTag("play"); ib_play.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ib_play.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (ib_play.getTag().equals("play")) { ib_play.setImageResource(R.drawable.pause_audio); ib_play.setTag("pause"); palyAudio(context, ib_play, pb, card.getAudioUrl()); } else { ib_play.setTag("play"); ib_play.setImageResource(R.drawable.play_audio); pauseAudio(ib_play); } } }); } }); // ???? iv_bell.setBackgroundResource(R.drawable.alert_bell_anim); AnimationDrawable draw = (AnimationDrawable) iv_bell.getBackground(); draw.start(); final WindowManager.LayoutParams params = new WindowManager.LayoutParams(); DisplayMetrics metrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(metrics); params.height = WindowManager.LayoutParams.MATCH_PARENT; params.width = WindowManager.LayoutParams.MATCH_PARENT; params.gravity = Gravity.BOTTOM; params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; // params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | // WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE // | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; params.format = PixelFormat.TRANSLUCENT; params.type = WindowManager.LayoutParams.TYPE_PHONE; params.windowAnimations = android.R.style.Animation_InputMethod; wm.addView(view, params); // ????? view.findViewById(R.id.ll_save).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { removeMyToast(wm, view); saveCard(context, card); } }); }
91. DragNDropListView#startDrag()
Project: codeexamples-android
File: DragNDropListView.java
File: DragNDropListView.java
// enable the drag view for dragging private void startDrag(int itemIndex, int y) { stopDrag(itemIndex); View item = getChildAt(itemIndex); if (item == null) return; item.setDrawingCacheEnabled(true); if (mDragListener != null) mDragListener.onStartDrag(item); // Create a copy of the drawing cache so that it does not get recycled // by the framework when the list tries to clean up memory Bitmap bitmap = Bitmap.createBitmap(item.getDrawingCache()); WindowManager.LayoutParams mWindowParams = new WindowManager.LayoutParams(); mWindowParams.gravity = Gravity.TOP; mWindowParams.x = 0; mWindowParams.y = y - mDragPointOffset; mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT; mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT; mWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; mWindowParams.format = PixelFormat.TRANSLUCENT; mWindowParams.windowAnimations = 0; Context context = getContext(); ImageView v = new ImageView(context); v.setImageBitmap(bitmap); WindowManager mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); mWindowManager.addView(v, mWindowParams); mDragView = v; }
92. FloatingActionMenu#show()
Project: Carbon
File: FloatingActionMenu.java
File: FloatingActionMenu.java
public boolean show() { int[] location = new int[2]; anchor.getLocationOnScreen(location); WindowManager wm = (WindowManager) anchor.getContext().getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); boolean left = location[0] < display.getWidth() + anchor.getWidth() - location[0]; boolean top = location[1] < display.getHeight() + anchor.getHeight() - location[1]; super.showAtLocation(anchor, Gravity.TOP | Gravity.LEFT, 0, 0); if (!left & top) { // right top update(location[0] - content.getMeasuredWidth() + anchor.getWidth(), location[1] + anchor.getHeight(), content.getMeasuredWidth(), content.getMeasuredHeight()); } else if (!left & !top) { // right bottom update(location[0] - content.getMeasuredWidth() + anchor.getWidth(), location[1] - content.getMeasuredHeight(), content.getMeasuredWidth(), content.getMeasuredHeight()); } else if (left & !top) { // left bottom update(location[0], location[1] - content.getMeasuredHeight(), content.getMeasuredWidth(), content.getMeasuredHeight()); } else { // left top update(location[0], location[1] + anchor.getHeight(), content.getMeasuredWidth(), content.getMeasuredHeight()); } for (int i = 0; i < menu.size(); i++) { final int finalI = i; handler.postDelayed(new Runnable() { @Override public void run() { content.getChildAt(finalI).setVisibility(View.VISIBLE); } }, top ? i * 50 : (menu.size() - 1 - i) * 50); } return true; }
93. FloatingActionMenu#build()
Project: Carbon
File: FloatingActionMenu.java
File: FloatingActionMenu.java
public void build() { int[] location = new int[2]; anchor.getLocationOnScreen(location); WindowManager wm = (WindowManager) anchor.getContext().getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); boolean left = location[0] < display.getWidth() + anchor.getWidth() - location[0]; content.removeAllViews(); for (int i = 0; i < menu.size(); i++) { final MenuItem item = menu.getItem(i); LayoutInflater inflater = LayoutInflater.from(content.getContext()); final LinearLayout view = (LinearLayout) inflater.inflate(left ? R.layout.carbon_floatingactionmenu_left : R.layout.carbon_floatingactionmenu_right, content, false); TextView tooltip = (TextView) view.findViewById(R.id.carbon_tooltip); FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.carbon_fab); tooltip.setText(item.getTitle()); fab.setImageDrawable(item.getIcon()); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (listener != null) listener.onMenuItemClick(item); dismiss(); } }); content.addView(view); view.setVisibilityImmediate(View.INVISIBLE); } content.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); }
94. SeekBarPopup#showImmediate()
Project: Carbon
File: SeekBarPopup.java
File: SeekBarPopup.java
public boolean showImmediate(View anchor) { super.showAtLocation(anchor, Gravity.START | Gravity.TOP, 0, 0); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); contentView.measure(View.MeasureSpec.makeMeasureSpec(wm.getDefaultDisplay().getWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); super.update(wm.getDefaultDisplay().getWidth(), contentView.getMeasuredHeight()); bubble.setVisibilityImmediate(View.VISIBLE); return true; }
95. SeekBarPopup#update()
Project: Carbon
File: SeekBarPopup.java
File: SeekBarPopup.java
@Override public void update(int x, int y) { WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); super.update(0, y, wm.getDefaultDisplay().getWidth(), contentView.getMeasuredHeight()); ViewHelper.setTranslationX(bubble, x); }
96. SwipeLayout#init()
Project: can_delete_listview
File: SwipeLayout.java
File: SwipeLayout.java
void init() { viewDragHelper = ViewDragHelper.create(this, new DragHelperCallback()); /** * ?????? */ WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics outMetrics = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(outMetrics); screenWidth = outMetrics.widthPixels; }
97. ThemeAdapter#setDisplaySize()
Project: cannonball-android
File: ThemeAdapter.java
File: ThemeAdapter.java
private void setDisplaySize() { final WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); final Display display = wm.getDefaultDisplay(); final Point p = new Point(); display.getSize(p); final Float ht_px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, HEADER_LAYOUT_HEIGHT, getContext().getResources().getDisplayMetrics()); height = (p.y - ht_px.intValue()) / Theme.values().length; width = p.x; }
98. ScreenshotUtils#createScreenshot()
Project: brailleback
File: ScreenshotUtils.java
File: ScreenshotUtils.java
/** * Returns a screenshot with the contents of the current display that * matches the current display rotation. * * @param context The current context. * @return A bitmap of the screenshot. */ public static Bitmap createScreenshot(Context context) { if (!hasScreenshotPermission(context)) { LogUtils.log(ScreenshotUtils.class, Log.ERROR, "Screenshot permission denied."); return null; } final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); final Bitmap bitmap = SurfaceControlCompatUtils.screenshot(0, 0); // Bail if we couldn't take the screenshot. if (bitmap == null) { LogUtils.log(ScreenshotUtils.class, Log.ERROR, "Failed to take screenshot."); return null; } final int width = bitmap.getWidth(); final int height = bitmap.getHeight(); final int rotation = windowManager.getDefaultDisplay().getRotation(); final int outWidth; final int outHeight; final float rotationDegrees; switch(rotation) { case Surface.ROTATION_90: outWidth = height; outHeight = width; rotationDegrees = 90; break; case Surface.ROTATION_180: outWidth = width; outHeight = height; rotationDegrees = 180; break; case Surface.ROTATION_270: outWidth = height; outHeight = width; rotationDegrees = 270; break; default: return bitmap; } // Rotate the screenshot to match the screen orientation. final Bitmap rotatedBitmap = Bitmap.createBitmap(outWidth, outHeight, Bitmap.Config.RGB_565); final Canvas c = new Canvas(rotatedBitmap); c.translate(outWidth / 2.0f, outHeight / 2.0f); c.rotate(-rotationDegrees); c.translate(-width / 2.0f, -height / 2.0f); c.drawBitmap(bitmap, 0, 0, null); bitmap.recycle(); return rotatedBitmap; }
99. ManagerSuperToast#displaySuperToast()
Project: Bitocle
File: ManagerSuperToast.java
File: ManagerSuperToast.java
/* Displays a SuperToast */ private void displaySuperToast(SuperToast superToast) { if (superToast.isShowing()) { return; } final WindowManager windowManager = superToast.getWindowManager(); final View toastView = superToast.getView(); final WindowManager.LayoutParams params = superToast.getWindowManagerParams(); if (windowManager != null) { windowManager.addView(toastView, params); } sendMessageDelayed(superToast, Messages.REMOVE_SUPERTOAST, superToast.getDuration() + 500); }
100. ManagerSuperToast#displaySuperToast()
Project: Bitocle
File: ManagerSuperToast.java
File: ManagerSuperToast.java
/* Displays a SuperToast */ private void displaySuperToast(SuperToast superToast) { if (superToast.isShowing()) { return; } final WindowManager windowManager = superToast.getWindowManager(); final View toastView = superToast.getView(); final WindowManager.LayoutParams params = superToast.getWindowManagerParams(); if (windowManager != null) { windowManager.addView(toastView, params); } sendMessageDelayed(superToast, Messages.REMOVE_SUPERTOAST, superToast.getDuration() + 500); }