Debian Codegraph @

templates/eclipse/other/BlankFragment/root/src/app_package/BlankFragment.java.ftl

raw
1 package ${packageName};
2
3 <#if includeCallbacks>import android.app.Activity;</#if>
4 <#if includeCallbacks>import android.net.Uri;</#if>
5 import android.os.Bundle;
6 import android<#if useSupport>.support.v4</#if>.app.Fragment;
7 import android.view.LayoutInflater;
8 import android.view.View;
9 import android.view.ViewGroup;
10 <#if !includeLayout>import android.widget.TextView;</#if>
11 <#if applicationPackage??>import ${applicationPackage}.R;</#if>
12
13 /**
14 * A simple {@link Fragment} subclass.
15 <#if includeCallbacks>
16 * Activities that contain this fragment must implement the
17 * {@link ${className}.OnFragmentInteractionListener} interface
18 * to handle interaction events.
19 </#if>
20 <#if includeFactory>
21 * Use the {@link ${className}#newInstance} factory method to
22 * create an instance of this fragment.
23 </#if>
24 *
25 */
26 public class ${className} extends Fragment {
27 <#if includeFactory>
28 // TODO: Rename parameter arguments, choose names that match
29 // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
30 private static final String ARG_PARAM1 = "param1";
31 private static final String ARG_PARAM2 = "param2";
32
33 // TODO: Rename and change types of parameters
34 private String mParam1;
35 private String mParam2;
36 </#if>
37
38 <#if includeCallbacks>
39 private OnFragmentInteractionListener mListener;
40 </#if>
41
42 <#if includeFactory>
43 /**
44 * Use this factory method to create a new instance of
45 * this fragment using the provided parameters.
46 *
47 * @param param1 Parameter 1.
48 * @param param2 Parameter 2.
49 * @return A new instance of fragment ${className}.
50 */
51 // TODO: Rename and change types and number of parameters
52 public static ${className} newInstance(String param1, String param2) {
53 ${className} fragment = new ${className}();
54 Bundle args = new Bundle();
55 args.putString(ARG_PARAM1, param1);
56 args.putString(ARG_PARAM2, param2);
57 fragment.setArguments(args);
58 return fragment;
59 }
60 </#if>
61 public ${className}() {
62 // Required empty public constructor
63 }
64
65 <#if includeFactory>
66 @Override
67 public void onCreate(Bundle savedInstanceState) {
68 super.onCreate(savedInstanceState);
69 if (getArguments() != null) {
70 mParam1 = getArguments().getString(ARG_PARAM1);
71 mParam2 = getArguments().getString(ARG_PARAM2);
72 }
73 }
74 </#if>
75
76 @Override
77 public View onCreateView(LayoutInflater inflater, ViewGroup container,
78 Bundle savedInstanceState) {
79 <#if includeLayout>
80 // Inflate the layout for this fragment
81 return inflater.inflate(R.layout.${fragmentName}, container, false);
82 <#else>
83 TextView textView = new TextView(getActivity());
84 textView.setText(R.string.hello_blank_fragment);
85 return textView;
86 </#if>
87 }
88
89 <#if includeCallbacks>
90 // TODO: Rename method, update argument and hook method into UI event
91 public void onButtonPressed(Uri uri) {
92 if (mListener != null) {
93 mListener.onFragmentInteraction(uri);
94 }
95 }
96
97 @Override
98 public void onAttach(Activity activity) {
99 super.onAttach(activity);
100 try {
101 mListener = (OnFragmentInteractionListener) activity;
102 } catch (ClassCastException e) {
103 throw new ClassCastException(activity.toString()
104 + " must implement OnFragmentInteractionListener");
105 }
106 }
107
108 @Override
109 public void onDetach() {
110 super.onDetach();
111 mListener = null;
112 }
113
114 /**
115 * This interface must be implemented by activities that contain this
116 * fragment to allow an interaction in this fragment to be communicated
117 * to the activity and potentially other fragments contained in that
118 * activity.
119 * <p>
120 * See the Android Training lesson <a href=
121 * "http://developer.android.com/training/basics/fragments/communicating.html"
122 * >Communicating with Other Fragments</a> for more information.
123 */
124 public interface OnFragmentInteractionListener {
125 // TODO: Update argument type and name
126 public void onFragmentInteraction(Uri uri);
127 }
128 </#if>
129
130 }