Example usage for android.os Bundle getParcelableArray

List of usage examples for android.os Bundle getParcelableArray

Introduction

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

Prototype

@Nullable
public Parcelable[] getParcelableArray(@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.example.newfragmentstatepageradapter.NewFragmentStatePagerAdapter.java

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);/*from   w w w . ja  v  a2  s  .  c  o  m*/
        mItemIds = bundle.getLongArray("itemids");
        if (mItemIds == null) {
            mItemIds = new long[] {};
        }
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (int i = 0; i < fss.length; i++) {
                mSavedState.add((Fragment.SavedState) fss[i]);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}

From source file:com.github.paradam.support.v4.infinitepager.InfiniteFragmentStatePagerAdapter.java

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);/*from  w w  w .  ja  v a  2s  .  c om*/
        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (Parcelable ss : fss) {
                mSavedState.add((Fragment.SavedState) ss);
            }
        }
        int currentPrimaryItem = bundle.getInt("currentPrimaryItem");
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = null;
                try {
                    f = mFragmentManager.getFragment(bundle, key);
                } catch (Exception e) {
                    Log.e(TAG, e.getMessage(), e);
                }
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(currentPrimaryItem == index);
                    f.setUserVisibleHint(currentPrimaryItem == index);
                    mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}

From source file:com.kevinread.sortablefragmentpager.SortableFragmentStatePagerAdapter.java

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);//from www . ja  v  a2 s . c  o m

        mItemIds = bundle.getLongArray("itemids");
        if (mItemIds == null) {
            mItemIds = new long[] {};
        }

        Parcelable[] fss = bundle.getParcelableArray("states");
        mSavedState.clear();
        mFragments.clear();
        if (fss != null) {
            for (int i = 0; i < fss.length; i++) {
                mSavedState.add((Fragment.SavedState) fss[i]);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (mFragments.size() <= index) {
                        mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
        checkForIdChanges();
    }
}

From source file:de.spiritcroc.ownlog.ui.fragment.MultiSelectTagDialog.java

private boolean restoreValues(Bundle savedInstanceState) {
    if (savedInstanceState == null) {
        return false;
    }//  w w  w  .  j a  v  a  2  s.c om
    try {
        if (savedInstanceState.containsKey(KEY_LOG_ITEMS)) {
            mEditItems = (LogItem[]) savedInstanceState.getParcelableArray(KEY_LOG_ITEMS);
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

From source file:com.github.michalbednarski.intentslab.bindservice.InvokeAidlMethodFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);//from ww w. j av a 2s. c  om
    setHasOptionsMenu(true);

    // Prepare editor launcher
    mEditorLauncher = EditorLauncher.getForFragment(this);

    // Restore method arguments from state
    if (savedInstanceState != null) {
        mMethodArgumentsToRestore = (SandboxedObject[]) Utils.deepCastArray(
                savedInstanceState.getParcelableArray(STATE_METHOD_ARGUMENTS), SandboxedObject[].class);
    }

    // Read arguments and continue to preparing aidl
    Bundle args = getArguments();
    mMethodNumber = args.getInt(ARG_METHOD_NUMBER);
    getServiceHelper().prepareAidlAndRunWhenReady(getActivity(), this);
}

From source file:com.repkap11.repcast.activities.RepcastActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Utils.showUpdateDialogIfNecessary(this);
    setContentView(R.layout.activity_repcast);
    if (savedInstanceState == null) {
        mPagerAdapter = new RepcastPageAdapter(getSupportFragmentManager(), this, getApplicationContext());
    } else {//from w  w  w  .  j  av  a2s  .c  o m
        mBackSelectFileFragments
                .addAll(Arrays.asList(savedInstanceState.getParcelableArray(INSTANCE_STATE_BACK_STACK_FILES)));
        mBackTorrentFragments.addAll(
                Arrays.asList(savedInstanceState.getParcelableArray(INSTANCE_STATE_BACK_STACK_TORRENTS)));
        mPagerAdapter = new RepcastPageAdapter(getSupportFragmentManager(), getApplicationContext(),
                (JsonDirectory.JsonFileDir) mBackSelectFileFragments.peek(),
                (JsonTorrent.JsonTorrentResult) mBackTorrentFragments.peek());
    }
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    mViewPager = (ViewPager) findViewById(R.id.viewpager);
    mViewPager.setAdapter(mPagerAdapter);
    mViewPager.setCurrentItem(RepcastPageAdapter.FILE_INDEX);
    mViewPager.addOnPageChangeListener(this);

    completeOnCreate(savedInstanceState, true);
    tabLayout.setupWithViewPager(mViewPager);
}

From source file:org.openintents.safe.SearchFragment.java

/**
 * Restore results from onSaveInstanceState()
 *///from   w w  w.  j  a  v a  2 s .c  om
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (debug) {
        Log.d(TAG, "onActivityCreated(" + savedInstanceState + ")");
    }

    if ((savedInstanceState != null) && (savedInstanceState.containsKey(KEY_RESULTS)) && (results != null)) {
        Parcelable[] parcels = savedInstanceState.getParcelableArray(KEY_RESULTS);
        for (Parcelable par : parcels) {
            results.add((SearchEntry) par);
        }
        if (results.size() > 0) {
            updateResultsInUi();
        }
    }
}

From source file:net.alexjf.tmm.activities.MoneyNodeDetailsActivity.java

@Override
public void onAsyncTaskResultSuccess(String taskId, Bundle result) {
    immedTransAdapter.setNotifyOnChange(false);
    immedTransAdapter.clear();//from  w ww  .  j  av a2 s.c  o  m

    income = Money.zero(currency);
    expense = Money.zero(currency);
    ImmediateTransaction[] immediateTransactions = (ImmediateTransaction[]) result
            .getParcelableArray(KEY_IMMEDIATETRANSACTIONS);
    for (ImmediateTransaction transaction : immediateTransactions) {
        try {
            transaction.load();
        } catch (DatabaseException e) {
            Log.e("TMM", "Error loading transaction " + transaction.getId(), e);
            continue;
        }

        Money value = transaction.getValue();

        if (value.isPositive()) {
            income = income.plus(value);
        } else if (value.isNegative()) {
            expense = expense.plus(value);
        }

        immedTransAdapter.add(transaction);
    }

    updateGui();
    transactionTask = null;
    Utils.allowOrientationChanges(this);
}

From source file:uk.co.threeonefour.android.snowball.activities.game.GameActivity.java

@Override
public void onRestoreInstanceState(Bundle restoreInstanceState) {

    if (initialised) {
        level9.setGameState((GameState) restoreInstanceState.getParcelable(GAME_STATE));
        ramSaveSlots = (RamSave[]) restoreInstanceState.getParcelableArray(RAM_SAVE_SLOTS_STATE);
        imageView.setBitmap((Bitmap) restoreInstanceState.getParcelable(IMAGE_STATE));
        gameStateSlot = restoreInstanceState.getInt(GAME_STATE_SLOT);
    } else {//from w  w w .  ja v  a2 s  .  c o  m
        restoredGameState = (GameState) restoreInstanceState.getParcelable(GAME_STATE);
        restoredRamSaveSlots = (RamSave[]) restoreInstanceState.getParcelableArray(RAM_SAVE_SLOTS_STATE);
        restoredBitmap = (Bitmap) restoreInstanceState.getParcelable(IMAGE_STATE);
        restoredGameStateSlot = restoreInstanceState.getInt(GAME_STATE_SLOT);
    }

    // Always call the superclass so it can save the view hierarchy state
    super.onRestoreInstanceState(restoreInstanceState);
}