下面列出了android.os.Bundle#putIntArray ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
if (DEBUG) {
Log.d(TAG, "onSaveInstanceState(Bundle)");
Log.d(TAG, ">>>> Bundle not null only");
}
outState.putBoolean("log_enable", isLog);
outState.putIntArray("custom_ui", new int[] {
customUI.getTitleBackgroundColor(),
customUI.getTitleTextColor(),
customUI.getLicenseBackgroundColor(),
customUI.getLicenseTextColor()
});
if (isLog) Log.i(TAG, "Call -> onSaveState(Bundle)");
onSaveState(outState);
}
/**
* Create the {@link ColorPickerDialog} instance.
*
* @return A new {@link ColorPickerDialog}.
* @see #show(FragmentActivity)
*/
public ColorPickerDialog create() {
ColorPickerDialog dialog = new ColorPickerDialog();
Bundle args = new Bundle();
args.putInt(ARG_ID, dialogId);
args.putInt(ARG_TYPE, dialogType);
args.putInt(ARG_COLOR, color);
args.putIntArray(ARG_PRESETS, presets);
args.putBoolean(ARG_ALPHA, showAlphaSlider);
args.putBoolean(ARG_ALLOW_CUSTOM, allowCustom);
args.putBoolean(ARG_ALLOW_PRESETS, allowPresets);
args.putInt(ARG_DIALOG_TITLE, dialogTitle);
args.putBoolean(ARG_SHOW_COLOR_SHADES, showColorShades);
args.putInt(ARG_COLOR_SHAPE, colorShape);
args.putInt(ARG_PRESETS_BUTTON_TEXT, presetsButtonText);
args.putInt(ARG_CUSTOM_BUTTON_TEXT, customButtonText);
args.putInt(ARG_SELECTED_BUTTON_TEXT, selectedButtonText);
dialog.setArguments(args);
return dialog;
}
Bundle toBundle(KeyParceler parceler) {
Bundle outState = new Bundle();
outState.putParcelable(KEY, parceler.toParcelable(getKey()));
int[] viewIds = new int[viewStateById.size()];
int c = 0;
for (Map.Entry<Integer, SparseArray<Parcelable>> entry : viewStateById.entrySet()) {
Integer viewId = entry.getKey();
viewIds[c++] = viewId;
SparseArray<Parcelable> viewState = entry.getValue();
if (viewState.size() > 0) {
outState.putSparseParcelableArray(VIEW_STATE_PREFIX + viewId, viewState);
}
}
outState.putIntArray(VIEW_STATE_IDS, viewIds);
if (bundle != null && !bundle.isEmpty()) {
outState.putBundle(BUNDLE, bundle);
}
return outState;
}
/**
* Called when the user has made a choice in the permission dialog.
*
* This method wraps the responses in a {@link Bundle} and passes it to the {@link ResultReceiver}
* specified in the {@link Intent} that started the activity, then closes the activity.
*/
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
Bundle resultData = new Bundle();
resultData.putStringArray(Const.KEY_PERMISSIONS, permissions);
resultData.putIntArray(Const.KEY_GRANT_RESULTS, grantResults);
resultReceiver.send(requestCode, resultData);
finish();
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putInt(TYPE, mType);
outState.putString(KEY, mKey);
outState.putStringArray(PRODUCT_ID, mProductsId);
outState.putIntArray(PRODUCT_COUNT, mProductsCount);
super.onSaveInstanceState(outState);
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(INST_KEY_ALPHA, isAlphaEnabled);
outState.putIntArray(INST_KEY_PRESETS, presets);
String[] pickerClassNames = new String[pickers.length];
for (int i = 0; i < pickers.length; i++) {
pickerClassNames[i] = pickers[i].gettClassName();
}
outState.putStringArray(INST_KEY_PICKERS, pickerClassNames);
}
/**
* Updates the {@link RemoteViews} of the secondary toolbar in an existing custom tab session.
* @param remoteViews The updated {@link RemoteViews} that will be shown in secondary toolbar.
* If null, the current secondary toolbar will be dismissed.
* @param clickableIDs The ids of clickable views. The onClick event of these views will be
* handled by custom tabs.
* @param pendingIntent The {@link PendingIntent} that will be sent when the user clicks on one
* of the {@link View}s in clickableIDs.
*/
public boolean setSecondaryToolbarViews(@Nullable RemoteViews remoteViews,
@Nullable int[] clickableIDs, @Nullable PendingIntent pendingIntent) {
Bundle bundle = new Bundle();
bundle.putParcelable(CustomTabsIntent.EXTRA_REMOTEVIEWS, remoteViews);
bundle.putIntArray(CustomTabsIntent.EXTRA_REMOTEVIEWS_VIEW_IDS, clickableIDs);
bundle.putParcelable(CustomTabsIntent.EXTRA_REMOTEVIEWS_PENDINGINTENT, pendingIntent);
try {
return mService.updateVisuals(mCallback, bundle);
} catch (RemoteException e) {
return false;
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putInt(TYPE, mType);
outState.putString(KEY, mKey);
outState.putStringArray(PRODUCT_ID, mProductsId);
outState.putIntArray(PRODUCT_COUNT, mProductsCount);
super.onSaveInstanceState(outState);
}
/**
* Updates the {@link RemoteViews} of the secondary toolbar in an existing custom tab session.
* @param remoteViews The updated {@link RemoteViews} that will be shown in secondary toolbar.
* If null, the current secondary toolbar will be dismissed.
* @param clickableIDs The ids of clickable views. The onClick event of these views will be
* handled by custom tabs.
* @param pendingIntent The {@link PendingIntent} that will be sent when the user clicks on one
* of the {@link View}s in clickableIDs.
*/
public boolean setSecondaryToolbarViews(@Nullable RemoteViews remoteViews,
@Nullable int[] clickableIDs, @Nullable PendingIntent pendingIntent) {
Bundle bundle = new Bundle();
bundle.putParcelable(CustomTabsIntent.EXTRA_REMOTEVIEWS, remoteViews);
bundle.putIntArray(CustomTabsIntent.EXTRA_REMOTEVIEWS_VIEW_IDS, clickableIDs);
bundle.putParcelable(CustomTabsIntent.EXTRA_REMOTEVIEWS_PENDINGINTENT, pendingIntent);
try {
return mService.updateVisuals(mCallback, bundle);
} catch (RemoteException e) {
return false;
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putIntArray(KEY_COLORS, mColors);
outState.putSerializable(KEY_SELECTED_COLOR, mSelectedColor);
outState.putStringArray(KEY_COLOR_CONTENT_DESCRIPTIONS, mColorContentDescriptions);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
if(notificationManager != null) {
notificationManager.cancel(NOTIFICATION_ID);
}
}
Intent callingIntent = getIntent();
if (callingIntent == null || callingIntent.getExtras() == null || !callingIntent.hasExtra(EXTRA_CALLBACK)) {
finish();
return;
}
Bundle extras = callingIntent.getExtras();
ResultReceiver callback = extras.getParcelable(EXTRA_CALLBACK);
if (callback == null) {
finish();
return;
}
Bundle resultData = new Bundle();
resultData.putStringArray(EXTRA_PERMISSIONS, permissions);
resultData.putIntArray(EXTRA_GRANT_RESULTS, grantResults);
callback.send(Activity.RESULT_OK, resultData);
finish();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putIntArray(KEY_COLORS, mColors);
outState.putSerializable(KEY_SELECTED_COLOR, mSelectedColor);
outState.putStringArray(KEY_COLOR_CONTENT_DESCRIPTIONS, mColorContentDescriptions);
outState.putBoolean(KEY_BACKWARDS_ORDER, mBackwardsOrder);
outState.putInt(KEY_STROKE_WIDTH, mStrokeWidth);
outState.putInt(KEY_STROKE_COLOR, mStrokeColor);
}
public static void fromArrayToBundle(Bundle bundle, String key, Object array) {
if (bundle != null && !TextUtils.isEmpty(key) && array != null) {
if (array instanceof String[]) {
bundle.putStringArray(key, (String[]) ((String[]) array));
} else if (array instanceof byte[]) {
bundle.putByteArray(key, (byte[]) ((byte[]) array));
} else if (array instanceof short[]) {
bundle.putShortArray(key, (short[]) ((short[]) array));
} else if (array instanceof int[]) {
bundle.putIntArray(key, (int[]) ((int[]) array));
} else if (array instanceof long[]) {
bundle.putLongArray(key, (long[]) ((long[]) array));
} else if (array instanceof float[]) {
bundle.putFloatArray(key, (float[]) ((float[]) array));
} else if (array instanceof double[]) {
bundle.putDoubleArray(key, (double[]) ((double[]) array));
} else if (array instanceof boolean[]) {
bundle.putBooleanArray(key, (boolean[]) ((boolean[]) array));
} else if (array instanceof char[]) {
bundle.putCharArray(key, (char[]) ((char[]) array));
} else {
if (!(array instanceof JSONArray)) {
throw new IllegalArgumentException("Unknown array type " + array.getClass());
}
ArrayList arraylist = new ArrayList();
JSONArray jsonArray = (JSONArray) array;
Iterator it = jsonArray.iterator();
while (it.hasNext()) {
JSONObject object = (JSONObject) it.next();
arraylist.add(fromJsonToBundle(object));
}
bundle.putParcelableArrayList(key, arraylist);
}
}
}
/**
* <p>
* Saves the cube current state to a bundle, in order for it to be recovered after a configuration change or after the app is resumed from background.
* </p>
* <p>
* If needed, the saved state can be read from the bundle by reading the values stored at keys defined in {@link CubeState}.
* </p>
*
* @return a {@link Bundle} containing the cube's current state
* @see #restoreState(Bundle)
*/
public Bundle saveState() {
Bundle b = new Bundle();
int[][] cubeDeepCopy = new int[6][9];
synchronized (animThreadLock) {
CubeUtils.deepCopy2DArray(cube, cubeDeepCopy);
for (int i = 0; i < cubeDeepCopy.length; i++) {
b.putIntArray(CubeState.KEY_CUBE + i, cubeDeepCopy[i]);
}
for (int i = 0; i < initialCube.length; i++) {
b.putIntArray(CubeState.KEY_INITIAL_CUBE + i, initialCube[i]);
}
b.putIntArray(CubeState.KEY_MOVE, move);
b.putBoolean(CubeState.KEY_IS_ANIMATING, animating);
b.putInt(CubeState.KEY_ANIMATION_MODE, animationMode);
b.putDoubleArray(CubeState.KEY_EYE, eye);
b.putDoubleArray(CubeState.KEY_EYE_X, eyeX);
b.putDoubleArray(CubeState.KEY_EYE_Y, eyeY);
b.putDouble(CubeState.KEY_ORIGINAL_ANGLE, originalAngle);
if (moveDir == -1) {
b.putInt(CubeState.KEY_MOVE_POS, movePos == move.length ? move.length : movePos + 1);
} else {
b.putInt(CubeState.KEY_MOVE_POS, movePos);
}
b.putBoolean(CubeState.KEY_EDITABLE, editable);
b.putInt(CubeState.KEY_BACKFACES_DISTANCE, backFacesDistance);
b.putInt(CubeState.KEY_SINGLE_ROTATION_SPEED, speed);
b.putInt(CubeState.KEY_DOUBLE_ROTATION_SPEED, doubleSpeed);
b.putBoolean(CubeState.KEY_IS_DEBUGGABLE, isDebuggable);
}
return b;
}
@Override
protected Parcelable onSaveInstanceState() {
Bundle bundle = new Bundle();
bundle.putParcelable(STATE_SUPER_INSTANCE, super.onSaveInstanceState());
bundle.putInt(STATE_MODE, mode);
if (renderer instanceof OrientationBasedMode) {
bundle.putInt(STATE_ORIENTATION, ((OrientationBasedMode) renderer).getOrientation());
}
bundle.putFloat(STATE_START_ANGLE, renderer.getStartAngle());
bundle.putInt(STATE_DURATION, renderer.getAnimationDuration());
bundle.putFloat(STATE_PROGRESS, renderer.getProgress());
bundle.putInt(STATE_PG_COLOR, renderer.getProgressColor());
bundle.putBoolean(STATE_DRAW_BG, renderer.isDrawBackgroundEnabled());
bundle.putInt(STATE_BG_COLOR, renderer.getBackgroundColor());
if (renderer instanceof OffsetEnabledMode) {
bundle.putInt(STATE_BG_OFFSET, ((OffsetEnabledMode) renderer).getBackgroundOffset());
}
bundle.putInt(STATE_TXT_COLOR, renderer.getTextColor());
bundle.putFloat(STATE_TXT_SIZE, renderer.getTextSize());
bundle.putInt(STATE_TXT_SHA_COLOR, renderer.getTextShadowColor());
bundle.putFloat(STATE_TXT_SHA_RADIUS, renderer.getTextShadowRadius());
bundle.putFloat(STATE_TXT_SHA_DIST_X, renderer.getTextShadowDistX());
bundle.putFloat(STATE_TXT_SHA_DIST_Y, renderer.getTextShadowDistY());
if (renderer instanceof RingModeRenderer) {
bundle.putFloat(STATE_PG_BAR_THICKNESS, ((RingModeRenderer) renderer).getProgressBarThickness());
bundle.putInt(STATE_PG_BAR_STYLE, ((RingModeRenderer) renderer).getProgressBarStyle());
bundle.putBoolean(STATE_DRAW_BG_BAR, ((RingModeRenderer) renderer).isDrawBackgroundBarEnabled());
bundle.putInt(STATE_BG_BAR_COLOR, ((RingModeRenderer) renderer).getBackgroundBarColor());
bundle.putFloat(STATE_BG_BAR_THICKNESS, ((RingModeRenderer) renderer).getBackgroundBarThickness());
}
if (renderer.getGradientType() != -1) {
bundle.putInt(STATE_GRADIENT_TYPE, renderer.getGradientType());
bundle.putFloat(STATE_GRADIENT_ANGLE, renderer.getGradientAngle());
bundle.putIntArray(STATE_GRADIENT_COLORS, renderer.getGradientColors());
bundle.putFloatArray(STATE_GRADIENT_POSITIONS, renderer.getGradientDistributions());
}
return bundle;
}
@Override
protected Parcelable onSaveInstanceState() {
Bundle bundle = new Bundle();
//保存父类的信息
bundle.putParcelable(KEY_SUPER_STATE, super.onSaveInstanceState());
//保存标签文字颜色
if (mTextColor != null) {
bundle.putParcelable(KEY_TEXT_COLOR_STATE, mTextColor);
}
//保存标签文字大小
bundle.putFloat(KEY_TEXT_SIZE_STATE, mTextSize);
//保存标签背景 (由于背景改用Drawable,所以不能自动保存和恢复)
// bundle.putInt(KEY_BG_RES_ID_STATE, mLabelBgResId);
//保存标签内边距
bundle.putIntArray(KEY_PADDING_STATE, new int[]{mTextPaddingLeft, mTextPaddingTop,
mTextPaddingRight, mTextPaddingBottom});
//保存标签间隔
bundle.putInt(KEY_WORD_MARGIN_STATE, mWordMargin);
//保存行间隔
bundle.putInt(KEY_LINE_MARGIN_STATE, mLineMargin);
//保存标签的选择类型
bundle.putInt(KEY_SELECT_TYPE_STATE, mSelectType.value);
//保存标签的最大选择数量
bundle.putInt(KEY_MAX_SELECT_STATE, mMaxSelect);
//保存标签的最少选择数量
bundle.putInt(KEY_MIN_SELECT_STATE, mMinSelect);
//保存标签的最大行数
bundle.putInt(KEY_MAX_LINES_STATE, mMaxLines);
//保存是否是指示器模式
bundle.putBoolean(KEY_INDICATOR_STATE, isIndicator);
//保存标签列表
// if (!mLabels.isEmpty()) {
// bundle.putStringArrayList(KEY_LABELS_STATE, mLabels);
// }
//保存已选择的标签列表
if (!mSelectLabels.isEmpty()) {
bundle.putIntegerArrayList(KEY_SELECT_LABELS_STATE, mSelectLabels);
}
//保存必选项列表
if (!mCompulsorys.isEmpty()) {
bundle.putIntegerArrayList(KEY_COMPULSORY_LABELS_STATE, mCompulsorys);
}
return bundle;
}
@Override
protected void putAdditionalInstanceState(Bundle saveState) {
if (selectedIndices != null) {
saveState.putIntArray(SAVE_STATE_KEY_SELECTED_INDICES, selectedIndices);
}
}
@Override
public void onSaveState(Bundle bundle) {
super.onSaveState(bundle);
bundle.putIntArray(LOOKUP_BUNDLE_KEY, mLazySpanLookup.mData);
// TODO: store span info
}
/**
* Utility method for implementations to create the base argument bundle
*
* @param pickerId The id of the item picker
* @param title The title for the dialog
* @param positiveButtonText The text of the positive button
* @param negativeButtonText The text of the negative button
* @param enableMultipleSelection Whether or not to allow selecting multiple items
* @param selectedItemIndices The positions of the items already selected
* @return The arguments bundle
*/
protected static Bundle buildCommonArgsBundle(int pickerId, String title, String positiveButtonText, String negativeButtonText, boolean enableMultipleSelection, int[] selectedItemIndices) {
Bundle args = new Bundle();
args.putInt(ARG_PICKER_ID, pickerId);
args.putString(ARG_TITLE, title);
args.putString(ARG_POSITIVE_BUTTON_TEXT, positiveButtonText);
args.putString(ARG_NEGATIVE_BUTTON_TEXT, negativeButtonText);
args.putBoolean(ARG_ENABLE_MULTIPLE_SELECTION, enableMultipleSelection);
args.putIntArray(ARG_SELECTED_ITEMS_INDICES, selectedItemIndices);
return args;
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putInt("power_graph_length", powerChart.getChartLength());
outState.putDouble("power_now", powerNowWatts);
outState.putDouble("power_today", powerTodaykWh);
outState.putInt("power_feed_id", myElectricSettings.getPowerFeedId());
outState.putInt("use_feed_id", myElectricSettings.getUseFeedId());
outState.putParcelable("settings", myElectricSettings);
outState.putIntArray("chart2_colors", dailyUsageBarChart.getBarColours());
double[] values = new double[powerChart.getValues().size()];
for (int i = 0; i < powerChart.getValues().size(); i++)
values[i] = powerChart.getValues().get(i);
outState.putStringArrayList("chart1_labels", powerChart.getLabels());
outState.putDoubleArray("chart1_values", values);
values = new double[dailyUsageBarChart.getValues().size()];
for (int i = 0; i < dailyUsageBarChart.getValues().size(); i++)
values[i] = dailyUsageBarChart.getValues().get(i);
outState.putStringArrayList("chart2_labels", dailyUsageBarChart.getLabels());
outState.putDoubleArray("chart2_values", values);
super.onSaveInstanceState(outState);
}