Search in sources :

Example 16 with DisplayManager

use of android.hardware.display.DisplayManager in project android_frameworks_base by crdroidandroid.

the class DividerView method updateDisplayInfo.

private void updateDisplayInfo() {
    final DisplayManager displayManager = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE);
    Display display = displayManager.getDisplay(Display.DEFAULT_DISPLAY);
    final DisplayInfo info = new DisplayInfo();
    display.getDisplayInfo(info);
    mDisplayWidth = info.logicalWidth;
    mDisplayHeight = info.logicalHeight;
    mSnapAlgorithm = null;
    initializeSnapAlgorithm();
}
Also used : DisplayInfo(android.view.DisplayInfo) DisplayManager(android.hardware.display.DisplayManager) Display(android.view.Display)

Example 17 with DisplayManager

use of android.hardware.display.DisplayManager in project ring-client-android by savoirfairelinux.

the class CallFragment method onStop.

@Override
public void onStop() {
    super.onStop();
    DisplayManager displayManager = (DisplayManager) getActivity().getSystemService(Context.DISPLAY_SERVICE);
    if (displayManager != null) {
        displayManager.unregisterDisplayListener(displayListener);
    }
    if (mScreenWakeLock != null && mScreenWakeLock.isHeld()) {
        mScreenWakeLock.release();
    }
}
Also used : DisplayManager(android.hardware.display.DisplayManager)

Example 18 with DisplayManager

use of android.hardware.display.DisplayManager in project android_frameworks_opt_telephony by LineageOS.

the class DeviceStateMonitor method isScreenOn.

/**
 * @return True if one the device's screen (e.g. main screen, wifi display, HDMI display, or
 *         Android auto, etc...) is on.
 */
private boolean isScreenOn() {
    // Note that we don't listen to Intent.SCREEN_ON and Intent.SCREEN_OFF because they are no
    // longer adequate for monitoring the screen state since they are not sent in cases where
    // the screen is turned off transiently such as due to the proximity sensor.
    final DisplayManager dm = (DisplayManager) mPhone.getContext().getSystemService(Context.DISPLAY_SERVICE);
    Display[] displays = dm.getDisplays();
    if (displays != null) {
        for (Display display : displays) {
            // STATE_DOZE_SUSPEND, etc...
            if (display.getState() == Display.STATE_ON) {
                log("Screen " + Display.typeToString(display.getType()) + " on", true);
                return true;
            }
        }
        log("Screens all off", true);
        return false;
    }
    log("No displays found", true);
    return false;
}
Also used : DisplayManager(android.hardware.display.DisplayManager) Display(android.view.Display)

Example 19 with DisplayManager

use of android.hardware.display.DisplayManager in project ExoPlayer by google.

the class Util method getCurrentDisplayModeSize.

/**
 * Gets the size of the current mode of the default display, in pixels.
 *
 * <p>Note that due to application UI scaling, the number of pixels made available to applications
 * (as reported by {@link Display#getSize(Point)} may differ from the mode's actual resolution (as
 * reported by this function). For example, applications running on a display configured with a 4K
 * mode may have their UI laid out and rendered in 1080p and then scaled up. Applications can take
 * advantage of the full mode resolution through a {@link SurfaceView} using full size buffers.
 *
 * @param context Any context.
 * @return The size of the current mode, in pixels.
 */
public static Point getCurrentDisplayModeSize(Context context) {
    @Nullable Display defaultDisplay = null;
    if (Util.SDK_INT >= 17) {
        @Nullable DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
        // Consider removing it when the library minSdkVersion is increased to 17 or higher.
        if (displayManager != null) {
            defaultDisplay = displayManager.getDisplay(Display.DEFAULT_DISPLAY);
        }
    }
    if (defaultDisplay == null) {
        WindowManager windowManager = checkNotNull((WindowManager) context.getSystemService(Context.WINDOW_SERVICE));
        defaultDisplay = windowManager.getDefaultDisplay();
    }
    return getCurrentDisplayModeSize(context, defaultDisplay);
}
Also used : DisplayManager(android.hardware.display.DisplayManager) Nullable(androidx.annotation.Nullable) Display(android.view.Display) WindowManager(android.view.WindowManager)

Example 20 with DisplayManager

use of android.hardware.display.DisplayManager in project mobile-center-sdk-android by Microsoft.

the class DeviceInfoHelper method getScreenSize.

/**
 * Gets a size of a device for base orientation.
 *
 * @param context The context of the application.
 * @return A string with {@code <width>x<height>} format.
 */
@SuppressLint("SwitchIntDef")
@SuppressWarnings("SuspiciousNameCombination")
private static String getScreenSize(Context context) {
    /* Guess resolution based on the natural device orientation */
    int screenWidth;
    int screenHeight;
    Display defaultDisplay;
    Point size = new Point();
    /* Use DeviceManager to avoid android.os.strictmode.IncorrectContextUseViolation when StrictMode is enabled on API 30. */
    DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE);
    defaultDisplay = displayManager.getDisplay(Display.DEFAULT_DISPLAY);
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    size.x = displayMetrics.widthPixels;
    size.y = displayMetrics.heightPixels;
    switch(defaultDisplay.getRotation()) {
        case Surface.ROTATION_90:
        case Surface.ROTATION_270:
            screenHeight = size.x;
            screenWidth = size.y;
            break;
        default:
            screenWidth = size.x;
            screenHeight = size.y;
    }
    /* Serialize screen resolution */
    return screenWidth + "x" + screenHeight;
}
Also used : DisplayManager(android.hardware.display.DisplayManager) Point(android.graphics.Point) DisplayMetrics(android.util.DisplayMetrics) Point(android.graphics.Point) SuppressLint(android.annotation.SuppressLint) Display(android.view.Display) SuppressLint(android.annotation.SuppressLint)

Aggregations

DisplayManager (android.hardware.display.DisplayManager)23 Display (android.view.Display)13 DisplayInfo (android.view.DisplayInfo)7 DisplayMetrics (android.util.DisplayMetrics)4 Test (org.junit.Test)2 Config (org.robolectric.annotation.Config)2 SuppressLint (android.annotation.SuppressLint)1 Point (android.graphics.Point)1 MediaMuxer (android.media.MediaMuxer)1 Handler (android.os.Handler)1 PowerManager (android.os.PowerManager)1 RequiresApi (android.support.annotation.RequiresApi)1 Fragment (android.support.v4.app.Fragment)1 View (android.view.View)1 WindowManager (android.view.WindowManager)1 AccessibilityEvent (android.view.accessibility.AccessibilityEvent)1 AccessibilityManager (android.view.accessibility.AccessibilityManager)1 Nullable (androidx.annotation.Nullable)1 File (java.io.File)1 IOException (java.io.IOException)1