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

The following examples show how to use android.os.Bundle#putParcelableArray() . 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 check out the related API usage on the sidebar.
Example 1
/**
 * Method for parsing the foursquare response
 *
 * @param response The Json string response
 * @return
 * @throws JSONException if the Json string is invalid
 */
private ResponseInfo parseVenuesResponse(final String response)
        throws JSONException {

    final ResponseInfo responseInfo = new ResponseInfo();

    final JSONObject responseObject = JsonUtils
            .readJSONObject(new JSONObject(response), HttpConstants.RESPONSE, true, true);
    final JSONArray venuesArray = JsonUtils
            .readJSONArray(responseObject, HttpConstants.VENUES, true, true);

    final Venue[] venues = new Venue[venuesArray.length()];
    JSONObject venueObject = null;
    for (int i = 0; i < venues.length; i++) {
        venueObject = JsonUtils.readJSONObject(venuesArray, i, true, true);
        venues[i] = new Venue();
        readVenueObjectIntoVenue(venueObject, venues[i]);
    }

    final Bundle responseBundle = new Bundle(1);
    responseBundle.putParcelableArray(HttpConstants.LOCATIONS, venues);
    responseInfo.responseBundle = responseBundle;
    return responseInfo;
}
 
Example 2
@Override
protected void onSaveInstanceState(final Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putInt(KEY_INSTANCE_STATE_PENDING_REQUEST, mPendingRequest);
    if (mPendingRequest == REQUEST_ADD_ACCOUNT) {
        outState.putParcelableArray(KEY_INSTANCE_STATE_EXISTING_ACCOUNTS, mExistingAccounts);
    }
    if (mSelectedItemIndex != SELECTED_ITEM_NONE) {
        if (mSelectedItemIndex == mAccounts.size()) {
            outState.putBoolean(KEY_INSTANCE_STATE_SELECTED_ADD_ACCOUNT, true);
        } else {
            outState.putBoolean(KEY_INSTANCE_STATE_SELECTED_ADD_ACCOUNT, false);
            outState.putString(KEY_INSTANCE_STATE_SELECTED_ACCOUNT_NAME,
                    mAccounts.get(mSelectedItemIndex).name);
        }
    }
}
 
Example 3
@Override
protected void onSaveInstanceState(final Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putInt(KEY_INSTANCE_STATE_PENDING_REQUEST, mPendingRequest);
    if (mPendingRequest == REQUEST_ADD_ACCOUNT) {
        outState.putParcelableArray(KEY_INSTANCE_STATE_EXISTING_ACCOUNTS, mExistingAccounts);
    }
    if (mSelectedItemIndex != SELECTED_ITEM_NONE) {
        if (mSelectedItemIndex == mPossiblyVisibleAccounts.size()) {
            outState.putBoolean(KEY_INSTANCE_STATE_SELECTED_ADD_ACCOUNT, true);
        } else {
            outState.putBoolean(KEY_INSTANCE_STATE_SELECTED_ADD_ACCOUNT, false);
            outState.putString(KEY_INSTANCE_STATE_SELECTED_ACCOUNT_NAME,
                    mPossiblyVisibleAccounts.get(mSelectedItemIndex).name);
        }
    }
    // save mAccounts
    Parcelable[] accounts = new Parcelable[mAccounts.size()];
    ArrayList<Integer> visibility = new ArrayList<>(mAccounts.size());
    int i = 0;
    for (Map.Entry<Account, Integer> e : mAccounts.entrySet()) {
        accounts[i++] = e.getKey();
        visibility.add(e.getValue());
    }
    outState.putParcelableArray(KEY_INSTANCE_STATE_ACCOUNTS_LIST, accounts);
    outState.putIntegerArrayList(KEY_INSTANCE_STATE_VISIBILITY_LIST, visibility);
}
 
