Debian Codegraph @

templates/eclipse/other/PlusOneFragment/root/src/app_package/PlusOneFragment.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.support.v4.app.Fragment;
7 import android.view.LayoutInflater;
8 import android.view.View;
9 import android.view.ViewGroup;
10 <#if applicationPackage??>import ${applicationPackage}.R;</#if>
11
12 import com.google.android.gms.plus.PlusOneButton;
13
14 /**
15 * A fragment with a Google +1 button.
16 <#if includeCallbacks>
17 * Activities that contain this fragment must implement the
18 * {@link ${className}.OnFragmentInteractionListener} interface
19 * to handle interaction events.
20 </#if>
21 <#if includeFactory>
22 * Use the {@link ${className}#newInstance} factory method to
23 * create an instance of this fragment.
24 </#if>
25 *
26 */
27 public class ${className} extends Fragment {
28 <#if includeFactory>
29 // TODO: Rename parameter arguments, choose names that match
30 // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
31 private static final String ARG_PARAM1 = "param1";
32 private static final String ARG_PARAM2 = "param2";
33
34 // TODO: Rename and change types of parameters
35 private String mParam1;
36 private String mParam2;
37 </#if>
38
39 // The URL to +1. Must be a valid URL.
40 private final String PLUS_ONE_URL = "http://developer.android.com";
41
42 // The request code must be 0 or greater.
43 private static final int PLUS_ONE_REQUEST_CODE = 0;
44
45 private PlusOneButton mPlusOneButton;
46
47 <#if includeCallbacks>
48 private OnFragmentInteractionListener mListener;
49 </#if>
50
51 <#if includeFactory>
52 /**
53 * Use this factory method to create a new instance of
54 * this fragment using the provided parameters.
55 *
56 * @param param1 Parameter 1.
57 * @param param2 Parameter 2.
58 * @return A new instance of fragment ${className}.
59 */
60 // TODO: Rename and change types and number of parameters
61 public static ${className} newInstance(String param1, String param2) {
62 ${className} fragment = new ${className}();
63 Bundle args = new Bundle();
64 args.putString(ARG_PARAM1, param1);
65 args.putString(ARG_PARAM2, param2);
66 fragment.setArguments(args);
67 return fragment;
68 }
69 </#if>
70 public ${className}() {
71 // Required empty public constructor
72 }
73
74 <#if includeFactory>
75 @Override
76 public void onCreate(Bundle savedInstanceState) {
77 super.onCreate(savedInstanceState);
78 if (getArguments() != null) {
79 mParam1 = getArguments().getString(ARG_PARAM1);
80 mParam2 = getArguments().getString(ARG_PARAM2);
81 }
82 }
83 </#if>
84
85 @Override
86 public View onCreateView(LayoutInflater inflater, ViewGroup container,
87 Bundle savedInstanceState) {
88 // Inflate the layout for this fragment
89 View view = inflater.inflate(R.layout.fragment_${classToResource(className)}, container, false);
90
91 //Find the +1 button
92 mPlusOneButton = (PlusOneButton) view.findViewById(R.id.plus_one_button);
93
94 return view;
95 }
96
97 @Override
98 public void onResume() {
99 super.onResume();
100
101 // Refresh the state of the +1 button each time the activity receives focus.
102 mPlusOneButton.initialize(PLUS_ONE_URL, PLUS_ONE_REQUEST_CODE);
103 }
104
105 <#if includeCallbacks>
106 // TODO: Rename method, update argument and hook method into UI event
107 public void onButtonPressed(Uri uri) {
108 if (mListener != null) {
109 mListener.onFragmentInteraction(uri);
110 }
111 }
112
113 @Override
114 public void onAttach(Activity activity) {
115 super.onAttach(activity);
116 try {
117 mListener = (OnFragmentInteractionListener) activity;
118 } catch (ClassCastException e) {
119 throw new ClassCastException(activity.toString()
120 + " must implement OnFragmentInteractionListener");
121 }
122 }
123
124 @Override
125 public void onDetach() {
126 super.onDetach();
127 mListener = null;
128 }
129
130 /**
131 * This interface must be implemented by activities that contain this
132 * fragment to allow an interaction in this fragment to be communicated
133 * to the activity and potentially other fragments contained in that
134 * activity.
135 * <p>
136 * See the Android Training lesson <a href=
137 * "http://developer.android.com/training/basics/fragments/communicating.html"
138 * >Communicating with Other Fragments</a> for more information.
139 */
140 public interface OnFragmentInteractionListener {
141 // TODO: Update argument type and name
142 public void onFragmentInteraction(Uri uri);
143 }
144 </#if>
145
146 }