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

Bundle(boolean doInit) 

Source Link

Document

Constructs a Bundle without initializing it.

Usage

From source file:Main.java

public static Message getMessage(int statusCode, byte[] responseBody) {
    Message message = new Message();
    message.what = statusCode;/*from   w ww .  j a v a  2s . c  o  m*/

    Bundle bundle = new Bundle(1);
    bundle.putByteArray("response", responseBody);
    message.setData(bundle);
    return message;
}

From source file:Main.java

/**
 *  /*from   w  w  w .jav  a  2s.c o m*/
 * @param jsonObject
 * @return
 */
@SuppressWarnings("unchecked")
public static Bundle parseBundle(JSONObject jsonObject) {
    Bundle bundle = null;
    if (jsonObject != null) {
        bundle = new Bundle(jsonObject.length());
        for (Iterator<String> iterator = jsonObject.keys(); iterator.hasNext();) {
            String key = iterator.next();
            Object object = null;
            try {
                object = jsonObject.get(key);
            } catch (JSONException e) {
                if (isLogEnabled()) {
                    e.printStackTrace();
                }
            }
            putBundleObject(bundle, key, object);
        }
    }
    return bundle;
}

From source file:at.bitfire.davdroid.ui.CreateCollectionFragment.java

public static CreateCollectionFragment newInstance(Account account, CollectionInfo info) {
    CreateCollectionFragment frag = new CreateCollectionFragment();
    Bundle args = new Bundle(2);
    args.putParcelable(ARG_ACCOUNT, account);
    args.putSerializable(ARG_COLLECTION_INFO, info);
    frag.setArguments(args);//from  w  ww . ja v a2 s. c  o m
    return frag;
}

From source file:Main.java

/**
 *  // ww  w .  j  av a  2 s  .  c  o m
 * @param bundle
 * @param key
 * @param object
 */
private static void putBundleObject(Bundle bundle, String key, Object object) {
    if (bundle != null && object != null && !TextUtils.isEmpty(key)) {
        if (object instanceof String) {
            bundle.putString(key, (String) object);
        } else if (object instanceof Boolean) {
            bundle.putBoolean(key, (Boolean) object);
        } else if (object instanceof Double) {
            bundle.putDouble(key, (Double) object);
        } else if (object instanceof Float) {
            Float value = (Float) object;
            bundle.putDouble(key, (double) value);
        } else if (object instanceof Integer) {
            bundle.putInt(key, (Integer) object);
        } else if (object instanceof Long) {
            bundle.putLong(key, (Long) object);
        } else if (object instanceof JSONObject) {
            object = parseBundle((JSONObject) object);
            bundle.putBundle(key, (Bundle) object);
        } else if (object instanceof JSONArray) {
            int elementQuantity = ((JSONArray) object).length();
            Bundle subBundle = new Bundle(elementQuantity);
            for (int i = 0; i < elementQuantity; i++) {
                Object subObject = getArrayValue((JSONArray) object, i, null);
                if (subObject != null) {
                    putBundleObject(subBundle, key, subObject);
                }
            }
        }
    }
}

From source file:com.ryan.ryanreader.fragments.MainMenuFragment.java

/**
 * MainMenuFragment/*  w  ww. ja v  a  2  s .  c om*/
 * 
 * @param force
 * @return
 */
public static MainMenuFragment newInstance(final boolean force) {

    final MainMenuFragment f = new MainMenuFragment();

    // Bundle1
    final Bundle bundle = new Bundle(1);
    bundle.putBoolean("force", force);
    f.setArguments(bundle);

    /*
     * public void setArguments(Bundle args)
     * 
     * Fragment????FragmentActivity?
     * Fragment?????Fragment??
     */
    return f;
}

From source file:com.normalexception.app.rx8club.fragment.LoginFragment.java

public static LoginFragment getInstance(boolean userClicked) {
    LoginFragment lf = new LoginFragment();
    Bundle args = new Bundle(1);
    args.putBoolean("userclick", userClicked);
    lf.setArguments(args);//from  w w w . j av  a  2 s  .c om
    return lf;
}

From source file:com.google.android.gcm.demo.logic.DeviceGroupsHelper.java

/**
 * Execute the HTTP call to create the Device Group in background.
 *
 * <code>/*from  ww w . ja  v  a 2 s. co m*/
 *   Content-Type: application/json
 *   Authorization: key=API_KEY
 *   project_id: SENDER_ID
 *   {
 *     "operation": "create",
 *     "notification_key_name": "appUser-Chris",
 *     "registration_ids": ["4", "8", "15", "16", "23", "42"]
 *   }
 * </code>
 */
public void asyncCreateGroup(final String senderId, final String apiKey, final String groupName,
        Bundle members) {
    final Bundle newMembers = new Bundle(members);
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... voids) {
            try {
                HttpRequest httpRequest = new HttpRequest();
                httpRequest.setHeader(HEADER_CONTENT_TYPE, CONTENT_TYPE_JSON);
                httpRequest.setHeader(HEADER_AUTHORIZATION, "key=" + apiKey);
                httpRequest.setHeader(HEADER_PROJECT_ID, senderId);

                JSONObject requestBody = new JSONObject();
                requestBody.put("operation", "create");
                requestBody.put("notification_key_name", groupName);
                requestBody.put("registration_ids", new JSONArray(bundleValues2Array(newMembers)));

                httpRequest.doPost(GCM_GROUPS_ENDPOINT, requestBody.toString());

                JSONObject responseBody = new JSONObject(httpRequest.getResponseBody());

                if (responseBody.has("error")) {
                    mLogger.log(Log.INFO, "Group creation failed." + "\ngroupName: " + groupName
                            + "\nhttpResponse:" + httpRequest.getResponseBody());
                    MainActivity.showToast(mContext, R.string.group_toast_group_creation_failed,
                            responseBody.getString("error"));
                } else {
                    // Store the group in the local storage.
                    DeviceGroup group = new DeviceGroup();
                    group.notificationKeyName = groupName;
                    group.notificationKey = responseBody.getString("notification_key");
                    for (String name : newMembers.keySet()) {
                        group.tokens.put(name, newMembers.getString(name));
                    }

                    Sender sender = mSenders.getSender(senderId);
                    sender.groups.put(group.notificationKeyName, group);
                    mSenders.updateSender(sender);

                    mLogger.log(Log.INFO, "Group creation succeeded." + "\ngroupName: "
                            + group.notificationKeyName + "\ngroupKey: " + group.notificationKey);
                    MainActivity.showToast(mContext, R.string.group_toast_group_creation_succeeded);
                }
            } catch (JSONException | IOException e) {
                mLogger.log(Log.INFO, "Exception while creating a new group" + "\nerror: " + e.getMessage()
                        + "\ngroupName: " + groupName);
                MainActivity.showToast(mContext, R.string.group_toast_group_creation_failed, e.getMessage());
            }
            return null;
        }
    }.execute();
}

From source file:com.ryan.ryanreader.fragments.ImageViewFragment.java

public static ImageViewFragment newInstance(final URI url, final RedditPost post) {

    final ImageViewFragment f = new ImageViewFragment();

    final Bundle bundle = new Bundle(1);
    bundle.putString("url", url.toString());
    if (post != null)
        bundle.putParcelable("post", post);
    f.setArguments(bundle);/*w ww  . j a  v a  2  s. com*/

    return f;
}