Example usage for android.os Bundle putInt

List of usage examples for android.os Bundle putInt

Introduction

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

Prototype

public void putInt(@Nullable String key, int value) 

Source Link

Document

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

Usage

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());
    }/*from   w ww  .  j  a va2  s  . com*/

    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: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.mifos.mifosxdroid.online.grouploanaccount.GroupLoanAccountFragment.java

public static GroupLoanAccountFragment newInstance(int groupId) {
    GroupLoanAccountFragment grouploanAccountFragment = new GroupLoanAccountFragment();
    Bundle args = new Bundle();
    args.putInt(Constants.GROUP_ID, groupId);
    grouploanAccountFragment.setArguments(args);
    return grouploanAccountFragment;
}

From source file:com.spoiledmilk.ibikecph.util.HttpUtils.java

public static Message JSONtoMessage(JsonNode result) {
    Message ret = new Message();
    Bundle data = new Bundle();
    if (result != null) {
        data.putBoolean("success", result.get("success").asBoolean());
        data.putString("info", result.get("info").asText());
        if (result.has("errors"))
            data.putString("errors", result.get("errors").asText());
        JsonNode dataNode = result.get("data");
        if (dataNode != null) {
            if (dataNode.has("id"))
                data.putInt("id", dataNode.get("id").asInt());
            if (dataNode.has("auth_token"))
                data.putString("auth_token", dataNode.get("auth_token").asText());
        }//from w w w  .j  a v a 2s.  c  om
    }
    ret.setData(data);
    return ret;
}

From source file:fr.cph.chicago.fragment.NearbyFragment.java

/**
 * Returns a new instance of this fragment for the given section number.
 * /*from   w  w w.j  a v a2 s. c  o  m*/
 * @param sectionNumber
 * @return
 */
public static NearbyFragment newInstance(final int sectionNumber) {
    NearbyFragment fragment = new NearbyFragment();
    Bundle args = new Bundle();
    args.putInt(ARG_SECTION_NUMBER, sectionNumber);
    fragment.setArguments(args);
    return fragment;
}

From source file:com.mifos.mifosxdroid.online.ClientDetailsFragment.java

/**
 * Use this factory method to create a new instance of
 * this fragment using the provided parameters.
 *
 * @param clientId Client's Id//from  w w w .jav a2s . c o m
 */
public static ClientDetailsFragment newInstance(int clientId) {
    ClientDetailsFragment fragment = new ClientDetailsFragment();
    Bundle args = new Bundle();
    args.putInt(Constants.CLIENT_ID, clientId);
    fragment.setArguments(args);
    return fragment;
}

From source file:Main.java

/**
 *  /*from   w  ww.j  a  v  a2  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.mb.android.playbackmediator.utils.Utils.java

/**
 * Builds and returns a {@link android.os.Bundle} which contains a select subset of data in the
 * {@link MediaInfo}. Since {@link MediaInfo} is not {@link android.os.Parcelable}, one can use this
 * container bundle to pass around from one activity to another.
 *
 * @param info//from  ww  w  .jav  a 2 s  . c  o m
 * @return
 * @see <code>toMediaInfo()</code>
 */
public static Bundle fromMediaInfo(MediaInfo info) {
    if (null == info) {
        return null;
    }

    MediaMetadata md = info.getMetadata();
    Bundle wrapper = new Bundle();
    wrapper.putString(MediaMetadata.KEY_TITLE, md.getString(MediaMetadata.KEY_TITLE));
    wrapper.putString(MediaMetadata.KEY_SUBTITLE, md.getString(MediaMetadata.KEY_SUBTITLE));
    wrapper.putString(KEY_URL, info.getContentId());
    wrapper.putString(MediaMetadata.KEY_STUDIO, md.getString(MediaMetadata.KEY_STUDIO));
    wrapper.putString(KEY_CONTENT_TYPE, info.getContentType());
    wrapper.putInt(KEY_STREAM_TYPE, info.getStreamType());
    wrapper.putLong(KEY_STREAM_DURATION, info.getStreamDuration());
    if (!md.getImages().isEmpty()) {
        ArrayList<String> urls = new ArrayList<String>();
        for (WebImage img : md.getImages()) {
            urls.add(img.getUrl().toString());
        }
        wrapper.putStringArrayList(KEY_IMAGES, urls);
    }
    JSONObject customData = info.getCustomData();
    if (null != customData) {
        wrapper.putString(KEY_CUSTOM_DATA, customData.toString());
    }

    return wrapper;
}

