Example usage for android.os Bundle Bundle

List of usage examples for android.os Bundle Bundle

Introduction

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

Prototype

public Bundle() 

Source Link

Document

Constructs a new, empty Bundle.

Usage

From source file:com.facebook.LegacyTokenCacheTest.java

@Test
public void testAllTypes() {
    Bundle originalBundle = new Bundle();

    putBoolean(BOOLEAN_KEY, originalBundle);
    putBooleanArray(BOOLEAN_ARRAY_KEY, originalBundle);
    putByte(BYTE_KEY, originalBundle);//from   w ww  .j  a v a2  s  .  c om
    putByteArray(BYTE_ARRAY_KEY, originalBundle);
    putShort(SHORT_KEY, originalBundle);
    putShortArray(SHORT_ARRAY_KEY, originalBundle);
    putInt(INT_KEY, originalBundle);
    putIntArray(INT_ARRAY_KEY, originalBundle);
    putLong(LONG_KEY, originalBundle);
    putLongArray(LONG_ARRAY_KEY, originalBundle);
    putFloat(FLOAT_KEY, originalBundle);
    putFloatArray(FLOAT_ARRAY_KEY, originalBundle);
    putDouble(DOUBLE_KEY, originalBundle);
    putDoubleArray(DOUBLE_ARRAY_KEY, originalBundle);
    putChar(CHAR_KEY, originalBundle);
    putCharArray(CHAR_ARRAY_KEY, originalBundle);
    putString(STRING_KEY, originalBundle);
    putStringList(STRING_LIST_KEY, originalBundle);
    originalBundle.putSerializable(SERIALIZABLE_KEY, AccessTokenSource.FACEBOOK_APPLICATION_WEB);

    ensureApplicationContext();

    LegacyTokenHelper cache = new LegacyTokenHelper(RuntimeEnvironment.application);
    cache.save(originalBundle);

    LegacyTokenHelper cache2 = new LegacyTokenHelper(RuntimeEnvironment.application);
    Bundle cachedBundle = cache2.load();

    assertEquals(originalBundle.getBoolean(BOOLEAN_KEY), cachedBundle.getBoolean(BOOLEAN_KEY));
    assertArrayEquals(originalBundle.getBooleanArray(BOOLEAN_ARRAY_KEY),
            cachedBundle.getBooleanArray(BOOLEAN_ARRAY_KEY));
    assertEquals(originalBundle.getByte(BYTE_KEY), cachedBundle.getByte(BYTE_KEY));
    assertArrayEquals(originalBundle.getByteArray(BYTE_ARRAY_KEY), cachedBundle.getByteArray(BYTE_ARRAY_KEY));
    assertEquals(originalBundle.getShort(SHORT_KEY), cachedBundle.getShort(SHORT_KEY));
    assertArrayEquals(originalBundle.getShortArray(SHORT_ARRAY_KEY),
            cachedBundle.getShortArray(SHORT_ARRAY_KEY));
    assertEquals(originalBundle.getInt(INT_KEY), cachedBundle.getInt(INT_KEY));
    assertArrayEquals(originalBundle.getIntArray(INT_ARRAY_KEY), cachedBundle.getIntArray(INT_ARRAY_KEY));
    assertEquals(originalBundle.getLong(LONG_KEY), cachedBundle.getLong(LONG_KEY));
    assertArrayEquals(originalBundle.getLongArray(LONG_ARRAY_KEY), cachedBundle.getLongArray(LONG_ARRAY_KEY));
    assertEquals(originalBundle.getFloat(FLOAT_KEY), cachedBundle.getFloat(FLOAT_KEY),
            TestUtils.DOUBLE_EQUALS_DELTA);
    assertArrayEquals(originalBundle.getFloatArray(FLOAT_ARRAY_KEY),
            cachedBundle.getFloatArray(FLOAT_ARRAY_KEY));
    assertEquals(originalBundle.getDouble(DOUBLE_KEY), cachedBundle.getDouble(DOUBLE_KEY),
            TestUtils.DOUBLE_EQUALS_DELTA);
    assertArrayEquals(originalBundle.getDoubleArray(DOUBLE_ARRAY_KEY),
            cachedBundle.getDoubleArray(DOUBLE_ARRAY_KEY));
    assertEquals(originalBundle.getChar(CHAR_KEY), cachedBundle.getChar(CHAR_KEY));
    assertArrayEquals(originalBundle.getCharArray(CHAR_ARRAY_KEY), cachedBundle.getCharArray(CHAR_ARRAY_KEY));
    assertEquals(originalBundle.getString(STRING_KEY), cachedBundle.getString(STRING_KEY));
    assertListEquals(originalBundle.getStringArrayList(STRING_LIST_KEY),
            cachedBundle.getStringArrayList(STRING_LIST_KEY));
    assertEquals(originalBundle.getSerializable(SERIALIZABLE_KEY),
            cachedBundle.getSerializable(SERIALIZABLE_KEY));
}

