[8379cd8] | 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 | |
---|
[e68708b] | 21 | package ve.gob.cenditel.tibisaymovil; |
---|
| 22 | |
---|
| 23 | import java.io.BufferedInputStream; |
---|
| 24 | import java.io.File; |
---|
| 25 | import java.io.InputStream; |
---|
| 26 | |
---|
| 27 | import android.net.Uri; |
---|
| 28 | import android.os.Bundle; |
---|
| 29 | import android.app.Activity; |
---|
| 30 | import android.content.Context; |
---|
| 31 | import android.content.Intent; |
---|
| 32 | import android.util.Log; |
---|
| 33 | import android.view.LayoutInflater; |
---|
| 34 | import android.view.View; |
---|
| 35 | import android.view.ViewGroup; |
---|
| 36 | import android.view.Window; |
---|
| 37 | import android.view.View.OnClickListener; |
---|
[42e7061] | 38 | import android.webkit.MimeTypeMap; |
---|
[e68708b] | 39 | import android.widget.AdapterView; |
---|
| 40 | import android.widget.BaseAdapter; |
---|
| 41 | import android.widget.ImageView; |
---|
| 42 | import android.widget.LinearLayout; |
---|
| 43 | import android.widget.ListView; |
---|
| 44 | import android.widget.TextView; |
---|
| 45 | import android.widget.Toast; |
---|
| 46 | |
---|
| 47 | import java.security.*; |
---|
| 48 | import java.security.cert.Certificate; |
---|
| 49 | import java.security.cert.CertificateFactory; |
---|
| 50 | import java.io.*; |
---|
| 51 | import java.lang.reflect.Field; |
---|
| 52 | |
---|
| 53 | import com.lowagie.text.pdf.*; |
---|
| 54 | |
---|
| 55 | import ee.sk.digidoc.SignedDoc; |
---|
| 56 | import ee.sk.utils.ConvertUtils; |
---|
| 57 | |
---|
| 58 | import java.util.Calendar; |
---|
| 59 | import java.util.ArrayList; |
---|
| 60 | import java.util.Random; |
---|
| 61 | import java.security.cert.X509Certificate; |
---|
| 62 | import java.text.SimpleDateFormat; |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | public class PDFVerifyResultActivity extends Activity { |
---|
| 67 | |
---|
| 68 | private LinearLayout button_share; |
---|
| 69 | private LinearLayout button_finish; |
---|
| 70 | |
---|
[c14b8d2] | 71 | // ruta absoluta al archivo a verificar |
---|
[e68708b] | 72 | private String pdfToVerify; |
---|
| 73 | |
---|
| 74 | @Override |
---|
| 75 | protected void onCreate(Bundle savedInstanceState) { |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | //Estilando la barra de titulo |
---|
| 80 | final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); |
---|
| 81 | |
---|
| 82 | super.onCreate(savedInstanceState); |
---|
| 83 | |
---|
| 84 | setContentView(R.layout.activity_verify_result_pdf); |
---|
| 85 | |
---|
| 86 | //Estilando Barra de titulo |
---|
| 87 | if(customTitleSupported) |
---|
| 88 | getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); |
---|
| 89 | |
---|
| 90 | // obtener el archivo pdf a verificar |
---|
[4c4873f] | 91 | //Bundle bundle = getIntent().getExtras(); |
---|
| 92 | //pdfToVerify = bundle.getString("pdfToVerify"); |
---|
| 93 | |
---|
| 94 | final android.net.Uri data = getIntent().getData (); |
---|
| 95 | |
---|
| 96 | if (data != null) { |
---|
| 97 | Toast.makeText(getApplicationContext(), "data != null", Toast.LENGTH_SHORT).show(); |
---|
| 98 | |
---|
| 99 | // verificar el tipo de scheme |
---|
| 100 | String scheme = data.getScheme(); |
---|
| 101 | |
---|
| 102 | // verificacion de un archivo que esta en el dispositivo |
---|
| 103 | if (scheme.equals("file")) { |
---|
| 104 | Toast.makeText(getApplicationContext(), "file: "+data.getPath(), Toast.LENGTH_SHORT).show(); |
---|
| 105 | pdfToVerify = data.getPath(); |
---|
| 106 | } |
---|
| 107 | }else{ |
---|
| 108 | // obtener el archivo pdf a verificar |
---|
| 109 | Bundle bundle = getIntent().getExtras(); |
---|
| 110 | pdfToVerify = bundle.getString("pdfToVerify"); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | |
---|
[e68708b] | 114 | TextView pdfName = (TextView) this.findViewById(R.id.filename_text); |
---|
| 115 | pdfName.setText(pdfToVerify); |
---|
| 116 | |
---|
| 117 | // ejecutar el proceso de verificacion del pdf |
---|
| 118 | doVerification(pdfToVerify); |
---|
| 119 | |
---|
[42e7061] | 120 | LinearLayout layoutPdfFileResult = (LinearLayout) this.findViewById(R.id.layout_pdf_signed_result); |
---|
| 121 | |
---|
| 122 | OnClickListener pdfFileListener = new OnClickListener() { |
---|
| 123 | public void onClick(View v) { |
---|
| 124 | |
---|
| 125 | //Toast.makeText(getApplicationContext(), "**CLICK SOBRE EL archivo***", Toast.LENGTH_LONG).show(); |
---|
| 126 | |
---|
| 127 | openIt(pdfToVerify, getMimeType(pdfToVerify)); |
---|
| 128 | } |
---|
| 129 | }; |
---|
| 130 | layoutPdfFileResult.setOnClickListener(pdfFileListener); |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | |
---|
[e68708b] | 134 | // habilitar opciones de botones inferiores |
---|
| 135 | button_share = (LinearLayout) this.findViewById(R.id.button_remove_certificate_zone); |
---|
| 136 | button_finish = (LinearLayout) this.findViewById(R.id.button_add_certificate_zone); |
---|
| 137 | |
---|
| 138 | // habilita el click sobre la acción de finalizar la verificacion de firma y regresar |
---|
| 139 | button_finish.setOnClickListener(new OnClickListener() |
---|
| 140 | { |
---|
| 141 | public void onClick(View v) |
---|
| 142 | { |
---|
| 143 | |
---|
| 144 | Intent oIntent = new Intent(PDFVerifyResultActivity.this, TibisayMovilActivity.class); |
---|
| 145 | oIntent.setAction(Intent.ACTION_VIEW); |
---|
| 146 | oIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
---|
| 147 | startActivity(oIntent); |
---|
| 148 | |
---|
| 149 | finish(); |
---|
| 150 | } |
---|
| 151 | }); |
---|
| 152 | |
---|
| 153 | // habilita el click sobre la acción de compartir el archivo |
---|
| 154 | button_share.setOnClickListener(new OnClickListener() |
---|
| 155 | { |
---|
| 156 | public void onClick(View v) |
---|
| 157 | { |
---|
| 158 | shareIt(); |
---|
| 159 | } |
---|
| 160 | }); |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | } // fin de onCreate |
---|
| 165 | |
---|
| 166 | |
---|
| 167 | /** |
---|
| 168 | * Ejecuta la verificacion de la firma del pdf utilizando la biblioteca droidtext |
---|
| 169 | * |
---|
| 170 | * */ |
---|
| 171 | private void doVerification(String pdfToVerify) { |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | try { |
---|
| 175 | |
---|
| 176 | Random rnd = new Random(); |
---|
| 177 | |
---|
| 178 | PdfReader reader = new PdfReader(pdfToVerify); |
---|
| 179 | Log.d("VerificadorPDF", "new PdfReader"); |
---|
| 180 | |
---|
| 181 | AcroFields af = reader.getAcroFields(); |
---|
| 182 | Log.d("VerificadorPDF", "reader.getAcroFields()"); |
---|
| 183 | |
---|
| 184 | ArrayList names = af.getSignatureNames(); |
---|
| 185 | Log.d("VerificadorPDF", "af.getSignatureNames()"); |
---|
| 186 | |
---|
[ba6bc7c] | 187 | //Toast.makeText(getApplicationContext(), "names.size: "+ Integer.toString(names.size()), Toast.LENGTH_SHORT).show(); |
---|
[e68708b] | 188 | Log.d("VerificadorPDF", Integer.toString(names.size())); |
---|
| 189 | |
---|
| 190 | if (names.size() == 0) { |
---|
| 191 | // el archivo no posee firmas |
---|
| 192 | TextView signatureMessage = (TextView) this.findViewById(R.id.archivo_original_a_descifrar); |
---|
| 193 | signatureMessage.setText("El documento PDF no está firmado electrónicamente."); |
---|
| 194 | |
---|
| 195 | TextView labelSignature = (TextView) this.findViewById(R.id.label_archivo_original); |
---|
| 196 | labelSignature.setText("Documento:"); |
---|
| 197 | |
---|
| 198 | TextView labelSigners = (TextView) this.findViewById(R.id.label_destinatario_cifrado); |
---|
| 199 | labelSigners.setVisibility(View.GONE); |
---|
| 200 | |
---|
| 201 | ListView listViewSigners = (ListView) this.findViewById(R.id.signatures_list); |
---|
| 202 | listViewSigners.setVisibility(View.GONE); |
---|
| 203 | return; |
---|
| 204 | }else{ |
---|
| 205 | // el documento si posee firmas |
---|
| 206 | //KeyStore kall = PdfPKCS7.loadCacertsKeyStore(); |
---|
| 207 | |
---|
| 208 | // crear certificate factory |
---|
| 209 | CertificateFactory cf = CertificateFactory.getInstance("X.509"); |
---|
| 210 | |
---|
| 211 | // crear un KeyStore |
---|
| 212 | String keyStoreType = KeyStore.getDefaultType(); |
---|
| 213 | KeyStore kall = KeyStore.getInstance(keyStoreType); |
---|
| 214 | kall.load(null, null); |
---|
| 215 | |
---|
| 216 | // obtener vector de campos de /res/raw |
---|
| 217 | Field[] fields = R.raw.class.getFields(); |
---|
| 218 | |
---|
| 219 | InputStream caInput = null; |
---|
| 220 | |
---|
| 221 | // iterar sobre todos los certificados incluidos en /res/raw y cargarlos |
---|
| 222 | // en el KeyStore |
---|
| 223 | for (int l=0; l < fields.length; l++) { |
---|
| 224 | try { |
---|
[42e7061] | 225 | //Toast.makeText(getApplicationContext(), "PDFVerifyResultActivity - reading certificate: "+Integer.toString(l)+ " "+ |
---|
| 226 | // Integer.toString(fields[l].getInt(null)), Toast.LENGTH_SHORT).show(); |
---|
[e68708b] | 227 | |
---|
| 228 | caInput = new BufferedInputStream(getResources().openRawResource(fields[l].getInt(null))); |
---|
| 229 | |
---|
| 230 | } catch (IllegalArgumentException e) { |
---|
| 231 | |
---|
| 232 | Toast.makeText(getApplicationContext(), "PDFVerifyResultActivity: IllegalArgumentException "+e.getMessage(), |
---|
| 233 | Toast.LENGTH_SHORT).show(); |
---|
| 234 | break; |
---|
| 235 | } catch (IllegalAccessException e) { |
---|
| 236 | |
---|
| 237 | Toast.makeText(getApplicationContext(), "PDFVerifyResultActivity: IllegalAccessException "+e.getMessage(), |
---|
| 238 | Toast.LENGTH_SHORT).show(); |
---|
| 239 | break; |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | Certificate ca; |
---|
| 243 | try { |
---|
| 244 | ca = cf.generateCertificate(caInput); |
---|
| 245 | //Log.d("**ca:", ((X509Certificate) ca).getSubjectDN()); |
---|
| 246 | |
---|
| 247 | //Log.d("*** try: ca.toString()", ca.toString()); |
---|
| 248 | } finally { |
---|
| 249 | caInput.close(); |
---|
| 250 | } |
---|
| 251 | kall.setCertificateEntry("ca"+Integer.toString(l), ca); |
---|
| 252 | }// fin de la iteracion sobre /res/raw |
---|
| 253 | |
---|
| 254 | |
---|
| 255 | // se crea el adaptador para mostrar los firmantes del contenedor |
---|
| 256 | ListView signerListView = (ListView) findViewById(R.id.signatures_list); |
---|
| 257 | final ArrayList<SignerFromPDF> signers = new ArrayList<SignerFromPDF>(); |
---|
| 258 | |
---|
| 259 | boolean invalidSignature = false; |
---|
| 260 | |
---|
| 261 | for (int i = 0; i < names.size(); i++){ |
---|
| 262 | |
---|
| 263 | String name = (String)names.get(i); |
---|
| 264 | PdfPKCS7 pk = af.verifySignature(name); |
---|
| 265 | Calendar cal = pk.getSignDate(); |
---|
| 266 | Certificate pkc[] = pk.getCertificates(); |
---|
| 267 | |
---|
| 268 | X509Certificate cert = (X509Certificate) pk.getSigningCertificate(); |
---|
| 269 | |
---|
| 270 | String cn = cert.getSubjectDN().toString(); |
---|
| 271 | String signerName = ConvertUtils.getCommonName(cn); |
---|
| 272 | |
---|
| 273 | SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS"); |
---|
| 274 | String date = date_format.format(pk.getSignDate().getTime()); |
---|
| 275 | |
---|
| 276 | String certificateSerial = cert.getSerialNumber().toString(); |
---|
| 277 | String validFrom = cert.getNotBefore().toString(); |
---|
| 278 | String validUntil = cert.getNotAfter().toString(); |
---|
| 279 | String certificateIssuer = cert.getIssuerDN().toString(); |
---|
| 280 | |
---|
| 281 | Object fails[] = PdfPKCS7.verifyCertificates(pkc, kall, null, cal); |
---|
| 282 | if (fails == null) { |
---|
| 283 | System.out.print(pk.getSignName()); |
---|
| 284 | Toast.makeText(getApplicationContext(), "Firma Válida", Toast.LENGTH_SHORT).show(); |
---|
| 285 | } |
---|
| 286 | else { |
---|
| 287 | System.out.print("Firma no válida"); |
---|
| 288 | Toast.makeText(getApplicationContext(), "Firma NO Válida", Toast.LENGTH_SHORT).show(); |
---|
| 289 | |
---|
| 290 | invalidSignature = true; |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | // agregar el nombre comun del firmante y la fecha y la hora |
---|
| 294 | signers.add(new SignerFromPDF(signerName, cn, date, certificateSerial, validFrom, validUntil, certificateIssuer)); |
---|
| 295 | |
---|
| 296 | TextView signatureValidation = (TextView) this.findViewById(R.id.archivo_original_a_descifrar); |
---|
| 297 | |
---|
| 298 | if (invalidSignature){ |
---|
| 299 | signatureValidation.setText("Firma Inválida"); |
---|
| 300 | }else{ |
---|
| 301 | signatureValidation.setText("Firma Válida"); |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | SignerFromPDFAdapter signerAdapter = new SignerFromPDFAdapter(PDFVerifyResultActivity.this, signers); |
---|
| 308 | signerListView.setAdapter(signerAdapter); |
---|
| 309 | signerListView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { |
---|
| 310 | |
---|
| 311 | |
---|
| 312 | @Override |
---|
| 313 | public void onItemClick(AdapterView<?> parent, View view, |
---|
| 314 | int position, long id) { |
---|
| 315 | |
---|
[ba6bc7c] | 316 | //Toast.makeText(getApplicationContext(), "SE DEBE MOSTRAR INFORMACIÓN DEL FIRMANTE", Toast.LENGTH_SHORT).show(); |
---|
[e68708b] | 317 | showSignatureDetails(position, signers); |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | }); |
---|
| 321 | |
---|
| 322 | |
---|
| 323 | |
---|
| 324 | } // fin de else: el documento posee firmas |
---|
| 325 | |
---|
| 326 | |
---|
| 327 | }catch(Exception e){ |
---|
| 328 | Toast.makeText(getApplicationContext(), "Error al verificar pdf:"+e.getMessage(), Toast.LENGTH_LONG).show(); |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | |
---|
| 334 | // funcion para compartir el documento |
---|
| 335 | private void shareIt() { |
---|
| 336 | |
---|
| 337 | Intent shareIntent = new Intent(); |
---|
| 338 | shareIntent.setAction(Intent.ACTION_SEND); |
---|
| 339 | File file = new File(pdfToVerify); |
---|
| 340 | |
---|
| 341 | |
---|
| 342 | Uri uri = Uri.fromFile(file); |
---|
| 343 | Log.i("DEBUG", file.getPath()); |
---|
| 344 | //Log.d("******", getMimeType(file.getPath())); |
---|
| 345 | //shareIntent.setDataAndType(uri, getMimeType(file.getPath())); |
---|
| 346 | shareIntent.putExtra(Intent.EXTRA_STREAM, uri); |
---|
| 347 | shareIntent.setType("application/*"); |
---|
| 348 | startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share_it_using))); |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | |
---|
| 352 | // class que abstrae un firmante incluido en un contenedor BDOC |
---|
| 353 | private class SignerFromPDF { |
---|
| 354 | |
---|
| 355 | // nombre del firmante |
---|
| 356 | private String mName; |
---|
| 357 | |
---|
| 358 | // nombre comun del firmante |
---|
| 359 | private String mCN; |
---|
| 360 | |
---|
| 361 | // fecha y hora de la firma |
---|
| 362 | private String mDate; |
---|
| 363 | |
---|
| 364 | // serial del certificado |
---|
| 365 | private String mCertificateSerial; |
---|
| 366 | |
---|
| 367 | // fecha de validez inicial |
---|
| 368 | private String mValidFrom; |
---|
| 369 | |
---|
| 370 | // fecha de validez final |
---|
| 371 | private String mValidUntil; |
---|
| 372 | |
---|
| 373 | // emisor del certificado |
---|
| 374 | private String mCertificateIssuer; |
---|
| 375 | |
---|
| 376 | public SignerFromPDF(String name, String cn, String date, String serial, String validFrom, String validUntil, String issuer){ |
---|
| 377 | mName = name; |
---|
| 378 | mCN = cn; |
---|
| 379 | mDate = date; |
---|
| 380 | mCertificateSerial = serial; |
---|
| 381 | mValidFrom = validFrom; |
---|
| 382 | mValidUntil = validUntil; |
---|
| 383 | mCertificateIssuer = issuer; |
---|
| 384 | } |
---|
| 385 | |
---|
| 386 | public void setName(String name) { |
---|
| 387 | this.mName = name; |
---|
| 388 | } |
---|
| 389 | |
---|
| 390 | public String getName() { |
---|
| 391 | return mName; |
---|
| 392 | } |
---|
| 393 | |
---|
| 394 | public void setCN(String cn) { |
---|
| 395 | this.mCN = cn; |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | public String getCN() { |
---|
| 399 | return mCN; |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | public void setDate(String date) { |
---|
| 403 | this.mDate = date; |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | public String getDate() { |
---|
| 407 | return mDate; |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | public void setCertificateSerial(String certSerial) { |
---|
| 411 | this.mCertificateSerial = certSerial; |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | public String getCertificateSerial() { |
---|
| 415 | return mCertificateSerial; |
---|
| 416 | } |
---|
| 417 | |
---|
| 418 | public void setValidFrom(String validFrom) { |
---|
| 419 | this.mValidFrom = validFrom; |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | public String getValidFrom() { |
---|
| 423 | return mValidFrom; |
---|
| 424 | } |
---|
| 425 | |
---|
| 426 | public void setValidUntil(String validUntil) { |
---|
| 427 | this.mValidUntil = validUntil; |
---|
| 428 | } |
---|
| 429 | |
---|
| 430 | public String getValidUntil() { |
---|
| 431 | return mValidUntil; |
---|
| 432 | } |
---|
| 433 | |
---|
| 434 | public void setCertificateIssuer(String certIssuer) { |
---|
| 435 | this.mCertificateIssuer = certIssuer; |
---|
| 436 | } |
---|
| 437 | |
---|
| 438 | public String getCertificateIssuer() { |
---|
| 439 | return mCertificateIssuer; |
---|
| 440 | } |
---|
| 441 | |
---|
| 442 | } // fin de clase SignerFromPDF |
---|
| 443 | |
---|
| 444 | // clase que abstrae el adaptador para llenar el ListView de documentos que |
---|
| 445 | // se encuentran dentro del contenedor BDOC |
---|
| 446 | private class SignerFromPDFAdapter extends BaseAdapter { |
---|
| 447 | |
---|
| 448 | private ArrayList<SignerFromPDF> mSignerFromPDFList; |
---|
| 449 | private LayoutInflater lInflater; |
---|
| 450 | |
---|
| 451 | private SignerFromPDFAdapter(Context context, ArrayList<SignerFromPDF> signers) { |
---|
| 452 | this.lInflater = LayoutInflater.from(context); |
---|
| 453 | this.mSignerFromPDFList = signers; |
---|
| 454 | |
---|
| 455 | } |
---|
| 456 | |
---|
| 457 | |
---|
| 458 | @Override |
---|
| 459 | public int getCount() { |
---|
| 460 | return mSignerFromPDFList.size(); |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | @Override |
---|
| 464 | public Object getItem(int position) { |
---|
| 465 | return mSignerFromPDFList.get(position); |
---|
| 466 | } |
---|
| 467 | |
---|
| 468 | @Override |
---|
| 469 | public long getItemId(int position) { |
---|
| 470 | return position; |
---|
| 471 | } |
---|
| 472 | |
---|
| 473 | @Override |
---|
| 474 | public View getView(int position, View convertView, ViewGroup parent) { |
---|
| 475 | ViewHolder container = null; |
---|
| 476 | |
---|
| 477 | if (convertView == null){ |
---|
| 478 | container = new ViewHolder(); |
---|
| 479 | convertView = lInflater.inflate(R.layout.signer_inside_bdoc_item, null); |
---|
| 480 | |
---|
| 481 | container.signer_text = (TextView) convertView.findViewById(R.id.signer_info); |
---|
| 482 | container.signer_modified = (TextView) convertView.findViewById(R.id.signature_errors); |
---|
| 483 | container.type_image = (ImageView) convertView.findViewById(R.id.type_image); |
---|
| 484 | convertView.setTag(container); |
---|
| 485 | }else{ |
---|
| 486 | container = (ViewHolder) convertView.getTag(); |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | SignerFromPDF doc = (SignerFromPDF) getItem(position); |
---|
| 490 | container.signer_text.setText(doc.getName()); |
---|
| 491 | container.signer_modified.setText(doc.getName()); |
---|
[58c7f6a] | 492 | container.type_image.setImageResource(R.drawable.ic_firmar_verde); |
---|
[e68708b] | 493 | |
---|
| 494 | return convertView; |
---|
| 495 | } |
---|
| 496 | |
---|
| 497 | |
---|
| 498 | class ViewHolder{ |
---|
| 499 | TextView signer_text; |
---|
| 500 | TextView signer_modified; |
---|
| 501 | ImageView type_image; |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | } |
---|
| 505 | |
---|
| 506 | /** |
---|
| 507 | * Lanza la actividad para mostrar detalles de un firmante |
---|
| 508 | * |
---|
| 509 | * */ |
---|
| 510 | private void showSignatureDetails(int position, ArrayList<SignerFromPDF> signers) { |
---|
| 511 | |
---|
| 512 | Log.d("**showSignatureDetails", Integer.toString(position)); |
---|
| 513 | Log.d("** nombre", signers.get(position).getName()); |
---|
| 514 | Intent intent = new Intent(this, ActivitySignerInfo.class); |
---|
| 515 | |
---|
| 516 | intent.putExtra("name", signers.get(position).getName()); |
---|
| 517 | intent.putExtra("cn", signers.get(position).getCN()); |
---|
| 518 | intent.putExtra("date", signers.get(position).getDate()); |
---|
| 519 | intent.putExtra("certificateSerial", signers.get(position).getCertificateSerial()); |
---|
| 520 | intent.putExtra("validFrom", signers.get(position).getValidFrom()); |
---|
| 521 | intent.putExtra("validUntil", signers.get(position).getValidUntil()); |
---|
| 522 | intent.putExtra("certificateIssuer", signers.get(position).getCertificateIssuer()); |
---|
| 523 | startActivity(intent); |
---|
| 524 | } |
---|
| 525 | |
---|
[42e7061] | 526 | // funcion para obtener el tipo mime de un archivo |
---|
| 527 | public static String getMimeType(String url) |
---|
| 528 | { |
---|
| 529 | String extension = url.substring(url.lastIndexOf(".")); |
---|
| 530 | String mimeTypeMap = MimeTypeMap.getFileExtensionFromUrl(extension); |
---|
| 531 | String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(mimeTypeMap); |
---|
| 532 | return mimeType; |
---|
| 533 | } |
---|
| 534 | |
---|
| 535 | |
---|
| 536 | // funcion para lanzar un intent que abra un archivo |
---|
| 537 | private void openIt(String pdfFile, String mimeType) { |
---|
| 538 | |
---|
| 539 | Intent shareIntent = new Intent(); |
---|
| 540 | shareIntent.setAction(Intent.ACTION_VIEW); |
---|
| 541 | File file = new File(pdfFile); |
---|
| 542 | Uri uri = Uri.fromFile(file); |
---|
| 543 | Log.i("DEBUG", file.getPath()); |
---|
| 544 | shareIntent.setDataAndType(uri, mimeType); |
---|
| 545 | startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.open_it_using))); |
---|
| 546 | } |
---|
[e68708b] | 547 | |
---|
| 548 | } |
---|