Java Code Examples for android.os.Bundle#getParcelableArray()

The following examples show how to use android.os.Bundle#getParcelableArray() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: MHViewer   File: GalleryDetailScene.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onSceneResult(int requestCode, int resultCode, Bundle data) {
    switch (requestCode) {
        case REQUEST_CODE_COMMENT_GALLERY:
            if (resultCode != RESULT_OK || data == null) {
                break;
            }
            Parcelable[] array = data.getParcelableArray(GalleryCommentsScene.KEY_COMMENTS);
            if (!(array instanceof GalleryComment[])) {
                break;
            }
            GalleryComment[] comments = (GalleryComment[]) array;
            if (mGalleryDetail == null) {
                break;
            }
            mGalleryDetail.comments = comments;
            bindComments(comments);
            break;
        default:
            super.onSceneResult(requestCode, resultCode, data);
    }
}
 
Example 2
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        if (fss != null) {
            for (Parcelable fs : fss) {
                mSavedState.add((Fragment.SavedState) fs);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    f.setMenuVisibility(false);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
Example 3
@Test
public void testWriteToBundle_contentUriTrigger() {
  ObservedUri observedUri =
      new ObservedUri(ContactsContract.AUTHORITY_URI, Flags.FLAG_NOTIFY_FOR_DESCENDANTS);
  ContentUriTrigger contentUriTrigger = Trigger.contentUriTrigger(Arrays.asList(observedUri));
  Bundle bundle =
      writer.writeToBundle(
          initializeDefaultBuilder().setTrigger(contentUriTrigger).build(), new Bundle());
  Uri[] uris = (Uri[]) bundle.getParcelableArray(BundleProtocol.PACKED_PARAM_CONTENT_URI_ARRAY);
  int[] flags = bundle.getIntArray(BundleProtocol.PACKED_PARAM_CONTENT_URI_FLAGS_ARRAY);
  assertTrue("Array size", uris.length == flags.length && flags.length == 1);
  assertEquals(
      BundleProtocol.PACKED_PARAM_CONTENT_URI_ARRAY, ContactsContract.AUTHORITY_URI, uris[0]);
  assertEquals(
      BundleProtocol.PACKED_PARAM_CONTENT_URI_FLAGS_ARRAY,
      Flags.FLAG_NOTIFY_FOR_DESCENDANTS,
      flags[0]);
}
 
Example 4
Source Project: MHViewer   File: GalleryCommentsScene.java    License: Apache License 2.0 5 votes vote down vote up
private void handleArgs(Bundle args) {
    if (args == null) {
        return;
    }

    mApiUid = args.getLong(KEY_API_UID, -1L);
    mApiKey = args.getString(KEY_API_KEY);
    mGid = args.getString(KEY_GID);
    mToken = args.getString(KEY_TOKEN, null);
    Parcelable[] parcelables = args.getParcelableArray(KEY_COMMENTS);
    if (parcelables instanceof GalleryComment[]) {
        mComments = (GalleryComment[]) parcelables;
    }
}
 
Example 5
/**
 * Helper method to extract the all clients from the given bundle and call {@link
 * #registerClient(String, Messenger)} or {@link #unregisterClient(String, Messenger)}.
 *
 * @param clientsBundle The message bundle containing clients info
 * @param shouldRegister Whether to register or unregister given clients
 */
private void clientsRegistrationFromBundle(Bundle clientsBundle, boolean shouldRegister) {
  logDebugWithProcess(TAG, "clientsRegistrationFromBundle called");

  if (null == clientsBundle) {
    Log.w(TAG, "The client bundle is null, ignoring...");
    return;
  }

  ArrayList<String> clientTypes = clientsBundle.getStringArrayList(BUNDLE_KEY_CLIENTS);

  if (null == clientTypes) {
    Log.w(TAG, "No clients found in the given bundle");
    return;
  }

  for (String type : clientTypes) {
    Parcelable[] clientArray = clientsBundle.getParcelableArray(String.valueOf(type));
    if (clientArray != null) {
      for (Parcelable client : clientArray) {
        if (shouldRegister) {
          registerClient(type, (Messenger) client);
        } else {
          unregisterClient(type, (Messenger) client);
        }
      }
    }
  }
}
 
Example 6
private void updateItems(Bundle restrictions) {
    if (!BUNDLE_SUPPORTED) {
        return;
    }
    StringBuilder builder = new StringBuilder();
    if (restrictions != null) {
        Parcelable[] parcelables = restrictions.getParcelableArray(KEY_ITEMS);
        if (parcelables != null && parcelables.length > 0) {
            Bundle[] items = new Bundle[parcelables.length];
            for (int i = 0; i < parcelables.length; i++) {
                items[i] = (Bundle) parcelables[i];
            }
            boolean first = true;
            for (Bundle item : items) {
                if (!item.containsKey(KEY_ITEM_KEY) || !item.containsKey(KEY_ITEM_VALUE)) {
                    continue;
                }
                if (first) {
                    first = false;
                } else {
                    builder.append(", ");
                }
                builder.append(item.getString(KEY_ITEM_KEY));
                builder.append(":");
                builder.append(item.getString(KEY_ITEM_VALUE));
            }
        } else {
            builder.append(getString(R.string.none));
        }
    } else {
        builder.append(getString(R.string.none));
    }
    mTextItems.setText(getString(R.string.your_items, builder));
}
 
Example 7
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (Parcelable fs : fss) {
                mSavedState.add((Fragment.SavedState) fs);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
Example 8
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (Parcelable fs : fss) {
                mSavedState.add((Fragment.SavedState) fs);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
Example 9
/**
 * Get an array of Notification objects from a parcelable array bundle field.
 * Update the bundle to have a typed array so fetches in the future don't need
 * to do an array copy.
 */
private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) {
    Parcelable[] array = bundle.getParcelableArray(key);
    if (array instanceof Notification[] || array == null) {
        return (Notification[]) array;
    }
    Notification[] typedArray = new Notification[array.length];
    for (int i = 0; i < array.length; i++) {
        typedArray[i] = (Notification) array[i];
    }
    bundle.putParcelableArray(key, typedArray);
    return typedArray;
}
 
Example 10
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState == null) {
        Bundle arguments = getArguments();
        uploadables = arguments.getParcelableArray(UPLOADABLES);
    } else {
        startMsg = savedInstanceState.getString(LASTMESSAGE);
    }

    Bundle extras = getActivity().getIntent().getExtras();
    user = extras.getString(PREFS_KEY_USER);
    pwd = extras.getString(PREFS_KEY_PWD);
}
 
Example 11
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle)state;
        bundle.setClassLoader(loader);
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (int i=0; i<fss.length; i++) {
                mSavedState.add((Fragment.SavedState)fss[i]);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key: keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    // f.setMenuVisibility(false);
                    mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
Example 12
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle)state;
        bundle.setClassLoader(loader);
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (int i=0; i<fss.length; i++) {
                mSavedState.add((Fragment.SavedState)fss[i]);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key: keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
Example 13
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (int i = 0; i < fss.length; i++) {
                mSavedState.add((Fragment.SavedState) fss[i]);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
Example 14
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle)state;
        bundle.setClassLoader(loader);
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (int i=0; i<fss.length; i++) {
                mSavedState.add((Fragment.SavedState)fss[i]);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key: keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
Example 15
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (Parcelable fs : fss) {
                mSavedState.add((Fragment.SavedState) fs);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
Example 16
Source Project: V.FlyoutTest   File: FragmentStatePagerAdapter.java    License: MIT License 5 votes vote down vote up
@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle)state;
        bundle.setClassLoader(loader);
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (int i=0; i<fss.length; i++) {
                mSavedState.add((Fragment.SavedState)fss[i]);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key: keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
Example 17
Source Project: Bitocle   File: SuperActivityToast.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Recreates pending/showing {@value #TAG} from orientation change and
 * reattaches any OnClickWrappers/OnDismissWrappers.
 *
 * @param bundle   {@link android.os.Bundle}
 * @param activity {@link android.app.Activity}
 * @param wrappers {@link com.github.johnpersano.supertoasts.util.Wrappers}
 */
public static void onRestoreState(Bundle bundle, Activity activity, Wrappers wrappers) {

    if (bundle == null) {

        return;
    }

    Parcelable[] savedArray = bundle.getParcelableArray(BUNDLE_TAG);

    int i = 0;

    if (savedArray != null) {

        for (Parcelable parcelable : savedArray) {

            i++;

            new SuperActivityToast(activity, (ReferenceHolder) parcelable, wrappers, i);

        }

    }

}
 
Example 18
public void restoreState(Parcelable parcelable, ClassLoader classloader)
{
    if (parcelable != null)
    {
        Bundle bundle = (Bundle)parcelable;
        bundle.setClassLoader(classloader);
        Parcelable aparcelable[] = bundle.getParcelableArray("states");
        e.clear();
        f.clear();
        if (aparcelable != null)
        {
            for (int j = 0; j < aparcelable.length; j++)
            {
                e.add((android.app.Fragment.SavedState)aparcelable[j]);
            }

        }
        Iterator iterator = bundle.keySet().iterator();
        do
        {
            if (!iterator.hasNext())
            {
                break;
            }
            String s = (String)iterator.next();
            if (s.startsWith("f"))
            {
                int i = Integer.parseInt(s.substring(1));
                Fragment fragment = c.getFragment(bundle, s);
                if (fragment != null)
                {
                    for (; f.size() <= i; f.add(null)) { }
                    FragmentCompat.setMenuVisibility(fragment, false);
                    f.set(i, fragment);
                } else
                {
                    Log.w("FragmentStatePagerAdapter", (new StringBuilder()).append("Bad fragment at key ").append(s).toString());
                }
            }
        } while (true);
    }
}
 
Example 19
public static ActiveNotificationsArgs fromBundle(Bundle bundle) {
    ensureBundleContains(bundle, KEY_ACTIVE_NOTIFICATIONS);
    return new ActiveNotificationsArgs((StatusBarNotification[])
            bundle.getParcelableArray(KEY_ACTIVE_NOTIFICATIONS));
}
 
Example 20
/**
 * Gets the location of specific range of node text. It returns null if the node doesn't support
 * text location data or the index is incorrect.
 *
 * @param node The node being queried.
 * @param fromCharIndex start index of the queried text range.
 * @param toCharIndex end index of the queried text range.
 */
@TargetApi(Build.VERSION_CODES.O)
@Nullable
public static List<Rect> getTextLocations(
    AccessibilityNodeInfoCompat node, int fromCharIndex, int toCharIndex) {
  if (node == null || !BuildVersionUtils.isAtLeastO()) {
    return null;
  }

  if (fromCharIndex < 0
      || !PrimitiveUtils.isInInterval(
          toCharIndex, fromCharIndex, node.getText().length(), true)) {
    return null;
  }
  AccessibilityNodeInfo info = node.unwrap();
  if (info == null) {
    return null;
  }
  Bundle args = new Bundle();
  args.putInt(
      AccessibilityNodeInfo.EXTRA_DATA_TEXT_CHARACTER_LOCATION_ARG_START_INDEX, fromCharIndex);
  args.putInt(
      AccessibilityNodeInfo.EXTRA_DATA_TEXT_CHARACTER_LOCATION_ARG_LENGTH,
      toCharIndex - fromCharIndex);
  if (!info.refreshWithExtraData(
      AccessibilityNodeInfo.EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY, args)) {
    return null;
  }

  Bundle extras = info.getExtras();
  Parcelable[] data =
      extras.getParcelableArray(AccessibilityNodeInfo.EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY);
  if (data == null) {
    return null;
  }
  List<Rect> result = new ArrayList<>(data.length);
  for (Parcelable item : data) {
    if (item == null) {
      continue;
    }
    RectF rectF = (RectF) item;
    result.add(
        new Rect((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) rectF.bottom));
  }
  return result;
}