Android Open Source - Skeleton Flow Bundler






From Project

Back to project page Skeleton.

License

The source code is released under:

Apache License

If you think the Android project Skeleton listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.gordon.skeleton.flow;
/*// w w w.j a  v a  2s.co m
 * Copyright 2014 Square Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import android.os.Bundle;

import flow.Backstack;
import flow.Flow;
import flow.Parcer;

/**
 * Handles Bundle persistence of a Flow.
 */
public class FlowBundler {
    private static final String FLOW_KEY = "flow_key";

    private final Object defaultScreen;
    private final Flow.Listener listener;
    private final Parcer<Object> parcer;

    private Flow flow;

    public FlowBundler(Object defaultScreen, Flow.Listener listener, Parcer<Object> parcer) {
        this.listener = listener;
        this.defaultScreen = defaultScreen;
        this.parcer = parcer;
    }

    public void onCreate(Bundle savedInstanceState) {
        Backstack backstack;
        if (savedInstanceState != null && savedInstanceState.containsKey(FLOW_KEY)) {
            backstack = Backstack.from(savedInstanceState.getParcelable(FLOW_KEY), parcer);
        } else {
            backstack = Backstack.fromUpChain(defaultScreen);
        }
        flow = new Flow(backstack, listener);
    }

    public void onSaveInstanceState(Bundle outState) {
        Backstack backstack = getBackstackToSave(flow.getBackstack());
        if (backstack == null) return;
        outState.putParcelable(FLOW_KEY, backstack.getParcelable(parcer));
    }

    public final Flow getFlow() {
        return flow;
    }

    /**
     * Returns the backstack that should be archived by {@link #onSaveInstanceState}. Overriding
     * allows subclasses to handle cases where the current configuration is not one that should
     * survive process death.  The default implementation returns a BackStackToSave that specifies
     * that view state should be persisted.
     *
     * @return the stack to archive, or null to archive nothing
     */
    protected Backstack getBackstackToSave(Backstack backstack) {
        return backstack;
    }
}




Java Source Code List

com.gordon.skeleton.ApplicationTest.java
com.gordon.skeleton.SkeletonActivity.java
com.gordon.skeleton.annotations.AnnotationHelper.java
com.gordon.skeleton.annotations.LayoutHelper.java
com.gordon.skeleton.annotations.MenuLayout.java
com.gordon.skeleton.containers.Container.java
com.gordon.skeleton.flow.FlowBundler.java
com.gordon.skeleton.flow.GsonParcer.java
com.gordon.skeleton.presenters.Presenter.java
com.gordon.skeleton.screens.ScreenManager.java
com.gordon.skeleton.screens.ScreenSwitcher.java
com.gordon.skeleton.screens.Screen.java
com.gordon.skeleton.utils.SkeletonDialog.java