Example 4
@VisibleForTesting
public static Bundle createConnectionBundle(
        String[] commandLine, FileDescriptorInfo[] filesToBeMapped) {
    assert sLinkerInitialized;

    Bundle bundle = new Bundle();
    bundle.putStringArray(ChildProcessConstants.EXTRA_COMMAND_LINE, commandLine);
    bundle.putParcelableArray(ChildProcessConstants.EXTRA_FILES, filesToBeMapped);
    // content specific parameters.
    bundle.putInt(ChildProcessConstants.EXTRA_CPU_COUNT, CpuFeatures.getCount());
    bundle.putLong(ChildProcessConstants.EXTRA_CPU_FEATURES, CpuFeatures.getMask());
    bundle.putBundle(Linker.EXTRA_LINKER_SHARED_RELROS, Linker.getInstance().getSharedRelros());
    return bundle;
}
 
Example 5
Source Project: cameraview   File: AspectRatioFragment.java    License: Apache License 2.0 5 votes vote down vote up
public static AspectRatioFragment newInstance(Set<AspectRatio> ratios,
        AspectRatio currentRatio) {
    final AspectRatioFragment fragment = new AspectRatioFragment();
    final Bundle args = new Bundle();
    args.putParcelableArray(ARG_ASPECT_RATIOS,
            ratios.toArray(new AspectRatio[ratios.size()]));
    args.putParcelable(ARG_CURRENT_ASPECT_RATIO, currentRatio);
    fragment.setArguments(args);
    return fragment;
}
 
Example 6
Source Project: MHViewer   File: GalleryCommentsScene.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putLong(KEY_API_UID, mApiUid);
    outState.putString(KEY_API_KEY, mApiKey);
    outState.putString(KEY_GID, mGid);
    outState.putString(KEY_TOKEN, mToken);
    outState.putParcelableArray(KEY_COMMENTS, mComments);
}
 
Example 7
@Nullable
@Override
public Bundle call(String method, String arg, Bundle extras) {
    String suggestedPackageName = null;
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
        suggestedPackageName = getCallingPackage();
    }
    String packageName = PackageUtils.getAndCheckCallingPackage(getContext(), suggestedPackageName);
    Log.d(TAG, "Call from " + packageName);
    if (!PackageUtils.callerHasExtendedAccess(getContext())) {
        String[] packagesForUid = getContext().getPackageManager().getPackagesForUid(Binder.getCallingUid());
        if (packagesForUid != null && packagesForUid.length != 0)
            Log.w(TAG, "Not granting extended access to " + Arrays.toString(packagesForUid)
                    + ", signature: " + PackageUtils.firstSignatureDigest(getContext(), packagesForUid[0]));
        if (getContext().checkCallingPermission(Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED)
            throw new SecurityException("Access denied, missing GET_ACCOUNTS or EXTENDED_ACCESS permission");
    }
    if (PROVIDER_METHOD_GET_ACCOUNTS.equals(method) && AuthConstants.DEFAULT_ACCOUNT_TYPE.equals(arg)) {
        Bundle result = new Bundle();
        AccountManager am = AccountManager.get(getContext());
        Account[] accounts = null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            accounts = am.getAccountsByTypeForPackage(arg, packageName);
        }
        if (accounts == null || accounts.length == 0) {
            accounts = am.getAccountsByType(arg);
        }
        result.putParcelableArray(PROVIDER_EXTRA_ACCOUNTS, accounts);
        return result;
    } else if (PROVIDER_METHOD_CLEAR_PASSWORD.equals(method)) {
        Account a = extras.getParcelable(PROVIDER_EXTRA_CLEAR_PASSWORD);
        AccountManager.get(getContext()).clearPassword(a);
        return null;
    }
    throw new UnsupportedOperationException(String.format("Unsupported method call %s(%s).", method, arg));
}
 
