| 1 |
package ${packageName}; |
| 2 |
|
| 3 |
<#if hasAppBar> |
| 4 |
import android.app.Activity; |
| 5 |
import android.support.design.widget.CollapsingToolbarLayout; |
| 6 |
</#if> |
| 7 |
import android.os.Bundle; |
| 8 |
import android.<#if appCompat>support.v4.</#if>app.Fragment; |
| 9 |
import android.view.LayoutInflater; |
| 10 |
import android.view.View; |
| 11 |
import android.view.ViewGroup; |
| 12 |
import android.widget.TextView; |
| 13 |
<#if applicationPackage??> |
| 14 |
import ${applicationPackage}.R; |
| 15 |
</#if> |
| 16 |
import ${packageName}.dummy.DummyContent; |
| 17 |
|
| 18 |
/** |
| 19 |
* A fragment representing a single ${objectKind} detail screen. |
| 20 |
* This fragment is either contained in a {@link ${CollectionName}Activity} |
| 21 |
* in two-pane mode (on tablets) or a {@link ${DetailName}Activity} |
| 22 |
* on handsets. |
| 23 |
*/ |
| 24 |
public class ${DetailName}Fragment extends Fragment { |
| 25 |
/** |
| 26 |
* The fragment argument representing the item ID that this fragment |
| 27 |
* represents. |
| 28 |
*/ |
| 29 |
public static final String ARG_ITEM_ID = "item_id"; |
| 30 |
|
| 31 |
/** |
| 32 |
* The dummy content this fragment is presenting. |
| 33 |
*/ |
| 34 |
private DummyContent.DummyItem mItem; |
| 35 |
|
| 36 |
/** |
| 37 |
* Mandatory empty constructor for the fragment manager to instantiate the |
| 38 |
* fragment (e.g. upon screen orientation changes). |
| 39 |
*/ |
| 40 |
public ${DetailName}Fragment() { |
| 41 |
} |
| 42 |
|
| 43 |
@Override |
| 44 |
public void onCreate(Bundle savedInstanceState) { |
| 45 |
super.onCreate(savedInstanceState); |
| 46 |
|
| 47 |
if (getArguments().containsKey(ARG_ITEM_ID)) { |
| 48 |
// Load the dummy content specified by the fragment |
| 49 |
// arguments. In a real-world scenario, use a Loader |
| 50 |
// to load content from a content provider. |
| 51 |
mItem = DummyContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID)); |
| 52 |
<#if hasAppBar> |
| 53 |
|
| 54 |
Activity activity = this.getActivity(); |
| 55 |
CollapsingToolbarLayout appBarLayout = (CollapsingToolbarLayout) activity.findViewById(R.id.toolbar_layout); |
| 56 |
if (appBarLayout != null) { |
| 57 |
appBarLayout.setTitle(mItem.content); |
| 58 |
} |
| 59 |
</#if> |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
@Override |
| 64 |
public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 65 |
Bundle savedInstanceState) { |
| 66 |
View rootView = inflater.inflate(R.layout.${detail_name}, container, false); |
| 67 |
|
| 68 |
// Show the dummy content as text in a TextView. |
| 69 |
if (mItem != null) { |
| 70 |
((TextView) rootView.findViewById(R.id.${detail_name})).setText(mItem.details); |
| 71 |
} |
| 72 |
|
| 73 |
return rootView; |
| 74 |
} |
| 75 |
} |