本文整理了Java中org.springframework.mobile.device.Device
类的一些代码示例,展示了Device
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Device
类的具体详情如下:
包路径:org.springframework.mobile.device.Device
类名称:Device
[英]A model for the user agent or device that submitted the current request. Callers may introspect this model to vary UI control or rendering logic by device type.
[中]提交当前请求的用户代理或设备的模型。调用者可能会反省此模型,以根据设备类型改变UI控制或呈现逻辑。
代码示例来源: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: 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: 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
/**
* 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: spring-projects/spring-mobile
/**
* Should the combination of {@link Device} and {@link SitePreference} be handled
* as a tablet device
* @param device the resolved device
* @param sitePreference the specified site preference
* @return true if tablet
*/
public static boolean isTablet(Device device, SitePreference sitePreference) {
return sitePreference == SitePreference.TABLET || device != null && device.isTablet() && sitePreference == null;
}
代码示例来源:origin: org.springframework.mobile/spring-mobile-device
/**
* Should the combination of {@link Device} and {@link SitePreference} be handled
* as a normal device
* @param device the resolved device
* @param sitePreference the specified site preference
* @return true if normal
*/
public static boolean isNormal(Device device, SitePreference sitePreference) {
return sitePreference == SitePreference.NORMAL ||
(device == null || device.isNormal() && sitePreference == null);
}
代码示例来源:origin: spring-projects/spring-mobile
@RequestMapping("/")
public ResponseEntity<Void> test(Device device) {
if (device.getDevicePlatform() != null) {
return new ResponseEntity<>(HttpStatus.OK);
}
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
代码示例来源: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: 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()).isFalse();
assertThat(device.isMobile()).isTrue();
assertThat(device.isTablet()).isFalse();
assertThat(device.getDevicePlatform()).isEqualByComparingTo(DevicePlatform.IOS);
}
代码示例来源: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.springframework.mobile/spring-mobile-device
/**
* Should the combination of {@link Device} and {@link SitePreference} be handled
* as a tablet device
* @param device the resolved device
* @param sitePreference the specified site preference
* @return true if tablet
*/
public static boolean isTablet(Device device, SitePreference sitePreference) {
return sitePreference == SitePreference.TABLET || device != null && device.isTablet() && sitePreference == null;
}
代码示例来源:origin: spring-projects/spring-mobile
/**
* Should the combination of {@link Device} and {@link SitePreference} be handled
* as a normal device
* @param device the resolved device
* @param sitePreference the specified site preference
* @return true if normal
*/
public static boolean isNormal(Device device, SitePreference sitePreference) {
return sitePreference == SitePreference.NORMAL ||
(device == null || device.isNormal() && sitePreference == null);
}
代码示例来源:origin: spring-projects/spring-mobile
private void assertIOSPlatform(MockMobileRequest request) {
Device device = resolver.resolveDevice(request);
assertEquals(device.getDevicePlatform(), DevicePlatform.IOS);
}
代码示例来源: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: org.springframework.mobile/spring-mobile-device
private boolean handleTabletIsNormal(Device device, SitePreference sitePreference) {
return sitePreference == SitePreference.TABLET && tabletIsMobile == false
&& (device.isTablet() || device.isMobile());
}
代码示例来源:origin: spring-projects/spring-mobile
@Test
public void resolveDevice() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(Config.class);
this.context.refresh();
DeviceResolverHandlerInterceptor interceptor = this.context.getBean(DeviceResolverHandlerInterceptor.class);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
interceptor.preHandle(request, response, null);
Device device = DeviceUtils.getCurrentDevice(request);
assertThat(device.isNormal()).isFalse();
assertThat(device.isMobile()).isTrue();
assertThat(device.isTablet()).isFalse();
assertThat(device.getDevicePlatform()).isEqualByComparingTo(DevicePlatform.IOS);
}
代码示例来源:origin: org.kantega.openaksess/openaksess-core
private DeviceCategory getDeviceFromUserAgent(HttpServletRequest request) {
Device device = deviceResolver.resolveDevice(request);
return device.isMobile() ? DeviceCategory.MOBILE : DeviceCategory.DESKTOP;
}
}
代码示例来源:origin: spring-projects/spring-mobile
private void assertAndroidPlatform(MockMobileRequest request) {
Device device = resolver.resolveDevice(request);
assertEquals(device.getDevicePlatform(), DevicePlatform.ANDROID);
}
代码示例来源: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: spring-projects/spring-mobile
private boolean handleTabletIsNormal(Device device, SitePreference sitePreference) {
return sitePreference == SitePreference.TABLET && tabletIsMobile == false
&& (device.isTablet() || device.isMobile());
}
内容来源于网络,如有侵权,请联系作者删除!