Example usage for android.os Bundle getBundle

List of usage examples for android.os Bundle getBundle

Introduction

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

Prototype

@Nullable
public Bundle getBundle(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:de.mrapp.android.preference.activity.PreferenceActivity.java

@CallSuper
@Override/*from   w  w w  . j  a v  a  2s  .  c o m*/
protected void onRestoreInstanceState(final Bundle savedInstanceState) {
    Bundle bundle = savedInstanceState.getBundle(CURRENT_BUNDLE_EXTRA);
    CharSequence title = savedInstanceState.getCharSequence(CURRENT_TITLE_EXTRA);
    CharSequence shortTitle = savedInstanceState.getCharSequence(CURRENT_SHORT_TITLE_EXTRA);
    PreferenceHeader currentPreferenceHeader = savedInstanceState
            .getParcelable(CURRENT_PREFERENCE_HEADER_EXTRA);

    if (currentPreferenceHeader != null) {
        preferenceScreenFragment = restoredPreferenceScreenFragment;
        showPreferenceScreen(currentPreferenceHeader, bundle, false);
        showBreadCrumb(title, shortTitle);

        if (isSplitScreen()) {
            int selectedIndex = getListAdapter().indexOf(currentPreferenceHeader);

            if (selectedIndex != -1) {
                getListView().setItemChecked(selectedIndex, true);
            }
        }
    } else {
        showPreferenceHeaders();
    }
}

From source file:com.facebook.samples.AdUnitsSample.InstreamVideoFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_instream_video, container, false);

    InstreamVideoAdStatusLabel = (TextView) view.findViewById(R.id.instreamVideoAdStatusLabel);
    loadInstreamVideoButton = (Button) view.findViewById(R.id.loadInstreamVideoButton);
    showInstreamVideoButton = (Button) view.findViewById(R.id.showInstreamVideoButton);
    destroyInstreamVideoButton = (Button) view.findViewById(R.id.destroyInstreamVideoButton);
    mAdViewContainer = (RelativeLayout) view.findViewById(R.id.adViewContainer);
    loadInstreamVideoButton.setOnClickListener(new View.OnClickListener() {

        @Override/*from  ww  w. j  av  a 2s  .  c  o  m*/
        public void onClick(View v) {
            if (instreamVideoAdView != null) {
                instreamVideoAdView.destroy();
                mAdViewContainer.removeAllViews();
            }
            instreamVideoAdView = new InstreamVideoAdView(InstreamVideoFragment.this.getActivity(),
                    "YOUR_PLACEMENT_ID", new AdSize(pxToDP(mAdViewContainer.getMeasuredWidth()),
                            pxToDP(mAdViewContainer.getMeasuredHeight())));
            instreamVideoAdView.setAdListener(InstreamVideoFragment.this);
            instreamVideoAdView.loadAd();

            setStatusLabelText("Loading Instream video ad...");
        }
    });

    showInstreamVideoButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (instreamVideoAdView == null || !instreamVideoAdView.isAdLoaded()) {
                setStatusLabelText("Ad not loaded. Click load to request an ad.");
            } else {
                if (instreamVideoAdView.getParent() != mAdViewContainer) {
                    mAdViewContainer.addView(instreamVideoAdView);
                }
                instreamVideoAdView.show();
                setStatusLabelText("Ad Showing");
            }
        }
    });

    destroyInstreamVideoButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (instreamVideoAdView == null) {
                return;
            }
            instreamVideoAdView.destroy();
            instreamVideoAdView = null;
            mAdViewContainer.removeAllViews();
            setStatusLabelText("Ad destroyed");
        }
    });

    // Restore state
    if (savedInstanceState == null) {
        return view;
    }
    Bundle adState = savedInstanceState.getBundle(AD);
    if (adState != null) {
        instreamVideoAdView = new InstreamVideoAdView(InstreamVideoFragment.this.getActivity(), adState);
        instreamVideoAdView.setAdListener(new InstreamVideoAdListener() {
            @Override
            public void onAdVideoComplete(Ad ad) {
                InstreamVideoFragment.this.onAdVideoComplete(ad);
            }

            @Override
            public void onError(Ad ad, AdError error) {
                InstreamVideoFragment.this.onError(ad, error);
            }

            @Override
            public void onAdLoaded(Ad ad) {
                InstreamVideoFragment.this.onAdLoaded(ad);
                showInstreamVideoButton.callOnClick();
            }

            @Override
            public void onAdClicked(Ad ad) {
                InstreamVideoFragment.this.onAdClicked(ad);
            }

            @Override
            public void onLoggingImpression(Ad ad) {
                InstreamVideoFragment.this.onLoggingImpression(ad);
            }
        });
        instreamVideoAdView.loadAd();
    }

    return view;
}

