Example usage for android.os Bundle getCharSequenceArray

List of usage examples for android.os Bundle getCharSequenceArray

Introduction

In this page you can find the example usage for android.os Bundle getCharSequenceArray.

Prototype

@Override
@Nullable
public CharSequence[] getCharSequenceArray(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:com.ademsha.appnotifico.NotificationDataHelper.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private static JSONObject getNotificationExtras(JSONObject notification,
        StatusBarNotification statusBarNotification) {
    try {/*from  w  w w . j a v a2  s .  co  m*/
        Bundle extras = statusBarNotification.getNotification().extras;
        if (extras != null) {
            notification.put("text", extras.getString(Notification.EXTRA_TEXT));
            notification.put("sub_text", extras.getString(Notification.EXTRA_SUB_TEXT));
            notification.put("summary_text", extras.getString(Notification.EXTRA_SUMMARY_TEXT));
            notification.put("text_lines", Arrays
                    .toString(extras.getCharSequenceArray(Notification.EXTRA_TEXT_LINES)).replace("null", ""));
            notification.put("icon", String.valueOf(extras.getInt(Notification.EXTRA_SMALL_ICON)));
            if (extras.getParcelable(Notification.EXTRA_LARGE_ICON) != null) {
                notification.put("large_icon",
                        String.valueOf(extras.getParcelable(Notification.EXTRA_LARGE_ICON).toString())
                                .replace("null", ""));
            }
            notification.put("title", extras.getString(Notification.EXTRA_TITLE));
            notification.put("title_big", extras.getString(Notification.EXTRA_TITLE_BIG));
            notification.put("progress", extras.getInt(Notification.EXTRA_PROGRESS));
            notification.put("progress_indeterminate",
                    String.valueOf(extras.getBoolean(Notification.EXTRA_PROGRESS_INDETERMINATE)));
            notification.put("progress_max", String.valueOf(extras.getInt(Notification.EXTRA_PROGRESS_MAX)));
            notification.put("people", extras.getStringArray(Notification.EXTRA_PEOPLE));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return notification;
}

From source file:Main.java

public static void LogBundleExtras(Bundle bundle) {
    for (String key : bundle.keySet()) {
        Object value = bundle.get(key);

        StringBuilder builder = new StringBuilder();
        builder.append("key: ");
        builder.append(key);//from   w w w .j  av a2  s. c o  m
        builder.append("\t\t\t\t");

        if (value != null) {

            builder.append("key: ");
            builder.append(key);
            builder.append("\t\t\t\t");

            if (value instanceof CharSequence[]) {
                builder.append("\n====== Charsequense[]======\n");

                for (CharSequence seq : bundle.getCharSequenceArray(key)) {
                    builder.append("value(charseq): ");
                    builder.append(seq);
                    builder.append("\n");
                }
                builder.append("====== \"Charsequense[]======\n");
            } else {
                builder.append("value: ");
                builder.append(value);
                builder.append("\t");
            }

            builder.append("value class: ");
            builder.append(value.getClass().getName());
        } else

            builder.append("value: null");

        Log.d(TAG, builder.toString());
    }
}

From source file:com.commonsware.android.tabfrag.TabFragmentDemoActivity.java

@Override
public void onCreate(Bundle state) {
    super.onCreate(state);

    if (state != null) {
        models = state.getCharSequenceArray(KEY_MODELS);
    }//  w w w .j  a va  2 s  .  c o m

    ActionBar bar = getSupportActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    for (int i = 0; i < 10; i++) {
        bar.addTab(bar.newTab().setText("Tab #" + String.valueOf(i + 1)).setTabListener(this).setTag(i));
    }

    if (state != null) {
        bar.setSelectedNavigationItem(state.getInt(KEY_POSITION));
    }
}

From source file:com.alicode.android.teraworldevents.TeraTimeActivity.java

@Override
public void onCreate(Bundle state) {
    super.onCreate(state);

    if (state != null) {
        models = state.getCharSequenceArray(KEY_MODELS);
    }//  w  w  w . j  a v  a 2  s  . co  m

    ActionBar bar = getSupportActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    for (int i = 0; i <= 4; i++) {
        if (i == 0)
            bar.addTab(bar.newTab().setText("US Nexus").setTabListener(this).setTag(i));
        if (i == 1)
            bar.addTab(bar.newTab().setText("EU Nexus").setTabListener(this).setTag(i));
        if (i == 2)
            bar.addTab(bar.newTab().setText("Leaderboard").setTabListener(this).setTag(i));
        if (i == 3)
            bar.addTab(bar.newTab().setText("Dailies").setTabListener(this).setTag(i));
        if (i == 4)
            bar.addTab(bar.newTab().setText("Dungeons").setTabListener(this).setTag(i));
    }

    if (state != null) {
        bar.setSelectedNavigationItem(state.getInt(KEY_POSITION));
    }

}

From source file:ca.rmen.android.scrumchatter.dialog.ChoiceDialogFragment.java

/**
 * @return an AlertDialog with a list of items, one of them possibly pre-selected.
 */// www. j  ava 2  s.com
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Log.v(TAG, "onCreateDialog: savedInstanceState = " + savedInstanceState);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    Bundle arguments = getArguments();
    builder.setTitle(arguments.getString(DialogFragmentFactory.EXTRA_TITLE));
    final int actionId = arguments.getInt(DialogFragmentFactory.EXTRA_ACTION_ID);
    int selectedItem = arguments.getInt(DialogFragmentFactory.EXTRA_SELECTED_ITEM);
    final CharSequence[] choices = arguments.getCharSequenceArray(DialogFragmentFactory.EXTRA_CHOICES);
    OnClickListener listener = null;
    if (getActivity() instanceof DialogItemListener) {
        listener = (dialog, which) -> {
            dialog.dismiss();
            FragmentActivity activity = getActivity();
            if (activity == null)
                Log.w(TAG, "User clicked on dialog after it was detached from activity. Monkey?");
            else
                ((DialogItemListener) activity).onItemSelected(actionId, choices, which);
        };
    }
    // If one item is to be pre-selected, use the single choice items layout.
    if (selectedItem >= 0)
        builder.setSingleChoiceItems(choices, selectedItem, listener);
    // If no particular item is to be pre-selected, use the default list item layout.
    else
        builder.setItems(choices, listener);

    return builder.create();
}

From source file:ca.rmen.android.networkmonitor.app.dialog.ChoiceDialogFragment.java

/**
 * @return a Dialog with a list of items, one of them possibly pre-selected.
 *///from w  w  w .  j av  a2s.c  o m
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Log.v(TAG, "onCreateDialog: savedInstanceState = " + savedInstanceState);
    Context context = getActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    Bundle arguments = getArguments();
    builder.setTitle(arguments.getString(DialogFragmentFactory.EXTRA_TITLE));
    final int actionId = arguments.getInt(DialogFragmentFactory.EXTRA_ACTION_ID);
    int selectedItem = arguments.getInt(DialogFragmentFactory.EXTRA_SELECTED_ITEM);
    final CharSequence[] choices = arguments.getCharSequenceArray(DialogFragmentFactory.EXTRA_CHOICES);
    OnClickListener listener = null;
    final AtomicBoolean hasClicked = new AtomicBoolean(false);
    if (getActivity() instanceof DialogItemListener) {
        listener = new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                FragmentActivity activity = getActivity();
                if (activity == null) {
                    Log.w(TAG, "User clicked on dialog after it was detached from activity. Monkey?");
                } else if (hasClicked.get()) {
                    Log.w(TAG, "User already clicked once on this dialog! Monkey?");
                } else {
                    hasClicked.set(true);
                    ((DialogItemListener) activity).onItemSelected(actionId, choices, which);
                }
            }
        };
    }
    // If one item is to be pre-selected, use the single choice items layout.
    if (selectedItem >= 0)
        builder.setSingleChoiceItems(choices, selectedItem, listener);
    // If no particular item is to be pre-selected, use the default list item layout.
    else
        builder.setItems(choices, listener);

    if (getActivity() instanceof OnCancelListener)
        builder.setOnCancelListener((OnCancelListener) getActivity());
    final Dialog dialog = builder.create();
    if (getActivity() instanceof OnDismissListener)
        dialog.setOnDismissListener((OnDismissListener) getActivity());
    return dialog;
}

