source: issm/oecreview/Archive/14312-15392/ISSM-15012-15013.diff@ 15393

Last change on this file since 15393 was 15393, checked in by Mathieu Morlighem, 12 years ago

NEW: adding Archive/14312-15392 for oecreview

File size: 19.5 KB
RevLine 
[15393]1Index: ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/GalleryAdapter.java
2===================================================================
3--- ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/GalleryAdapter.java (revision 15012)
4+++ ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/GalleryAdapter.java (revision 15013)
5@@ -3,7 +3,6 @@
6 import java.util.List;
7
8 import android.app.Activity;
9-import android.graphics.drawable.Drawable;
10 import android.view.View;
11 import android.view.ViewGroup;
12 import android.widget.BaseAdapter;
13@@ -16,17 +15,17 @@
14
15 private static ImageView imageView;
16
17- private List<Drawable> plotsImages;
18-
19+
20+ private List<Integer> plotsImages;
21 private static ViewHolder holder;
22+
23+ public GalleryAdapter(Activity context, List<Integer> plotsImages)
24+ {
25+ this.context = context;
26+ this.plotsImages = plotsImages;
27+ }
28
29- public GalleryAdapter(Activity context, List<Drawable> plotsImages) {
30
31- this.context = context;
32- this.plotsImages = plotsImages;
33-
34- }
35-
36 @Override
37 public int getCount() {
38 return plotsImages.size();
39@@ -64,8 +63,8 @@
40 holder = (ViewHolder) convertView.getTag();
41 }
42
43- holder.imageView.setImageDrawable(plotsImages.get(position));
44-
45+
46+ holder.imageView.setImageBitmap(ImageList.getImageList().get(position));
47 holder.imageView.setScaleType(ImageView.ScaleType.FIT_XY);
48 holder.imageView.setLayoutParams(new Gallery.LayoutParams(150, 90));
49
50Index: ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/MenuPage.java
51===================================================================
52--- ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/MenuPage.java (revision 15012)
53+++ ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/MenuPage.java (revision 15013)
54@@ -12,7 +12,7 @@
55 public class MenuPage extends Activity
56 {
57 ISSM issm = new ISSM();
58- GalleryImage gallery = new GalleryImage();
59+ //GalleryImage gallery = new GalleryImage();
60 private String issmFolder;
61 //------------------------------------------------------------------------
62 public void onCreate(Bundle icicle)
63Index: ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/GalleryImage.java
64===================================================================
65--- ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/GalleryImage.java (revision 15012)
66+++ ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/GalleryImage.java (revision 15013)
67@@ -5,8 +5,6 @@
68 import android.app.Activity;
69 import android.content.Intent;
70 import android.graphics.Bitmap;
71-import android.graphics.drawable.BitmapDrawable;
72-import android.graphics.drawable.Drawable;
73 import android.os.Bundle;
74 import android.view.View;
75 import android.view.View.OnClickListener;
76@@ -33,7 +31,8 @@
77
78 private int selectedImagePosition = 0;
79
80- private List<Drawable> drawables;
81+ //private List<Drawable> drawables;
82+ private List<Integer> drawables;
83
84 private GalleryAdapter galImageAdapter;
85
86@@ -184,19 +183,23 @@
87
88 private void getDrawablesList() {
89
90- drawables = new ArrayList<Drawable>();
91-
92+ drawables = new ArrayList<Integer>();
93+ int resID;
94 for (int i = 0; i < 17; i++)
95 {
96- drawables.add(getResources().getDrawable(getResources().getIdentifier("image"+i, "drawable", getPackageName())));
97+ resID=getResources().getIdentifier("image"+i, "drawable", getPackageName());
98+ drawables.add(resID);
99+
100 }
101-
102 }
103
104 private void setSelectedImage(int selectedImagePosition) {
105-
106- BitmapDrawable bd = (BitmapDrawable) drawables.get(selectedImagePosition);
107- Bitmap b = Bitmap.createScaledBitmap(bd.getBitmap(), (int) (bd.getIntrinsicHeight() * 0.9), (int) (bd.getIntrinsicWidth() * 0.7), false);
108+
109+ int width= getResources().getDisplayMetrics().widthPixels;
110+ int height= getResources().getDisplayMetrics().heightPixels;
111+ Bitmap b;
112+ b = ImageResizer.decodeSampledBitmapFromResource(getResources(), drawables.get(selectedImagePosition), width, height);
113+ b = Bitmap.createScaledBitmap(b, width, height, true);
114 selectedImageView.setImageBitmap(b);
115 selectedImageView.setScaleType(ScaleType.FIT_XY);
116 selectedTextView.setText(description.getDescription(selectedImagePosition ));
117Index: ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ColorBar.java
118===================================================================
119--- ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ColorBar.java (revision 15012)
120+++ ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ColorBar.java (revision 15013)
121@@ -1,13 +1,10 @@
122 package gov.nasa.jpl.issm;
123
124-import java.text.DecimalFormat;
125-
126 import android.content.Context;
127 import android.graphics.Canvas;
128 import android.graphics.Color;
129 import android.graphics.Paint;
130 import android.util.AttributeSet;
131-import android.view.MotionEvent;
132 import android.view.View;
133 /////////////////////////////////////////////////////////////
134 public class ColorBar extends View
135@@ -18,7 +15,7 @@
136 private int width = 30;
137 private int start_x = 10;
138 private int start_y = 10;
139- private int end_y = 0;
140+ //private int end_y = 0;
141 boolean touch;
142 final int MAX_SCALING =255;
143 double [][] colorBuffer;
144@@ -75,7 +72,7 @@
145 }
146 y+=3;
147 }
148- end_y = y;
149+ //end_y = y;
150 }
151 //----------------------------------------------------------------
152 /*allow user to move color bar around
153Index: ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ISSM.java
154===================================================================
155--- ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ISSM.java (revision 15012)
156+++ ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ISSM.java (revision 15013)
157@@ -8,7 +8,6 @@
158 import android.os.Bundle;
159 import android.app.Activity;
160 import android.app.ProgressDialog;
161-import android.graphics.Matrix;
162 import android.util.DisplayMetrics;
163 import android.view.GestureDetector;
164 import android.view.Gravity;
165Index: ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ISSMAPP.java
166===================================================================
167--- ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ISSMAPP.java (revision 15012)
168+++ ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ISSMAPP.java (revision 15013)
169@@ -6,6 +6,7 @@
170 import java.io.InputStream;
171 import java.io.OutputStream;
172 import android.app.Activity;
173+import android.app.ProgressDialog;
174 import android.os.AsyncTask;
175 import android.os.Bundle;
176 import android.os.Environment;
177@@ -21,11 +22,12 @@
178 ///////////////////////////////////////////////////////////////////////////
179 public class ISSMAPP extends Activity
180 {
181- MenuPage mp = new MenuPage();
182+ ImageList imageList;
183 private static final String PREFERENCE_FIRST_RUN = null;
184 private String extStorageDirectory;
185 private String issmFolder;
186 SharedPreferences settings;
187+ private ProgressDialog progressDialog;
188 //------------------------------------------------------------------------
189 public void onCreate(Bundle icicle)
190 {
191@@ -35,7 +37,7 @@
192 boolean firstrun = settings.getBoolean(PREFERENCE_FIRST_RUN, true);
193 extStorageDirectory = Environment.getExternalStorageDirectory().toString();
194 issmFolder = extStorageDirectory + "/ISSM/input_files/";
195-
196+ imageList = new ImageList(this);
197 new CopyDataTask().execute(firstrun);
198 }
199 //-------------------------------------------------------------------------------------------
200@@ -46,13 +48,7 @@
201 @Override
202 protected Boolean doInBackground(Boolean... target)
203 {
204- StartAnimations();
205- try {
206- Thread.sleep(3000);
207- } catch (InterruptedException e1) {
208- // TODO Auto-generated catch block
209- e1.printStackTrace();
210- }
211+ imageList.decodeAndResizeImage();
212 //not sure why, but target[0] can be true on install! more to be done.
213 //if(target[0] = false)
214 //{
215@@ -65,8 +61,18 @@
216 //}
217 return true;
218 }
219+ @Override
220+ protected void onPreExecute()
221+ {
222+ progressDialog = new ProgressDialog(ISSMAPP.this);
223+ progressDialog.setMessage("Loading Data");
224+ progressDialog.setIndeterminate(true);
225+ progressDialog.setCancelable(false);
226+ progressDialog.show();
227+ }
228 protected void onPostExecute(Boolean result)
229 {
230+ progressDialog.dismiss();
231 Intent i = new Intent(ISSMAPP.this, MenuPage.class);
232 i.putExtra("pathToFile", issmFolder);
233 startActivity(i);
234@@ -77,14 +83,12 @@
235 {
236 if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
237 {
238- System.out.println(issmFolder);
239 File txtDirectory = new File(issmFolder);
240
241 // Check and create directory in SDcard
242 if(!txtDirectory.exists())
243 {
244 txtDirectory.mkdirs();
245- System.out.println("making directory");
246 }
247 CopyAssets(); // Then run the method to copy the file.
248
249@@ -126,7 +130,6 @@
250 Log.e("tag", e.getMessage());
251 }
252 }
253- System.out.println("Done");
254 }
255 //----------------------------------------------------------------------------
256 private void copyFile(InputStream in, OutputStream out) throws IOException
257Index: ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ImageList.java
258===================================================================
259--- ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ImageList.java (revision 0)
260+++ ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ImageList.java (revision 15013)
261@@ -0,0 +1,34 @@
262+package gov.nasa.jpl.issm;
263+
264+import java.util.ArrayList;
265+
266+import android.content.Context;
267+import android.graphics.Bitmap;
268+
269+public class ImageList
270+{
271+ private static ArrayList <Bitmap> imageList;
272+ private Context context;
273+ final int nImage = 17;
274+//----------------------------------------------------------
275+ public ImageList(Context context)
276+ {
277+ imageList = new ArrayList <Bitmap>();
278+ this.context = context;
279+ }
280+//----------------------------------------------------------
281+ public void decodeAndResizeImage()
282+ {
283+ int resID;
284+ for(int i = 0 ; i < nImage; i++)
285+ {
286+ resID=context.getResources().getIdentifier("image"+i, "drawable", context.getPackageName());
287+ imageList.add(ImageResizer.decodeSampledBitmapFromResource(context.getResources(), resID , 50, 50));
288+ }
289+ }
290+//----------------------------------------------------------
291+ public static ArrayList<Bitmap> getImageList()
292+ {
293+ return imageList;
294+ }
295+}
296Index: ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ZoomImageView.java
297===================================================================
298--- ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ZoomImageView.java (revision 15012)
299+++ ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ZoomImageView.java (revision 15013)
300@@ -16,7 +16,9 @@
301 package gov.nasa.jpl.issm;
302
303 import android.content.Context;
304+import android.graphics.Bitmap;
305 import android.graphics.Canvas;
306+import android.graphics.drawable.BitmapDrawable;
307 import android.graphics.drawable.Drawable;
308 import android.util.AttributeSet;
309 import android.view.MotionEvent;
310@@ -26,11 +28,10 @@
311
312 public class ZoomImageView extends View {
313 private static final int INVALID_POINTER_ID = -1;
314-
315+ private Bitmap b;
316 private Drawable mIcon;
317 private float mPosX;
318 private float mPosY;
319-
320 private float mLastTouchX;
321 private float mLastTouchY;
322 private int mActivePointerId = INVALID_POINTER_ID;
323@@ -38,6 +39,7 @@
324 private ScaleGestureDetector mScaleDetector;
325 private float mScaleFactor = 1.f;
326
327+
328 public ZoomImageView(Context context, int i) {
329 this(context, null, 0, i);
330 }
331@@ -46,13 +48,19 @@
332 this(context, attrs, 0 ,i);
333 }
334
335+
336 public ZoomImageView(Context context, AttributeSet attrs, int defStyle, int i) {
337 super(context, attrs, defStyle);
338- mIcon = getResources().getDrawable(getResources().getIdentifier("image"+i, "drawable", context.getPackageName()));
339+ int resID2 = getResources().getIdentifier("image"+i, "drawable", context.getPackageName());
340+ //mIcon = getResources().getDrawable(resID);
341 int width= context.getResources().getDisplayMetrics().widthPixels;
342 int height= context.getResources().getDisplayMetrics().heightPixels;
343+
344+
345+ b = ImageResizer.decodeSampledBitmapFromResource(getResources(), resID2, width, height);
346+ b = Bitmap.createScaledBitmap(b, width, height, true);
347+ mIcon = new BitmapDrawable(getResources(), b);
348 mIcon.setBounds(0, 0, width, height);
349-
350 mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
351 }
352
353@@ -133,6 +141,7 @@
354 canvas.translate(mPosX, mPosY);
355 canvas.scale(mScaleFactor, mScaleFactor);
356 mIcon.draw(canvas);
357+ // canvas.drawBitmap(b,0,0,null);
358 canvas.restore();
359 }
360
361Index: ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ImageResizer.java
362===================================================================
363--- ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ImageResizer.java (revision 0)
364+++ ../trunk-jpl/src/mobile/android/ISSM_APP/src/gov/nasa/jpl/issm/ImageResizer.java (revision 15013)
365@@ -0,0 +1,49 @@
366+package gov.nasa.jpl.issm;
367+
368+import android.content.res.Resources;
369+import android.graphics.Bitmap;
370+import android.graphics.BitmapFactory;
371+
372+public class ImageResizer {
373+
374+ public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
375+ int reqWidth, int reqHeight) {
376+
377+ // First decode with inJustDecodeBounds=true to check dimensions
378+ final BitmapFactory.Options options = new BitmapFactory.Options();
379+ options.inJustDecodeBounds = true;
380+ BitmapFactory.decodeResource(res, resId, options);
381+
382+ // Calculate inSampleSize
383+ options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
384+
385+ // Decode bitmap with inSampleSize set
386+ options.inJustDecodeBounds = false;
387+ return BitmapFactory.decodeResource(res, resId, options);
388+ }
389+
390+ public static int calculateInSampleSize(
391+ BitmapFactory.Options options, int reqWidth, int reqHeight)
392+ {
393+ // Raw height and width of image
394+ int height = options.outHeight;
395+ int width = options.outWidth;
396+ int inSampleSize = 1;
397+
398+ if (height > reqHeight || width > reqWidth) {
399+
400+ // Calculate ratios of height and width to requested height and width
401+ final int heightRatio = Math.round((float) height / (float) reqHeight);
402+ final int widthRatio = Math.round((float) width / (float) reqWidth);
403+
404+ // Choose the smallest ratio as inSampleSize value, this will guarantee
405+ // a final image with both dimensions larger than or equal to the
406+ // requested height and width.
407+ inSampleSize = heightRatio > widthRatio ? heightRatio : widthRatio;
408+ }
409+
410+ return inSampleSize;
411+
412+ }
413+
414+}
415Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/drawable/image0.png
416===================================================================
417Cannot display: file marked as a binary type.
418svn:mime-type = application/octet-stream
419Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/drawable/image1.png
420===================================================================
421Cannot display: file marked as a binary type.
422svn:mime-type = application/octet-stream
423Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/drawable/image2.png
424===================================================================
425Cannot display: file marked as a binary type.
426svn:mime-type = application/octet-stream
427Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/drawable/image3.png
428===================================================================
429Cannot display: file marked as a binary type.
430svn:mime-type = application/octet-stream
431Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/drawable/image4.png
432===================================================================
433Cannot display: file marked as a binary type.
434svn:mime-type = application/octet-stream
435Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/drawable/image5.png
436===================================================================
437Cannot display: file marked as a binary type.
438svn:mime-type = application/octet-stream
439Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/drawable/image6.png
440===================================================================
441Cannot display: file marked as a binary type.
442svn:mime-type = application/octet-stream
443Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/drawable/image7.png
444===================================================================
445Cannot display: file marked as a binary type.
446svn:mime-type = application/octet-stream
447Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/drawable/image8.png
448===================================================================
449Cannot display: file marked as a binary type.
450svn:mime-type = application/octet-stream
451Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/drawable/image9.png
452===================================================================
453Cannot display: file marked as a binary type.
454svn:mime-type = application/octet-stream
455Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/drawable/image10.png
456===================================================================
457Cannot display: file marked as a binary type.
458svn:mime-type = application/octet-stream
459Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/drawable/image11.png
460===================================================================
461Cannot display: file marked as a binary type.
462svn:mime-type = application/octet-stream
463Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/drawable/image12.png
464===================================================================
465Cannot display: file marked as a binary type.
466svn:mime-type = application/octet-stream
467Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/drawable/image13.png
468===================================================================
469Cannot display: file marked as a binary type.
470svn:mime-type = application/octet-stream
471Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/drawable/image14.png
472===================================================================
473Cannot display: file marked as a binary type.
474svn:mime-type = application/octet-stream
475Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/drawable/image15.png
476===================================================================
477Cannot display: file marked as a binary type.
478svn:mime-type = application/octet-stream
479Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/drawable/image16.png
480===================================================================
481Cannot display: file marked as a binary type.
482svn:mime-type = application/octet-stream
483Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/drawable/image17.png
484===================================================================
485Cannot display: file marked as a binary type.
486svn:mime-type = application/octet-stream
487Index: ../trunk-jpl/src/mobile/android/ISSM_APP/res/anim/translate.xml
488===================================================================
489--- ../trunk-jpl/src/mobile/android/ISSM_APP/res/anim/translate.xml (revision 15012)
490+++ ../trunk-jpl/src/mobile/android/ISSM_APP/res/anim/translate.xml (revision 15013)
491@@ -8,7 +8,7 @@
492 android:toXDelta="0%"
493 android:fromYDelta="200%"
494 android:toYDelta="0%"
495- android:duration="2000"
496+ android:duration="3000"
497 android:zAdjustment="top" />
498
499 </set>
500\ No newline at end of file
Note: See TracBrowser for help on using the repository browser.