Example usage for android.os Bundle putStringArray

List of usage examples for android.os Bundle putStringArray

Introduction

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

Prototype

public void putStringArray(@Nullable String key, @Nullable String[] value) 

Source Link

Document

Inserts a String array value into the mapping of this Bundle, replacing any existing value for the given key.

Usage

From source file:nuclei.task.TaskScheduler.java

private void onSchedulePreL(Context context) {
    Task.Builder builder;//  www  .j  ava2 s .co m

    switch (mBuilder.mTaskType) {
    case TASK_ONE_OFF:
        OneoffTask.Builder oneOffBuilder = new OneoffTask.Builder();
        builder = oneOffBuilder;
        if (mBuilder.mWindowStartDelaySecondsSet || mBuilder.mWindowEndDelaySecondsSet)
            oneOffBuilder.setExecutionWindow(mBuilder.mWindowStartDelaySeconds,
                    mBuilder.mWindowEndDelaySeconds);
        break;
    case TASK_PERIODIC:
        builder = new PeriodicTask.Builder().setFlex(mBuilder.mFlexInSeconds)
                .setPeriod(mBuilder.mPeriodInSeconds);
        break;
    default:
        throw new IllegalArgumentException();
    }

    ArrayMap<String, Object> map = new ArrayMap<>();
    mBuilder.mTask.serialize(map);
    Bundle extras = new Bundle();
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        Object v = entry.getValue();
        if (v == null)
            continue;
        if (v instanceof Integer)
            extras.putInt(entry.getKey(), (int) v);
        else if (v instanceof Double)
            extras.putDouble(entry.getKey(), (double) v);
        else if (v instanceof Long)
            extras.putLong(entry.getKey(), (long) v);
        else if (v instanceof String)
            extras.putString(entry.getKey(), (String) v);
        else if (v instanceof String[])
            extras.putStringArray(entry.getKey(), (String[]) v);
        else if (v instanceof boolean[])
            extras.putBooleanArray(entry.getKey(), (boolean[]) v);
        else if (v instanceof double[])
            extras.putDoubleArray(entry.getKey(), (double[]) v);
        else if (v instanceof long[])
            extras.putLongArray(entry.getKey(), (long[]) v);
        else if (v instanceof int[])
            extras.putIntArray(entry.getKey(), (int[]) v);
        else if (v instanceof Parcelable)
            extras.putParcelable(entry.getKey(), (Parcelable) v);
        else if (v instanceof Serializable)
            extras.putSerializable(entry.getKey(), (Serializable) v);
        else
            throw new IllegalArgumentException("Invalid Type: " + entry.getKey());
    }
    extras.putString(TASK_NAME, mBuilder.mTask.getClass().getName());

    builder.setExtras(extras).setPersisted(mBuilder.mPersisted).setRequiresCharging(mBuilder.mRequiresCharging)
            .setService(TaskGcmService.class).setTag(mBuilder.mTask.getTaskTag())
            .setUpdateCurrent(mBuilder.mUpdateCurrent);

    switch (mBuilder.mNetworkState) {
    case NETWORK_STATE_ANY:
        builder.setRequiredNetwork(Task.NETWORK_STATE_ANY);
        break;
    case NETWORK_STATE_CONNECTED:
        builder.setRequiredNetwork(Task.NETWORK_STATE_CONNECTED);
        break;
    case NETWORK_STATE_UNMETERED:
        builder.setRequiredNetwork(Task.NETWORK_STATE_UNMETERED);
        break;
    }

    GcmNetworkManager.getInstance(context).schedule(builder.build());
}

From source file:at.wada811.android.dialogfragments.sample.alertdialogfragment.AlertDialogFragmentExamplesFragment.java

