public interface Screen
A screen implementation may be obtained via Screen.PROVIDER.getScreen(Context).
Below are listed methods provided by this interface:
getType()getDensity()getRawDensity()getCurrentRotation()getDefaultOrientation()getCurrentOrientation()requestOrientation(Activity, int)getRequestedOrientation(Activity)lockOrientation(Activity)isOrientationLocked()unlockOrientation(Activity)getWidth()getHeight()getCurrentWidth()getCurrentHeight()getMetrics()getScreenDP()getDiagonalDistanceInInches()getDiagonalDistanceInPixels()getBrightness(Activity)setBrightness(Activity, int)setBrightness(Activity, int)getSystemBrightness()getRefreshRate()dpToPixel(float)pixelToDP(int)isOn()isInteractive()| Modifier and Type | Interface and Description |
|---|---|
static interface |
Screen.Orientation
Defines an annotation for determining set of available screen orientations.
|
static interface |
Screen.Provider
Interface for provider that may be used to access implementation of
Screen. |
static class |
Screen.ScreenDensity
Represents density of the Android device's screen.
|
static class |
Screen.ScreenRotation
Represents rotation of the Android device's screen.
|
static class |
Screen.ScreenType
Represents type of the Android device's screen.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
ORIENTATION_BEHIND
Copy of
ActivityInfo.SCREEN_ORIENTATION_BEHIND flag for better access. |
static int |
ORIENTATION_CURRENT
Orientation flag that is used to lock screen on the current orientation.
|
static int |
ORIENTATION_FULL_SENSOR
Copy of
ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR flag for better access. |
static int |
ORIENTATION_LANDSCAPE
Copy of
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE flag for better access. |
static int |
ORIENTATION_PORTRAIT
Copy of
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT flag for better access. |
static int |
ORIENTATION_REVERSE_LANDSCAPE
Copy of
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE flag for better access. |
static int |
ORIENTATION_REVERSE_PORTRAIT
Copy of
ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT flag for better access. |
static int |
ORIENTATION_SENSOR
Copy of
ActivityInfo.SCREEN_ORIENTATION_SENSOR flag for better access. |
static int |
ORIENTATION_SENSOR_LANDSCAPE
Copy of
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE flag for better access. |
static int |
ORIENTATION_SENSOR_PORTRAIT
Copy of
ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT flag for better access. |
static int |
ORIENTATION_UNSPECIFIED
Copy of
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED flag for better access. |
static int |
ORIENTATION_USER
Copy of
ActivityInfo.SCREEN_ORIENTATION_USER flag for better access. |
static Screen.Provider |
PROVIDER
A
Screen.Provider implementation that may be used to access implementation of Screen. |
| Modifier and Type | Method and Description |
|---|---|
int |
dpToPixel(float dp)
Transforms density pixel to raw pixel.
|
int |
getBrightness(android.app.Activity activity)
Returns the back-light brightness of the Android device's screen for the current application
window from the range [0, 100].
|
int |
getCurrentHeight()
Returns the current height of the Android device's screen, which depends on the current screen
orientation.
|
int |
getCurrentOrientation()
Returns the current orientation of the Android device's screen.
|
Screen.ScreenRotation |
getCurrentRotation()
Returns the current rotation of the Android device's screen.
|
int |
getCurrentWidth()
Returns the current width of the Android device's screen, which depends on the current screen
orientation.
|
int |
getDefaultOrientation()
Returns the default orientation of the Android device's screen.
|
Screen.ScreenDensity |
getDensity()
Returns the density of the Android device's screen.
|
float |
getDiagonalDistanceInInches()
Returns the diagonal distance of the Android device's screen.
|
int |
getDiagonalDistanceInPixels()
Returns the diagonal distance of the Android device's screen.
|
android.view.Display |
getDisplay()
Returns default display of the Android device.
|
int |
getHeight()
Returns the "default" height of the Android device's screen.
|
android.util.DisplayMetrics |
getMetrics()
Returns the current display metrics of the Android device's screen.
|
int |
getRawDensity()
Returns the raw density of the Android device's screen obtained from the screen metrics.
|
float |
getRefreshRate()
Returns refresh rate of the Android device's screen.
|
int |
getRequestedOrientation(android.app.Activity activity)
Returns the orientation that was requested for the specified activity via
requestOrientation(Activity, int) or directly Activity.setRequestedOrientation(int). |
float |
getScreenDP()
Returns the value of density pixel for 1 pixel for the Android device's screen.
|
int |
getSystemBrightness()
Returns the back-light brightness of the Android device's screen.
|
Screen.ScreenType |
getType()
Returns the type of the Android device's screen.
|
int |
getWidth()
Returns the "default" width of the Android device's screen.
|
boolean |
isInteractive()
Checks whether the Android device's screen is interactive or not.
|
boolean |
isOn()
Checks whether the Android device's screen is currently on or off.
|
boolean |
isOrientationLocked()
Returns flag indicating whether orientation of the Android device's screen is currently locked
or not.
|
boolean |
lockOrientation(android.app.Activity activity)
Locks orientation of the Android device's screen at the current orientation for the given
activity.
|
float |
pixelToDP(int pixel)
Transforms raw pixel to density pixel.
|
boolean |
requestOrientation(android.app.Activity activity,
int orientation)
Requests the specified orientation as orientation of the Android device's screen for the given
activity.
|
void |
setBrightness(android.app.Activity activity,
int brightness)
Sets the back-light brightness of the Android device's screen.
|
void |
unlockOrientation(android.app.Activity activity)
Unlocks orientation of the Android device's screen for the given activity.
|
static final Screen.Provider PROVIDER
Screen.Provider implementation that may be used to access implementation of Screen.static final int ORIENTATION_CURRENT
static final int ORIENTATION_UNSPECIFIED
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED flag for better access.static final int ORIENTATION_LANDSCAPE
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE flag for better access.static final int ORIENTATION_PORTRAIT
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT flag for better access.static final int ORIENTATION_USER
ActivityInfo.SCREEN_ORIENTATION_USER flag for better access.static final int ORIENTATION_BEHIND
ActivityInfo.SCREEN_ORIENTATION_BEHIND flag for better access.static final int ORIENTATION_SENSOR
ActivityInfo.SCREEN_ORIENTATION_SENSOR flag for better access.static final int ORIENTATION_SENSOR_LANDSCAPE
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE flag for better access.static final int ORIENTATION_SENSOR_PORTRAIT
ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT flag for better access.static final int ORIENTATION_REVERSE_LANDSCAPE
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE flag for better access.static final int ORIENTATION_REVERSE_PORTRAIT
ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT flag for better access.static final int ORIENTATION_FULL_SENSOR
ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR flag for better access.boolean isOn()
True if screen is on, false otherwise.boolean isInteractive()
Note, that this is supported only for KITKAT_WATCH
and above.
True if screen is interactive, false otherwise.android.view.Display getDisplay()
WindowManager.getDefaultDisplay().int getWidth()
int getHeight()
int getCurrentWidth()
int getCurrentHeight()
android.util.DisplayMetrics getMetrics()
Screen.ScreenDensity getDensity()
Screen.ScreenDensity values or UNKNOWN
if the current screen data are unavailable.getRawDensity()int getRawDensity()
getDensity()Screen.ScreenType getType()
Screen.ScreenType values or UNKNOWN
if the current screen data are unavailable.int getDefaultOrientation()
ORIENTATION_PORTRAIT for phone, ORIENTATION_LANDSCAPE
for tablet or UNSPECIFIED if the current screen data
are unavailable or orientation is unknown.int getCurrentOrientation()
ORIENTATION_PORTRAIT, ORIENTATION_LANDSCAPE, ORIENTATION_REVERSE_PORTRAIT
ORIENTATION_REVERSE_LANDSCAPE, ORIENTATION_USER, ORIENTATION_SENSOR,
ORIENTATION_SENSOR_PORTRAIT, ORIENTATION_SENSOR_LANDSCAPE, ORIENTATION_FULL_SENSOR,
ORIENTATION_BEHIND, or ORIENTATION_UNSPECIFIED if the current screen data
are unavailable or orientation is unknown.Screen.ScreenRotation getCurrentRotation()
Screen.ScreenRotation values or UNKNOWN
if the current screen data are unavailable or orientation is unknown.float getDiagonalDistanceInInches()
int getDiagonalDistanceInPixels()
int getBrightness(android.app.Activity activity)
activity - Currently visible activity.void setBrightness(android.app.Activity activity,
int brightness)
Note, that the platform will automatically take care of changing the brightness as the user moves in and out of the application with custom brightness.
activity - Currently visible activity.brightness - The value of brightness for the application window from the range [0, 100].IllegalArgumentException - When the given brightness value is out of the specified range.int getSystemBrightness()
boolean requestOrientation(android.app.Activity activity,
int orientation)
activity - Currently visible activity.orientation - Orientation that you would like to set for the activity. One of the orientation
flags specified within this interface.True if orientation was successfully requested, false otherwise.isOrientationLocked(),
lockOrientation(Activity)int getRequestedOrientation(android.app.Activity activity)
requestOrientation(Activity, int) or directly Activity.setRequestedOrientation(int).activity - Currently visible activity of which requested orientation to obtain.boolean lockOrientation(android.app.Activity activity)
activity - Currently visible activity.True if orientation was locked, false otherwise.isOrientationLocked(),
unlockOrientation(Activity),
requestOrientation(Activity, int)void unlockOrientation(android.app.Activity activity)
SCREEN_ORIENTATION_USER orientation.activity - Currently visible activity.isOrientationLocked(),
lockOrientation(Activity)boolean isOrientationLocked()
True if screen orientation is currently locked by one of lockOrientation(Activity)
or requestOrientation(Activity, int), false otherwise.lockOrientation(Activity),
requestOrientation(Activity, int)float pixelToDP(int pixel)
pixel - The pixel value which you want to transform to density pixel value.dpToPixel(float)int dpToPixel(float dp)
dp - The density pixel value which you want to transform to pixel raw value.pixelToDP(int)float getScreenDP()
This value depends on the screen's density.
dpToPixel(float),
pixelToDP(int)float getRefreshRate()
Display.getRefreshRate()