Example 8
Source Project: FacebookImageShareIntent   File: AppLinkData.java    License: MIT License 5 votes vote down vote up
private static Bundle toBundle(JSONObject node) throws JSONException {
    Bundle bundle = new Bundle();
    @SuppressWarnings("unchecked")
    Iterator<String> fields = node.keys();
    while (fields.hasNext()) {
        String key = fields.next();
        Object value;
        value = node.get(key);

        if (value instanceof JSONObject) {
            bundle.putBundle(key, toBundle((JSONObject) value));
        } else if (value instanceof JSONArray) {
            JSONArray valueArr = (JSONArray) value;
            if (valueArr.length() == 0) {
                bundle.putStringArray(key, new String[0]);
            } else {
                Object firstNode = valueArr.get(0);
                if (firstNode instanceof JSONObject) {
                    Bundle[] bundles = new Bundle[valueArr.length()];
                    for (int i = 0; i < valueArr.length(); i++) {
                        bundles[i] = toBundle(valueArr.getJSONObject(i));
                    }
                    bundle.putParcelableArray(key, bundles);
                } else if (firstNode instanceof JSONArray) {
                    // we don't support nested arrays
                    throw new FacebookException("Nested arrays are not supported.");
                } else { // just use the string value
                    String[] arrValues = new String[valueArr.length()];
                    for (int i = 0; i < valueArr.length(); i++) {
                        arrValues[i] = valueArr.get(i).toString();
                    }
                    bundle.putStringArray(key, arrValues);
                }
            }
        } else {
            bundle.putString(key, value.toString());
        }
    }
    return bundle;
}
 
Example 9
Source Project: AssistantBySDK   File: TimePickerDialog.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
    if (mTimePicker != null) {
        outState.putParcelable(KEY_INITIAL_TIME, mTimePicker.getTime());
        outState.putBoolean(KEY_IS_24_HOUR_VIEW, mIs24HourMode);
        outState.putInt(KEY_CURRENT_ITEM_SHOWING, mTimePicker.getCurrentItemShowing());
        outState.putBoolean(KEY_IN_KB_MODE, mInKbMode);
        if (mInKbMode) {
            outState.putIntegerArrayList(KEY_TYPED_TIMES, mTypedTimes);
        }
        outState.putString(KEY_TITLE, mTitle);
        outState.putBoolean(KEY_THEME_DARK, mThemeDark);
        outState.putBoolean(KEY_THEME_DARK_CHANGED, mThemeDarkChanged);
        outState.putInt(KEY_ACCENT, mAccentColor);
        outState.putBoolean(KEY_VIBRATE, mVibrate);
        outState.putBoolean(KEY_DISMISS, mDismissOnPause);
        outState.putParcelableArray(KEY_SELECTABLE_TIMES, mSelectableTimes);
        outState.putParcelable(KEY_MIN_TIME, mMinTime);
        outState.putParcelable(KEY_MAX_TIME, mMaxTime);
        outState.putBoolean(KEY_ENABLE_SECONDS, mEnableSeconds);
        outState.putBoolean(KEY_ENABLE_MINUTES, mEnableMinutes);
        outState.putInt(KEY_OK_RESID, mOkResid);
        outState.putString(KEY_OK_STRING, mOkString);
        outState.putInt(KEY_OK_COLOR, mOkColor);
        outState.putInt(KEY_CANCEL_RESID, mCancelResid);
        outState.putString(KEY_CANCEL_STRING, mCancelString);
        outState.putInt(KEY_CANCEL_COLOR, mCancelColor);
        outState.putSerializable(KEY_VERSION, mVersion);
    }
}
 
Example 10
Source Project: Abelana-Android   File: AppLinkData.java    License: Apache License 2.0 5 votes vote down vote up
private static Bundle toBundle(JSONObject node) throws JSONException {
    Bundle bundle = new Bundle();
    @SuppressWarnings("unchecked")
    Iterator<String> fields = node.keys();
    while (fields.hasNext()) {
        String key = fields.next();
        Object value;
        value = node.get(key);

        if (value instanceof JSONObject) {
            bundle.putBundle(key, toBundle((JSONObject) value));
        } else if (value instanceof JSONArray) {
            JSONArray valueArr = (JSONArray) value;
            if (valueArr.length() == 0) {
                bundle.putStringArray(key, new String[0]);
            } else {
                Object firstNode = valueArr.get(0);
                if (firstNode instanceof JSONObject) {
                    Bundle[] bundles = new Bundle[valueArr.length()];
                    for (int i = 0; i < valueArr.length(); i++) {
                        bundles[i] = toBundle(valueArr.getJSONObject(i));
                    }
                    bundle.putParcelableArray(key, bundles);
                } else if (firstNode instanceof JSONArray) {
                    // we don't support nested arrays
                    throw new FacebookException("Nested arrays are not supported.");
                } else { // just use the string value
                    String[] arrValues = new String[valueArr.length()];
                    for (int i = 0; i < valueArr.length(); i++) {
                        arrValues[i] = valueArr.get(i).toString();
                    }
                    bundle.putStringArray(key, arrValues);
                }
            }
        } else {
            bundle.putString(key, value.toString());
        }
    }
    return bundle;
}
 
