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:com.dtech.uniqilm.activities.ActivityHome.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    // Connect view objects with view ids in xml
    frmLayoutList = (FrameLayout) findViewById(R.id.fragment_container);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);

    // Set FragmentVideo object
    mFragmentVideo = (FragmentVideo) getFragmentManager().findFragmentById(R.id.video_fragment_container);

    // Get channels data from strings.xml
    mChannelNames = getResources().getStringArray(R.array.channel_names);
    mVideoTypes = getResources().getStringArray(R.array.video_types);
    mChannelIds = getResources().getStringArray(R.array.channel_ids);

    // Check Youtube API
    checkYouTubeApi();/*from w  w w . java2s .  c  o  m*/

    // Set number of PrimaryDrawerItem objects based on number of channel and playlist data
    PrimaryDrawerItem[] mPrimaryDrawerItem = new PrimaryDrawerItem[mChannelIds.length];

    // Set PrimaryDrawerItem object for each channel data
    for (int i = 0; i < mChannelIds.length; i++) {
        mPrimaryDrawerItem[i] = new PrimaryDrawerItem().withName(mChannelNames[i]).withIdentifier(i)
                .withSelectable(false);

    }

    // Create drawer menu
    mDrawer = new DrawerBuilder(this).withActivity(ActivityHome.this).withToolbar(mToolbar)
            .withRootView(R.id.drawer_container).withActionBarDrawerToggleAnimated(true)
            .withSavedInstance(savedInstanceState)
            // Add menu items to the drawer
            .addDrawerItems(mPrimaryDrawerItem)
            .addStickyDrawerItems(new SecondaryDrawerItem().withName(getString(R.string.about))
                    .withIdentifier(mChannelIds.length - 1).withSelectable(false))
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

                @Override
                public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                    // Check if the drawerItem is set.
                    // There are different reasons for the drawerItem to be null
                    // --> click on the header
                    // --> click on the footer
                    // Those items don't contain a drawerItem
                    mSelectedDrawerItem = position;
                    if (drawerItem != null) {
                        if (drawerItem.getIdentifier() == 0 && mSelectedDrawerItem != -1) {
                            // Set toolbar title and selected drawer item
                            setToolbarAndSelectedDrawerItem(mChannelNames[0], 0);

                            // Pass all channel names and ids to FragmentNewVideos
                            // to display the latest video for each channel and playlist.
                            Bundle bundle = new Bundle();
                            bundle.putStringArray(Utils.TAG_CHANNEL_NAMES, mChannelNames);
                            bundle.putStringArray(Utils.TAG_VIDEO_TYPE, mVideoTypes);
                            bundle.putStringArray(Utils.TAG_CHANNEL_IDS, mChannelIds);

                            // Create FragmentNewVideos object
                            mFragment = new FragmentNewVideos();
                            mFragment.setArguments(bundle);

                            // Replace fragment in fragment_container with FragmentNewVideos
                            getSupportFragmentManager().beginTransaction()
                                    .replace(R.id.fragment_container, mFragment).commit();

                        } else if (drawerItem.getIdentifier() > 0 && mSelectedDrawerItem != -1) {
                            // Set toolbar title and selected drawer item
                            setToolbarAndSelectedDrawerItem(mChannelNames[mSelectedDrawerItem],
                                    (mSelectedDrawerItem));

                            // Pass selected video types and channel ids to FragmentChannelVideos
                            Bundle bundle = new Bundle();
                            bundle.putString(Utils.TAG_VIDEO_TYPE, mVideoTypes[mSelectedDrawerItem]);
                            bundle.putString(Utils.TAG_CHANNEL_ID, mChannelIds[mSelectedDrawerItem]);

                            // Create FragmentChannelVideos object
                            mFragment = new FragmentChannelVideos();
                            mFragment.setArguments(bundle);

                            // Replace fragment in fragment_container with FragmentChannelVideos
                            getSupportFragmentManager().beginTransaction()
                                    .replace(R.id.fragment_container, mFragment).commit();
                        } else if (mSelectedDrawerItem == -1) {
                            // Open about page by calling ActivityAbout.java
                            Intent aboutIntent = new Intent(getApplicationContext(), ActivityAbout.class);
                            startActivity(aboutIntent);
                            overridePendingTransition(R.anim.open_next, R.anim.close_main);
                        }
                    }

                    return false;
                }
            }).withSavedInstance(savedInstanceState).withShowDrawerOnFirstLaunch(true).build();

    // Set toolbar title and selected drawer item with first data in default
    setToolbarAndSelectedDrawerItem(mChannelNames[0], 0);

    // In default display FragmentNewVideos first.
    // Pass all channel names and ids to FragmentNewVideos
    // to display the latest video for each channel.
    Bundle bundle = new Bundle();
    bundle.putStringArray(Utils.TAG_CHANNEL_NAMES, mChannelNames);
    bundle.putStringArray(Utils.TAG_VIDEO_TYPE, mVideoTypes);
    bundle.putStringArray(Utils.TAG_CHANNEL_IDS, mChannelIds);

    // Create FragmentNewVideos and set it as default fragment
    mFragment = new FragmentNewVideos();
    mFragment.setArguments(bundle);

    // Replace fragment in fragment_container with FragmentNewVideos
    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, mFragment).commit();

    getSupportFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {

        @Override
        public void onBackStackChanged() {
            Fragment f = getSupportFragmentManager().findFragmentById(R.id.fragment_container);
            if (f != null) {
                updateTitleAndDrawer(f);
            }

        }
    });

    // Only set the active selection or active profile if we do not recreate the activity
    if (savedInstanceState == null) {
        // Set the selection to the item with the identifier 10
        mDrawer.setSelection(0, false);
    }
}

