App
MasterMaskView.java
Go to the documentation of this file.
1 package mhr.appandroid.views.imagepresentationview;
2 
3 import mhr.appandroid.R;
4 import mhr.appandroid.adapters.APDBitmap;
5 import mhr.appandroid.views.SimpleBitmapView;
6 import mhr.appandroid.views.imagepresentationview.ImagePresentationEvent.EventType;
7 import mhr.appcore.image.layers.LayerPDInfo;
8 import mhr.appcore.image.layers.LayerType;
9 import android.app.Activity;
10 import android.content.ClipData;
11 import android.content.Context;
12 import android.graphics.Bitmap;
13 import android.graphics.BitmapFactory;
14 import android.graphics.BitmapShader;
15 import android.graphics.Rect;
16 import android.graphics.Shader.TileMode;
17 import android.util.AttributeSet;
18 import android.widget.CheckBox;
19 import android.widget.CompoundButton;
20 import android.widget.CompoundButton.OnCheckedChangeListener;
21 import android.widget.PopupMenu.OnMenuItemClickListener;
22 import android.widget.FrameLayout;
23 import android.widget.ImageView;
24 import android.widget.PopupMenu;
25 import android.widget.ProgressBar;
26 import android.widget.SeekBar;
27 import android.widget.SeekBar.OnSeekBarChangeListener;
28 import android.widget.TextView;
29 import android.view.DragEvent;
30 import android.view.MenuItem;
31 import android.view.View;
32 import android.view.View.OnClickListener;
33 import android.view.View.OnLongClickListener;
34 
35 
36 
37 public class MasterMaskView extends FrameLayout implements OnCheckedChangeListener, OnClickListener, OnLongClickListener, OnMenuItemClickListener {
38  //===================================================================================================================================================//
39  //===== PUBLIC ==============================================================================================================================//
40  //----- interface a třídy -------------------------------------------------------------------------------------------------------------------//
41  public interface OnMasterMaskEventListener {
43  }
44 
45  //----- pole --------------------------------------------------------------------------------------------------------------------------------//
46  //----- acesory a primitivní metody ---------------------------------------------------------------------------------------------------------//
48  this.listener = listener;
49  }
50 
51  public void setState(boolean selected, boolean applied) {
52  this.selected = selected;
53  if (selected) {
54  maskPreviewCheckedV.setBackgroundColor(checkedColor);
55  } else {
56  maskPreviewCheckedV.setBackgroundColor(uncheckedColor);
57  }
58  this.applied = applied;
59  maskAppliedChB.setChecked(applied);
60  }
61 
62  public boolean isSelected() {
63  return selected;
64  }
65 
66  public boolean isApplied() {
67  return applied;
68  }
69 
70  //----- konstruktory ------------------------------------------------------------------------------------------------------------------------//
71  public MasterMaskView(Context context) {
72  super(context);
73  init();
74  }
75 
76  public MasterMaskView(Context context, AttributeSet attrs) {
77  super(context, attrs);
78  init();
79  }
80 
81  public MasterMaskView(Context context, AttributeSet attrs, int defStyle) {
82  super(context, attrs, defStyle);
83  init();
84  }
85 
86  public void setMaskPreview(Bitmap preview) {
87  maskPreviewSBV.setBitmap(preview);
88  maskPreviewSBV.setVisibility(VISIBLE);
89  maskThumbIV.setVisibility(INVISIBLE);
90  }
91 
92  //----- destruktory -------------------------------------------------------------------------------------------------------------------------//
93  //----- metody ------------------------------------------------------------------------------------------------------------------------------//
94 
95  //===================================================================================================================================================//
96  //===== NON-PUBLIC ==========================================================================================================================//
97  //----- interface a třídy -------------------------------------------------------------------------------------------------------------------//
98  //----- pole --------------------------------------------------------------------------------------------------------------------------------//
99  protected ImageView maskThumbIV;
101  protected CheckBox maskAppliedChB;
102  protected View maskPreviewCheckedV;
103  protected View LayerViewOverlay;
104 
105 
106 
107 
108  protected boolean selected;
109  protected boolean applied;
110 
111  protected int checkedColor;
112  protected int uncheckedColor;
113 
115 
116  protected PopupMenu maskPopup;
117 
118  //----- acesory a primitivní metody ---------------------------------------------------------------------------------------------------------//
119  //----- konstruktory ------------------------------------------------------------------------------------------------------------------------//
120 
121  protected void init() {
122  try {
123  ((Activity) getContext()).getLayoutInflater().inflate(R.layout.view_master_mask, this, true);
124  } catch (ClassCastException exc) {
125  // Tento kod probehne, pokud je poroblem s pretypovanim, napriklad pro nahled v Eclipse
126  TextView tv = new TextView(getContext());
127  tv.setText("Prewiew not available, requires Activity to be Context.");
128  addView(tv);
129  return;
130  }
131 
132  maskThumbIV = (ImageView) findViewById(R.id.MasterMaskThumb);
133  maskPreviewSBV = (SimpleBitmapView) findViewById(R.id.MasterMaskPreview);
134  maskAppliedChB = (CheckBox) findViewById(R.id.MasterMaskAppliedChckB);
135  maskPreviewCheckedV = findViewById(R.id.MasterMaskPreviewChecked);
136  LayerViewOverlay = findViewById(R.id.LayerViewOverlay);
137 
138  maskPreviewCheckedV.setOnClickListener(this);
139  maskPreviewCheckedV.setOnLongClickListener(this);
140 
141  maskAppliedChB.setOnCheckedChangeListener(this);
142 
143  maskPreviewSBV.getBitmapBackground().setShader(new BitmapShader(BitmapFactory.decodeResource(getResources(), R.drawable.checkboard), TileMode.REPEAT, TileMode.REPEAT));
144 
145  uncheckedColor = 0x00000000;
146  checkedColor = getResources().getColor(R.color.SelectedToolBackground);
147 
148  maskPopup = new PopupMenu(getContext(), this);
149  maskPopup.inflate(R.menu.view_layer_view_mask);
150  maskPopup.setOnMenuItemClickListener(this);
151  }
152 
153  @Override
154  public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
155  if (buttonView == maskAppliedChB) {
156  if (listener != null) {
158  }
159  }
160  }
161 
162  @Override
163  public void onClick(View v) {
164  if (v == maskPreviewCheckedV) {
165  if (!selected) {
166  selected = true;
168  if (listener != null) {
170  }
171  }
172  }
173  }
174  //----- destruktory -------------------------------------------------------------------------------------------------------------------------//
175  //----- metody ------------------------------------------------------------------------------------------------------------------------------//
176 
177  @Override
178  public boolean onLongClick(View v) {
179  maskPopup.show();
180  return true;
181  }
182 
183  @Override
184  public boolean onMenuItemClick(MenuItem item) {
185  final int id = item.getItemId();
186  if (id == R.id.LayerPopUpCopyMaskBitmap) {
187  if (listener != null) {
189  }
190  } else if (id == R.id.LayerPopUpPasteMaskBitmap) {
191  if (listener != null) {
193  }
194  } else if (id == R.id.LayerPopUpClearMaskBitmap) {
195  if (listener != null) {
197  }
198  } else if (id == R.id.LayerPopUpFillMaskBitmap) {
199  if (listener != null) {
201  }
202  } else if (id == R.id.LayerPopUpInvertMaskBitmap) {
203  if (listener != null) {
205  }
206  } else if (id == R.id.LayerPopUpAddMaskBitmap) {
207  if (listener != null) {
209  }
210  } else if (id == R.id.LayerPopUpRemoveMaskBitmap) {
211  if (listener != null) {
213  }
214  }
215  return true;
216  }
217 
218  //===================================================================================================================================================//
219  //===== DEPRECATED ==========================================================================================================================//
220 
221 }