From source file:com.fenlisproject.elf.core.framework.ElfBinder.java

public static void bindFragmentArgument(Fragment receiver) {
    Field[] fields = receiver.getClass().getDeclaredFields();
    for (Field field : fields) {
        field.setAccessible(true);//from ww w .  j  a v a 2s  . com
        FragmentArgument fragmentArgument = field.getAnnotation(FragmentArgument.class);
        if (fragmentArgument != null) {
            try {
                Bundle bundle = receiver.getArguments();
                if (bundle != null) {
                    Class<?> type = field.getType();
                    if (type == Boolean.class || type == boolean.class) {
                        field.set(receiver, bundle.getBoolean(fragmentArgument.value()));
                    } else if (type == Byte.class || type == byte.class) {
                        field.set(receiver, bundle.getByte(fragmentArgument.value()));
                    } else if (type == Character.class || type == char.class) {
                        field.set(receiver, bundle.getChar(fragmentArgument.value()));
                    } else if (type == Double.class || type == double.class) {
                        field.set(receiver, bundle.getDouble(fragmentArgument.value()));
                    } else if (type == Float.class || type == float.class) {
                        field.set(receiver, bundle.getFloat(fragmentArgument.value()));
                    } else if (type == Integer.class || type == int.class) {
                        field.set(receiver, bundle.getInt(fragmentArgument.value()));
                    } else if (type == Long.class || type == long.class) {
                        field.set(receiver, bundle.getLong(fragmentArgument.value()));
                    } else if (type == Short.class || type == short.class) {
                        field.set(receiver, bundle.getShort(fragmentArgument.value()));
                    } else if (type == String.class) {
                        field.set(receiver, bundle.getString(fragmentArgument.value()));
                    } else if (type == Boolean[].class || type == boolean[].class) {
                        field.set(receiver, bundle.getBooleanArray(fragmentArgument.value()));
                    } else if (type == Byte[].class || type == byte[].class) {
                        field.set(receiver, bundle.getByteArray(fragmentArgument.value()));
                    } else if (type == Character[].class || type == char[].class) {
                        field.set(receiver, bundle.getCharArray(fragmentArgument.value()));
                    } else if (type == Double[].class || type == double[].class) {
                        field.set(receiver, bundle.getDoubleArray(fragmentArgument.value()));
                    } else if (type == Float[].class || type == float[].class) {
                        field.set(receiver, bundle.getFloatArray(fragmentArgument.value()));
                    } else if (type == Integer[].class || type == int[].class) {
                        field.set(receiver, bundle.getIntArray(fragmentArgument.value()));
                    } else if (type == Long[].class || type == long[].class) {
                        field.set(receiver, bundle.getLongArray(fragmentArgument.value()));
                    } else if (type == Short[].class || type == short[].class) {
                        field.set(receiver, bundle.getShortArray(fragmentArgument.value()));
                    } else if (type == String[].class) {
                        field.set(receiver, bundle.getStringArray(fragmentArgument.value()));
                    } else if (Serializable.class.isAssignableFrom(type)) {
                        field.set(receiver, bundle.getSerializable(fragmentArgument.value()));
                    } else if (type == Bundle.class) {
                        field.set(receiver, bundle.getBundle(fragmentArgument.value()));
                    }
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:saphion.fragments.alarm.AlarmFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {

    mCursorLoader = getActivity().getSupportLoaderManager().initLoader(0, null, this);
    try {/*from  w  ww  .  jav a2s.c om*/
        if (!created)
            mCursorLoader.forceLoad();
    } catch (Exception ex) {
    }
    // Inflate the layout for this fragment
    final View v = inflater.inflate(R.layout.alarm_listview, container, false);

    long[] expandedIds = null;
    long[] repeatCheckedIds = null;
    long[] selectedAlarms = null;
    Bundle previousDayMap = null;
    if (savedState != null) {
        expandedIds = savedState.getLongArray(KEY_EXPANDED_IDS);
        repeatCheckedIds = savedState.getLongArray(KEY_REPEAT_CHECKED_IDS);
        mRingtoneTitleCache = savedState.getBundle(KEY_RINGTONE_TITLE_CACHE);
        mDeletedAlarm = savedState.getParcelable(KEY_DELETED_ALARM);
        mUndoShowing = savedState.getBoolean(KEY_UNDO_SHOWING);
        selectedAlarms = savedState.getLongArray(KEY_SELECTED_ALARMS);
        previousDayMap = savedState.getBundle(KEY_PREVIOUS_DAY_MAP);
        mSelectedAlarm = savedState.getParcelable(KEY_SELECTED_ALARM);
    }

    mMessageBar = new MessageBar(getActivity());

    mExpandInterpolator = new DecelerateInterpolator(EXPAND_DECELERATION);
    mCollapseInterpolator = new DecelerateInterpolator(COLLAPSE_DECELERATION);

    mAddAlarmButton = (ImageButton) v.findViewById(R.id.alarm_add_alarm);
    mAddAlarmButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            hideUndoBar(true, null);
            startCreatingAlarm();
        }
    });
    // For landscape, put the add button on the right and the menu in the
    // actionbar.
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mAddAlarmButton.getLayoutParams();
    boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    if (isLandscape) {
        layoutParams.gravity = Gravity.RIGHT;
    } else {
        layoutParams.gravity = Gravity.CENTER;
    }
    mAddAlarmButton.setLayoutParams(layoutParams);

    View menuButton = v.findViewById(R.id.menu_button);
    if (menuButton != null) {
        if (isLandscape) {
            menuButton.setVisibility(View.GONE);
        } else {
            menuButton.setVisibility(View.VISIBLE);
            setupFakeOverflowMenuButton(menuButton);
        }
    }

    mEmptyView = v.findViewById(R.id.alarms_empty_view);
    mEmptyView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            startCreatingAlarm();
        }
    });
    mAlarmsList = (ListView) v.findViewById(R.id.alarms_list);

    mFadeIn = AnimatorInflater.loadAnimator(getActivity(), R.anim.fade_in);
    mFadeIn.setDuration(ANIMATION_DURATION);
    mFadeIn.addListener(new AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
            mEmptyView.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            // Do nothing.
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // Do nothing.
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
            // Do nothing.
        }
    });
    mFadeIn.setTarget(mEmptyView);
    mFadeOut = AnimatorInflater.loadAnimator(getActivity(), R.anim.fade_out);
    mFadeOut.setDuration(ANIMATION_DURATION);
    mFadeOut.addListener(new AnimatorListener() {

        @Override
        public void onAnimationStart(Animator arg0) {
            mEmptyView.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationCancel(Animator arg0) {
            // Do nothing.
        }

        @Override
        public void onAnimationEnd(Animator arg0) {
            mEmptyView.setVisibility(View.GONE);
        }

        @Override
        public void onAnimationRepeat(Animator arg0) {
            // Do nothing.
        }
    });
    mFadeOut.setTarget(mEmptyView);

    mFooterView = v.findViewById(R.id.alarms_footer_view);
    mFooterView.setOnTouchListener(this);

    mAdapter = new AlarmItemAdapter(getActivity(), expandedIds, repeatCheckedIds, selectedAlarms,
            previousDayMap, mAlarmsList);

    hideandshow(mAdapter.getCount());

    mAdapter.registerDataSetObserver(new DataSetObserver() {

        private int prevAdapterCount = -1;

        @Override
        public void onChanged() {

            final int count = mAdapter.getCount();
            if (mDeletedAlarm != null && prevAdapterCount > count) {
                showUndoBar();
            }

            hideandshow(count);
            // Cache this adapter's count for when the adapter changes.
            prevAdapterCount = count;
            super.onChanged();
        }
    });

    if (mRingtoneTitleCache == null) {
        mRingtoneTitleCache = new Bundle();
    }

    mAlarmsList.setAdapter(mAdapter);
    mAlarmsList.setVerticalScrollBarEnabled(true);
    mAlarmsList.setOnCreateContextMenuListener(this);

    if (mUndoShowing) {
        showUndoBar();
    }
    return v;
}