From source file:com.jittr.android.facebook.Example.java

/** Called when the activity is first created. */
@Override//from  www.  j a  va 2s .  c o  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (APP_ID == null) {
        Util.showAlert(this, "Warning",
                "Facebook Applicaton ID must be " + "specified before running this example: see Example.java");
    }

    // mFacebook.
    setContentView(R.layout.mainfacebook);
    mLoginButton = (LoginButton) findViewById(R.id.login);
    mText = (TextView) Example.this.findViewById(R.id.txt);
    mRequestButton = (Button) findViewById(R.id.requestButton);
    mPostButton = (Button) findViewById(R.id.postButton);
    mDeleteButton = (Button) findViewById(R.id.deletePostButton);
    mUploadButton = (Button) findViewById(R.id.uploadButton);

    mFacebook = new Facebook();
    mAsyncRunner = new AsyncFacebookRunner(mFacebook);

    SessionStore.restore(mFacebook, this);
    SessionEvents.addAuthListener(new SampleAuthListener());
    SessionEvents.addLogoutListener(new SampleLogoutListener());
    mLoginButton.init(mFacebook, PERMISSIONS);

    mRequestButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mAsyncRunner.request("me", new SampleRequestListener());
        }
    });
    mRequestButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);

    mUploadButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Bundle params = new Bundle();
            params.putString("method", "photos.upload");

            URL uploadFileUrl = null;
            try {
                uploadFileUrl = new URL("http://www.facebook.com/images/devsite/iphone_connect_btn.jpg");
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            try {
                HttpURLConnection conn = (HttpURLConnection) uploadFileUrl.openConnection();
                conn.setDoInput(true);
                conn.connect();
                int length = conn.getContentLength();

                byte[] imgData = new byte[length];
                InputStream is = conn.getInputStream();
                is.read(imgData);
                params.putByteArray("picture", imgData);

            } catch (IOException e) {
                e.printStackTrace();
            }

            mAsyncRunner.request(null, params, "POST", new SampleUploadListener());
        }
    });
    mUploadButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);

    mPostButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mFacebook.dialog(Example.this, "stream.publish", new SampleDialogListener());
        }
    });
    mPostButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);
}

From source file:gov.wa.wsdot.android.wsdot.ui.FerriesRouteAlertsBulletinsFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Bundle b = new Bundle();
    Intent intent = new Intent(getActivity(), FerriesRouteAlertsBulletinDetailsActivity.class);
    b.putString("AlertFullTitle", routeAlertItems.get(position).getAlertFullTitle());
    b.putString("AlertPublishDate", routeAlertItems.get(position).getPublishDate());
    b.putString("AlertDescription", routeAlertItems.get(position).getAlertDescription());
    b.putString("AlertFullText", routeAlertItems.get(position).getAlertFullText());
    intent.putExtras(b);//from  ww  w.ja v  a 2 s  . c  o m
    startActivity(intent);
}

From source file:most.voip.example.remote_config.LoginActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check which request we're responding to
    if (requestCode == REMOTE_ACCOUNT_CONFIG_REQUEST) {
        // Make sure the request was successful
        if (resultCode == RESULT_OK) {
            Intent resultIntent = new Intent();
            Bundle b = new Bundle();
            b.putString("account_data", data.getExtras().getString("account_data"));
            b.putString("buddies_data", data.getExtras().getString("buddies_data"));

            resultIntent.putExtras(b);/* ww  w  . j a  va 2  s. c  om*/
            // TODO Add extras or a data URI to this intent as appropriate.
            Log.d("VoipConfigDemo", "Configuration accepted");
            setResult(Activity.RESULT_OK, resultIntent);

            finish();
        } else {
            Log.d("VoipConfigDemo", "Account data NOT received from the activity");
        }
    } else {
        Log.d("VoipConfigDemo", "Received unknown requestCode:" + String.valueOf(requestCode));
    }
}

From source file:com.codingrhemes.steamsalesmobile.GameSaleActivity.java

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

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    if (savedInstanceState == null) {
        // Setting up bundle to keep values
        Bundle mostPopGames = new Bundle();
        mostPopGames.putBoolean("isMostPopular", true);
        dailyDealFragment = new DealOfTheDayFragment();
        gamesFragment = new GamesFragment();
        mostPopularFragment = new MostPopularGamesFragment();
        // set them to the fragment
        mostPopularFragment.setArguments(mostPopGames);
    }/* w  ww .  j  av  a  2 s.  c  om*/

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

}

