下面列出了android.os.Bundle#putCharSequence ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static SimpleSlideFragment newInstance(long id, CharSequence title, @StringRes int titleRes,
CharSequence description, @StringRes int descriptionRes,
@DrawableRes int imageRes, @ColorRes int backgroundRes,
@LayoutRes int layout, int permissionsRequestCode) {
Bundle arguments = new Bundle();
arguments.putLong(ARGUMENT_ID, id);
arguments.putCharSequence(ARGUMENT_TITLE, title);
arguments.putInt(ARGUMENT_TITLE_RES, titleRes);
arguments.putCharSequence(ARGUMENT_DESCRIPTION, description);
arguments.putInt(ARGUMENT_DESCRIPTION_RES, descriptionRes);
arguments.putInt(ARGUMENT_IMAGE_RES, imageRes);
arguments.putInt(ARGUMENT_BACKGROUND_RES, backgroundRes);
arguments.putInt(ARGUMENT_LAYOUT_RES, layout);
arguments.putInt(ARGUMENT_PERMISSIONS_REQUEST_CODE, permissionsRequestCode);
SimpleSlideFragment fragment = new SimpleSlideFragment();
fragment.setArguments(arguments);
return fragment;
}
public static SimpleSlideFragment newInstance(CharSequence title, @StringRes int titleRes,
CharSequence description, @StringRes int descriptionRes,
@DrawableRes int imageRes, @ColorRes int background,
@ColorRes int backgroundDark, @LayoutRes int layout,
String[] permissions, int permissionsRequestCode) {
SimpleSlideFragment fragment = new SimpleSlideFragment();
Bundle arguments = new Bundle();
arguments.putCharSequence(ARGUMENT_TITLE, title);
arguments.putInt(ARGUMENT_TITLE_RES, titleRes);
arguments.putCharSequence(ARGUMENT_DESCRIPTION, description);
arguments.putInt(ARGUMENT_DESCRIPTION_RES, descriptionRes);
arguments.putInt(ARGUMENT_IMAGE_RES, imageRes);
arguments.putInt(ARGUMENT_BACKGROUND_RES, background);
arguments.putInt(ARGUMENT_BACKGROUND_DARK_RES, backgroundDark);
arguments.putInt(ARGUMENT_LAYOUT_RES, layout);
arguments.putStringArray(ARGUMENT_PERMISSIONS, permissions);
arguments.putInt(ARGUMENT_PERMISSIONS_REQUEST_CODE, permissionsRequestCode);
fragment.setArguments(arguments);
return fragment;
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
final TextView textBox = (TextView) findViewById(R.id.editText);
CharSequence userText = textBox.getText();
outState.putCharSequence("savedText", userText);
}
public static EditTextDialog create(int requestCode, int titleResId, int hintResId, CharSequence text) {
EditTextDialog dialog = new EditTextDialog();
Bundle bundle = new Bundle();
bundle.putInt(ARG_REQUEST_CODE, requestCode);
bundle.putInt(ARG_TITLE_RES_ID, titleResId);
bundle.putInt(ARG_HINT_RES_ID, hintResId);
bundle.putCharSequence(ARG_TEXT, text);
dialog.setArguments(bundle);
return dialog;
}
@Override
protected Bundle prepareArguments() {
Bundle args = new Bundle();
args.putCharSequence(SimpleDialogFragment.ARG_MESSAGE, mMessage);
args.putCharSequence(SimpleDialogFragment.ARG_TITLE, mTitle);
return args;
}
public static DialogFragment newInstance(CharSequence text) {
Bundle args = new Bundle();
args.putCharSequence(ARGS_TEXT, text);
AdvancedOptionsDialogFragment fragment = new AdvancedOptionsDialogFragment();
fragment.setArguments(args);
return fragment;
}
/**
* Display a confirmation message asking for cancel or ok.
*
* @param activity the current activity
* @param listener The listener waiting for the response
* @param buttonResource the display on the positive button
* @param messageResource the confirmation message
* @param args arguments for the confirmation message
*/
public static void displayConfirmationMessage(@NonNull final Activity activity,
final ConfirmDialogListener listener, final int buttonResource,
final int messageResource, final Object... args) {
String message = String.format(activity.getString(messageResource), args);
Bundle bundle = new Bundle();
bundle.putCharSequence(PARAM_MESSAGE, message);
bundle.putInt(PARAM_BUTTON_RESOURCE, buttonResource);
bundle.putSerializable(PARAM_LISTENER, listener);
ConfirmDialogFragment fragment = new ConfirmDialogFragment();
fragment.setArguments(bundle);
fragment.show(activity.getFragmentManager(), fragment.getClass().toString());
}
@Override
public void onSaveInstanceState( Bundle outState )
{
//Log.d("DEBUG", "HelpDialog onSaveInstanceState");
outState.putCharSequence(KEY_HELPTEXT, rawContent);
outState.putString(KEY_NEUTRALTEXT, neutralButtonMsg);
outState.putString(KEY_NEUTRALTAG, listenerTag);
super.onSaveInstanceState(outState);
}
/**
* If called, this method will occur after onStop() for applications targeting platforms
* starting with Build.VERSION_CODES.P. For applications targeting earlier platform versions
* this method will occur before onStop() and there are no guarantees about whether it will
* occur before or after onPause()
*
* @see Activity#onSaveInstanceState(Bundle) of Build.VERSION_CODES.P
*/
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Log.v(LOG_TAG, "-> onSaveInstanceState");
this.outState = outState;
outState.putBoolean(BUNDLE_DISTRACTION_FREE_MODE, distractionFreeMode);
outState.putBundle(SearchAdapter.DATA_BUNDLE, searchAdapterDataBundle);
outState.putCharSequence(SearchActivity.BUNDLE_SAVE_SEARCH_QUERY, searchQuery);
}
@Override protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putCharSequence("title", fragmentTitle);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putCharSequence(MTEXTVIEW_TEXT_KEY,mTextView.getText());
}
/**
* Intercept standard device administrator broadcasts. Implementations
* should not override this method; it is better to implement the
* convenience callbacks for each action.
*/
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_PASSWORD_CHANGED.equals(action)) {
onPasswordChanged(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
} else if (ACTION_PASSWORD_FAILED.equals(action)) {
onPasswordFailed(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
} else if (ACTION_PASSWORD_SUCCEEDED.equals(action)) {
onPasswordSucceeded(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
} else if (ACTION_DEVICE_ADMIN_ENABLED.equals(action)) {
onEnabled(context, intent);
} else if (ACTION_DEVICE_ADMIN_DISABLE_REQUESTED.equals(action)) {
CharSequence res = onDisableRequested(context, intent);
if (res != null) {
Bundle extras = getResultExtras(true);
extras.putCharSequence(EXTRA_DISABLE_WARNING, res);
}
} else if (ACTION_DEVICE_ADMIN_DISABLED.equals(action)) {
onDisabled(context, intent);
} else if (ACTION_PASSWORD_EXPIRING.equals(action)) {
onPasswordExpiring(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
} else if (ACTION_PROFILE_PROVISIONING_COMPLETE.equals(action)) {
onProfileProvisioningComplete(context, intent);
} else if (ACTION_CHOOSE_PRIVATE_KEY_ALIAS.equals(action)) {
int uid = intent.getIntExtra(EXTRA_CHOOSE_PRIVATE_KEY_SENDER_UID, -1);
Uri uri = intent.getParcelableExtra(EXTRA_CHOOSE_PRIVATE_KEY_URI);
String alias = intent.getStringExtra(EXTRA_CHOOSE_PRIVATE_KEY_ALIAS);
String chosenAlias = onChoosePrivateKeyAlias(context, intent, uid, uri, alias);
setResultData(chosenAlias);
} else if (ACTION_LOCK_TASK_ENTERING.equals(action)) {
String pkg = intent.getStringExtra(EXTRA_LOCK_TASK_PACKAGE);
onLockTaskModeEntering(context, intent, pkg);
} else if (ACTION_LOCK_TASK_EXITING.equals(action)) {
onLockTaskModeExiting(context, intent);
} else if (ACTION_NOTIFY_PENDING_SYSTEM_UPDATE.equals(action)) {
long receivedTime = intent.getLongExtra(EXTRA_SYSTEM_UPDATE_RECEIVED_TIME, -1);
onSystemUpdatePending(context, intent, receivedTime);
} else if (ACTION_BUGREPORT_SHARING_DECLINED.equals(action)) {
onBugreportSharingDeclined(context, intent);
} else if (ACTION_BUGREPORT_SHARE.equals(action)) {
String bugreportFileHash = intent.getStringExtra(EXTRA_BUGREPORT_HASH);
onBugreportShared(context, intent, bugreportFileHash);
} else if (ACTION_BUGREPORT_FAILED.equals(action)) {
int failureCode = intent.getIntExtra(EXTRA_BUGREPORT_FAILURE_REASON,
BUGREPORT_FAILURE_FAILED_COMPLETING);
onBugreportFailed(context, intent, failureCode);
} else if (ACTION_SECURITY_LOGS_AVAILABLE.equals(action)) {
onSecurityLogsAvailable(context, intent);
} else if (ACTION_NETWORK_LOGS_AVAILABLE.equals(action)) {
long batchToken = intent.getLongExtra(EXTRA_NETWORK_LOGS_TOKEN, -1);
int networkLogsCount = intent.getIntExtra(EXTRA_NETWORK_LOGS_COUNT, 0);
onNetworkLogsAvailable(context, intent, batchToken, networkLogsCount);
} else if (ACTION_USER_ADDED.equals(action)) {
onUserAdded(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
} else if (ACTION_USER_REMOVED.equals(action)) {
onUserRemoved(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
} else if (ACTION_USER_STARTED.equals(action)) {
onUserStarted(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
} else if (ACTION_USER_STOPPED.equals(action)) {
onUserStopped(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
} else if (ACTION_USER_SWITCHED.equals(action)) {
onUserSwitched(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
} else if (ACTION_TRANSFER_OWNERSHIP_COMPLETE.equals(action)) {
PersistableBundle bundle =
intent.getParcelableExtra(EXTRA_TRANSFER_OWNERSHIP_ADMIN_EXTRAS_BUNDLE);
onTransferOwnershipComplete(context, bundle);
} else if (ACTION_AFFILIATED_PROFILE_TRANSFER_OWNERSHIP_COMPLETE.equals(action)) {
onTransferAffiliatedProfileOwnershipComplete(context,
intent.getParcelableExtra(Intent.EXTRA_USER));
}
}
/**
* Parse a name/value pair out of an XML tag holding that data. The
* AttributeSet must be holding the data defined by
* {@link android.R.styleable#Extra}. The following value types are supported:
* <ul>
* <li> {@link TypedValue#TYPE_STRING}:
* {@link Bundle#putCharSequence Bundle.putCharSequence()}
* <li> {@link TypedValue#TYPE_INT_BOOLEAN}:
* {@link Bundle#putCharSequence Bundle.putBoolean()}
* <li> {@link TypedValue#TYPE_FIRST_INT}-{@link TypedValue#TYPE_LAST_INT}:
* {@link Bundle#putCharSequence Bundle.putBoolean()}
* <li> {@link TypedValue#TYPE_FLOAT}:
* {@link Bundle#putCharSequence Bundle.putFloat()}
* </ul>
*
* @param tagName The name of the tag these attributes come from; this is
* only used for reporting error messages.
* @param attrs The attributes from which to retrieve the name/value pair.
* @param outBundle The Bundle in which to place the parsed value.
* @throws XmlPullParserException If the attributes are not valid.
*/
public void parseBundleExtra(String tagName, AttributeSet attrs,
Bundle outBundle) throws XmlPullParserException {
TypedArray sa = obtainAttributes(attrs,
com.android.internal.R.styleable.Extra);
String name = sa.getString(
com.android.internal.R.styleable.Extra_name);
if (name == null) {
sa.recycle();
throw new XmlPullParserException("<" + tagName
+ "> requires an android:name attribute at "
+ attrs.getPositionDescription());
}
TypedValue v = sa.peekValue(
com.android.internal.R.styleable.Extra_value);
if (v != null) {
if (v.type == TypedValue.TYPE_STRING) {
CharSequence cs = v.coerceToString();
outBundle.putCharSequence(name, cs);
} else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
outBundle.putBoolean(name, v.data != 0);
} else if (v.type >= TypedValue.TYPE_FIRST_INT
&& v.type <= TypedValue.TYPE_LAST_INT) {
outBundle.putInt(name, v.data);
} else if (v.type == TypedValue.TYPE_FLOAT) {
outBundle.putFloat(name, v.getFloat());
} else {
sa.recycle();
throw new XmlPullParserException("<" + tagName
+ "> only supports string, integer, float, color, and boolean at "
+ attrs.getPositionDescription());
}
} else {
sa.recycle();
throw new XmlPullParserException("<" + tagName
+ "> requires an android:value or android:resource attribute at "
+ attrs.getPositionDescription());
}
sa.recycle();
}
@Override public void onReceive(final Context context, final Intent proxy) {
final PendingIntent reply_action = proxy.getParcelableExtra(EXTRA_REPLY_ACTION);
final String result_key = proxy.getStringExtra(EXTRA_RESULT_KEY), reply_prefix = proxy.getStringExtra(EXTRA_REPLY_PREFIX);
final Uri data = proxy.getData(); final Bundle results = RemoteInput.getResultsFromIntent(proxy);
final CharSequence input = results != null ? results.getCharSequence(result_key) : null;
if (data == null || reply_action == null || result_key == null || input == null) return; // Should never happen
final String key = data.getSchemeSpecificPart(), original_key = proxy.getStringExtra(EXTRA_ORIGINAL_KEY);
if (BuildConfig.DEBUG && "debug".equals(input.toString())) {
final Conversation conversation = mController.getConversation(proxy.getIntExtra(EXTRA_CONVERSATION_ID, 0));
if (conversation != null) showDebugNotification(conversation, "Type: " + conversation.typeToString());
mController.recastNotification(original_key != null ? original_key : key, null);
return;
}
final CharSequence text;
if (reply_prefix != null) {
text = reply_prefix + input;
results.putCharSequence(result_key, text);
RemoteInput.addResultsToIntent(new RemoteInput[]{ new RemoteInput.Builder(result_key).build() }, proxy, results);
} else text = input;
final ArrayList<CharSequence> history = SDK_INT >= N ? proxy.getCharSequenceArrayListExtra(EXTRA_REMOTE_INPUT_HISTORY) : null;
try {
final Intent input_data = addTargetPackageAndWakeUp(reply_action);
input_data.setClipData(proxy.getClipData());
reply_action.send(mContext, 0, input_data, (pendingIntent, intent, _result_code, _result_data, _result_extras) -> {
if (BuildConfig.DEBUG) Log.d(TAG, "Reply sent: " + intent.toUri(0));
if (SDK_INT >= N) {
final Bundle addition = new Bundle(); final CharSequence[] inputs;
final boolean to_current_user = Process.myUserHandle().equals(pendingIntent.getCreatorUserHandle());
if (to_current_user && context.getPackageManager().queryBroadcastReceivers(intent, 0).isEmpty()) {
inputs = new CharSequence[] { context.getString(R.string.wechat_with_no_reply_receiver) };
} else if (history != null) {
history.add(0, text);
inputs = history.toArray(new CharSequence[0]);
} else inputs = new CharSequence[] { text };
addition.putCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY, inputs);
mController.recastNotification(original_key != null ? original_key : key, addition);
}
markRead(key);
}, null);
} catch (final PendingIntent.CanceledException e) {
Log.w(TAG, "Reply action is already cancelled: " + key);
abortBroadcast();
}
}
/** Inserts text in edit-text. Modifies edit history. */
public boolean insert(
AccessibilityNodeInfoCompat node, CharSequence textToInsert, EventId eventId) {
if (node == null || Role.getRole(node) != Role.ROLE_EDIT_TEXT) {
return false;
}
// Find current selected text or cursor position.
int selectionStart = node.getTextSelectionStart();
if (selectionStart < 0) {
selectionStart = 0;
}
int selectionEnd = node.getTextSelectionEnd();
if (selectionEnd < 0) {
selectionEnd = selectionStart;
}
if (selectionEnd < selectionStart) {
// Swap start and end to make sure they are in order.
int newStart = selectionEnd;
selectionEnd = selectionStart;
selectionStart = newStart;
}
CharSequence currentText = node.getText();
LogUtils.v(
"RuleEditText",
"insert() currentText=\"%s\"",
(currentText == null ? "null" : currentText));
if (currentText == null) {
currentText = "";
}
// Set updated text.
CharSequence textUpdated =
TextUtils.concat(
currentText.subSequence(0, selectionStart),
textToInsert,
currentText.subSequence(selectionEnd, currentText.length()));
Bundle arguments = new Bundle();
arguments.putCharSequence(ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, textUpdated);
boolean result = PerformActionUtils.performAction(node, ACTION_SET_TEXT, arguments, eventId);
if (!result) {
return false;
}
// Move cursor to end of inserted text.
return moveCursor(node, selectionStart + textToInsert.length(), eventId);
}
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putCharSequence(SAVE_STATE_TEXT, this.mText);
}
/**
* Creates the arguments of the {@code SimpleAlertDialog} as a {@code Bundle}.<br/>
* In most cases, you don't have to call this method directly.
*
* @return Created arguments bundle
*/
@TargetApi(Build.VERSION_CODES.FROYO)
public Bundle createArguments() {
Bundle args = new Bundle();
if (mThemeResId > 0) {
args.putInt(SimpleAlertDialog.ARG_THEME_RES_ID, mThemeResId);
}
if (mTitle != null) {
args.putCharSequence(SimpleAlertDialog.ARG_TITLE, mTitle);
} else if (mTitleResId > 0) {
args.putInt(SimpleAlertDialog.ARG_TITLE_RES_ID, mTitleResId);
}
if (mIcon > 0) {
args.putInt(SimpleAlertDialog.ARG_ICON, mIcon);
}
if (mMessage != null) {
args.putCharSequence(SimpleAlertDialog.ARG_MESSAGE, mMessage);
} else if (mMessageResId > 0) {
args.putInt(SimpleAlertDialog.ARG_MESSAGE_RES_ID, mMessageResId);
}
if (mPositiveButton != null) {
args.putCharSequence(SimpleAlertDialog.ARG_POSITIVE_BUTTON, mPositiveButton);
} else if (mPositiveButtonResId > 0) {
args.putInt(SimpleAlertDialog.ARG_POSITIVE_BUTTON_RES_ID, mPositiveButtonResId);
}
if (mNeutralButton != null) {
args.putCharSequence(SimpleAlertDialog.ARG_NEUTRAL_BUTTON, mNeutralButton);
} else if (mNeutralButtonResId > 0) {
args.putInt(SimpleAlertDialog.ARG_NEUTRAL_BUTTON_RES_ID, mNeutralButtonResId);
}
if (mNegativeButton != null) {
args.putCharSequence(SimpleAlertDialog.ARG_NEGATIVE_BUTTON, mNegativeButton);
} else if (mNegativeButtonResId > 0) {
args.putInt(SimpleAlertDialog.ARG_NEGATIVE_BUTTON_RES_ID, mNegativeButtonResId);
}
if (mItems != null && Build.VERSION_CODES.ECLAIR <= Build.VERSION.SDK_INT) {
args.putCharSequenceArray(SimpleAlertDialog.ARG_ITEMS, mItems);
} else if (mItemsResId > 0) {
args.putInt(SimpleAlertDialog.ARG_ITEMS_RES_ID, mItemsResId);
}
if (mIcons != null) {
args.putIntArray(SimpleAlertDialog.ARG_ICONS, mIcons);
}
args.putBoolean(SimpleAlertDialog.ARG_CANCELABLE, mCancelable);
args.putBoolean(SimpleAlertDialog.ARG_CANCELED_ON_TOUCH_OUTSIDE,
mCanceledOnTouchOutside);
if (mSingleChoiceCheckedItem >= 0) {
args.putInt(SimpleAlertDialog.ARG_SINGLE_CHOICE_CHECKED_ITEM,
mSingleChoiceCheckedItem);
}
if (mEditTextInitialText != null || 0 < mEditTextInputType) {
args.putCharSequence(SimpleAlertDialog.ARG_EDIT_TEXT_INITIAL_TEXT, mEditTextInitialText);
args.putInt(SimpleAlertDialog.ARG_EDIT_TEXT_INPUT_TYPE, mEditTextInputType);
}
args.putBoolean(SimpleAlertDialog.ARG_USE_VIEW, mUseView);
args.putBoolean(SimpleAlertDialog.ARG_USE_ADAPTER, mUseAdapter);
args.putInt(SimpleAlertDialog.ARG_REQUEST_CODE, mRequestCode);
return args;
}
@Override protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putCharSequence("title", fragmentTitle);
}
public void onSaveInstanceState(Bundle outState) {
outState.putCharSequence("undo_message", mUndoMessage);
outState.putParcelable("undo_token", mUndoToken);
}
@Override
public void onSaveInstanceState(@NotNull Bundle outState) {
super.onSaveInstanceState(outState);
// save current activity title so we can set it again after a configuration change
outState.putCharSequence(TITLE_TAG, getTitle());
}