Search in sources :

Example 1 with BackstackDelegate

use of com.zhuinden.simplestack.BackstackDelegate in project simple-stack by Zhuinden.

the class MainActivity method onCreate.

/**
     * Pay attention to the {@link #setContentView} call here. It's creating a responsive layout
     * for us.
     * <p>
     * Notice that the app has two root_layout files. The main one, in {@code res/layout} is used by
     * mobile devices and by tablets in portrait orientation. It holds a generic {@link
     * com.example.stackmasterdetailfrag.util.pathview.SinglePaneRoot}.
     * <p>
     * The interesting one, loaded by tablets in landscape mode, is {@code res/layout-sw600dp-land}.
     * It loads a {@link TabletMasterDetailRoot}, with a master list on the
     * left and a detail view on the right.
     * <p>
     * But this master activity knows nothing about those two view types. It only requires that
     * the view loaded by {@code root_layout.xml} implements the StateChanger interface,
     * to render whatever is appropriate for the screens received from {@link com.zhuinden.simplestack.Backstack} via
     * {@link #handleStateChange}.
     */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowHomeEnabled(false);
    backstackDelegate = new BackstackDelegate(null);
    backstackDelegate.setStateClearStrategy(new MasterDetailStateClearStrategy());
    backstackDelegate.onCreate(savedInstanceState, getLastCustomNonConfigurationInstance(), HistoryBuilder.single(ConversationListPath.create()));
    setContentView(R.layout.root_layout);
    container = (StateChanger) findViewById(R.id.container);
    containerAsBackTarget = (HandlesBack) container;
    backstackDelegate.setStateChanger(this);
}
Also used : MasterDetailStateClearStrategy(com.example.stackmasterdetailfrag.util.MasterDetailStateClearStrategy) BackstackDelegate(com.zhuinden.simplestack.BackstackDelegate) ActionBar(android.support.v7.app.ActionBar)

Example 2 with BackstackDelegate

use of com.zhuinden.simplestack.BackstackDelegate in project simple-stack by Zhuinden.

the class Multistack method restoreViewFromState.

public void restoreViewFromState(View view) {
    Key key = Backstack.getKey(view.getContext());
    BackstackDelegate backstackDelegate = key.selectDelegate(view.getContext());
    backstackDelegate.restoreViewFromState(view);
}
Also used : BackstackDelegate(com.zhuinden.simplestack.BackstackDelegate) Key(com.zhuinden.simplestackdemomultistack.application.Key)

Example 3 with BackstackDelegate

use of com.zhuinden.simplestack.BackstackDelegate in project simple-stack by Zhuinden.

the class Multistack method persistViewToState.

public void persistViewToState(View view) {
    if (view != null) {
        Key key = Backstack.getKey(view.getContext());
        BackstackDelegate backstackDelegate = key.selectDelegate(view.getContext());
        backstackDelegate.persistViewToState(view);
    }
}
Also used : BackstackDelegate(com.zhuinden.simplestack.BackstackDelegate) Key(com.zhuinden.simplestackdemomultistack.application.Key)

Example 4 with BackstackDelegate

use of com.zhuinden.simplestack.BackstackDelegate in project simple-stack by Zhuinden.

the class BackstackDelegateActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    backstackDelegate = new BackstackDelegate(null);
    //
    backstackDelegate.onCreate(//
    savedInstanceState, //
    getLastCustomNonConfigurationInstance(), HistoryBuilder.single(FirstKey.create()));
    defaultStateChanger = DefaultStateChanger.configure().setStatePersistenceStrategy(new DefaultStateChanger.StatePersistenceStrategy() {

        @Override
        public void persistViewToState(@NonNull Object previousKey, @NonNull View previousView) {
            backstackDelegate.persistViewToState(previousView);
        }

        @Override
        public void restoreViewFromState(@NonNull Object newKey, @NonNull View newView) {
            backstackDelegate.restoreViewFromState(newView);
        }
    }).create(this, root);
    backstackDelegate.setStateChanger(defaultStateChanger);
}
Also used : BackstackDelegate(com.zhuinden.simplestack.BackstackDelegate) DefaultStateChanger(com.zhuinden.simplestack.navigator.DefaultStateChanger) BindView(butterknife.BindView) View(android.view.View)

Example 5 with BackstackDelegate

use of com.zhuinden.simplestack.BackstackDelegate in project simple-stack by Zhuinden.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    this.multistack = new Multistack();
    multistack.add(CLOUDSYNC.name(), new BackstackDelegate(null));
    multistack.add(CHROMECAST.name(), new BackstackDelegate(null));
    multistack.add(MAIL.name(), new BackstackDelegate(null));
    multistack.add(LIST.name(), new BackstackDelegate(null));
    Multistack.NonConfigurationInstance nonConfigurationInstance = (Multistack.NonConfigurationInstance) getLastCustomNonConfigurationInstance();
    multistack.onCreate(savedInstanceState);
    multistack.onCreate(CLOUDSYNC.name(), savedInstanceState, nonConfigurationInstance, CloudSyncKey.create());
    multistack.onCreate(CHROMECAST.name(), savedInstanceState, nonConfigurationInstance, ChromeCastKey.create());
    multistack.onCreate(MAIL.name(), savedInstanceState, nonConfigurationInstance, MailKey.create());
    multistack.onCreate(LIST.name(), savedInstanceState, nonConfigurationInstance, ListKey.create());
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    bottomNavigation.setOnMenuItemClickListener(new BottomNavigation.OnMenuItemSelectionListener() {

        @Override
        public void onMenuItemSelect(@IdRes int menuItemId, int itemIndex, boolean b) {
            multistack.setSelectedStack(StackType.values()[itemIndex].name());
        }

        @Override
        public void onMenuItemReselect(@IdRes int menuItemId, int itemIndex, boolean b) {
        }
    });
    multistack.setStateChanger(this);
}
Also used : BottomNavigation(it.sephiroth.android.library.bottomnavigation.BottomNavigation) BackstackDelegate(com.zhuinden.simplestack.BackstackDelegate) Multistack(com.zhuinden.simplestackdemomultistack.util.Multistack)

Aggregations

BackstackDelegate (com.zhuinden.simplestack.BackstackDelegate)7 Key (com.zhuinden.simplestackdemomultistack.application.Key)2 ActionBar (android.support.v7.app.ActionBar)1 View (android.view.View)1 BindView (butterknife.BindView)1 MasterDetailStateClearStrategy (com.example.stackmasterdetailfrag.util.MasterDetailStateClearStrategy)1 DefaultStateChanger (com.zhuinden.simplestack.navigator.DefaultStateChanger)1 FragmentStateChanger (com.zhuinden.simplestackdemoexamplefragments.util.FragmentStateChanger)1 Multistack (com.zhuinden.simplestackdemomultistack.util.Multistack)1 BottomNavigation (it.sephiroth.android.library.bottomnavigation.BottomNavigation)1