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