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.example.jonas.materialmockups.activities.ExhibitDetailsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);// w  ww .  j a v a2s. c  om

    // generated
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    // select first menu item on startup
    navigationView.getMenu().getItem(0).setChecked(true);

    if (savedInstanceState != null) {
        // activity re-creation because of device rotation, instant run, ...

        exhibitPages = (List<Page>) savedInstanceState.getSerializable(KEY_EXHIBIT_PAGES);
        currentPageIndex = savedInstanceState.getInt(KEY_CURRENT_PAGE_INDEX, 0);
        isAudioPlaying = savedInstanceState.getBoolean(KEY_AUDIO_PLAYING, false);
        isAudioToolbarHidden = true;
        extras = savedInstanceState.getBundle(KEY_EXTRAS);

        if (exhibitPages == null)
            throw new NullPointerException("exhibitPages cannot be null!");

    } else {
        // activity creation because of intent
        Intent intent = getIntent();
        extras = intent.getExtras();
        // TODO: extract pages from exhibit contained in intent instead of subsequent init
        exhibitPages.add(new Page(ExhibitPageFragment.Type.APPETIZER));
        for (int noOfPages = 3; noOfPages > 0; noOfPages--)
            exhibitPages.add(new Page(ExhibitPageFragment.Type.IMAGE));
    }

    // set up bottom sheet behavior
    bottomSheet = findViewById(R.id.bottom_sheet);
    bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
    bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
        @Override
        public void onStateChanged(@NonNull View bottomSheet, int newState) {
            if (fabAction != BottomSheetConfig.FabAction.NEXT) {
                if (newState == BottomSheetBehavior.STATE_EXPANDED)
                    setFabCollapseAction();
                else if (newState == BottomSheetBehavior.STATE_COLLAPSED)
                    setFabExpandAction();
                else {
                    /* we don't care about any other state */}
            }
        }

        @Override
        public void onSlide(@NonNull View bottomSheet, float slideOffset) {
            // intentionally left blank
        }
    });

    // audio toolbar
    mRevealView = (LinearLayout) findViewById(R.id.reveal_items);
    mRevealView.setVisibility(View.INVISIBLE);

    // display audio toolbar on savedInstanceState:
    // if (! isAudioToolbarHidden) showAudioToolbar();
    // does not work because activity creation has not been completed?!

    // set up play / pause toggle
    btnPlayPause = (ImageButton) findViewById(R.id.btnPlayPause);
    btnPlayPause.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            togglePlayPause();
        }
    });

    btnPreviousPage = (ImageButton) findViewById(R.id.buttonPrevious);
    btnPreviousPage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            displayPreviousExhibitPage();
        }
    });

    btnNextPage = (ImageButton) findViewById(R.id.buttonNext);
    btnNextPage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            displayNextExhibitPage();
        }
    });

    fab = (FloatingActionButton) findViewById(R.id.fab);

    displayCurrentExhibitPage();

}

From source file:org.mifos.androidclient.main.CustomerDetailsActivity.java

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.customer_details);

    tabs = (TabHost) findViewById(R.id.customerDetails_tabhost);
    tabs.setup();/*from w  w  w .  j a  v a2  s .c o m*/
    TabHost.TabSpec overviewSpec = tabs.newTabSpec(getString(R.string.customerDetails_tab_overview));
    overviewSpec.setIndicator(getString(R.string.customerDetails_tab_overview));
    overviewSpec.setContent(R.id.customer_overview);
    TabHost.TabSpec accountsSpec = tabs.newTabSpec(getString(R.string.customerDetails_tab_accounts));
    accountsSpec.setIndicator(getString(R.string.customerDetails_tab_accounts));
    accountsSpec.setContent(R.id.customer_accounts);
    TabHost.TabSpec additionalSpec = tabs.newTabSpec(getString(R.string.customerDetails_tab_additional));
    additionalSpec.setIndicator(getString(R.string.customerDetails_tab_additional));
    additionalSpec.setContent(R.id.customer_additional);
    tabs.addTab(overviewSpec);
    tabs.addTab(accountsSpec);
    tabs.addTab(additionalSpec);
    TabColorUtils.setTabColor(tabs);
    tabs.setOnTabChangedListener(this);

    if (bundle != null) {
        if (bundle.containsKey(CustomerDetailsEntity.BUNDLE_KEY)) {
            mDetails = (CustomerDetailsEntity) bundle.getSerializable(CustomerDetailsEntity.BUNDLE_KEY);
        }
        if (bundle.containsKey(Fee.BUNDLE_KEY)) {
            mApplicableFees = (Map<String, Map<String, String>>) bundle.getSerializable(Fee.BUNDLE_KEY);
        }
        if (bundle.containsKey(SELECTED_TAB_BUNDLE_KEY)) {
            tabs.setCurrentTab(bundle.getInt(SELECTED_TAB_BUNDLE_KEY));
        }
    }

    if (getIntent().hasExtra("isGroup")) {
        isGroup = true;
    }

    mCustomer = (AbstractCustomer) getIntent().getSerializableExtra(AbstractCustomer.BUNDLE_KEY);
    mCustomerService = new CustomerService(this);
}