From source file:de.mrapp.android.adapter.expandablelist.AbstractExpandableListAdapter.java

@Override
public final void onRestoreInstanceState(@NonNull final Bundle savedInstanceState, @NonNull final String key) {
    Bundle savedState = savedInstanceState.getBundle(key);

    if (savedState != null) {
        if (savedState.containsKey(GROUP_ADAPTER_BUNDLE_KEY)) {
            groupAdapter.onRestoreInstanceState(savedState, GROUP_ADAPTER_BUNDLE_KEY);

            for (int i = 0; i < groupAdapter.getCount(); i++) {
                Group<GroupType, ChildType> group = groupAdapter.getItem(i);
                String childAdapterKey = String.format(CHILD_ADAPTER_BUNDLE_KEY, i);
                MultipleChoiceListAdapter<ChildType> childAdapter = createChildAdapter();

                if (savedState.containsKey(childAdapterKey)) {
                    childAdapter.onRestoreInstanceState(savedState, childAdapterKey);
                }// w ww  .  ja va2 s.  c  om

                group.setChildAdapter(childAdapter);
            }
        }

        if (savedState.containsKey(ADAPTER_VIEW_STATE_BUNDLE_KEY)) {
            if (adapterView != null) {
                AdapterViewUtil.onRestoreInstanceState(adapterView, savedState, ADAPTER_VIEW_STATE_BUNDLE_KEY);
            } else if (expandableGridView != null) {
                AdapterViewUtil.onRestoreInstanceState(expandableGridView, savedState,
                        ADAPTER_VIEW_STATE_BUNDLE_KEY);
            } else if (expandableRecyclerView != null) {
                expandableRecyclerView.getLayoutManager()
                        .onRestoreInstanceState(savedState.getParcelable(ADAPTER_VIEW_STATE_BUNDLE_KEY));
            }
        }

        allowDuplicateChildren(savedState.getBoolean(ALLOW_DUPLICATE_CHILDREN_BUNDLE_KEY));
        triggerGroupExpansionOnClick(savedState.getBoolean(TRIGGER_GROUP_EXPANSION_ON_CLICK_BUNDLE_KEY));
        setLogLevel(LogLevel.fromRank(savedState.getInt(LOG_LEVEL_BUNDLE_KEY)));
        onRestoreInstanceState(savedState);
        notifyDataSetChanged();
        getLogger().logDebug(getClass(), "Restored instance state");
    } else {
        getLogger().logWarn(getClass(),
                "Saved instance state does not contain bundle with key \"" + key + "\"");
    }
}