From source file:com.commonsware.cwac.colormixer.ColorMixer.java

@Override
public Parcelable onSaveInstanceState() {
    Bundle state = new Bundle();

    state.putParcelable(SUPERSTATE, super.onSaveInstanceState());
    state.putInt(COLOR, getColor());//from  ww w  .j  ava  2 s.  com

    return (state);
}

From source file:com.example.carrie.carrie_test1.druginfo.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_druginfo);
    Bundle bundle = getIntent().getExtras();
    my_id = bundle.getString("my_id");//get  id
    my_google_id = bundle.getString("my_google_id");//get google_ id
    my_mon_id = bundle.getString("my_supervise_id");
    m_calid = bundle.getString("m_calid", "not found");

    Log.d("qqqqq", m_calid);

    btmbar = (RelativeLayout) findViewById(R.id.btmbar);
    if (my_id.equals("0") && my_google_id.equals("0") && my_mon_id.equals("0")) {
        //???????
        btmbar.setVisibility(View.GONE);
    } else {//  ww w . j av  a2 s  . c o m
        BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottomNavView_Bar);
        BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);
        Menu menu = bottomNavigationView.getMenu();
        MenuItem menuItem = menu.getItem(3);
        menuItem.setChecked(true);

        bottomNavigationView.setOnNavigationItemSelectedListener(
                new BottomNavigationView.OnNavigationItemSelectedListener() {
                    @Override
                    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                        switch (item.getItemId()) {
                        case R.id.ic_list:
                            Intent intent0 = new Intent(druginfo.this, Choice.class);
                            Bundle bundle0 = new Bundle();
                            bundle0.putString("memberid", my_id);
                            bundle0.putString("my_google_id", my_google_id);
                            bundle0.putString("my_supervise_id", my_mon_id);
                            intent0.putExtras(bundle0); // put???
                            startActivity(intent0);
                            break;

                        case R.id.ic_eye:
                            Intent intent1 = new Intent(druginfo.this, MonitorActivity.class);
                            Bundle bundle1 = new Bundle();
                            bundle1.putString("my_id", my_id);
                            bundle1.putString("my_google_id", my_google_id);
                            bundle1.putString("my_supervise_id", my_mon_id);
                            intent1.putExtras(bundle1);
                            startActivity(intent1);
                            break;

                        case R.id.ic_home:
                            Intent intent2 = new Intent(druginfo.this, MainActivity.class);
                            Bundle bundle2 = new Bundle();
                            bundle2.putString("googleid", my_google_id);
                            intent2.putExtras(bundle2);
                            startActivity(intent2);
                            break;

                        case R.id.ic_information:
                            Intent intent3 = new Intent(druginfo.this, druginfo.class);
                            Bundle bundle3 = new Bundle();
                            bundle3.putString("my_id", my_id);
                            bundle3.putString("my_google_id", my_google_id);
                            bundle3.putString("my_supervise_id", my_mon_id);
                            intent3.putExtras(bundle3);
                            startActivity(intent3);
                            break;

                        case R.id.ic_beacon:
                            Intent intent4 = new Intent(druginfo.this, Beacon.class);
                            Bundle bundle4 = new Bundle();
                            bundle4.putString("my_id", my_id);
                            bundle4.putString("my_google_id", my_google_id);
                            bundle4.putString("my_supervise_id", my_mon_id);
                            intent4.putExtras(bundle4);
                            startActivity(intent4);
                            break;
                        }

                        return false;
                    }
                });
    }

    listView = (ListView) findViewById(R.id.listview);
    editText = (EditText) findViewById(R.id.textsearch);

    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (!s.toString().equals("")) {
                //reset listview

                //                    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
                //                    data_list = new ArrayList<>();
                //                    load_data_from_server(0);
                //
                //                    gridLayoutManager = new GridLayoutManager(getBaseContext(), 2);
                //                    recyclerView.setLayoutManager(gridLayoutManager);
                //
                //                    adapter = new CustomAdapter2(getBaseContext(), data_list);
                //                    recyclerView.setAdapter(adapter);
                //
                //                    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                //                        @Override
                //                        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                //
                //                            if (gridLayoutManager.findLastCompletelyVisibleItemPosition() == data_list.size() - 1) {
                //                                load_data_from_server(data_list.get(data_list.size() - 1).getId());
                //                            }
                //
                //                        }
                //                    });
                recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
                data_list2 = new ArrayList<>();
                Log.d("searchtest", "3");
                load_data_from_server_search(s.toString());

                Log.d("searchtest", "1");
                gridLayoutManager = new GridLayoutManager(getBaseContext(), 2);
                recyclerView.setLayoutManager(gridLayoutManager);
                Log.d("searchtest", "2");
                adapter = new CustomAdapter2(getBaseContext(), data_list2, m_calid);
                recyclerView.setAdapter(adapter);
            } else {
                recyclerView = (RecyclerView) findViewById(R.id.recycler_view);

                gridLayoutManager = new GridLayoutManager(getBaseContext(), 2);
                recyclerView.setLayoutManager(gridLayoutManager);

                adapter = new CustomAdapter2(getBaseContext(), data_list, m_calid);
                recyclerView.setAdapter(adapter);

            }

        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    data_list = new ArrayList<>();
    load_data_from_server(0);

    gridLayoutManager = new GridLayoutManager(this, 2);
    recyclerView.setLayoutManager(gridLayoutManager);

    adapter = new CustomAdapter2(this, data_list, m_calid);
    recyclerView.setAdapter(adapter);

    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

            if (gridLayoutManager.findLastCompletelyVisibleItemPosition() == data_list.size() - 1) {
                load_data_from_server(data_list.get(data_list.size() - 1).getId());
            }

        }
    });

}

