[5147e01] | 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(); |
---|
[064d990] | 89 | |
---|
[5147e01] | 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 | |
---|
[824553a] | 149 | // TextView para colocar el resultado de la firma |
---|
| 150 | TextView signatureVerificationResult = (TextView) findViewById(R.id.archivo_para_firmar_path); |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | // array de excepciones lanzadas al verificar firmas |
---|
| 154 | ArrayList arraySignaturesErrors = null; |
---|
| 155 | |
---|
| 156 | // array de strings para almanecenar los errores de firmas |
---|
| 157 | ArrayList<String> signatureVerificationErrors = new ArrayList<String>(); |
---|
| 158 | |
---|
| 159 | // verificar cada una de las firmas del contenedor |
---|
| 160 | for (int i = 0; i < sdoc.countSignatures(); i++){ |
---|
| 161 | Signature tmpSignature = sdoc.getSignature(i); |
---|
| 162 | arraySignaturesErrors = new ArrayList(); |
---|
| 163 | arraySignaturesErrors = tmpSignature.verify(sdoc, false, false); |
---|
| 164 | Log.d("****i:"+i,"arraySignaturesErrors.size: "+ arraySignaturesErrors.size()); |
---|
| 165 | |
---|
| 166 | for (int j = 0; j < arraySignaturesErrors.size(); j++){ |
---|
| 167 | |
---|
| 168 | signatureVerificationErrors.add("Firma "+Integer.toString(i+1)+ ": "+ |
---|
| 169 | arraySignaturesErrors.get(j).toString() + "\n"); |
---|
| 170 | |
---|
| 171 | Log.d("****signatureVerificationErrors", |
---|
| 172 | "Firma "+Integer.toString(i+1)+ ": "+ |
---|
| 173 | arraySignaturesErrors.get(j).toString() + "\n"); |
---|
| 174 | Log.d("signatureVerificationErrors: ", signatureVerificationErrors.get(j).toString()); |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | //signatureVerificationErrors = "Firma "+Integer.toString(i+1)+ ": "+ |
---|
| 178 | //arraySignaturesErrors.get(i).toString() + "\n"; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | if (arraySignaturesErrors.isEmpty()) { |
---|
| 182 | signatureVerificationResult.setText("Firma Válida"); |
---|
| 183 | Log.d("signature.verify", "NO HUBO ERROR EN LA VERIFICACION DE FIRMA"); |
---|
| 184 | Toast.makeText(getApplicationContext(), "¡FIRMA CORRECTA!", Toast.LENGTH_SHORT).show(); |
---|
| 185 | |
---|
| 186 | }else{ |
---|
| 187 | String finalErrors = ""; |
---|
| 188 | for (int i = 0; i < signatureVerificationErrors.size(); i++ ) { |
---|
| 189 | finalErrors = finalErrors.concat(signatureVerificationErrors.get(i).toString()); |
---|
| 190 | //resultAndErrors = resultAndErrors.concat("Firma: "+i+" "+sigError.get(i).toString()+"\n"); |
---|
| 191 | } |
---|
| 192 | signatureVerificationResult.setText("Firma Inválida\n"+finalErrors); |
---|
| 193 | Log.d("************", "SI HUBO ERROR"); |
---|
| 194 | Log.d("************", finalErrors); |
---|
| 195 | |
---|
| 196 | Toast.makeText(getApplicationContext(), "ERROR DE VERIFICACION DE FIRMA", Toast.LENGTH_SHORT).show(); |
---|
| 197 | } |
---|
| 198 | |
---|
[5147e01] | 199 | |
---|
| 200 | //ArrayList sigError = signature.verify(sdoc, false, false); |
---|
[824553a] | 201 | //ArrayList sigError = sdoc.verify(false, false); |
---|
[5147e01] | 202 | |
---|
| 203 | // se crea el adaptador para mostrar los documentos firmados |
---|
| 204 | ListView documentListView = (ListView) findViewById(R.id.documents_list); |
---|
| 205 | final ArrayList<DocumentFromBDOC> docs = new ArrayList<DocumentFromBDOC>(); |
---|
| 206 | |
---|
| 207 | // Crear directorio ExtractedFiles donde se almacenan los archivos extraidos |
---|
| 208 | // de los contenedores BDOC |
---|
| 209 | extractedDirFiles = Environment.getExternalStorageDirectory() + "/" + |
---|
| 210 | getResources().getString(R.string.app_name) + "/" + |
---|
| 211 | getResources().getString(R.string.extracted_dir_files) + "/"; |
---|
| 212 | prepareDirectory(); |
---|
| 213 | |
---|
| 214 | for (int i = 0; i < sdoc.countDataFiles(); i++){ |
---|
| 215 | // obtener el DataFile |
---|
| 216 | DataFile df = sdoc.getDataFile(i); |
---|
| 217 | docs.add(new DocumentFromBDOC(df.getFileName())); |
---|
| 218 | Log.d("MIMETYPE:", df.getMimeType()); |
---|
| 219 | // Extraer el archivo y guardarlo en /mnt/sdcard/TibisayMovil/ExtractedFiles |
---|
| 220 | FileOutputStream fos = new FileOutputStream(extractedDirFiles+df.getFileName()); |
---|
| 221 | InputStream is = df.getBodyAsStream(); |
---|
| 222 | if(is == null) { |
---|
| 223 | Log.d("ERROR al extrarer archivo", "DataFile has no data!"); |
---|
| 224 | //return false; |
---|
| 225 | } |
---|
| 226 | byte[] data = new byte[4096]; |
---|
| 227 | int n = 0, m = 0; |
---|
| 228 | while((n = is.read(data)) > 0) { |
---|
| 229 | fos.write(data, 0, n); |
---|
| 230 | m += n; |
---|
| 231 | } |
---|
| 232 | fos.close(); |
---|
| 233 | is.close(); |
---|
| 234 | } |
---|
| 235 | |
---|
| 236 | DocumentFromBDOCAdapter documentAdapter = new DocumentFromBDOCAdapter(BDOCVerifyResultActivity.this, docs); |
---|
| 237 | documentListView.setAdapter(documentAdapter); |
---|
| 238 | documentListView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { |
---|
| 239 | |
---|
| 240 | @Override |
---|
| 241 | public void onItemClick(AdapterView<?> parent, View view, |
---|
| 242 | int position, long id) { |
---|
| 243 | String absolutePathToOpen = extractedDirFiles + docs.get(position).getName(); |
---|
| 244 | Toast.makeText(getApplicationContext(), getMimeType(absolutePathToOpen), Toast.LENGTH_SHORT).show(); |
---|
| 245 | openIt(absolutePathToOpen, getMimeType(absolutePathToOpen)); |
---|
| 246 | |
---|
| 247 | |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | }); |
---|
| 251 | |
---|
| 252 | // se crea el adaptador para mostrar los firmantes del contenedor |
---|
| 253 | ListView signerListView = (ListView) findViewById(R.id.signatures_list); |
---|
[064d990] | 254 | final ArrayList<SignerFromBDOC> signers = new ArrayList<SignerFromBDOC>(); |
---|
[5147e01] | 255 | |
---|
| 256 | for (int i = 0; i < sdoc.countSignatures(); i++){ |
---|
| 257 | Signature signatureTemp = sdoc.getSignature(i); |
---|
[064d990] | 258 | //signers.add(new SignerFromBDOC(signatureTemp.getSubject())); |
---|
| 259 | |
---|
| 260 | String cn = SignedDoc.getCommonName( |
---|
| 261 | sdoc.getSignature(i).getKeyInfo().getSignersCertificate().getSubjectDN().getName()); |
---|
| 262 | String name = sdoc.getSignature(i).getKeyInfo().getSubjectLastName(); |
---|
| 263 | String date = sdoc.getSignature(i).getSignedProperties().getSigningTime().toString(); |
---|
| 264 | String certificateSerial = sdoc.getSignature(i).getKeyInfo().getSignersCertificate().getSerialNumber().toString(); |
---|
| 265 | String validFrom = sdoc.getSignature(i).getKeyInfo().getSignersCertificate().getNotBefore().toLocaleString(); |
---|
| 266 | String validUntil = sdoc.getSignature(i).getKeyInfo().getSignersCertificate().getNotAfter().toLocaleString(); |
---|
| 267 | String certificateIssuer = sdoc.getSignature(i).getKeyInfo().getSignersCertificate().getIssuerX500Principal().toString(); |
---|
| 268 | |
---|
| 269 | // agregar el nombre comun del firmante y la fecha y la hora |
---|
| 270 | signers.add(new SignerFromBDOC(name, cn, date, certificateSerial, validFrom, validUntil, certificateIssuer)); |
---|
| 271 | |
---|
[5147e01] | 272 | } |
---|
| 273 | SignerFromBDOCAdapter signerAdapter = new SignerFromBDOCAdapter(BDOCVerifyResultActivity.this, signers); |
---|
| 274 | signerListView.setAdapter(signerAdapter); |
---|
| 275 | signerListView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { |
---|
| 276 | |
---|
| 277 | String ss = "hola mundo"; |
---|
| 278 | @Override |
---|
| 279 | public void onItemClick(AdapterView<?> parent, View view, |
---|
| 280 | int position, long id) { |
---|
| 281 | |
---|
| 282 | //String signer = parent.getItemAtPosition(position).toString(); |
---|
| 283 | |
---|
| 284 | Toast.makeText(getApplicationContext(), "SE DEBE MOSTRAR INFORMACIÓN DEL FIRMANTE", Toast.LENGTH_SHORT).show(); |
---|
[064d990] | 285 | showSignatureDetails(position, signers); |
---|
[5147e01] | 286 | } |
---|
| 287 | |
---|
| 288 | }); |
---|
| 289 | |
---|
| 290 | |
---|
[824553a] | 291 | /* |
---|
[5147e01] | 292 | if(sigError.isEmpty()){ |
---|
| 293 | Log.d("signature.verify", "NO HUBO ERROR EN LA VERIFICACION DE FIRMA"); |
---|
| 294 | String res = "Numero de firmas: " + Integer.toString(sdoc.countSignatures()) + |
---|
| 295 | " Numero de documentos: " + Integer.toString(sdoc.countDataFiles()) + |
---|
| 296 | " Perfil de firma: " + signature.getProfile() + |
---|
| 297 | " Sujeto: " + signature.getSubject() + |
---|
| 298 | " Hora: " + signature.getSignedProperties().getSigningTime().toString(); |
---|
| 299 | Log.d("-->: ", res); |
---|
| 300 | |
---|
[824553a] | 301 | //result.setText("Firma válida"); |
---|
[5147e01] | 302 | |
---|
| 303 | }else{ |
---|
| 304 | Log.d("signature.verify", "SI HUBO ERROR"); |
---|
| 305 | Log.d("signature.verify", Integer.toString(sigError.size())); |
---|
| 306 | |
---|
| 307 | String resultAndErrors = "Firma Inválida\n"; |
---|
| 308 | |
---|
| 309 | for (int i=0; i<sigError.size(); i++ ){ |
---|
| 310 | Log.d("signature.verify", sigError.get(i).toString()); |
---|
| 311 | //resultAndErrors.concat(sigError.get(i).toString()+"\n"); |
---|
[824553a] | 312 | resultAndErrors = resultAndErrors.concat("Firma: "+i+" "+sigError.get(i).toString()+"\n"); |
---|
[5147e01] | 313 | |
---|
| 314 | //Toast.makeText(getApplicationContext(), sigError.get(i).toString(), Toast.LENGTH_SHORT).show(); |
---|
| 315 | } |
---|
| 316 | Toast.makeText(getApplicationContext(), "ERROR DE VERIFICACION DE FIRMA", Toast.LENGTH_SHORT).show(); |
---|
| 317 | //result.setText("Firma inválida"); |
---|
[824553a] | 318 | //result.setText(resultAndErrors); |
---|
[5147e01] | 319 | } |
---|
[824553a] | 320 | */ |
---|
[5147e01] | 321 | |
---|
| 322 | |
---|
| 323 | } catch (Exception e) { |
---|
| 324 | // TODO Auto-generated catch block |
---|
| 325 | |
---|
| 326 | //showOneButtonDialog(e.getMessage()); |
---|
| 327 | |
---|
| 328 | Log.d("****exception:", e.getMessage()); |
---|
| 329 | e.printStackTrace(); |
---|
| 330 | } |
---|
| 331 | |
---|
| 332 | } // fin de doVerification(String f) |
---|
| 333 | |
---|
| 334 | |
---|
| 335 | |
---|
| 336 | |
---|
| 337 | |
---|
| 338 | |
---|
| 339 | |
---|
| 340 | |
---|
| 341 | |
---|
| 342 | |
---|
| 343 | // clase que abstrae un documento incluido dentro de un contenedor BDOC |
---|
| 344 | public class DocumentFromBDOC { |
---|
| 345 | private String mName; |
---|
| 346 | |
---|
| 347 | public DocumentFromBDOC(String name){ |
---|
| 348 | mName = name; |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | public void setName(String name) { |
---|
| 352 | this.mName = name; |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | public String getName() { |
---|
| 356 | return mName; |
---|
| 357 | } |
---|
| 358 | } // fin de clase DocumentFromBDOC |
---|
| 359 | |
---|
| 360 | // clase que abstrae el adaptador para llenar el ListView de documentos que |
---|
| 361 | // se encuentran dentro del contenedor BDOC |
---|
| 362 | private class DocumentFromBDOCAdapter extends BaseAdapter { |
---|
| 363 | |
---|
| 364 | private ArrayList<DocumentFromBDOC> mDocumentFromBDOCList; |
---|
| 365 | private LayoutInflater lInflater; |
---|
| 366 | |
---|
| 367 | private DocumentFromBDOCAdapter(Context context, ArrayList<DocumentFromBDOC> documents) { |
---|
| 368 | this.lInflater = LayoutInflater.from(context); |
---|
| 369 | this.mDocumentFromBDOCList = documents; |
---|
| 370 | |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | |
---|
| 374 | @Override |
---|
| 375 | public int getCount() { |
---|
| 376 | return mDocumentFromBDOCList.size(); |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | @Override |
---|
| 380 | public Object getItem(int position) { |
---|
| 381 | return mDocumentFromBDOCList.get(position); |
---|
| 382 | } |
---|
| 383 | |
---|
| 384 | @Override |
---|
| 385 | public long getItemId(int position) { |
---|
| 386 | return position; |
---|
| 387 | } |
---|
| 388 | |
---|
| 389 | @Override |
---|
| 390 | public View getView(int position, View convertView, ViewGroup parent) { |
---|
| 391 | ViewHolder container = null; |
---|
| 392 | |
---|
| 393 | if (convertView == null){ |
---|
| 394 | container = new ViewHolder(); |
---|
| 395 | convertView = lInflater.inflate(R.layout.document_inside_bdoc_item, null); |
---|
| 396 | |
---|
| 397 | container.filename_text = (TextView) convertView.findViewById(R.id.filename_text); |
---|
| 398 | container.filename_modified = (TextView) convertView.findViewById(R.id.filename_modified); |
---|
| 399 | container.type_image = (ImageView) convertView.findViewById(R.id.type_image); |
---|
| 400 | convertView.setTag(container); |
---|
| 401 | }else{ |
---|
| 402 | container = (ViewHolder) convertView.getTag(); |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | DocumentFromBDOC doc = (DocumentFromBDOC) getItem(position); |
---|
| 406 | container.filename_text.setText(doc.getName()); |
---|
| 407 | container.filename_modified.setText(doc.getName()); |
---|
| 408 | container.type_image.setImageResource(R.drawable.ic_archivo); |
---|
| 409 | |
---|
| 410 | return convertView; |
---|
| 411 | } |
---|
| 412 | |
---|
| 413 | |
---|
| 414 | class ViewHolder{ |
---|
| 415 | TextView filename_text; |
---|
| 416 | TextView filename_modified; |
---|
| 417 | ImageView type_image; |
---|
| 418 | } |
---|
| 419 | |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | |
---|
| 423 | // class que abstrae un firmante incluido en un contenedor BDOC |
---|
| 424 | private class SignerFromBDOC { |
---|
[064d990] | 425 | |
---|
| 426 | // nombre del firmante |
---|
[5147e01] | 427 | private String mName; |
---|
| 428 | |
---|
[064d990] | 429 | // nombre comun del firmante |
---|
| 430 | private String mCN; |
---|
| 431 | |
---|
| 432 | // fecha y hora de la firma |
---|
| 433 | private String mDate; |
---|
| 434 | |
---|
| 435 | // serial del certificado |
---|
| 436 | private String mCertificateSerial; |
---|
| 437 | |
---|
| 438 | // fecha de validez inicial |
---|
| 439 | private String mValidFrom; |
---|
| 440 | |
---|
| 441 | // fecha de validez final |
---|
| 442 | private String mValidUntil; |
---|
| 443 | |
---|
| 444 | // emisor del certificado |
---|
| 445 | private String mCertificateIssuer; |
---|
| 446 | |
---|
| 447 | public SignerFromBDOC(String name, String cn, String date, String serial, String validFrom, String validUntil, String issuer){ |
---|
[5147e01] | 448 | mName = name; |
---|
[064d990] | 449 | mCN = cn; |
---|
| 450 | mDate = date; |
---|
| 451 | mCertificateSerial = serial; |
---|
| 452 | mValidFrom = validFrom; |
---|
| 453 | mValidUntil = validUntil; |
---|
| 454 | mCertificateIssuer = issuer; |
---|
[5147e01] | 455 | } |
---|
| 456 | |
---|
| 457 | public void setName(String name) { |
---|
| 458 | this.mName = name; |
---|
| 459 | } |
---|
| 460 | |
---|
| 461 | public String getName() { |
---|
| 462 | return mName; |
---|
| 463 | } |
---|
[064d990] | 464 | |
---|
| 465 | public void setCN(String cn) { |
---|
| 466 | this.mCN = cn; |
---|
| 467 | } |
---|
| 468 | |
---|
| 469 | public String getCN() { |
---|
| 470 | return mCN; |
---|
| 471 | } |
---|
| 472 | |
---|
| 473 | public void setDate(String date) { |
---|
| 474 | this.mDate = date; |
---|
| 475 | } |
---|
| 476 | |
---|
| 477 | public String getDate() { |
---|
| 478 | return mDate; |
---|
| 479 | } |
---|
| 480 | |
---|
| 481 | public void setCertificateSerial(String certSerial) { |
---|
| 482 | this.mCertificateSerial = certSerial; |
---|
| 483 | } |
---|
| 484 | |
---|
| 485 | public String getCertificateSerial() { |
---|
| 486 | return mCertificateSerial; |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | public void setValidFrom(String validFrom) { |
---|
| 490 | this.mValidFrom = validFrom; |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | public String getValidFrom() { |
---|
| 494 | return mValidFrom; |
---|
| 495 | } |
---|
| 496 | |
---|
| 497 | public void setValidUntil(String validUntil) { |
---|
| 498 | this.mValidUntil = validUntil; |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | public String getValidUntil() { |
---|
| 502 | return mValidUntil; |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | public void setCertificateIssuer(String certIssuer) { |
---|
| 506 | this.mCertificateIssuer = certIssuer; |
---|
| 507 | } |
---|
| 508 | |
---|
| 509 | public String getCertificateIssuer() { |
---|
| 510 | return mCertificateIssuer; |
---|
| 511 | } |
---|
| 512 | |
---|
| 513 | } // fin de clase SignerFromBDOC |
---|
[5147e01] | 514 | |
---|
| 515 | // clase que abstrae el adaptador para llenar el ListView de documentos que |
---|
| 516 | // se encuentran dentro del contenedor BDOC |
---|
| 517 | private class SignerFromBDOCAdapter extends BaseAdapter { |
---|
| 518 | |
---|
| 519 | private ArrayList<SignerFromBDOC> mSignerFromBDOCList; |
---|
| 520 | private LayoutInflater lInflater; |
---|
| 521 | |
---|
| 522 | private SignerFromBDOCAdapter(Context context, ArrayList<SignerFromBDOC> signers) { |
---|
| 523 | this.lInflater = LayoutInflater.from(context); |
---|
| 524 | this.mSignerFromBDOCList = signers; |
---|
| 525 | |
---|
| 526 | } |
---|
| 527 | |
---|
| 528 | |
---|
| 529 | @Override |
---|
| 530 | public int getCount() { |
---|
| 531 | return mSignerFromBDOCList.size(); |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | @Override |
---|
| 535 | public Object getItem(int position) { |
---|
| 536 | return mSignerFromBDOCList.get(position); |
---|
| 537 | } |
---|
| 538 | |
---|
| 539 | @Override |
---|
| 540 | public long getItemId(int position) { |
---|
| 541 | return position; |
---|
| 542 | } |
---|
| 543 | |
---|
| 544 | @Override |
---|
| 545 | public View getView(int position, View convertView, ViewGroup parent) { |
---|
| 546 | ViewHolder container = null; |
---|
| 547 | |
---|
| 548 | if (convertView == null){ |
---|
| 549 | container = new ViewHolder(); |
---|
| 550 | convertView = lInflater.inflate(R.layout.signer_inside_bdoc_item, null); |
---|
| 551 | |
---|
| 552 | container.signer_text = (TextView) convertView.findViewById(R.id.signer_text); |
---|
| 553 | container.signer_modified = (TextView) convertView.findViewById(R.id.signer_modified); |
---|
| 554 | container.type_image = (ImageView) convertView.findViewById(R.id.type_image); |
---|
| 555 | convertView.setTag(container); |
---|
| 556 | }else{ |
---|
| 557 | container = (ViewHolder) convertView.getTag(); |
---|
| 558 | } |
---|
| 559 | |
---|
| 560 | SignerFromBDOC doc = (SignerFromBDOC) getItem(position); |
---|
| 561 | container.signer_text.setText(doc.getName()); |
---|
| 562 | container.signer_modified.setText(doc.getName()); |
---|
| 563 | container.type_image.setImageResource(R.drawable.ic_pluma); |
---|
| 564 | |
---|
| 565 | return convertView; |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | |
---|
| 569 | class ViewHolder{ |
---|
| 570 | TextView signer_text; |
---|
| 571 | TextView signer_modified; |
---|
| 572 | ImageView type_image; |
---|
| 573 | } |
---|
| 574 | |
---|
| 575 | } |
---|
| 576 | |
---|
| 577 | |
---|
| 578 | /** |
---|
| 579 | * Prepara directorio |
---|
| 580 | * @return boolean |
---|
| 581 | */ |
---|
| 582 | private boolean prepareDirectory() |
---|
| 583 | { |
---|
| 584 | try |
---|
| 585 | { |
---|
| 586 | if (makedirs()) |
---|
| 587 | { |
---|
| 588 | return true; |
---|
| 589 | } else { |
---|
| 590 | return false; |
---|
| 591 | } |
---|
| 592 | } catch (Exception e) |
---|
| 593 | { |
---|
| 594 | e.printStackTrace(); |
---|
| 595 | Toast.makeText(this, "Could not initiate File System.. Is Sdcard mounted properly?", Toast.LENGTH_LONG).show(); |
---|
| 596 | return false; |
---|
| 597 | } |
---|
| 598 | } |
---|
| 599 | |
---|
| 600 | /** |
---|
| 601 | * Crea directorio utilizando la variable tmpDir |
---|
| 602 | * @return boolean |
---|
| 603 | */ |
---|
| 604 | private boolean makedirs() |
---|
| 605 | { |
---|
| 606 | File tempdir = new File(extractedDirFiles); |
---|
| 607 | if (!tempdir.exists()) |
---|
| 608 | tempdir.mkdirs(); |
---|
| 609 | |
---|
| 610 | // if (tempdir.isDirectory()) |
---|
| 611 | // { |
---|
| 612 | // File[] files = tempdir.listFiles(); |
---|
| 613 | // for (File file : files) |
---|
| 614 | // { |
---|
| 615 | // if (!file.delete()) |
---|
| 616 | // { |
---|
| 617 | // System.out.println("Failed to delete " + file); |
---|
| 618 | // } |
---|
| 619 | // } |
---|
| 620 | // } |
---|
| 621 | return (tempdir.isDirectory()); |
---|
| 622 | } |
---|
| 623 | |
---|
| 624 | // funcion para lanzar un intent que abra un archivo |
---|
| 625 | private void openIt(String filePath, String mimeType) { |
---|
| 626 | |
---|
| 627 | Intent shareIntent = new Intent(); |
---|
| 628 | shareIntent.setAction(Intent.ACTION_VIEW); |
---|
| 629 | File file = new File(filePath); |
---|
| 630 | Uri uri = Uri.fromFile(file); |
---|
| 631 | Log.i("DEBUG", file.getPath()); |
---|
| 632 | shareIntent.setDataAndType(uri, mimeType); |
---|
| 633 | startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.open_it_using))); |
---|
| 634 | } |
---|
| 635 | |
---|
| 636 | // funcion para obtener el tipo mime de un archivo |
---|
| 637 | public static String getMimeType(String url) |
---|
| 638 | { |
---|
| 639 | String extension = url.substring(url.lastIndexOf(".")); |
---|
| 640 | String mimeTypeMap = MimeTypeMap.getFileExtensionFromUrl(extension); |
---|
| 641 | String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(mimeTypeMap); |
---|
| 642 | return mimeType; |
---|
| 643 | } |
---|
| 644 | |
---|
| 645 | // funcion para compartir el documento |
---|
| 646 | private void shareIt() { |
---|
| 647 | |
---|
| 648 | Intent shareIntent = new Intent(); |
---|
| 649 | shareIntent.setAction(Intent.ACTION_SEND); |
---|
| 650 | File file = new File(fileToVerify); |
---|
| 651 | |
---|
| 652 | |
---|
| 653 | Uri uri = Uri.fromFile(file); |
---|
| 654 | Log.i("DEBUG", file.getPath()); |
---|
| 655 | //Log.d("******", getMimeType(file.getPath())); |
---|
| 656 | //shareIntent.setDataAndType(uri, getMimeType(file.getPath())); |
---|
| 657 | shareIntent.putExtra(Intent.EXTRA_STREAM, uri); |
---|
| 658 | shareIntent.setType("application/*"); |
---|
| 659 | startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share_it_using))); |
---|
| 660 | } |
---|
| 661 | |
---|
| 662 | @Override |
---|
| 663 | public boolean onCreateOptionsMenu(Menu menu) { |
---|
| 664 | // Inflate the menu; this adds items to the action bar if it is present. |
---|
| 665 | getMenuInflater().inflate(R.menu.bdocverify_result, menu); |
---|
| 666 | return true; |
---|
| 667 | } |
---|
| 668 | |
---|
[064d990] | 669 | private void showSignatureDetails(int position, ArrayList<SignerFromBDOC> signers) { |
---|
| 670 | |
---|
| 671 | Log.d("**showSignatureDetails", Integer.toString(position)); |
---|
| 672 | Log.d("** nombre", signers.get(position).getName()); |
---|
| 673 | Intent intent = new Intent(this, ActivitySignerInfo.class); |
---|
| 674 | |
---|
| 675 | intent.putExtra("name", signers.get(position).getName()); |
---|
| 676 | intent.putExtra("cn", signers.get(position).getCN()); |
---|
| 677 | intent.putExtra("date", signers.get(position).getDate()); |
---|
| 678 | intent.putExtra("certificateSerial", signers.get(position).getCertificateSerial()); |
---|
| 679 | intent.putExtra("validFrom", signers.get(position).getValidFrom()); |
---|
| 680 | intent.putExtra("validUntil", signers.get(position).getValidUntil()); |
---|
| 681 | intent.putExtra("certificateIssuer", signers.get(position).getCertificateIssuer()); |
---|
| 682 | startActivity(intent); |
---|
| 683 | } |
---|
| 684 | |
---|
[5147e01] | 685 | } |
---|
| 686 | |
---|
| 687 | |
---|
| 688 | |
---|
[064d990] | 689 | |
---|