App

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

- File List
- File Members

ImagesExplorerPopUpFragment.java
Go to the documentation of this file.
1 package mhr.app.fragments.toolbox;
2
3 import java.io.File;
4 import java.util.ArrayList;
5
6 import mhr.app.AppMainActivity;
7 import mhr.app.R;
8 import mhr.appandroid.adapters.AndroidImageFile;
9 import mhr.appandroid.views.SimpleBitmapView;
10 import android.app.Activity;
11 import android.app.Fragment;
12 import android.content.res.Resources;
13 import android.graphics.Bitmap;
14 import android.os.Bundle;
15 import android.view.LayoutInflater;
16 import android.view.View;
17 import android.view.View.OnClickListener;
18 import android.view.ViewGroup;
19 import android.widget.Button;
20 import android.widget.EditText;
21 import android.widget.LinearLayout;
22 import android.widget.TextView;
23
27 public abstract class ImagesExplorerPopUpFragment extends Fragment implements OnClickListener {
28
29 //===== INTERFACES, CLASSES, ENUMS ==========================================================================================================//
30 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
31 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
32
33 //===== FIELDS ==============================================================================================================================//
34 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
35 protected View root;
36 protected AppMainActivity activity;
37 protected boolean firstCreated = true;
38
39 protected LinearLayout items;
40 protected String selected = null;
41 protected View selIndicator;
42
43 protected EditText fnameET;
44 protected TextView captionTV;
45
46 protected String caption = "Some generic caption";
47 protected boolean fnameEnabled = false;
48 protected String actionCaption = "ACTION";
49
50
51
52 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
53
54 //===== CONSTRUCTORS, DESTRUCTORS, RELATED METHODS ==========================================================================================//
55 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
63 protected View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
64 root = inflater.inflate(R.layout.fragment_image_explorer_popup, container, false);
65
66 Button b = (Button) root.findViewById(R.id.ImageExplorerActionBtn);
67 b.setOnClickListener(this);
68 b.setText(actionCaption );
69
70 root.findViewById(R.id.DeleteImageBtn).setOnClickListener(this);
71 root.findViewById(R.id.CancelBtn).setOnClickListener(this);
72
73 fnameET = (EditText) root.findViewById(R.id.ImageExplorerFNameET);
74 captionTV = (TextView) root.findViewById(R.id.ImaegExplorerPopUpCaption);
75
76 if (!fnameEnabled) {
77 fnameET.setVisibility(View.GONE);
78 }
79
80 captionTV.setText(caption);
81
82 items = (LinearLayout) root.findViewById(R.id.ImageExplorerItems);
83
84 initItems(inflater);
85
86 firstCreated = false;
87
88 return root;
89 }
90
91 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
92
93 //===== METHODS =============================================================================================================================//
94 //----- NON-PUBLIC --------------------------------------------------------------------------------------------------------------------------//
99 protected void initItems(LayoutInflater inflater) {
100 items.removeAllViews();
101 File r = activity.getExternalFilesDir(null);
102 File[] files = r.listFiles();
103 Resources res = getResources();
104 int size = res.getDimensionPixelSize(R.dimen.LayerThumbSize) - 2 * res.getDimensionPixelSize(R.dimen.LayerThumbPadding);
105 if (files != null) {
106 for (File f : files ) {
107 if (f.isDirectory()) {
108 final ViewGroup v = (ViewGroup) inflater.inflate(R.layout.image_explorer_item, null);
109 final String fname = f.getName();
110 ((TextView)v.findViewById(R.id.ImageNameTV)).setText(fname);
111
112 Bitmap thumb = AndroidImageFile.loadThumb(f, 200, 200);
113
114 ((SimpleBitmapView)v.findViewById(R.id.ImagePreview)).setBitmap(thumb);
115 v.findViewById(R.id.ImagePreview).setVisibility(View.VISIBLE);
116 v.findViewById(R.id.ImageThumb).setVisibility(View.INVISIBLE);
117
118 v.setOnClickListener(new View.OnClickListener() {
119
120 View indicator = v.findViewById(R.id.ImageChecked);
121 String name = fname;
122
123 @Override
124 public void onClick(View v) {
125 if (selIndicator != null) {
126 selIndicator.setVisibility(View.INVISIBLE);
127 }
128 selIndicator = indicator;
129 indicator.setVisibility(View.VISIBLE);
130 selected = name;
131 }
132 });
133 items.addView(v);
134 }
135 }
136 }
137
138 }
139
143 protected abstract void onActionBtn();
144
145
146 //----- PUBLIC ------------------------------------------------------------------------------------------------------------------------------//
147
148 //===== CALLBACKS ===========================================================================================================================//
149 @Override
150 public void onClick(View v) {
151 int id = v.getId();
152
153
154
155 switch (id) {
156 case R.id.ImageExplorerActionBtn:
157 onActionBtn();
158 break;
159
160 case R.id.DeleteImageBtn:
161 if (selected != null) {
162 AndroidImageFile.deleteFile(selected, activity);
163 initItems(activity.getLayoutInflater());
164 } else {
165 return;
166 }
167
168 break;
169
170 case R.id.CancelBtn:
171 activity.dismissDialog();
172 break;
173 }
174 }
175
176 //----- LIFE CYCLE --------------------------------------------------------------------------------------------------------------------------//
177
178 @Override
179 public void onAttach(Activity activity) {
180 super.onAttach(activity);
181 /*
182 * called once the fragment is associated with its activity.
183 */
184 this.activity = (AppMainActivity) activity;
185 }
186
187 // @Override
188 // public void onCreate(Bundle savedInstanceState) {
189 // super.onCreate(savedInstanceState);
190 // /*
191 // * called to do initial creation of the fragment.
192 // *
193 // * The system calls this when creating the fragment. Within your implementation, you should initialize essential components of the fragment that you want
194 // * to retain when the fragment is paused or stopped, then resumed.
195 // */
196 // }
197
198 @Override
199 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
200 /*
201 * creates and returns the view hierarchy associated with the fragment.
202 *
203 * 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
204 * 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.
205 *
206 * Zde začíná životní cyklus při návratu z backstacku
207 */
208 if (firstCreated) {
209 firstCreated = false;
210 return initView(inflater, container, savedInstanceState);
211 } else {
212 return root;
213 }
214 }
215
216 // @Override
217 // public void onActivityCreated(Bundle savedInstanceState) {
218 // super.onActivityCreated(savedInstanceState);
219 // /*
220 // * tells the fragment that its activity has completed its own Activity.onCreate().
221 // */
222 // }
223
224 // @Override // Vyžaduje API 17
225 // public void onViewStateRestored(Bundle savedInstanceState) {
226 // super.onViewStateRestored(savedInstanceState);
227 // /*
228 // * tells the fragment that all of the saved state of its view hierarchy has been restored.
229 // */
230 // }
231
232 // @Override
233 // public void onStart() {
234 // super.onStart();
235 // /*
236 // * makes the fragment visible to the user (based on its containing activity being started).
237 // */
238 // }
239
240 @Override
241 public void onResume() {
242 super.onResume();
243 /*
244 * makes the fragment interacting with the user (based on its containing activity being resumed).
245 */
246 }
247
248 @Override
249 public void onPause() {
250 super.onPause();
251 /*
252 * 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.
253 *
254 * 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).
255 * 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).
256 */
257 }
258
259 // @Override
260 // public void onStop() {
261 // super.onStop();
262 // /*
263 // * 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.
264 // */
265 // }
266
267 // @Override
268 // public void onDestroyView() {
269 // super.onDestroyView();
270 // /*
271 // * allows the fragment to clean up resources associated with its View.
272 // *
273 // * Zde končí životní cyklus při umístění do backstacku
274 // */
275 // }
276
277 // @Override
278 // public void onDestroy() {
279 // super.onDestroy();
280 // /*
281 // * called to do final cleanup of the fragment's state.
282 // */
283 // }
284
285 // @Override
286 // public void onDetach() {
287 // super.onDetach();
288 // /*
289 // * called immediately prior to the fragment no longer being associated with its activity.
290 // */
291 // }
292 }