App
ResizePopUpFragment.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.views.LabelledSeekBar;
6 import mhr.appandroid.views.LabelledSeekBar.LabelledSBChangeListener;
7 import mhr.appcore.commands.core.ResizeImageCommand;
8 import mhr.appcore.commands.core.ResizeImageCommand.ResizeAction;
9 import mhr.appcore.interpolators.InterpolatorType;
10 import android.app.Activity;
11 import android.app.Fragment;
12 import android.os.Bundle;
13 import android.view.LayoutInflater;
14 import android.view.View;
15 import android.view.View.OnClickListener;
16 import android.view.ViewGroup;
17 import android.widget.RadioGroup;
18 import android.widget.RatingBar;
19 import android.widget.ToggleButton;
20 
21 public class ResizePopUpFragment extends Fragment implements OnClickListener, LabelledSBChangeListener{
22 
23  //===== INTERFACES, CLASSES, ENUMS ==========================================================================================================//
24  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
25  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
26 
27  //===== FIELDS ==============================================================================================================================//
28  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
29  protected View root;
31  protected boolean firstCreated = true;
32 
33  protected int origWidth;
34  protected int origHeight;
35  protected double origRatio;
36 
40  protected ToggleButton keepRatioTBtn;
41  protected RadioGroup interpType;
42 
43  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
44 
45  //===== CONSTRUCTORS, DESTRUCTORS, RELATED METHODS ==========================================================================================//
46  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
54  protected View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
55  root = inflater.inflate(R.layout.fragment_resize_tool_settings, container, false);
56 
57  nWidth = (LabelledSeekBar) root.findViewById(R.id.WidthValueLSB);
59  nHeight = (LabelledSeekBar) root.findViewById(R.id.HeightValueLSB);
61 
62  forceLSB = (LabelledSeekBar) root.findViewById(R.id.ForceValueLSB);
63  keepRatioTBtn = (ToggleButton) root.findViewById(R.id.FixedRatioTBtn);
64  keepRatioTBtn.setOnClickListener(this);
65 
66  interpType = (RadioGroup) root.findViewById(R.id.InterpolationTypeRG);
67 
68  root.findViewById(R.id.ResizeImageBtn).setOnClickListener(this);
69  root.findViewById(R.id.PreviewResizeBtn).setOnClickListener(this);
70  root.findViewById(R.id.CancelBtn).setOnClickListener(this);
71 
72  firstCreated = false;
73 
74  return root;
75  }
76 
77  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
78 
79  //===== METHODS =============================================================================================================================//
80  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
81  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
82 
83  //===== CALLBACKS ===========================================================================================================================//
84  @Override
85  public void onClick(View v) {
86  int id = v.getId();
87 
88  if (id == R.id.FixedRatioTBtn) {
89  if (keepRatioTBtn.isChecked()) {
91  }
92  return;
93  }
94 
95  InterpolatorType iType = null;
96  switch (interpType.getCheckedRadioButtonId()) {
97  case R.id.NearestNeighbourR:
99  break;
100  case R.id.BilinearR:
102  break;
103  case R.id.BicubicR:
105  break;
106  }
107  switch (id) {
108  case R.id.ResizeImageBtn:
111  break;
112  case R.id.PreviewResizeBtn:
114  break;
115  case R.id.CancelBtn:
117  break;
118  }
119  }
120 
121  //----- LIFE CYCLE --------------------------------------------------------------------------------------------------------------------------//
122 
123  @Override
124  public void onAttach(Activity activity) {
125  super.onAttach(activity);
126  /*
127  * called once the fragment is associated with its activity.
128  */
129  this.activity = (AppMainActivity) activity;
130  }
131 
132  // @Override
133  // public void onCreate(Bundle savedInstanceState) {
134  // super.onCreate(savedInstanceState);
135  // /*
136  // * called to do initial creation of the fragment.
137  // *
138  // * The system calls this when creating the fragment. Within your implementation, you should initialize essential components of the fragment that you want
139  // * to retain when the fragment is paused or stopped, then resumed.
140  // */
141  // }
142 
143  @Override
144  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
145  /*
146  * creates and returns the view hierarchy associated with the fragment.
147  *
148  * 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
149  * 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.
150  *
151  * Zde začíná životní cyklus při návratu z backstacku
152  */
153  if (firstCreated) {
154  firstCreated = false;
155  return initView(inflater, container, savedInstanceState);
156  } else {
157  return root;
158  }
159  }
160 
161  // @Override
162  // public void onActivityCreated(Bundle savedInstanceState) {
163  // super.onActivityCreated(savedInstanceState);
164  // /*
165  // * tells the fragment that its activity has completed its own Activity.onCreate().
166  // */
167  // }
168 
169  // @Override // Vyžaduje API 17
170  // public void onViewStateRestored(Bundle savedInstanceState) {
171  // super.onViewStateRestored(savedInstanceState);
172  // /*
173  // * tells the fragment that all of the saved state of its view hierarchy has been restored.
174  // */
175  // }
176 
177  // @Override
178  // public void onStart() {
179  // super.onStart();
180  // /*
181  // * makes the fragment visible to the user (based on its containing activity being started).
182  // */
183  // }
184 
185  @Override
186  public void onResume() {
187  super.onResume();
188  /*
189  * makes the fragment interacting with the user (based on its containing activity being resumed).
190  */
192 
195  origRatio = origHeight / (double) origWidth;
196 
199  }
200 
201  @Override
202  public void onPause() {
203  super.onPause();
204  /*
205  * 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.
206  *
207  * 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).
208  * 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).
209  */
211  }
212 
213  @Override
214  public void onValueChanged(LabelledSeekBar sb, float value, boolean fromUser) {
215 
216 
217  }
218 
219  @Override
221 
222  }
223 
224  @Override
226  if (keepRatioTBtn.isChecked()) {
227  if (sb == nWidth) {
229  } else if ( sb == nHeight) {
231  }
232  }
233 
234  }
235 
236  // @Override
237  // public void onStop() {
238  // super.onStop();
239  // /*
240  // * 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.
241  // */
242  // }
243 
244  // @Override
245  // public void onDestroyView() {
246  // super.onDestroyView();
247  // /*
248  // * allows the fragment to clean up resources associated with its View.
249  // *
250  // * Zde končí životní cyklus při umístění do backstacku
251  // */
252  // }
253 
254  // @Override
255  // public void onDestroy() {
256  // super.onDestroy();
257  // /*
258  // * called to do final cleanup of the fragment's state.
259  // */
260  // }
261 
262  // @Override
263  // public void onDetach() {
264  // super.onDetach();
265  // /*
266  // * called immediately prior to the fragment no longer being associated with its activity.
267  // */
268  // }
269 }