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.internal.BundleJSONConverterTest.java

@Test
public void testSimpleValues() throws JSONException {
    ArrayList<String> arrayList = new ArrayList<String>();
    arrayList.add("1st");
    arrayList.add("2nd");
    arrayList.add("third");

    Bundle innerBundle1 = new Bundle();
    innerBundle1.putInt("inner", 1);

    Bundle innerBundle2 = new Bundle();
    innerBundle2.putString("inner", "2");
    innerBundle2.putStringArray("deep list", new String[] { "7", "8" });

    innerBundle1.putBundle("nested bundle", innerBundle2);

    Bundle b = new Bundle();
    b.putBoolean("boolValue", true);
    b.putInt("intValue", 7);
    b.putLong("longValue", 5000000000l);
    b.putDouble("doubleValue", 3.14);
    b.putString("stringValue", "hello world");
    b.putStringArray("stringArrayValue", new String[] { "first", "second" });
    b.putStringArrayList("stringArrayListValue", arrayList);
    b.putBundle("nested", innerBundle1);

    JSONObject json = BundleJSONConverter.convertToJSON(b);
    assertNotNull(json);/*from   w  w  w .  j  a v  a  2 s .  c  om*/

    assertEquals(true, json.getBoolean("boolValue"));
    assertEquals(7, json.getInt("intValue"));
    assertEquals(5000000000l, json.getLong("longValue"));
    assertEquals(3.14, json.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA);
    assertEquals("hello world", json.getString("stringValue"));

    JSONArray jsonArray = json.getJSONArray("stringArrayValue");
    assertEquals(2, jsonArray.length());
    assertEquals("first", jsonArray.getString(0));
    assertEquals("second", jsonArray.getString(1));

    jsonArray = json.getJSONArray("stringArrayListValue");
    assertEquals(3, jsonArray.length());
    assertEquals("1st", jsonArray.getString(0));
    assertEquals("2nd", jsonArray.getString(1));
    assertEquals("third", jsonArray.getString(2));

    JSONObject innerJson = json.getJSONObject("nested");
    assertEquals(1, innerJson.getInt("inner"));
    innerJson = innerJson.getJSONObject("nested bundle");
    assertEquals("2", innerJson.getString("inner"));

    jsonArray = innerJson.getJSONArray("deep list");
    assertEquals(2, jsonArray.length());
    assertEquals("7", jsonArray.getString(0));
    assertEquals("8", jsonArray.getString(1));

    Bundle finalBundle = BundleJSONConverter.convertToBundle(json);
    assertNotNull(finalBundle);

    assertEquals(true, finalBundle.getBoolean("boolValue"));
    assertEquals(7, finalBundle.getInt("intValue"));
    assertEquals(5000000000l, finalBundle.getLong("longValue"));
    assertEquals(3.14, finalBundle.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA);
    assertEquals("hello world", finalBundle.getString("stringValue"));

    List<String> stringList = finalBundle.getStringArrayList("stringArrayValue");
    assertEquals(2, stringList.size());
    assertEquals("first", stringList.get(0));
    assertEquals("second", stringList.get(1));

    stringList = finalBundle.getStringArrayList("stringArrayListValue");
    assertEquals(3, stringList.size());
    assertEquals("1st", stringList.get(0));
    assertEquals("2nd", stringList.get(1));
    assertEquals("third", stringList.get(2));

    Bundle finalInnerBundle = finalBundle.getBundle("nested");
    assertEquals(1, finalInnerBundle.getInt("inner"));
    finalBundle = finalInnerBundle.getBundle("nested bundle");
    assertEquals("2", finalBundle.getString("inner"));

    stringList = finalBundle.getStringArrayList("deep list");
    assertEquals(2, stringList.size());
    assertEquals("7", stringList.get(0));
    assertEquals("8", stringList.get(1));
}

From source file:com.ronnyml.sweetplayer.fragments.CommonFragment.java

public static CommonFragment newInstance(int position, String screen) {
    CommonFragment fragment = new CommonFragment();
    Bundle args = new Bundle();
    args.putInt(Constants.POSITION, position);
    args.putString(Constants.SCREEN, screen);
    fragment.setArguments(args);//  w w  w  .  j a v  a2  s  . c om
    return fragment;
}

From source file:com.ds.kaixin.GetFriendListTask.java