From source file:com.google.android.libraries.cast.companionlibrary.utils.Utils.java

/**
 * Builds and returns a {@link Bundle} which contains a select subset of data in the
 * {@link MediaInfo}. Since {@link MediaInfo} is not {@link Parcelable}, one can use this
 * container bundle to pass around from one activity to another.
 *
 * @see <code>bundleToMediaInfo()</code>
 *//*  w ww  . ja  va 2 s . co  m*/
public static Bundle mediaInfoToBundle(MediaInfo info) {
    if (info == null) {
        return null;
    }

    MediaMetadata md = info.getMetadata();
    Bundle wrapper = new Bundle();
    wrapper.putString(MediaMetadata.KEY_TITLE, md.getString(MediaMetadata.KEY_TITLE));
    wrapper.putString(MediaMetadata.KEY_SUBTITLE, md.getString(MediaMetadata.KEY_SUBTITLE));
    wrapper.putString(KEY_URL, info.getContentId());
    wrapper.putString(MediaMetadata.KEY_STUDIO, md.getString(MediaMetadata.KEY_STUDIO));
    wrapper.putString(KEY_CONTENT_TYPE, info.getContentType());
    wrapper.putInt(KEY_STREAM_TYPE, info.getStreamType());
    wrapper.putLong(KEY_STREAM_DURATION, info.getStreamDuration());
    if (!md.getImages().isEmpty()) {
        ArrayList<String> urls = new ArrayList<>();
        for (WebImage img : md.getImages()) {
            urls.add(img.getUrl().toString());
        }
        wrapper.putStringArrayList(KEY_IMAGES, urls);
    }
    JSONObject customData = info.getCustomData();
    if (customData != null) {
        wrapper.putString(KEY_CUSTOM_DATA, customData.toString());
    }
    if (info.getMediaTracks() != null && !info.getMediaTracks().isEmpty()) {
        try {
            JSONArray jsonArray = new JSONArray();
            for (MediaTrack mt : info.getMediaTracks()) {
                JSONObject jsonObject = new JSONObject();
                jsonObject.put(KEY_TRACK_NAME, mt.getName());
                jsonObject.put(KEY_TRACK_CONTENT_ID, mt.getContentId());
                jsonObject.put(KEY_TRACK_ID, mt.getId());
                jsonObject.put(KEY_TRACK_LANGUAGE, mt.getLanguage());
                jsonObject.put(KEY_TRACK_TYPE, mt.getType());
                if (mt.getSubtype() != MediaTrack.SUBTYPE_UNKNOWN) {
                    jsonObject.put(KEY_TRACK_SUBTYPE, mt.getSubtype());
                }
                if (mt.getCustomData() != null) {
                    jsonObject.put(KEY_TRACK_CUSTOM_DATA, mt.getCustomData().toString());
                }
                jsonArray.put(jsonObject);
            }
            wrapper.putString(KEY_TRACKS_DATA, jsonArray.toString());
        } catch (JSONException e) {
            LOGE(TAG, "mediaInfoToBundle(): Failed to convert Tracks data to json", e);
        }
    }

    return wrapper;
}

From source file:org.openhab.habdroid.ui.OpenHABWidgetListFragment.java

public static OpenHABWidgetListFragment withPage(String pageUrl, String baseUrl, String rootUrl,
        String username, String password, int position) {
    Log.d(TAG, "withPage(" + pageUrl + ")");
    OpenHABWidgetListFragment fragment = new OpenHABWidgetListFragment();
    Bundle args = new Bundle();
    args.putString("displayPageUrl", pageUrl);
    args.putString("openHABBaseUrl", baseUrl);
    args.putString("sitemapRootUrl", rootUrl);
    args.putString("openHABUsername", username);
    args.putString("openHABPassword", password);
    args.putInt("position", position);
    fragment.setArguments(args);//  w  w w.  ja  va 2 s.c  om
    return fragment;
}