App

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

CancellableToolPopUpFragment.java
Go to the documentation of this file.
1 package mhr.app.fragments.toolbox;
2
3 import mhr.app.AppMainActivity;
4 import mhr.app.R;
5 import mhr.appcore.commands.toolcommands.CancelableToolCommitCommand;
6 import mhr.appcore.commands.toolcommands.CancelableToolUpdateCommand;
7 import mhr.appcore.commands.toolcommands.SelectToolCommand;
8 import mhr.appcore.tools.Tool;
9 import mhr.appcore.tools.actiondata.CancelableToolActionData;
10 import mhr.appcore.tools.actiondata.CancelableToolActionData.Action;
11 import android.app.Activity;
12 import android.app.Fragment;
13 import android.os.Bundle;
14 import android.view.LayoutInflater;
15 import android.view.View;
16 import android.view.View.OnClickListener;
17 import android.view.ViewGroup;
18 import android.widget.Button;
19 import android.widget.CompoundButton;
20 import android.widget.CompoundButton.OnCheckedChangeListener;
21 import android.widget.ToggleButton;
22
26 public abstract class CancellableToolPopUpFragment extends Fragment implements OnClickListener, OnCheckedChangeListener {
27
28 //===== INTERFACES, CLASSES, ENUMS ==========================================================================================================//
29 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
30 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
31
32 //===== FIELDS ==============================================================================================================================//
33 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
34 protected View root;
35 protected AppMainActivity activity;
36 protected boolean firstCreated = true;
37
38 protected Button applyBtn;
39 protected Button previewBtn;
40 protected Button cancelBtn;
41 protected ToggleButton livePreviewTBtn;
42
43 protected boolean livePreviewOn = false;
44
45 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
46
47 //===== CONSTRUCTORS, DESTRUCTORS, RELATED METHODS ==========================================================================================//
48 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
56 protected View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
57 root = inflater.inflate(getLayoutId(), container, false);
58
59 applyBtn = (Button) root.findViewById(R.id.PointOperationToolApplyBtn);
60 previewBtn = (Button) root.findViewById(R.id.PointOperationToolPreviewBtn);
61 cancelBtn = (Button) root.findViewById(R.id.PointOperationToolCancelBtn);
62 livePreviewTBtn = (ToggleButton) root.findViewById(R.id.PointOperationToolLivePreviewTBtn);
63
64 applyBtn.setOnClickListener(this);
65 previewBtn.setOnClickListener(this);
66 cancelBtn.setOnClickListener(this);
67 livePreviewTBtn.setOnCheckedChangeListener(this);
68
69 firstCreated = false;
70
71 onInitView();
72
73 return root;
74 }
75
76 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
77
78 //===== METHODS =============================================================================================================================//
79 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
84 protected abstract Tool getTool();
85
90 protected abstract CancelableToolActionData getUpdateToolData();
91
96 protected abstract int getLayoutId();
97
101 protected abstract void onInitView();
102
106 protected abstract void onCancel();
107
108 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
109
110 //===== CALLBACKS ===========================================================================================================================//
111 @Override
112 public void onClick(View v) {
113 int id = v.getId();
114 switch (id) {
115 //(biasSeekBar.getProgress() - 100) / 100.0)
116 case R.id.PointOperationToolApplyBtn:
117 activity.addCommand(new CancelableToolUpdateCommand(getUpdateToolData()));
118 activity.addCommand(new CancelableToolCommitCommand(new CancelableToolActionData(Action.COMMIT_PREVIEW)));
119 onCancel();
120 break;
121 case R.id.PointOperationToolPreviewBtn:
122 activity.addCommand(new CancelableToolUpdateCommand(getUpdateToolData()));
123 break;
124 case R.id.PointOperationToolCancelBtn:
125 onCancel();
126 activity.addCommand(new CancelableToolCommitCommand(new CancelableToolActionData(Action.CANCEL_PREVIEW)));
127 break;
128 }
129
130 }
131
132 @Override
133 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
134 if (buttonView == livePreviewTBtn) {
135 livePreviewOn = isChecked;
136 }
137 if (livePreviewOn) {
138 activity.addCommand(new CancelableToolUpdateCommand(getUpdateToolData()));
139 }
140 }
141
142 //----- LIFE CYCLE --------------------------------------------------------------------------------------------------------------------------//
143
144 @Override
145 public void onAttach(Activity activity) {
146 super.onAttach(activity);
147 /*
148 * called once the fragment is associated with its activity.
149 */
150 this.activity = (AppMainActivity) activity;
151 }
152
153 // @Override
154 // public void onCreate(Bundle savedInstanceState) {
155 // super.onCreate(savedInstanceState);
156 // /*
157 // * called to do initial creation of the fragment.
158 // *
159 // * The system calls this when creating the fragment. Within your implementation, you should initialize essential components of the fragment that you want
160 // * to retain when the fragment is paused or stopped, then resumed.
161 // */
162 // }
163
164 @Override
165 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
166 /*
167 * creates and returns the view hierarchy associated with the fragment.
168 *
169 * The system calls this when it's time for the fragment to draw its user interface for the first time. To draw a UI for your fragment, you must return a
170 * View from this method that is the root of your fragment's layout. You can return null if the fragment does not provide a UI.
171 *
172 * Zde začíná životní cyklus při návratu z backstacku
173 */
174 if (firstCreated) {
175 firstCreated = false;
176 return initView(inflater, container, savedInstanceState);
177 } else {
178 return root;
179 }
180 }
181
182 // @Override
183 // public void onActivityCreated(Bundle savedInstanceState) {
184 // super.onActivityCreated(savedInstanceState);
185 // /*
186 // * tells the fragment that its activity has completed its own Activity.onCreate().
187 // */
188 // }
189
190 // @Override // Vyžaduje API 17
191 // public void onViewStateRestored(Bundle savedInstanceState) {
192 // super.onViewStateRestored(savedInstanceState);
193 // /*
194 // * tells the fragment that all of the saved state of its view hierarchy has been restored.
195 // */
196 // }
197
198 // @Override
199 // public void onStart() {
200 // super.onStart();
201 // /*
202 // * makes the fragment visible to the user (based on its containing activity being started).
203 // */
204 // }
205
206 @Override
207 public void onResume() {
208 super.onResume();
209 /*
210 * makes the fragment interacting with the user (based on its containing activity being resumed).
211 */
212 activity.addCommand(new SelectToolCommand(getTool()));
213 }
214
215 @Override
216 public void onPause() {
217 super.onPause();
218 /*
219 * fragment is no longer interacting with the user either because its activity is being paused or a fragment operation is modifying it in the activity.
220 *
221 * The system calls this method as the first indication that the user is leaving the fragment (though it does not always mean the fragment is being destroyed).
222 * This is usually where you should commit any changes that should be persisted beyond the current user session (because the user might not come back).
223 */
224 }
225
226 // @Override
227 // public void onStop() {
228 // super.onStop();
229 // /*
230 // * fragment is no longer visible to the user either because its activity is being stopped or a fragment operation is modifying it in the activity.
231 // */
232 // }
233
234 // @Override
235 // public void onDestroyView() {
236 // super.onDestroyView();
237 // /*
238 // * allows the fragment to clean up resources associated with its View.
239 // *
240 // * Zde končí životní cyklus při umístění do backstacku
241 // */
242 // }
243
244 // @Override
245 // public void onDestroy() {
246 // super.onDestroy();
247 // /*
248 // * called to do final cleanup of the fragment's state.
249 // */
250 // }
251
252 // @Override
253 // public void onDetach() {
254 // super.onDetach();
255 // /*
256 // * called immediately prior to the fragment no longer being associated with its activity.
257 // */
258 // }
259 }