List of usage examples for android.app Activity getWindowManager
public WindowManager getWindowManager()
From source file:com.example.ray.firstapp.bottombar.BottomBar.java
private static void navBarMagic(Activity activity, final BottomBar bottomBar) { Resources res = activity.getResources(); int softMenuIdentifier = res.getIdentifier("config_showNavigationBar", "bool", "android"); int navBarIdentifier = res.getIdentifier("navigation_bar_height", "dimen", "android"); int navBarHeight = 0; if (navBarIdentifier > 0) { navBarHeight = res.getDimensionPixelSize(navBarIdentifier); }//from ww w . j a va 2s. c o m if (!bottomBar.drawBehindNavBar() || navBarHeight == 0 || (!(softMenuIdentifier > 0 && res.getBoolean(softMenuIdentifier)))) { return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && ViewConfiguration.get(activity).hasPermanentMenuKey()) { return; } /** * Copy-paste coding made possible by: * http://stackoverflow.com/a/14871974/940036 */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Display d = activity.getWindowManager().getDefaultDisplay(); DisplayMetrics realDisplayMetrics = new DisplayMetrics(); d.getRealMetrics(realDisplayMetrics); int realHeight = realDisplayMetrics.heightPixels; int realWidth = realDisplayMetrics.widthPixels; DisplayMetrics displayMetrics = new DisplayMetrics(); d.getMetrics(displayMetrics); int displayHeight = displayMetrics.heightPixels; int displayWidth = displayMetrics.widthPixels; boolean hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; if (!hasSoftwareKeys) { return; } } /** * End of delicious copy-paste code */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { activity.getWindow().getAttributes().flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if (bottomBar.useTopOffset()) { int offset; int statusBarResource = res.getIdentifier("status_bar_height", "dimen", "android"); if (statusBarResource > 0) { offset = res.getDimensionPixelSize(statusBarResource); } else { offset = MiscUtils.dpToPixel(activity, 25); } if (!bottomBar.useOnlyStatusbarOffset()) { TypedValue tv = new TypedValue(); if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { offset += TypedValue.complexToDimensionPixelSize(tv.data, res.getDisplayMetrics()); } else { offset += MiscUtils.dpToPixel(activity, 56); } } bottomBar.getUserContainer().setPadding(0, offset, 0, 0); } final View outerContainer = bottomBar.getOuterContainer(); final int navBarHeightCopy = navBarHeight; bottomBar.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { bottomBar.shyHeightAlreadyCalculated(); int newHeight = outerContainer.getHeight() + navBarHeightCopy; outerContainer.getLayoutParams().height = newHeight; if (bottomBar.isShy()) { int defaultOffset = bottomBar.useExtraOffset() ? navBarHeightCopy : 0; bottomBar.setTranslationY(defaultOffset); ((CoordinatorLayout.LayoutParams) bottomBar.getLayoutParams()) .setBehavior(new BottomNavigationBehavior(newHeight, defaultOffset)); } ViewTreeObserver obs = outerContainer.getViewTreeObserver(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obs.removeOnGlobalLayoutListener(this); } else { obs.removeGlobalOnLayoutListener(this); } } }); } }
From source file:org.odk.collect.android.fragments.Camera2VideoFragment.java
private void setUpMediaRecorder() throws IOException { final Activity activity = getActivity(); if (null == activity) { return;//from w ww .j a v a2 s .c o m } mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); if (nextVideoAbsolutePath == null || nextVideoAbsolutePath.isEmpty()) { nextVideoAbsolutePath = getVideoFilePath(getActivity()); } mediaRecorder.setOutputFile(nextVideoAbsolutePath); mediaRecorder.setVideoEncodingBitRate(10000000); mediaRecorder.setVideoFrameRate(30); mediaRecorder.setVideoSize(videoSize.getWidth(), videoSize.getHeight()); mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); switch (sensorOrientation) { case SENSOR_ORIENTATION_DEFAULT_DEGREES: mediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(rotation)); break; case SENSOR_ORIENTATION_INVERSE_DEGREES: mediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(rotation)); break; } mediaRecorder.prepare(); }
From source file:com.android.launcher3.Utilities.java
private static Bitmap takeShot(Activity activity) { View view = activity.getWindow().getDecorView(); view.setDrawingCacheEnabled(true);/*from www. ja v a2 s .c om*/ view.buildDrawingCache(); Bitmap b1 = view.getDrawingCache(); Rect frame = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; int width = activity.getWindowManager().getDefaultDisplay().getWidth(); int height = activity.getWindowManager().getDefaultDisplay().getHeight(); Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight); view.destroyDrawingCache(); return b; }
From source file:com.example.testcamera.Camera2BasicFragmentGoogle.java
/** * Capture a still picture. This method should be called when we get a response in * {@link #mCaptureCallback} from both {@link #lockFocus()}. *///from w ww. j a va 2 s .c om private void captureStillPicture() { try { final Activity activity = getActivity(); if (null == activity || null == mCameraDevice) { return; } // This is the CaptureRequest.Builder that we use to take a picture. final CaptureRequest.Builder captureBuilder = mCameraDevice .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); captureBuilder.addTarget(mImageReader.getSurface()); // Use the same AE and AF modes as the preview. captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE); captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH); // Orientation int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation)); CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() { @Override public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) { Toast.makeText(getActivity(), "Saved: " + mFile, Toast.LENGTH_SHORT).show(); unlockFocus(); } }; mCaptureSession.stopRepeating(); mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null); } catch (CameraAccessException e) { e.printStackTrace(); } }
From source file:com.harlan.jxust.ui.view.bottombar.BottomBar.java
private static void navBarMagic(Activity activity, final BottomBar bottomBar) { Resources res = activity.getResources(); int softMenuIdentifier = res.getIdentifier("config_showNavigationBar", "bool", "android"); int navBarIdentifier = res.getIdentifier("navigation_bar_height", "dimen", "android"); int navBarHeight = 0; if (navBarIdentifier > 0) { navBarHeight = res.getDimensionPixelSize(navBarIdentifier); }/*from w w w . j a va 2s .co m*/ if (!bottomBar.drawBehindNavBar() || navBarHeight == 0 || (!(softMenuIdentifier > 0 && res.getBoolean(softMenuIdentifier)))) { return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && ViewConfiguration.get(activity).hasPermanentMenuKey()) { return; } /** * Copy-paste coding made possible by: * http://stackoverflow.com/a/14871974/940036 */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Display d = activity.getWindowManager().getDefaultDisplay(); DisplayMetrics realDisplayMetrics = new DisplayMetrics(); d.getRealMetrics(realDisplayMetrics); int realHeight = realDisplayMetrics.heightPixels; int realWidth = realDisplayMetrics.widthPixels; DisplayMetrics displayMetrics = new DisplayMetrics(); d.getMetrics(displayMetrics); int displayHeight = displayMetrics.heightPixels; int displayWidth = displayMetrics.widthPixels; boolean hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; if (!hasSoftwareKeys) { return; } } /** * End of delicious copy-paste code */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { activity.getWindow().getAttributes().flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if (bottomBar.useTopOffset()) { int offset; int statusBarResource = res.getIdentifier("status_bar_height", "dimen", "android"); if (statusBarResource > 0) { offset = res.getDimensionPixelSize(statusBarResource); } else { offset = MiscUtils.dpToPixel(activity, 25); } if (!bottomBar.useOnlyStatusbarOffset()) { TypedValue tv = new TypedValue(); if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { offset += TypedValue.complexToDimensionPixelSize(tv.data, res.getDisplayMetrics()); } else { offset += MiscUtils.dpToPixel(activity, 56); } } bottomBar.getUserContainer().setPadding(0, offset, 0, 0); } final View outerContainer = bottomBar.getOuterContainer(); final int navBarHeightCopy = navBarHeight; bottomBar.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { bottomBar.shyHeightAlreadyCalculated(); int newHeight = outerContainer.getHeight() + navBarHeightCopy; outerContainer.getLayoutParams().height = newHeight; if (bottomBar.isShy()) { int defaultOffset = bottomBar.useExtraOffset() ? navBarHeightCopy : 0; bottomBar.setTranslationY(defaultOffset); ((CoordinatorLayout.LayoutParams) bottomBar.getLayoutParams()) .setBehavior(new BottomNavigationBehavior(newHeight, defaultOffset, bottomBar.isShy(), bottomBar.mIsTabletMode)); } ViewTreeObserver obs = outerContainer.getViewTreeObserver(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obs.removeOnGlobalLayoutListener(this); } else { obs.removeGlobalOnLayoutListener(this); } } }); } }
From source file:com.rockacode.ocr.ui.camera.CameraFragment.java
/** * Capture a still picture. This method should be called when we get a response in * {@link #mCaptureCallback} from both {@link #lockFocus()}. *//*from w w w .j a v a2 s. c o m*/ private void captureStillPicture() { try { final Activity activity = getActivity(); if (null == activity || null == mCameraDevice) { return; } // This is the CaptureRequest.Builder that we use to take a picture. final CaptureRequest.Builder captureBuilder = mCameraDevice .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); captureBuilder.addTarget(mImageReader.getSurface()); // Use the same AE and AF modes as the preview. captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE); setAutoFlash(captureBuilder); // Orientation int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation)); CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() { @Override public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) { showToast("Saved: " + mFile); startImageDetails(imageFilePath); Log.d(TAG, mFile.toString()); Log.d(TAG, imageFilePath); unlockFocus(); } }; mCaptureSession.stopRepeating(); mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null); } catch (CameraAccessException e) { e.printStackTrace(); } }
From source file:com.hippo.ehviewer.ui.scene.GalleryListScene.java
private void guideQuickSearch() { Activity activity = getActivity2(); if (null == activity || !Settings.getGuideQuickSearch()) { return;// w ww . j av a 2 s. c o m } Display display = activity.getWindowManager().getDefaultDisplay(); Point point = new Point(); display.getSize(point); mShowcaseView = new ShowcaseView.Builder(activity).withMaterialShowcase().setStyle(R.style.Guide) .setTarget(new PointTarget(point.x, point.y / 3)).blockAllTouches() .setContentTitle(R.string.guide_quick_search_title).setContentText(R.string.guide_quick_search_text) .replaceEndButton(R.layout.button_guide) .setShowcaseEventListener(new SimpleShowcaseEventListener() { @Override public void onShowcaseViewDidHide(ShowcaseView showcaseView) { mShowcaseView = null; ViewUtils.removeFromParent(showcaseView); Settings.putGuideQuickSearch(false); openDrawer(Gravity.RIGHT); } }).build(); }
From source file:com.android.rahul.myselfieapp.Fragment.CamVideoFragment.java
private void setUpMediaRecorder() throws IOException { final Activity activity = getActivity(); if (null == activity) { return;/* ww w . jav a 2 s. com*/ } mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); if (mNextVideoAbsolutePath == null || mNextVideoAbsolutePath.isEmpty()) { mNextVideoAbsolutePath = getVideoFilePath(getActivity()); } mMediaRecorder.setOutputFile(mNextVideoAbsolutePath); mMediaRecorder.setVideoEncodingBitRate(10000000); mMediaRecorder.setVideoFrameRate(30); mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight()); mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); switch (mSensorOrientation) { case SENSOR_ORIENTATION_DEFAULT_DEGREES: mMediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(rotation)); break; case SENSOR_ORIENTATION_INVERSE_DEGREES: mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(rotation)); break; } mMediaRecorder.prepare(); }
From source file:com.daiv.android.twitter.manipulations.widgets.NotificationDrawerLayout.java
public void setDrawerRightEdgeSize(Activity activity, float displayWidthPercentage) { Point displaySize = new Point(); activity.getWindowManager().getDefaultDisplay().getSize(displaySize); mRightDragger.setEdgeSize((int) (displaySize.x * displayWidthPercentage)); }
From source file:com.quectel.camera2test.Camera2VideoFragment.java
private void setUpMediaRecorder() throws IOException { final Activity activity = getActivity(); if (null == activity) { return;/*w w w. j av a 2 s.c o m*/ } mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); mMediaRecorder.setOutputFormat(/*MediaRecorder.OutputFormat.MPEG_2_TS*/ 8); if (mNextVideoAbsolutePath == null || mNextVideoAbsolutePath.isEmpty()) { mNextVideoAbsolutePath = getVideoFilePath(getActivity()); } mMediaRecorder.setOutputFile(mNextVideoAbsolutePath); mMediaRecorder.setVideoEncodingBitRate(10000000); mMediaRecorder.setVideoFrameRate(30); mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight()); mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); switch (mSensorOrientation) { case SENSOR_ORIENTATION_DEFAULT_DEGREES: mMediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(rotation)); break; case SENSOR_ORIENTATION_INVERSE_DEGREES: mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(rotation)); break; } mMediaRecorder.prepare(); }