Example usage for android.os Bundle getSparseParcelableArray

List of usage examples for android.os Bundle getSparseParcelableArray

Introduction

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

Prototype

@Nullable
public <T extends Parcelable> SparseArray<T> getSparseParcelableArray(@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:org.ale.scanner.zotero.MainActivity.java

@Override
public void onCreate(Bundle state) {
    super.onCreate(state);
    setContentView(R.layout.main);//from w  w  w .  jav  a2s  .co  m
    Bundle extras = getIntent().getExtras();

    mUIThreadHandler = new Handler();

    // Get the account we're logged in as
    mAccount = (Account) extras.getParcelable(INTENT_EXTRA_ACCOUNT);

    // Load preferences
    SharedPreferences prefs = getSharedPreferences(mAccount.getUid(), MODE_PRIVATE);
    // The group we'll upload to (default to user's personal library)
    mSelectedGroup = prefs.getInt(PREF_GROUP, Group.GROUP_LIBRARY);
    mISBNService = prefs.getInt(PREF_SERVICE, SERVICE_GOOGLE);

    // Initialize Clients
    mGoogleBooksAPI = new GoogleBooksAPIClient();
    mWorldCatAPI = new WorldCatAPIClient();
    mZAPI = new ZoteroAPIClient();
    mZAPI.setAccount(mAccount);

    // BibItem list
    ExpandableListView bibItemList = (ExpandableListView) findViewById(R.id.bib_items);

    // Pending item list
    View pendingListHolder = getLayoutInflater().inflate(R.layout.pending_item_list, bibItemList, false);
    bibItemList.addHeaderView(pendingListHolder);

    mPendingList = (ListView) pendingListHolder.findViewById(R.id.pending_item_list);

    int[] checked;
    if (state == null) { // Fresh activity
        mAccountAccess = null; // will check for permissions in onResume
        mPendingItems = new ArrayList<String>(2); // RC_PEND
        mPendingStatus = new ArrayList<Integer>(2); // RC_PEND_STAT
        checked = new int[0];
        mUploadState = UPLOAD_STATE_WAIT;
        mGroups = new SparseArray<PString>();
    } else { // Recreating activity
             // Rebuild pending list
        mAccountAccess = state.getParcelable(RC_ACCESS);
        mPendingItems = state.getStringArrayList(RC_PEND);
        mPendingStatus = state.getIntegerArrayList(RC_PEND_STAT);
        // Set checked items
        checked = state.getIntArray(RC_CHECKED);

        mUploadState = state.getInt(RC_UPLOADING);
        mGroups = state.getSparseParcelableArray(RC_GROUPS);
    }

    // Initialize list adapters
    mItemAdapter = new BibItemListAdapter(MainActivity.this);
    mItemAdapter.setChecked(checked);
    bibItemList.setAdapter(mItemAdapter);
    registerForContextMenu(bibItemList);

    mPendingAdapter = new PendingListAdapter(MainActivity.this, R.layout.pending_item, R.id.pending_item_id,
            mPendingItems, mPendingStatus);
    mPendingList.setAdapter(mPendingAdapter);
    registerForContextMenu(mPendingList);

    // Listeners
    findViewById(R.id.scan_isbn).setOnClickListener(scanIsbn);
    findViewById(R.id.upload).setOnClickListener(uploadSelected);

    // Load animations
    mAnimations = new Animation[] { AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_in_next),
            AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_out_next),
            AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_in_previous),
            AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_out_previous) };

    // Upload Bar
    findViewById(R.id.upload_progress).setOnClickListener(dismissUploadStatus);
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    // NOTE: Do NOT do this. Ever. This is a terrible and horrifying hack.
    ////from w w w .  jav a 2  s  .c o  m
    // Home loads the content of the workspace on a background thread. This
    // means that
    // a previously focused view will be, after orientation change, added to
    // the view
    // hierarchy at an undeterminate time in the future. If we were to
    // invoke
    // super.onRestoreInstanceState() here, the focus restoration would fail
    // because the
    // view to focus does not exist yet.
    //
    // However, not invoking super.onRestoreInstanceState() is equally bad.
    // In such a case,
    // panels would not be restored properly. For instance, if the menu is
    // open then the
    // user changes the orientation, the menu would not be opened in the new
    // orientation.
    //
    // To solve both issues Home messes up with the internal state of the
    // bundle to remove
    // the properties it does not want to see restored at this moment. After
    // invoking
    // super.onRestoreInstanceState(), it removes the panels state.
    //
    // Later, when the workspace is done loading, Home calls
    // super.onRestoreInstanceState()
    // again to restore focus and other view properties. It will not,
    // however, restore
    // the panels since at this point the panels' state has been removed
    // from the bundle.
    //
    // This is a bad example, do not do this.
    //
    // If you are curious on how this code was put together, take a look at
    // the following
    // in Android's source code:
    // - Activity.onRestoreInstanceState()
    // - PhoneWindow.restoreHierarchyState()
    // - PhoneWindow.DecorView.onAttachedToWindow()
    //
    // The source code of these various methods shows what states should be
    // kept to
    // achieve what we want here.

    Bundle windowState = savedInstanceState.getBundle("android:viewHierarchyState");
    SparseArray<Parcelable> savedStates = null;
    int focusedViewId = View.NO_ID;

    if (windowState != null) {
        savedStates = windowState.getSparseParcelableArray("android:views");
        windowState.remove("android:views");
        focusedViewId = windowState.getInt("android:focusedViewId", View.NO_ID);
        windowState.remove("android:focusedViewId");
    }

    super.onRestoreInstanceState(savedInstanceState);

    if (windowState != null) {
        windowState.putSparseParcelableArray("android:views", savedStates);
        windowState.putInt("android:focusedViewId", focusedViewId);
        windowState.remove("android:Panels");
    }

    mSavedInstanceState = savedInstanceState;
}