From source file:ca.six.unittestapp.todo.tasks.TasksActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tasks_act);/*from  w  w  w .j a v a 2s  . c  om*/

    // Set up the toolbar.
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar ab = getSupportActionBar();
    ab.setHomeAsUpIndicator(R.drawable.ic_menu);
    ab.setDisplayHomeAsUpEnabled(true);

    // Set up the navigation drawer.
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setStatusBarBackground(R.color.colorPrimaryDark);
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null) {
        setupDrawerContent(navigationView);
    }

    TasksFragment tasksFragment = (TasksFragment) getSupportFragmentManager()
            .findFragmentById(R.id.contentFrame);
    if (tasksFragment == null) {
        // Create the fragment
        tasksFragment = TasksFragment.newInstance();
        ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), tasksFragment, R.id.contentFrame);
    }

    // Create the presenter
    mTasksPresenter = new TasksPresenter(Injection.provideTasksRepository(getApplicationContext()),
            tasksFragment);

    // Load previously saved state, if available.
    if (savedInstanceState != null) {
        TasksFilterType currentFiltering = (TasksFilterType) savedInstanceState
                .getSerializable(CURRENT_FILTERING_KEY);
        mTasksPresenter.setFiltering(currentFiltering);
    }
}

From source file:com.mycelium.wallet.activity.send.SendMainActivity.java

@SuppressLint("ShowToast")
@Override/*  ww  w .  ja v a 2 s. co  m*/
public void onCreate(Bundle savedInstanceState) {
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.send_main_activity);
    _mbwManager = MbwManager.getInstance(getApplication());

    // Get intent parameters
    UUID accountId = Preconditions.checkNotNull((UUID) getIntent().getSerializableExtra("account"));

    // May be null
    _amountToSend = (Long) getIntent().getSerializableExtra("amountToSend");
    // May be null
    _receivingAddress = (Address) getIntent().getSerializableExtra("receivingAddress");
    //May be null
    _transactionLabel = getIntent().getStringExtra("transactionLabel");

    _isColdStorage = getIntent().getBooleanExtra("isColdStorage", false);
    _account = _mbwManager.getWalletManager(_isColdStorage).getAccount(accountId);

    // Load saved state, overwriting amount and address
    if (savedInstanceState != null) {
        _amountToSend = (Long) savedInstanceState.getSerializable("amountToSend");
        _receivingAddress = (Address) savedInstanceState.getSerializable("receivingAddress");
        _transactionLabel = savedInstanceState.getString("transactionLabel");
    }

    //check whether the account can spend, if not, ask user to select one
    if (_account.canSpend()) {
        // See if we can create the transaction with what we have
        _transactionStatus = tryCreateUnsignedTransaction();
    } else {
        //we need the user to pick a spending account - the activity will then init sendmain correctly
        BitcoinUri uri = new BitcoinUri(_receivingAddress, _amountToSend, _transactionLabel);
        GetSpendingRecordActivity.callMeWithResult(this, uri, REQUEST_PICK_ACCOUNT);
        //no matter whether the user did successfully send or tapped back - we do not want to stay here with a wrong account selected
        finish();
    }

    // Scan
    findViewById(R.id.btScan).setOnClickListener(scanClickListener);

    // Address Book
    findViewById(R.id.btAddressBook).setOnClickListener(addressBookClickListener);

    // Manual Entry
    findViewById(R.id.btManualEntry).setOnClickListener(manualEntryClickListener);

    // Clipboard
    findViewById(R.id.btClipboard).setOnClickListener(clipboardClickListener);

    // Enter Amount
    findViewById(R.id.btEnterAmount).setOnClickListener(amountClickListener);

    // Send button
    findViewById(R.id.btSend).setOnClickListener(sendClickListener);

    // Amount Hint
    ((TextView) findViewById(R.id.tvAmount)).setHint(getResources().getString(R.string.amount_hint_denomination,
            _mbwManager.getBitcoinDenomination().toString()));

}

