Example usage for android.os Bundle putString

List of usage examples for android.os Bundle putString

Introduction

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

Prototype

public void putString(@Nullable String key, @Nullable String value) 

Source Link

Document

Inserts a String value into the mapping of this Bundle, replacing any existing value for the given key.

Usage

From source file:com.mobilesolutionworks.android.twitter.TwitterPluginFragment.java

public static TwitterPluginFragment create(String consumerKey, String consumerSecret) {
    Bundle args = new Bundle();
    args.putString("consumerKey", consumerKey);
    args.putString("consumerSecret", consumerSecret);

    TwitterPluginFragment fragment = new TwitterPluginFragment();
    fragment.setArguments(args);//from ww  w .j a  v  a  2 s.com

    return fragment;
}

From source file:com.groupme.sdk.util.HttpUtils.java

public static Bundle decodeParams(String query) {
    Bundle params = new Bundle();

    if (query != null && !query.equals("")) {
        String[] parts = query.split("&");

        for (String param : parts) {
            String[] item = param.split("=");

            try {
                params.putString(URLDecoder.decode(item[0], Constants.UTF_8),
                        URLDecoder.decode(item[1], Constants.UTF_8));
            } catch (UnsupportedEncodingException e) {
                Log.e(Constants.LOG_TAG, "Unsupported encoding: " + e.toString());
            }//from w  w  w . j  a v  a  2s .  c o m
        }
    }

    return params;
}

From source file:Main.java

public static Bundle decodeUrl(String query) {
    Bundle ret = new Bundle();
    if (query != null) {
        String[] pairs = query.split("&");
        for (String pair : pairs) {
            String[] keyAndValues = pair.split("=");
            if (keyAndValues != null && keyAndValues.length == 2) {
                String key = keyAndValues[0];
                String value = keyAndValues[1];
                if (!isEmpty(key) && !isEmpty(value)) {
                    ret.putString(URLDecoder.decode(key), URLDecoder.decode(value));
                }/*from ww w  .  j a  va2  s.  com*/
            }
        }
    }
    return ret;
}

From source file:Main.java

public static ResponseHandler<String> GetResponseHandlerInstance(final Handler handler) {
    final ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
        @Override// ww  w . jav a  2  s .  c  o  m
        public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
            Message message = handler.obtainMessage();
            Bundle bundle = new Bundle();
            StatusLine status = response.getStatusLine();
            HttpEntity entity = response.getEntity();
            String result = null;
            if (entity != null) {
                try {
                    result = InputStreamToString(entity.getContent());
                    bundle.putString("RESPONSE", result);
                    message.setData(bundle);
                    handler.sendMessage(message);
                } catch (IOException e) {
                    bundle.putString("RESPONSE", "Error - " + e.getMessage());
                    message.setData(bundle);
                    handler.sendMessage(message);
                }
            } else {
                bundle.putString("RESPONSE", "Error - " + response.getStatusLine().getReasonPhrase());
                message.setData(bundle);
                handler.sendMessage(message);
            }
            return result;
        }
    };

    return responseHandler;
}

From source file:net.neoturbine.autolycus.internal.BusTimeAPI.java

/**
 * Retrieves the list of directions for a given route in a system.
 * //from w  ww.j  av  a2 s  .  c o m
 * @param context
 *            Currently unused, but needed for analytics.
 * @param system
 *            One of the internally supported transit systems.
 * @param route
 *            the route designator to see supported directions.
 * @return an ArrayList containing the directions as strings.
 * @throws BusTimeError
 *             indicating the API returned an error
 * @throws Exception
 */
public static ArrayList<String> getDirections(Context context, String system, String route) throws Exception {
    // we don't check the date of the cache since we're going to assume
    // the route directions will never ever ever change
    // Bad assumption? we'll see
    ArrayList<String> directions = new ArrayList<String>();
    Bundle params = new Bundle();
    params.putString("rt", route);
    XmlPullParser xpp = BusTimeAPI.loadData(context, "getdirections", system, params);
    int eventType = xpp.getEventType();
    String curTag = "";
    BusTimeError err = null;
    while (eventType != XmlPullParser.END_DOCUMENT) {
        switch (eventType) {
        case XmlPullParser.START_TAG:
            curTag = xpp.getName();
            if (curTag.equals("dir")) { // on to new route
                // nothing yet
            } else if (curTag.equals("error"))
                err = new BusTimeError();
            break;
        case XmlPullParser.TEXT:
            String text = xpp.getText().trim();
            if (!curTag.equals("") && !text.equals("")) {
                if (err != null)
                    err.setField(curTag, text);
                else {
                    if (text.equals("Westbound"))
                        directions.add("West bound");
                    else if (text.equals("Eastbound"))
                        directions.add("East bound");
                    else
                        directions.add(text);
                }
            }
            break;
        case XmlPullParser.END_TAG:
            curTag = "";
            break;
        }
        eventType = xpp.next();
    }
    if (err != null)
        throw err;
    return directions;
}

From source file:net.neoturbine.autolycus.internal.BusTimeAPI.java

