1 package ${packageName};
3 import android.content.Intent;
4 import android.os.Bundle;
5 import <#if appCompat>android.support.v4.app.FragmentActivity<#else>android.app.Activity</#if>;
6 <#if (parentActivityClass != "" && minApiLevel lt 16)>import android.support.v4.app.NavUtils;</#if>
7 <#if parentActivityClass != "">import android.view.MenuItem;</#if>
8 <#if applicationPackage??>import ${applicationPackage}.R;</#if>
11 * An activity representing a list of ${objectKindPlural}. This activity
12 * has different presentations for handset and tablet-size devices. On
13 * handsets, the activity presents a list of items, which when touched,
14 * lead to a {@link ${DetailName}Activity} representing
15 * item details. On tablets, the activity presents the list of items and
16 * item details side-by-side using two vertical panes.
18 * The activity makes heavy use of fragments. The list of items is a
19 * {@link ${CollectionName}Fragment} and the item details
20 * (if present) is a {@link ${DetailName}Fragment}.
22 * This activity also implements the required
23 * {@link ${CollectionName}Fragment.Callbacks} interface
24 * to listen for item selections.
26 public class ${CollectionName}Activity extends ${(appCompat)?string('Fragment','')}Activity
27 implements ${CollectionName}Fragment.Callbacks {
30 * Whether or not the activity is in two-pane mode, i.e. running on a tablet
33 private boolean mTwoPane;
36 protected void onCreate(Bundle savedInstanceState) {
37 super.onCreate(savedInstanceState);
38 setContentView(R.layout.activity_${collection_name});
39 <#if parentActivityClass != "">
40 // Show the Up button in the action bar.
41 get${Support}ActionBar().setDisplayHomeAsUpEnabled(true);
44 if (findViewById(R.id.${detail_name}_container) != null) {
45 // The detail container view will be present only in the
46 // large-screen layouts (res/values-large and
47 // res/values-sw600dp). If this view is present, then the
48 // activity should be in two-pane mode.
51 // In two-pane mode, list items should be given the
52 // 'activated' state when touched.
53 ((${CollectionName}Fragment) get${Support}FragmentManager()
54 .findFragmentById(R.id.${collection_name}))
55 .setActivateOnItemClick(true);
58 // TODO: If exposing deep links into your app, handle intents here.
60 <#if parentActivityClass != "">
63 public boolean onOptionsItemSelected(MenuItem item) {
64 int id = item.getItemId();
65 if (id == android.R.id.home) {
66 // This ID represents the Home or Up button. In the case of this
67 // activity, the Up button is shown. Use NavUtils to allow users
68 // to navigate up one level in the application structure. For
69 // more details, see the Navigation pattern on Android Design:
71 // http://developer.android.com/design/patterns/navigation.html#up-vs-back
73 ${(minApiLevel lt 16)?string('NavUtils.','')}navigateUpFromSameTask(this);
76 return super.onOptionsItemSelected(item);
81 * Callback method from {@link ${CollectionName}Fragment.Callbacks}
82 * indicating that the item with the given ID was selected.
85 public void onItemSelected(String id) {
87 // In two-pane mode, show the detail view in this activity by
88 // adding or replacing the detail fragment using a
89 // fragment transaction.
90 Bundle arguments = new Bundle();
91 arguments.putString(${DetailName}Fragment.ARG_ITEM_ID, id);
92 ${DetailName}Fragment fragment = new ${DetailName}Fragment();
93 fragment.setArguments(arguments);
94 get${Support}FragmentManager().beginTransaction()
95 .replace(R.id.${detail_name}_container, fragment)
99 // In single-pane mode, simply start the detail activity
100 // for the selected item ID.
101 Intent detailIntent = new Intent(this, ${DetailName}Activity.class);
102 detailIntent.putExtra(${DetailName}Fragment.ARG_ITEM_ID, id);
103 startActivity(detailIntent);