Debian Codegraph @

templates/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 <#if hasAppBar>
6 import android.support.design.widget.FloatingActionButton;
7 import android.support.design.widget.Snackbar;
8 import android.support.v7.widget.Toolbar;
9 import android.view.View;
10 </#if>
11 import ${superClassFqcn};
12 import ${actionBarClassFqcn};
13 <#if minApiLevel lt 16>
14 import android.support.v4.app.NavUtils;
15 </#if>
16 import android.view.MenuItem;
17 <#if applicationPackage??>
18 import ${applicationPackage}.R;
19 </#if>
20
21 /**
22 * An activity representing a single ${objectKind} detail screen. This
23 * activity is only used narrow width devices. On tablet-size devices,
24 * item details are presented side-by-side with a list of items
25 * in a {@link ${CollectionName}Activity}.
26 */
27 public class ${DetailName}Activity extends ${superClass} {
28
29 @Override
30 protected void onCreate(Bundle savedInstanceState) {
31 super.onCreate(savedInstanceState);
32 setContentView(R.layout.activity_${detail_name});
33 <#if hasAppBar>
34 Toolbar toolbar = (Toolbar) findViewById(R.id.detail_toolbar);
35 setSupportActionBar(toolbar);
36
37 FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
38 fab.setOnClickListener(new View.OnClickListener() {
39 @Override
40 public void onClick(View view) {
41 Snackbar.make(view, "Replace with your own detail action", Snackbar.LENGTH_LONG)
42 .setAction("Action", null).show();
43 }
44 });
45 </#if>
46
47 // Show the Up button in the action bar.
48 ActionBar actionBar = getSupportActionBar();
49 if (actionBar != null) {
50 actionBar.setDisplayHomeAsUpEnabled(true);
51 }
52
53 // savedInstanceState is non-null when there is fragment state
54 // saved from previous configurations of this activity
55 // (e.g. when rotating the screen from portrait to landscape).
56 // In this case, the fragment will automatically be re-added
57 // to its container so we don't need to manually add it.
58 // For more information, see the Fragments API guide at:
59 //
60 // http://developer.android.com/guide/components/fragments.html
61 //
62 if (savedInstanceState == null) {
63 // Create the detail fragment and add it to the activity
64 // using a fragment transaction.
65 Bundle arguments = new Bundle();
66 arguments.putString(${DetailName}Fragment.ARG_ITEM_ID,
67 getIntent().getStringExtra(${DetailName}Fragment.ARG_ITEM_ID));
68 ${DetailName}Fragment fragment = new ${DetailName}Fragment();
69 fragment.setArguments(arguments);
70 get${Support}FragmentManager().beginTransaction()
71 .add(R.id.${detail_name}_container, fragment)
72 .commit();
73 }
74 }
75
76 @Override
77 public boolean onOptionsItemSelected(MenuItem item) {
78 int id = item.getItemId();
79 if (id == android.R.id.home) {
80 <#if minApiLevel lt 16>
81 // This ID represents the Home or Up button. In the case of this
82 // activity, the Up button is shown. Use NavUtils to allow users
83 // to navigate up one level in the application structure. For
84 // more details, see the Navigation pattern on Android Design:
85 //
86 // http://developer.android.com/design/patterns/navigation.html#up-vs-back
87 //
88 NavUtils.navigateUpTo(this, new Intent(this, ${CollectionName}Activity.class));
89 <#else>
90 // This ID represents the Home or Up button. In the case of this
91 // activity, the Up button is shown. For
92 // more details, see the Navigation pattern on Android Design:
93 //
94 // http://developer.android.com/design/patterns/navigation.html#up-vs-back
95 //
96 navigateUpTo(new Intent(this, ${CollectionName}Activity.class));
97 </#if>
98 return true;
99 }
100 return super.onOptionsItemSelected(item);
101 }
102 }