App

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

- File List
- File Members

CropPopUpFragment.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.appandroid.displayer.BitmapDisplayer;
6 import mhr.appandroid.views.CropPicker;
7 import mhr.appandroid.views.ProjectiveTransformPicker;
8 import mhr.appcore.commands.core.CropImageCommand;
9 import mhr.appcore.commands.toolcommands.CancelableToolCommitCommand;
10 import mhr.appcore.commands.toolcommands.CancelableToolUpdateCommand;
11 import mhr.appcore.commands.toolcommands.SelectToolCommand;
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.utils.Rect;
16 import android.app.Activity;
17 import android.app.Fragment;
18 import android.graphics.RectF;
19 import android.os.Bundle;
20 import android.view.LayoutInflater;
21 import android.view.View;
22 import android.view.View.OnClickListener;
23 import android.view.ViewGroup.LayoutParams;
24 import android.view.ViewGroup;
25 import android.widget.Button;
26 import android.widget.CompoundButton;
27 import android.widget.FrameLayout;
28 import android.widget.CompoundButton.OnCheckedChangeListener;
29 import android.widget.ToggleButton;
30
31 public class CropPopUpFragment extends Fragment implements OnClickListener{
32
33 //===== INTERFACES, CLASSES, ENUMS ==========================================================================================================//
34 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
35 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
36
37 //===== FIELDS ==============================================================================================================================//
38 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
39 protected View root;
40 protected AppMainActivity activity;
41 protected boolean firstCreated = true;
42
43 protected Button cropBtn;
44
45 protected FrameLayout guiHolder;
46 protected CropPicker p;
47
48 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
49
50 //===== CONSTRUCTORS, DESTRUCTORS, RELATED METHODS ==========================================================================================//
51 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
59 protected View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
60 root = inflater.inflate(R.layout.fragment_crop_tool_popup, container, false);
61
62 cropBtn = (Button) root.findViewById(R.id.ApplyCropBtn);
63 cropBtn.setOnClickListener(this);
64 firstCreated = false;
65
66 return root;
67 }
68
69 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
70
71 //===== METHODS =============================================================================================================================//
72 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
73 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
74
75 //===== CALLBACKS ===========================================================================================================================//
76 @Override
77 public void onClick(View v) {
78 int id = v.getId();
79 switch (id) {
80 //(biasSeekBar.getProgress() - 100) / 100.0)
81 case R.id.ApplyCropBtn:
82 BitmapDisplayer disp = activity.getBitmapDisplayer();
83 RectF crop = p.getCrop();
84
85 Rect cropR = new Rect(
86 disp.translateCoordX(crop.left),
87 disp.translateCoordY(crop.top),
88 disp.translateCoordX(crop.right),
89 disp.translateCoordY(crop.bottom));
90 if (cropR.getWidth() == 0 || cropR.getHeight() == 0) {
91 return;
92 }
93
94 activity.addCommand(new CropImageCommand(cropR));
95 p.resetCrop();
96 break;
97 }
98 }
99
100 //----- LIFE CYCLE --------------------------------------------------------------------------------------------------------------------------//
101
102 @Override
103 public void onAttach(Activity activity) {
104 super.onAttach(activity);
105 /*
106 * called once the fragment is associated with its activity.
107 */
108 this.activity = (AppMainActivity) activity;
109 }
110
111 // @Override
112 // public void onCreate(Bundle savedInstanceState) {
113 // super.onCreate(savedInstanceState);
114 // /*
115 // * called to do initial creation of the fragment.
116 // *
117 // * The system calls this when creating the fragment. Within your implementation, you should initialize essential components of the fragment that you want
118 // * to retain when the fragment is paused or stopped, then resumed.
119 // */
120 // }
121
122 @Override
123 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
124 /*
125 * creates and returns the view hierarchy associated with the fragment.
126 *
127 * 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
128 * 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.
129 *
130 * Zde začíná životní cyklus při návratu z backstacku
131 */
132 if (firstCreated) {
133 firstCreated = false;
134 return initView(inflater, container, savedInstanceState);
135 } else {
136 return root;
137 }
138 }
139
140 // @Override
141 // public void onActivityCreated(Bundle savedInstanceState) {
142 // super.onActivityCreated(savedInstanceState);
143 // /*
144 // * tells the fragment that its activity has completed its own Activity.onCreate().
145 // */
146 // }
147
148 // @Override // Vyžaduje API 17
149 // public void onViewStateRestored(Bundle savedInstanceState) {
150 // super.onViewStateRestored(savedInstanceState);
151 // /*
152 // * tells the fragment that all of the saved state of its view hierarchy has been restored.
153 // */
154 // }
155
156 // @Override
157 // public void onStart() {
158 // super.onStart();
159 // /*
160 // * makes the fragment visible to the user (based on its containing activity being started).
161 // */
162 // }
163
164 @Override
165 public void onResume() {
166 super.onResume();
167 /*
168 * makes the fragment interacting with the user (based on its containing activity being resumed).
169 */
170 guiHolder = activity.getGuiOverCanvas();
171 guiHolder.removeAllViews();
172 p = new CropPicker(activity);
173 p.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
174 guiHolder.addView(p);
175 guiHolder.setVisibility(View.VISIBLE);
176 }
177
178 @Override
179 public void onPause() {
180 super.onPause();
181 /*
182 * 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.
183 *
184 * 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).
185 * 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).
186 */
187 guiHolder.removeAllViews();
188 guiHolder.setVisibility(View.GONE);
189 }
190
191 // @Override
192 // public void onStop() {
193 // super.onStop();
194 // /*
195 // * 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.
196 // */
197 // }
198
199 // @Override
200 // public void onDestroyView() {
201 // super.onDestroyView();
202 // /*
203 // * allows the fragment to clean up resources associated with its View.
204 // *
205 // * Zde končí životní cyklus při umístění do backstacku
206 // */
207 // }
208
209 // @Override
210 // public void onDestroy() {
211 // super.onDestroy();
212 // /*
213 // * called to do final cleanup of the fragment's state.
214 // */
215 // }
216
217 // @Override
218 // public void onDetach() {
219 // super.onDetach();
220 // /*
221 // * called immediately prior to the fragment no longer being associated with its activity.
222 // */
223 // }
224 }