From source file:com.loloof64.android.chess_position_manager.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int menuItemId = menuItem.getItemId();
    DialogFragment newFragment;//from  w ww .  j av a  2s. c  o m
    switch (menuItemId) {
    case R.id.action_new_directory:
        newFragment = new NewDirectoryDialogFragment();
        newFragment.show(getSupportFragmentManager(), "newDirectory");
        return true;
    case R.id.action_new_position:
        newFragment = new NewPositionDialogFragment();
        newFragment.show(getSupportFragmentManager(), "newPosition");
        return true;
    case R.id.action_toggle_selection_mode:
        setSelectionMode(!selectionMode);
        return true;
    case R.id.action_remove:
        if (selectionMode) {
            final ListFileElement[] selectedElements = listAdapter.getSelectedElements();
            boolean thereIsSelection = selectedElements != null && selectedElements.length > 0;

            if (thereIsSelection) {
                new AsyncTask<Void, Void, Void>() {
                    @Override
                    protected Void doInBackground(Void... params) {
                        ArrayList<String> folders = new ArrayList<>();
                        ArrayList<String> positions = new ArrayList<>();

                        for (ListFileElement currentFileElement : selectedElements) {
                            if (currentFileElement.isDirectory()) {
                                folders.add(currentFileElement.getFileName());
                            } else {
                                positions.add(currentFileElement.getFileName());
                            }
                        }

                        final String[] foldersArray = new String[folders.size()];
                        final String[] positionsArray = new String[positions.size()];
                        folders.toArray(foldersArray);
                        positions.toArray(positionsArray);

                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                DialogFragment newFragment = new ConfirmRemoveElementsDialogFragment();
                                Bundle arguments = new Bundle();
                                arguments.putStringArray(ConfirmRemoveElementsDialogFragment.FOLDERS_TAG,
                                        foldersArray);
                                arguments.putStringArray(ConfirmRemoveElementsDialogFragment.POSITIONS_TAG,
                                        positionsArray);
                                newFragment.setArguments(arguments);
                                newFragment.show(getSupportFragmentManager(), "confirmRemoveElements");
                            }
                        });

                        return null;
                    }
                }.execute();
            }
            // if (thereIsSelection)
            else {
                Toast.makeText(this, R.string.error_select_removing_elements_first, Toast.LENGTH_LONG).show();
            }
        }
        // if (selectionMode)
        else {
            Toast.makeText(this, R.string.error_enter_selection_mode_first, Toast.LENGTH_LONG).show();
        }
        return true;
    /////////////////// temporary
    case R.id.action_test:
        DialogFragment dialog = new ExistingFileDialogFragment();
        Bundle arguments = new Bundle();
        arguments.putString(ExistingFileDialogFragment.FILE_NAME_TAG, "MyTest.epd");
        dialog.setArguments(arguments);
        dialog.show(getSupportFragmentManager(), "testDialog");
        return true;
    ////////////////////
    default:
        return super.onOptionsItemSelected(menuItem);
    }
}

