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:Main.java

/**
 * Concatenate two Parcelable Bundles containing String to form one Parcelable.<br>
 * The String message is stored via Bundle.putCharArray using {@link #BUNDLE_MESSAGE} as the key for the item.<br>
 *  //from  ww w  .  java  2s. c  o  m
 * @param one       Parcelable Bundle, containing String message
 * @param another    Parcelable Bundle, containing String message
 * @return Parcelable Bundle, including Parcelable one and another.
 * @see Bundle#putCharArray(String, char[])
 * @see Bundle#getCharArray(String)
 */
public static Parcelable assembleParcelMessage(Parcelable one, Parcelable another) {
    Bundle bundle = new Bundle();
    String message = "";
    String tmp = null;

    if (one != null) {
        tmp = ((Bundle) one).getString(BUNDLE_MESSAGE);
        if (tmp != null)
            message += tmp;
    }
    if (another != null) {
        tmp = ((Bundle) another).getString(BUNDLE_MESSAGE);
        if (tmp != null)
            message += tmp;
    }

    bundle.putString(BUNDLE_MESSAGE, message);
    bundle.setClassLoader(Bundle.class.getClassLoader());
    return bundle;
}

From source file:Main.java

public static void sendMessageHandler(Handler handler, int what, String key, int value) {
    Message message = new Message();
    message.what = what;/*from   w  w w  . ja v a 2s. c o  m*/
    Bundle bundle = new Bundle();
    bundle.putInt(key, value);
    message.setData(bundle);
    handler.sendMessage(message);
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
public static Bundle persistableBundleToBundle(PersistableBundle persistableBundle) {
    Set<String> keySet = persistableBundle.keySet();
    Bundle bundle = new Bundle();
    for (String key : keySet) {
        Object value = persistableBundle.get(key);
        if (value instanceof Boolean) {
            bundle.putBoolean(key, (boolean) value);
        } else if (value instanceof Integer) {
            bundle.putInt(key, (int) value);
        } else if (value instanceof String) {
            bundle.putString(key, (String) value);
        } else if (value instanceof String[]) {
            bundle.putStringArray(key, (String[]) value);
        } else if (value instanceof PersistableBundle) {
            Bundle innerBundle = persistableBundleToBundle((PersistableBundle) value);
            bundle.putBundle(key, innerBundle);
        }//from  w w w. jav a  2s.c  o  m
    }
    return bundle;
}

From source file:Main.java

/**
 * Create a Parcelable Bundle containing a char[] for transport to the test package engine.
 * The char[] message is stored via Bundle.putCharArray using {@link #BUNDLE_PROPERTIES} as the key for the item. 
 * The original intent here is to store Java Properties in the Bundle that were serialized via 
 * the Java Properties.store method.<br>
 * NOTE: This has not yet been tested!/*from  w  w w .  ja va 2  s.  c o  m*/
 * @param char[] (Properties) to send across processes.
 * @return Parcelable Bundle
 * @see Bundle#putCharArray(String, char[])
 * @see Bundle#getCharArray(String)
 */
public static Parcelable setParcelableProps(char[] bytes) {
    Bundle bundle = new Bundle();
    bundle.putCharArray(BUNDLE_PROPERTIES, bytes);
    bundle.setClassLoader(Bundle.class.getClassLoader());
    return bundle;
}

From source file:Main.java

/**
 * Concatenate two Parcelable Bundles containing char[] to form one Parcelable.<br>
 * The char[] message is stored via Bundle.putCharArray using {@link #BUNDLE_PROPERTIES} as the key for the item.<br>
 *  /*  ww w .j  ava  2 s.c  om*/
 * @param one       Parcelable Bundle, containing char[] message
 * @param another    Parcelable Bundle, containing char[] message
 * @return Parcelable Bundle, including Parcelable one and another.
 * @see Bundle#putCharArray(String, char[])
 * @see Bundle#getCharArray(String)
 */
public static Parcelable assembleParcelProps(Parcelable one, Parcelable another) {
    Bundle bundle = new Bundle();
    char[] characters = null;
    char[] characters1 = null;
    char[] characters2 = null;
    int length = 0;

    if (one != null) {
        characters1 = ((Bundle) one).getCharArray(BUNDLE_PROPERTIES);
        if (characters1 != null)
            length += characters1.length;
    }
    if (another != null) {
        characters2 = ((Bundle) another).getCharArray(BUNDLE_PROPERTIES);
        if (characters2 != null)
            length += characters2.length;
    }

    characters = new char[length];

    if (characters1 != null && characters2 != null) {
        System.arraycopy(characters1, 0, characters, 0, characters1.length);
        System.arraycopy(characters2, 0, characters, characters1.length, characters2.length);
    } else if (characters1 != null && characters2 == null) {
        System.arraycopy(characters1, 0, characters, 0, characters1.length);
    } else if (characters1 == null && characters2 != null) {
        System.arraycopy(characters2, 0, characters, 0, characters2.length);
    }

    bundle.putCharArray(BUNDLE_PROPERTIES, characters);
    bundle.setClassLoader(Bundle.class.getClassLoader());
    return bundle;
}

From source file:Main.java

/**
 * Removes key if value is null/*  ww  w .j av  a  2 s.  c  o  m*/
 */
@NonNull
public static Bundle toBundle(Bundle bundleIn, String key, Long value) {
    Bundle bundle = bundleIn == null ? new Bundle() : bundleIn;
    if (!TextUtils.isEmpty(key)) {
        if (value == null) {
            bundle.remove(key);
        } else {
            bundle.putLong(key, value);
        }
    }
    return bundle;
}

From source file:Main.java

public static Bundle parseUrl(String url) {
    url = url.replace("rrconnect", "http");
    try {/*w  w w. jav  a  2 s  . c  o m*/
        URL u = new URL(url);
        Bundle b = decodeUrl(u.getQuery());
        b.putAll(decodeUrl(u.getRef()));
        return b;
    } catch (MalformedURLException e) {
        return new Bundle();
    }
}

From source file:Main.java

public static Bundle parseUrl(String url) {
    url = url.replace("#", "?");
    try {//from   w  ww .j  a  v  a  2 s. co  m
        URL u = new URL(url);
        Bundle b = decodeUrl(u.getQuery());
        Bundle ref = decodeUrl(u.getRef());
        if (ref != null)
            b.putAll(ref);
        return b;
    } catch (MalformedURLException e) {
        return new Bundle();
    }
}

From source file:Main.java

public static void sendMsg2Client(Messenger messenger, String sKey, String sObjParam, int iMsg) {
    if (messenger == null) {
        return;/*w  ww .j ava  2  s. c  o m*/
    }

    try {
        Bundle b = new Bundle();

        if (null != sKey) {
            b.putString(sKey, sObjParam);
        }

        Message msgBack = Message.obtain(null, iMsg);

        if (msgBack != null) {
            msgBack.setData(b);
            messenger.send(msgBack);
        }
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * Inverse operation of {@link #fragmentArgumentsToIntent(Bundle)}.
 *//*from ww  w  .ja  v  a  2s.co m*/
public static Bundle intentToFragmentArguments(Intent intent) {
    Bundle arguments = new Bundle();
    if (intent == null) {
        return arguments;
    }

    final Uri data = intent.getData();
    if (data != null) {
        arguments.putParcelable(URI_KEY, data);
    }

    final Bundle extras = intent.getExtras();
    if (extras != null) {
        arguments.putAll(extras);
    }
    return arguments;
}