Index: TibisayMovil/src/ve/gob/cenditel/tibisaymovil/CaptureImgHandwrittenSignatureActivity.java
===================================================================
--- TibisayMovil/src/ve/gob/cenditel/tibisaymovil/CaptureImgHandwrittenSignatureActivity.java	(revision a8bb2bbd62a519f8aa67a0e6bb2e0f1d6b330a79)
+++ TibisayMovil/src/ve/gob/cenditel/tibisaymovil/CaptureImgHandwrittenSignatureActivity.java	(revision a8bb2bbd62a519f8aa67a0e6bb2e0f1d6b330a79)
@@ -0,0 +1,378 @@
+package ve.gob.cenditel.tibisaymovil;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.Calendar;
+import android.app.Activity;
+import android.content.Context;
+import android.content.ContextWrapper;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Path;
+import android.graphics.RectF;
+import android.os.Bundle;
+import android.os.Environment;
+import android.provider.MediaStore.Images;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.Window;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup.LayoutParams;
+import android.widget.LinearLayout;
+import android.widget.Toast;
+
+public class CaptureImgHandwrittenSignatureActivity extends Activity{
+ 
+    LinearLayout mContent;
+    signature mSignature;
+    LinearLayout mClear, mGetSign, mCancel;
+    
+    public static String tempDir;
+    public int count = 1;
+    public String current = null;
+      
+    private Bitmap mBitmap;
+    View mView;
+    File mypath;
+    private Canvas canvas;
+ 
+    private String uniqueId;
+    private String fileToSign;
+ 
+    @Override
+    public void onCreate(Bundle savedInstanceState) 
+    {
+        super.onCreate(savedInstanceState);
+        //Capturando archivo que será firmado
+        fileToSign = getIntent().getExtras().getString("FILE_TO_SIGN");
+
+		//Estilando la barra de titulo
+		final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
+        setContentView(R.layout.activity_capture_img_handwritten_signature);
+        //Estilando Barra de titulo
+		if(customTitleSupported)
+			getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
+        
+        tempDir = Environment.getExternalStorageDirectory() + "/" +
+        			getResources().getString(R.string.app_name) + "/" +
+        			getResources().getString(R.string.external_dir) + "/";
+        
+	    /*       
+	     *  Crea si es necesario, un directorio en el cual la aplicación
+	     *  puede colocar sus propios archivos de datos personalizados
+	     */
+        ContextWrapper cw = new ContextWrapper(getApplicationContext());
+        File directory = cw.getDir(getResources().getString(R.string.external_dir), Context.MODE_PRIVATE);
+        File directory2 = cw.getDir(getResources().getString(R.string.external_dir_files), Context.MODE_PRIVATE);
+         
+        prepareDirectory();
+        
+        // Obtiene identificador unico para el nombre del archivo
+        uniqueId = getTodaysDate() + "_" + getCurrentTime();
+        current = uniqueId + ".png";
+        
+        //Ruta completa para crear el archivo
+        mypath= new File(directory,current);
+ 
+        // Obtiene referencia a los recursos del layout
+        mContent = (LinearLayout) findViewById(R.id.linearLayout);
+        mClear = (LinearLayout)findViewById(R.id.button_clear_zone);
+        mGetSign = (LinearLayout)findViewById(R.id.button_accept_zone);
+        mCancel = (LinearLayout)findViewById(R.id.button_cancel_zone);
+        
+        mSignature = new signature(this, null);
+        mContent.addView(mSignature, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
+        mGetSign.setEnabled(false);
+        mView = mContent;    
+        
+        
+        mClear.setOnClickListener(new OnClickListener() 
+        {        
+            public void onClick(View v) 
+            {
+                mSignature.clear();
+                mGetSign.setEnabled(false);
+            }
+        });
+ 
+        mGetSign.setOnClickListener(new OnClickListener() 
+        {        
+            public void onClick(View v) 
+            {
+                boolean error = captureSignature();
+                if(!error){
+                    mView.setDrawingCacheEnabled(true);
+                    mSignature.save(mView);
+                    
+
+    				Intent intent = new Intent(CaptureImgHandwrittenSignatureActivity.this, SelectSignUbicationHandwrittenSignatureActivity.class);
+    	            intent.putExtra("STATUS", "done");
+    	            intent.putExtra("IMAGE_CAPTURED", mypath.getAbsolutePath());
+    	            intent.putExtra("FILE_TO_SIGN", fileToSign);
+    	            startActivity(intent);
+                    Log.i("DEBUG", "saliendo");
+//                    setResult(RESULT_OK,intent);   
+//                    finish();
+                    
+                }
+            }
+        });
+ 
+        mCancel.setOnClickListener(new OnClickListener() 
+        {        
+            public void onClick(View v) 
+            {
+                finish();
+            }
+        });
+ 
+    }
+ 
+    @Override
+    protected void onDestroy() {
+        super.onDestroy();
+    }
+ 
+    private boolean captureSignature() {
+ 
+        boolean error = false;
+        //String errorMessage = "";
+ 
+ /*
+ 		// por ahora no nos interesa mostrar la caja de texto
+        if(yourName.getText().toString().equalsIgnoreCase("")){
+            errorMessage = errorMessage + "Por favor introduzca su nombre\n";
+            error = true;
+        }   
+ 
+        if(error){
+            Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
+            toast.setGravity(Gravity.TOP, 105, 50);
+            toast.show();
+        }
+ */
+        return error;
+    }
+ 
+    private String getTodaysDate() { 
+ 
+        final Calendar c = Calendar.getInstance();
+        int todaysDate =     (c.get(Calendar.YEAR) * 10000) + 
+        ((c.get(Calendar.MONTH) + 1) * 100) + 
+        (c.get(Calendar.DAY_OF_MONTH));
+        return(String.valueOf(todaysDate));
+ 
+    }
+ 
+    private String getCurrentTime() {
+ 
+        final Calendar c = Calendar.getInstance();
+        int currentTime =     (c.get(Calendar.HOUR_OF_DAY) * 10000) + 
+        (c.get(Calendar.MINUTE) * 100) + 
+        (c.get(Calendar.SECOND));
+        return(String.valueOf(currentTime));
+ 
+    }
+ 
+    /**
+     * Prepara directorio
+     * @return boolean
+     */
+    private boolean prepareDirectory() 
+    {
+        try
+        {
+            if (makedirs()) 
+            {
+                return true;
+            } else {
+                return false;
+            }
+        } catch (Exception e) 
+        {
+            e.printStackTrace();
+            Toast.makeText(this, "Could not initiate File System.. Is Sdcard mounted properly?", Toast.LENGTH_LONG).show();
+            return false;
+        }
+    }
+ 
+    /**
+     * Crea directorio utilizando la variable tmpDir
+     * @return boolean
+     */
+    private boolean makedirs() 
+    {
+        File tempdir = new File(tempDir);
+        if (!tempdir.exists())
+            tempdir.mkdirs();
+ 
+        if (tempdir.isDirectory()) 
+        {
+            File[] files = tempdir.listFiles();
+            for (File file : files) 
+            {
+                if (!file.delete()) 
+                {
+                    System.out.println("Failed to delete " + file);
+                }
+            }
+        }
+        return (tempdir.isDirectory());
+    }
+ 
+    public class signature extends View 
+    {
+        private static final float STROKE_WIDTH = 5f;
+        private static final float HALF_STROKE_WIDTH = STROKE_WIDTH / 2;
+        private Paint paint = new Paint();
+        private Path path = new Path();
+ 
+        private float lastTouchX;
+        private float lastTouchY;
+        private final RectF dirtyRect = new RectF();
+ 
+        public signature(Context context, AttributeSet attrs) 
+        {
+            super(context, attrs);
+            paint.setAntiAlias(true);
+            paint.setColor(Color.BLACK);
+            paint.setStyle(Paint.Style.STROKE);
+            paint.setStrokeJoin(Paint.Join.ROUND);
+            paint.setStrokeWidth(STROKE_WIDTH);
+        }
+ 
+        public void save(View v) 
+        {
+                        
+            if(mBitmap == null)
+            {
+                mBitmap =  Bitmap.createBitmap (mContent.getWidth(), mContent.getHeight(), Bitmap.Config.ARGB_8888);
+            }
+            canvas = new Canvas(mBitmap);
+            try
+            {
+            	//Log.v("*****yourName:", yourName.getText().toString());
+            	
+                FileOutputStream mFileOutStream = new FileOutputStream(mypath);
+ 
+                v.draw(canvas); 
+                mBitmap.compress(Bitmap.CompressFormat.PNG, 90, mFileOutStream); 
+                mFileOutStream.flush();
+                mFileOutStream.close();
+                String url = Images.Media.insertImage(getContentResolver(), mBitmap, "title", null);
+                
+//                Toast.makeText(CaptureImgHandwrittenSignatureActivity.this,
+//                		getString(R.string.firma_guardada) + " " + mypath, Toast.LENGTH_SHORT).show();
+                
+                //In case you want to delete the file
+                //boolean deleted = mypath.delete();
+                //Log.v("log_tag","deleted: " + mypath.toString() + deleted);
+                //If you want to convert the image to string use base64 converter
+ 
+            }
+            catch(Exception e) 
+            { 
+                Log.v("log_tag", e.toString()); 
+            } 
+        }
+ 
+        public void clear() 
+        {
+            path.reset();
+            invalidate();
+        }
+ 
+        @Override
+        protected void onDraw(Canvas canvas) 
+        {
+            canvas.drawPath(path, paint);
+//          canvas.drawCircle(lastTouchX, lastTouchX, HALF_STROKE_WIDTH, paint);
+        }
+ 
+        @Override
+        public boolean onTouchEvent(MotionEvent event) 
+        {
+            float eventX = event.getX();
+            float eventY = event.getY();
+            mGetSign.setEnabled(true);
+ 
+            switch (event.getAction()) 
+            {
+            case MotionEvent.ACTION_DOWN:
+                path.moveTo(eventX, eventY);
+                lastTouchX = eventX;
+                lastTouchY = eventY;
+                                
+                return true;
+ 
+            case MotionEvent.ACTION_MOVE:
+                
+            case MotionEvent.ACTION_UP:
+ 
+                resetDirtyRect(eventX, eventY);
+                int historySize = event.getHistorySize();
+                for (int i = 0; i < historySize; i++) 
+                {
+                    float historicalX = event.getHistoricalX(i);
+                    float historicalY = event.getHistoricalY(i);
+                    expandDirtyRect(historicalX, historicalY);
+                    path.lineTo(historicalX, historicalY);
+                }
+                path.lineTo(eventX, eventY);
+                break;
+ 
+            default:
+                Log.i("DRAW:","Ignored touch event: " + event.toString());
+                return false;
+            }
+ 
+            invalidate((int) (dirtyRect.left - HALF_STROKE_WIDTH),
+                    (int) (dirtyRect.top - HALF_STROKE_WIDTH),
+                    (int) (dirtyRect.right + HALF_STROKE_WIDTH),
+                    (int) (dirtyRect.bottom + HALF_STROKE_WIDTH));
+ 
+            lastTouchX = eventX;
+            lastTouchY = eventY;
+ 
+            return true;
+        }
+ 
+        private void debug(String string){
+        }
+ 
+        private void expandDirtyRect(float historicalX, float historicalY) 
+        {
+            if (historicalX < dirtyRect.left) 
+            {
+                dirtyRect.left = historicalX;
+            } 
+            else if (historicalX > dirtyRect.right) 
+            {
+                dirtyRect.right = historicalX;
+            }
+ 
+            if (historicalY < dirtyRect.top) 
+            {
+                dirtyRect.top = historicalY;
+            } 
+            else if (historicalY > dirtyRect.bottom) 
+            {
+                dirtyRect.bottom = historicalY;
+            }
+        }
+ 
+        private void resetDirtyRect(float eventX, float eventY) 
+        {
+            dirtyRect.left = Math.min(lastTouchX, eventX);
+            dirtyRect.right = Math.max(lastTouchX, eventX);
+            dirtyRect.top = Math.min(lastTouchY, eventY);
+            dirtyRect.bottom = Math.max(lastTouchY, eventY);
+        }
+        
+    }
+}
Index: TibisayMovil/src/ve/gob/cenditel/tibisaymovil/FileToSignHandwrittenSignatureActivity.java
===================================================================
--- TibisayMovil/src/ve/gob/cenditel/tibisaymovil/FileToSignHandwrittenSignatureActivity.java	(revision 37467beeb785e07fbb61834ed995522280a570be)
+++ TibisayMovil/src/ve/gob/cenditel/tibisaymovil/FileToSignHandwrittenSignatureActivity.java	(revision a8bb2bbd62a519f8aa67a0e6bb2e0f1d6b330a79)
@@ -6,8 +6,11 @@
 import java.util.Collections;
 import java.util.Date;
-import java.util.List;
 import ve.gob.cenditel.tibisaymovil.R;
 import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.Intent;
 import android.graphics.drawable.Drawable;
+import android.net.Uri;
 import android.os.Bundle;
 import android.util.Log;
@@ -17,20 +20,23 @@
 import android.view.View.OnClickListener;
 import android.view.Window;
+import android.webkit.MimeTypeMap;
 import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
 import android.widget.BaseAdapter;
-import android.widget.CheckBox;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.ListView;
+import android.widget.RadioButton;
 import android.widget.TextView;
+import android.widget.AdapterView.OnItemClickListener;
 import android.widget.Toast;
-import android.widget.AdapterView.OnItemClickListener;
 
 public class FileToSignHandwrittenSignatureActivity extends Activity implements OnItemClickListener, OnClickListener {
 
 	private File cwd;
-    private List<File> selected;
+    private File selected;
     private FileBrowserView viewHolder;
     private FileListAdapter listAdapter;
+    private String filterMImeType = "application/pdf";
 
 	@Override
@@ -44,7 +50,8 @@
 
         if (savedInstanceState != null) {
-            this.selected = TypeUtils.convertToFileList(savedInstanceState.getStringArrayList("selected"));
-
-            if (this.selected.size() > 0) {
+        	if(savedInstanceState.getString("selected") != null)
+        		this.selected = new File(savedInstanceState.getString("selected"));
+
+            if (this.selected != null) {
             	
             	FileToSignHandwrittenSignatureActivity.this.updateButton
@@ -52,10 +59,10 @@
 
             }
-
+            
             this.cwd = new File(savedInstanceState.getString("cwd"));
-            this.viewHolder.fileList.setAdapter(this.listAdapter = new FileListAdapter(this.cwd.getAbsolutePath()));
+            this.viewHolder.fileList.setAdapter(this.listAdapter = new FileListAdapter(this.cwd.getAbsolutePath(), filterMImeType));
             
         } else {
-            this.selected = new ArrayList<File>();
+            this.selected = null;
             this.viewHolder.fileList.setAdapter(this.listAdapter = new FileListAdapter());
         }
@@ -63,5 +70,5 @@
         
         boolean enabled = false;
-        if (!this.selected.isEmpty())
+        if (this.selected != null)
         	enabled = this.viewHolder.accept.isEnabled();
         
@@ -86,8 +93,12 @@
 
         private FileListAdapter() {
-            this("/");
+            this("/",filterMImeType);
         }
 
         private FileListAdapter(String location) {
+            this(location, "");
+        }
+        
+        private FileListAdapter(String location, String filterMimeType) {
         	
             directories = new ArrayList<File>();
@@ -104,5 +115,6 @@
             //Obtiene el directorio padre del objeto file cwd
             File parent = FileToSignHandwrittenSignatureActivity.this.cwd.getParentFile();
-            //Si tiene un padre, lo agrega en la posición cero de la lista de directorios 
+            //Si tiene un padre, lo agrega en la posición cero de la lista de directorios  
+            
             if (parent != null) {
                 directories.add(0, parent);
@@ -113,4 +125,5 @@
             if (ls != null) {
                 for (File f : ls) { //recorre todos los archivos contenidos en el directorio
+                	
                     if (FsUtils.isHiddenOrNotReadable(f)) { // Si son ocultos no hace nada
                         continue;
@@ -122,5 +135,18 @@
                     } else // De lo contrario lo agrega a la lista de archivos 
                     	{
-                        files.add(f);
+                    	//Valida tipo de archivo a mostrar
+                        Uri selectedUri = Uri.fromFile(f);
+                        String fileExtension = MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString());
+                        String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension);
+                          
+//                        Toast.makeText(FileToSignHandwrittenSignatureActivity.this,
+//                          "FileExtension: " + fileExtension + "\n" +
+//                          "MimeType: " + mimeType,
+//                          Toast.LENGTH_LONG).show();
+                        
+                        //Filtra por mimeType
+                        if(filterMimeType.isEmpty() || filterMimeType == mimeType)
+                            files.add(f);
+                        	
                     }
                 }
@@ -173,5 +199,5 @@
             if (convertView == null) {
                 LayoutInflater inflater = LayoutInflater.from(FileToSignHandwrittenSignatureActivity.this);
-                convertView = inflater.inflate(R.layout.file_browser_item, parent, false);
+                convertView = inflater.inflate(R.layout.file_to_sign_handwritten_signature_item, parent, false); 
             }
             
@@ -184,22 +210,23 @@
         	File file = getItem(position);
         	
-        	//CheckBox
-            CheckBox check = (CheckBox) convertView.findViewById(R.id.file_checkbox);
-            check.setFocusable(false);
-            
-            // Se asignan los iconos según el tipo de archivo y se oculta el checkbox en los directorios
+        	//RadioButton
+            RadioButton radio = (RadioButton) convertView.findViewById(R.id.file_radio);
+            radio.setFocusable(false);
+            
+            // Se asignan los iconos según el tipo de archivo y se oculta el radio en los directorios
             if (file.isDirectory()) {
                 image.setImageResource(R.drawable.ic_carpeta);
-                check.setVisibility(View.INVISIBLE);
-                check.setChecked(false);
+                radio.setVisibility(View.INVISIBLE);
+                radio.setChecked(false);
             } else {
                 image.setImageResource(R.drawable.ic_archivo);
-                check.setVisibility(View.VISIBLE);
-            	if (!FileToSignHandwrittenSignatureActivity.this.selected.contains(file)){
-            		check.setChecked(false);
+                radio.setVisibility(View.VISIBLE);
+                
+                if (FileToSignHandwrittenSignatureActivity.this.selected == null ||
+	            	FileToSignHandwrittenSignatureActivity.this.selected.hashCode() != file.hashCode()){
+	            		radio.setChecked(false);
             	} else{
-            		check.setChecked(true);
-            	}
-         
+            		radio.setChecked(true);
+            	}         
             }
 
@@ -233,24 +260,21 @@
             //Si es un directorio el seleccionado se hace un llamado del fileBrowser del directorio
             if (item.isDirectory()) {
-                parent.setAdapter(FileToSignHandwrittenSignatureActivity.this.listAdapter = new FileListAdapter(item.getAbsolutePath()));
+                parent.setAdapter(FileToSignHandwrittenSignatureActivity.this.listAdapter = new FileListAdapter(item.getAbsolutePath(), filterMImeType));
             } else { // Si es un archivo
             	
-        		//Se agrega el archivo a la lista de seleccionados si no se encuentra en la misma 
-            	if (!FileToSignHandwrittenSignatureActivity.this.selected.contains(item)){
-            		FileToSignHandwrittenSignatureActivity.this.selected.add(item);
+        		//Se agrega el archivo a la lista de seleccionados si no se encuentra en la misma            	
+            	if (FileToSignHandwrittenSignatureActivity.this.selected == null || 
+            		FileToSignHandwrittenSignatureActivity.this.selected.hashCode() != item.hashCode()){
+            		
+            		FileToSignHandwrittenSignatureActivity.this.selected = item;
             		
             		FileToSignHandwrittenSignatureActivity.this.updateButton(FileToSignHandwrittenSignatureActivity.this.viewHolder.accept,true);  		
-            		
-                }else{ // De lo contrario se elimina de la lista de seleccionados
+            		            		
+            	}
+            	else{ // De lo contrario se elimina de la lista de seleccionados
                 	
-            		FileToSignHandwrittenSignatureActivity.this.selected.remove(item);
-            		
-                	
-                	if (FileToSignHandwrittenSignatureActivity.this.selected.isEmpty()){                		
-                		FileToSignHandwrittenSignatureActivity.this.updateButton(FileToSignHandwrittenSignatureActivity.this.viewHolder.accept,false);                		
-                	}else {
-                		FileToSignHandwrittenSignatureActivity.this.updateButton(FileToSignHandwrittenSignatureActivity.this.viewHolder.accept,true);
-                	}
-                	
+            		FileToSignHandwrittenSignatureActivity.this.selected = null;             		
+                	FileToSignHandwrittenSignatureActivity.this.updateButton(FileToSignHandwrittenSignatureActivity.this.viewHolder.accept,false);
+                	               	
                 }
                 notifyDataSetChanged();
@@ -259,4 +283,17 @@
     }    
 
+
+    
+    
+    @Override
+    protected void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+
+        outState.putParcelable("intent", this.getIntent());
+        outState.putString("cwd", this.cwd.getAbsolutePath());
+        if(this.selected != null)
+        	outState.putString("selected", this.selected.getAbsolutePath());
+        
+        }
     
     private void updateButton(View v, boolean bool) {
@@ -351,5 +388,5 @@
         case R.id.button_clear_zone:
         	
-        	this.selected.clear();
+        	this.selected = null;
         	this.listAdapter.notifyDataSetChanged();
 
@@ -357,7 +394,55 @@
             this.updateButton(this.viewHolder.accept, false);
         	break;        	
-        	
+        
+
+        
+	    case R.id.button_accept_zone:
+	    	
+			//Crear dialogo de opciones para firmar
+			final AlertDialog image_dialog = selectImageOptionsDialog();
+			image_dialog.show();
+            
+	    	break;        	
+    	
         }
     }
+    
+	
+	//Crea dialogo de opciones para seleccion de imagen de firma
+	public AlertDialog selectImageOptionsDialog() {
+		final String[] option = new String[] {getString(R.string.firmar_man_capt_img), getString(R.string.firmar_man_exist_img), getString(R.string.firmar_man_prefer_img) };
+		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
+		        android.R.layout.select_dialog_item, option);
+		AlertDialog.Builder builder = new AlertDialog.Builder(this);
+		
+		builder.setTitle(getString(R.string.seleccione_opcion_firmar_man_img));
+		builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
+		
+		  public void onClick(DialogInterface dialog, int which) {
+			  
+			  switch (which) {
+			case 0: // Capturar imágen
+				Intent intent = new Intent(FileToSignHandwrittenSignatureActivity.this, CaptureImgHandwrittenSignatureActivity.class);
+	            intent.putExtra("FILE_TO_SIGN", FileToSignHandwrittenSignatureActivity.this.selected.getAbsolutePath());
+	            Log.i("DEBUG",  FileToSignHandwrittenSignatureActivity.this.selected.getAbsolutePath());
+	            startActivity(intent);
+				
+				break;
+			case 1: // Buscar en archivos
+				
+				break;
+			case 2: // Usar predeterminada
+				
+				break;
+
+			default:
+				break;
+			}
+		  }
+		  
+		});	
+		
+		return builder.create();
+	}
 
 }