@SuppressWarnings("unchecked")
protected Integer doInBackground(Object... params) {
    if (params == null || params.length == 0 || params.length != 6) {
        handler.sendEmptyMessage(Constant.RESULT_FAILED_ARG_ERR);
        return 0;
    }/*from w  ww . j  a v a 2s.c om*/

    String start = (String) params[0];
    String number = (String) params[1];
    Kaixin kaixin = (Kaixin) params[2];
    handler = (Handler) params[3];
    resultContainer = (ArrayList<FriendInfo>) params[4];
    Context context = (Context) params[5];

    Bundle bundle = new Bundle();
    bundle.putString("start", start);
    bundle.putString("num", number);
    bundle.putString("fields", "uid,name,gender,logo50,birthday");

    try {
        String jsonResult = kaixin.request(context, RESTAPI_INTERFACE_GETFRIENDLIST, bundle, "GET");
        if (jsonResult == null) {
            handler.sendEmptyMessage(Constant.RESULT_FAILED_NETWORK_ERR);
        } else {
            KaixinError kaixinError = Util.parseRequestError(jsonResult);
            if (kaixinError != null) {
                Message msg = Message.obtain();
                msg.what = Constant.RESULT_FAILED_REQUEST_ERR;
                msg.obj = kaixinError;
                handler.sendMessage(msg);
            } else {
                ArrayList<FriendInfo> friendList = getFriendInfos(jsonResult);
                if (null != friendList) {
                    resultContainer.addAll(friendList);
                }
                if (resultContainer.size() > 0) {
                    handler.sendEmptyMessage(Constant.RESULT_GET_FRIENDS_OK);
                } else {
                    handler.sendEmptyMessage(Constant.RESULT_GET_FRIENDS_ZERO);
                }
            }
        }
    } catch (MalformedURLException e1) {
        Log.e(TAG, "", e1);
        handler.sendEmptyMessage(Constant.RESULT_FAILED_MALFORMEDURL_ERR);
    } catch (JSONException e1) {
        Log.e(TAG, "", e1);
        handler.sendEmptyMessage(Constant.RESULT_FAILED_JSON_PARSE_ERR);
    } catch (IOException e1) {
        Log.e(TAG, "", e1);
        handler.sendEmptyMessage(Constant.RESULT_FAILED_NETWORK_ERR);
    } catch (Exception e1) {
        Log.e(TAG, "", e1);
        handler.sendEmptyMessage(Constant.RESULT_FAILED);
    }

    return 1;
}

From source file:Main.java

@SuppressWarnings("unchecked")
private static void putArray(String key, ArrayList arrayList, Bundle bundle) {
    if (arrayList.size() == 0) {
        bundle.putBooleanArray(key, new boolean[] {});
    } else {//  ww w.  j  av  a 2 s .c  o  m
        verifyArrayListIsSingleType(arrayList);
        if (arrayList.get(0) instanceof String) {
            bundle.putStringArray(key, toStringArray((ArrayList<String>) arrayList));
        } else if (arrayList.get(0) instanceof Integer) {
            bundle.putIntArray(key, toIntArray((ArrayList<Integer>) arrayList));
        } else if (arrayList.get(0) instanceof Float) {
            bundle.putFloatArray(key, toFloatArray((ArrayList<Float>) arrayList));
        } else if (arrayList.get(0) instanceof Double) {
            bundle.putDoubleArray(key, toDoubleArray((ArrayList<Double>) arrayList));
        } else if (arrayList.get(0) instanceof Boolean) {
            bundle.putBooleanArray(key, toBooleanArray((ArrayList<Boolean>) arrayList));
        } else if (arrayList.get(0) instanceof HashMap) {
            bundle.putParcelableArray(key, toBundleArray((ArrayList<HashMap>) arrayList));
        } else if (arrayList.get(0) instanceof ArrayList) {
            Log.w("RNNavigation",
                    "Arrays of arrays passed in props are converted to dictionaries with indexes as keys");
            Bundle innerArray = new Bundle();
            for (int i = 0; i < arrayList.size(); i++) {
                putArray(String.valueOf(i), (ArrayList) arrayList.get(i), innerArray);
            }
            bundle.putParcelable(key, innerArray);
        }
    }
}

From source file:love.juhe.androidmonkey.MonkeyActivityEvent.java

@SuppressLint("NewApi")
@Override/*from www  .java2  s .c  o  m*/
public int fireEvent(Instrumentation testRuner) {
    Intent intent = getEvent();
    MonkeyLog.l(":Switch: " + intent.toUri(0));

    if (mAlarmTime != 0) {
        Bundle args = new Bundle();
        args.putLong("alarmTime", mAlarmTime);
        intent.putExtras(args);
    }
    try {
        //         IntentFilter filter = new IntentFilter(getEvent().getAction());
        //         ActivityMonitor monitor = testRuner.addMonitor(filter, null, true);
        testRuner.startActivitySync(intent);
        //         testRuner.waitForMonitorWithTimeout(monitor, 10);

    } catch (SecurityException e) {
        MonkeyLog.l("** Permissions error starting activity " + intent.toUri(0));
        return MonkeyEvent.INJECT_ERROR_SECURITY_EXCEPTION;
    }
    return MonkeyEvent.INJECT_SUCCESS;
}

