Class ExtendedClientDetails
- All Implemented Interfaces:
Serializable
Browser details are automatically fetched on the first call to
Page.getExtendedClientDetails() and cached for the lifetime of the
UI. The fetch happens asynchronously, so the first call may return
null while the data is being retrieved. To update the cached values
with fresh data from the browser, use
refresh(SerializableConsumer)}.
- Since:
- 2.0
- Author:
- Vaadin Ltd
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionExtendedClientDetails(UI ui, String screenWidth, String screenHeight, String windowInnerWidth, String windowInnerHeight, String bodyClientWidth, String bodyClientHeight, String tzOffset, String rawTzOffset, String dstShift, String dstInEffect, String tzId, String curDate, String touchDevice, String devicePixelRatio, String windowName, String navigatorPlatform, String colorScheme, String themeName) For internal use only. -
Method Summary
Modifier and TypeMethodDescriptionstatic ExtendedClientDetailsCreates an ExtendedClientDetails instance from browser details JSON object.intGets the height of the body element in the document in pixels.intGets the width of the body element in the document in pixels.Gets the color scheme.Returns the current date and time of the browser.doubleGets the device pixel ratio,window.devicePixelRatio.intReturns the offset in milliseconds between the browser's GMT TimeZone and DST.intReturns the browser-reported TimeZone offset in milliseconds from GMT ignoring possible daylight saving adjustments that may be in effect in the browser.intGets the height of the screen in pixels.intGets the width of the screen in pixels.Gets the theme name.Returns the TimeZone Id (like "Europe/Helsinki") provided by the browser (if the browser supports this feature).intReturns the browser-reported TimeZone offset in milliseconds from GMT.intGets the inner height of the browser windowwindow.innerHeightin pixels.intGets the inner width of the browser windowwindow.innerWidthin pixels.Returns a unique browser window identifier.booleanReturns whether daylight saving time (DST) is currently in effect in the region of the browser or not.booleanisIOS()Check if the browser is run on IOS.booleanisIPad()Check if the browser is run on IPad.booleanChecks if the browser supports touch events.voidrefresh(SerializableConsumer<ExtendedClientDetails> callback) Refreshes the browser details by fetching updated values from the browser.
-
Constructor Details
-
ExtendedClientDetails
public ExtendedClientDetails(UI ui, String screenWidth, String screenHeight, String windowInnerWidth, String windowInnerHeight, String bodyClientWidth, String bodyClientHeight, String tzOffset, String rawTzOffset, String dstShift, String dstInEffect, String tzId, String curDate, String touchDevice, String devicePixelRatio, String windowName, String navigatorPlatform, String colorScheme, String themeName) For internal use only. Updates all properties in the class according to the given information.- Parameters:
ui- the UI instance that owns this ExtendedClientDetailsscreenWidth- Screen widthscreenHeight- Screen heightwindowInnerWidth- Window widthwindowInnerHeight- Window heightbodyClientWidth- Body element widthbodyClientHeight- Body element heighttzOffset- TimeZone offset in minutes from GMTrawTzOffset- raw TimeZone offset in minutes from GMT (w/o DST adjustment)dstShift- the difference between the raw TimeZone and DST in minutesdstInEffect- is DST currently active in the region or not?tzId- time zone idcurDate- the current date in milliseconds since the epochtouchDevice- whether browser responds to touch eventsdevicePixelRatio- the ratio of the display's resolution in physical pixels to the resolution in CSS pixelswindowName- a unique browser window name which persists on reloadnavigatorPlatform- navigation platform received from the browsercolorScheme- the current color schemethemeName- the theme name (e.g., "lumo", "aura")
-
-
Method Details
-
getScreenWidth
public int getScreenWidth()Gets the width of the screen in pixels. This is the full screen resolution and not the width available for the application.- Returns:
- the width of the screen in pixels.
-
getScreenHeight
public int getScreenHeight()Gets the height of the screen in pixels. This is the full screen resolution and not the height available for the application.- Returns:
- the height of the screen in pixels.
-
getWindowInnerHeight
public int getWindowInnerHeight()Gets the inner height of the browser windowwindow.innerHeightin pixels. This includes the scrollbar, if it is visible.Delegates to the window size signal on the
Page. Returns-1if no UI is available.- Returns:
- the browser window inner height in pixels, or
-1
-
getWindowInnerWidth
public int getWindowInnerWidth()Gets the inner width of the browser windowwindow.innerWidthin pixels. This includes the scrollbar, if it is visible.Delegates to the window size signal on the
Page. Returns-1if no UI is available.- Returns:
- the browser window inner width in pixels, or
-1
-
getBodyClientHeight
public int getBodyClientHeight()Gets the height of the body element in the document in pixels.- Returns:
- the height of the body element
-
getBodyClientWidth
public int getBodyClientWidth()Gets the width of the body element in the document in pixels.- Returns:
- the width of the body element
-
getTimezoneOffset
public int getTimezoneOffset()Returns the browser-reported TimeZone offset in milliseconds from GMT. This includes possible daylight saving adjustments, to figure out which TimeZone the user actually might be in, seegetRawTimezoneOffset().- Returns:
- timezone offset in milliseconds, 0 if not available
- See Also:
-
getTimeZoneId
Returns the TimeZone Id (like "Europe/Helsinki") provided by the browser (if the browser supports this feature).- Returns:
- the TimeZone Id if provided by the browser, null otherwise.
- See Also:
-
getRawTimezoneOffset
public int getRawTimezoneOffset()Returns the browser-reported TimeZone offset in milliseconds from GMT ignoring possible daylight saving adjustments that may be in effect in the browser.You can use this to figure out which TimeZones the user could actually be in by calling
TimeZone.getAvailableIDs(int).If
getRawTimezoneOffset()andgetTimezoneOffset()returns the same value, the browser is either in a zone that does not currently have daylight saving time, or in a zone that never has daylight saving time.- Returns:
- timezone offset in milliseconds excluding DST, 0 if not available
-
getDSTSavings
public int getDSTSavings()Returns the offset in milliseconds between the browser's GMT TimeZone and DST.- Returns:
- the number of milliseconds that the TimeZone shifts when DST is in effect
-
isDSTInEffect
public boolean isDSTInEffect()Returns whether daylight saving time (DST) is currently in effect in the region of the browser or not.- Returns:
- true if the browser resides at a location that currently is in DST
-
getCurrentDate
Returns the current date and time of the browser. This will not be entirely accurate due to varying network latencies, but should provide a close-enough value for most cases. Also note that the returned Date object uses servers default time zone, not the clients.To get the actual date and time shown in the end users computer, you can do something like:
WebBrowser browser = ...; SimpleTimeZone timeZone = new SimpleTimeZone(browser.getTimezoneOffset(), "Fake client time zone"); DateFormat format = DateFormat.getDateTimeInstance(); format.setTimeZone(timeZone); myLabel.setValue(format.format(browser.getCurrentDate()));
- Returns:
- the current date and time of the browser.
- See Also:
-
isTouchDevice
public boolean isTouchDevice()Checks if the browser supports touch events.- Returns:
- true if the browser is detected to support touch events, false otherwise
-
getDevicePixelRatio
public double getDevicePixelRatio()Gets the device pixel ratio,window.devicePixelRatio. See more from MDN web docs.A value of -1 indicates that the value was not reported by the browser correctly.
- Returns:
- double-precision floating-point value indicating the ratio of the display's resolution in physical pixels to the resolution in CSS pixels
-
getWindowName
Returns a unique browser window identifier. For internal use only.- Returns:
- An id which persists if the UI is reloaded in the same browser window/tab.
-
isIPad
public boolean isIPad()Check if the browser is run on IPad.- Returns:
- true if run on IPad false if the user is not using IPad or if no information from the browser is present
-
isIOS
public boolean isIOS()Check if the browser is run on IOS.- Returns:
trueif run on IOS ,falseif the user is not using IOS or if no information from the browser is present
-
getColorScheme
Gets the color scheme.- Returns:
- the color scheme, never
null
-
getThemeName
Gets the theme name.- Returns:
- the theme name (e.g., "lumo", "aura"), or empty string if not detected
-
fromJson
Creates an ExtendedClientDetails instance from browser details JSON object. This is intended for internal use when browser details are provided as JSON (e.g., during UI initialization or refresh).For internal use only.
- Parameters:
ui- the UI instance that owns this ExtendedClientDetailsjson- the JSON object containing browser details parameters- Returns:
- a new ExtendedClientDetails instance
- Throws:
RuntimeException- if the JSON is not a valid object
-
refresh
Refreshes the browser details by fetching updated values from the browser. The refresh happens asynchronously. The cached values in this instance will be updated when the browser responds, and then the provided callback will be invoked with the updated details.- Parameters:
callback- a callback that will be invoked with the updated ExtendedClientDetails when the refresh is complete
-