Java Code Examples for android.os.PersistableBundle#keySet()

The following examples show how to use android.os.PersistableBundle#keySet() . 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: BundleUtil.java    From android-testdpc with Apache License 2.0 6 votes vote down vote up
@TargetApi(VERSION_CODES.LOLLIPOP_MR1)
public static Bundle persistableBundleToBundle(PersistableBundle persistableBundle) {
    Set<String> keySet = persistableBundle.keySet();
    Bundle bundle = new Bundle();
    for (String key : keySet) {
        Object value = persistableBundle.get(key);
        if (value instanceof Boolean) {
            bundle.putBoolean(key, (boolean) value);
        } else if (value instanceof Integer) {
            bundle.putInt(key, (int) value);
        } else if (value instanceof String) {
            bundle.putString(key, (String) value);
        } else if (value instanceof String[]) {
            bundle.putStringArray(key, (String[]) value);
        } else if (value instanceof PersistableBundle) {
            Bundle innerBundle = persistableBundleToBundle((PersistableBundle) value);
            bundle.putBundle(key, innerBundle);
        }
    }
    return bundle;
}
 
Example 2
Source File: JobStore.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private PersistableBundle deepCopyBundle(PersistableBundle bundle, int maxDepth) {
    if (maxDepth <= 0) {
        return null;
    }
    PersistableBundle copy = (PersistableBundle) bundle.clone();
    Set<String> keySet = bundle.keySet();
    for (String key: keySet) {
        Object o = copy.get(key);
        if (o instanceof PersistableBundle) {
            PersistableBundle bCopy = deepCopyBundle((PersistableBundle) o, maxDepth-1);
            copy.putPersistableBundle(key, bCopy);
        }
    }
    return copy;
}
 
Example 3
Source File: Util.java    From BackPackTrackII with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
public static Bundle getBundle(PersistableBundle arg) {
    Bundle result = new Bundle();
    for (String key : arg.keySet())
        if (arg.get(key) instanceof Boolean)
            result.putBoolean(key, arg.getBoolean(key));
        else if (arg.get(key) instanceof Integer)
            result.putInt(key, arg.getInt(key));
        else if (arg.get(key) instanceof Long)
            result.putLong(key, arg.getLong(key));
        else if (arg.get(key) instanceof String || arg.get(key) == null)
            result.putString(key, arg.getString(key));
    return result;
}
 
Example 4
Source File: SpannableUtils.java    From talkback with Apache License 2.0 4 votes vote down vote up
/**
 * Logs the type, position and args of spans which attach to given text, but only if log priority
 * is equal to Log.VERBOSE. Format is {type 'spanned text' extra-data} {type 'other text'
 * extra-data} ..."
 *
 * @param text Text to be logged
 */
public static String spansToStringForLogging(CharSequence text) {
  if (!LogUtils.shouldLog(Log.VERBOSE)) {
    return null;
  }

  if (isEmptyOrNotSpannableStringType(text)) {
    return null;
  }

  Spanned spanned = (Spanned) text;
  ParcelableSpan[] spans = spanned.getSpans(0, text.length(), ParcelableSpan.class);
  if (spans.length == 0) {
    return null;
  }

  StringBuilder stringBuilder = new StringBuilder();
  for (ParcelableSpan span : spans) {
    stringBuilder.append("{");
    // Span type.
    stringBuilder.append(span.getClass().getSimpleName());

    // Span text.
    int start = spanned.getSpanStart(span);
    int end = spanned.getSpanEnd(span);
    if (start < 0 || end < 0 || start == end) {
      stringBuilder.append(" invalid index:[");
      stringBuilder.append(start);
      stringBuilder.append(",");
      stringBuilder.append(end);
      stringBuilder.append("]}");
      continue;
    } else {
      stringBuilder.append(" '");
      stringBuilder.append(spanned, start, end);
      stringBuilder.append("'");
    }

    // Extra data.
    if (span instanceof LocaleSpan) {
      LocaleSpan localeSpan = (LocaleSpan) span;
      if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
        Locale locale = localeSpan.getLocale();
        if (locale != null) {
          stringBuilder.append(" locale=");
          stringBuilder.append(locale);
        }
      } else {
        LocaleList localeList = localeSpan.getLocales();
        int size = localeList.size();
        if (size > 0) {
          stringBuilder.append(" locale=[");
          for (int i = 0; i < size - 1; i++) {
            stringBuilder.append(localeList.get(i));
            stringBuilder.append(",");
          }
          stringBuilder.append(localeList.get(size - 1));
          stringBuilder.append("]");
        }
      }

    } else if (span instanceof TtsSpan) {
      TtsSpan ttsSpan = (TtsSpan) span;
      stringBuilder.append(" ttsType=");
      stringBuilder.append(ttsSpan.getType());
      PersistableBundle bundle = ttsSpan.getArgs();
      Set<String> keys = bundle.keySet();
      if (!keys.isEmpty()) {
        for (String key : keys) {
          stringBuilder.append(" ");
          stringBuilder.append(key);
          stringBuilder.append("=");
          stringBuilder.append(bundle.get(key));
        }
      }
    } else if (span instanceof URLSpan) {
      URLSpan urlSpan = (URLSpan) span;
      stringBuilder.append(" url=");
      stringBuilder.append(urlSpan.getURL());
    }
    stringBuilder.append("}");
  }
  return stringBuilder.toString();
}