android.os.Bundle#putParcelableArray ( )源码实例Demo

下面列出了android.os.Bundle#putParcelableArray ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: barterli_android   文件: HttpResponseParser.java
/**
 * 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;
}
 
@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);
        }
    }
}
 
@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);
}
 
源代码4 项目: 365browser   文件: ChildProcessLauncherHelper.java
@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;
}
 
源代码5 项目: cameraview   文件: AspectRatioFragment.java
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;
}
 
源代码6 项目: MHViewer   文件: GalleryCommentsScene.java
@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);
}
 
@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));
}
 
源代码8 项目: FacebookImageShareIntent   文件: AppLinkData.java
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;
}
 
源代码9 项目: AssistantBySDK   文件: TimePickerDialog.java
@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);
    }
}
 
源代码10 项目: Abelana-Android   文件: AppLinkData.java
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;
}
 
源代码11 项目: BrainPhaser   文件: MultipleChoiceFragment.java
/**
 * 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);
}
 
@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);
}
 
源代码13 项目: IslamicLibraryAndroid   文件: ReadingActivity.java
@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;
}
 
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;
}
 
源代码15 项目: android_9.0.0_r45   文件: UserManagerService.java
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);
            }
        }
    }
}
 
源代码16 项目: EmojiChat   文件: EmojiconsView.java
@Override
public Parcelable saveState() {
    Bundle state = new Bundle();
    state.putParcelableArray("states", savedStates);
    return state;
}
 
源代码17 项目: android-state   文件: InjectionHelper.java
public void putParcelableArray(Bundle state, String key, Parcelable[] x) {
    state.putParcelableArray(key + mBaseKey, x);
}
 
源代码18 项目: Bitocle   文件: SuperActivityToast.java
/**
 * 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();

}
 
源代码19 项目: IPCInvoker   文件: ParameterHelper.java
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));
        }
    }
 
@Override
public void onSaveInstanceState(final Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putParcelableArray(Keys.LOCATIONS, mVenues);
    outState.putBoolean(Keys.OVERLAY_VISIBLE, mIsOverlayShown);
}