Search in sources :

Example 1 with DeviceInfo

use of com.haulmont.cuba.gui.config.DeviceInfo in project cuba by cuba-platform.

the class WebDeviceInfoProvider method getDeviceInfo.

@Nullable
@Override
public DeviceInfo getDeviceInfo() {
    // per request cache
    HttpServletRequest currentServletRequest = VaadinServletService.getCurrentServletRequest();
    if (currentServletRequest == null) {
        return null;
    }
    DeviceInfo deviceInfo = (DeviceInfo) currentServletRequest.getAttribute(DeviceInfoProvider.NAME);
    if (deviceInfo != null) {
        return deviceInfo;
    }
    Page page = Page.getCurrent();
    if (page == null) {
        return null;
    }
    WebBrowser webBrowser = page.getWebBrowser();
    DeviceInfo di = new DeviceInfo();
    di.setAddress(webBrowser.getAddress());
    di.setBrowserApplication(webBrowser.getBrowserApplication());
    di.setBrowserMajorVersion(webBrowser.getBrowserMajorVersion());
    di.setBrowserMinorVersion(webBrowser.getBrowserMinorVersion());
    di.setChrome(webBrowser.isChrome());
    di.setChromeFrame(webBrowser.isChromeFrame());
    di.setChromeFrameCapable(webBrowser.isChromeFrameCapable());
    di.setEdge(webBrowser.isEdge());
    di.setFirefox(webBrowser.isFirefox());
    di.setOpera(webBrowser.isOpera());
    di.setIE(webBrowser.isIE());
    if (webBrowser.isWindows()) {
        di.setOperatingSystem(OperatingSystem.WINDOWS);
    } else if (webBrowser.isAndroid()) {
        di.setOperatingSystem(OperatingSystem.ANDROID);
    } else if (webBrowser.isIOS()) {
        di.setOperatingSystem(OperatingSystem.IOS);
    } else if (webBrowser.isMacOSX()) {
        di.setOperatingSystem(OperatingSystem.MACOSX);
    } else if (webBrowser.isLinux()) {
        di.setOperatingSystem(OperatingSystem.LINUX);
    }
    di.setIPad(webBrowser.isIPad());
    di.setIPhone(webBrowser.isIPhone());
    di.setWindowsPhone(webBrowser.isWindowsPhone());
    di.setSecureConnection(webBrowser.isSecureConnection());
    di.setLocale(webBrowser.getLocale());
    di.setScreenHeight(webBrowser.getScreenHeight());
    di.setScreenWidth(webBrowser.getScreenWidth());
    currentServletRequest.setAttribute(DeviceInfoProvider.NAME, di);
    return di;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebBrowser(com.vaadin.server.WebBrowser) DeviceInfo(com.haulmont.cuba.gui.config.DeviceInfo) Page(com.vaadin.server.Page) Nullable(javax.annotation.Nullable)

Aggregations

DeviceInfo (com.haulmont.cuba.gui.config.DeviceInfo)1 Page (com.vaadin.server.Page)1 WebBrowser (com.vaadin.server.WebBrowser)1 Nullable (javax.annotation.Nullable)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1