From source file:github.popeen.dsub.fragments.SelectDirectoryFragment.java

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    if (bundle != null) {
        entries = (List<Entry>) bundle.getSerializable(Constants.FRAGMENT_LIST);
        albums = (List<Entry>) bundle.getSerializable(Constants.FRAGMENT_LIST2);
        if (albums == null) {
            albums = new ArrayList<>();
        }//from   w ww. j  a  v  a 2s .c o  m
        artistInfo = (ArtistInfo) bundle.getSerializable(Constants.FRAGMENT_EXTRA);
        restoredInstance = true;
    }
}

From source file:com.lastsoft.plog.PlayersFragment_Groups.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_players, container, false);
    rootView.setTag(TAG);/*from   w  ww  . j  a  v  a 2 s.c o  m*/

    // BEGIN_INCLUDE(initializeRecyclerView)
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
    RecyclerFastScroller fastScroller = (RecyclerFastScroller) rootView.findViewById(R.id.fastscroller);
    fastScroller.attachRecyclerView(mRecyclerView);
    //VerticalRecyclerViewFastScroller fastScroller = (VerticalRecyclerViewFastScroller) rootView.findViewById(R.id.fastscroller);

    // Connect the recycler to the scroller (to let the scroller scroll the list)
    //fastScroller.setRecyclerView(mRecyclerView, null);

    // Connect the scroller to the recycler (to let the recycler scroll the scroller's handle)
    //mRecyclerView.setOnScrollListener(fastScroller.getOnScrollListener());

    // LinearLayoutManager is used here, this will layout the elements in a similar fashion
    // to the way ListView would layout elements. The RecyclerView.LayoutManager defines how
    // elements are laid out.
    mLayoutManager = new LinearLayoutManager(mActivity);

    mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER;

    if (savedInstanceState != null) {
        // Restore saved layout manager type.
        mCurrentLayoutManagerType = (LayoutManagerType) savedInstanceState.getSerializable(KEY_LAYOUT_MANAGER);
    }
    setRecyclerViewLayoutManager(mCurrentLayoutManagerType);

    mAdapter = new GroupAdapter(mActivity, this, MainActivity.CurrentYear);
    // Set CustomAdapter as the adapter for RecyclerView.
    mRecyclerView.setAdapter(mAdapter);
    return rootView;
}

From source file:com.example.ray.firstapp.bottombar.BottomBar.java

private void onRestoreInstanceState(Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        mCurrentTabPosition = savedInstanceState.getInt(STATE_CURRENT_SELECTED_TAB, -1);
        mBadgeStateMap = (HashMap<Integer, Boolean>) savedInstanceState
                .getSerializable(STATE_BADGE_STATES_BUNDLE);

        if (mCurrentTabPosition == -1) {
            mCurrentTabPosition = 0;/*from ww  w  . j a  v a2  s . co m*/
            Log.e("BottomBar",
                    "You must override the Activity's onSave"
                            + "InstanceState(Bundle outState) and call BottomBar.onSaveInstanc"
                            + "eState(outState) there to restore the state properly.");
        }

        mIsComingFromRestoredState = true;
        mShouldUpdateFragmentInitially = true;
    }
}

From source file:com.android.fpuna.activityrecognition.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    // Get the UI widgets.
    mRequestActivityUpdatesButton = (Button) findViewById(R.id.request_activity_updates_button);
    mRemoveActivityUpdatesButton = (Button) findViewById(R.id.remove_activity_updates_button);
    mDetectedActivitiesListView = (ListView) findViewById(R.id.detected_activities_listview);

    // Get a receiver for broadcasts from ActivityDetectionIntentService.
    mBroadcastReceiver = new ActivityDetectionBroadcastReceiver();

    // Enable either the Request Updates button or the Remove Updates button depending on
    // whether activity updates have been requested.
    setButtonsEnabledState();/*w ww  .j  a  v  a2s. c  om*/

    // Reuse the value of mDetectedActivities from the bundle if possible. This maintains state
    // across device orientation changes. If mDetectedActivities is not stored in the bundle,
    // populate it with DetectedActivity objects whose confidence is set to 0. Doing this
    // ensures that the bar graphs for only only the most recently detected activities are
    // filled in.
    if (savedInstanceState != null && savedInstanceState.containsKey(Constants.DETECTED_ACTIVITIES)) {
        mDetectedActivities = (ArrayList<HumanActivity>) savedInstanceState
                .getSerializable(Constants.DETECTED_ACTIVITIES);
    } else {
        mDetectedActivities = new ArrayList<HumanActivity>();

        // Set the confidence level of each monitored activity to zero.
        for (int i = 0; i < Constants.MONITORED_ACTIVITIES.length; i++) {
            mDetectedActivities.add(new HumanActivity(Constants.MONITORED_ACTIVITIES[i], 0));
        }
    }

    // Bind the adapter to the ListView responsible for display data for detected activities.
    mAdapter = new DetectedActivitiesAdapter(this, mDetectedActivities);
    mDetectedActivitiesListView.setAdapter(mAdapter);

    // Kick off the request to build GoogleApiClient.
    buildApiClient();
}

