5
5
import android .content .Context ;
6
6
import android .content .Intent ;
7
7
import android .content .SharedPreferences ;
8
+ import android .graphics .Bitmap ;
9
+ import android .graphics .BitmapFactory ;
10
+ import android .net .Uri ;
8
11
import android .os .Bundle ;
12
+ import android .os .Environment ;
13
+ import android .provider .MediaStore ;
9
14
import android .view .Menu ;
10
15
import android .view .MenuItem ;
11
16
import android .view .View ;
12
17
import android .view .WindowManager ;
13
18
import android .view .inputmethod .InputMethodManager ;
14
19
import android .widget .Button ;
15
20
import android .widget .ImageButton ;
21
+ import android .widget .ImageView ;
16
22
import android .widget .TableRow ;
17
23
import android .widget .Toast ;
18
24
19
25
import com .google .gson .Gson ;
20
26
27
+ import java .io .File ;
28
+ import java .io .FileInputStream ;
29
+ import java .io .FileNotFoundException ;
30
+ import java .io .IOException ;
31
+ import java .text .SimpleDateFormat ;
32
+ import java .util .Date ;
33
+
21
34
import maas .com .mx .maas .R ;
22
35
import maas .com .mx .maas .entidades .Solicitud ;
23
36
import maas .com .mx .maas .entidades .SolicitudType ;
@@ -31,6 +44,14 @@ public class frmDocumentos extends Activity {
31
44
String objSolicitud ="" ;
32
45
int countExtras =0 ;
33
46
47
+ private static final int CAMERA_REQUEST = 1888 ;
48
+ private static File path ;
49
+ static String str_Camera_Photo_ImagePath = "" ;
50
+ private static int Take_Photo = 2 ;
51
+ static String imageName ="" ;
52
+ Bitmap myBitmap ;
53
+ String mCurrentPhotoPath ;
54
+
34
55
@ Override
35
56
protected void onCreate (Bundle savedInstanceState ) {
36
57
super .onCreate (savedInstanceState );
@@ -208,10 +229,209 @@ private SolicitudType getLastVersion(SolicitudType objSol) {
208
229
209
230
public void clickPhoto (View view ) {
210
231
211
- Intent myIntent = new Intent (frmDocumentos .this , frmPhoto .class );
232
+ /* Intent myIntent = new Intent(frmDocumentos.this, frmPhoto.class);
212
233
myIntent.putExtra("idSolicitud",this.idSolicitud);
213
234
myIntent.putExtra("objSolicitud",this.objSolicitud);
214
235
236
+ startActivity(myIntent);*/
237
+ //String pathTaget=getApplicationContext().getFilesDir().getPath().toString();
238
+ //imageName="TEC_" + System.currentTimeMillis() + ".jpg";
239
+
240
+ //Uri newImageUri = null;
241
+ //path = new File(pathTaget);
242
+
243
+ /*if (!path.exists())
244
+ path.mkdirs();
245
+
246
+ boolean setWritable = false;
247
+ setWritable = path.setWritable(true, false);
248
+ path.setReadable(true,false);
249
+ path.setExecutable(true,false);
250
+
251
+ File file = new File(path, imageName);//ok
252
+ newImageUri = Uri.fromFile(file);
253
+
254
+ file.setWritable(true, false);
255
+ file.setReadable(true,false);
256
+ file.setExecutable(true,false);
257
+
258
+ str_Camera_Photo_ImagePath = pathTaget + "/" + imageName;*/
259
+
260
+ File photoFile = null ;
261
+ try {
262
+ photoFile = createImageFile ();
263
+ } catch (IOException ex ) {
264
+ // Error occurred while creating the File
265
+ }
266
+
267
+ Intent takePictureIntent = new Intent (android .provider .MediaStore .ACTION_IMAGE_CAPTURE );
268
+ //takePictureIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, newImageUri);
269
+ if (photoFile != null ) {
270
+ imageName =photoFile .getName ();
271
+ mCurrentPhotoPath =photoFile .getAbsolutePath ();
272
+ takePictureIntent .putExtra (MediaStore .EXTRA_OUTPUT ,Uri .fromFile (photoFile ));
273
+ startActivityForResult (takePictureIntent , Take_Photo );
274
+ }
275
+
276
+ /* if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
277
+ startActivityForResult(takePictureIntent, Take_Photo);
278
+ }*/
279
+
280
+ }
281
+
282
+ protected void onActivityResult (int requestCode , int resultCode , Intent data ) {
283
+
284
+ // super.onActivityResult(requestCode, resultCode, data);
285
+
286
+ if (requestCode == Take_Photo && resultCode == RESULT_OK ) {
287
+
288
+ Button btnIdentificacion1 = (Button ) findViewById (R .id .btnIdentificacion1 );
289
+ btnIdentificacion1 .setText (imageName );
290
+ btnIdentificacion1 .setTag (mCurrentPhotoPath );
291
+
292
+ //Bundle extras = data.getExtras();
293
+ //Bitmap imageBitmap = (Bitmap) extras.get("data");
294
+
295
+ //File myfile=new File( getApplicationContext().getFilesDir().getPath().toString(),imageName);
296
+ //Bitmap myBitmap = BitmapFactory.decodeFile(myfile.getAbsolutePath());//imgFile.getAbsolutePath());
297
+ //Bitmap faceView = ( new_decode(new File( getApplicationContext().getFilesDir().getPath().toString(),imageName)));
298
+ //String h="";
299
+ //btnIdentificacion1.setTag(imageName);
300
+ /* String filePath = null;
301
+
302
+ filePath = str_Camera_Photo_ImagePath;
303
+
304
+ File imgFile = new File(str_Camera_Photo_ImagePath);
305
+
306
+ if(imgFile.exists()){
307
+
308
+ myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
309
+ //ImageView imageView1 = (ImageView) findViewById(R.id.imageViewTest);
310
+ // imageView1.setImageBitmap(myBitmap);
311
+
312
+ }*/
313
+
314
+ /*
315
+ if (filePath != null) {
316
+ Bitmap faceView = ( new_decode(new File(
317
+ filePath))); // ========================> good lines
318
+ imageView.setImageBitmap(faceView);
319
+
320
+ } else {
321
+ bitmap = null;
322
+ }*/
323
+ }
324
+ }
325
+
326
+ private File createImageFile () throws IOException {
327
+ // Create an image file name
328
+ String timeStamp = new SimpleDateFormat ("yyyyMMdd_HHmmss" ).format (new Date ());
329
+ String imageFileName = "TEC_" + timeStamp ;
330
+ File storageDir = Environment .getExternalStoragePublicDirectory (
331
+ Environment .DIRECTORY_PICTURES );
332
+ File image = File .createTempFile (
333
+ imageFileName , /* prefix */
334
+ ".jpg" , /* suffix */
335
+ storageDir /* directory */
336
+ );
337
+
338
+ // Save a file: path for use with ACTION_VIEW intents
339
+ mCurrentPhotoPath = "file:" + image .getAbsolutePath ();
340
+ return image ;
341
+ }
342
+
343
+
344
+ public void clickBtnIdentificacion1 (View view ) {
345
+
346
+ Button btnIdentificacion1 = (Button ) findViewById (R .id .btnIdentificacion1 );
347
+ String strImage =btnIdentificacion1 .getText ().toString ();
348
+ String strPath =btnIdentificacion1 .getTag ().toString ();
349
+
350
+ Intent myIntent = new Intent (frmDocumentos .this , frmPhoto .class );
351
+ myIntent .putExtra ("imageName" ,strImage );
352
+ myIntent .putExtra ("strPath" ,strPath );
353
+
215
354
startActivity (myIntent );
355
+
216
356
}
357
+
358
+ public static Bitmap new_decode (File f ) {
359
+
360
+ // decode image size
361
+
362
+ BitmapFactory .Options o = new BitmapFactory .Options ();
363
+ o .inJustDecodeBounds = true ;
364
+ o .inDither = false ; // Disable Dithering mode
365
+
366
+ o .inPurgeable = true ; // Tell to gc that whether it needs free memory,
367
+ // the Bitmap can be cleared
368
+
369
+ o .inInputShareable = true ; // Which kind of reference will be used to
370
+ // recover the Bitmap data after being
371
+ // clear, when it will be used in the future
372
+ try {
373
+
374
+
375
+ BitmapFactory .decodeStream (new FileInputStream (f ), null , o );
376
+ } catch (FileNotFoundException e1 ) {
377
+ // TODO Auto-generated catch block
378
+ e1 .printStackTrace ();
379
+ }
380
+
381
+ // Find the correct scale value. It should be the power of 2.
382
+ final int REQUIRED_SIZE = 300 ;
383
+ int width_tmp = o .outWidth , height_tmp = o .outHeight ;
384
+ int scale = 1 ;
385
+ while (true ) {
386
+ if (width_tmp / 1.5 < REQUIRED_SIZE && height_tmp / 1.5 < REQUIRED_SIZE )
387
+ break ;
388
+ width_tmp /= 1.5 ;
389
+ height_tmp /= 1.5 ;
390
+ scale *= 1.5 ;
391
+ }
392
+
393
+ // decode with inSampleSize
394
+ BitmapFactory .Options o2 = new BitmapFactory .Options ();
395
+ // o2.inSampleSize=scale;
396
+ o .inDither = false ; // Disable Dithering mode
397
+
398
+ o .inPurgeable = true ; // Tell to gc that whether it needs free memory,
399
+ // the Bitmap can be cleared
400
+
401
+ o .inInputShareable = true ; // Which kind of reference will be used to
402
+ // recover the Bitmap data after being
403
+ // clear, when it will be used in the future
404
+ // return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
405
+ try {
406
+
407
+ // return BitmapFactory.decodeStream(new FileInputStream(f), null,
408
+ // null);
409
+ Bitmap bitmap = BitmapFactory .decodeStream (new FileInputStream (f ), null , null );
410
+ System .out .println (" IW " + width_tmp );
411
+ System .out .println ("IHH " + height_tmp );
412
+ int iW = width_tmp ;
413
+ int iH = height_tmp ;
414
+
415
+ return Bitmap .createScaledBitmap (bitmap , iW , iH , true );
416
+
417
+ } catch (OutOfMemoryError e ) {
418
+ // TODO: handle exception
419
+ e .printStackTrace ();
420
+ // clearCache();
421
+
422
+ // System.out.println("bitmap creating success");
423
+ System .gc ();
424
+ return null ;
425
+ // System.runFinalization();
426
+ // Runtime.getRuntime().gc();
427
+ // System.gc();
428
+ // decodeFile(f);
429
+ } catch (FileNotFoundException e ) {
430
+ // TODO Auto-generated catch block
431
+ e .printStackTrace ();
432
+ return null ;
433
+ }
434
+
435
+ }
436
+
217
437
}
0 commit comments