List of usage examples for android.os Bundle putLong
public void putLong(@Nullable String key, long value)
From source file:com.nttec.everychan.ui.BoardsListFragment.java
public static BoardsListFragment newInstance(long tabId) { TabsState tabsState = MainApplication.getInstance().tabsState; if (tabsState == null) throw new IllegalStateException("tabsState was not initialized in the MainApplication singleton"); TabModel model = tabsState.findTabById(tabId); if (model == null) throw new IllegalArgumentException("cannot find tab with id " + tabId); if (model.pageModel.type != UrlPageModel.TYPE_INDEXPAGE) { throw new IllegalArgumentException( "pageModel.type != INDEXPAGE (this fragment can show only boardslists)"); }// w w w . j av a2 s. com BoardsListFragment fragment = new BoardsListFragment(); Bundle args = new Bundle(1); args.putLong("TabModelId", tabId); fragment.setArguments(args); return fragment; }
From source file:com.akop.bach.fragment.xboxlive.AchievementsFragment.java
public static AchievementsFragment newInstance(XboxLiveAccount account, long titleId, boolean showGameTotals) { AchievementsFragment f = new AchievementsFragment(); Bundle args = new Bundle(); args.putParcelable("account", account); args.putLong("titleId", titleId); args.putBoolean("showGameTotals", showGameTotals); f.setArguments(args);/*from ww w .ja v a 2 s .c o m*/ return f; }
From source file:Main.java
public static Intent mapToIntent(Context context, Class<?> clazz, Map<String, Object> map) { Intent intent = new Intent(context, clazz); Bundle bundle = new Bundle(); if (map != null && map.size() > 0) { for (String key : map.keySet()) { if (map.get(key) instanceof String) { bundle.putString(key, (String) map.get(key)); } else if (map.get(key) instanceof Integer) { bundle.putInt(key, (Integer) map.get(key)); } else if (map.get(key) instanceof Boolean) { bundle.putBoolean(key, (Boolean) map.get(key)); } else if (map.get(key) instanceof Double) { bundle.putDouble(key, (Double) map.get(key)); } else if (map.get(key) instanceof Long) { bundle.putLong(key, (Long) map.get(key)); } else if (map.get(key) instanceof Float) { bundle.putFloat(key, (Float) map.get(key)); } else if (map.get(key) instanceof Double) { bundle.putDouble(key, (Double) map.get(key)); } else if (map.get(key) instanceof Serializable) { bundle.putSerializable(key, (Serializable) map.get(key)); } else if (map.get(key) instanceof Parcelable) { bundle.putParcelable(key, (Parcelable) map.get(key)); }/*from w w w. ja v a 2 s.c o m*/ } } return intent.putExtras(bundle); }
From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.ui.list.TaskListFragment.java
public static TaskListFragment getInstance(final long listId) { TaskListFragment f = new TaskListFragment(); Bundle args = new Bundle(); args.putLong(LIST_ID, listId); f.setArguments(args);/*from www.ja v a2 s. com*/ return f; }
From source file:bikebadger.RideFragment.java
public static RideFragment newInstance(long runId) { Log.d(Constants.APP.TAG, "RideFragment::newInstance"); Bundle args = new Bundle(); args.putLong(ARG_RUN_ID, runId); RideFragment rf = new RideFragment(); rf.setArguments(args);//from w w w. j a va 2 s . c om return rf; }
From source file:Main.java
/** * //from w w w. j a v 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.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 om*/ * @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> *//*from w w w . j av a 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:com.google.sample.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. * * @param info/*from www . j av a2s.c om*/ * @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()); } 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()); jsonObject.put(KEY_TRACK_SUBTYPE, mt.getSubtype()); if (null != mt.getCustomData()) { jsonObject.put(KEY_TRACK_CUSTOM_DATA, mt.getCustomData().toString()); } jsonArray.put(jsonObject); } wrapper.putString(KEY_TRACKS_DATA, jsonArray.toString()); } catch (JSONException e) { LOGE(TAG, "fromMediaInfo(): Failed to convert Tracks data to json", e); } } return wrapper; }
From source file:com.nadmm.airports.utils.NetworkUtils.java
public static boolean doHttpGet(Context context, URL url, File file, ResultReceiver receiver, Bundle result, Class<? extends FilterInputStream> filter) throws Exception { if (!NetworkUtils.isNetworkAvailable(context)) { return false; }// ww w . ja v a 2 s . com if (receiver != null && result == null) { throw new Exception("Result cannot be null when receiver is passed"); } InputStream f = null; CountingInputStream in = null; OutputStream out = null; try { HttpURLConnection conn = (HttpURLConnection) url.openConnection(); int status = conn.getResponseCode(); if (status != HttpURLConnection.HTTP_OK) { if (receiver != null) { // Signal the receiver that download is aborted result.putLong(CONTENT_LENGTH, 0); result.putLong(CONTENT_PROGRESS, 0); receiver.send(2, result); } throw new Exception(conn.getResponseMessage()); } long length = conn.getContentLength(); if (receiver != null) { result.putLong(CONTENT_LENGTH, length); } out = new FileOutputStream(file); in = new CountingInputStream(conn.getInputStream()); if (filter != null) { @SuppressWarnings("unchecked") Constructor<FilterInputStream> ctor = (Constructor<FilterInputStream>) filter .getConstructor(InputStream.class); f = ctor.newInstance(in); } else { f = in; } long chunk = Math.max(length / 100, 16 * 1024); long last = 0; int count; while ((count = f.read(sBuffer)) != -1) { out.write(sBuffer, 0, count); if (receiver != null) { long current = in.getCount(); long delta = current - last; if (delta >= chunk) { result.putLong(CONTENT_PROGRESS, current); receiver.send(0, result); last = current; } } } if (receiver != null) { // If compressed, the filter stream may not read the entire source stream result.putLong(CONTENT_PROGRESS, length); receiver.send(1, result); } } finally { try { if (f != null) { f.close(); } if (out != null) { out.close(); } } catch (IOException ignored) { } } return true; }