App
LayerSettingsFragment.java
Go to the documentation of this file.
1 package mhr.app.fragments.layers;
2 
3 import mhr.app.AppMainActivity;
4 import mhr.app.R;
5 import mhr.appandroid.adapters.APDImagePresentation;
6 import mhr.appcore.blending.BlendMode;
7 import mhr.appcore.image.layers.LayerSpecificPresentation;
8 import mhr.appcore.image.layers.RasterLayerSpecificPresentation;
9 import android.app.Activity;
10 import android.app.Fragment;
11 import android.os.Bundle;
12 import android.view.LayoutInflater;
13 import android.view.View;
14 import android.view.View.OnClickListener;
15 import android.view.ViewGroup;
16 import android.widget.Button;
17 import android.widget.Toast;
18 
22 public abstract class LayerSettingsFragment extends Fragment implements OnClickListener{
23 
24  //===== INTERFACES, CLASSES, ENUMS ==========================================================================================================//
25  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
26  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
27 
28  //===== FIELDS ==============================================================================================================================//
29  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
30  protected View root;
31  protected LayoutInflater inflater;
34  protected int associatedLayerId = -1;
35  protected boolean firstCreated = true;
36  protected boolean initialized = false;
37  protected boolean updatePending = false;
38  protected Button selectBtn;
39 
40  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
41 
42  //===== CONSTRUCTORS, DESTRUCTORS, RELATED METHODS ==========================================================================================//
43  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
51  protected abstract View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState);
52  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
53 
54  //===== METHODS =============================================================================================================================//
55  //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
60  protected abstract void updateFromPresentation(LayerSpecificPresentation pres);
65  protected abstract void updatePresentation(LayerSpecificPresentation pres);
66 
70  protected void onSelectBtnClicked() {
72  if (pres != null) {
73  synchronized (pres) {
75  }
76  }
78  }
79  //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
85  this.parent = parent;
86  }
87 
92  public void setAssociatedLayerId(int id) {
93  this.associatedLayerId = id;
94  if (!initialized || associatedLayerId < 0) {
95  updatePending = true;
96  return;
97  }
99  if (pres != null) {
100  synchronized (pres) {
102  }
103  }
104  }
105 
106  //===== CALLBACKS ===========================================================================================================================//
107  @Override
108  public void onClick(View v) {
109  switch (v.getId()) {
110  case R.id.LayerSettingsSelectBtn:
112  break;
113  default:
114  break;
115  }
116  }
117  //----- LIFE CYCLE --------------------------------------------------------------------------------------------------------------------------//
118 
119  @Override
120  public void onAttach(Activity activity) {
121  super.onAttach(activity);
122  /*
123  * called once the fragment is associated with its activity.
124  */
125  this.activity = (AppMainActivity) activity;
126  }
127 
128  // @Override
129  // public void onCreate(Bundle savedInstanceState) {
130  // super.onCreate(savedInstanceState);
131  // /*
132  // * called to do initial creation of the fragment.
133  // *
134  // * The system calls this when creating the fragment. Within your implementation, you should initialize essential components of the fragment that you want
135  // * to retain when the fragment is paused or stopped, then resumed.
136  // */
137  // }
138 
139  @Override
140  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
141  //return super.onCreateView(inflater, container, savedInstanceState);
142  /*
143  * creates and returns the view hierarchy associated with the fragment.
144  *
145  * 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
146  * 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.
147  *
148  * Zde začíná životní cyklus při návratu z backstacku
149  */
150  if (firstCreated) {
151  firstCreated = false;
152  initView(inflater, container, savedInstanceState);
153  selectBtn = (Button) root.findViewById(R.id.LayerSettingsSelectBtn);
154  selectBtn.setOnClickListener(this);
155  initialized = true;
156  }
157  return root;
158  }
159 
160 // @Override
161 // public void onActivityCreated(Bundle savedInstanceState) {
162 // super.onActivityCreated(savedInstanceState);
163 // /*
164 // * tells the fragment that its activity has completed its own Activity.onCreate().
165 // */
166 // }
167 
168  // @Override // Vyžaduje API 17
169  // public void onViewStateRestored(Bundle savedInstanceState) {
170  // super.onViewStateRestored(savedInstanceState);
171  // /*
172  // * tells the fragment that all of the saved state of its view hierarchy has been restored.
173  // */
174  // }
175 
176  // @Override
177  // public void onStart() {
178  // super.onStart();
179  // /*
180  // * makes the fragment visible to the user (based on its containing activity being started).
181  // */
182  // }
183 
184  @Override
185  public void onResume() {
186  super.onResume();
187  /*
188  * makes the fragment interacting with the user (based on its containing activity being resumed).
189  */
190  if (updatePending) {
191  updatePending = false;
192  setAssociatedLayerId(associatedLayerId); // Zde je již inicializovaný View, proto je bezepčné zavolat. Je zde kvůli prvnímu volání.
193  }
194  }
195 
196  // @Override
197  // public void onPause() {
198  // super.onPause();
199  // /*
200  // * 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.
201  // *
202  // * 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).
203  // * 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).
204  // */
205  // }
206 
207  // @Override
208  // public void onStop() {
209  // super.onStop();
210  // /*
211  // * 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.
212  // */
213  // }
214 
215  // @Override
216  // public void onDestroyView() {
217  // super.onDestroyView();
218  // /*
219  // * allows the fragment to clean up resources associated with its View.
220  // *
221  // * Zde končí životní cyklus při umístění do backstacku
222  // */
223  // }
224 
225  // @Override
226  // public void onDestroy() {
227  // super.onDestroy();
228  // /*
229  // * called to do final cleanup of the fragment's state.
230  // */
231  // }
232 
233  // @Override
234  // public void onDetach() {
235  // super.onDetach();
236  // /*
237  // * called immediately prior to the fragment no longer being associated with its activity.
238  // */
239  // }
240 
241 }