From source file:com.adkdevelopment.earthquakesurvival.ui.DetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.detailed_fragment, container, false);
    setHasOptionsMenu(true);/*from ww w  .j  a  va  2s  .c  om*/

    mUnbinder = ButterKnife.bind(this, rootView);

    if (getActivity().getIntent().hasExtra(Feature.GEOFENCE)) {

        ArrayList<String> place = getActivity().getIntent().getStringArrayListExtra(Feature.GEOFENCE);

        Cursor cursor = null;
        if (place != null && place.size() > 1) {
            cursor = getActivity().getContentResolver().query(EarthquakeColumns.CONTENT_URI, null,
                    EarthquakeColumns.URL + "= ?", new String[] { place.get(1) }, null);
        }

        if (cursor != null && cursor.getCount() > 0) {
            cursor.moveToFirst();

            long dateMillis = cursor.getLong(cursor.getColumnIndex(EarthquakeColumns.TIME));
            double latitude = cursor.getDouble(cursor.getColumnIndex(EarthquakeColumns.LATITUDE));
            double longitude = cursor.getDouble(cursor.getColumnIndex(EarthquakeColumns.LONGITUDE));

            LatLng latLng = new LatLng(latitude, longitude);

            mCameraPosition = CameraPosition.builder().target(latLng).zoom(LocationUtils.CAMERA_DEFAULT_ZOOM)
                    .build();

            mDistance = getString(R.string.earthquake_distance,
                    LocationUtils.getDistance(latLng, LocationUtils.getLocation(getContext())));
            mDate = Utilities.getRelativeDate(dateMillis);
            mDescription = Utilities
                    .formatEarthquakePlace(cursor.getString(cursor.getColumnIndex(EarthquakeColumns.PLACE)));
            mLink = cursor.getString(cursor.getColumnIndex(EarthquakeColumns.URL));
            mMagnitude = cursor.getDouble(cursor.getColumnIndex(EarthquakeColumns.MAG));
            mDepth = cursor.getDouble(cursor.getColumnIndex(EarthquakeColumns.DEPTH)) / 1.6;
            cursor.close();

            setDataToViews();
        }

    } else if (getActivity().getIntent() != null) {
        Intent input = getActivity().getIntent();
        mDate = input.getStringExtra(Feature.DATE);
        mDescription = input.getStringExtra(Feature.PLACE);
        mLink = input.getStringExtra(Feature.LINK);
        mMagnitude = input.getDoubleExtra(Feature.MAGNITUDE, 0.0);
        mPosition = input.getParcelableExtra(Feature.LATLNG);
        mDistance = input.getStringExtra(Feature.DISTANCE);
        mDepth = input.getDoubleExtra(Feature.DEPTH, 0.0);

        setDataToViews();
    }

    if (mPosition == null) {
        mPosition = LocationUtils.getLocation(getContext());
    }

    final Bundle mapViewSavedInstanceState = savedInstanceState != null
            ? savedInstanceState.getBundle(MAP_STATE)
            : null;

    if (Utilities.checkPlayServices(getActivity())) {
        mMapView.onCreate(mapViewSavedInstanceState);
        mMapView.getMapAsync(this);
    }

    if (savedInstanceState != null) {
        mCameraPosition = savedInstanceState.getParcelable(CAMERA_POSITION);
    } else {
        mCameraPosition = CameraPosition.builder().target(mPosition).zoom(LocationUtils.CAMERA_DEFAULT_ZOOM)
                .build();
    }

    return rootView;
}

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.  jav a  2s  .co  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:cn.edu.zafu.corepage.base.BaseActivity.java

