Back to project page Skeleton.
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.
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; } }