Example 11
/**
 * Saves the current state of the view
 *
 * @param outState Bundle that contains the Challenge-Id and the state of the fragment
 */
@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    outState.putParcelableArray(KEY_BUTTONS_STATE, mStateHolder);
    outState.putBoolean(KEY_ANSWERS_CHECKED, mAnswersChecked);
}
 
Example 12
@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putParcelableArray(KEY_SELECTED_PHOTOS, selectedPhotos.toArray(new InstagramPhoto[0]));
    outState.putBoolean(KEY_HAS_MORE_PHOTOS, gridView.hasMoreItems());
    outState.putParcelableArray(KEY_FETCHED_PHOTOS, adapter.getItems().toArray(new InstagramPhoto[0]));
    outState.putParcelable(KEY_NEXT_PAGE_REQUEST, nextPageRequest);
}
 
Example 13
@Override
public Parcelable saveState() {
    Bundle bundle = (Bundle) super.saveState();
    if (bundle != null) {
        bundle.putParcelableArray("states", null); // Never maintain any states from the base class, just null it out
    }
    return bundle;
}
 
Example 14
static Bundle getBundleForUnreadConversation(NotificationCompatBase.UnreadConversation uc) {
    if (uc == null) {
        return null;
    }
    Bundle b = new Bundle();
    String author = null;
    if (uc.getParticipants() != null && uc.getParticipants().length > 1) {
        author = uc.getParticipants()[0];
    }
    Parcelable[] messages = new Parcelable[uc.getMessages().length];
    for (int i = 0; i < messages.length; i++) {
        Bundle m = new Bundle();
        m.putString(KEY_TEXT, uc.getMessages()[i]);
        m.putString(KEY_AUTHOR, author);
        messages[i] = m;
    }
    b.putParcelableArray(KEY_MESSAGES, messages);
    RemoteInputCompatBase.RemoteInput remoteInput = uc.getRemoteInput();
    if (remoteInput != null) {
        b.putParcelable(KEY_REMOTE_INPUT, fromCompatRemoteInput(remoteInput));
    }
    b.putParcelable(KEY_ON_REPLY, uc.getReplyPendingIntent());
    b.putParcelable(KEY_ON_READ, uc.getReadPendingIntent());
    b.putStringArray(KEY_PARTICIPANTS, uc.getParticipants());
    b.putLong(KEY_TIMESTAMP, uc.getLatestTimestamp());
    return b;
}
 
Example 15
private static void readEntry(Bundle restrictions, ArrayList<String> values,
        XmlPullParser parser) throws XmlPullParserException, IOException {
    int type = parser.getEventType();
    if (type == XmlPullParser.START_TAG && parser.getName().equals(TAG_ENTRY)) {
        String key = parser.getAttributeValue(null, ATTR_KEY);
        String valType = parser.getAttributeValue(null, ATTR_VALUE_TYPE);
        String multiple = parser.getAttributeValue(null, ATTR_MULTIPLE);
        if (multiple != null) {
            values.clear();
            int count = Integer.parseInt(multiple);
            while (count > 0 && (type = parser.next()) != XmlPullParser.END_DOCUMENT) {
                if (type == XmlPullParser.START_TAG
                        && parser.getName().equals(TAG_VALUE)) {
                    values.add(parser.nextText().trim());
                    count--;
                }
            }
            String [] valueStrings = new String[values.size()];
            values.toArray(valueStrings);
            restrictions.putStringArray(key, valueStrings);
        } else if (ATTR_TYPE_BUNDLE.equals(valType)) {
            restrictions.putBundle(key, readBundleEntry(parser, values));
        } else if (ATTR_TYPE_BUNDLE_ARRAY.equals(valType)) {
            final int outerDepth = parser.getDepth();
            ArrayList<Bundle> bundleList = new ArrayList<>();
            while (XmlUtils.nextElementWithin(parser, outerDepth)) {
                Bundle childBundle = readBundleEntry(parser, values);
                bundleList.add(childBundle);
            }
            restrictions.putParcelableArray(key,
                    bundleList.toArray(new Bundle[bundleList.size()]));
        } else {
            String value = parser.nextText().trim();
            if (ATTR_TYPE_BOOLEAN.equals(valType)) {
                restrictions.putBoolean(key, Boolean.parseBoolean(value));
            } else if (ATTR_TYPE_INTEGER.equals(valType)) {
                restrictions.putInt(key, Integer.parseInt(value));
            } else {
                restrictions.putString(key, value);
            }
        }
    }
}
 