From source file:com.mercandalli.android.apps.files.file.cloud.FileMyCloudFragment.java

public static FileMyCloudFragment newInstance(final int positionInViewPager) {
    final FileMyCloudFragment fileMyCloudLocalFragment = new FileMyCloudFragment();
    final Bundle args = new Bundle();
    args.putInt(ARG_POSITION_IN_VIEW_PAGER, positionInViewPager);
    fileMyCloudLocalFragment.setArguments(args);
    return fileMyCloudLocalFragment;
}

From source file:com.pixem.core.activity.Example.java

/** Called when the activity is first created. */
@Override// ww  w .  j a va 2s. c o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (APP_ID == null) {
        Util.showAlert(this, "Warning",
                "Facebook Applicaton ID must be " + "specified before running this example: see Example.java");
    }

    setContentView(R.layout.facebook);
    mLoginButton = (LoginButton) findViewById(R.id.login);
    mText = (TextView) Example.this.findViewById(R.id.txt);
    mRequestButton = (Button) findViewById(R.id.requestButton);
    mPostButton = (Button) findViewById(R.id.postButton);
    mDeleteButton = (Button) findViewById(R.id.deletePostButton);
    mUploadButton = (Button) findViewById(R.id.uploadButton);

    mFacebook = new Facebook(APP_ID);
    mAsyncRunner = new AsyncFacebookRunner(mFacebook);

    SessionStore.restore(mFacebook, this);
    SessionEvents.addAuthListener(new SampleAuthListener());
    SessionEvents.addLogoutListener(new SampleLogoutListener());
    mLoginButton.init(this, mFacebook);

    mRequestButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mAsyncRunner.request("me", new SampleRequestListener());
        }
    });
    mRequestButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);

    mUploadButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Bundle params = new Bundle();
            params.putString("method", "photos.upload");

            URL uploadFileUrl = null;
            try {
                uploadFileUrl = new URL("http://www.facebook.com/images/devsite/iphone_connect_btn.jpg");
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            try {
                HttpURLConnection conn = (HttpURLConnection) uploadFileUrl.openConnection();
                conn.setDoInput(true);
                conn.connect();
                int length = conn.getContentLength();

                byte[] imgData = new byte[length];
                InputStream is = conn.getInputStream();
                is.read(imgData);
                params.putByteArray("picture", imgData);

            } catch (IOException e) {
                e.printStackTrace();
            }

            mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null);
        }
    });
    mUploadButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);

    mPostButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mFacebook.dialog(Example.this, "feed", new SampleDialogListener());
        }
    });
    mPostButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE);
}

From source file:com.katamaditya.apps.weather4u.weathersync.Weather4USyncAdapter.java

/**
 * Helper method to schedule the sync adapter periodic execution
 *///w w  w  .  j  a  v  a 2  s .  c o m
public static void configurePeriodicSync(Context context, int syncInterval, int flexTime) {
    Account account = getSyncAccount(context);
    String authority = context.getString(R.string.content_authority);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // we can enable inexact timers in our periodic sync
        SyncRequest request = new SyncRequest.Builder().syncPeriodic(syncInterval, flexTime)
                .setSyncAdapter(account, authority).setExtras(new Bundle()).build();
        ContentResolver.requestSync(request);
    } else {
        ContentResolver.addPeriodicSync(account, authority, new Bundle(), syncInterval);
    }
}