From source file:at.wada811.android.dialogfragments.AlertDialogFragment.java

private void setItems(AlertDialog.Builder builder) {
    final Bundle args = getArguments();
    final CharSequence[] items = args.getCharSequenceArray(ITEMS);
    if (items == null) {
        return;/*from w  w  w  . ja v  a  2 s.  c  o  m*/
    }
    builder.setItems(items, new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            bindItemClickListener(which);
        }
    });
}

From source file:at.wada811.android.dialogfragments.AlertDialogFragment.java

private void setSingleChoiceItems(AlertDialog.Builder builder) {
    final Bundle args = getArguments();
    final CharSequence[] items = args.getCharSequenceArray(SINGLE_CHOICE_ITEMS);
    final int checkedItem = args.getInt(CHECKED_ITEM);
    if (items == null) {
        return;/*from  w  w  w. j a  va 2s  . co m*/
    }
    builder.setSingleChoiceItems(items, checkedItem, new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            bindSingleChoiceClickListener(which);
        }
    });
}

From source file:at.wada811.android.dialogfragments.AlertDialogFragment.java

private void setMultiChoiceItems(AlertDialog.Builder builder) {
    final Bundle args = getArguments();
    final CharSequence[] items = args.getCharSequenceArray(MULTI_CHOICE_ITEMS);
    final boolean[] checked = args.getBooleanArray(CHECKED_ITEMS);
    if (items == null || checked == null) {
        return;//from   w w  w.j av a  2s  . co  m
    }
    if (items.length != checked.length) {
        throw new IllegalArgumentException("Item's length is not same as checkedItem's length.");
    }
    builder.setMultiChoiceItems(items, checked, new DialogInterface.OnMultiChoiceClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which, boolean isChecked) {
            bindMultiChoiceClickListener(which, isChecked);
        }
    });
}

