org.springframework.mobile.device.Device.isMobile()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(212)

本文整理了Java中org.springframework.mobile.device.Device.isMobile()方法的一些代码示例,展示了Device.isMobile()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Device.isMobile()方法的具体详情如下:
包路径:org.springframework.mobile.device.Device
类名称:Device
方法名:isMobile

Device.isMobile介绍

[英]True if this device is a mobile device such as an Apple iPhone or an Nexus One Android. Could be used by a pre-handle interceptor to redirect the user to a dedicated mobile web site. Could be used to apply a different page layout or stylesheet when the device is a mobile device.
[中]如果此设备是苹果iPhone或Nexus One Android等移动设备,则为True。可由预处理拦截器用于将用户重定向到专用移动网站。当设备是移动设备时,可用于应用不同的页面布局或样式表。

代码示例

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

protected void resolveDeviceType(final HttpServletRequest request) {
  final Device device = deviceResolver.resolveDevice(request);
  String type = "UNKNOWN";
  
  if (device != null) {
    if (device.isMobile()) {
      type = "MOBILE";
    } else if (device.isTablet()) {
      type = "TABLET";
    } else if (device.isNormal()) {
      type = "NORMAL";
    }
  }
  BroadleafRequestContext.getBroadleafRequestContext().getAdditionalProperties().put(DeviceUtils.CURRENT_DEVICE_ATTRIBUTE, WebRequestDeviceType.getInstance(type));
}

代码示例来源:origin: spring-projects/spring-mobile

/**
 * Should the combination of {@link Device} and {@link SitePreference} be handled
 * as a mobile device
 * @param device the resolved device
 * @param sitePreference the specified site preference
 * @return true if mobile
 */
public static boolean isMobile(Device device, SitePreference sitePreference) {
  return sitePreference == SitePreference.MOBILE || device != null && device.isMobile() && sitePreference == null;
}

代码示例来源:origin: org.springframework.mobile/spring-mobile-device

/**
 * Should the combination of {@link Device} and {@link SitePreference} be handled
 * as a mobile device
 * @param device the resolved device
 * @param sitePreference the specified site preference
 * @return true if mobile
 */
public static boolean isMobile(Device device, SitePreference sitePreference) {
  return sitePreference == SitePreference.MOBILE || device != null && device.isMobile() && sitePreference == null;
}

代码示例来源:origin: org.kantega.openaksess/openaksess-core

private DeviceCategory getDeviceFromUserAgent(HttpServletRequest request) {
    Device device = deviceResolver.resolveDevice(request);

    return device.isMobile() ? DeviceCategory.MOBILE : DeviceCategory.DESKTOP;
  }
}

代码示例来源:origin: org.apache.rave/rave-web

/**
 * Utility function to determine if this HttpServletRequest
 * is coming from a mobile client
 *
 * @param request the HttpServletRequest from the client
 * @return true if the client is a mobile device, false if not mobile
 */
public static boolean isMobileDevice(HttpServletRequest request) {
  return DeviceUtils.getCurrentDevice(request).isMobile();
}

代码示例来源:origin: stackoverflow.com

@RequestMapping("/")
public String home(Device device) {
  if (device.isMobile()) {
    return "mobile/home/index";
  } else if (device.isTablet()) {
    return "tablet/home/index";
  } else {
    return "desktop/home/index";       
  }
}

代码示例来源:origin: org.springframework.mobile/spring-mobile-device

private boolean handleTabletIsMobile(Device device, SitePreference sitePreference) {
  return tabletIsMobile == true && (sitePreference == SitePreference.TABLET || sitePreference == null)
      && (device.isTablet() || device.isMobile());
}

代码示例来源:origin: org.springframework.mobile/spring-mobile-device

private boolean handleTabletIsNormal(Device device, SitePreference sitePreference) {
  return sitePreference == SitePreference.TABLET && tabletIsMobile == false
      && (device.isTablet() || device.isMobile());
}

代码示例来源:origin: bfwg/springboot-jwt-starter

private Date generateExpirationDate(Device device) {
  long expiresIn = device.isTablet() || device.isMobile() ? MOBILE_EXPIRES_IN : EXPIRES_IN;
  return new Date(timeProvider.now().getTime() + expiresIn * 1000);
}

代码示例来源:origin: bfwg/springboot-jwt-starter

private String generateAudience(Device device) {
  String audience = AUDIENCE_UNKNOWN;
  if (device.isNormal()) {
    audience = AUDIENCE_WEB;
  } else if (device.isTablet()) {
    audience = AUDIENCE_TABLET;
  } else if (device.isMobile()) {
    audience = AUDIENCE_MOBILE;
  }
  return audience;
}

