當前位置: 首頁>>代碼示例>>Java>>正文


Java WindowManager.getDefaultDisplay方法代碼示例

本文整理匯總了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);
}
 
開發者ID:anandwana001,項目名稱:Tech-Jalsa,代碼行數:24,代碼來源:Game.java

示例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);
  }
}
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:21,代碼來源:ScreenResolution.java

示例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);
}
 
開發者ID:dufangyu1990,項目名稱:LeCatApp,代碼行數:27,代碼來源:CameraConfigurationManager.java

示例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;
}
 
開發者ID:zuoweitan,項目名稱:Hitalk,代碼行數:33,代碼來源:CameraConfigurationManager.java

示例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);
    }
}
 
開發者ID:monthlypub,項目名稱:SmingZZick_App,代碼行數:34,代碼來源:ScreenCaptureService.java

示例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;
}
 
開發者ID:GitLqr,項目名稱:LQRWeChat,代碼行數:33,代碼來源:ImageUtils.java

示例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()};
    }
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:18,代碼來源:AndroidUtil.java

示例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;
}
 
開發者ID:adithya321,項目名稱:Instincts-2k17,代碼行數:10,代碼來源:GalleryAdapter.java

示例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;
}
 
開發者ID:RuanXiaoHui,項目名稱:ZxingScan,代碼行數:13,代碼來源:DisplayUtil.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:DensityUtil.java

示例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();
}
 
開發者ID:bunnyblue,項目名稱:NoticeDog,代碼行數:28,代碼來源:SwipeTabViewRelocationController.java

示例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);
}
 
開發者ID:lpy19930103,項目名稱:MinimalismJotter,代碼行數:11,代碼來源:PhotoDialog.java

示例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;
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:App.java

示例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;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:16,代碼來源:SDKUtils.java

示例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;
}
 
開發者ID:XndroidDev,項目名稱:Xndroid,代碼行數:8,代碼來源:DeviceUtils.java


注:本文中的android.view.WindowManager.getDefaultDisplay方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。