本文整理汇总了Java中android.view.WindowManager.getDefaultDisplay方法的典型用法代码示例。如果您正苦于以下问题:Java WindowManager.getDefaultDisplay方法的具体用法?Java WindowManager.getDefaultDisplay怎么用?Java WindowManager.getDefaultDisplay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.WindowManager
的用法示例。
在下文中一共展示了WindowManager.getDefaultDisplay方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initGame
import android.view.WindowManager; //导入方法依赖的package包/类
private void initGame() {
WindowManager wm = getWindowManager();
Display disp = wm.getDefaultDisplay();
Point size = new Point();
disp.getSize(size);
screenWidth = size.x;
screenHeight = size.y;
// Now
// Nexus4 Width: 768 Height:1280
// Speed Box:20 Orange:12 Pink:20 Black:16
boxSpeed = Math.round(screenHeight / 60); // 1280 / 60 = 21.333... => 21
orangeSpeed = Math.round(screenWidth / 60); // 768 / 60 = 12.8 => 13
pinkSpeed = Math.round(screenWidth / 36); // 768 / 36 = 21.333... => 21
blackSpeed = Math.round(screenWidth / 45); // 768 / 45 = 17.06... => 17
// Move to out of screen.
orange.setX(-80);
orange.setY(-80);
pink.setX(-80);
pink.setY(-80);
black.setX(-80);
black.setY(-80);
scoreLabel.setText(getString(R.string.score)+score);
}
示例2: getRealResolutionOnOldDevice
import android.view.WindowManager; //导入方法依赖的package包/类
/**
* Gets resolution on old devices.
* Tries the reflection to get the real resolution first.
* Fall back to getDisplayMetrics if the above method failed.
* */
private static Pair<Integer, Integer> getRealResolutionOnOldDevice(Context ctx) {
try{
WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Method mGetRawWidth = Display.class.getMethod("getRawWidth");
Method mGetRawHeight = Display.class.getMethod("getRawHeight");
Integer realWidth = (Integer) mGetRawWidth.invoke(display);
Integer realHeight = (Integer) mGetRawHeight.invoke(display);
return new Pair<Integer, Integer>(realWidth, realHeight);
}
catch (Exception e) {
DisplayMetrics disp = ctx.getResources().getDisplayMetrics();
return new Pair<Integer, Integer>(disp.widthPixels, disp.heightPixels);
}
}
示例3: initFromCameraParameters
import android.view.WindowManager; //导入方法依赖的package包/类
/**
* 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.getSize(theScreenResolution);
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 = getCameraResolution(parameters, screenResolution);
cameraResolution = findBestPreviewSizeValue(parameters,
screenResolutionForCamera);
Log.i(TAG, "Camera resolution: " + cameraResolution);
}
示例4: getDisplayOrientation
import android.view.WindowManager; //导入方法依赖的package包/类
public int getDisplayOrientation() {
Camera.CameraInfo info = new Camera.CameraInfo();
Camera.getCameraInfo(Camera.CameraInfo.CAMERA_FACING_BACK, info);
WindowManager wm = (WindowManager) mContext.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;
result = (360 - result) % 360;
} else {
result = (info.orientation - degrees + 360) % 360;
}
return result;
}
示例5: startCapture
import android.view.WindowManager; //导入方法依赖的package包/类
private void startCapture() {
if (sMediaProjection != null) {
makeDirectory(null);
// display metrics
DisplayMetrics metrics = getResources().getDisplayMetrics();
mDensity = metrics.densityDpi;
WindowManager window = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
mDisplay = window.getDefaultDisplay();
// create virtual display depending on device width / height
createVirtualDisplay();
// register orientation change callback
mOrientationChangeCallback = new OrientationChangeCallback(this);
if (mOrientationChangeCallback.canDetectOrientation()) {
mOrientationChangeCallback.enable();
}
// register media projection stop callback
if (hasStopCallbackBug() == false) {
mediaProjectionStopCallback = new MediaProjectionStopCallback(true);
sMediaProjection.registerCallback(mediaProjectionStopCallback, mHandler);
} else {
mediaProjectionStopCallback = new MediaProjectionStopCallback(false);
}
updateNotification();
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(100);
}
}
示例6: zoomForFilePath
import android.view.WindowManager; //导入方法依赖的package包/类
public static Bitmap zoomForFilePath(Activity context, String filePath) {
Bitmap bitmap = BitmapFactory.decodeFile(filePath);
BitmapFactory.Options opt = new BitmapFactory.Options();
//这个isjustdecodebounds很重要
opt.inJustDecodeBounds = true;
//获取到这个图片的原始宽度和高度
int picWidth = bitmap.getWidth();
int picHeight = bitmap.getHeight();
//获取屏的宽度和高度
WindowManager windowManager = context.getWindowManager();
Display display = windowManager.getDefaultDisplay();
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();
//isSampleSize是表示对图片的缩放程度,比如值为2图片的宽度和高度都变为以前的1/2
opt.inSampleSize = 1;
//根据屏的大小和图片大小计算出缩放比例
if (picWidth > picHeight) {
if (picWidth > screenWidth)
opt.inSampleSize = picWidth / screenWidth;
} else {
if (picHeight > screenHeight)
opt.inSampleSize = picHeight / screenHeight;
}
//这次再真正地生成一个有像素的,经过缩放了的bitmap
opt.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeFile(filePath, opt);
return bitmap;
}
示例7: getWindowSize
import android.view.WindowManager; //导入方法依赖的package包/类
/**
* 获取window的size
*
* @param context
* @return
*/
public static int[] getWindowSize(Context context) {
final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
final Display display = wm.getDefaultDisplay();
if (android.os.Build.VERSION.SDK_INT >= 13) {
Point point = new Point();
display.getSize(point);
return new int[]{point.x, point.y};
} else {
return new int[]{display.getWidth(), display.getHeight()};
}
}
示例8: GalleryAdapter
import android.view.WindowManager; //导入方法依赖的package包/类
public GalleryAdapter(Context context, ArrayList<String> imagesList) {
this.context = context;
this.imagesList = imagesList;
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenWidth = size.x;
}
示例9: getScreenResolution
import android.view.WindowManager; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static Point getScreenResolution(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point screenResolution = new Point();
if (android.os.Build.VERSION.SDK_INT >= 13) {
display.getSize(screenResolution);
} else {
screenResolution.set(display.getWidth(), display.getHeight());
}
return screenResolution;
}
示例10: getScreenWidth
import android.view.WindowManager; //导入方法依赖的package包/类
public static int getScreenWidth(Context c) {
if (screenWidth == 0) {
WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenWidth = size.x;
}
return screenWidth;
}
示例11: init
import android.view.WindowManager; //导入方法依赖的package包/类
void init() {
WindowManager windowManager = (WindowManager) this.context.getSystemService("window");
Display display = windowManager.getDefaultDisplay();
Point size = new Point();
Point size2 = new Point();
display.getCurrentSizeRange(size, size2);
this.screenWidth = size.x;
this.screenHeight = size2.x;
this.statusBarHeight = size2.x - size2.y;
LayoutParams params = new LayoutParams(-2, -2, 2007, 16843544, -3);
params.gravity = 51;
params.width = -1;
params.height = -1;
params.x = this.FAR_AWAY;
params.y = 0;
LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.renderView = new RelativeLayout(this.context);
this.trashFooter = (ViewGroup) inflater.inflate(R.layout.swipe_relocation_trash_footer, null);
this.trashCan = this.trashFooter.findViewById(R.id.swipe_relocator_trash);
this.swipeTab = (YettiTabLayout) inflater.inflate(R.layout.yetti_tab_layout, null);
this.swipeTab.animate().setDuration(0).alpha(0.0f);
windowManager.addView(this.renderView, params);
this.renderView.addView(this.swipeTab, -2, -2);
this.renderView.addView(this.trashFooter, -1, -1);
resetTrash();
setupGestureDetector();
}
示例12: show
import android.view.WindowManager; //导入方法依赖的package包/类
@Override
public void show() {
super.show();
WindowManager windowManager = ((Activity) mContext).getWindowManager();
Display display = windowManager.getDefaultDisplay();
WindowManager.LayoutParams lp = this.getWindow().getAttributes();
lp.width = display.getWidth(); //设置宽度
lp.height = display.getHeight();
this.getWindow().setAttributes(lp);
}
示例13: getScreenSize
import android.view.WindowManager; //导入方法依赖的package包/类
public void getScreenSize() {
WindowManager windowManager = (WindowManager)this.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
Display display = windowManager.getDefaultDisplay();
display.getMetrics(dm);
DIMEN_RATE = dm.density / 1.0F;
DIMEN_DPI = dm.densityDpi;
SCREEN_WIDTH = dm.widthPixels;
SCREEN_HEIGHT = dm.heightPixels;
if(SCREEN_WIDTH > SCREEN_HEIGHT) {
int t = SCREEN_HEIGHT;
SCREEN_HEIGHT = SCREEN_WIDTH;
SCREEN_WIDTH = t;
}
}
示例14: getScreenHeightWidth
import android.view.WindowManager; //导入方法依赖的package包/类
public static Point getScreenHeightWidth(WindowManager mWindowManager) {
Point point = new Point();
try {
Display display = mWindowManager.getDefaultDisplay();
if (VERSION.SDK_INT >= 17) {
display.getRealSize(point);
} else {
point.y = display.getHeight();
point.x = display.getWidth();
}
} catch (Throwable e) {
LOG.w(TAG, "getScreenHeightWidth failed(Throwable): " + e.getMessage());
}
return point;
}
示例15: getScreenWidth
import android.view.WindowManager; //导入方法依赖的package包/类
public static int getScreenWidth(@NonNull Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point point = new Point();
display.getSize(point);
return point.x;
}