From source file:com.lastsoft.plog.PlayersFragment_Players.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_players, container, false);
    rootView.setTag(TAG);/* ww w . j a va2 s  .c  o  m*/

    // BEGIN_INCLUDE(initializeRecyclerView)
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
    RecyclerFastScroller fastScroller = (RecyclerFastScroller) rootView.findViewById(R.id.fastscroller);
    fastScroller.attachRecyclerView(mRecyclerView);
    //VerticalRecyclerViewFastScroller fastScroller = (VerticalRecyclerViewFastScroller) rootView.findViewById(R.id.fastscroller);

    // Connect the recycler to the scroller (to let the scroller scroll the list)
    //fastScroller.setRecyclerView(mRecyclerView, null);

    // Connect the scroller to the recycler (to let the recycler scroll the scroller's handle)
    //mRecyclerView.setOnScrollListener(fastScroller.getOnScrollListener());

    // LinearLayoutManager is used here, this will layout the elements in a similar fashion
    // to the way ListView would layout elements. The RecyclerView.LayoutManager defines how
    // elements are laid out.
    mLayoutManager = new LinearLayoutManager(mActivity);

    mCurrentLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT_MANAGER;

    if (savedInstanceState != null) {
        // Restore saved layout manager type.
        mCurrentLayoutManagerType = (LayoutManagerType) savedInstanceState.getSerializable(KEY_LAYOUT_MANAGER);
    }
    setRecyclerViewLayoutManager(mCurrentLayoutManagerType);

    mAdapter = new PlayerAdapter(mActivity, this, MainActivity.CurrentYear);
    // Set CustomAdapter as the adapter for RecyclerView.
    mRecyclerView.setAdapter(mAdapter);

    fabMargin = getResources().getDimensionPixelSize(R.dimen.fab_margin);
    mRecyclerView.addOnScrollListener(new MyRecyclerScroll() {
        @Override
        public void show() {
            ((MainActivity) mActivity).showPlayerFAB();
        }

        @Override
        public void hide() {
            ((MainActivity) mActivity).hidePlayerFAB();

        }
    });

    return rootView;
}

From source file:com.irccloud.android.activity.PastebinsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= 21) {
        Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name),
                cloud, 0xFFF2F7FC));//from w  w  w. java2  s .  c om
        cloud.recycle();
    }

    setContentView(R.layout.ignorelist);

    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
        getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar));
        getSupportActionBar().setElevation(0);
    }

    if (savedInstanceState != null && savedInstanceState.containsKey("adapter")) {
        try {
            page = savedInstanceState.getInt("page");
            Pastebin[] pastebins = (Pastebin[]) savedInstanceState.getSerializable("adapter");
            for (Pastebin p : pastebins) {
                adapter.addPastebin(p);
            }
            adapter.notifyDataSetChanged();
        } catch (Exception e) {
            page = 0;
            adapter.clear();
        }
    }

    footer = getLayoutInflater().inflate(R.layout.messageview_header, null);
    ListView listView = (ListView) findViewById(android.R.id.list);
    listView.setAdapter(adapter);
    listView.addFooterView(footer);
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (canLoadMore && firstVisibleItem + visibleItemCount > totalItemCount - 4) {
                canLoadMore = false;
                new FetchPastebinsTask().execute((Void) null);
            }
        }
    });
    listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            final Pastebin p = (Pastebin) adapter.getItem(i);

            Intent intent = new Intent(PastebinsActivity.this, PastebinViewerActivity.class);
            intent.setData(Uri.parse(p.url + "?id=" + p.id + "&own_paste=" + (p.own_paste ? "1" : "0")));
            startActivity(intent);
        }
    });

    Toast.makeText(this, "Tap a pastebin to view full text with syntax highlighting", Toast.LENGTH_LONG).show();
}