| 1 |
package ${packageName}; |
| 2 |
|
| 3 |
import android.app.Activity; |
| 4 |
<#if appCompat>import android.support.v7.app.ActionBarActivity;</#if> |
| 5 |
import android.<#if appCompat>support.v7.</#if>app.ActionBar; |
| 6 |
import android.<#if appCompat>support.v4.</#if>app.Fragment; |
| 7 |
import android.<#if appCompat>support.v4.</#if>app.FragmentManager; |
| 8 |
import android.content.Context; |
| 9 |
import android.os.Build; |
| 10 |
import android.os.Bundle; |
| 11 |
import android.view.Gravity; |
| 12 |
import android.view.LayoutInflater; |
| 13 |
import android.view.Menu; |
| 14 |
import android.view.MenuItem; |
| 15 |
import android.view.View; |
| 16 |
import android.view.ViewGroup; |
| 17 |
import android.support.v4.widget.DrawerLayout; |
| 18 |
import android.widget.ArrayAdapter; |
| 19 |
import android.widget.TextView; |
| 20 |
<#if applicationPackage??>import ${applicationPackage}.R;</#if> |
| 21 |
|
| 22 |
public class ${activityClass} extends ${(appCompat)?string('ActionBar','')}Activity |
| 23 |
implements NavigationDrawerFragment.NavigationDrawerCallbacks { |
| 24 |
|
| 25 |
/** |
| 26 |
* Fragment managing the behaviors, interactions and presentation of the navigation drawer. |
| 27 |
*/ |
| 28 |
private NavigationDrawerFragment mNavigationDrawerFragment; |
| 29 |
|
| 30 |
/** |
| 31 |
* Used to store the last screen title. For use in {@link #restoreActionBar()}. |
| 32 |
*/ |
| 33 |
private CharSequence mTitle; |
| 34 |
|
| 35 |
@Override |
| 36 |
protected void onCreate(Bundle savedInstanceState) { |
| 37 |
super.onCreate(savedInstanceState); |
| 38 |
setContentView(R.layout.${layoutName}); |
| 39 |
|
| 40 |
mNavigationDrawerFragment = (NavigationDrawerFragment) |
| 41 |
get${Support}FragmentManager().findFragmentById(R.id.navigation_drawer); |
| 42 |
mTitle = getTitle(); |
| 43 |
|
| 44 |
// Set up the drawer. |
| 45 |
mNavigationDrawerFragment.setUp( |
| 46 |
R.id.navigation_drawer, |
| 47 |
(DrawerLayout) findViewById(R.id.drawer_layout)); |
| 48 |
} |
| 49 |
|
| 50 |
@Override |
| 51 |
public void onNavigationDrawerItemSelected(int position) { |
| 52 |
// update the main content by replacing fragments |
| 53 |
FragmentManager fragmentManager = get${Support}FragmentManager(); |
| 54 |
fragmentManager.beginTransaction() |
| 55 |
.replace(R.id.container, PlaceholderFragment.newInstance(position + 1)) |
| 56 |
.commit(); |
| 57 |
} |
| 58 |
|
| 59 |
public void onSectionAttached(int number) { |
| 60 |
switch (number) { |
| 61 |
case 1: |
| 62 |
mTitle = getString(R.string.title_section1); |
| 63 |
break; |
| 64 |
case 2: |
| 65 |
mTitle = getString(R.string.title_section2); |
| 66 |
break; |
| 67 |
case 3: |
| 68 |
mTitle = getString(R.string.title_section3); |
| 69 |
break; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
public void restoreActionBar() { |
| 74 |
ActionBar actionBar = get${Support}ActionBar(); |
| 75 |
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); |
| 76 |
actionBar.setDisplayShowTitleEnabled(true); |
| 77 |
actionBar.setTitle(mTitle); |
| 78 |
} |
| 79 |
|
| 80 |
<#include "include_options_menu.java.ftl"> |
| 81 |
|
| 82 |
<#include "include_fragment.java.ftl"> |
| 83 |
|
| 84 |
} |