Debian Codegraph @

templates/eclipse/activities/MasterDetailFlow/root/src/app_package/ContentDetailActivity.java.ftl

raw
1 package ${packageName};
2
3 import android.content.Intent;
4 import android.os.Bundle;
5 import <#if appCompat>android.support.v7.app.ActionBarActivity<#else>android.app.Activity</#if>;
6 <#if minApiLevel lt 16>import android.support.v4.app.NavUtils;</#if>
7 import android.view.MenuItem;
8 <#if applicationPackage??>import ${applicationPackage}.R;</#if>
9
10 /**
11 * An activity representing a single ${objectKind} detail screen. This
12 * activity is only used on handset devices. On tablet-size devices,
13 * item details are presented side-by-side with a list of items
14 * in a {@link ${CollectionName}Activity}.
15 * <p>
16 * This activity is mostly just a 'shell' activity containing nothing
17 * more than a {@link ${DetailName}Fragment}.
18 */
19 public class ${DetailName}Activity extends ${appCompat?string('ActionBar','')}Activity {
20
21 @Override
22 protected void onCreate(Bundle savedInstanceState) {
23 super.onCreate(savedInstanceState);
24 setContentView(R.layout.activity_${detail_name});
25
26 // Show the Up button in the action bar.
27 get${Support}ActionBar().setDisplayHomeAsUpEnabled(true);
28
29 // savedInstanceState is non-null when there is fragment state
30 // saved from previous configurations of this activity
31 // (e.g. when rotating the screen from portrait to landscape).
32 // In this case, the fragment will automatically be re-added
33 // to its container so we don't need to manually add it.
34 // For more information, see the Fragments API guide at:
35 //
36 // http://developer.android.com/guide/components/fragments.html
37 //
38 if (savedInstanceState == null) {
39 // Create the detail fragment and add it to the activity
40 // using a fragment transaction.
41 Bundle arguments = new Bundle();
42 arguments.putString(${DetailName}Fragment.ARG_ITEM_ID,
43 getIntent().getStringExtra(${DetailName}Fragment.ARG_ITEM_ID));
44 ${DetailName}Fragment fragment = new ${DetailName}Fragment();
45 fragment.setArguments(arguments);
46 get${Support}FragmentManager().beginTransaction()
47 .add(R.id.${detail_name}_container, fragment)
48 .commit();
49 }
50 }
51
52 @Override
53 public boolean onOptionsItemSelected(MenuItem item) {
54 int id = item.getItemId();
55 if (id == android.R.id.home) {
56 <#if minApiLevel lt 16>
57 // This ID represents the Home or Up button. In the case of this
58 // activity, the Up button is shown. Use NavUtils to allow users
59 // to navigate up one level in the application structure. For
60 // more details, see the Navigation pattern on Android Design:
61 //
62 // http://developer.android.com/design/patterns/navigation.html#up-vs-back
63 //
64 NavUtils.navigateUpTo(this, new Intent(this, ${CollectionName}Activity.class));
65 <#else>
66 // This ID represents the Home or Up button. In the case of this
67 // activity, the Up button is shown. For
68 // more details, see the Navigation pattern on Android Design:
69 //
70 // http://developer.android.com/design/patterns/navigation.html#up-vs-back
71 //
72 navigateUpTo(new Intent(this, ${CollectionName}Activity.class));
73 </#if>
74 return true;
75 }
76 return super.onOptionsItemSelected(item);
77 }
78 }