App

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

- File List
- File Members

LayersPaneFragment.java
Go to the documentation of this file.
1 package mhr.app.fragments.layers;
2
3 import java.util.HashMap;
4
5 import mhr.app.AppMainActivity;
6 import mhr.app.R;
7 import mhr.app.fragments.layers.filter.DifferenceOfGaussianSharpenLayerSettingsFragment;
8 import mhr.app.fragments.layers.filter.GaussianBlurLayerSettingsFragment;
9 import mhr.app.fragments.layers.filter.GaussianSharpenLayerSettingsFragment;
10 import mhr.app.fragments.layers.filter.LaplaceSharpenLayerSettingsFragment;
11 import mhr.app.fragments.layers.filter.LaplacianOfGaussianSharpenLayerSettingsFragment;
12 import mhr.app.fragments.layers.lut.BrightnessLayerSettingsFragment;
13 import mhr.app.fragments.layers.lut.ContrastLayerSettingsFragment;
14 import mhr.app.fragments.layers.lut.CurvesLayerSettingsFragment;
15 import mhr.app.fragments.layers.lut.GammaLayerSettingsFragment;
16 import mhr.appandroid.adapters.APDImagePresentation;
17 import mhr.appandroid.adapters.APDImagePresentation.OnImagePresentationChangedListener;
18 import mhr.appandroid.feedback.APDFeedback;
19 import mhr.appandroid.views.imagepresentationview.ImagePresentationView;
20 import mhr.appandroid.views.imagepresentationview.ImagePresentationView.OnImagePresentationEventListener;
21 import mhr.appandroid.views.imagepresentationview.ImagePresentationEvent;
22 import mhr.appcore.commands.AppCommand;
23 import mhr.appcore.commands.imagecommands.CreateLayerCommand;
24 import mhr.appcore.commands.imagecommands.DeleteLayerCommand;
25 import mhr.appcore.commands.imagecommands.DuplicateLayerCommand;
26 import mhr.appcore.commands.imagecommands.MergeAllCommand;
27 import mhr.appcore.commands.imagecommands.MoveLayerCommand;
28 import mhr.appcore.commands.imagecommands.SetImageSelectedStateCommand;
29 import mhr.appcore.commands.imagecommands.SetLayerMaskActiveCommand;
30 import mhr.appcore.commands.imagecommands.SetLayerOpacityCommand;
31 import mhr.appcore.commands.imagecommands.SetLayerVisibilityCommand;
32 import mhr.appcore.commands.imagecommands.SetMasterMaskActiveCommand;
33 import mhr.appcore.commands.imagecommands.UpdateLayerFromPresentationCommand;
34 import mhr.appcore.commands.imagecommands.rasterdatacommands.AddRasterDataCommand;
35 import mhr.appcore.commands.imagecommands.rasterdatacommands.BlendRasterDataCommand;
36 import mhr.appcore.commands.imagecommands.rasterdatacommands.ClearRasterDataCommand;
37 import mhr.appcore.commands.imagecommands.rasterdatacommands.CopyRasterDataCommand;
38 import mhr.appcore.commands.imagecommands.rasterdatacommands.FillRasterDataCommand;
39 import mhr.appcore.commands.imagecommands.rasterdatacommands.InvertRasterDataCommand;
40 import mhr.appcore.commands.imagecommands.rasterdatacommands.PasteRasterDataCommand;
41 import mhr.appcore.commands.imagecommands.rasterdatacommands.RemoveRasterDataCommand;
42 import mhr.appcore.image.ImageSelectedState;
43 import mhr.appcore.image.layers.LayerPDInfo;
44 import mhr.appcore.image.layers.LayerType;
45 import mhr.appcore.interfaces.PDFeedback;
46 import android.app.Activity;
47 import android.app.Fragment;
48 import android.app.FragmentTransaction;
49 import android.graphics.Rect;
50 import android.os.Bundle;
51 import android.util.SparseArray;
52 import android.view.LayoutInflater;
53 import android.view.View;
54 import android.view.View.OnClickListener;
55 import android.view.ViewGroup;
56 import android.widget.Toast;
57
61 public class LayersPaneFragment extends Fragment implements OnClickListener, OnImagePresentationChangedListener, OnImagePresentationEventListener {
62
63 //===== INTERFACES, CLASSES, ENUMS ==========================================================================================================//
64 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
65 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
66
67 //===== FIELDS ==============================================================================================================================//
68 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
69 protected View root;
70 protected ImagePresentationView layers;
71 protected ViewGroup layersToolbarContent;
72 protected LayoutInflater inflater;
73 protected AppMainActivity activity;
74 protected APDImagePresentation presentation;
75 protected PDFeedback hideProgressBarFeedback;
76 protected SparseArray<LayerSettingsFragment> fragments = new SparseArray<LayerSettingsFragment>();
77 protected LayerSettingsFragment currentSettings = null;
78
79 protected boolean firstCreated = true;
80
81 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
82
83 //===== CONSTRUCTORS, DESTRUCTORS, RELATED METHODS ==========================================================================================//
84 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
92 protected View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
93 root = inflater.inflate(R.layout.fragment_layers_pane, container, false);
94 layers = (ImagePresentationView) root.findViewById(R.id.ImageLayersView);
95 layers.setOnLayerEventListener(this);
96 layersToolbarContent = (ViewGroup) root.findViewById(R.id.LayersToolbarContent);
97 root.findViewById(R.id.LayersToolbarBorder).setOnClickListener(this);
98 root.findViewById(R.id.LayersCaptionTV).setOnClickListener(this);
99 Rect thumb = layers.getLayerPreviewRect();
100 presentation = new APDImagePresentation(thumb.width(), thumb.height(), thumb.width(), thumb.height());
101 layers.setImagePresentation(presentation);
102 presentation.setOnImagePresentationChangedListener(this, activity);
103
104 //===== PŘIDÁNÍ FRAGMENTŮ ===================================================================================================================//
105 LayerSettingsFragment f;
106
107 f = new RasterLayerSettingsFragment();
108 f.setParent(this);
109 fragments.put(LayerType.LAYER_RASTER.ordinal(), f);
110
111 f = new ColorLayerSettingsFragment();
112 f.setParent(this);
113 fragments.put(LayerType.LAYER_COLOR.ordinal(), f);
114
115 f = new BrightnessLayerSettingsFragment();
116 f.setParent(this);
117 fragments.put(LayerType.LAYER_BRIGHTNESS.ordinal(), f);
118
119 f = new ContrastLayerSettingsFragment();
120 f.setParent(this);
121 fragments.put(LayerType.LAYER_CONTRAST.ordinal(), f);
122
123 f = new GammaLayerSettingsFragment();
124 f.setParent(this);
125 fragments.put(LayerType.LAYER_GAMMA.ordinal(), f);
126
127 f = new CurvesLayerSettingsFragment();
128 f.setParent(this);
129 fragments.put(LayerType.LAYER_CURVES.ordinal(), f);
130
131 f = new GaussianBlurLayerSettingsFragment();
132 f.setParent(this);
133 fragments.put(LayerType.LAYER_GAUSSIAN_BLUR.ordinal(), f);
134
135 f = new LaplaceSharpenLayerSettingsFragment();
136 f.setParent(this);
137 fragments.put(LayerType.LAYER_LAPLACE_SHARPEN.ordinal(), f);
138
139 f = new GaussianSharpenLayerSettingsFragment();
140 f.setParent(this);
141 fragments.put(LayerType.LAYER_GAUSSIAN_SHARPEN.ordinal(), f);
142
143 f = new LaplacianOfGaussianSharpenLayerSettingsFragment();
144 f.setParent(this);
145 fragments.put(LayerType.LAYER_LAPLACIAN_OF_GAUSSIAN_SHARPEN.ordinal(), f);
146
147 f = new DifferenceOfGaussianSharpenLayerSettingsFragment();
148 f.setParent(this);
149 fragments.put(LayerType.LAYER_DIFFERENCE_OF_GAUSSIAN_SHARPEN.ordinal(), f);
150
151 return root;
152 }
153
154 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
155
156 //===== METHODS =============================================================================================================================//
157 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
158 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
163 public APDImagePresentation getImagePresentation() {
164 return presentation;
165 }
166
170 public void reseImagePresentation() {
171 Rect thumb = layers.getLayerPreviewRect();
172 presentation = new APDImagePresentation(thumb.width(), thumb.height(), thumb.width(), thumb.height());
173 layers.setImagePresentation(presentation);
174 presentation.setOnImagePresentationChangedListener(this, activity);
175 activity.getAppCore().setImagePresentation(presentation);
176 layers.updateFromPresentation();
177 }
178
183 public void updateLayerFromPresentation(int layerId) {
184 activity.showProgressBar();
185 AppCommand cmd = new UpdateLayerFromPresentationCommand(layerId);
186 cmd.setPDFeedback(hideProgressBarFeedback);
187 activity.addCommand(cmd);
188 }
189
193 public void updateLayers() {
194 layers.updateFromPresentation();
195 synchronized (presentation) {
196 if (presentation.selectedLayerId >= 0) {
197 LayerSettingsFragment f = null;
198 LayerPDInfo i = presentation.getLayerInfo(presentation.selectedLayerId);
199 f = fragments.get(i.type.ordinal());
200 f.setAssociatedLayerId(presentation.selectedLayerId);
201 if (f == currentSettings) {
202 return;
203 }
204 FragmentTransaction ft = getFragmentManager().beginTransaction();
205 ft.replace(R.id.LayerSettingPlaceholder, f);
206 ft.commit();
207 currentSettings = f;
208 } else {
209 }
210 }
211 }
212
216 public void changeVisibility() {
217 if (layersToolbarContent.getVisibility() == View.VISIBLE) {
218 layersToolbarContent.setVisibility(View.GONE);
219 } else {
220 layersToolbarContent.setVisibility(View.VISIBLE);
221 }
222 }
223
224 //===== CALLBACKS ===========================================================================================================================//
225 @Override
226 public void onClick(View v) {
227 switch (v.getId()) {
228 case R.id.LayersToolbarBorder:
229 changeVisibility();
230 break;
231 case R.id.LayersCaptionTV:
232 changeVisibility();
233 break;
234 default:
235 break;
236 }
237 }
238
239 @Override
240 public void onImagePresentationChanged(APDImagePresentation p) {
241 updateLayers();
242 }
243
244 @Override
245 public void onImagePresentationEvent(ImagePresentationEvent e) {
246 AppCommand cmd;
247 switch (e.type) {
248
249 case LAYER_SELECTED:
250 activity.showProgressBar();
251 cmd = new SetImageSelectedStateCommand(ImageSelectedState.SELECTED_LAYER, e.layerId);
252 cmd.setPDFeedback(hideProgressBarFeedback);
253 activity.addCommand(cmd);
254 break;
255 case LAYER_MASK_SELECTED:
256 activity.showProgressBar();
257 cmd = new SetImageSelectedStateCommand(ImageSelectedState.SELECTED_MASK, e.layerId);
258 cmd.setPDFeedback(hideProgressBarFeedback);
259 activity.addCommand(cmd);
260 break;
261 case MASTER_MASK_SELECTED:
262 activity.showProgressBar();
263 cmd = new SetImageSelectedStateCommand(ImageSelectedState.SELECTED_MASTER_MASK, -1);
264 cmd.setPDFeedback(hideProgressBarFeedback);
265 activity.addCommand(cmd);
266 break;
267
268 case LAYER_VISIBILITY_CHANGED:
269 activity.showProgressBar();
270 cmd = new SetLayerVisibilityCommand(e.layerId, ((Boolean) e.extra));
271 cmd.setPDFeedback(hideProgressBarFeedback);
272 activity.addCommand(cmd);
273 break;
274 case LAYER_MASK_ACTIVE_CHANGED:
275 activity.showProgressBar();
276 cmd = new SetLayerMaskActiveCommand(e.layerId, ((Boolean) e.extra));
277 cmd.setPDFeedback(hideProgressBarFeedback);
278 activity.addCommand(cmd);
279 break;
280 case MASTER_MASK_APPLIED_CHANGED:
281 cmd = new SetMasterMaskActiveCommand((Boolean) e.extra);
282 activity.addCommand(cmd);
283 break;
284
285 case LAYER_OPACITY_CHANGED:
286 activity.showProgressBar();
287 cmd = new SetLayerOpacityCommand(e.layerId, ((Double) e.extra));
288 cmd.setPDFeedback(hideProgressBarFeedback);
289 activity.addCommand(cmd);
290 break;
291 case LAYER_MOVED:
292 activity.showProgressBar();
293 cmd = new MoveLayerCommand(e.layerId, ((Integer) e.extra));
294 cmd.setPDFeedback(hideProgressBarFeedback);
295 activity.addCommand(cmd);
296 break;
297
298 case LAYER_CREATED:
299 activity.showProgressBar();
300 cmd = new CreateLayerCommand((LayerType) e.extra, e.layerId);
301 cmd.setPDFeedback(hideProgressBarFeedback);
302 activity.addCommand(cmd);
303 break;
304 case LAYER_DUPLICATED:
305 activity.showProgressBar();
306 cmd = new DuplicateLayerCommand(e.layerId);
307 cmd.setPDFeedback(hideProgressBarFeedback);
308 activity.addCommand(cmd);
309 break;
310
311 case LAYER_DELETED:
312 activity.showProgressBar();
313 cmd = new DeleteLayerCommand(e.layerId);
314 cmd.setPDFeedback(hideProgressBarFeedback);
315 activity.addCommand(cmd);
316 break;
317
318 //---------------------------------------------------------------------------------------------------------------------------------------------------//
319 case LAYER_COPY_BITMAP:
320 activity.addCommand(new CopyRasterDataCommand(ImageSelectedState.SELECTED_LAYER, e.layerId));
321 break;
322
323 case LAYER_MASK_COPY_BITMAP:
324 activity.addCommand(new CopyRasterDataCommand(ImageSelectedState.SELECTED_MASK, e.layerId));
325 break;
326
327 case MASTER_MASK_COPY_BITMAP:
328 activity.addCommand(new CopyRasterDataCommand(ImageSelectedState.SELECTED_MASTER_MASK, e.layerId));
329 break;
330
331 //---------------------------------------------------------------------------------------------------------------------------------------------------//
332 case LAYER_PASTE_BITMAP:
333 activity.addCommand(new PasteRasterDataCommand(ImageSelectedState.SELECTED_LAYER, e.layerId));
334 break;
335
336 case LAYER_MASK_PASTE_BITMAP:
337 activity.addCommand(new PasteRasterDataCommand(ImageSelectedState.SELECTED_MASK, e.layerId));
338 break;
339
340 case MASTER_MASK_PASTE_BITMAP:
341 activity.addCommand(new PasteRasterDataCommand(ImageSelectedState.SELECTED_MASTER_MASK, e.layerId));
342 break;
343
344 //---------------------------------------------------------------------------------------------------------------------------------------------------//
345 case LAYER_CLEAR_BITMAP:
346 activity.addCommand(new ClearRasterDataCommand(ImageSelectedState.SELECTED_LAYER, e.layerId));
347 break;
348
349 case LAYER_MASK_CLEAR_BITMAP:
350 activity.addCommand(new ClearRasterDataCommand(ImageSelectedState.SELECTED_MASK, e.layerId));
351 break;
352
353 case MASTER_MASK_CLEAR_BITMAP:
354 activity.addCommand(new ClearRasterDataCommand(ImageSelectedState.SELECTED_MASTER_MASK, e.layerId));
355 break;
356
357 //---------------------------------------------------------------------------------------------------------------------------------------------------//
358 case LAYER_MASK_FILL_BITMAP:
359 activity.addCommand(new FillRasterDataCommand(ImageSelectedState.SELECTED_MASK, e.layerId));
360 break;
361
362 case MASTER_MASK_FILL_BITMAP:
363 activity.addCommand(new FillRasterDataCommand(ImageSelectedState.SELECTED_MASTER_MASK, e.layerId));
364 break;
365
366 //---------------------------------------------------------------------------------------------------------------------------------------------------//
367 case LAYER_MASK_INVERT_BITMAP:
368 activity.addCommand(new InvertRasterDataCommand(ImageSelectedState.SELECTED_MASK, e.layerId));
369 break;
370
371 case MASTER_MASK_INVERT_BITMAP:
372 activity.addCommand(new InvertRasterDataCommand(ImageSelectedState.SELECTED_MASTER_MASK, e.layerId));
373 break;
374
375 //---------------------------------------------------------------------------------------------------------------------------------------------------//
376 case LAYER_ADD_BITMAP:
377 activity.addCommand(new AddRasterDataCommand(ImageSelectedState.SELECTED_LAYER, e.layerId));
378 break;
379
380 case LAYER_MASK_ADD_BITMAP:
381 activity.addCommand(new AddRasterDataCommand(ImageSelectedState.SELECTED_MASK, e.layerId));
382 break;
383
384 case MASTER_MASK_ADD_BITMAP:
385 activity.addCommand(new AddRasterDataCommand(ImageSelectedState.SELECTED_MASTER_MASK, e.layerId));
386 break;
387
388 //---------------------------------------------------------------------------------------------------------------------------------------------------//
389 case LAYER_REMOVE_BITMAP:
390 activity.addCommand(new RemoveRasterDataCommand(ImageSelectedState.SELECTED_LAYER, e.layerId));
391 break;
392
393 case LAYER_MASK_REMOVE_BITMAP:
394 activity.addCommand(new RemoveRasterDataCommand(ImageSelectedState.SELECTED_MASK, e.layerId));
395 break;
396
397 case MASTER_MASK_REMOVE_BITMAP:
398 activity.addCommand(new RemoveRasterDataCommand(ImageSelectedState.SELECTED_MASTER_MASK, e.layerId));
399 break;
400
401 //---------------------------------------------------------------------------------------------------------------------------------------------------//
402 case LAYER_BLEND_BITMAP:
403 activity.addCommand(new BlendRasterDataCommand(ImageSelectedState.SELECTED_LAYER, e.layerId));
404 break;
405
406 //---------------------------------------------------------------------------------------------------------------------------------------------------//
407 case IMAGE_MERGE_LAYERS:
408 activity.showProgressBar();
409 cmd = new MergeAllCommand();
410 cmd.setPDFeedback(hideProgressBarFeedback);
411 activity.addCommand(cmd);
412 break;
413
414 default:
415 break;
416 }
417
418 }
419
420 //----- LIFE CYCLE --------------------------------------------------------------------------------------------------------------------------//
421
422 @Override
423 public void onAttach(Activity activity) {
424 super.onAttach(activity);
425 /*
426 * called once the fragment is associated with its activity.
427 */
428 this.activity = (AppMainActivity) getActivity();
429 hideProgressBarFeedback = new APDFeedback(activity) {
430
431 @Override
432 public void run() {
433 LayersPaneFragment.this.activity.hideProgressBar();
434
435 }
436 };
437 }
438
439 // @Override
440 // public void onCreate(Bundle savedInstanceState) {
441 // super.onCreate(savedInstanceState);
442 // /*
443 // * called to do initial creation of the fragment.
444 // *
445 // * The system calls this when creating the fragment. Within your implementation, you should initialize essential components of the fragment that you want
446 // * to retain when the fragment is paused or stopped, then resumed.
447 // */
448 // }
449
450 @Override
451 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
452 //return super.onCreateView(inflater, container, savedInstanceState);
453 /*
454 * creates and returns the view hierarchy associated with the fragment.
455 *
456 * 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
457 * 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.
458 *
459 * Zde začíná životní cyklus při návratu z backstacku
460 */
461 if (firstCreated) {
462 firstCreated = false;
463 return initView(inflater, container, savedInstanceState);
464 } else {
465 return root;
466 }
467
468 }
469
470 // @Override
471 // public void onActivityCreated(Bundle savedInstanceState) {
472 // super.onActivityCreated(savedInstanceState);
473 // /*
474 // * tells the fragment that its activity has completed its own Activity.onCreate().
475 // */
476 // }
477
478 // @Override // Vyžaduje API 17
479 // public void onViewStateRestored(Bundle savedInstanceState) {
480 // super.onViewStateRestored(savedInstanceState);
481 // /*
482 // * tells the fragment that all of the saved state of its view hierarchy has been restored.
483 // */
484 // }
485
486 // @Override
487 // public void onStart() {
488 // super.onStart();
489 // /*
490 // * makes the fragment visible to the user (based on its containing activity being started).
491 // */
492 // }
493
494 @Override
495 public void onResume() {
496 super.onResume();
497 /*
498 * makes the fragment interacting with the user (based on its containing activity being resumed).
499 */
500 layers.updateFromPresentation();
501 }
502
503 // @Override
504 // public void onPause() {
505 // super.onPause();
506 // /*
507 // * 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.
508 // *
509 // * 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).
510 // * 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).
511 // */
512 // }
513
514 // @Override
515 // public void onStop() {
516 // super.onStop();
517 // /*
518 // * 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.
519 // */
520 // }
521
522 // @Override
523 // public void onDestroyView() {
524 // super.onDestroyView();
525 // /*
526 // * allows the fragment to clean up resources associated with its View.
527 // *
528 // * Zde končí životní cyklus při umístění do backstacku
529 // */
530 // }
531
532 // @Override
533 // public void onDestroy() {
534 // super.onDestroy();
535 // /*
536 // * called to do final cleanup of the fragment's state.
537 // */
538 // }
539
540 // @Override
541 // public void onDetach() {
542 // super.onDetach();
543 // /*
544 // * called immediately prior to the fragment no longer being associated with its activity.
545 // */
546 // }
547
548 }