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:br.liveo.ndrawer.ui.fragment.MainFragment22.java

public static MainFragment22 newInstance(String text) {
    MainFragment22 mFragment = new MainFragment22();
    Bundle mBundle = new Bundle();
    mBundle.putString(TEXT_FRAGMENT, text);
    mFragment.setArguments(mBundle);//from  ww  w  . j a v a2 s . c o  m
    return mFragment;
}

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);/*from   w  ww .  j  a  v  a  2s. c  o  m*/

    return f;
}

From source file:com.miz.mizuu.fragments.RelatedMoviesFragment.java

public static RelatedMoviesFragment newInstance(String tmdbId, boolean setBackground, String json,
        String baseUrl) {/*ww w .j a  v a2  s .  c o  m*/
    RelatedMoviesFragment pageFragment = new RelatedMoviesFragment();
    Bundle bundle = new Bundle();
    bundle.putString("tmdbId", tmdbId);
    bundle.putBoolean("setBackground", setBackground);
    bundle.putString("json", json);
    bundle.putString("baseUrl", baseUrl);
    pageFragment.setArguments(bundle);
    return pageFragment;
}

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

public static SearchFragment newInstance(int position, String screen) {
    SearchFragment fragment = new SearchFragment();
    Bundle args = new Bundle();
    args.putInt(Constants.POSITION, position);
    args.putString(Constants.SCREEN, screen);
    fragment.setArguments(args);/*from   ww  w .ja  v  a 2 s .  co  m*/
    return fragment;
}

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

public static ExploreFragment newInstance(int position, String screen) {
    ExploreFragment fragment = new ExploreFragment();
    Bundle args = new Bundle();
    args.putInt(Constants.POSITION, position);
    args.putString(Constants.SCREEN, screen);
    fragment.setArguments(args);//from   www  . ja v  a 2s  .c  o  m
    return fragment;
}

From source file:com.seregil13.literarytracker.lightnovel.LightNovelEditFragment.java

/**
 * Creates a new instance of the fragment in edit mode with all the pertinent data passed in as
 * parameters.//ww w .j  ava 2 s.  c  om
 *
 * @return An instance of LightNovelEditFragment.
 */
public static LightNovelEditFragment newEditInstance(int id, String title, String author, String description,
        String completed, String translatorSite, ArrayList<String> genres) {
    LightNovelEditFragment fragment = new LightNovelEditFragment();
    Bundle arguments = new Bundle();
    arguments.putInt(JsonKeys.ID.toString(), id);
    arguments.putString(JsonKeys.TITLE.toString(), title);
    arguments.putString(JsonKeys.AUTHOR.toString(), author);
    arguments.putString(JsonKeys.DESCRIPTION.toString(), description);
    arguments.putString(JsonKeys.COMPLETED.toString(), completed);
    arguments.putString(JsonKeys.TRANSLATOR_SITE.toString(), translatorSite);
    arguments.putStringArrayList(JsonKeys.GENRES.toString(), genres);
    arguments.putSerializable(CREATE_OR_EDIT_KEY, Mode.EDIT);

    fragment.setArguments(arguments);
    return fragment;
}

From source file:com.catchoom.api.CatchoomSearchResponseItem.java

/**
 * Parse a {@link CatchoomSearchResponseItem} from a {@link JSONObject}.  
 * @param json The json to parse./*from w  ww  .  j av  a 2s.c om*/
 * @return The {@link CatchoomSearchResponseItem} parsed.
 */
