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

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

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

Device.isNormal介绍

[英]True if this device is not a mobile or tablet device.
[中]如果此设备不是移动设备或平板电脑设备,则为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: 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

/**
 * 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: 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: 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: 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: com.foreach.across.modules/spring-mobile-module

@Override
  public String resolveDeviceSpecificView( String viewName ) {
    Device device = DeviceUtils.getCurrentDevice( RequestContextHolder.currentRequestAttributes() );
    StringBuilder builder = new StringBuilder();

    if ( device.isMobile() && deviceTypes.contains( DeviceType.MOBILE ) ) {
      builder.append( SpringMobileConfiguration.MOBILE_PREFIX );
    }
    else if ( device.isTablet() && deviceTypes.contains( DeviceType.TABLET ) ) {
      builder.append( SpringMobileConfiguration.TABLET_PREFIX );
    }
    else if ( device.isNormal() && deviceTypes.contains( DeviceType.NORMAL ) ) {
      builder.append( SpringMobileConfiguration.NORMAL_PREFIX );
    }

    builder.append( viewName );

    return builder.toString();
  }
}

代码示例来源:origin: jonsychen/rest-security-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

@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

@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: 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: 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

@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()).isTrue();
  assertThat(device.isMobile()).isFalse();
  assertThat(device.isTablet()).isFalse();
  assertThat(device.getDevicePlatform()).isEqualByComparingTo(DevicePlatform.UNKNOWN);
}

代码示例来源: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 constructorNormalDeviceOverride() {
  String[] normalDevices = new String[] { "android", "iphone" };
  LiteDeviceResolver resolver2 = new LiteDeviceResolver(
      Arrays.asList(normalDevices));
  request.setUserAgentHeader(UserAgent.IPHONE_IOS5_STRING);
  Device device = resolver2.resolveDevice(request);
  assertTrue(device.isNormal());
  assertFalse(device.isMobile());
  assertFalse(device.isTablet());
  assertEquals(device.toString(), NORMAL_TO_STRING);
  assertIOSPlatform(request);
}

相关文章