Android Open Source - Skeleton Screen






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.screens;
/*from ww w  .j  ava  2  s  . c om*/
import android.content.Context;
import android.os.Parcelable;
import android.util.SparseArray;
import android.view.MenuItem;
import android.view.View;

/**
 * Created by kg on 10/31/14.
 */
public abstract class Screen implements View.OnAttachStateChangeListener {

    public abstract String getTitle(Context context);

    protected transient ScreenManager screenManager;
    private transient View view;
    private transient SparseArray<Parcelable> viewStateArray;

    public final void onViewCreated(View view, ScreenManager screenManager) {
        this.view = view;
        this.screenManager = screenManager;

        screenManager.setDisplayHomeAsUpEnabled(false); // default to not showing home icon
        onViewCreated(view);
        view.addOnAttachStateChangeListener(this);
    }

    @Override
    public final void onViewAttachedToWindow(View view) {
        if (viewStateArray != null) {
            view.restoreHierarchyState(viewStateArray);
        }

        onViewAttached();
    }

    @Override
    public final void onViewDetachedFromWindow(View view) {
        viewStateArray = new SparseArray<>();
        view.saveHierarchyState(viewStateArray);
        onViewDetached();
        tearDown();
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        return false;
    }

    protected void onViewCreated(View view) {
        // Event hook
    }

    protected void onViewAttached() {
        // Event hook
    }

    protected void onViewDetached() {
        // Event hook
    }

    protected Context getContext() {
        return view.getContext();
    }

    protected <T extends View> T findViewById(int viewResId) {
        return (T) view.findViewById(viewResId);
    }

    private void tearDown() {
        view = null;
        screenManager = null;
    }
}




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