@Override
public DialogFragmentCallback getDialogFragmentCallback() {
    return new SimpleDialogFragmentCallback() {
        @Override/*from   w ww . jav a  2s.  co  m*/
        public void onShow(DialogFragmentInterface dialog) {
            String text = "onShow";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel(DialogFragmentInterface dialog) {
            String text = "onCancel";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onDismiss(DialogFragmentInterface dialog) {
            String text = "onDismiss";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onClickPositive(DialogFragmentInterface dialog) {
            String text = "onClickPositive";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onClickNeutral(DialogFragmentInterface dialog) {
            String text = "onClickNeutral";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onClickNegative(DialogFragmentInterface dialog) {
            String text = "onClickNegative";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public boolean onKey(DialogFragmentInterface dialog, int keyCode, KeyEvent event) {
            String text = "onKey[keyCode: " + keyCode + ", KeyEvent: " + event + "]";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
            return false;
        }

        @Override
        public void onItemClick(DialogFragmentInterface dialog, int position) {
            Bundle extra = dialog.getExtra();
            String[] items = extra.getStringArray("items");
            String text = "onItemClick[position: " + position + ", item: " + items[position] + "]";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public ListAdapter getAdapter(DialogFragmentInterface dialog) {
            String[] items = new String[] { AlertDialog.class.getSimpleName(),
                    CharacterPickerDialog.class.getSimpleName(), ProgressDialog.class.getSimpleName(),
                    DatePickerDialog.class.getSimpleName(), TimePickerDialog.class.getSimpleName(), };
            Bundle extra = new Bundle();
            extra.putStringArray("items", items);
            dialog.setExtra(extra);
            return new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, items);
        }

        @Override
        public void onSingleChoiceClick(DialogFragmentInterface dialog, int position) {
            Bundle extra = dialog.getExtra();
            String[] items = extra.getStringArray("items");
            String text = "onItemClick[position: " + position + ", item: " + items[position] + "]";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onMultiChoiceClick(DialogFragmentInterface dialog, int position, boolean isChecked) {
            Bundle extra = dialog.getExtra();
            String[] items = extra.getStringArray("items");
            String text = "onItemClick[position: " + position + ", item: " + items[position] + ", isChecked: "
                    + isChecked + "]";
            Log.v(dialog.getTag(), text);
            Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();
        }

        @Override
        public View getCustomTitle(DialogFragmentInterface dialog) {
            TextView titleView = new TextView(getActivity());
            titleView.setText(dialog.getTag());
            titleView.setPadding(0, 24, 0, 24);
            titleView.setGravity(Gravity.CENTER);
            titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
            return titleView;
        }

        @Override
        public View getView(DialogFragmentInterface dialog) {
            ImageView imageView = new ImageView(getActivity());
            imageView.setImageResource(R.drawable.ic_launcher);
            imageView.setPadding(0, 24, 0, 24);
            return imageView;
        }
    };
}

From source file:net.reichholf.dreamdroid.fragment.TimerEditFragment.java

@Override
public void onSaveInstanceState(Bundle outState) {
    outState.putParcelable("timer", mTimer);
    outState.putParcelable("timerOld", mTimerOld);

    String[] selectedTags;/*  ww  w  .j av a  2s.  com*/
    if (mSelectedTags != null) {
        selectedTags = new String[mSelectedTags.size()];
        mSelectedTags.toArray(selectedTags);
    } else {
        selectedTags = new String[0];
    }
    outState.putStringArray("selectedTags", selectedTags);

    if (mProgress != null) {
        if (mProgress.isShowing()) {
            mProgress.dismiss();
        }
    }

    super.onSaveInstanceState(outState);
}

From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.DisplayStopDataFragment.java

/**
 * Request new bus times.//  ww  w . ja  va  2s. c om
 */
private void loadBusTimes(final boolean reload) {
    mHandler.removeMessages(EVENT_REFRESH);

    final Bundle args = new Bundle();
    args.putStringArray(LOADER_ARG_STOPCODES, new String[] { stopCode });
    args.putInt(LOADER_ARG_NUMBER_OF_DEPARTURES, numDepartures);

    if (reload) {
        getLoaderManager().restartLoader(0, args, this);
    } else {
        getLoaderManager().initLoader(0, args, this);
    }
}

From source file:org.qeo.android.service.ApplicationSecurity.java

/**
 * Show a dialog containing all permissions for this application.
 *
 * @param permissions the permissions to be displayed
 * @throws RemoteException Thrown when calling the onManifestReady callback fails
 *//*  ww w  .  java 2  s.  com*/
private void showDialog(QeoServiceImpl serviceImpl, IServiceQeoCallback cb, List<String> permissions)
        throws RemoteException {
    Boolean[] popupDisabled = { false };

    serviceImpl.checkPopupDisabled(popupDisabled);
    LOG.fine("Manifest popup "
            + (mService.isManifestPopupDisabled() || popupDisabled[0] ? "disabled" : "enabled"));
    if (mService.isManifestPopupDisabled() || popupDisabled[0]) {
        // popup disabled, just accept everything
        insertAppInfo();
        insertReadersWriters();
        cb.onManifestReady(true);
    } else {
        // launching activity to show the manifest popup
        try {
            Class<?> clazz = Class.forName("org.qeo.android.security.ManifestActivity");
            Intent intent = new Intent(mService, clazz);
            Bundle args = new Bundle();

            // save the callback in order to be able to use it in the onDialogFinished broadcast
            mManifestDialogCallback = cb;

            // Listen for intent signaling completion of manifest dialog
            LocalBroadcastManager.getInstance(mService).registerReceiver(mOnDialogFinished,
                    new IntentFilter(ACTION_MANIFEST_DIALOG_FINISHED));

            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            args.putInt(INTENT_EXTRA_UID, mUid);
            args.putString(INTENT_EXTRA_TITLE, mAppLabel + " is requesting the following Qeo permissions");
            args.putStringArray(INTENT_EXTRA_PERMISSIONS, permissions.toArray(new String[permissions.size()]));
            intent.putExtras(args);
            mService.getApplicationContext().startActivity(intent);
        } catch (ClassNotFoundException e) {
            LOG.log(Level.SEVERE, "Error launching manifest activity", e);
        }

    }
}

From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.NearestStopsFragment.java

/**
 * Cause the data to refresh. The refresh happens asynchronously in another
 * thread.//  ww  w .j a  va2s.  c  o  m
 * 
 * @param isFirst Is this the first load?
 */
private void doUpdate(final boolean isFirst) {
    if (lastLocation == null)
        return;

    // Stuff the arguments Bundle.
    final Bundle args = new Bundle();
    args.putDouble(NearestStopsLoader.ARG_LATITUDE, lastLocation.getLatitude());
    args.putDouble(NearestStopsLoader.ARG_LONGITUDE, lastLocation.getLongitude());

    // Only put this argument in if chosen services exist.
    if (chosenServices != null && chosenServices.length > 0)
        args.putStringArray(NearestStopsLoader.ARG_FILTERED_SERVICES, chosenServices);

    if (isFirst) {
        getLoaderManager().initLoader(0, args, this);
    } else {
        getLoaderManager().restartLoader(0, args, this);
    }
}

From source file:com.androidaq.AndroiDAQMain.java

private void updateFromPreferences() {
    //Log.e(TAG, "Update Preferences Fired");
    Context context = getApplicationContext();
    boolean[] isOutputCh = loadBooleanArray("isInput", context);
    boolean[] isDigCh = loadBooleanArray("isDig", context);
    boolean[] outputState = loadBooleanArray("outputState", context);
    boolean fromFreq = true;
    String[] desiredFreq = loadStringArray("desiredFreqs", context, fromFreq);
    fromFreq = false;/*  w  ww. ja  v  a2 s  .  c  om*/
    String[] desiredDuty = loadStringArray("desiredDutys", context, fromFreq);
    Bundle myBundle = new Bundle();
    myBundle.putBooleanArray("isInput", isOutputCh);
    myBundle.putBooleanArray("isDig", isDigCh);
    myBundle.putBooleanArray("outputState", outputState);
    myBundle.putStringArray("desiredFreqs", desiredFreq);
    myBundle.putStringArray("desiredDutys", desiredDuty);
    ((AndroiDAQAdapter) pager.getAdapter()).setUIStates(myBundle);
    /*Example
    countSecs = prefs.getInt("setTime", 5000);
    timeIsSet = prefs.getBoolean("timeSet", true);
    project = prefs.getString("project", "Project01");*/
}

From source file:org.mariotaku.twidere.provider.TwidereDataProvider.java

private void displayMentionsNotification(final Context context, final ContentValues[] values) {
    final Resources res = context.getResources();
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    final boolean display_screen_name = NAME_DISPLAY_OPTION_SCREEN_NAME
            .equals(mPreferences.getString(PREFERENCE_KEY_NAME_DISPLAY_OPTION, NAME_DISPLAY_OPTION_BOTH));
    final boolean display_hires_profile_image = res.getBoolean(R.bool.hires_profile_image);
    final Intent delete_intent = new Intent(BROADCAST_NOTIFICATION_CLEARED);
    final Bundle delete_extras = new Bundle();
    delete_extras.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_MENTIONS);
    delete_intent.putExtras(delete_extras);
    final Intent content_intent;
    int notified_count = 0;
    // Add statuses that not filtered to list for future use.
    for (final ContentValues value : values) {
        final ParcelableStatus status = new ParcelableStatus(value);
        if (!isFiltered(mDatabase, status)) {
            mNewMentions.add(status);/*w w w.j  av a 2s.  c o m*/
            mNewMentionScreenNames.add(status.screen_name);
            mNewMentionAccounts.add(status.account_id);
            notified_count++;
        }
    }
    Collections.sort(mNewMentions);
    final int mentions_size = mNewMentions.size();
    if (notified_count == 0 || mentions_size == 0 || mNewMentionScreenNames.size() == 0)
        return;
    final String title;
    if (mentions_size > 1) {
        builder.setNumber(mentions_size);
    }
    final int screen_names_size = mNewMentionScreenNames.size();
    final ParcelableStatus status = mNewMentions.get(0);
    if (mentions_size == 1) {
        final Uri.Builder uri_builder = new Uri.Builder();
        uri_builder.scheme(SCHEME_TWIDERE);
        uri_builder.authority(AUTHORITY_STATUS);
        uri_builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(status.account_id));
        uri_builder.appendQueryParameter(QUERY_PARAM_STATUS_ID, String.valueOf(status.status_id));
        content_intent = new Intent(Intent.ACTION_VIEW, uri_builder.build());
    } else {
        content_intent = new Intent(context, HomeActivity.class);
        content_intent.setAction(Intent.ACTION_MAIN);
        content_intent.addCategory(Intent.CATEGORY_LAUNCHER);
        final Bundle content_extras = new Bundle();
        content_extras.putInt(INTENT_KEY_INITIAL_TAB, HomeActivity.TAB_POSITION_MENTIONS);
        content_intent.putExtras(content_extras);
    }
    if (screen_names_size > 1) {
        title = res.getString(R.string.notification_mention_multiple,
                display_screen_name ? "@" + status.screen_name : status.name, screen_names_size - 1);
    } else {
        title = res.getString(R.string.notification_mention,
                display_screen_name ? "@" + status.screen_name : status.name);
    }
    final String profile_image_url_string = status.profile_image_url_string;
    final File profile_image_file = mProfileImageLoader.getCachedImageFile(
            display_hires_profile_image ? getBiggerTwitterProfileImage(profile_image_url_string)
                    : profile_image_url_string);
    final int w = res.getDimensionPixelSize(R.dimen.notification_large_icon_width);
    final int h = res.getDimensionPixelSize(R.dimen.notification_large_icon_height);
    final Bitmap profile_image = profile_image_file != null && profile_image_file.isFile()
            ? BitmapFactory.decodeFile(profile_image_file.getPath())
            : null;
    final Bitmap profile_image_fallback = BitmapFactory.decodeResource(res,
            R.drawable.ic_profile_image_default);
    builder.setLargeIcon(Bitmap
            .createScaledBitmap(profile_image != null ? profile_image : profile_image_fallback, w, h, true));
    buildNotification(builder, title, title, status.text_plain, R.drawable.ic_stat_mention, null,
            content_intent, delete_intent);
    if (mentions_size > 1) {
        final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(builder);
        final int max = Math.min(4, mentions_size);
        for (int i = 0; i < max; i++) {
            final ParcelableStatus s = mNewMentions.get(i);
            final String name = display_screen_name ? "@" + s.screen_name : s.name;
            style.addLine(Html.fromHtml("<b>" + name + "</b>: "
                    + stripMentionText(s.text_plain, getAccountScreenName(context, s.account_id))));
        }
        if (max == 4 && mentions_size - max > 0) {
            style.addLine(context.getString(R.string.and_more, mentions_size - max));
        }
        final StringBuilder summary = new StringBuilder();
        final int accounts_count = mNewMentionAccounts.size();
        if (accounts_count > 0) {
            for (int i = 0; i < accounts_count; i++) {
                final String name = display_screen_name
                        ? "@" + getAccountScreenName(context, mNewMentionAccounts.get(i))
                        : getAccountName(context, mNewMentionAccounts.get(i));
                summary.append(name);
                if (i != accounts_count - 1) {
                    summary.append(", ");
                }
            }
            style.setSummaryText(summary);
        }
        mNotificationManager.notify(NOTIFICATION_ID_MENTIONS, style.build());
    } else {
        final Intent reply_intent = new Intent(INTENT_ACTION_COMPOSE);
        final Bundle bundle = new Bundle();
        final List<String> mentions = new Extractor().extractMentionedScreennames(status.text_plain);
        mentions.remove(status.screen_name);
        mentions.add(0, status.screen_name);
        bundle.putInt(INTENT_KEY_NOTIFICATION_ID, NOTIFICATION_ID_MENTIONS);
        bundle.putStringArray(INTENT_KEY_MENTIONS, mentions.toArray(new String[mentions.size()]));
        bundle.putLong(INTENT_KEY_ACCOUNT_ID, status.account_id);
        bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, status.status_id);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, status.screen_name);
        bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, status.name);
        reply_intent.putExtras(bundle);
        reply_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        builder.addAction(R.drawable.ic_menu_reply, context.getString(R.string.reply),
                PendingIntent.getActivity(context, 0, reply_intent, PendingIntent.FLAG_UPDATE_CURRENT));
        final NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(builder);
        style.bigText(stripMentionText(status.text_plain, getAccountScreenName(context, status.account_id)));
        mNotificationManager.notify(NOTIFICATION_ID_MENTIONS, style.build());
    }
}

From source file:com.androidaq.AndroiDAQTCPMain.java

private void updateFromPreferences() {
    //Log.e(TAG, "Update Preferences Fired");
    Context context = getApplicationContext();
    boolean[] isOutputCh = loadBooleanArray("isInput", context);
    boolean[] isDigCh = loadBooleanArray("isDig", context);
    boolean[] outputState = loadBooleanArray("outputState", context);
    boolean fromFreq = true;
    String[] desiredFreq = loadStringArray("desiredFreqs", context, fromFreq);
    fromFreq = false;//from ww w . j  a va  2s .  c o m
    String[] desiredDuty = loadStringArray("desiredDutys", context, fromFreq);
    Bundle myBundle = new Bundle();
    myBundle.putBooleanArray("isInput", isOutputCh);
    myBundle.putBooleanArray("isDig", isDigCh);
    myBundle.putBooleanArray("outputState", outputState);
    myBundle.putStringArray("desiredFreqs", desiredFreq);
    myBundle.putStringArray("desiredDutys", desiredDuty);
    ((AndroiDAQTCPAdapter) pager.getAdapter()).setUIStates(myBundle);
    /*Example
    countSecs = prefs.getInt("setTime", 5000);
    timeIsSet = prefs.getBoolean("timeSet", true);
    project = prefs.getString("project", "Project01");*/
}

From source file:cz.metaverse.android.bilingualreader.ReaderActivity.java

/**
 * Open a bilingual book - if it contains more than 2 languages, let the user pick which he wants.
 * @return  True if bilingual book was just opened,
 *          False if language chooser dialog was opened, or if this is not a bilingual book.
 *///from   w w  w.  j a v a  2 s.  co  m
public boolean openBilingualBook(int book) {

    String[] languages;
    languages = governor.getPanelHolder(book).getLanguagesInABook();

    // If there are just two languages, start parallel text mode with them.
    if (languages.length == 2) {
        startParallelText(book, 0, 1);
        return true;

        // If there are more than 2 languages, show a dialog to pick the two languages
        //    with which to start parallel text mode.
    } else if (languages.length > 0) {
        Bundle bundle = new Bundle();
        bundle.putInt(getString(R.string.tome), book);
        bundle.putStringArray(getString(R.string.lang), languages);

        LanguageChooserDialog langChooser = new LanguageChooserDialog();
        langChooser.setArguments(bundle);
        langChooser.show(getFragmentManager(), "");
        return false;
    } else {
        errorMessage(getString(R.string.error_noOtherLanguages));
        return false;
    }
}