Index: TibisayMovil/src/ve/gob/cenditel/tibisaymovil/FunctionListAdapter.java
===================================================================
--- TibisayMovil/src/ve/gob/cenditel/tibisaymovil/FunctionListAdapter.java	(revision 37467beeb785e07fbb61834ed995522280a570be)
+++ TibisayMovil/src/ve/gob/cenditel/tibisaymovil/FunctionListAdapter.java	(revision a8bb2bbd62a519f8aa67a0e6bb2e0f1d6b330a79)
@@ -2,4 +2,5 @@
 
 
+import android.annotation.SuppressLint;
 import android.content.Context;
 import android.view.LayoutInflater;
Index: TibisayMovil/src/ve/gob/cenditel/tibisaymovil/SelectSignUbicationHandwrittenSignatureActivity.java
===================================================================
--- TibisayMovil/src/ve/gob/cenditel/tibisaymovil/SelectSignUbicationHandwrittenSignatureActivity.java	(revision a8bb2bbd62a519f8aa67a0e6bb2e0f1d6b330a79)
+++ TibisayMovil/src/ve/gob/cenditel/tibisaymovil/SelectSignUbicationHandwrittenSignatureActivity.java	(revision a8bb2bbd62a519f8aa67a0e6bb2e0f1d6b330a79)
@@ -0,0 +1,382 @@
+package ve.gob.cenditel.tibisaymovil;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.Vector;
+
+import com.lowagie.text.DocumentException;
+import com.lowagie.text.Image;
+import com.lowagie.text.Rectangle;
+import com.lowagie.text.pdf.PdfContentByte;
+import com.lowagie.text.pdf.PdfReader;
+import com.lowagie.text.pdf.PdfStamper;
+
+import android.app.Activity;
+import android.app.ProgressDialog;
+import android.content.Intent;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.os.Environment;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.Window;
+import android.widget.ArrayAdapter;
+import android.widget.LinearLayout;
+import android.widget.Spinner;
+import android.widget.TextView;
+import android.widget.Toast;
+
+public class SelectSignUbicationHandwrittenSignatureActivity extends Activity{
+	
+	private TextView selected_position = null;
+    private String fileToSign;
+    private String imageCaptured;
+    private float x_coef, y_coef;
+    private LinearLayout button_accept, button_cancel;
+    private PdfReader pdfReader;
+    private Spinner spinner_page_number;
+    private String tempDir;
+	
+	@Override		
+	protected void onCreate(Bundle savedInstanceState) {
+
+			
+        //Capturando archivo que será firmado
+        fileToSign = getIntent().getExtras().getString("FILE_TO_SIGN");
+        //Capturando imagen de firma
+        imageCaptured = getIntent().getExtras().getString("IMAGE_CAPTURED");
+	        
+		//Estilando la barra de titulo
+		final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
+	
+		super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_select_sign_ubication_handwritten_signature);
+	    //Estilando Barra de titulo
+		if(customTitleSupported)
+			getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
+
+        TextView text_view_11 = (TextView) this.findViewById(R.id.textView11);
+        TextView text_view_12 = (TextView) this.findViewById(R.id.textView12);
+        TextView text_view_13 = (TextView) this.findViewById(R.id.textView13);
+
+        TextView text_view_21 = (TextView) this.findViewById(R.id.textView21);
+        TextView text_view_22 = (TextView) this.findViewById(R.id.textView22);
+        TextView text_view_23 = (TextView) this.findViewById(R.id.textView23);
+
+        TextView text_view_31 = (TextView) this.findViewById(R.id.textView31);
+        TextView text_view_32 = (TextView) this.findViewById(R.id.textView32);
+        TextView text_view_33 = (TextView) this.findViewById(R.id.textView33);
+        
+        spinner_page_number = (Spinner) findViewById(R.id.pages_spinner);
+
+        button_accept = (LinearLayout) this.findViewById(R.id.button_accept_zone);
+        button_cancel = (LinearLayout) this.findViewById(R.id.button_cancel_zone);  
+
+        button_accept.setEnabled(false);
+        
+
+        
+        
+        
+        
+        AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
+
+            private ProgressDialog pd;
+
+            @Override
+            protected void onPreExecute() {
+
+	             pd = new ProgressDialog(SelectSignUbicationHandwrittenSignatureActivity.this);	
+	             pd.setTitle(getString(R.string.title_progress_file_read));	
+	             pd.setMessage(getString(R.string.por_favor_epsere));	
+	             pd.setCancelable(false);	
+	             pd.setIndeterminate(true);	
+	             pd.show();
+
+            }
+
+            @Override
+            protected Void doInBackground(Void... arg0) {
+
+        	//Cargar Spinner
+            //Cargar PDF
+            try{
+			  pdfReader = new PdfReader(fileToSign);
+      		  
+      		} catch (IOException e) {
+			    e.printStackTrace();
+			    
+			    //Si el archivo no puede ser leído se envía al activity de selectionar archivo
+			    Intent oIntent = new Intent(SelectSignUbicationHandwrittenSignatureActivity.this,
+			    		FileToSignHandwrittenSignatureActivity.class);
+		        oIntent.setAction(Intent.ACTION_VIEW);
+		        oIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+		        startActivity(oIntent);
+		        finish();
+			    Toast.makeText(SelectSignUbicationHandwrittenSignatureActivity.this,
+			    			   	SelectSignUbicationHandwrittenSignatureActivity.this.getString(R.string.error_lectura), 
+			    			   	Toast.LENGTH_SHORT).show();
+    		}
+
+                return null;
+         }            
+         @Override
+         protected void onPostExecute(Void result) {
+        	 
+			  int number_pages = pdfReader.getNumberOfPages();
+				
+			  Vector<String> pages_vector = new Vector<String>();
+			  for(int i = 0; i < number_pages ; i++)
+				  pages_vector.add(String.valueOf(i+1));
+			  
+			  // Create an ArrayAdapter using the string array and a default spinner layout
+			  ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
+					  SelectSignUbicationHandwrittenSignatureActivity.this,
+					  android.R.layout.simple_spinner_item, pages_vector);
+			  // Specify the layout to use when the list of choices appears
+			  spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+			  // Apply the adapter to the spinner
+			  spinner_page_number.setAdapter(spinnerArrayAdapter);
+
+             pd.dismiss();
+
+         }
+
+        };
+
+        task.execute((Void[])null);
+        
+    
+        
+        button_accept.setOnClickListener(new OnClickListener() 
+        {        
+            public void onClick(View v) 
+            {
+                pdfSignatureDig();
+            }
+        });
+        
+        button_cancel.setOnClickListener(new OnClickListener() 
+        {        
+            public void onClick(View v) 
+            {
+                finish();
+            }
+        });
+        
+
+        OnClickListener listen_area = new OnClickListener() {
+        	
+			@Override
+			public void onClick(View v) {
+				
+				if(!button_accept.isEnabled()) button_accept.setEnabled(true);
+				
+				if(selected_position != null) {
+					selected_position.setBackgroundResource(R.drawable.shape_table1);
+				}				
+				v.setBackgroundColor(getResources().getColor(R.color.gris1));
+				selected_position = (TextView) v;
+				
+				int cols = 3;
+				int rows = 3;
+				int row = 0;
+				int col = 0;
+				switch (v.getId()) {
+				case R.id.textView11:
+					row = 1;
+					col = 1;
+					break;
+				case R.id.textView12:
+					row = 1;
+					col = 2;
+					break;
+				case R.id.textView13:
+					row = 1;
+					col = 3;
+					break;
+				case R.id.textView21:
+					row = 2;
+					col = 1;
+					break;
+				case R.id.textView22:
+					row = 2;
+					col = 2;
+					break;
+				case R.id.textView23:
+					row = 2;
+					col = 3;
+					break;
+				case R.id.textView31:
+					row = 3;
+					col = 1;
+					break;
+				case R.id.textView32:
+					row = 3;
+					col = 2;
+					break;
+				case R.id.textView33:
+					row = 3;
+					col = 3;
+					break;
+
+				default:
+					break;
+				}
+				
+				// Coeficientes para calcular la posición de la firma
+				x_coef = (float)col/(float)cols - 1f/(float)cols/2f;
+				y_coef = ((float)rows-(float)row+1)/(float)rows - 1f/(float)rows/2f;
+							
+			}
+        };
+
+        text_view_11.setOnClickListener(listen_area);
+        text_view_12.setOnClickListener(listen_area);
+        text_view_13.setOnClickListener(listen_area);
+        
+        text_view_21.setOnClickListener(listen_area);
+        text_view_22.setOnClickListener(listen_area);
+        text_view_23.setOnClickListener(listen_area);
+
+        text_view_31.setOnClickListener(listen_area);
+        text_view_32.setOnClickListener(listen_area);
+        text_view_33.setOnClickListener(listen_area);
+	}
+	
+	public boolean pdfSignatureDig(){
+		try{
+		  // Número de página seleccionada
+		  int number_page = Integer.parseInt(spinner_page_number.getSelectedItem().toString());
+		  // Lee el archivo pdf
+		 // PdfReader pdfReader = new PdfReader(fileToSign);
+		  
+		  // Crea un archivo de salida para estampar la firma
+	      String uniqueId = getTodaysDate() + "_" + getCurrentTime();
+	      
+		  String output_filename = "firmaManuscrita"+uniqueId+".pdf";
+		  
+		  tempDir = Environment.getExternalStorageDirectory() + "/" +
+      			getResources().getString(R.string.app_name) + "/" +
+      			getResources().getString(R.string.external_dir_files) + "/";
+		  prepareDirectory();
+		  PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileOutputStream(tempDir+output_filename));
+
+		  // Obtiene referencia a la imágen de la firma
+          Image image = Image.getInstance(imageCaptured);
+
+          image.scalePercent(75); //Escala al 75%
+          
+          // Obtiene las dimensiones de la página
+          Rectangle rec = pdfReader.getPageSize(number_page);
+          float page_width = rec.getWidth();
+          float page_height = rec.getHeight();
+          
+          /*
+           * Calcula la posición de la firma basada en los coeficientes
+           * y el tamaño de la página a firmar
+           */
+          float x = (page_width  * x_coef) - image.getWidth() / 2;
+          float y = (page_height * y_coef) - image.getHeight() / 2;
+        	  
+          //put content under
+          PdfContentByte content = pdfStamper.getUnderContent(number_page);
+          //put content over
+          content = pdfStamper.getOverContent(number_page);
+
+          image.setAbsolutePosition(x, y);
+          content.addImage(image);
+
+          pdfStamper.close();
+          
+//          Toast.makeText(getApplicationContext(), "Archivo firmado correctamente...", Toast.LENGTH_LONG).show();
+//          finish();
+          Intent intent = new Intent(SelectSignUbicationHandwrittenSignatureActivity.this,
+        		  SignResultHandwrittenSignatureActivity.class);
+          intent.putExtra("STATUS", "done");
+          intent.putExtra("IMAGE_CAPTURED", imageCaptured);
+          intent.putExtra("FILE_TO_SIGN", fileToSign);
+          intent.putExtra("FILE_SIGNED", output_filename);
+          intent.putExtra("PATH_FILE_SIGNED", tempDir);
+          startActivity(intent);
+		 
+		}catch (IOException e) {
+            e.printStackTrace();
+            Toast.makeText(getApplicationContext(), "Error al firmar el archivo", Toast.LENGTH_LONG).show();
+        }catch (DocumentException e) {
+            e.printStackTrace();
+            Toast.makeText(getApplicationContext(), "Error al firmar el archivo", Toast.LENGTH_LONG).show();
+        }
+		return true;
+	}
+ 
+    private String getTodaysDate() { 
+ 
+        final Calendar c = Calendar.getInstance();
+        int todaysDate =     (c.get(Calendar.YEAR) * 10000) + 
+        ((c.get(Calendar.MONTH) + 1) * 100) + 
+        (c.get(Calendar.DAY_OF_MONTH));
+        return(String.valueOf(todaysDate));
+ 
+    }
+ 
+    private String getCurrentTime() {
+ 
+        final Calendar c = Calendar.getInstance();
+        int currentTime =     (c.get(Calendar.HOUR_OF_DAY) * 10000) + 
+        (c.get(Calendar.MINUTE) * 100) + 
+        (c.get(Calendar.SECOND));
+        return(String.valueOf(currentTime));
+ 
+    }
+	 
+    /**
+     * Prepara directorio
+     * @return boolean
+     */
+    private boolean prepareDirectory() 
+    {
+        try
+        {
+            if (makedirs()) 
+            {
+                return true;
+            } else {
+                return false;
+            }
+        } catch (Exception e) 
+        {
+            e.printStackTrace();
+            Toast.makeText(this, "Could not initiate File System.. Is Sdcard mounted properly?", Toast.LENGTH_LONG).show();
+            return false;
+        }
+    }
+ 
+    /**
+     * Crea directorio utilizando la variable tmpDir
+     * @return boolean
+     */
+    private boolean makedirs() 
+    {
+        File tempdir = new File(tempDir);
+        if (!tempdir.exists())
+            tempdir.mkdirs();
+ 
+//        if (tempdir.isDirectory()) 
+//        {
+//            File[] files = tempdir.listFiles();
+//            for (File file : files) 
+//            {
+//                if (!file.delete()) 
+//                {
+//                    System.out.println("Failed to delete " + file);
+//                }
+//            }
+//        }
+        return (tempdir.isDirectory());
+    }
+		
+		
+}
Index: TibisayMovil/src/ve/gob/cenditel/tibisaymovil/SignResultHandwrittenSignatureActivity.java
===================================================================
--- TibisayMovil/src/ve/gob/cenditel/tibisaymovil/SignResultHandwrittenSignatureActivity.java	(revision a8bb2bbd62a519f8aa67a0e6bb2e0f1d6b330a79)
+++ TibisayMovil/src/ve/gob/cenditel/tibisaymovil/SignResultHandwrittenSignatureActivity.java	(revision a8bb2bbd62a519f8aa67a0e6bb2e0f1d6b330a79)
@@ -0,0 +1,91 @@
+package ve.gob.cenditel.tibisaymovil;
+
+
+import java.io.File;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.Window;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+
+public class SignResultHandwrittenSignatureActivity extends Activity{
+    private String fileToSign;
+    private String imageCaptured;
+    private String fileSigned;
+    private String pathFileSigned;
+    private LinearLayout button_share;
+    private LinearLayout button_finish;
+	
+	@Override		
+	protected void onCreate(Bundle savedInstanceState) {
+			
+        //Capturando archivo que será firmado
+        fileToSign = getIntent().getExtras().getString("FILE_TO_SIGN");
+        //Capturando imagen de firma
+        imageCaptured = getIntent().getExtras().getString("IMAGE_CAPTURED");
+        //Capturando archivo firmado
+        fileSigned = getIntent().getExtras().getString("FILE_SIGNED");
+        pathFileSigned = getIntent().getExtras().getString("PATH_FILE_SIGNED");
+	        
+		//Estilando la barra de titulo
+		final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
+	
+		super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_sign_result_handwritten_signature);
+	    //Estilando Barra de titulo
+		if(customTitleSupported)
+			getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
+
+        TextView archivo_para_firm = (TextView) this.findViewById(R.id.archivo_para_firmar_path);
+        TextView imagen_utlizada= (TextView) this.findViewById(R.id.imagen_utlizada_name);
+        TextView archivo_firmado = (TextView) this.findViewById(R.id.archivo_firmado_path);
+
+        archivo_para_firm.setText(fileToSign);
+        imagen_utlizada.setText(imageCaptured);
+        archivo_firmado.setText(pathFileSigned+fileSigned);
+
+        button_share = (LinearLayout) this.findViewById(R.id.button_share_zone);
+        button_finish = (LinearLayout) this.findViewById(R.id.button_finish_zone);          
+       
+		
+        
+        button_finish.setOnClickListener(new OnClickListener() 
+        {        
+            public void onClick(View v) 
+            {
+            	Intent oIntent = new Intent(SignResultHandwrittenSignatureActivity.this, TibisayMovilActivity.class);
+		        oIntent.setAction(Intent.ACTION_VIEW);
+		        oIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+		        startActivity(oIntent);
+		        finish();
+            }
+        });
+        
+        button_share.setOnClickListener(new OnClickListener() 
+        {        
+            public void onClick(View v) 
+            {
+            	shareIt();
+            }
+        });
+	}
+	
+	private void shareIt() {
+		
+		Intent shareIntent = new Intent();
+		shareIntent.setAction(Intent.ACTION_SEND);
+		File file = new File(pathFileSigned + fileSigned);
+		Uri pdf_uri = Uri.fromFile(file);
+		Log.i("DEBUG", file.getPath());
+		shareIntent.putExtra(Intent.EXTRA_STREAM, pdf_uri);
+		shareIntent.setType("application/pdf ");
+		startActivity(Intent.createChooser(shareIntent, "Compartir pdf usando"));
+	}
+}
Index: TibisayMovil/src/ve/gob/cenditel/tibisaymovil/TibisayMovilActivity.java
===================================================================
--- TibisayMovil/src/ve/gob/cenditel/tibisaymovil/TibisayMovilActivity.java	(revision 37467beeb785e07fbb61834ed995522280a570be)
+++ TibisayMovil/src/ve/gob/cenditel/tibisaymovil/TibisayMovilActivity.java	(revision a8bb2bbd62a519f8aa67a0e6bb2e0f1d6b330a79)
@@ -1,4 +1,5 @@
 package ve.gob.cenditel.tibisaymovil;
 
+import ve.gob.cenditel.tibisaymovil.R.color;
 import android.os.Build;
 import android.os.Bundle;
@@ -134,9 +135,6 @@
 	
 	private void fileToSignHandwrittenSignature(){
-		Log.i("DEBUG", "antes de declarar intent");
 		Intent intent = new Intent(this, FileToSignHandwrittenSignatureActivity.class);
-		Log.i("DEBUG", "despues de declarar intent");
 		startActivity(intent);
-		Log.i("DEBUG", "despues de llamar intent");
 	}
 	
