App

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

- File List
- File Members

ProjectiveTransformPopUpFragment.java
Go to the documentation of this file.
1 package mhr.app.fragments.toolbox.transforms;
2
3 import mhr.app.AppMainActivity;
4 import mhr.app.R;
5 import mhr.app.fragments.toolbox.CancellableToolPopUpFragment;
6 import mhr.appandroid.displayer.BitmapDisplayer;
7 import mhr.appandroid.views.ProjectiveTransformPicker;
8 import mhr.appandroid.views.ProjectiveTransformPicker.ProjTransformData;
9 import mhr.appandroid.views.ProjectiveTransformPicker.ProjectiveTransformPickerEventListener;
10 import mhr.appandroid.views.ProjectiveTransformPicker.Quadrilateral;
11 import mhr.appcore.commands.toolcommands.CancelableToolUpdateCommand;
12 import mhr.appcore.tools.Tool;
13 import mhr.appcore.tools.actiondata.CancelableToolActionData;
14 import mhr.appcore.tools.actiondata.CancelableToolActionData.Action;
15 import mhr.appcore.tools.actiondata.LinearTransformationToolActionData;
16 import mhr.appcore.tools.cancelable.LinearTransformationTool;
17 import mhr.appcore.transform.TM;
18 import mhr.appcore.transform.Transform;
19 import android.app.Activity;
20 import android.view.View;
21 import android.view.ViewGroup.LayoutParams;
22 import android.widget.FrameLayout;
23 import android.widget.ToggleButton;
24
25 public class ProjectiveTransformPopUpFragment extends CancellableToolPopUpFragment implements ProjectiveTransformPickerEventListener {
26
27 //===== INTERFACES, CLASSES, ENUMS ==========================================================================================================//
28 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
29 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
30
31 //===== FIELDS ==============================================================================================================================//
32 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
33 protected AppMainActivity activity;
34
35 ProjectiveTransformPicker p;
36 ToggleButton repairTBtn;
37
38 FrameLayout guiHolder;
39
40 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
41
42 //===== CONSTRUCTORS, DESTRUCTORS, RELATED METHODS ==========================================================================================//
43 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
44 @Override
45 protected void onInitView() {
46 repairTBtn = (ToggleButton) root.findViewById(R.id.ProjectiveTransformInverseTBtn);
47 }
48
49 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
50 public ProjectiveTransformPopUpFragment() {
51
52 }
53
54 //===== METHODS =============================================================================================================================//
55 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
56
57 @Override
58 protected Tool getTool() {
59 return new LinearTransformationTool();
60 }
61
62 @Override
63 protected CancelableToolActionData getUpdateToolData() {
64 BitmapDisplayer disp = activity.getBitmapDisplayer();
65 ProjTransformData d = p.getTransformationData();
66 Quadrilateral o = d.oldQuad;
67 Quadrilateral n = d.newQuad;
68 // Matice transformuje jednotkovy ctverec na puvodni oblast
69 TM mo = Transform.getProjectiveMatrix(
70 disp.translateCoordX(o.TLx),
71 disp.translateCoordY(o.TLy),
72 disp.translateCoordX(o.TRx),
73 disp.translateCoordY(o.TRy),
74 disp.translateCoordX(o.BLx),
75 disp.translateCoordY(o.BLy),
76 disp.translateCoordX(o.BRx),
77 disp.translateCoordY(o.BRy));
78 // Matice transformuje jednotkovy ctverec na novou oblast
79 TM mn = Transform.getProjectiveMatrix(
80 disp.translateCoordX(n.TLx),
81 disp.translateCoordY(n.TLy),
82 disp.translateCoordX(n.TRx),
83 disp.translateCoordY(n.TRy),
84 disp.translateCoordX(n.BLx),
85 disp.translateCoordY(n.BLy),
86 disp.translateCoordX(n.BRx),
87 disp.translateCoordY(n.BRy));
88
89 TM m;
90 if (repairTBtn.isChecked()) {
91 m = TM.multiply(TM.inverseOf(mn), mo);
92 } else {
93 m = TM.multiply(TM.inverseOf(mo), mn);
94 }
95
96 return new LinearTransformationToolActionData(Action.UPDATE_PREVIEW, m);
97 }
98
99 @Override
100 protected int getLayoutId() {
101 return R.layout.fragment_projective_transform_tool_settings;
102 }
103
104 @Override
105 protected void onCancel() {
106 guiHolder.removeAllViews();
107 p = new ProjectiveTransformPicker(activity);
108 p.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
109 p.setListener(this);
110 guiHolder.addView(p);
111
112 }
113
114 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
115
116 //===== CALLBACKS ===========================================================================================================================//
117
118 @Override
119 public void onStartTrackingTransformation(ProjectiveTransformPicker p) {
120 }
121
122 @Override
123 public void onTransformationChanged(ProjectiveTransformPicker p) {
124 if (livePreviewOn) {
125 activity.addCommand(new CancelableToolUpdateCommand(getUpdateToolData()));
126 }
127
128 }
129
130 @Override
131 public void onStopTrackingTransformation(ProjectiveTransformPicker p) {
132 }
133
134 //----- LIFE CYCLE --------------------------------------------------------------------------------------------------------------------------//
135
136 @Override
137 public void onAttach(Activity activity) {
138 super.onAttach(activity);
139 /*
140 * called once the fragment is associated with its activity.
141 */
142 this.activity = (AppMainActivity) activity;
143 }
144
145 // @Override
146 // public void onCreate(Bundle savedInstanceState) {
147 // super.onCreate(savedInstanceState);
148 // /*
149 // * called to do initial creation of the fragment.
150 // *
151 // * The system calls this when creating the fragment. Within your implementation, you should initialize essential components of the fragment that you want
152 // * to retain when the fragment is paused or stopped, then resumed.
153 // */
154 // }
155
156 // @Override
157 // public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
158 // /*
159 // * creates and returns the view hierarchy associated with the fragment.
160 // *
161 // * 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
162 // * 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.
163 // *
164 // * Zde začíná životní cyklus při návratu z backstacku
165 // */
166 // if (firstCreated) {
167 // firstCreated = false;
168 // return initView(inflater, container, savedInstanceState);
169 // } else {
170 // return root;
171 // }
172 // }
173
174 // @Override
175 // public void onActivityCreated(Bundle savedInstanceState) {
176 // super.onActivityCreated(savedInstanceState);
177 // /*
178 // * tells the fragment that its activity has completed its own Activity.onCreate().
179 // */
180 // }
181
182 // @Override // Vyžaduje API 17
183 // public void onViewStateRestored(Bundle savedInstanceState) {
184 // super.onViewStateRestored(savedInstanceState);
185 // /*
186 // * tells the fragment that all of the saved state of its view hierarchy has been restored.
187 // */
188 // }
189
190 // @Override
191 // public void onStart() {
192 // super.onStart();
193 // /*
194 // * makes the fragment visible to the user (based on its containing activity being started).
195 // */
196 // }
197
198 @Override
199 public void onResume() {
200 super.onResume();
201 /*
202 * makes the fragment interacting with the user (based on its containing activity being resumed).
203 */
204
205 guiHolder = activity.getGuiOverCanvas();
206 guiHolder.removeAllViews();
207 p = new ProjectiveTransformPicker(activity);
208 p.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
209 p.setListener(this);
210 guiHolder.addView(p);
211 guiHolder.setVisibility(View.VISIBLE);
212 }
213
214 @Override
215 public void onPause() {
216 super.onPause();
217 /*
218 * 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.
219 *
220 * 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).
221 * 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).
222 */
223 // activity.dismissDialog();
224 guiHolder.removeAllViews();
225 guiHolder.setVisibility(View.GONE);
226 }
227
228 // @Override
229 // public void onStop() {
230 // super.onStop();
231 // /*
232 // * 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.
233 // */
234 // }
235
236 // @Override
237 // public void onDestroyView() {
238 // super.onDestroyView();
239 // /*
240 // * allows the fragment to clean up resources associated with its View.
241 // *
242 // * Zde končí životní cyklus při umístění do backstacku
243 // */
244 // }
245
246 // @Override
247 // public void onDestroy() {
248 // super.onDestroy();
249 // /*
250 // * called to do final cleanup of the fragment's state.
251 // */
252 // }
253
254 // @Override
255 // public void onDetach() {
256 // super.onDetach();
257 // /*
258 // * called immediately prior to the fragment no longer being associated with its activity.
259 // */
260 // }
261
262 }