Example usage for com.liferay.portal.kernel.theme ThemeDisplay getDevice

List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay getDevice

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.theme ThemeDisplay getDevice.

Prototype

public Device getDevice() 

Source Link

Document

Returns the information about the detected device, such as the device's brand, browser, operating system, screen resolution, etc.

Usage

From source file:com.liferay.journal.transformer.JournalTransformer.java

License:Open Source License

protected Device getDevice(ThemeDisplay themeDisplay) {
    if (themeDisplay != null) {
        return themeDisplay.getDevice();
    }//  w w w .ja  v a 2 s  .  c om

    return UnknownDevice.getInstance();
}

From source file:com.liferay.mobile.device.rules.rule.group.rule.SimpleRuleHandler.java

License:Open Source License

@Override
public boolean evaluateRule(MDRRule mdrRule, ThemeDisplay themeDisplay) {
    Device device = themeDisplay.getDevice();

    if (device == null) {
        if (_log.isDebugEnabled()) {
            _log.debug("Rule evaluation is not possible because the information "
                    + "about the device is not available");
        }//from   w  ww  . j  a v a  2s .c om

        return false;
    }

    if (!isValidMultiValue(mdrRule, PROPERTY_OS, device.getOS())) {
        return false;
    }

    if (!isValidBooleanValue(mdrRule, PROPERTY_TABLET, device.isTablet())) {
        return false;
    }

    Dimensions screenPhysicalSize = device.getScreenPhysicalSize();

    if (!isValidRangeValue(mdrRule, PROPERTY_SCREEN_PHYSICAL_HEIGHT_MAX, PROPERTY_SCREEN_PHYSICAL_HEIGHT_MIN,
            screenPhysicalSize.getHeight())) {

        return false;
    }

    if (!isValidRangeValue(mdrRule, PROPERTY_SCREEN_PHYSICAL_WIDTH_MAX, PROPERTY_SCREEN_PHYSICAL_WIDTH_MIN,
            screenPhysicalSize.getWidth())) {

        return false;
    }

    Dimensions screenResolution = device.getScreenResolution();

    if (!isValidRangeValue(mdrRule, PROPERTY_SCREEN_RESOLUTION_HEIGHT_MAX,
            PROPERTY_SCREEN_RESOLUTION_HEIGHT_MIN, screenResolution.getHeight())) {

        return false;
    }

    if (!isValidRangeValue(mdrRule, PROPERTY_SCREEN_RESOLUTION_WIDTH_MAX, PROPERTY_SCREEN_RESOLUTION_WIDTH_MIN,
            screenResolution.getWidth())) {

        return false;
    }

    return true;
}