Skip to content

Instantly share code, notes, and snippets.

@togi
Created August 8, 2012 13:17
Show Gist options
  • Save togi/3294971 to your computer and use it in GitHub Desktop.
Save togi/3294971 to your computer and use it in GitHub Desktop.
public class Page {
PageObservable mPageObservable = new PageObservable();
private Context mContext;
private ViewGroup mParent;
private View mView;
private int mID;
private boolean mIsInFront;
public Page(Context context, ViewGroup parent) {
mContext = context;
mParent = parent;
mIsInFront = false;
}
public int getId() {
return mID;
}
public void setId(int id) {
mID = id;
}
public void setContentView(int resId) {
setContentView(getLayoutInflater().inflate(resId, mParent, false));
}
public void setContentView(View view) {
mView = view;
mID = mView.getId();
}
public Context getContext() {
return mContext;
}
public View getView() {
return mView;
}
public View findViewById(int resId) {
if (mView != null)
return mView.findViewById(resId);
return null;
}
public LayoutInflater getLayoutInflater() {
return (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void registerPageObserver(PageObserver observer) {
mPageObservable.registerObserver(observer);
}
public void unregisterPageObserver(PageObserver observer) {
mPageObservable.unregisterObserver(observer);
}
public void notifyPageChanged() {
mPageObservable.notifyPageChanged();
}
public void onSaveInstanceState(Bundle bundle) {
SparseArray<Parcelable> container = new SparseArray<Parcelable>();
mView.saveHierarchyState(container);
bundle.putSparseParcelableArray("view-state", container);
}
public void onRestoreInstanceState(Bundle bundle) {
SparseArray<Parcelable> container = bundle.getSparseParcelableArray("view-state");
mView.restoreHierarchyState(container);
}
public void onAppear() {
mIsInFront = true;
}
public void onDisappear() {
mIsInFront = false;
}
public boolean isInFront() {
return mIsInFront;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment