Example usage for android.os Bundle getSerializable

List of usage examples for android.os Bundle getSerializable

Introduction

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

Prototype

@Override
@Nullable
public Serializable getSerializable(@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:com.supremainc.biostar2.base.BaseFragment.java

@SuppressWarnings("unchecked")
protected <T> T getBundleData(String tag, Bundle bundle) {
    if (bundle == null) {
        return null;
    }/*w w w.  jav  a 2 s  .c o  m*/
    try {
        T result = (T) bundle.getSerializable(tag);
        if (BuildConfig.DEBUG) {
            if (result == null) {
                Log.e(TAG, "getExtraData null, tag:" + tag);
            }
        }
        return result;
    } catch (Exception e) {
        if (BuildConfig.DEBUG) {
            Log.e(TAG, "getExtraData tag:" + tag + " error:" + e.getMessage());
        }
    }
    return null;
}

From source file:com.android.contacts.list.MultiSelectContactsListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (savedInstanceState != null) {
        final TreeSet<Long> selectedContactIds = (TreeSet<Long>) savedInstanceState
                .getSerializable(EXTRA_KEY_SELECTED_CONTACTS);
        getAdapter().setSelectedContactIds(selectedContactIds);
    }//from   w ww .  j a  va 2s  . co  m
}

From source file:de.unipassau.isl.evs.ssh.app.activity.EditUserDeviceFragment.java

/**
 * Creates and shows a dialogs that gives the user the option to edit a group.
 *//*w  ww.  j av a2s . co m*/
private void showEditUserDeviceDialog(Bundle bundle) {
    final UserDevice userDevice = (UserDevice) bundle.getSerializable(EDIT_USERDEVICE_DIALOG);
    if (userDevice == null) {
        Log.i(TAG, "No device found.");
        return;
    }

    final String[] groupNames = bundle.getStringArray(ALL_GROUPS_DIALOG);
    if (groupNames == null) {
        Log.i(TAG, "Empty bundle");
        return;
    }

    final AppUserConfigurationHandler handler = getComponent(AppUserConfigurationHandler.KEY);
    if (handler == null) {
        Log.i(TAG, "Container not yet connected!");
        return;
    }

    final LayoutInflater inflater = getActivity().getLayoutInflater();
    final View dialogView = inflater.inflate(R.layout.dialog_edituserdevice, null);

    final TextView title = (TextView) dialogView.findViewById(R.id.editdevicedialog_title);
    title.setText(String.format(getResources().getString(R.string.edit_user_device), userDevice.getName()));

    final EditText userDeviceName = (EditText) dialogView.findViewById(R.id.editdevicedialog_username);
    userDeviceName.setText(userDevice.getName());

    final ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(),
            android.R.layout.simple_spinner_dropdown_item, groupNames);
    final Spinner groupName = ((Spinner) dialogView.findViewById(R.id.editdevicedialog_spinner));
    groupName.setAdapter(adapter);
    groupName.setSelection(adapter.getPosition(userDevice.getInGroup()));

    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    final Resources res = getResources();
    final AlertDialog editDialog = builder.setView(dialogView).setNegativeButton(R.string.cancel, null)
            .setPositiveButton(R.string.edit, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    final AppMainActivity activity = (AppMainActivity) getActivity();
                    if (activity.hasPermission(Permission.CHANGE_USER_NAME)
                            && activity.hasPermission(Permission.CHANGE_USER_GROUP)) {
                        String name = userDeviceName.getText().toString();
                        String group = ((String) groupName.getSelectedItem());
                        DeviceID userDeviceID = userDevice.getUserDeviceID();

                        // no permission check as method only gets called when user can edit user name / user group
                        handler.setUserName(userDeviceID, name);
                        handler.setUserGroup(userDeviceID, group);
                    } else {
                        showToast(R.string.you_can_not_edit_user_devices);
                    }
                }
            }).setNeutralButton(R.string.remove, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (((AppMainActivity) getActivity()).hasPermission(Permission.DELETE_USER)) {
                        handler.removeUserDevice(userDevice.getUserDeviceID());
                        String toastText = String.format(res.getString(R.string.device_removed),
                                userDevice.getName());
                        Toast.makeText(getActivity(), toastText, Toast.LENGTH_SHORT).show();
                    } else {
                        showToast(R.string.you_can_not_remove_users);
                    }
                }
            }).create();

    // open the soft keyboard when dialog gets focused
    userDeviceName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                editDialog.getWindow()
                        .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }
        }
    });

    editDialog.show();
    userDeviceName.requestFocus();
}

From source file:cs.man.ac.uk.tavernamobile.WorkflowDetail.java

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    // Restore UI state from the savedInstanceState.
    // This bundle has also been passed to onCreate.
    workflow = (Workflow) savedInstanceState.getSerializable("workflow");
    license = (License) savedInstanceState.getSerializable("license");
    uploader = (User) savedInstanceState.getSerializable("uploader");
}

