App
AlphaBrushToolSettingsFragment.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.app.touchlisteners.BrushToolTouchListener;
6 import mhr.appandroid.views.brushpicker.RoundBrushPickerView;
7 import mhr.appandroid.views.brushpicker.RoundBrushPickerView.RoundBrushPickerEvent;
8 import mhr.appandroid.views.brushpicker.RoundBrushPickerView.RoundBrushPickerViewEventListener;
9 import mhr.appandroid.views.pathpicker.PathPickerView;
10 import mhr.appandroid.views.pathpicker.PathPickerView.PathParams;
11 import mhr.appandroid.views.pathpicker.PathPickerView.PathPickerEvent;
12 import mhr.appandroid.views.pathpicker.PathPickerView.PathPickerViewEventListener;
13 import mhr.appcore.bitmap.NBitmap;
14 import mhr.appcore.commands.toolcommands.SelectToolCommand;
15 import mhr.appcore.tools.brushlike.AlphaBrush;
16 import mhr.appcore.tools.brushlike.BrushLikeTool.BrushMode;
17 import android.app.Activity;
18 import android.app.Fragment;
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;
24 import android.widget.ArrayAdapter;
25 import android.widget.Button;
26 import android.widget.Spinner;
27 
31 public class AlphaBrushToolSettingsFragment extends Fragment implements OnClickListener, PathPickerViewEventListener, RoundBrushPickerViewEventListener {
32 
33  //===== INTERFACES, CLASSES, ENUMS ==========================================================================================================//
34  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
35  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
36 
37  //===== FIELDS ==============================================================================================================================//
38  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
39  protected View root;
41  protected boolean firstCreated = true;
42 
45  protected boolean pathLivePreviewOn;
46  protected Button selectAlphaBrushToolBtn;
47  protected Spinner modePicker;
48 
49  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
50 
51  //===== CONSTRUCTORS, DESTRUCTORS, RELATED METHODS ==========================================================================================//
52  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
60  protected View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
61  root = inflater.inflate(R.layout.fragment_alpha_brush_tool_settings, container, false);
62 
63  modePicker = (Spinner) root.findViewById(R.id.AlphaBrushModeSp);
64  ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(activity, R.array.AlphaModeNames, android.R.layout.simple_spinner_item);
65  adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
66  modePicker.setAdapter(adapter);
67 
68  brushPicker = (RoundBrushPickerView) root.findViewById(R.id.AlphaBrushRoundBrushPicker);
70 
71  pathPicker = (PathPickerView) root.findViewById(R.id.AlphaBrushPathPicker);
73 
75  selectAlphaBrushToolBtn = (Button) root.findViewById(R.id.SelectAlphaBrushToolBtn);
76  selectAlphaBrushToolBtn.setOnClickListener(this);
77  firstCreated = false;
78 
79  return root;
80  }
81 
82  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
83 
84  //===== METHODS =============================================================================================================================//
85  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
89  protected void setBrush() {
90  BrushMode mode = null;
91  switch (modePicker.getSelectedItemPosition()) {
92  case 0:
93  mode = BrushMode.MODE_ADD;
94  break;
95  case 1:
96  mode = BrushMode.MODE_REMOVE;
97  break;
98  }
101  / 100.0)));
102  }
103 
104  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
105 
106  //===== CALLBACKS ===========================================================================================================================//
107  @Override
108  public void onClick(View v) {
109  int id = v.getId();
110  switch (id) {
111  case R.id.SelectAlphaBrushToolBtn:
112  setBrush();
113  }
114  }
115 
116  @Override
118  switch (e) {
119  case EVENT_SELECTED:
120  if (!pathLivePreviewOn) {
121  NBitmap tmp = v.getNewBrush();
122  pathPicker.setBrush(tmp);
123  tmp.dispose();
124  }
125  setBrush();
126 
127  break;
128 
129  case EVENT_CANCELED:
130  if (!pathLivePreviewOn) {
131  NBitmap tmp = v.getNewBrush();
132  pathPicker.setBrush(tmp);
133  tmp.dispose();
134  }
135 
136  break;
137 
138  case EVENT_CHANGED:
139  if (pathLivePreviewOn) {
140  NBitmap tmp = v.getNewBrush();
141  pathPicker.setBrush(tmp);
142  tmp.dispose();
143  }
144 
145  break;
146 
147  case EVENT_LIVE_PREVIEW_STATE_CHANGED:
148 
149  break;
150 
151  default:
152  break;
153  }
154 
155  }
156 
157  @Override
159  switch (e) {
160  case EVENT_SELECTED:
161  setBrush();
162  break;
163 
164  case EVENT_LIVE_PREVIEW_STATE_CHANGED:
166  if (pathLivePreviewOn) {
168  pathPicker.setBrush(tmp);
169  tmp.dispose();
170  }
171  break;
172  default:
173  break;
174  }
175 
176  }
177 
178  //----- LIFE CYCLE --------------------------------------------------------------------------------------------------------------------------//
179 
180  @Override
181  public void onAttach(Activity activity) {
182  super.onAttach(activity);
183  /*
184  * called once the fragment is associated with its activity.
185  */
186  this.activity = (AppMainActivity) activity;
187  }
188 
189  // @Override
190  // public void onCreate(Bundle savedInstanceState) {
191  // super.onCreate(savedInstanceState);
192  // /*
193  // * called to do initial creation of the fragment.
194  // *
195  // * The system calls this when creating the fragment. Within your implementation, you should initialize essential components of the fragment that you want
196  // * to retain when the fragment is paused or stopped, then resumed.
197  // */
198  // }
199 
200  @Override
201  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
202  /*
203  * creates and returns the view hierarchy associated with the fragment.
204  *
205  * 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
206  * 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.
207  *
208  * Zde začíná životní cyklus při návratu z backstacku
209  */
210  if (firstCreated) {
211  firstCreated = false;
212  return initView(inflater, container, savedInstanceState);
213  } else {
214  return root;
215  }
216  }
217 
218  // @Override
219  // public void onActivityCreated(Bundle savedInstanceState) {
220  // super.onActivityCreated(savedInstanceState);
221  // /*
222  // * tells the fragment that its activity has completed its own Activity.onCreate().
223  // */
224  // }
225 
226  // @Override // Vyžaduje API 17
227  // public void onViewStateRestored(Bundle savedInstanceState) {
228  // super.onViewStateRestored(savedInstanceState);
229  // /*
230  // * tells the fragment that all of the saved state of its view hierarchy has been restored.
231  // */
232  // }
233 
234  // @Override
235  // public void onStart() {
236  // super.onStart();
237  // /*
238  // * makes the fragment visible to the user (based on its containing activity being started).
239  // */
240  // }
241 
242  @Override
243  public void onResume() {
244  super.onResume();
245  /*
246  * makes the fragment interacting with the user (based on its containing activity being resumed).
247  */
248  NBitmap brush = brushPicker.getNewBrush();
249  pathPicker.setBrush(brush);
250  brush.dispose();
251  setBrush();
252 // PathParams pp = pathPicker.getNewPathParams();
253 // activity.app.addCommand(new SelectToolCommand(new AlphaBrush(brushPicker.getNewBrush(), BrushMode.MODE_ADD, pp.opacity / 100.0, pp.flow / 100.0, brushPicker.getSize()
254 // * pp.spacing / 100.0)));
256  }
257 
258  // @Override
259  // public void onPause() {
260  // super.onPause();
261  // /*
262  // * 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.
263  // *
264  // * 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).
265  // * 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).
266  // */
267  // }
268 
269  // @Override
270  // public void onStop() {
271  // super.onStop();
272  // /*
273  // * 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.
274  // */
275  // }
276 
277  // @Override
278  // public void onDestroyView() {
279  // super.onDestroyView();
280  // /*
281  // * allows the fragment to clean up resources associated with its View.
282  // *
283  // * Zde končí životní cyklus při umístění do backstacku
284  // */
285  // }
286 
287  // @Override
288  // public void onDestroy() {
289  // super.onDestroy();
290  // /*
291  // * called to do final cleanup of the fragment's state.
292  // */
293  // }
294 
295  // @Override
296  // public void onDetach() {
297  // super.onDetach();
298  // /*
299  // * called immediately prior to the fragment no longer being associated with its activity.
300  // */
301  // }
302 }