If you think the Android project utexas-utilities 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.mapsaurus.paneslayout;
/*www.java2s.com*/import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.MenuItem;
import com.mapsaurus.paneslayout.PanesSizer.PaneSizer;
publicabstractclass PanesActivity extends SherlockFragmentActivity implements FragmentLauncher{
private ActivityDelegate mDelegate;
@Override
publicvoid onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
mDelegate.onSaveInstanceState(savedInstanceState);
}
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getResources().getBoolean(R.bool.largeScreen)) {
mDelegate = new TabletDelegate(this);
} else {
mDelegate = new PhoneDelegate(this);
}
mDelegate.onCreate(savedInstanceState);
}
/* *********************************************************************
* Deal with over-riding activity methods
* ********************************************************************* *//**
* Deal with menu buttons
*/
@Override
publicboolean onOptionsItemSelected(MenuItem item) {
if (mDelegate.onOptionsItemSelected(item)) return true;
return super.onOptionsItemSelected(item);
}
@Override
protectedvoid onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDelegate.onPostCreate(savedInstanceState);
}
@Override
publicvoid onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDelegate.onConfigurationChanged(newConfig);
}
/**
* Deal with back pressed
*/
@Override
publicvoid onBackPressed() {
if (onBackPressedHelper()) return;
super.onBackPressed();
}
protectedboolean onBackPressedHelper() {
if (mDelegate.onBackPressed()) return true;
return false;
}
/* *********************************************************************
* Adding, removing, getting fragments
*
* Note: fragments are added in a stack. Here's a sample use case:
*
* setMenuFragment(A)
* stack: A
*
* addFragment(A, B)
* stack: A, B
*
* addFragment(B, C)
* stack: A, B, C
*
* addFragment(B, D)
* stack: A, B, D
*
* clearFragments()
* stack: A
*
* ********************************************************************* *//**
* Add a new fragment after the previous fragment.
*/
@Override
publicvoid addFragment(Fragment prevFragment, Fragment newFragment) {
mDelegate.addFragment(prevFragment, newFragment);
}
/**
* Add a fragment as a menu
*/publicvoid setMenuFragment(Fragment f) {
mDelegate.setMenuFragment(f);
}
/**
* Clear all fragments from stack except the menu fragment
*/publicvoid clearFragments() {
mDelegate.clearFragments();
}
/**
* Get menu fragment
*/public Fragment getMenuFragment() {
return mDelegate.getMenuFragment();
}
/**
* Get top fragment
*/public Fragment getTopFragment() {
return mDelegate.getTopFragment();
}
/**
* Show the menu
*/publicvoid showMenu() {
mDelegate.showMenu();
}
/**
* Show the content
*/publicvoid showContent() {
mDelegate.showContent();
}
/* *********************************************************************
* Setup tablet or phone delegates
* ********************************************************************* *//**
* Set the pane sizer
*/publicvoid setPaneSizer(PaneSizer sizer) {
if (mDelegate instanceof TabletDelegate)
((TabletDelegate) mDelegate).setPaneSizer(sizer);
}
public Fragment getFragment(int index) {
if (mDelegate instanceof TabletDelegate)
return ((TabletDelegate) mDelegate).getFragment(index);
elsethrownew IllegalStateException("Can't call getFragment() when you're on a phone.");
}
}