From source file:com.example.ramesh.p2pfileshare.ClientActivity.java

public void displayPeers(final WifiP2pDeviceList peers) {
    //Dialog to show errors/status
    final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setTitle("WiFi Direct File Transfer");

    //Get list view
    //ListView peerView = (ListView) findViewById(R.id.peers_listview); //--version2

    //Make array list
    ArrayList<String> peersStringArrayList = new ArrayList<String>();

    //Fill array list with strings of peer names
    for (WifiP2pDevice wd : peers.getDeviceList()) {
        peersStringArrayList.add(wd.deviceName);
    }//from   w w w .  j a  v  a2  s. c o m

    //Set list view as clickable
    //peerView.setClickable(true); --version2

    String[] peersList = new String[peersStringArrayList.size()];
    peersList = peersStringArrayList.toArray(peersList);

    Log.v("WIFIP2PNEW", "Total servers showing " + peersList.length);
    Bundle bundle = new Bundle();
    bundle.putStringArray("server_names", peersList);

    ServerListFragment serverListFragment = new ServerListFragment();
    serverListFragment.setArguments(bundle);

    FragmentManager fm = getSupportFragmentManager();

    ServerListFragment prevFrag = (ServerListFragment) fm.findFragmentById(R.id.myclientlayout);
    if (prevFrag != null) {
        fm.beginTransaction().remove(prevFrag).commit();
        Log.v("WIFIP2PNEW", "Prevs fargment found so removing");
    } else {
        Log.v("WIFIP2PNEW", "No Prevs fargment found so creating new one");
    }

    fm.beginTransaction().add(R.id.myclientlayout, serverListFragment, "myfragement").commit();
    //Make adapter to connect peer data to list view
    /*ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, peersStringArrayList.toArray()); //--version2
            
    //Show peer data in listview
    peerView.setAdapter(arrayAdapter);
               
            
    peerView.setOnItemClickListener(new OnItemClickListener() {
            
      public void onItemClick(AdapterView<?> arg0, View view, int arg2,long arg3) {
            
    //Get string from textview
    TextView tv = (TextView) view;
            
    WifiP2pDevice device = null;
            
    //Search all known peers for matching name
     for(WifiP2pDevice wd : peers.getDeviceList())
     {
        if(wd.deviceName.equals(tv.getText()))
           device = wd;                   
     }
            
    if(device != null)
    {
       //Connect to selected peer
       connectToPeer(device);
                              
    }
    else
    {
       dialog.setMessage("Failed");
       dialog.show();
                              
    }                     
      }         
    // TODO Auto-generated method stub            
      }); //--version2
    */
}

From source file:com.fbbackup.TagMeImageGridFragment.java

@TargetApi(16)
@Override/*from  w  w w .  j  a  v a2  s . c  o m*/
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    final Intent i = new Intent(getActivity(), TagImageDetailActivity.class);

    Bundle bundle = new Bundle();

    bundle.putStringArray("photo", tagMePicture);

    bundle.putString("userName", name);

    i.putExtras(bundle);

    i.putExtra(ImageDetailActivity.EXTRA_IMAGE, (int) id);
    if (Utils.hasJellyBean()) {
        // makeThumbnailScaleUpAnimation() looks kind of ugly here as the
        // loading spinner may
        // show plus the thumbnail image in GridView is cropped. so using
        // makeScaleUpAnimation() instead.
        ActivityOptions options = ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getWidth(), v.getHeight());
        getActivity().startActivity(i, options.toBundle());
    } else {
        startActivity(i);
    }
}

From source file:org.onebusaway.android.directions.realtime.RealtimeService.java

private Bundle getSimplifiedBundle(Bundle params) {
    Itinerary itinerary = getItinerary(params);
    ItineraryDescription desc = new ItineraryDescription(itinerary);

    Bundle extras = new Bundle();
    new TripRequestBuilder(params).copyIntoBundleSimple(extras);

    List<String> idList = desc.getTripIds();
    String[] ids = idList.toArray(new String[idList.size()]);
    extras.putStringArray(ITINERARY_DESC, ids);
    extras.putLong(ITINERARY_END_DATE, desc.getEndDate().getTime());

    Class<? extends Activity> source = (Class<? extends Activity>) params
            .getSerializable(OTPConstants.NOTIFICATION_TARGET);

    extras.putString(OTPConstants.NOTIFICATION_TARGET, source.getName());

    return extras;
}

