List of usage examples for android.os Bundle getLong
public long getLong(String key)
From source file:com.androzic.MapActivity.java
@Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); Log.e(TAG, "onRestoreInstanceState()"); lastKnownLocation = savedInstanceState.getParcelable("lastKnownLocation"); lastRenderTime = savedInstanceState.getLong("lastRenderTime"); lastMagnetic = savedInstanceState.getLong("lastMagnetic"); lastDim = savedInstanceState.getLong("lastDim"); lastGeoid = savedInstanceState.getBoolean("lastGeoid"); waypointSelected = savedInstanceState.getInt("waypointSelected"); routeSelected = savedInstanceState.getInt("routeSelected"); mapObjectSelected = savedInstanceState.getLong("mapObjectSelected"); /*/*www.jav a 2 s. co m*/ * double[] distAncor = savedInstanceState.getDoubleArray("distAncor"); * if (distAncor != null) * { * application.distanceOverlay = new DistanceOverlay(this); * application.distanceOverlay.setAncor(distAncor); * } */ }
From source file:androidx.media.MediaSession2StubImplBase.java
@Override public void onCommand(String command, final Bundle extras, final ResultReceiver cb) { switch (command) { case CONTROLLER_COMMAND_CONNECT: connect(extras, cb);// w ww .j a v a2 s. c o m break; case CONTROLLER_COMMAND_DISCONNECT: disconnect(extras); break; case CONTROLLER_COMMAND_BY_COMMAND_CODE: { final int commandCode = extras.getInt(ARGUMENT_COMMAND_CODE); IMediaControllerCallback caller = (IMediaControllerCallback) extras .getBinder(ARGUMENT_ICONTROLLER_CALLBACK); if (caller == null) { return; } onCommand2(caller.asBinder(), commandCode, new Session2Runnable() { @Override public void run(ControllerInfo controller) { switch (commandCode) { case COMMAND_CODE_PLAYBACK_PLAY: mSession.play(); break; case COMMAND_CODE_PLAYBACK_PAUSE: mSession.pause(); break; case COMMAND_CODE_PLAYBACK_RESET: mSession.reset(); break; case COMMAND_CODE_PLAYBACK_PREPARE: mSession.prepare(); break; case COMMAND_CODE_PLAYBACK_SEEK_TO: { long seekPos = extras.getLong(ARGUMENT_SEEK_POSITION); mSession.seekTo(seekPos); break; } case COMMAND_CODE_PLAYLIST_SET_REPEAT_MODE: { int repeatMode = extras.getInt(ARGUMENT_REPEAT_MODE); mSession.setRepeatMode(repeatMode); break; } case COMMAND_CODE_PLAYLIST_SET_SHUFFLE_MODE: { int shuffleMode = extras.getInt(ARGUMENT_SHUFFLE_MODE); mSession.setShuffleMode(shuffleMode); break; } case COMMAND_CODE_PLAYLIST_SET_LIST: { List<MediaItem2> list = MediaUtils2 .fromMediaItem2ParcelableArray(extras.getParcelableArray(ARGUMENT_PLAYLIST)); MediaMetadata2 metadata = MediaMetadata2 .fromBundle(extras.getBundle(ARGUMENT_PLAYLIST_METADATA)); mSession.setPlaylist(list, metadata); break; } case COMMAND_CODE_PLAYLIST_SET_LIST_METADATA: { MediaMetadata2 metadata = MediaMetadata2 .fromBundle(extras.getBundle(ARGUMENT_PLAYLIST_METADATA)); mSession.updatePlaylistMetadata(metadata); break; } case COMMAND_CODE_PLAYLIST_ADD_ITEM: { int index = extras.getInt(ARGUMENT_PLAYLIST_INDEX); MediaItem2 item = MediaItem2.fromBundle(extras.getBundle(ARGUMENT_MEDIA_ITEM)); mSession.addPlaylistItem(index, item); break; } case COMMAND_CODE_PLAYLIST_REMOVE_ITEM: { MediaItem2 item = MediaItem2.fromBundle(extras.getBundle(ARGUMENT_MEDIA_ITEM)); mSession.removePlaylistItem(item); break; } case COMMAND_CODE_PLAYLIST_REPLACE_ITEM: { int index = extras.getInt(ARGUMENT_PLAYLIST_INDEX); MediaItem2 item = MediaItem2.fromBundle(extras.getBundle(ARGUMENT_MEDIA_ITEM)); mSession.replacePlaylistItem(index, item); break; } case COMMAND_CODE_PLAYLIST_SKIP_TO_NEXT_ITEM: { mSession.skipToNextItem(); break; } case COMMAND_CODE_PLAYLIST_SKIP_TO_PREV_ITEM: { mSession.skipToPreviousItem(); break; } case COMMAND_CODE_PLAYLIST_SKIP_TO_PLAYLIST_ITEM: { MediaItem2 item = MediaItem2.fromBundle(extras.getBundle(ARGUMENT_MEDIA_ITEM)); mSession.skipToPlaylistItem(item); break; } case COMMAND_CODE_VOLUME_SET_VOLUME: { int value = extras.getInt(ARGUMENT_VOLUME); int flags = extras.getInt(ARGUMENT_VOLUME_FLAGS); VolumeProviderCompat vp = mSession.getVolumeProvider(); if (vp == null) { // TODO: Revisit } else { vp.onSetVolumeTo(value); } break; } case COMMAND_CODE_VOLUME_ADJUST_VOLUME: { int direction = extras.getInt(ARGUMENT_VOLUME_DIRECTION); int flags = extras.getInt(ARGUMENT_VOLUME_FLAGS); VolumeProviderCompat vp = mSession.getVolumeProvider(); if (vp == null) { // TODO: Revisit } else { vp.onAdjustVolume(direction); } break; } case COMMAND_CODE_SESSION_REWIND: { mSession.getCallback().onRewind(mSession.getInstance(), controller); break; } case COMMAND_CODE_SESSION_FAST_FORWARD: { mSession.getCallback().onFastForward(mSession.getInstance(), controller); break; } case COMMAND_CODE_SESSION_PLAY_FROM_MEDIA_ID: { String mediaId = extras.getString(ARGUMENT_MEDIA_ID); Bundle extra = extras.getBundle(ARGUMENT_EXTRAS); mSession.getCallback().onPlayFromMediaId(mSession.getInstance(), controller, mediaId, extra); break; } case COMMAND_CODE_SESSION_PLAY_FROM_SEARCH: { String query = extras.getString(ARGUMENT_QUERY); Bundle extra = extras.getBundle(ARGUMENT_EXTRAS); mSession.getCallback().onPlayFromSearch(mSession.getInstance(), controller, query, extra); break; } case COMMAND_CODE_SESSION_PLAY_FROM_URI: { Uri uri = extras.getParcelable(ARGUMENT_URI); Bundle extra = extras.getBundle(ARGUMENT_EXTRAS); mSession.getCallback().onPlayFromUri(mSession.getInstance(), controller, uri, extra); break; } case COMMAND_CODE_SESSION_PREPARE_FROM_MEDIA_ID: { String mediaId = extras.getString(ARGUMENT_MEDIA_ID); Bundle extra = extras.getBundle(ARGUMENT_EXTRAS); mSession.getCallback().onPrepareFromMediaId(mSession.getInstance(), controller, mediaId, extra); break; } case COMMAND_CODE_SESSION_PREPARE_FROM_SEARCH: { String query = extras.getString(ARGUMENT_QUERY); Bundle extra = extras.getBundle(ARGUMENT_EXTRAS); mSession.getCallback().onPrepareFromSearch(mSession.getInstance(), controller, query, extra); break; } case COMMAND_CODE_SESSION_PREPARE_FROM_URI: { Uri uri = extras.getParcelable(ARGUMENT_URI); Bundle extra = extras.getBundle(ARGUMENT_EXTRAS); mSession.getCallback().onPrepareFromUri(mSession.getInstance(), controller, uri, extra); break; } case COMMAND_CODE_SESSION_SET_RATING: { String mediaId = extras.getString(ARGUMENT_MEDIA_ID); Rating2 rating = Rating2.fromBundle(extras.getBundle(ARGUMENT_RATING)); mSession.getCallback().onSetRating(mSession.getInstance(), controller, mediaId, rating); break; } case COMMAND_CODE_SESSION_SUBSCRIBE_ROUTES_INFO: { mSession.getCallback().onSubscribeRoutesInfo(mSession.getInstance(), controller); break; } case COMMAND_CODE_SESSION_UNSUBSCRIBE_ROUTES_INFO: { mSession.getCallback().onUnsubscribeRoutesInfo(mSession.getInstance(), controller); break; } case COMMAND_CODE_SESSION_SELECT_ROUTE: { Bundle route = extras.getBundle(ARGUMENT_ROUTE_BUNDLE); mSession.getCallback().onSelectRoute(mSession.getInstance(), controller, route); break; } case COMMAND_CODE_PLAYBACK_SET_SPEED: { float speed = extras.getFloat(ARGUMENT_PLAYBACK_SPEED); mSession.setPlaybackSpeed(speed); break; } } } }); break; } case CONTROLLER_COMMAND_BY_CUSTOM_COMMAND: { final SessionCommand2 customCommand = SessionCommand2 .fromBundle(extras.getBundle(ARGUMENT_CUSTOM_COMMAND)); IMediaControllerCallback caller = (IMediaControllerCallback) extras .getBinder(ARGUMENT_ICONTROLLER_CALLBACK); if (caller == null || customCommand == null) { return; } final Bundle args = extras.getBundle(ARGUMENT_ARGUMENTS); onCommand2(caller.asBinder(), customCommand, new Session2Runnable() { @Override public void run(ControllerInfo controller) throws RemoteException { mSession.getCallback().onCustomCommand(mSession.getInstance(), controller, customCommand, args, cb); } }); break; } } }
From source file:com.xandy.calendar.AllInOneActivity.java
@Override protected void onCreate(Bundle icicle) { if (Utils.getSharedPreference(this, OtherPreferences.KEY_OTHER_1, false)) { setTheme(R.style.CalendarTheme_WithActionBarWallpaper); }/*from w w w . ja v a2 s . com*/ super.onCreate(icicle); if (icicle != null && icicle.containsKey(BUNDLE_KEY_CHECK_ACCOUNTS)) { mCheckForAccounts = icicle.getBoolean(BUNDLE_KEY_CHECK_ACCOUNTS); } // Launch add google account if this is first time and there are no // accounts yet if (mCheckForAccounts && !Utils.getSharedPreference(this, GeneralPreferences.KEY_SKIP_SETUP, false)) { mHandler = new QueryHandler(this.getContentResolver()); mHandler.startQuery(0, null, Calendars.CONTENT_URI, new String[] { Calendars._ID }, null, null /* selection args */, null /* sort order */); } // This needs to be created before setContentView mController = CalendarController.getInstance(this); // Get time from intent or icicle long timeMillis = -1; int viewType = -1; final Intent intent = getIntent(); if (icicle != null) { timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME); viewType = icicle.getInt(BUNDLE_KEY_RESTORE_VIEW, -1); } else { String action = intent.getAction(); if (Intent.ACTION_VIEW.equals(action)) { // Open EventInfo later timeMillis = parseViewAction(intent); } if (timeMillis == -1) { timeMillis = Utils.timeFromIntentInMillis(intent); } } if (viewType == -1 || viewType > ViewType.MAX_VALUE) { viewType = Utils.getViewTypeFromIntentAndSharedPref(this); } mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater); Time t = new Time(mTimeZone); t.set(timeMillis); if (DEBUG) { if (icicle != null && intent != null) { Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString()); } else { Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent); } } Resources res = getResources(); mHideString = res.getString(R.string.hide_controls); mShowString = res.getString(R.string.show_controls); mOrientation = res.getConfiguration().orientation; if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) { mControlsAnimateWidth = (int) res.getDimension(R.dimen.calendar_controls_width); if (mControlsParams == null) { mControlsParams = new LayoutParams(mControlsAnimateWidth, 0); } mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } else { // Make sure width is in between allowed min and max width values mControlsAnimateWidth = Math.max(res.getDisplayMetrics().widthPixels * 45 / 100, (int) res.getDimension(R.dimen.min_portrait_calendar_controls_width)); mControlsAnimateWidth = Math.min(mControlsAnimateWidth, (int) res.getDimension(R.dimen.max_portrait_calendar_controls_width)); } mControlsAnimateHeight = (int) res.getDimension(R.dimen.calendar_controls_height); mHideControls = !Utils.getSharedPreference(this, GeneralPreferences.KEY_SHOW_CONTROLS, true); mIsMultipane = Utils.getConfigBool(this, R.bool.multiple_pane_config); mIsTabletConfig = Utils.getConfigBool(this, R.bool.tablet_config); mShowAgendaWithMonth = Utils.getConfigBool(this, R.bool.show_agenda_with_month); mShowCalendarControls = Utils.getConfigBool(this, R.bool.show_calendar_controls); mShowEventDetailsWithAgenda = Utils.getConfigBool(this, R.bool.show_event_details_with_agenda); mShowEventInfoFullScreenAgenda = Utils.getConfigBool(this, R.bool.agenda_show_event_info_full_screen); mShowEventInfoFullScreen = Utils.getConfigBool(this, R.bool.show_event_info_full_screen); mCalendarControlsAnimationTime = res.getInteger(R.integer.calendar_controls_animation_time); Utils.setAllowWeekForDetailView(mIsMultipane); // setContentView must be called before configureActionBar setContentView(R.layout.all_in_one); if (mIsTabletConfig) { mDateRange = (TextView) findViewById(R.id.date_bar); mWeekTextView = (TextView) findViewById(R.id.week_num); } else { mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null); } // configureActionBar auto-selects the first tab you add, so we need to // call it before we set up our own fragments to make sure it doesn't // overwrite us configureActionBar(viewType); mHomeTime = (TextView) findViewById(R.id.home_time); mMiniMonth = findViewById(R.id.mini_month); if (mIsTabletConfig && mOrientation == Configuration.ORIENTATION_PORTRAIT) { mMiniMonth.setLayoutParams( new RelativeLayout.LayoutParams(mControlsAnimateWidth, mControlsAnimateHeight)); } mCalendarsList = findViewById(R.id.calendar_list); mMiniMonthContainer = findViewById(R.id.mini_month_container); mSecondaryPane = findViewById(R.id.secondary_pane); // Must register as the first activity because this activity can modify // the list of event handlers in it's handle method. This affects who // the rest of the handlers the controller dispatches to are. mController.registerFirstEventHandler(HANDLER_KEY, this); initFragments(timeMillis, viewType, icicle); // Listen for changes that would require this to be refreshed SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(this); mContentResolver = getContentResolver(); }
From source file:com.facebook.LegacyTokenCacheTest.java
@Test public void testAllTypes() { Bundle originalBundle = new Bundle(); putBoolean(BOOLEAN_KEY, originalBundle); putBooleanArray(BOOLEAN_ARRAY_KEY, originalBundle); putByte(BYTE_KEY, originalBundle);// w w w. j a v a 2 s . c om putByteArray(BYTE_ARRAY_KEY, originalBundle); putShort(SHORT_KEY, originalBundle); putShortArray(SHORT_ARRAY_KEY, originalBundle); putInt(INT_KEY, originalBundle); putIntArray(INT_ARRAY_KEY, originalBundle); putLong(LONG_KEY, originalBundle); putLongArray(LONG_ARRAY_KEY, originalBundle); putFloat(FLOAT_KEY, originalBundle); putFloatArray(FLOAT_ARRAY_KEY, originalBundle); putDouble(DOUBLE_KEY, originalBundle); putDoubleArray(DOUBLE_ARRAY_KEY, originalBundle); putChar(CHAR_KEY, originalBundle); putCharArray(CHAR_ARRAY_KEY, originalBundle); putString(STRING_KEY, originalBundle); putStringList(STRING_LIST_KEY, originalBundle); originalBundle.putSerializable(SERIALIZABLE_KEY, AccessTokenSource.FACEBOOK_APPLICATION_WEB); ensureApplicationContext(); LegacyTokenHelper cache = new LegacyTokenHelper(RuntimeEnvironment.application); cache.save(originalBundle); LegacyTokenHelper cache2 = new LegacyTokenHelper(RuntimeEnvironment.application); Bundle cachedBundle = cache2.load(); assertEquals(originalBundle.getBoolean(BOOLEAN_KEY), cachedBundle.getBoolean(BOOLEAN_KEY)); assertArrayEquals(originalBundle.getBooleanArray(BOOLEAN_ARRAY_KEY), cachedBundle.getBooleanArray(BOOLEAN_ARRAY_KEY)); assertEquals(originalBundle.getByte(BYTE_KEY), cachedBundle.getByte(BYTE_KEY)); assertArrayEquals(originalBundle.getByteArray(BYTE_ARRAY_KEY), cachedBundle.getByteArray(BYTE_ARRAY_KEY)); assertEquals(originalBundle.getShort(SHORT_KEY), cachedBundle.getShort(SHORT_KEY)); assertArrayEquals(originalBundle.getShortArray(SHORT_ARRAY_KEY), cachedBundle.getShortArray(SHORT_ARRAY_KEY)); assertEquals(originalBundle.getInt(INT_KEY), cachedBundle.getInt(INT_KEY)); assertArrayEquals(originalBundle.getIntArray(INT_ARRAY_KEY), cachedBundle.getIntArray(INT_ARRAY_KEY)); assertEquals(originalBundle.getLong(LONG_KEY), cachedBundle.getLong(LONG_KEY)); assertArrayEquals(originalBundle.getLongArray(LONG_ARRAY_KEY), cachedBundle.getLongArray(LONG_ARRAY_KEY)); assertEquals(originalBundle.getFloat(FLOAT_KEY), cachedBundle.getFloat(FLOAT_KEY), TestUtils.DOUBLE_EQUALS_DELTA); assertArrayEquals(originalBundle.getFloatArray(FLOAT_ARRAY_KEY), cachedBundle.getFloatArray(FLOAT_ARRAY_KEY)); assertEquals(originalBundle.getDouble(DOUBLE_KEY), cachedBundle.getDouble(DOUBLE_KEY), TestUtils.DOUBLE_EQUALS_DELTA); assertArrayEquals(originalBundle.getDoubleArray(DOUBLE_ARRAY_KEY), cachedBundle.getDoubleArray(DOUBLE_ARRAY_KEY)); assertEquals(originalBundle.getChar(CHAR_KEY), cachedBundle.getChar(CHAR_KEY)); assertArrayEquals(originalBundle.getCharArray(CHAR_ARRAY_KEY), cachedBundle.getCharArray(CHAR_ARRAY_KEY)); assertEquals(originalBundle.getString(STRING_KEY), cachedBundle.getString(STRING_KEY)); assertListEquals(originalBundle.getStringArrayList(STRING_LIST_KEY), cachedBundle.getStringArrayList(STRING_LIST_KEY)); assertEquals(originalBundle.getSerializable(SERIALIZABLE_KEY), cachedBundle.getSerializable(SERIALIZABLE_KEY)); }
From source file:com.google.android.libraries.cast.companionlibrary.utils.Utils.java
/** * Builds and returns a {@link MediaInfo} that was wrapped in a {@link Bundle} by * <code>mediaInfoToBundle</code>. It is assumed that the type of the {@link MediaInfo} is * {@code MediaMetaData.MEDIA_TYPE_MOVIE} * * @see <code>mediaInfoToBundle()</code> *//*from w w w. j a v a2 s .co m*/ public static MediaInfo bundleToMediaInfo(Bundle wrapper) { if (wrapper == null) { return null; } MediaMetadata metaData = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE); metaData.putString(MediaMetadata.KEY_SUBTITLE, wrapper.getString(MediaMetadata.KEY_SUBTITLE)); metaData.putString(MediaMetadata.KEY_TITLE, wrapper.getString(MediaMetadata.KEY_TITLE)); metaData.putString(MediaMetadata.KEY_STUDIO, wrapper.getString(MediaMetadata.KEY_STUDIO)); ArrayList<String> images = wrapper.getStringArrayList(KEY_IMAGES); if (images != null && !images.isEmpty()) { for (String url : images) { Uri uri = Uri.parse(url); metaData.addImage(new WebImage(uri)); } } String customDataStr = wrapper.getString(KEY_CUSTOM_DATA); JSONObject customData = null; if (!TextUtils.isEmpty(customDataStr)) { try { customData = new JSONObject(customDataStr); } catch (JSONException e) { LOGE(TAG, "Failed to deserialize the custom data string: custom data= " + customDataStr); } } List<MediaTrack> mediaTracks = null; if (wrapper.getString(KEY_TRACKS_DATA) != null) { try { JSONArray jsonArray = new JSONArray(wrapper.getString(KEY_TRACKS_DATA)); mediaTracks = new ArrayList<MediaTrack>(); if (jsonArray.length() > 0) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObj = (JSONObject) jsonArray.get(i); MediaTrack.Builder builder = new MediaTrack.Builder(jsonObj.getLong(KEY_TRACK_ID), jsonObj.getInt(KEY_TRACK_TYPE)); if (jsonObj.has(KEY_TRACK_NAME)) { builder.setName(jsonObj.getString(KEY_TRACK_NAME)); } if (jsonObj.has(KEY_TRACK_SUBTYPE)) { builder.setSubtype(jsonObj.getInt(KEY_TRACK_SUBTYPE)); } if (jsonObj.has(KEY_TRACK_CONTENT_ID)) { builder.setContentId(jsonObj.getString(KEY_TRACK_CONTENT_ID)); } if (jsonObj.has(KEY_TRACK_LANGUAGE)) { builder.setLanguage(jsonObj.getString(KEY_TRACK_LANGUAGE)); } if (jsonObj.has(KEY_TRACKS_DATA)) { builder.setCustomData(new JSONObject(jsonObj.getString(KEY_TRACKS_DATA))); } mediaTracks.add(builder.build()); } } } catch (JSONException e) { LOGE(TAG, "Failed to build media tracks from the wrapper bundle", e); } } MediaInfo.Builder mediaBuilder = new MediaInfo.Builder(wrapper.getString(KEY_URL)) .setStreamType(wrapper.getInt(KEY_STREAM_TYPE)).setContentType(wrapper.getString(KEY_CONTENT_TYPE)) .setMetadata(metaData).setCustomData(customData).setMediaTracks(mediaTracks); if (wrapper.containsKey(KEY_STREAM_DURATION) && wrapper.getLong(KEY_STREAM_DURATION) >= 0) { mediaBuilder.setStreamDuration(wrapper.getLong(KEY_STREAM_DURATION)); } return mediaBuilder.build(); }
From source file:com.google.sample.castcompanionlibrary.utils.Utils.java
/** * Builds and returns a {@link MediaInfo} that was wrapped in a {@link Bundle} by * <code>fromMediaInfo</code>. * * @param wrapper//from w ww . ja v a2 s.c o m * @return * @see <code>fromMediaInfo()</code> */ public static MediaInfo toMediaInfo(Bundle wrapper) { if (null == wrapper) { return null; } MediaMetadata metaData = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE); metaData.putString(MediaMetadata.KEY_SUBTITLE, wrapper.getString(MediaMetadata.KEY_SUBTITLE)); metaData.putString(MediaMetadata.KEY_TITLE, wrapper.getString(MediaMetadata.KEY_TITLE)); metaData.putString(MediaMetadata.KEY_STUDIO, wrapper.getString(MediaMetadata.KEY_STUDIO)); ArrayList<String> images = wrapper.getStringArrayList(KEY_IMAGES); if (null != images && !images.isEmpty()) { for (String url : images) { Uri uri = Uri.parse(url); metaData.addImage(new WebImage(uri)); } } String customDataStr = wrapper.getString(KEY_CUSTOM_DATA); JSONObject customData = null; if (!TextUtils.isEmpty(customDataStr)) { try { customData = new JSONObject(customDataStr); } catch (JSONException e) { LOGE(TAG, "Failed to deserialize the custom data string: custom data= " + customDataStr); } } List<MediaTrack> mediaTracks = null; if (wrapper.getString(KEY_TRACKS_DATA) != null) { try { JSONArray jsonArray = new JSONArray(wrapper.getString(KEY_TRACKS_DATA)); mediaTracks = new ArrayList<MediaTrack>(); if (jsonArray != null && jsonArray.length() > 0) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObj = (JSONObject) jsonArray.get(i); MediaTrack.Builder builder = new MediaTrack.Builder(jsonObj.getLong(KEY_TRACK_ID), jsonObj.getInt(KEY_TRACK_TYPE)); if (jsonObj.has(KEY_TRACK_NAME)) { builder.setName(jsonObj.getString(KEY_TRACK_NAME)); } if (jsonObj.has(KEY_TRACK_SUBTYPE)) { builder.setSubtype(jsonObj.getInt(KEY_TRACK_SUBTYPE)); } if (jsonObj.has(KEY_TRACK_CONTENT_ID)) { builder.setContentId(jsonObj.getString(KEY_TRACK_CONTENT_ID)); } if (jsonObj.has(KEY_TRACK_LANGUAGE)) { builder.setLanguage(jsonObj.getString(KEY_TRACK_LANGUAGE)); } if (jsonObj.has(KEY_TRACKS_DATA)) { builder.setCustomData(new JSONObject(jsonObj.getString(KEY_TRACKS_DATA))); } mediaTracks.add(builder.build()); } } } catch (JSONException e) { LOGE(TAG, "Failed to build media tracks from the wrapper bundle", e); } } return new MediaInfo.Builder(wrapper.getString(KEY_URL)).setStreamType(wrapper.getInt(KEY_STREAM_TYPE)) .setContentType(wrapper.getString(KEY_CONTENT_TYPE)).setMetadata(metaData).setCustomData(customData) .setMediaTracks(mediaTracks).setStreamDuration(wrapper.getLong(KEY_STREAM_DURATION)).build(); }
From source file:com.digitalarx.android.authentication.AuthenticatorActivity.java
/** * {@inheritDoc}/*from www .j a v a 2s .c o m*/ * * IMPORTANT ENTRY POINT 1: activity is shown to the user */ @Override protected void onCreate(Bundle savedInstanceState) { //Log_OC.wtf(TAG, "onCreate init"); super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_NO_TITLE); // bind to Operations Service mOperationsServiceConnection = new OperationsServiceConnection(); if (!bindService(new Intent(this, OperationsService.class), mOperationsServiceConnection, Context.BIND_AUTO_CREATE)) { Toast.makeText(this, R.string.error_cant_bind_to_operations_service, Toast.LENGTH_LONG).show(); finish(); } /// init activity state mAccountMgr = AccountManager.get(this); mNewCapturedUriFromOAuth2Redirection = null; /// get input values mAction = getIntent().getByteExtra(EXTRA_ACTION, ACTION_CREATE); mAccount = getIntent().getExtras().getParcelable(EXTRA_ACCOUNT); if (savedInstanceState == null) { initAuthTokenType(); } else { mAuthTokenType = savedInstanceState.getString(KEY_AUTH_TOKEN_TYPE); mWaitingForOpId = savedInstanceState.getLong(KEY_WAITING_FOR_OP_ID); } /// load user interface setContentView(R.layout.account_setup); /// initialize general UI elements initOverallUi(savedInstanceState); mOkButton = findViewById(R.id.buttonOK); /// initialize block to be moved to single Fragment to check server and get info about it initServerPreFragment(savedInstanceState); /// initialize block to be moved to single Fragment to retrieve and validate credentials initAuthorizationPreFragment(savedInstanceState); //Log_OC.wtf(TAG, "onCreate end"); }
From source file:com.android.calendar.AllInOneActivity.java
@Override protected void onCreate(Bundle icicle) { if (Utils.getSharedPreference(this, OtherPreferences.KEY_OTHER_1, false)) { setTheme(R.style.CalendarTheme_WithActionBarWallpaper); }/* ww w. j a va 2s . c o m*/ super.onCreate(icicle); dynamicTheme.onCreate(this); if (icicle != null && icicle.containsKey(BUNDLE_KEY_CHECK_ACCOUNTS)) { mCheckForAccounts = icicle.getBoolean(BUNDLE_KEY_CHECK_ACCOUNTS); } // Launch add google account if this is first time and there are no // accounts yet if (mCheckForAccounts && !Utils.getSharedPreference(this, GeneralPreferences.KEY_SKIP_SETUP, false)) { mHandler = new QueryHandler(this.getContentResolver()); mHandler.startQuery(0, null, Calendars.CONTENT_URI, new String[] { Calendars._ID }, null, null /* selection args */, null /* sort order */); } // This needs to be created before setContentView mController = CalendarController.getInstance(this); // Check and ask for most needed permissions checkAppPermissions(); // Get time from intent or icicle long timeMillis = -1; int viewType = -1; final Intent intent = getIntent(); if (icicle != null) { timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME); viewType = icicle.getInt(BUNDLE_KEY_RESTORE_VIEW, -1); } else { String action = intent.getAction(); if (Intent.ACTION_VIEW.equals(action)) { // Open EventInfo later timeMillis = parseViewAction(intent); } if (timeMillis == -1) { timeMillis = Utils.timeFromIntentInMillis(intent); } } if (viewType == -1 || viewType > ViewType.MAX_VALUE) { viewType = Utils.getViewTypeFromIntentAndSharedPref(this); } mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater); Time t = new Time(mTimeZone); t.set(timeMillis); if (DEBUG) { if (icicle != null && intent != null) { Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString()); } else { Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent); } } Resources res = getResources(); mHideString = res.getString(R.string.hide_controls); mShowString = res.getString(R.string.show_controls); mOrientation = res.getConfiguration().orientation; if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) { mControlsAnimateWidth = (int) res.getDimension(R.dimen.calendar_controls_width); if (mControlsParams == null) { mControlsParams = new LayoutParams(mControlsAnimateWidth, 0); } mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } else { // Make sure width is in between allowed min and max width values mControlsAnimateWidth = Math.max(res.getDisplayMetrics().widthPixels * 45 / 100, (int) res.getDimension(R.dimen.min_portrait_calendar_controls_width)); mControlsAnimateWidth = Math.min(mControlsAnimateWidth, (int) res.getDimension(R.dimen.max_portrait_calendar_controls_width)); } mControlsAnimateHeight = (int) res.getDimension(R.dimen.calendar_controls_height); mHideControls = !Utils.getSharedPreference(this, GeneralPreferences.KEY_SHOW_CONTROLS, true); mIsMultipane = Utils.getConfigBool(this, R.bool.multiple_pane_config); mIsTabletConfig = Utils.getConfigBool(this, R.bool.tablet_config); mShowAgendaWithMonth = Utils.getConfigBool(this, R.bool.show_agenda_with_month); mShowCalendarControls = Utils.getConfigBool(this, R.bool.show_calendar_controls); mShowEventDetailsWithAgenda = Utils.getConfigBool(this, R.bool.show_event_details_with_agenda); mShowEventInfoFullScreenAgenda = Utils.getConfigBool(this, R.bool.agenda_show_event_info_full_screen); mShowEventInfoFullScreen = Utils.getConfigBool(this, R.bool.show_event_info_full_screen); mCalendarControlsAnimationTime = res.getInteger(R.integer.calendar_controls_animation_time); Utils.setAllowWeekForDetailView(mIsMultipane); // setContentView must be called before configureActionBar setContentView(R.layout.all_in_one_material); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mNavigationView = (NavigationView) findViewById(R.id.navigation_view); mFab = (FloatingActionButton) findViewById(R.id.floating_action_button); if (mIsTabletConfig) { mDateRange = (TextView) findViewById(R.id.date_bar); mWeekTextView = (TextView) findViewById(R.id.week_num); } else { mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null); } setupToolbar(viewType); setupNavDrawer(); setupFloatingActionButton(); mHomeTime = (TextView) findViewById(R.id.home_time); mMiniMonth = findViewById(R.id.mini_month); if (mIsTabletConfig && mOrientation == Configuration.ORIENTATION_PORTRAIT) { mMiniMonth.setLayoutParams( new RelativeLayout.LayoutParams(mControlsAnimateWidth, mControlsAnimateHeight)); } mCalendarsList = findViewById(R.id.calendar_list); mMiniMonthContainer = findViewById(R.id.mini_month_container); mSecondaryPane = findViewById(R.id.secondary_pane); // Must register as the first activity because this activity can modify // the list of event handlers in it's handle method. This affects who // the rest of the handlers the controller dispatches to are. mController.registerFirstEventHandler(HANDLER_KEY, this); initFragments(timeMillis, viewType, icicle); // Listen for changes that would require this to be refreshed SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(this); mContentResolver = getContentResolver(); }
From source file:android.support.mediacompat.client.ClientBroadcastReceiver.java
@Override public void onReceive(Context context, Intent intent) { Bundle extras = intent.getExtras(); MediaControllerCompat controller;//from w ww .j a va 2 s .c om try { controller = new MediaControllerCompat(context, (MediaSessionCompat.Token) extras.getParcelable(KEY_SESSION_TOKEN)); } catch (RemoteException ex) { // Do nothing. return; } int method = extras.getInt(KEY_METHOD_ID, 0); if (ACTION_CALL_MEDIA_CONTROLLER_METHOD.equals(intent.getAction()) && extras != null) { Bundle arguments; switch (method) { case SEND_COMMAND: arguments = extras.getBundle(KEY_ARGUMENT); controller.sendCommand(arguments.getString("command"), arguments.getBundle("extras"), new ResultReceiver(null)); break; case ADD_QUEUE_ITEM: controller.addQueueItem((MediaDescriptionCompat) extras.getParcelable(KEY_ARGUMENT)); break; case ADD_QUEUE_ITEM_WITH_INDEX: arguments = extras.getBundle(KEY_ARGUMENT); controller.addQueueItem((MediaDescriptionCompat) arguments.getParcelable("description"), arguments.getInt("index")); break; case REMOVE_QUEUE_ITEM: controller.removeQueueItem((MediaDescriptionCompat) extras.getParcelable(KEY_ARGUMENT)); break; case SET_VOLUME_TO: controller.setVolumeTo(extras.getInt(KEY_ARGUMENT), 0); break; case ADJUST_VOLUME: controller.adjustVolume(extras.getInt(KEY_ARGUMENT), 0); break; } } else if (ACTION_CALL_TRANSPORT_CONTROLS_METHOD.equals(intent.getAction()) && extras != null) { TransportControls controls = controller.getTransportControls(); Bundle arguments; switch (method) { case PLAY: controls.play(); break; case PAUSE: controls.pause(); break; case STOP: controls.stop(); break; case FAST_FORWARD: controls.fastForward(); break; case REWIND: controls.rewind(); break; case SKIP_TO_PREVIOUS: controls.skipToPrevious(); break; case SKIP_TO_NEXT: controls.skipToNext(); break; case SEEK_TO: controls.seekTo(extras.getLong(KEY_ARGUMENT)); break; case SET_RATING: controls.setRating((RatingCompat) extras.getParcelable(KEY_ARGUMENT)); break; case PLAY_FROM_MEDIA_ID: arguments = extras.getBundle(KEY_ARGUMENT); controls.playFromMediaId(arguments.getString("mediaId"), arguments.getBundle("extras")); break; case PLAY_FROM_SEARCH: arguments = extras.getBundle(KEY_ARGUMENT); controls.playFromSearch(arguments.getString("query"), arguments.getBundle("extras")); break; case PLAY_FROM_URI: arguments = extras.getBundle(KEY_ARGUMENT); controls.playFromUri((Uri) arguments.getParcelable("uri"), arguments.getBundle("extras")); break; case SEND_CUSTOM_ACTION: arguments = extras.getBundle(KEY_ARGUMENT); controls.sendCustomAction(arguments.getString("action"), arguments.getBundle("extras")); break; case SEND_CUSTOM_ACTION_PARCELABLE: arguments = extras.getBundle(KEY_ARGUMENT); controls.sendCustomAction((PlaybackStateCompat.CustomAction) arguments.getParcelable("action"), arguments.getBundle("extras")); break; case SKIP_TO_QUEUE_ITEM: controls.skipToQueueItem(extras.getLong(KEY_ARGUMENT)); break; case PREPARE: controls.prepare(); break; case PREPARE_FROM_MEDIA_ID: arguments = extras.getBundle(KEY_ARGUMENT); controls.prepareFromMediaId(arguments.getString("mediaId"), arguments.getBundle("extras")); break; case PREPARE_FROM_SEARCH: arguments = extras.getBundle(KEY_ARGUMENT); controls.prepareFromSearch(arguments.getString("query"), arguments.getBundle("extras")); break; case PREPARE_FROM_URI: arguments = extras.getBundle(KEY_ARGUMENT); controls.prepareFromUri((Uri) arguments.getParcelable("uri"), arguments.getBundle("extras")); break; case SET_CAPTIONING_ENABLED: controls.setCaptioningEnabled(extras.getBoolean(KEY_ARGUMENT)); break; case SET_REPEAT_MODE: controls.setRepeatMode(extras.getInt(KEY_ARGUMENT)); break; case SET_SHUFFLE_MODE: controls.setShuffleMode(extras.getInt(KEY_ARGUMENT)); break; } } }
From source file:com.dwdesign.tweetings.util.Utils.java
public static String buildArguments(final Bundle args) { final Set<String> keys = args.keySet(); final JSONObject json = new JSONObject(); for (final String key : keys) { final Object value = args.get(key); if (value == null) { continue; }// www .j av a 2 s . c om try { if (value instanceof Boolean) { json.put(key, args.getBoolean(key)); } else if (value instanceof Integer) { json.put(key, args.getInt(key)); } else if (value instanceof Long) { json.put(key, args.getLong(key)); } else if (value instanceof String) { json.put(key, args.getString(key)); } else { Log.w(LOGTAG, "Unknown type " + (value != null ? value.getClass().getSimpleName() : null) + " in arguments key " + key); } } catch (final JSONException e) { e.printStackTrace(); } } return json.toString(); }