Roll NDK to pick std::deque patch.
[android_tools.git] / sdk / tools / templates / activities / MasterDetailFlow / root / src / app_package / ContentListActivity.java.ftl
blob8e8ac58fd8e149a0ce82ba8b48b9d9282b88708a
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>
10 /**
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.
17  * <p>
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}.
21  * <p>
22  * This activity also implements the required
23  * {@link ${CollectionName}Fragment.Callbacks} interface
24  * to listen for item selections.
25  */
26 public class ${CollectionName}Activity extends ${(appCompat)?string('Fragment','')}Activity
27         implements ${CollectionName}Fragment.Callbacks {
29     /**
30      * Whether or not the activity is in two-pane mode, i.e. running on a tablet
31      * device.
32      */
33     private boolean mTwoPane;
35     @Override
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);
42         </#if>
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.
49             mTwoPane = true;
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);
56         }
58         // TODO: If exposing deep links into your app, handle intents here.
59     }
60     <#if parentActivityClass != "">
62     @Override
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:
70             //
71             // http://developer.android.com/design/patterns/navigation.html#up-vs-back
72             //
73             ${(minApiLevel lt 16)?string('NavUtils.','')}navigateUpFromSameTask(this);
74             return true;
75         }
76         return super.onOptionsItemSelected(item);
77     }
78     </#if>
80     /**
81      * Callback method from {@link ${CollectionName}Fragment.Callbacks}
82      * indicating that the item with the given ID was selected.
83      */
84     @Override
85     public void onItemSelected(String id) {
86         if (mTwoPane) {
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)
96                     .commit();
98         } else {
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);
104         }
105     }