From source file:iovi.testtask.MainActivity.java

private void selectItem(int position) {

    Fragment fragment = new ListF();
    FragmentManager fragmentManager;/* ww w.  j a v  a 2 s. c  om*/
    FragmentTransaction fragmentTransaction;
    Bundle args = new Bundle();
    args.putString("Title", mMenuTitles[position]);

    switch (position) {
    case 0:
        args.putString(ListF.TABLE, DataBaseHelper.TABLE_ORGANISATIONS);
        args.putString(ListF.COLUMN, DataBaseHelper.NAME);
        args.putString(ListF.SELECTION, null);
        args.putStringArray(ListF.ARGS, null);
        fragment.setArguments(args);
        fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
        break;
    case 1:
        args.putString(ListF.TABLE, DataBaseHelper.TABLE_NEWS);
        args.putString(ListF.COLUMN, DataBaseHelper.NEWS_TITLE);
        args.putString(ListF.SELECTION, null);
        args.putStringArray(ListF.ARGS, null);
        fragment.setArguments(args);

        fragmentManager = getFragmentManager();
        fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.content_frame, fragment);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();
        break;

    case 2:
        fragment = new ContactsF();
        fragment.setArguments(args);
        fragmentManager = getFragmentManager();
        fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.content_frame, fragment);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();

        break;
    }

    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(mMenuTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

From source file:de.aw.monma.wertpapier.FragmentWertpapierUebersicht.java

@Override
protected void setInternalArguments(Bundle args) {
    super.setInternalArguments(args);
    args.putParcelable(DBDEFINITION, tbd);
    args.putStringArray(PROJECTION, projection);
    args.putInt(LAYOUT, layout);/*from   w  ww .ja  v a  2 s  .  c o  m*/
    args.putInt(VIEWHOLDERLAYOUT, detailLayout);
    args.putString(SELECTION, selection);
    args.putString(ORDERBY, orderBy);
    args.putString(GROUPBY, groupBy);
}

From source file:org.harleydroid.HarleyDroidService.java

public void startSend(String type[], String ta[], String sa[], String command[], String expect[], int timeout[],
        int delay) {
    if (D)/*  w w  w.ja  v a 2 s . c  om*/
        Log.d(TAG, "send()");
    Message m = mServiceHandler.obtainMessage(MSG_START_SEND);
    Bundle b = new Bundle();
    b.putStringArray("type", type);
    b.putStringArray("ta", ta);
    b.putStringArray("sa", sa);
    b.putStringArray("command", command);
    b.putStringArray("expect", expect);
    b.putIntArray("timeout", timeout);
    b.putInt("delay", delay);
    m.setData(b);
    //mServiceHandler.removeCallbacksAndMessages(null);
    m.sendToTarget();
}

From source file:org.harleydroid.HarleyDroidService.java

public void setSendData(String type[], String ta[], String sa[], String command[], String expect[],
        int timeout[], int delay) {
    if (D)//from   w ww .  j  av  a 2 s .  c  o  m
        Log.d(TAG, "setSendData()");
    Message m = mServiceHandler.obtainMessage(MSG_SET_SEND);
    Bundle b = new Bundle();
    b.putStringArray("type", type);
    b.putStringArray("ta", ta);
    b.putStringArray("sa", sa);
    b.putStringArray("command", command);
    b.putStringArray("expect", expect);
    b.putIntArray("timeout", timeout);
    b.putInt("delay", delay);
    m.setData(b);
    //mServiceHandler.removeCallbacksAndMessages(null);
    m.sendToTarget();
}

From source file:net.xisberto.phonetodesktop.ui.SendTasksActivity.java

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    //We save the caches because they don't go to the database
    outState.putStringArray(SAVE_CACHE_UNSHORTEN, localTask.cache_unshorten);
    outState.putStringArray(SAVE_CACHE_TITLES, localTask.cache_titles);
    outState.putBoolean(SAVE_IS_WAITING, isWaiting);
    outState.putLong(SAVE_LOCAL_TASK_ID, localTask.getLocalId());
}