Java Code Examples for android.content.res.Configuration#SMALLEST_SCREEN_WIDTH_DP_UNDEFINED

The following examples show how to use android.content.res.Configuration#SMALLEST_SCREEN_WIDTH_DP_UNDEFINED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceQualifiersFragment.java    From java-android-developertools with Apache License 2.0 5 votes vote down vote up
private void setUpManualResourceQualifiers(View view) {
    final Configuration configuration = getResources().getConfiguration();

    String mccAndMnc = getString(R.string.fallback_no_qualifier);
    if (configuration.mcc != 0) { // NOTE: According to the docs, 0 if undefined, even though Wikipedia says 0 is used for test networks
        mccAndMnc = "mcc" + String.format(Locale.US, "%03d", configuration.mcc); // Mobile country codes should always be 3 decimals, but can be prefixed with 0
        mccAndMnc += "-mnc" + getBestGuessMobileNetworkCode(configuration);
    }
    ((TextView) view.findViewById(R.id.textView_mcc_and_mnc)).setText(mccAndMnc);

    ((TextView) view.findViewById(R.id.textView_locale)).setText(configuration.locale.getLanguage() + "-r" + configuration.locale.getCountry());

    String smallestWidth = getString(R.string.fallback_no_qualifier);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        if (configuration.smallestScreenWidthDp != Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
            smallestWidth = "sw" + configuration.smallestScreenWidthDp + "dp";
        }
    }
    ((TextView) view.findViewById(R.id.textView_smallest_width)).setText(smallestWidth);

    String availableWidth = getString(R.string.fallback_no_qualifier);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        if (configuration.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) {
            availableWidth = "w" + configuration.screenWidthDp + "dp";
        }
    }
    ((TextView) view.findViewById(R.id.textView_available_width)).setText(availableWidth);

    String availableHeight = getString(R.string.fallback_no_qualifier);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        if (configuration.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED) {
            availableHeight = "h" + configuration.screenHeightDp + "dp";
        }
    }
    ((TextView) view.findViewById(R.id.textView_available_height)).setText(availableHeight);
}
 
Example 2
Source File: DeviceTypeResolver.java    From react-native-device-info with MIT License 5 votes vote down vote up
private DeviceType getDeviceTypeFromResourceConfiguration() {
  int smallestScreenWidthDp = context.getResources().getConfiguration().smallestScreenWidthDp;

  if (smallestScreenWidthDp == Configuration.SMALLEST_SCREEN_WIDTH_DP_UNDEFINED) {
    return DeviceType.UNKNOWN;
  }

  return smallestScreenWidthDp >= 600 ? DeviceType.TABLET : DeviceType.HANDSET;
}