From source file:com.bukanir.android.activities.SearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate");
    super.onCreate(savedInstanceState);

    supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    setContentView(R.layout.activity_movie_list);

    if (findViewById(R.id.movie_container) != null) {
        twoPane = true;/*  w w w .  jav a 2 s .c o  m*/
    }

    if (savedInstanceState != null) {
        movies = (ArrayList<Movie>) savedInstanceState.getSerializable("search");
    } else {
        Bundle bundle = getIntent().getExtras();
        movies = (ArrayList<Movie>) bundle.get("search");
    }

    final ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);

    beginTransaction(movies);
}

From source file:fi.mikuz.boarder.gui.internet.InternetMenu.java

@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    switch (requestCode) {
    case LOGIN_RETURN:
        if (resultCode == RESULT_OK) {
            Bundle extras = intent.getExtras();
            @SuppressWarnings("unchecked")
            HashMap<String, String> returnInfo = (HashMap<String, String>) extras.getSerializable(LOGIN_KEY);
            mLoginInfo = returnInfo;//  www  . j a va  2s. com
            sendDonationInfo();

            if (mLoginInfo == null) {
                setLoggedOutView();
            } else {
                setLoggedInView();
            }

            String accountMessage = extras.getString(ACCOUNT_MESSAGE_KEY);
            updateAccountMessage(accountMessage);
        }
        break;
    }
}

From source file:android.example.colorpicker.ColorPickerDialog.java

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

    if (getArguments() != null) {
        mTitleResId = getArguments().getInt(KEY_TITLE_ID);
        mColumns = getArguments().getInt(KEY_COLUMNS);
        mSize = getArguments().getInt(KEY_SIZE);
    }/*w  w  w .j av a 2 s.c om*/

    if (savedInstanceState != null) {
        mColors = savedInstanceState.getIntArray(KEY_COLORS);
        mSelectedColor = (Integer) savedInstanceState.getSerializable(KEY_SELECTED_COLOR);
    }
}

From source file:at.ac.tuwien.detlef.fragments.EpisodeListFragment.java

/**
 * Restores the {@link EpisodeFilter episode filters}, e.g. after the screen
 * has been rotated./*from   w w w. ja v a 2s.c o  m*/
 *
 * @param savedInstanceState
 */
private void restoreFilter(Bundle savedInstanceState) {

    if (savedInstanceState == null) {
        return;
    }

    try {
        FilterChain pFilter = (FilterChain) savedInstanceState.getSerializable(BUNDLE_FILTERS);
        setFilter(pFilter);
        refresh();
    } catch (Exception e) {
        Log.e(TAG, "Exception restoring filter chain", e);
    }

}

From source file:br.com.brolam.cloudvision.ui.NoteVisionDetailsActivity.java

private void setSaveInstanceState(Bundle savedInstanceState) {
    // read parameters from the  savedInstanceState ou intent used to launch the activity.
    Bundle bundle = savedInstanceState != null ? savedInstanceState : getIntent().getExtras();
    if (bundle != null) {
        this.noteVisionKey = bundle.getString(NOTE_VISION_KEY);
        this.noteVision = (HashMap) bundle.getSerializable(NOTE_VISION);
        this.setHeader();
    }/*from  w ww . j a v a  2s  .c  o  m*/
}

From source file:android.support.car.ui.CarNavExtender.java

/**
 * Reconstruct a CarNavExtender from an existing notification. Can be used to retrieve values.
 *
 * @param notification The notification to retrieve the values from.
 *//*from  ww  w. j  a  v  a  2  s  .c  o  m*/
public CarNavExtender(@NonNull Notification notification) {
    Bundle extras = NotificationCompat.getExtras(notification);
    if (extras == null) {
        return;
    }
    Bundle b = extras.getBundle(EXTRA_CAR_EXTENDER);
    if (b == null) {
        return;
    }

    mIsExtended = b.getBoolean(EXTRA_IS_EXTENDED);
    mContentId = (Long) b.getSerializable(EXTRA_CONTENT_ID);
    // The ternary guarantees that we return either TYPE_HERO or TYPE_NORMAL.
    mType = (b.getInt(EXTRA_TYPE, TYPE_NORMAL) == TYPE_HERO) ? TYPE_HERO : TYPE_NORMAL;
    mContentTitle = b.getCharSequence(Notification.EXTRA_TITLE);
    mContentText = b.getCharSequence(Notification.EXTRA_TEXT);
    mSubText = b.getCharSequence(EXTRA_SUB_TEXT);
    mLargeIcon = b.getParcelable(Notification.EXTRA_LARGE_ICON);
    mActionIcon = b.getInt(EXTRA_ACTION_ICON);
    mContentIntent = b.getParcelable(EXTRA_CONTENT_INTENT);
    mColor = b.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT);
    mNightColor = b.getInt(EXTRA_NIGHT_COLOR, Notification.COLOR_DEFAULT);
    mShowInStream = b.getBoolean(EXTRA_STREAM_VISIBILITY, true);
    mShowAsHeadsUp = b.getBoolean(EXTRA_HEADS_UP_VISIBILITY);
    mIgnoreInStream = b.getBoolean(EXTRA_IGNORE_IN_STREAM);
}