1 | package ve.gob.cenditel.tibisaymovil; |
---|
2 | |
---|
3 | import java.io.BufferedInputStream; |
---|
4 | import java.io.File; |
---|
5 | import java.io.FileInputStream; |
---|
6 | import java.io.FileOutputStream; |
---|
7 | import java.io.InputStream; |
---|
8 | import java.util.ArrayList; |
---|
9 | |
---|
10 | |
---|
11 | import ee.sk.digidoc.DataFile; |
---|
12 | import ee.sk.digidoc.DigiDocException; |
---|
13 | import ee.sk.digidoc.Signature; |
---|
14 | import ee.sk.digidoc.SignedDoc; |
---|
15 | import ee.sk.digidoc.factory.DigiDocFactory; |
---|
16 | import ee.sk.utils.ConfigManager; |
---|
17 | import android.net.Uri; |
---|
18 | import android.os.Bundle; |
---|
19 | import android.os.Environment; |
---|
20 | import android.app.Activity; |
---|
21 | import android.content.Context; |
---|
22 | import android.content.Intent; |
---|
23 | import android.util.Log; |
---|
24 | import android.view.LayoutInflater; |
---|
25 | import android.view.Menu; |
---|
26 | import android.view.View; |
---|
27 | import android.view.ViewGroup; |
---|
28 | import android.view.Window; |
---|
29 | import android.view.View.OnClickListener; |
---|
30 | import android.webkit.MimeTypeMap; |
---|
31 | import android.widget.AdapterView; |
---|
32 | import android.widget.BaseAdapter; |
---|
33 | import android.widget.EditText; |
---|
34 | import android.widget.ImageView; |
---|
35 | import android.widget.LinearLayout; |
---|
36 | import android.widget.ListView; |
---|
37 | import android.widget.TextView; |
---|
38 | import android.widget.Toast; |
---|
39 | |
---|
40 | public class BDOCVerifyResultActivity extends Activity { |
---|
41 | |
---|
42 | |
---|
43 | |
---|
44 | |
---|
45 | // linear |
---|
46 | private LinearLayout button_share; |
---|
47 | private LinearLayout button_finish; |
---|
48 | private ListView documents_list; |
---|
49 | private ImageView arrowShowErrors; |
---|
50 | |
---|
51 | // cadena que mantiene la ruta para almacenar los archivos |
---|
52 | // extraidos de un contendor BDOC |
---|
53 | private String extractedDirFiles; |
---|
54 | |
---|
55 | // ruta absoluta al archivo a verificar |
---|
56 | private String fileToVerify; |
---|
57 | |
---|
58 | // extension del archivo a verificar |
---|
59 | private String fileToVerifyExtension; |
---|
60 | |
---|
61 | |
---|
62 | // mimetype del archivo a verificar |
---|
63 | private String mimeTypeFileToVerify; |
---|
64 | |
---|
65 | |
---|
66 | private ArrayList<SignatureErrorDetail> errorList; |
---|
67 | |
---|
68 | @Override |
---|
69 | protected void onCreate(Bundle savedInstanceState) { |
---|
70 | |
---|
71 | //Estilando la barra de titulo |
---|
72 | final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); |
---|
73 | Log.d("onCreate", "antes de super"); |
---|
74 | super.onCreate(savedInstanceState); |
---|
75 | |
---|
76 | setContentView(R.layout.activity_verify_result_bdoc); |
---|
77 | |
---|
78 | //Estilando Barra de titulo |
---|
79 | if(customTitleSupported) |
---|
80 | getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); |
---|
81 | |
---|
82 | arrowShowErrors = (ImageView) this.findViewById(R.id.arrow_show_errors); |
---|
83 | arrowShowErrors.setVisibility(ImageView.GONE); |
---|
84 | |
---|
85 | button_share = (LinearLayout) this.findViewById(R.id.button_share_zone); |
---|
86 | button_finish = (LinearLayout) this.findViewById(R.id.button_finish_zone); |
---|
87 | |
---|
88 | Bundle bundle=getIntent().getExtras(); |
---|
89 | fileToVerify = bundle.getString("fileToVerify"); |
---|
90 | fileToVerifyExtension = bundle.getString("fileExtension"); |
---|
91 | mimeTypeFileToVerify = getMimeType(fileToVerify); |
---|
92 | |
---|
93 | if (fileToVerifyExtension.equals("bdoc")){ |
---|
94 | // ejecutar la verificacion |
---|
95 | doBdocVerification(fileToVerify); |
---|
96 | }else{ |
---|
97 | Toast.makeText(getApplicationContext(), "¡Por Implementar!", Toast.LENGTH_SHORT).show(); |
---|
98 | |
---|
99 | } |
---|
100 | |
---|
101 | // inicializa la lista de objetos de errores de firma |
---|
102 | errorList = new ArrayList<SignatureErrorDetail>(); |
---|
103 | |
---|
104 | // habilita el click sobre la acción de finalizar la verificacion de firma y regresar |
---|
105 | button_finish.setOnClickListener(new OnClickListener() |
---|
106 | { |
---|
107 | public void onClick(View v) |
---|
108 | { |
---|
109 | |
---|
110 | Intent oIntent = new Intent(BDOCVerifyResultActivity.this, TibisayMovilActivity.class); |
---|
111 | oIntent.setAction(Intent.ACTION_VIEW); |
---|
112 | oIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
---|
113 | startActivity(oIntent); |
---|
114 | |
---|
115 | finish(); |
---|
116 | } |
---|
117 | }); |
---|
118 | |
---|
119 | // habilita el click sobre la acción de compartir el archivo |
---|
120 | button_share.setOnClickListener(new OnClickListener() |
---|
121 | { |
---|
122 | public void onClick(View v) |
---|
123 | { |
---|
124 | shareIt(); |
---|
125 | } |
---|
126 | }); |
---|
127 | |
---|
128 | // habilita el click sobre la flecha para mostrar los errores de la firma |
---|
129 | arrowShowErrors.setOnClickListener(new OnClickListener(){ |
---|
130 | |
---|
131 | public void onClick(View arg0) { |
---|
132 | |
---|
133 | Intent intent = new Intent(BDOCVerifyResultActivity.this, ActivitySignatureErrors.class); |
---|
134 | |
---|
135 | intent.putExtra("string", "hola mundo"); |
---|
136 | |
---|
137 | intent.setClass(BDOCVerifyResultActivity.this, ActivitySignatureErrors.class); |
---|
138 | intent.putExtra("SignatureErrorDetailList", errorList); |
---|
139 | |
---|
140 | startActivity(intent); |
---|
141 | |
---|
142 | } |
---|
143 | |
---|
144 | }); |
---|
145 | |
---|
146 | } |
---|
147 | |
---|
148 | |
---|
149 | |
---|
150 | |
---|
151 | |
---|
152 | |
---|
153 | // funcion para verificar un documento |
---|
154 | private void doBdocVerification(String absolutePathFileToVerify){ |
---|
155 | |
---|
156 | try { |
---|
157 | Log.d("doBdocVerification:", "Inicializando jdigidoc ..."); |
---|
158 | ConfigManager.init("jar://jdigidoc.cfg"); |
---|
159 | Log.d("despues de:", "ConfigManager.init"); |
---|
160 | |
---|
161 | Log.d("antes de:", "digFac"); |
---|
162 | DigiDocFactory digFac = ConfigManager.instance().getDigiDocFactory(); |
---|
163 | |
---|
164 | Log.d("getFilesDir:", getFilesDir().getAbsolutePath()); |
---|
165 | |
---|
166 | Log.d("PATH", Environment.getExternalStorageDirectory().toString()); |
---|
167 | |
---|
168 | File file = new File(absolutePathFileToVerify); |
---|
169 | InputStream selectedFile = null; |
---|
170 | selectedFile = new BufferedInputStream(new FileInputStream(file)); |
---|
171 | |
---|
172 | SignedDoc sdoc = digFac.readSignedDocFromStreamOfType(selectedFile, true); |
---|
173 | selectedFile.close(); |
---|
174 | |
---|
175 | //SignedDoc sdoc = digFac.readSignedDocFromStreamOfType(fraw, true); |
---|
176 | Signature signature = sdoc.getSignature(0); |
---|
177 | |
---|
178 | // TextView para colocar el resultado de la firma |
---|
179 | TextView signatureVerificationResult = (TextView) findViewById(R.id.archivo_para_firmar_path); |
---|
180 | |
---|
181 | |
---|
182 | // array de excepciones lanzadas al verificar firmas |
---|
183 | ArrayList arraySignaturesErrors = null; |
---|
184 | |
---|
185 | // array de strings para almanecenar los errores de firmas |
---|
186 | ArrayList<String> signatureVerificationErrors = new ArrayList<String>(); |
---|
187 | |
---|
188 | // verificar cada una de las firmas del contenedor |
---|
189 | for (int i = 0; i < sdoc.countSignatures(); i++){ |
---|
190 | Signature tmpSignature = sdoc.getSignature(i); |
---|
191 | arraySignaturesErrors = new ArrayList(); |
---|
192 | arraySignaturesErrors = tmpSignature.verify(sdoc, false, false); |
---|
193 | Log.d("****i:"+i,"arraySignaturesErrors.size: "+ arraySignaturesErrors.size()); |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | //String tmpError = new String(); |
---|
198 | for (int j = 0; j < arraySignaturesErrors.size(); j++){ |
---|
199 | |
---|
200 | signatureVerificationErrors.add("Firma "+Integer.toString(i+1)+ ": "+ |
---|
201 | arraySignaturesErrors.get(j).toString() + "\n"); |
---|
202 | //BDOCUtils.translateError(((DigiDocException) arraySignaturesErrors.get(j)).getCode()) + "\n"); |
---|
203 | |
---|
204 | Log.d("****signatureVerificationErrors", |
---|
205 | "Firma "+Integer.toString(i+1)+ ": "+ |
---|
206 | arraySignaturesErrors.get(j).toString() + "\n"); |
---|
207 | Log.d("signatureVerificationErrors: ", signatureVerificationErrors.get(j).toString()); |
---|
208 | Log.d("----", Integer.toString(((DigiDocException) arraySignaturesErrors.get(j)).getCode())); |
---|
209 | Log.d("---traduccion: ", BDOCUtils.translateErrors(arraySignaturesErrors)); |
---|
210 | Log.d("---traduccion codigo: ", BDOCUtils.translateError(((DigiDocException) arraySignaturesErrors.get(j)).getCode())); |
---|
211 | |
---|
212 | //tmpError = tmpError.concat(arraySignaturesErrors.get(j).toString()+"\n"); |
---|
213 | } |
---|
214 | |
---|
215 | //signatureVerificationErrors = "Firma "+Integer.toString(i+1)+ ": "+ |
---|
216 | //arraySignaturesErrors.get(i).toString() + "\n"; |
---|
217 | |
---|
218 | // lista de errores a pasar a la interfaz de detalles de error |
---|
219 | //String cn = SignedDoc.getCommonName(sdoc.getSignature(i).getKeyInfo().getSignersCertificate().getSubjectDN().getName()); |
---|
220 | |
---|
221 | //SignatureErrorDetail object = new SignatureErrorDetail(cn, tmpError); |
---|
222 | |
---|
223 | //errorList.add(object); |
---|
224 | |
---|
225 | } |
---|
226 | |
---|
227 | if (arraySignaturesErrors.isEmpty()) { |
---|
228 | signatureVerificationResult.setText("Válida"); |
---|
229 | Log.d("signature.verify", "NO HUBO ERROR EN LA VERIFICACION DE FIRMA"); |
---|
230 | Toast.makeText(getApplicationContext(), "¡FIRMA CORRECTA!", Toast.LENGTH_SHORT).show(); |
---|
231 | |
---|
232 | }else{ |
---|
233 | |
---|
234 | // habilitar la flecha para mostrar los errores de firma |
---|
235 | arrowShowErrors.setVisibility(ImageView.VISIBLE); |
---|
236 | |
---|
237 | String finalErrors = ""; |
---|
238 | for (int i = 0; i < signatureVerificationErrors.size(); i++ ) { |
---|
239 | finalErrors = finalErrors.concat(signatureVerificationErrors.get(i).toString()); |
---|
240 | //resultAndErrors = resultAndErrors.concat("Firma: "+i+" "+sigError.get(i).toString()+"\n"); |
---|
241 | } |
---|
242 | signatureVerificationResult.setText("Inválida\n"+finalErrors); |
---|
243 | Log.d("************", "SI HUBO ERROR"); |
---|
244 | Log.d("************", finalErrors); |
---|
245 | |
---|
246 | Toast.makeText(getApplicationContext(), "ERROR DE VERIFICACION DE FIRMA", Toast.LENGTH_SHORT).show(); |
---|
247 | } |
---|
248 | |
---|
249 | |
---|
250 | //ArrayList sigError = signature.verify(sdoc, false, false); |
---|
251 | //ArrayList sigError = sdoc.verify(false, false); |
---|
252 | |
---|
253 | // se crea el adaptador para mostrar los documentos firmados |
---|
254 | ListView documentListView = (ListView) findViewById(R.id.documents_list); |
---|
255 | final ArrayList<DocumentFromBDOC> docs = new ArrayList<DocumentFromBDOC>(); |
---|
256 | |
---|
257 | // Crear directorio ExtractedFiles donde se almacenan los archivos extraidos |
---|
258 | // de los contenedores BDOC |
---|
259 | extractedDirFiles = Environment.getExternalStorageDirectory() + "/" + |
---|
260 | getResources().getString(R.string.app_name) + "/" + |
---|
261 | getResources().getString(R.string.extracted_dir_files) + "/"; |
---|
262 | prepareDirectory(); |
---|
263 | |
---|
264 | for (int i = 0; i < sdoc.countDataFiles(); i++){ |
---|
265 | // obtener el DataFile |
---|
266 | DataFile df = sdoc.getDataFile(i); |
---|
267 | docs.add(new DocumentFromBDOC(df.getFileName())); |
---|
268 | Log.d("MIMETYPE:", df.getMimeType()); |
---|
269 | // Extraer el archivo y guardarlo en /mnt/sdcard/TibisayMovil/ExtractedFiles |
---|
270 | FileOutputStream fos = new FileOutputStream(extractedDirFiles+df.getFileName()); |
---|
271 | InputStream is = df.getBodyAsStream(); |
---|
272 | if(is == null) { |
---|
273 | Log.d("ERROR al extrarer archivo", "DataFile has no data!"); |
---|
274 | //return false; |
---|
275 | } |
---|
276 | byte[] data = new byte[4096]; |
---|
277 | int n = 0, m = 0; |
---|
278 | while((n = is.read(data)) > 0) { |
---|
279 | fos.write(data, 0, n); |
---|
280 | m += n; |
---|
281 | } |
---|
282 | fos.close(); |
---|
283 | is.close(); |
---|
284 | } |
---|
285 | |
---|
286 | DocumentFromBDOCAdapter documentAdapter = new DocumentFromBDOCAdapter(BDOCVerifyResultActivity.this, docs); |
---|
287 | documentListView.setAdapter(documentAdapter); |
---|
288 | documentListView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { |
---|
289 | |
---|
290 | @Override |
---|
291 | public void onItemClick(AdapterView<?> parent, View view, |
---|
292 | int position, long id) { |
---|
293 | String absolutePathToOpen = extractedDirFiles + docs.get(position).getName(); |
---|
294 | Toast.makeText(getApplicationContext(), getMimeType(absolutePathToOpen), Toast.LENGTH_SHORT).show(); |
---|
295 | openIt(absolutePathToOpen, getMimeType(absolutePathToOpen)); |
---|
296 | |
---|
297 | |
---|
298 | } |
---|
299 | |
---|
300 | }); |
---|
301 | |
---|
302 | // se crea el adaptador para mostrar los firmantes del contenedor |
---|
303 | ListView signerListView = (ListView) findViewById(R.id.signatures_list); |
---|
304 | final ArrayList<SignerFromBDOC> signers = new ArrayList<SignerFromBDOC>(); |
---|
305 | |
---|
306 | for (int i = 0; i < sdoc.countSignatures(); i++){ |
---|
307 | Signature signatureTemp = sdoc.getSignature(i); |
---|
308 | //signers.add(new SignerFromBDOC(signatureTemp.getSubject())); |
---|
309 | |
---|
310 | String cn = SignedDoc.getCommonName( |
---|
311 | sdoc.getSignature(i).getKeyInfo().getSignersCertificate().getSubjectDN().getName()); |
---|
312 | String name = sdoc.getSignature(i).getKeyInfo().getSubjectLastName(); |
---|
313 | String date = sdoc.getSignature(i).getSignedProperties().getSigningTime().toString(); |
---|
314 | String certificateSerial = sdoc.getSignature(i).getKeyInfo().getSignersCertificate().getSerialNumber().toString(); |
---|
315 | String validFrom = sdoc.getSignature(i).getKeyInfo().getSignersCertificate().getNotBefore().toLocaleString(); |
---|
316 | String validUntil = sdoc.getSignature(i).getKeyInfo().getSignersCertificate().getNotAfter().toLocaleString(); |
---|
317 | String certificateIssuer = sdoc.getSignature(i).getKeyInfo().getSignersCertificate().getIssuerX500Principal().toString(); |
---|
318 | |
---|
319 | // agregar el nombre comun del firmante y la fecha y la hora |
---|
320 | signers.add(new SignerFromBDOC(name, cn, date, certificateSerial, validFrom, validUntil, certificateIssuer)); |
---|
321 | |
---|
322 | } |
---|
323 | SignerFromBDOCAdapter signerAdapter = new SignerFromBDOCAdapter(BDOCVerifyResultActivity.this, signers); |
---|
324 | signerListView.setAdapter(signerAdapter); |
---|
325 | signerListView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { |
---|
326 | |
---|
327 | String ss = "hola mundo"; |
---|
328 | @Override |
---|
329 | public void onItemClick(AdapterView<?> parent, View view, |
---|
330 | int position, long id) { |
---|
331 | |
---|
332 | //String signer = parent.getItemAtPosition(position).toString(); |
---|
333 | |
---|
334 | Toast.makeText(getApplicationContext(), "SE DEBE MOSTRAR INFORMACIÓN DEL FIRMANTE", Toast.LENGTH_SHORT).show(); |
---|
335 | showSignatureDetails(position, signers); |
---|
336 | } |
---|
337 | |
---|
338 | }); |
---|
339 | |
---|
340 | |
---|
341 | /* |
---|
342 | if(sigError.isEmpty()){ |
---|
343 | Log.d("signature.verify", "NO HUBO ERROR EN LA VERIFICACION DE FIRMA"); |
---|
344 | String res = "Numero de firmas: " + Integer.toString(sdoc.countSignatures()) + |
---|
345 | " Numero de documentos: " + Integer.toString(sdoc.countDataFiles()) + |
---|
346 | " Perfil de firma: " + signature.getProfile() + |
---|
347 | " Sujeto: " + signature.getSubject() + |
---|
348 | " Hora: " + signature.getSignedProperties().getSigningTime().toString(); |
---|
349 | Log.d("-->: ", res); |
---|
350 | |
---|
351 | //result.setText("Firma válida"); |
---|
352 | |
---|
353 | }else{ |
---|
354 | Log.d("signature.verify", "SI HUBO ERROR"); |
---|
355 | Log.d("signature.verify", Integer.toString(sigError.size())); |
---|
356 | |
---|
357 | String resultAndErrors = "Firma Inválida\n"; |
---|
358 | |
---|
359 | for (int i=0; i<sigError.size(); i++ ){ |
---|
360 | Log.d("signature.verify", sigError.get(i).toString()); |
---|
361 | //resultAndErrors.concat(sigError.get(i).toString()+"\n"); |
---|
362 | resultAndErrors = resultAndErrors.concat("Firma: "+i+" "+sigError.get(i).toString()+"\n"); |
---|
363 | |
---|
364 | //Toast.makeText(getApplicationContext(), sigError.get(i).toString(), Toast.LENGTH_SHORT).show(); |
---|
365 | } |
---|
366 | Toast.makeText(getApplicationContext(), "ERROR DE VERIFICACION DE FIRMA", Toast.LENGTH_SHORT).show(); |
---|
367 | //result.setText("Firma inválida"); |
---|
368 | //result.setText(resultAndErrors); |
---|
369 | } |
---|
370 | */ |
---|
371 | |
---|
372 | |
---|
373 | } catch (Exception e) { |
---|
374 | // TODO Auto-generated catch block |
---|
375 | |
---|
376 | //showOneButtonDialog(e.getMessage()); |
---|
377 | |
---|
378 | Log.d("****exception:", e.getMessage()); |
---|
379 | e.printStackTrace(); |
---|
380 | } |
---|
381 | |
---|
382 | } // fin de doVerification(String f) |
---|
383 | |
---|
384 | |
---|
385 | |
---|
386 | |
---|
387 | |
---|
388 | |
---|
389 | |
---|
390 | |
---|
391 | |
---|
392 | |
---|
393 | // clase que abstrae un documento incluido dentro de un contenedor BDOC |
---|
394 | public class DocumentFromBDOC { |
---|
395 | private String mName; |
---|
396 | |
---|
397 | public DocumentFromBDOC(String name){ |
---|
398 | mName = name; |
---|
399 | } |
---|
400 | |
---|
401 | public void setName(String name) { |
---|
402 | this.mName = name; |
---|
403 | } |
---|
404 | |
---|
405 | public String getName() { |
---|
406 | return mName; |
---|
407 | } |
---|
408 | } // fin de clase DocumentFromBDOC |
---|
409 | |
---|
410 | // clase que abstrae el adaptador para llenar el ListView de documentos que |
---|
411 | // se encuentran dentro del contenedor BDOC |
---|
412 | private class DocumentFromBDOCAdapter extends BaseAdapter { |
---|
413 | |
---|
414 | private ArrayList<DocumentFromBDOC> mDocumentFromBDOCList; |
---|
415 | private LayoutInflater lInflater; |
---|
416 | |
---|
417 | private DocumentFromBDOCAdapter(Context context, ArrayList<DocumentFromBDOC> documents) { |
---|
418 | this.lInflater = LayoutInflater.from(context); |
---|
419 | this.mDocumentFromBDOCList = documents; |
---|
420 | |
---|
421 | } |
---|
422 | |
---|
423 | |
---|
424 | @Override |
---|
425 | public int getCount() { |
---|
426 | return mDocumentFromBDOCList.size(); |
---|
427 | } |
---|
428 | |
---|
429 | @Override |
---|
430 | public Object getItem(int position) { |
---|
431 | return mDocumentFromBDOCList.get(position); |
---|
432 | } |
---|
433 | |
---|
434 | @Override |
---|
435 | public long getItemId(int position) { |
---|
436 | return position; |
---|
437 | } |
---|
438 | |
---|
439 | @Override |
---|
440 | public View getView(int position, View convertView, ViewGroup parent) { |
---|
441 | ViewHolder container = null; |
---|
442 | |
---|
443 | if (convertView == null){ |
---|
444 | container = new ViewHolder(); |
---|
445 | convertView = lInflater.inflate(R.layout.document_inside_bdoc_item, null); |
---|
446 | |
---|
447 | container.filename_text = (TextView) convertView.findViewById(R.id.filename_text); |
---|
448 | container.filename_modified = (TextView) convertView.findViewById(R.id.filename_modified); |
---|
449 | container.type_image = (ImageView) convertView.findViewById(R.id.type_image); |
---|
450 | convertView.setTag(container); |
---|
451 | }else{ |
---|
452 | container = (ViewHolder) convertView.getTag(); |
---|
453 | } |
---|
454 | |
---|
455 | DocumentFromBDOC doc = (DocumentFromBDOC) getItem(position); |
---|
456 | container.filename_text.setText(doc.getName()); |
---|
457 | container.filename_modified.setText(doc.getName()); |
---|
458 | container.type_image.setImageResource(R.drawable.ic_archivo); |
---|
459 | |
---|
460 | return convertView; |
---|
461 | } |
---|
462 | |
---|
463 | |
---|
464 | class ViewHolder{ |
---|
465 | TextView filename_text; |
---|
466 | TextView filename_modified; |
---|
467 | ImageView type_image; |
---|
468 | } |
---|
469 | |
---|
470 | } |
---|
471 | |
---|
472 | |
---|
473 | // class que abstrae un firmante incluido en un contenedor BDOC |
---|
474 | private class SignerFromBDOC { |
---|
475 | |
---|
476 | // nombre del firmante |
---|
477 | private String mName; |
---|
478 | |
---|
479 | // nombre comun del firmante |
---|
480 | private String mCN; |
---|
481 | |
---|
482 | // fecha y hora de la firma |
---|
483 | private String mDate; |
---|
484 | |
---|
485 | // serial del certificado |
---|
486 | private String mCertificateSerial; |
---|
487 | |
---|
488 | // fecha de validez inicial |
---|
489 | private String mValidFrom; |
---|
490 | |
---|
491 | // fecha de validez final |
---|
492 | private String mValidUntil; |
---|
493 | |
---|
494 | // emisor del certificado |
---|
495 | private String mCertificateIssuer; |
---|
496 | |
---|
497 | public SignerFromBDOC(String name, String cn, String date, String serial, String validFrom, String validUntil, String issuer){ |
---|
498 | mName = name; |
---|
499 | mCN = cn; |
---|
500 | mDate = date; |
---|
501 | mCertificateSerial = serial; |
---|
502 | mValidFrom = validFrom; |
---|
503 | mValidUntil = validUntil; |
---|
504 | mCertificateIssuer = issuer; |
---|
505 | } |
---|
506 | |
---|
507 | public void setName(String name) { |
---|
508 | this.mName = name; |
---|
509 | } |
---|
510 | |
---|
511 | public String getName() { |
---|
512 | return mName; |
---|
513 | } |
---|
514 | |
---|
515 | public void setCN(String cn) { |
---|
516 | this.mCN = cn; |
---|
517 | } |
---|
518 | |
---|
519 | public String getCN() { |
---|
520 | return mCN; |
---|
521 | } |
---|
522 | |
---|
523 | public void setDate(String date) { |
---|
524 | this.mDate = date; |
---|
525 | } |
---|
526 | |
---|
527 | public String getDate() { |
---|
528 | return mDate; |
---|
529 | } |
---|
530 | |
---|
531 | public void setCertificateSerial(String certSerial) { |
---|
532 | this.mCertificateSerial = certSerial; |
---|
533 | } |
---|
534 | |
---|
535 | public String getCertificateSerial() { |
---|
536 | return mCertificateSerial; |
---|
537 | } |
---|
538 | |
---|
539 | public void setValidFrom(String validFrom) { |
---|
540 | this.mValidFrom = validFrom; |
---|
541 | } |
---|
542 | |
---|
543 | public String getValidFrom() { |
---|
544 | return mValidFrom; |
---|
545 | } |
---|
546 | |
---|
547 | public void setValidUntil(String validUntil) { |
---|
548 | this.mValidUntil = validUntil; |
---|
549 | } |
---|
550 | |
---|
551 | public String getValidUntil() { |
---|
552 | return mValidUntil; |
---|
553 | } |
---|
554 | |
---|
555 | public void setCertificateIssuer(String certIssuer) { |
---|
556 | this.mCertificateIssuer = certIssuer; |
---|
557 | } |
---|
558 | |
---|
559 | public String getCertificateIssuer() { |
---|
560 | return mCertificateIssuer; |
---|
561 | } |
---|
562 | |
---|
563 | } // fin de clase SignerFromBDOC |
---|
564 | |
---|
565 | // clase que abstrae el adaptador para llenar el ListView de documentos que |
---|
566 | // se encuentran dentro del contenedor BDOC |
---|
567 | private class SignerFromBDOCAdapter extends BaseAdapter { |
---|
568 | |
---|
569 | private ArrayList<SignerFromBDOC> mSignerFromBDOCList; |
---|
570 | private LayoutInflater lInflater; |
---|
571 | |
---|
572 | private SignerFromBDOCAdapter(Context context, ArrayList<SignerFromBDOC> signers) { |
---|
573 | this.lInflater = LayoutInflater.from(context); |
---|
574 | this.mSignerFromBDOCList = signers; |
---|
575 | |
---|
576 | } |
---|
577 | |
---|
578 | |
---|
579 | @Override |
---|
580 | public int getCount() { |
---|
581 | return mSignerFromBDOCList.size(); |
---|
582 | } |
---|
583 | |
---|
584 | @Override |
---|
585 | public Object getItem(int position) { |
---|
586 | return mSignerFromBDOCList.get(position); |
---|
587 | } |
---|
588 | |
---|
589 | @Override |
---|
590 | public long getItemId(int position) { |
---|
591 | return position; |
---|
592 | } |
---|
593 | |
---|
594 | @Override |
---|
595 | public View getView(int position, View convertView, ViewGroup parent) { |
---|
596 | ViewHolder container = null; |
---|
597 | |
---|
598 | if (convertView == null){ |
---|
599 | container = new ViewHolder(); |
---|
600 | convertView = lInflater.inflate(R.layout.signer_inside_bdoc_item, null); |
---|
601 | |
---|
602 | container.signer_text = (TextView) convertView.findViewById(R.id.signer_info); |
---|
603 | container.signer_modified = (TextView) convertView.findViewById(R.id.signature_errors); |
---|
604 | container.type_image = (ImageView) convertView.findViewById(R.id.type_image); |
---|
605 | convertView.setTag(container); |
---|
606 | }else{ |
---|
607 | container = (ViewHolder) convertView.getTag(); |
---|
608 | } |
---|
609 | |
---|
610 | SignerFromBDOC doc = (SignerFromBDOC) getItem(position); |
---|
611 | container.signer_text.setText(doc.getName()); |
---|
612 | container.signer_modified.setText(doc.getName()); |
---|
613 | container.type_image.setImageResource(R.drawable.ic_pluma); |
---|
614 | |
---|
615 | return convertView; |
---|
616 | } |
---|
617 | |
---|
618 | |
---|
619 | class ViewHolder{ |
---|
620 | TextView signer_text; |
---|
621 | TextView signer_modified; |
---|
622 | ImageView type_image; |
---|
623 | } |
---|
624 | |
---|
625 | } |
---|
626 | |
---|
627 | |
---|
628 | /** |
---|
629 | * Prepara directorio |
---|
630 | * @return boolean |
---|
631 | */ |
---|
632 | private boolean prepareDirectory() |
---|
633 | { |
---|
634 | try |
---|
635 | { |
---|
636 | if (makedirs()) |
---|
637 | { |
---|
638 | return true; |
---|
639 | } else { |
---|
640 | return false; |
---|
641 | } |
---|
642 | } catch (Exception e) |
---|
643 | { |
---|
644 | e.printStackTrace(); |
---|
645 | Toast.makeText(this, "Could not initiate File System.. Is Sdcard mounted properly?", Toast.LENGTH_LONG).show(); |
---|
646 | return false; |
---|
647 | } |
---|
648 | } |
---|
649 | |
---|
650 | /** |
---|
651 | * Crea directorio utilizando la variable tmpDir |
---|
652 | * @return boolean |
---|
653 | */ |
---|
654 | private boolean makedirs() |
---|
655 | { |
---|
656 | File tempdir = new File(extractedDirFiles); |
---|
657 | if (!tempdir.exists()) |
---|
658 | tempdir.mkdirs(); |
---|
659 | |
---|
660 | // if (tempdir.isDirectory()) |
---|
661 | // { |
---|
662 | // File[] files = tempdir.listFiles(); |
---|
663 | // for (File file : files) |
---|
664 | // { |
---|
665 | // if (!file.delete()) |
---|
666 | // { |
---|
667 | // System.out.println("Failed to delete " + file); |
---|
668 | // } |
---|
669 | // } |
---|
670 | // } |
---|
671 | return (tempdir.isDirectory()); |
---|
672 | } |
---|
673 | |
---|
674 | // funcion para lanzar un intent que abra un archivo |
---|
675 | private void openIt(String filePath, String mimeType) { |
---|
676 | |
---|
677 | Intent shareIntent = new Intent(); |
---|
678 | shareIntent.setAction(Intent.ACTION_VIEW); |
---|
679 | File file = new File(filePath); |
---|
680 | Uri uri = Uri.fromFile(file); |
---|
681 | Log.i("DEBUG", file.getPath()); |
---|
682 | shareIntent.setDataAndType(uri, mimeType); |
---|
683 | startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.open_it_using))); |
---|
684 | } |
---|
685 | |
---|
686 | // funcion para obtener el tipo mime de un archivo |
---|
687 | public static String getMimeType(String url) |
---|
688 | { |
---|
689 | String extension = url.substring(url.lastIndexOf(".")); |
---|
690 | String mimeTypeMap = MimeTypeMap.getFileExtensionFromUrl(extension); |
---|
691 | String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(mimeTypeMap); |
---|
692 | return mimeType; |
---|
693 | } |
---|
694 | |
---|
695 | // funcion para compartir el documento |
---|
696 | private void shareIt() { |
---|
697 | |
---|
698 | Intent shareIntent = new Intent(); |
---|
699 | shareIntent.setAction(Intent.ACTION_SEND); |
---|
700 | File file = new File(fileToVerify); |
---|
701 | |
---|
702 | |
---|
703 | Uri uri = Uri.fromFile(file); |
---|
704 | Log.i("DEBUG", file.getPath()); |
---|
705 | //Log.d("******", getMimeType(file.getPath())); |
---|
706 | //shareIntent.setDataAndType(uri, getMimeType(file.getPath())); |
---|
707 | shareIntent.putExtra(Intent.EXTRA_STREAM, uri); |
---|
708 | shareIntent.setType("application/*"); |
---|
709 | startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share_it_using))); |
---|
710 | } |
---|
711 | |
---|
712 | @Override |
---|
713 | public boolean onCreateOptionsMenu(Menu menu) { |
---|
714 | // Inflate the menu; this adds items to the action bar if it is present. |
---|
715 | getMenuInflater().inflate(R.menu.bdocverify_result, menu); |
---|
716 | return true; |
---|
717 | } |
---|
718 | |
---|
719 | private void showSignatureDetails(int position, ArrayList<SignerFromBDOC> signers) { |
---|
720 | |
---|
721 | Log.d("**showSignatureDetails", Integer.toString(position)); |
---|
722 | Log.d("** nombre", signers.get(position).getName()); |
---|
723 | Intent intent = new Intent(this, ActivitySignerInfo.class); |
---|
724 | |
---|
725 | intent.putExtra("name", signers.get(position).getName()); |
---|
726 | intent.putExtra("cn", signers.get(position).getCN()); |
---|
727 | intent.putExtra("date", signers.get(position).getDate()); |
---|
728 | intent.putExtra("certificateSerial", signers.get(position).getCertificateSerial()); |
---|
729 | intent.putExtra("validFrom", signers.get(position).getValidFrom()); |
---|
730 | intent.putExtra("validUntil", signers.get(position).getValidUntil()); |
---|
731 | intent.putExtra("certificateIssuer", signers.get(position).getCertificateIssuer()); |
---|
732 | startActivity(intent); |
---|
733 | } |
---|
734 | |
---|
735 | // funcion para desplegar la interfaz con los detalles de errores de la firma |
---|
736 | private void showSignatureDetails() { |
---|
737 | Log.d("showSignatureDetails()", "..."); |
---|
738 | } |
---|
739 | |
---|
740 | |
---|
741 | } |
---|
742 | |
---|
743 | |
---|
744 | |
---|
745 | |
---|