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();
}
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();
}
}
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;
}
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);
}
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;
}
Aggregations