Example 16
Source Project: EmojiChat   File: EmojiconsView.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Parcelable saveState() {
    Bundle state = new Bundle();
    state.putParcelableArray("states", savedStates);
    return state;
}
 
Example 17
public void putParcelableArray(Bundle state, String key, Parcelable[] x) {
    state.putParcelableArray(key + mBaseKey, x);
}
 
Example 18
Source Project: Bitocle   File: SuperActivityToast.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Saves pending/showing {@value #TAG} to a bundle.
 *
 * @param bundle {@link android.os.Bundle}
 */
public static void onSaveState(Bundle bundle) {

    ReferenceHolder[] list = new ReferenceHolder[ManagerSuperActivityToast
            .getInstance().getList().size()];

    LinkedList<SuperActivityToast> lister = ManagerSuperActivityToast
            .getInstance().getList();

    for (int i = 0; i < list.length; i++) {

        list[i] = new ReferenceHolder(lister.get(i));

    }

    bundle.putParcelableArray(BUNDLE_TAG, list);

    SuperActivityToast.cancelAllSuperActivityToasts();

}
 
Example 19
Source Project: IPCInvoker   File: ParameterHelper.java    License: Apache License 2.0 4 votes vote down vote up
public static void put(Bundle bundle, String key, Object value) {
        if (value instanceof Integer) {
            bundle.putInt(key, (Integer) value);
        } else if (value instanceof Float) {
            bundle.putFloat(key, (Float) value);
        } else if (value instanceof Character) {
            bundle.putChar(key, (Character) value);
        } else if (value instanceof CharSequence) {
            bundle.putCharSequence(key, (CharSequence) value);
        } else if (value instanceof Long) {
            bundle.putLong(key, (Long) value);
        } else if (value instanceof Short) {
            bundle.putShort(key, (Short) value);
        } else if (value instanceof Byte) {
            bundle.putByte(key, (Byte) value);
        } else if (value instanceof Boolean) {
            bundle.putBoolean(key, (Boolean) value);
        } else if (value instanceof Double) {
            bundle.putDouble(key, (Double) value);
        } else if (value instanceof Parcelable) {
            bundle.putParcelable(key, (Parcelable) value);
        } else if (value instanceof Bundle) {
            bundle.putBundle(key, (Bundle) value);
        } else if (value instanceof int[]) {
            bundle.putIntArray(key, (int[]) value);
        } else if (value instanceof byte[]) {
            bundle.putByteArray(key, (byte[]) value);
        } else if (value instanceof float[]) {
            bundle.putFloatArray(key, (float[]) value);
        } else if (value instanceof double[]) {
            bundle.putDoubleArray(key, (double[]) value);
        } else if (value instanceof boolean[]) {
            bundle.putBooleanArray(key, (boolean[]) value);
        } else if (value instanceof long[]) {
            bundle.putLongArray(key, (long[]) value);
        } else if (value instanceof Parcelable[]) {
            bundle.putParcelableArray(key, (Parcelable[]) value);
        } else if (value instanceof short[]) {
            bundle.putShortArray(key, (short[]) value);
        } else if (value instanceof String[]) {
            bundle.putStringArray(key, (String[]) value);
        } else {
//            bundle.putString(key, String.valueOf(value));
        }
    }
 
Example 20
@Override
public void onSaveInstanceState(final Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putParcelableArray(Keys.LOCATIONS, mVenues);
    outState.putBoolean(Keys.OVERLAY_VISIBLE, mIsOverlayShown);
}