From source file:com.syncedsynapse.kore2.ui.GenericSelectDialog.java

/**
 * Build the dialog/*from w  w  w. j a  va  2s .c om*/
 *
 * @param savedInstanceState State
 *
 * @return Dialog to select calendars
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    Bundle args = getArguments();
    final String title = args.getString(TITLE_KEY);
    final int token = args.getInt(TOKEN_KEY);
    final int selectedItem = args.getInt(SELECTED_ITEM_KEY);

    builder.setTitle(title);
    if (getArguments().containsKey(ARRAY_ID_KEY)) {
        final int arrayId = args.getInt(ARRAY_ID_KEY);
        builder.setSingleChoiceItems(arrayId, selectedItem, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (mListener != null)
                    mListener.onDialogSelect(token, which);
                dialog.dismiss();
            }
        });
    } else {
        final CharSequence[] items = args.getCharSequenceArray(ARRAY_ITEMS);

        // TODO: This should be a singleChoiceItems, but how do we include actions in it?
        //            builder.setSingleChoiceItems(items, selectedItem,
        //                    new DialogInterface.OnClickListener() {
        //                        @Override
        //                        public void onClick(DialogInterface dialog, int which) {
        //                            if (mListener != null)
        //                                mListener.onDialogSelect(token, which);
        //                            dialog.dismiss();
        //                        }
        //                    });

        builder.setItems(items, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (mListener != null)
                    mListener.onDialogSelect(token, which);
                dialog.dismiss();
            }
        });

    }
    return builder.create();

}