| 1 |
package ${packageName}; |
| 2 |
|
| 3 |
import ${superClassFqcn}; |
| 4 |
import android.<#if appCompat>support.v7.</#if>app.ActionBar; |
| 5 |
import android.<#if appCompat>support.v4.</#if>app.Fragment; |
| 6 |
import android.content.Context; |
| 7 |
import android.os.Build; |
| 8 |
import android.os.Bundle; |
| 9 |
import android.view.Gravity; |
| 10 |
import android.view.LayoutInflater; |
| 11 |
import android.view.Menu; |
| 12 |
import android.view.MenuItem; |
| 13 |
import android.view.View; |
| 14 |
import android.view.ViewGroup; |
| 15 |
import android.widget.ArrayAdapter; |
| 16 |
import android.widget.TextView; |
| 17 |
<#if applicationPackage??> |
| 18 |
import ${applicationPackage}.R; |
| 19 |
</#if> |
| 20 |
|
| 21 |
public class ${activityClass} extends ${superClass} implements ActionBar.OnNavigationListener { |
| 22 |
|
| 23 |
/** |
| 24 |
* The serialization (saved instance state) Bundle key representing the |
| 25 |
* current dropdown position. |
| 26 |
*/ |
| 27 |
private static final String STATE_SELECTED_NAVIGATION_ITEM = "selected_navigation_item"; |
| 28 |
|
| 29 |
@Override |
| 30 |
protected void onCreate(Bundle savedInstanceState) { |
| 31 |
super.onCreate(savedInstanceState); |
| 32 |
setContentView(R.layout.${layoutName}); |
| 33 |
|
| 34 |
// Set up the action bar to show a dropdown list. |
| 35 |
final ActionBar actionBar = get${Support}ActionBar(); |
| 36 |
actionBar.setDisplayShowTitleEnabled(false); |
| 37 |
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); |
| 38 |
<#if parentActivityClass != ""> |
| 39 |
// Show the Up button in the action bar. |
| 40 |
actionBar.setDisplayHomeAsUpEnabled(true); |
| 41 |
</#if> |
| 42 |
|
| 43 |
// Set up the dropdown list navigation in the action bar. |
| 44 |
actionBar.setListNavigationCallbacks( |
| 45 |
// Specify a SpinnerAdapter to populate the dropdown list. |
| 46 |
new ArrayAdapter<String>( |
| 47 |
actionBar.getThemedContext(), |
| 48 |
android.R.layout.simple_list_item_1, |
| 49 |
android.R.id.text1, |
| 50 |
new String[] { |
| 51 |
"Section 1", |
| 52 |
"Section 2", |
| 53 |
"Section 3", |
| 54 |
}), |
| 55 |
this); |
| 56 |
} |
| 57 |
|
| 58 |
@Override |
| 59 |
public void onRestoreInstanceState(Bundle savedInstanceState) { |
| 60 |
// Restore the previously serialized current dropdown position. |
| 61 |
if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) { |
| 62 |
get${Support}ActionBar().setSelectedNavigationItem( |
| 63 |
savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM)); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
@Override |
| 68 |
public void onSaveInstanceState(Bundle outState) { |
| 69 |
// Serialize the current dropdown position. |
| 70 |
outState.putInt(STATE_SELECTED_NAVIGATION_ITEM, |
| 71 |
get${Support}ActionBar().getSelectedNavigationIndex()); |
| 72 |
} |
| 73 |
|
| 74 |
<#include "include_options_menu.java.ftl"> |
| 75 |
|
| 76 |
@Override |
| 77 |
public boolean onNavigationItemSelected(int position, long id) { |
| 78 |
// When the given dropdown item is selected, show its contents in the |
| 79 |
// container view. |
| 80 |
get${Support}FragmentManager().beginTransaction() |
| 81 |
.replace(R.id.container, PlaceholderFragment.newInstance(position + 1)) |
| 82 |
.commit(); |
| 83 |
return true; |
| 84 |
} |
| 85 |
|
| 86 |
<#include "include_fragment.java.ftl"> |
| 87 |
|
| 88 |
} |