From source file:com.google.android.apps.authenticator.dataexport.Exporter.java

public Bundle getData() {
    Bundle result = new Bundle();
    result.putBundle("accountDb", getAccountDbBundle(mAccountDb));
    if (mPreferences != null) {
        result.putBundle("preferences", getPreferencesBundle(mPreferences));
    }// ww  w . j av a 2 s  .c  o  m
    return result;
}

From source file:com.ntsync.android.sync.activities.CreatePwdProgressDialog.java

/**
 * Creates a new Key//from   w ww . j  a v a 2 s  .  co m
 * 
 * @param userName
 * @param pwdSalt
 * @param authtoken
 * @return invisible Dialog
 */
public static CreatePwdProgressDialog newInstance(String userName, byte[] currPwdSalt) {
    CreatePwdProgressDialog dlg = new CreatePwdProgressDialog();

    Bundle args = new Bundle();
    args.putString(KeyPasswordActivity.PARAM_USERNAME, userName);
    args.putByteArray(KeyPasswordActivity.PARAM_SALT, currPwdSalt);

    dlg.setArguments(args);
    return dlg;
}

From source file:at.madexperts.logmynight.facebook.PublishHandler.java

/**
 * Called by the dispatcher to render the stream page.
 *//*  www  .  ja  va 2 s  .c  o  m*/
public void go() {
    Facebook fb = Session.restore(getActivity()).getFb();
    AsyncFacebookRunner runner = new AsyncFacebookRunner(fb);
    Bundle params = new Bundle();
    String message = getActivity().getIntent().getStringExtra("message");

    params.putString("message", message);
    params.putString("link", "http://github.com/mikegr/alogmynight");
    params.putString("name", "Testname");
    params.putString("caption", "Test caption");
    params.putString("description", "<b>HTML Test for message</b>");

    runner.request("me/feed", params, "POST", new AsyncRequestListener() {

        public void onComplete(JSONObject obj) {
            String html;
            Log.d(TAG, "onComplete");
            getActivity().finish();
        }
    });

}

From source file:cn.edu.szjm.service.PostRecordTask.java

protected Integer doInBackground(Object... params) {

    requestListener.onRequestStart();/* w w w.  j a v  a  2s  .c  om*/

    if ((activity == null) || (!(in == null) && (news == null)))
        requestListener.onRequestFault(new Throwable(new NullPointerException().getMessage()));

    Kaixin kaixin = Kaixin.getInstance();

    try {

        Bundle bundle = new Bundle();
        bundle.putByteArray("content", news.getBytes());

        Map<String, Object> photoes = new HashMap<String, Object>();
        photoes.put("filename", in);

        String jsonResult = kaixin.uploadContent(activity, RESTAPI_INTERFACE_POSTRECORD, bundle, photoes);

        if (TextUtils.isEmpty(jsonResult)) {

            requestListener.onRequestFault(new KaixinError(Constant.RESULT_FAILED_REQUEST_ERR,
                    "/", "", ""));

        } else {

            KaixinError kaixinError = Util.parseRequestError(jsonResult);

            if (kaixinError != null) {

                requestListener.onRequestError(kaixinError);

            } else {

                long rid = getRecordID(jsonResult);

                if (rid < 0)
                    requestListener.onRequestError(new KaixinError(Constant.RESULT_POST_RECORD_FAILED,
                            "/???", "", jsonResult));
                else
                    requestListener.onRequestComplete(jsonResult);
            }

        }

    } catch (IOException e) {
        requestListener
                .onRequestFault(new KaixinError(Constant.RESULT_FAILED_NETWORK_ERR, e.getMessage(), "", ""));
    } catch (JSONException e) {
        requestListener
                .onRequestError(new KaixinError(Constant.RESULT_FAILED_JSON_PARSE_ERR, e.getMessage(), "", ""));
    }
    return params.length;
}

From source file:com.manning.androidhacks.hack040.ImageDetailFragment.java

/**
 * Factory method to generate a new instance of the fragment given an image
 * number./*from w  w w . j  a v  a2 s.c  o  m*/
 * 
 * @param imageNum
 *          The image number within the parent adapter to load
 * @return A new instance of ImageDetailFragment with imageNum extras
 */
public static ImageDetailFragment newInstance(int imageNum) {
    final ImageDetailFragment f = new ImageDetailFragment();

    final Bundle args = new Bundle();
    args.putInt(IMAGE_DATA_EXTRA, imageNum);
    f.setArguments(args);

    return f;
}