public static ArrayList<ServiceBulletin> getServiceBulletinsContext(Context context, String system,
        String stopID, String route) throws Exception {
    ArrayList<ServiceBulletin> sbs = new ArrayList<ServiceBulletin>();
    Bundle params = new Bundle();
    params.putString("stpid", stopID);
    params.putString("rt", route);
    ServiceBulletinBuilder curBuilder = new ServiceBulletinBuilder();
    XmlPullParser xpp = BusTimeAPI.loadData(context, "getservicebulletins", system, params);
    int eventType = xpp.getEventType();
    String curTag = "";
    BusTimeError err = null;//from w  w w .  j  a v  a 2 s.com
    while (eventType != XmlPullParser.END_DOCUMENT) {
        switch (eventType) {
        case XmlPullParser.START_TAG:
            curTag = xpp.getName();
            if (curTag.equals("sb")) {
                if (curBuilder.isSet()) {
                    sbs.add(curBuilder.toBulletin());
                }
                curBuilder = new ServiceBulletinBuilder();
            } else if (curTag.equals("error")) {
                err = new BusTimeError();
            }
            break;
        case XmlPullParser.TEXT:
            String text = xpp.getText().trim();
            if (!curTag.equals("") && !text.equals("")) {
                if (err != null)
                    err.setField(curTag, text);
                else {
                    curBuilder.setField(curTag, text);
                }
            }
            break;
        case XmlPullParser.END_TAG:
            curTag = "";
            break;
        }
        eventType = xpp.next(); // moving on....
    }
    if (err != null)
        throw err;

    if (curBuilder.isSet())
        sbs.add(curBuilder.toBulletin());
    return sbs;
}

From source file:com.nextgis.mobile.map.LocalGeoJsonLayer.java

protected static void create(final MapBase map, String layerName, List<Feature> features, int layerType)
        throws JSONException, IOException {

    GeoEnvelope extents = new GeoEnvelope();
    for (Feature feature : features) {
        //update bbox
        extents.merge(feature.getGeometry().getEnvelope());
    }//w ww  . j  av a 2  s.c om

    Feature feature = features.get(0);
    int geometryType = feature.getGeometry().getType();
    List<Field> fields = feature.getFields();

    //create layer description file
    JSONObject oJSONRoot = new JSONObject();
    oJSONRoot.put(JSON_NAME_KEY, layerName);
    oJSONRoot.put(JSON_VISIBILITY_KEY, true);
    oJSONRoot.put(JSON_TYPE_KEY, layerType);
    oJSONRoot.put(JSON_MAXLEVEL_KEY, 50);
    oJSONRoot.put(JSON_MINLEVEL_KEY, 0);

    //add geometry type
    oJSONRoot.put(JSON_GEOMETRY_TYPE_KEY, geometryType);

    //add bbox
    JSONObject oJSONBBox = extents.toJSON();
    oJSONRoot.put(JSON_BBOX_KEY, oJSONBBox);

    //add fields description
    JSONArray oJSONFields = new JSONArray();
    for (Field field : fields) {
        oJSONFields.put(field.toJSON());
    }
    oJSONRoot.put(JSON_FIELDS_KEY, oJSONFields);

    // store layer description to file
    File outputPath = map.cretateLayerStorage();
    File file = new File(outputPath, LAYER_CONFIG);
    FileUtil.createDir(outputPath);
    FileUtil.writeToFile(file, oJSONRoot.toString());

    //store GeoJson to file
    store(features, outputPath);

    if (map.getMapEventsHandler() != null) {
        Bundle bundle = new Bundle();
        bundle.putBoolean(BUNDLE_HASERROR_KEY, false);
        bundle.putString(BUNDLE_MSG_KEY, map.getContext().getString(R.string.message_layer_added));
        bundle.putInt(BUNDLE_TYPE_KEY, MSGTYPE_LAYER_ADDED);
        bundle.putSerializable(BUNDLE_PATH_KEY, outputPath);

        Message msg = new Message();
        msg.setData(bundle);
        map.getMapEventsHandler().sendMessage(msg);
    }
}

From source file:me.gpelaez.cordova.plugins.ibeacon.GPIBeacon.java

/**
 * + * Issues a notification to inform the user that server has sent a
 * message. +/*from w ww  . j ava2 s.  c  o  m*/
 * @throws JSONException 
 */
