1 | /* |
---|
2 | Tibisay Movil |
---|
3 | |
---|
4 | Copyright (C) 2013 Antonio Araujo (aaraujo@cenditel.gob.ve), Jose Ruiz |
---|
5 | (jruiz@cenditel.gob.ve), Fundacion Centro Nacional de Desarrollo e |
---|
6 | Investigacion en Tecnologias Libres - CENDITEL. |
---|
7 | |
---|
8 | La Fundación CENDITEL concede permiso para usar, copiar, distribuir y/o |
---|
9 | modificar este programa, reconociendo el derecho que la humanidad posee al |
---|
10 | libre acceso al conocimiento, bajo los términos de la licencia de software |
---|
11 | GPL versión 2.0 de la Free Software Foundation. |
---|
12 | |
---|
13 | Este programa se distribuye con la esperanza de que sea util, pero SIN |
---|
14 | NINGUNA GARANTIA; tampoco las implicitas garantias de MERCANTILIDAD o |
---|
15 | ADECUACION A UN PROPOSITO PARTICULAR. |
---|
16 | |
---|
17 | Para mayor información sobre los términos de la licencia ver el archivo |
---|
18 | llamado "gpl-2.0.txt" en ingles. |
---|
19 | */ |
---|
20 | |
---|
21 | package ve.gob.cenditel.tibisaymovil; |
---|
22 | |
---|
23 | |
---|
24 | import java.io.File; |
---|
25 | |
---|
26 | import android.app.Activity; |
---|
27 | import android.content.Intent; |
---|
28 | import android.net.Uri; |
---|
29 | import android.os.Bundle; |
---|
30 | import android.util.Log; |
---|
31 | import android.view.View; |
---|
32 | import android.view.View.OnClickListener; |
---|
33 | import android.view.Window; |
---|
34 | import android.webkit.MimeTypeMap; |
---|
35 | import android.widget.LinearLayout; |
---|
36 | import android.widget.TextView; |
---|
37 | import android.widget.Toast; |
---|
38 | |
---|
39 | public class SignResultHandwrittenSignatureActivity extends Activity{ |
---|
40 | private String fileToSign; |
---|
41 | private String imageCaptured; |
---|
42 | private String fileSigned; |
---|
43 | private String pathFileSigned; |
---|
44 | private LinearLayout button_share; |
---|
45 | private LinearLayout button_finish; |
---|
46 | |
---|
47 | @Override |
---|
48 | protected void onCreate(Bundle savedInstanceState) { |
---|
49 | |
---|
50 | //Capturando archivo que será firmado |
---|
51 | fileToSign = getIntent().getExtras().getString("FILE_TO_SIGN"); |
---|
52 | //Capturando imagen de firma |
---|
53 | imageCaptured = getIntent().getExtras().getString("IMAGE_CAPTURED"); |
---|
54 | //Capturando archivo firmado |
---|
55 | fileSigned = getIntent().getExtras().getString("FILE_SIGNED"); |
---|
56 | pathFileSigned = getIntent().getExtras().getString("PATH_FILE_SIGNED"); |
---|
57 | |
---|
58 | //Estilando la barra de titulo |
---|
59 | final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); |
---|
60 | |
---|
61 | super.onCreate(savedInstanceState); |
---|
62 | setContentView(R.layout.activity_sign_result_handwritten_signature); |
---|
63 | //Estilando Barra de titulo |
---|
64 | if(customTitleSupported) |
---|
65 | getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); |
---|
66 | |
---|
67 | TextView archivo_para_firm = (TextView) this.findViewById(R.id.archivo_original_a_firmar); |
---|
68 | TextView imagen_utlizada= (TextView) this.findViewById(R.id.archivo_descifrado); |
---|
69 | TextView archivo_firmado = (TextView) this.findViewById(R.id.destinatario); |
---|
70 | |
---|
71 | archivo_para_firm.setText(fileToSign); |
---|
72 | imagen_utlizada.setText(imageCaptured); |
---|
73 | archivo_firmado.setText(pathFileSigned+fileSigned); |
---|
74 | |
---|
75 | button_share = (LinearLayout) this.findViewById(R.id.button_remove_certificate_zone); |
---|
76 | button_finish = (LinearLayout) this.findViewById(R.id.button_add_certificate_zone); |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | button_finish.setOnClickListener(new OnClickListener() |
---|
81 | { |
---|
82 | public void onClick(View v) |
---|
83 | { |
---|
84 | Intent oIntent = new Intent(SignResultHandwrittenSignatureActivity.this, TibisayMovilActivity.class); |
---|
85 | oIntent.setAction(Intent.ACTION_VIEW); |
---|
86 | oIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
---|
87 | startActivity(oIntent); |
---|
88 | finish(); |
---|
89 | } |
---|
90 | }); |
---|
91 | |
---|
92 | button_share.setOnClickListener(new OnClickListener() |
---|
93 | { |
---|
94 | public void onClick(View v) |
---|
95 | { |
---|
96 | shareIt(); |
---|
97 | } |
---|
98 | }); |
---|
99 | |
---|
100 | |
---|
101 | LinearLayout layoutDecryptedFileAndArror = (LinearLayout) this.findViewById(R.id.layout_decrypted_file_and_arrow); |
---|
102 | |
---|
103 | OnClickListener decryptedFileListener = new OnClickListener() { |
---|
104 | public void onClick(View v) { |
---|
105 | // do something when the button is clicked |
---|
106 | //Toast.makeText(getApplicationContext(), "**CLICK SOBRE EL TEXTVIEW***", Toast.LENGTH_LONG).show(); |
---|
107 | |
---|
108 | openIt(pathFileSigned+fileSigned, getMimeType(pathFileSigned+fileSigned)); |
---|
109 | } |
---|
110 | }; |
---|
111 | layoutDecryptedFileAndArror.setOnClickListener(decryptedFileListener); |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | // funcion para lanzar un intent que abra un archivo |
---|
116 | private void openIt(String decryptedFile, String mimeType) { |
---|
117 | |
---|
118 | Intent shareIntent = new Intent(); |
---|
119 | shareIntent.setAction(Intent.ACTION_VIEW); |
---|
120 | File file = new File(decryptedFile); |
---|
121 | Uri uri = Uri.fromFile(file); |
---|
122 | Log.i("DEBUG", file.getPath()); |
---|
123 | shareIntent.setDataAndType(uri, mimeType); |
---|
124 | startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.open_it_using))); |
---|
125 | } |
---|
126 | |
---|
127 | private void shareIt() { |
---|
128 | |
---|
129 | Intent shareIntent = new Intent(); |
---|
130 | shareIntent.setAction(Intent.ACTION_SEND); |
---|
131 | Toast.makeText(SignResultHandwrittenSignatureActivity.this,pathFileSigned + fileSigned,Toast.LENGTH_LONG).show(); |
---|
132 | File file = new File(pathFileSigned + fileSigned); |
---|
133 | Uri pdf_uri = Uri.fromFile(file); |
---|
134 | Log.i("DEBUG", file.getPath()); |
---|
135 | shareIntent.putExtra(Intent.EXTRA_STREAM, pdf_uri); |
---|
136 | shareIntent.setType("application/pdf "); |
---|
137 | startActivity(Intent.createChooser(shareIntent, "Compartir pdf usando")); |
---|
138 | } |
---|
139 | |
---|
140 | // funcion para obtener el tipo mime de un archivo |
---|
141 | public static String getMimeType(String url) |
---|
142 | { |
---|
143 | String extension = url.substring(url.lastIndexOf(".")); |
---|
144 | String mimeTypeMap = MimeTypeMap.getFileExtensionFromUrl(extension); |
---|
145 | String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(mimeTypeMap); |
---|
146 | return mimeType; |
---|
147 | } |
---|
148 | } |
---|