Debian Codegraph @

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

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