@SuppressLint("InlinedApi")
private static void createNotification(Context context, JSONObject json) throws JSONException {
    Bundle extra = new Bundle();
    extra.putString("json", json.toString());

    Intent notificationIntent = new Intent(activity, BeaconNotificationHandler.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("beacon", extra);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setDefaults(Notification.DEFAULT_ALL).setSmallIcon(context.getApplicationInfo().icon)
            .setWhen(System.currentTimeMillis()).setTicker(json.getString("title"))
            .setContentTitle(json.getString("message")).setContentIntent(contentIntent);

    String message = json.getString("message");
    if (message != null) {
        mBuilder.setContentText(message);
    } else {
        mBuilder.setContentText("<missing message content>");
    }
    mBuilder.addAction(context.getApplicationInfo().icon, json.getString("message"), contentIntent);

    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
            .notify((String) getAppName(context), NOTIFICATION_ID, mBuilder.build());
}

From source file:net.neoturbine.autolycus.internal.BusTimeAPI.java

/**
 * Retrieves the arrival time predictions for the given Stop ID in a given
 * transit system./*from  w  w  w.  ja  v a  2s.  c  om*/
 * 
 * @see Prediction
 * @param context
 *            Currently unused, but needed for analytics.
 * @param system
 *            One of the internally supported transit systems.
 * @param stopID
 *            the string containing the direction returned by the API.
 * @param route
 *            optionally limit the predictions at this stop for a this
 *            route.
 * @return an ArrayList of all predictions returned by the API. May be empty
 *         with no error if there is no predictions at this time.
 * @throws BusTimeError
 *             indicating the API returned an error
 * @throws Exception
 */
public static ArrayList<Prediction> getPrediction(Context context, String system, String stopID, String route,
        String timeZone) throws Exception {
    ArrayList<Prediction> preds = new ArrayList<Prediction>();
    Bundle params = new Bundle();
    params.putString("stpid", stopID);
    if (route != null)
        params.putString("rt", route);
    PredictionBuilder curBuilder = new PredictionBuilder(timeZone);
    XmlPullParser xpp = BusTimeAPI.loadData(context, "getpredictions", system, params);
    int eventType = xpp.getEventType();
    String curTag = "";
    BusTimeError err = null;
    while (eventType != XmlPullParser.END_DOCUMENT) {
        switch (eventType) {
        case XmlPullParser.START_TAG:
            curTag = xpp.getName();
            if (curTag.equals("prd")) { // on to new prediction
                if (curBuilder.isSet()) {
                    preds.add(curBuilder.toPrediction());
                }
                curBuilder = new PredictionBuilder(timeZone);
            } else if (curTag.equals("error")) {
                err = new BusTimeError();
            }
            break;
        case XmlPullParser.TEXT:
            String text = xpp.getText().trim();
            if (!curTag.equals("") && !text.equals("")) {
                if (err != null)
                    err.setField(curTag, text);
                else {
                    if (text.equals("Eastbound"))
                        curBuilder.setField(curTag, "East bound");
                    else if (text.equals("Westbound"))
                        curBuilder.setField(curTag, "West bound");
                    else
                        curBuilder.setField(curTag, text);
                }
            }
            break;
        case XmlPullParser.END_TAG:
            curTag = "";
            break;
        }
        eventType = xpp.next(); // moving on....
    }
    if (err != null)
        throw err;

    if (curBuilder.isSet())
        preds.add(curBuilder.toPrediction());
    return preds;
}

From source file:net.neoturbine.autolycus.internal.BusTimeAPI.java

/**
 * Retrieves the list of stops for a given route and direction in a system.
 * //  w  w w  . j a va2  s.  c  o  m
 * @see StopInfo
 * @param context
 *            Currently unused, but needed for analytics.
 * @param system
 *            One of the internally supported transit systems.
 * @param route
 *            the route designator.
 * @param direction
 *            the string containing the direction returned by the API.
 * @return an ArrayList of StopInfo objects for each stop.
 * @throws BusTimeError
 *             indicating the API returned an error.
 * @throws Exception
 */
public static ArrayList<StopInfo> getStops(Context context, String system, String route, String direction)
        throws Exception {
    ArrayList<StopInfo> stops = new ArrayList<StopInfo>();
    Bundle params = new Bundle();
    params.putString("rt", route);
    params.putString("dir", direction);
    XmlPullParser xpp = BusTimeAPI.loadData(context, "getstops", system, params);
    int eventType = xpp.getEventType();
    String curTag = "";
    StopInfoBuilder curBuilder = new StopInfoBuilder(system);
    BusTimeError err = null;
    while (eventType != XmlPullParser.END_DOCUMENT) {
        switch (eventType) {
        case XmlPullParser.START_TAG:
            curTag = xpp.getName();
            if (curTag.equals("stop")) { // on to new route
                if (curBuilder.getName() != null) { // finished a route
                    stops.add(curBuilder.toStopInfo());
                }
                curBuilder = new StopInfoBuilder(system);
                curBuilder.setRoute(route); // do these get overriden?
                curBuilder.setDir(direction); // ditto?
            } else if (curTag.equals("error"))
                err = new BusTimeError();
            break;
        case XmlPullParser.TEXT:
            String text = xpp.getText().trim();
            if (!curTag.equals("") && !text.equals("")) {
                if (err != null) {
                    err.setField(curTag, text);
                } else {
                    if (text.equals("Eastbound"))
                        curBuilder.setField(curTag, "East bound");
                    else if (text.equals("Westbound"))
                        curBuilder.setField(curTag, "West bound");
                    else
                        curBuilder.setField(curTag, text);
                }
            }
            break;
        case XmlPullParser.END_TAG:
            curTag = "";
            break;
        }
        eventType = xpp.next();
    }

    if (err != null)
        throw err;

    if (curBuilder.getName() != null)
        stops.add(curBuilder.toStopInfo());

    return stops;
}