代码示例来源:origin: koldaman/springboot-jwt-swagger

private String generateAudience(Device device) {
  String audience = AUDIENCE_UNKNOWN;
  if (device.isNormal()) {
    audience = AUDIENCE_WEB;
  } else if (device.isTablet()) {
    audience = AUDIENCE_TABLET;
  } else if (device.isMobile()) {
    audience = AUDIENCE_MOBILE;
  }
  return audience;
}

代码示例来源:origin: liumapp/spring-security-mybatis-demo

private String generateAudience(Device device) {
  String audience = AUDIENCE_UNKNOWN;
  if (device.isNormal()) {
    audience = AUDIENCE_WEB;
  } else if (device.isTablet()) {
    audience = AUDIENCE_TABLET;
  } else if (device.isMobile()) {
    audience = AUDIENCE_MOBILE;
  }
  return audience;
}

代码示例来源:origin: TomChen001/xmanager

private String generateAudience(Device device) {
  String audience = AUDIENCE_UNKNOWN;
  if (device.isNormal()) {
    audience = AUDIENCE_WEB;
  } else if (device.isTablet()) {
    audience = AUDIENCE_TABLET;
  } else if (device.isMobile()) {
    audience = AUDIENCE_MOBILE;
  }
  return audience;
}

代码示例来源:origin: org.togglz/togglz-spring-mobile

@Override
  public boolean isActive(FeatureState featureState, FeatureUser user) {

    HttpServletRequest request = HttpServletRequestHolder.get();
    if (request != null) {
      Device device = DeviceUtils.getCurrentDevice(request);
      DeviceType deviceType = device.isMobile() ? MOBILE : (device.isTablet() ? TABLET : NORMAL);
      return (YES.equalsIgnoreCase(featureState.getParameter(deviceType.name())));

    }
    return false;

  }
}

代码示例来源:origin: spring-projects/spring-mobile

@Test
public void resolveDevice() throws Exception {
  MockHttpServletRequest request = new MockHttpServletRequest();
  MockHttpServletResponse response = new MockHttpServletResponse();
  DeviceResolverHandlerInterceptor interceptor = (DeviceResolverHandlerInterceptor) this.context
      .getBean("deviceResolverHandlerInterceptor");
  interceptor.preHandle(request, response, null);
  Device device = DeviceUtils.getCurrentDevice(request);
  assertThat(device.isNormal()).isTrue();
  assertThat(device.isMobile()).isFalse();
  assertThat(device.isTablet()).isFalse();
  assertThat(device.getDevicePlatform()).isEqualByComparingTo(DevicePlatform.UNKNOWN);
}

代码示例来源:origin: spring-projects/spring-mobile

private void assertMobile(MockMobileRequest request) {
  Device device = resolver.resolveDevice(request);
  assertFalse(device.isNormal());
  assertTrue(device.isMobile());
  assertFalse(device.isTablet());
  assertEquals(device.toString(), MOBILE_TO_STRING);
}

代码示例来源:origin: spring-projects/spring-mobile

private void assertTablet(MockMobileRequest request) {
  Device device = resolver.resolveDevice(request);
  assertFalse(device.isNormal());
  assertFalse(device.isMobile());
  assertTrue(device.isTablet());
  assertEquals(device.toString(), TABLET_TO_STRING);
}

代码示例来源:origin: spring-projects/spring-mobile

private void assertNormal(MockMobileRequest request) {
  Device device = resolver.resolveDevice(request);
  assertTrue(device.isNormal());
  assertFalse(device.isMobile());
  assertFalse(device.isTablet());
  assertEquals(device.toString(), NORMAL_TO_STRING);
}

代码示例来源:origin: spring-projects/spring-mobile

@Test
public void resolveDefaultResolver() throws Exception {
  filter = new DeviceResolverRequestFilter();
  request.addHeader("User-Agent", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7");
  filter.doFilterInternal(request, response, filterChain);
  Device device = DeviceUtils.getCurrentDevice(request);
  assertTrue(device.isMobile());
}

代码示例来源:origin: spring-projects/spring-mobile

@Test
public void resolveDefaultResolver() throws Exception {
  interceptor = new DeviceResolverHandlerInterceptor();
  request.addHeader("User-Agent", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7");
  assertTrue(interceptor.preHandle(request, response, null));
  Device device = DeviceUtils.getCurrentDevice(request);
  assertTrue(device.isMobile());
}

相关文章