/**
 * ???//from  ww  w.j  a  va2  s.  c o  m
 *
 * @param savedInstanceState Bundle
 */
private void loadActivitySavedData(Bundle savedInstanceState) {
    Field[] fields = this.getClass().getDeclaredFields();
    Field.setAccessible(fields, true);
    Annotation[] ans;
    for (Field f : fields) {
        ans = f.getDeclaredAnnotations();
        for (Annotation an : ans) {
            if (an instanceof SaveWithActivity) {
                try {
                    String fieldName = f.getName();
                    @SuppressWarnings("rawtypes")
                    Class cls = f.getType();
                    if (cls == int.class || cls == Integer.class) {
                        f.setInt(this, savedInstanceState.getInt(fieldName));
                    } else if (String.class.isAssignableFrom(cls)) {
                        f.set(this, savedInstanceState.getString(fieldName));
                    } else if (Serializable.class.isAssignableFrom(cls)) {
                        f.set(this, savedInstanceState.getSerializable(fieldName));
                    } else if (cls == long.class || cls == Long.class) {
                        f.setLong(this, savedInstanceState.getLong(fieldName));
                    } else if (cls == short.class || cls == Short.class) {
                        f.setShort(this, savedInstanceState.getShort(fieldName));
                    } else if (cls == boolean.class || cls == Boolean.class) {
                        f.setBoolean(this, savedInstanceState.getBoolean(fieldName));
                    } else if (cls == byte.class || cls == Byte.class) {
                        f.setByte(this, savedInstanceState.getByte(fieldName));
                    } else if (cls == char.class || cls == Character.class) {
                        f.setChar(this, savedInstanceState.getChar(fieldName));
                    } else if (CharSequence.class.isAssignableFrom(cls)) {
                        f.set(this, savedInstanceState.getCharSequence(fieldName));
                    } else if (cls == float.class || cls == Float.class) {
                        f.setFloat(this, savedInstanceState.getFloat(fieldName));
                    } else if (cls == double.class || cls == Double.class) {
                        f.setDouble(this, savedInstanceState.getDouble(fieldName));
                    } else if (String[].class.isAssignableFrom(cls)) {
                        f.set(this, savedInstanceState.getStringArray(fieldName));
                    } else if (Parcelable.class.isAssignableFrom(cls)) {
                        f.set(this, savedInstanceState.getParcelable(fieldName));
                    } else if (Bundle.class.isAssignableFrom(cls)) {
                        f.set(this, savedInstanceState.getBundle(fieldName));
                    }
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

From source file:com.free.searcher.MainFragment.java

@Override
public void onViewStateRestored(Bundle savedInstanceState) {
    super.onViewStateRestored(savedInstanceState);

    if (savedInstanceState == null) {
        return;/*w  ww .j a va  2 s .c  o m*/
    }

    Log.i("SearcheFragment.onViewStateRestored();", savedInstanceState + "uuu");
    selectedFiles = savedInstanceState.getStringArray("selectedFiles");
    if (savedInstanceState.getSerializable("files") instanceof File[]) {
        files = (File[]) savedInstanceState.getSerializable("files");
    }

    if (savedInstanceState.getString("currentSearching") instanceof String) {
        currentSearching = savedInstanceState.getString("currentSearching");
    }

    if (savedInstanceState.getString("currentZipFileName") instanceof String) {
        currentZipFileName = savedInstanceState.getString("currentZipFileName");
        if (currentZipFileName.length() > 0) {
            try {
                extractFile = new ExtractFile(currentZipFileName,
                        MainFragment.PRIVATE_PATH + currentZipFileName);
            } catch (RarException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    if (savedInstanceState.getString("load") instanceof String) {
        load = savedInstanceState.getString("load");
    }

    if (savedInstanceState.getString("currentUrl") instanceof String) {
        currentUrl = savedInstanceState.getString("currentUrl");
    }
    //      HtmlSourceViewJavaScriptInterface.source = savedInstanceState.getString("source");

    if (currentUrl != null && currentUrl.length() > 0) {
        (webTask = new WebTask(MainFragment.this, webView, currentUrl)).execute();
    }

    if (mSearchView != null && savedInstanceState.getCharSequence("query") != null) {
        mSearchView.setQuery(savedInstanceState.getCharSequence("query"), false);
    }

    if (savedInstanceState.getString("status") instanceof String) {
        status = savedInstanceState.getCharSequence("status");
    }
    locX = savedInstanceState.getInt("locX");
    locY = savedInstanceState.getInt("locY");

    webViewBundle = savedInstanceState.getBundle("webViewBundle");
    if (savedInstanceState.getString("home") instanceof String) {
        home = savedInstanceState.getString("home");
    }

    //      webView.setOnTouchListener(new View.OnTouchListener() {
    //            @Override
    //            public boolean onTouch(View p1, MotionEvent event) {
    //               //Log.d("onClick", p1 + "");
    //               Log.d("MotionEvent", event + "");
    //               if ((event.getAction() ==  MotionEvent.ACTION_DOWN || event.getAction() ==  MotionEvent.ACTION_POINTER_UP) && statusView != null) {
    //                  int curVis = statusView.getSystemUiVisibility();
    //                  Log.d("curVis", curVis + ", " + ((curVis&View.SYSTEM_UI_FLAG_LOW_PROFILE) != 0));
    //                  SHOW = !SHOW;
    //                  Log.d("SHOW", SHOW + "");
    //                  setNavVisibility(SHOW); //((curVis&View.SYSTEM_UI_FLAG_LOW_PROFILE) != 0);
    //               }
    //               return false;
    //            }
    //         });

    /**
     if (savedInstanceState.getString("readTextFiles") != null) {
     String[] readTextFilesStr = savedInstanceState.getString("readTextFiles").split(";;;"); // ,
     // Util.listToString(readTextFiles,false, ";;;"));
     for (String textFile : readTextFilesStr) {
     readTextFiles.add(new File(textFile));
     }
     }
            
     if (savedInstanceState.getString("initFolderFiles") != null) {
     String[] initFolderFilesStr = savedInstanceState.getString("initFolderFiles").split(";;;"); // ,
     // Util.listToString(initFolderFiles,false, ";;;"));
     for (String folderFile : initFolderFilesStr) {
     initFolderFiles.add(new File(folderFile));
     }
     }
     **/
}

From source file:com.android.mail.compose.ComposeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Change the title for accessibility so we announce "Compose" instead
    // of the app_name while still showing the app_name in recents.
    setTitle(R.string.compose_title);/* ww  w  . java 2  s .c  o  m*/
    setContentView(R.layout.compose);
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        // Hide the app icon.
        actionBar.setIcon(null);
        actionBar.setDisplayUseLogoEnabled(false);
    }

    mInnerSavedState = (savedInstanceState != null) ? savedInstanceState.getBundle(KEY_INNER_SAVED_STATE)
            : null;
    checkValidAccounts();
}