App
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;
71  protected ViewGroup layersToolbarContent;
72  protected LayoutInflater inflater;
76  protected SparseArray<LayerSettingsFragment> fragments = new SparseArray<LayerSettingsFragment>();
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);
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());
103 
104  //===== PŘIDÁNÍ FRAGMENTŮ ===================================================================================================================//
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 
116  f.setParent(this);
117  fragments.put(LayerType.LAYER_BRIGHTNESS.ordinal(), f);
118 
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 
132  f.setParent(this);
133  fragments.put(LayerType.LAYER_GAUSSIAN_BLUR.ordinal(), f);
134 
136  f.setParent(this);
137  fragments.put(LayerType.LAYER_LAPLACE_SHARPEN.ordinal(), f);
138 
140  f.setParent(this);
141  fragments.put(LayerType.LAYER_GAUSSIAN_SHARPEN.ordinal(), f);
142 
144  f.setParent(this);
146 
148  f.setParent(this);
150 
151  return root;
152  }
153 
154  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
155 
156  //===== METHODS =============================================================================================================================//
157  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
158  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
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());
177  }
178 
183  public void updateLayerFromPresentation(int layerId) {
187  activity.addCommand(cmd);
188  }
189 
193  public void updateLayers() {
195  synchronized (presentation) {
196  if (presentation.selectedLayerId >= 0) {
197  LayerSettingsFragment f = null;
199  f = fragments.get(i.type.ordinal());
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:
230  break;
231  case R.id.LayersCaptionTV:
233  break;
234  default:
235  break;
236  }
237  }
238 
239  @Override
241  updateLayers();
242  }
243 
244  @Override
246  AppCommand cmd;
247  switch (e.type) {
248 
249  case LAYER_SELECTED:
253  activity.addCommand(cmd);
254  break;
255  case LAYER_MASK_SELECTED:
259  activity.addCommand(cmd);
260  break;
261  case MASTER_MASK_SELECTED:
265  activity.addCommand(cmd);
266  break;
267 
268  case LAYER_VISIBILITY_CHANGED:
270  cmd = new SetLayerVisibilityCommand(e.layerId, ((Boolean) e.extra));
272  activity.addCommand(cmd);
273  break;
274  case LAYER_MASK_ACTIVE_CHANGED:
276  cmd = new SetLayerMaskActiveCommand(e.layerId, ((Boolean) e.extra));
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:
287  cmd = new SetLayerOpacityCommand(e.layerId, ((Double) e.extra));
289  activity.addCommand(cmd);
290  break;
291  case LAYER_MOVED:
293  cmd = new MoveLayerCommand(e.layerId, ((Integer) e.extra));
295  activity.addCommand(cmd);
296  break;
297 
298  case LAYER_CREATED:
300  cmd = new CreateLayerCommand((LayerType) e.extra, e.layerId);
302  activity.addCommand(cmd);
303  break;
304  case LAYER_DUPLICATED:
306  cmd = new DuplicateLayerCommand(e.layerId);
308  activity.addCommand(cmd);
309  break;
310 
311  case LAYER_DELETED:
313  cmd = new DeleteLayerCommand(e.layerId);
315  activity.addCommand(cmd);
316  break;
317 
318 //---------------------------------------------------------------------------------------------------------------------------------------------------//
319  case LAYER_COPY_BITMAP:
321  break;
322 
323  case LAYER_MASK_COPY_BITMAP:
325  break;
326 
327  case MASTER_MASK_COPY_BITMAP:
329  break;
330 
331 //---------------------------------------------------------------------------------------------------------------------------------------------------//
332  case LAYER_PASTE_BITMAP:
334  break;
335 
336  case LAYER_MASK_PASTE_BITMAP:
338  break;
339 
340  case MASTER_MASK_PASTE_BITMAP:
342  break;
343 
344 //---------------------------------------------------------------------------------------------------------------------------------------------------//
345  case LAYER_CLEAR_BITMAP:
347  break;
348 
349  case LAYER_MASK_CLEAR_BITMAP:
351  break;
352 
353  case MASTER_MASK_CLEAR_BITMAP:
355  break;
356 
357 //---------------------------------------------------------------------------------------------------------------------------------------------------//
358  case LAYER_MASK_FILL_BITMAP:
360  break;
361 
362  case MASTER_MASK_FILL_BITMAP:
364  break;
365 
366 //---------------------------------------------------------------------------------------------------------------------------------------------------//
367  case LAYER_MASK_INVERT_BITMAP:
369  break;
370 
371  case MASTER_MASK_INVERT_BITMAP:
373  break;
374 
375 //---------------------------------------------------------------------------------------------------------------------------------------------------//
376  case LAYER_ADD_BITMAP:
378  break;
379 
380  case LAYER_MASK_ADD_BITMAP:
382  break;
383 
384  case MASTER_MASK_ADD_BITMAP:
386  break;
387 
388 //---------------------------------------------------------------------------------------------------------------------------------------------------//
389  case LAYER_REMOVE_BITMAP:
391  break;
392 
393  case LAYER_MASK_REMOVE_BITMAP:
395  break;
396 
397  case MASTER_MASK_REMOVE_BITMAP:
399  break;
400 
401 //---------------------------------------------------------------------------------------------------------------------------------------------------//
402  case LAYER_BLEND_BITMAP:
404  break;
405 
406 //---------------------------------------------------------------------------------------------------------------------------------------------------//
407  case IMAGE_MERGE_LAYERS:
409  cmd = new MergeAllCommand();
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() {
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  */
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 }