static CatchoomSearchResponseItem parseFromJSON(JSONObject json) {

    try {

        if (json.has("item_id") && json.has("score")) {
            String parsedItemId = json.getString("item_id");
            int parsedScore = json.getInt("score");

            JSONObject rawMetadata = json.getJSONObject("metadata");
            Bundle parsedMetadata = new Bundle();

            if (null != rawMetadata) {
                Iterator<?> metadataKeys = rawMetadata.keys();

                while (metadataKeys.hasNext()) {
                    String key = (String) metadataKeys.next();
                    parsedMetadata.putString(key, rawMetadata.getString(key));
                }
            }

            return new CatchoomSearchResponseItem(parsedItemId, parsedScore, parsedMetadata);
        } else {
            return null;
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:com.ymt.demo1.plates.hub.MyHubFragment.java

public static MyHubFragment getInstance(String myHubItemType, HubReplyPostCountGetter countGetter) {
    MyHubFragment.countGetter = countGetter;

    MyHubFragment fragment = new MyHubFragment();
    Bundle bundle = new Bundle();
    bundle.putString("type", myHubItemType);
    fragment.setArguments(bundle);/*from w ww. j av a2 s  .  c  o  m*/
    return fragment;
}

From source file:jp.sonymusicstudio.cast.castcompanionlibrary.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>
 *///from   ww  w .  ja  va2 s. c om
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(MediaMetadata.KEY_ALBUM_TITLE, md.getString(MediaMetadata.KEY_ALBUM_TITLE));
    wrapper.putString(MediaMetadata.KEY_ALBUM_ARTIST, md.getString(MediaMetadata.KEY_ALBUM_ARTIST));
    wrapper.putString(MediaMetadata.KEY_COMPOSER, md.getString(MediaMetadata.KEY_COMPOSER));
    wrapper.putString(MediaMetadata.KEY_SERIES_TITLE, md.getString(MediaMetadata.KEY_SERIES_TITLE));
    wrapper.putString(MediaMetadata.KEY_SEASON_NUMBER, md.getString(MediaMetadata.KEY_SEASON_NUMBER));
    wrapper.putString(MediaMetadata.KEY_EPISODE_NUMBER, md.getString(MediaMetadata.KEY_EPISODE_NUMBER));

    Calendar releaseCalender = md.getDate(MediaMetadata.KEY_RELEASE_DATE);
    if (releaseCalender != null) {
        long releaseMillis = releaseCalender.getTimeInMillis();
        wrapper.putLong(MediaMetadata.KEY_RELEASE_DATE, releaseMillis);
    }

    wrapper.putInt(KEY_MEDIA_TYPE, info.getMetadata().getMediaType());
    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:m2.android.archetype.example.FacebookSdk.Settings.java

/**
 * Manually publish install attribution to the Facebook graph.  Internally handles tracking repeat calls to prevent
 * multiple installs being published to the graph.
 * @param context the current Context/*from  w  ww.  j  a  va 2 s . co  m*/
 * @return returns false on error.  Applications should retry until true is returned.  Safe to call again after
 * true is returned.
 */
public static boolean publishInstallAndWait(final Context context, final String applicationId) {
    try {
        if (applicationId == null) {
            return false;
        }
        String attributionId = Settings.getAttributionId(context.getContentResolver());
        SharedPreferences preferences = context.getSharedPreferences(ATTRIBUTION_PREFERENCES,
                Context.MODE_PRIVATE);
        String pingKey = applicationId + "ping";
        long lastPing = preferences.getLong(pingKey, 0);
        if (lastPing == 0 && attributionId != null) {
            Bundle supportsAttributionParams = new Bundle();
            supportsAttributionParams.putString(APPLICATION_FIELDS, SUPPORTS_ATTRIBUTION);
            Request pingRequest = Request.newGraphPathRequest(null, applicationId, null);
            pingRequest.setParameters(supportsAttributionParams);

            GraphObject supportResponse = pingRequest.executeAndWait().getGraphObject();
            Object doesSupportAttribution = supportResponse.getProperty(SUPPORTS_ATTRIBUTION);

            if (!(doesSupportAttribution instanceof Boolean)) {
                throw new JSONException(String.format("%s contains %s instead of a Boolean",
                        SUPPORTS_ATTRIBUTION, doesSupportAttribution));
            }

            if ((Boolean) doesSupportAttribution) {
                GraphObject publishParams = GraphObject.Factory.create();
                publishParams.setProperty(ANALYTICS_EVENT, MOBILE_INSTALL_EVENT);
                publishParams.setProperty(ATTRIBUTION_KEY, attributionId);

                String publishUrl = String.format(PUBLISH_ACTIVITY_PATH, applicationId);

                Request publishRequest = Request.newPostRequest(null, publishUrl, publishParams, null);
                publishRequest.executeAndWait();

                // denote success since no error threw from the post.
                SharedPreferences.Editor editor = preferences.edit();
                lastPing = System.currentTimeMillis();
                editor.putLong(pingKey, lastPing);
                editor.commit();
            }
        }
        return lastPing != 0;
    } catch (Exception e) {
        // if there was an error, fall through to the failure case.
        Utility.logd("Facebook-publish", e.getMessage());
    }
    return false;
}