MARICRUZFERNANDEZ

foto en una tabla

Aug 18th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var self=Ti.UI.createWindow();
  2.     var tabla_fotos=Ti.UI.createTableView({
  3.         backgroundColor:'#eee',
  4.         top:0,
  5.         width:'100%',height:'88%'
  6.     });  
  7.     var boton_camara=Ti.UI.createButton({
  8.        title:"Nueva foto",
  9.        bottom:0,color:'#fff',
  10.        width:'100%',height:'10%',
  11.        backgroundColor:'#336699'
  12.     });
  13.     self.add(tabla_fotos);
  14.     self.add(boton_camara);
  15.    
  16.     boton_camara.addEventListener('click',function(e){      
  17.        
  18.         function cargaFotos(){
  19.            
  20.             var db=Ti.Database.open('my_baseDate');
  21.             var query='SELECT * FROM fotos ORDER BY fecha DESC';
  22.             var res=db.execute(query);
  23.             var appDir=Titanium.Filesystem.applicationDataDirectory;
  24.             var filas=[];
  25.            
  26.             while(res.isPrototypeOf.ValidRow()){
  27.                 var archivo_txt=res.fieldByName('archivo');
  28.                
  29.                 var fecha_txt=res.fieldByName('fecha');
  30.                 var fecha_label=Ti.UI.createLabel({
  31.                     text:fecha_txt,
  32.                     top:48,right:16,
  33.                     width:'50%',
  34.                     color:'#000',
  35.                     font:{fontWeight:'bold',fontSize:16,fontAlign:'right'},
  36.                     textAlign:'center'
  37.                 });
  38.                 var img=Titanium.Filesystem.getFile(appDir,'fotos/t_'+archivo_txt).read();
  39.                 var archivo_view=Ti.UI.createImageView({
  40.                     image:img,
  41.                     top:8,left:16,
  42.                     width:'30%'
  43.                 });
  44.                
  45.                 var imagen_view=Ti.UI.createView({
  46.                     width:'100%'
  47.                 });
  48.                 imagen_view.add(fecha_label);
  49.                 imagen_view.add(archivo_view);
  50.                
  51.                 var fila_tabla=Ti.UI.createTableViewRow({
  52.                     selectedColor:"black"
  53.                 });
  54.                 fila_tabla.img_org=archivo_txt;
  55.                 fila_tabla.add(imagen_view);
  56.                 filas.push(fila_tabla);
  57.                 res.next();
  58.             }
  59.            
  60.             res.close();
  61.             db.close();
  62.            
  63.             tabla_fotos.setData(filas);
  64.            
  65.         }
  66.         var view=Ti.UI.createView();
  67.         var boton_foto=Ti.UI.createButton({
  68.             title:'¡¡¡Hacer foto!!!',
  69.             width:192,height:64,
  70.             bottom:16,
  71.             borderRadius:6,borderWidth:6,
  72.             backgroundColor:'#336699',
  73.            
  74.         });
  75.         view.add(boton_foto);
  76.         Ti.Media.showCamera({
  77.             success:function(e){
  78.              function hacerFoto(e){
  79.            
  80.             var fecha=new Date();
  81.             var unix_time=fecha.getTime();
  82.              
  83.             var file_name='cuadernito_'+unix_time+'jpg';
  84.             var appDir=Titanium.Filesystem.applicationDataDirectory;
  85.             var foto_file=Titanium.Filesystem.getFile(appDir,'fotos/'+file_name);
  86.            
  87.             var imagen=e.media;
  88.             foto_file.write(imagen);
  89.            
  90.             var image_view=Ti.UI.createImageView({
  91.                 image:imagen,
  92.                 width:'128px',height:'128px'
  93.             });
  94.             var previa=imagen_view.toBlob();
  95.             var previa_file=Titanium.Filesystem.getFile(appDir,'fotos/t_'+file_name);
  96.             previa_file.write(previa);
  97.            
  98.                              
  99.         }
  100.             },
  101.             overlay:view,
  102.             showControls:false,
  103.             madiaTypes:[Ti.Media.MEDIA_TYPE_PHOTO],
  104.             autohide:false,
  105.             saveToPhotoGallery:false
  106.         });
  107.         boton_foto.addEventListener('click',function(e){
  108.             Ti.Media.takePicture();
  109.         });
  110.     });
  111.    
  112.     tabla_fotos.addEventListener('click',function(e){
  113.         var appDir=Titanium.Filesystem.applicationDataDirectory;      
  114.         var archivo_imagen=Ti.UI.createImageView({
  115.             image:appDir+'fotos/'+e.row_orig
  116.         });
  117.         var img_win=Ti.UI.createWindow();
  118.         img_win.add(archivo_imagen);
  119.         img_win.open({'fullscreen':true});
  120.     });
Add Comment
Please, Sign In to add comment