Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var self=Ti.UI.createWindow();
- var tabla_fotos=Ti.UI.createTableView({
- backgroundColor:'#eee',
- top:0,
- width:'100%',height:'88%'
- });
- var boton_camara=Ti.UI.createButton({
- title:"Nueva foto",
- bottom:0,color:'#fff',
- width:'100%',height:'10%',
- backgroundColor:'#336699'
- });
- self.add(tabla_fotos);
- self.add(boton_camara);
- boton_camara.addEventListener('click',function(e){
- function cargaFotos(){
- var db=Ti.Database.open('my_baseDate');
- var query='SELECT * FROM fotos ORDER BY fecha DESC';
- var res=db.execute(query);
- var appDir=Titanium.Filesystem.applicationDataDirectory;
- var filas=[];
- while(res.isPrototypeOf.ValidRow()){
- var archivo_txt=res.fieldByName('archivo');
- var fecha_txt=res.fieldByName('fecha');
- var fecha_label=Ti.UI.createLabel({
- text:fecha_txt,
- top:48,right:16,
- width:'50%',
- color:'#000',
- font:{fontWeight:'bold',fontSize:16,fontAlign:'right'},
- textAlign:'center'
- });
- var img=Titanium.Filesystem.getFile(appDir,'fotos/t_'+archivo_txt).read();
- var archivo_view=Ti.UI.createImageView({
- image:img,
- top:8,left:16,
- width:'30%'
- });
- var imagen_view=Ti.UI.createView({
- width:'100%'
- });
- imagen_view.add(fecha_label);
- imagen_view.add(archivo_view);
- var fila_tabla=Ti.UI.createTableViewRow({
- selectedColor:"black"
- });
- fila_tabla.img_org=archivo_txt;
- fila_tabla.add(imagen_view);
- filas.push(fila_tabla);
- res.next();
- }
- res.close();
- db.close();
- tabla_fotos.setData(filas);
- }
- var view=Ti.UI.createView();
- var boton_foto=Ti.UI.createButton({
- title:'¡¡¡Hacer foto!!!',
- width:192,height:64,
- bottom:16,
- borderRadius:6,borderWidth:6,
- backgroundColor:'#336699',
- });
- view.add(boton_foto);
- Ti.Media.showCamera({
- success:function(e){
- function hacerFoto(e){
- var fecha=new Date();
- var unix_time=fecha.getTime();
- var file_name='cuadernito_'+unix_time+'jpg';
- var appDir=Titanium.Filesystem.applicationDataDirectory;
- var foto_file=Titanium.Filesystem.getFile(appDir,'fotos/'+file_name);
- var imagen=e.media;
- foto_file.write(imagen);
- var image_view=Ti.UI.createImageView({
- image:imagen,
- width:'128px',height:'128px'
- });
- var previa=imagen_view.toBlob();
- var previa_file=Titanium.Filesystem.getFile(appDir,'fotos/t_'+file_name);
- previa_file.write(previa);
- }
- },
- overlay:view,
- showControls:false,
- madiaTypes:[Ti.Media.MEDIA_TYPE_PHOTO],
- autohide:false,
- saveToPhotoGallery:false
- });
- boton_foto.addEventListener('click',function(e){
- Ti.Media.takePicture();
- });
- });
- tabla_fotos.addEventListener('click',function(e){
- var appDir=Titanium.Filesystem.applicationDataDirectory;
- var archivo_imagen=Ti.UI.createImageView({
- image:appDir+'fotos/'+e.row_orig
- });
- var img_win=Ti.UI.createWindow();
- img_win.add(archivo_imagen);
- img_win.open({'fullscreen':true});
- });
Add Comment
Please, Sign In to add comment