[a8ff2b6] | 1 | package ve.gob.cenditel.tibisaymovil; |
---|
| 2 | |
---|
[73b8c70] | 3 | import android.net.Uri; |
---|
[09c6eb7] | 4 | import android.os.Build; |
---|
[a8ff2b6] | 5 | import android.os.Bundle; |
---|
| 6 | import android.app.Activity; |
---|
[37467be] | 7 | import android.app.AlertDialog; |
---|
[a8ff2b6] | 8 | import android.content.Context; |
---|
[37467be] | 9 | import android.content.DialogInterface; |
---|
[a8ff2b6] | 10 | import android.content.Intent; |
---|
| 11 | import android.util.Log; |
---|
| 12 | import android.view.Menu; |
---|
[73b8c70] | 13 | import android.view.MenuItem; |
---|
[a8ff2b6] | 14 | import android.view.View; |
---|
[08c45bd] | 15 | import android.view.Window; |
---|
[a8ff2b6] | 16 | import android.widget.AdapterView; |
---|
| 17 | import android.widget.AdapterView.OnItemClickListener; |
---|
[37467be] | 18 | import android.widget.ArrayAdapter; |
---|
[a8ff2b6] | 19 | import android.widget.ListView; |
---|
| 20 | import android.widget.TextView; |
---|
| 21 | import android.widget.Toast; |
---|
| 22 | |
---|
[8fcfbf1] | 23 | |
---|
[a8ff2b6] | 24 | public class TibisayMovilActivity extends Activity { |
---|
| 25 | |
---|
[288126d] | 26 | |
---|
| 27 | public DirectKeyChain keyChain; |
---|
| 28 | |
---|
[a8ff2b6] | 29 | @Override |
---|
| 30 | protected void onCreate(Bundle savedInstanceState) { |
---|
| 31 | super.onCreate(savedInstanceState); |
---|
| 32 | |
---|
[08c45bd] | 33 | final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); |
---|
| 34 | setContentView(R.layout.activity_main); |
---|
[37467be] | 35 | if(customTitleSupported) |
---|
| 36 | getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); |
---|
[08c45bd] | 37 | |
---|
[a8ff2b6] | 38 | // listview de funciones |
---|
| 39 | final ListView listViewFunctions = (ListView) findViewById(R.id.listViewFunctions); |
---|
| 40 | |
---|
[37467be] | 41 | String[] values = new String[] {getString(R.string.firmar), |
---|
| 42 | getString(R.string.verificar), |
---|
| 43 | getString(R.string.cifrar), |
---|
| 44 | getString(R.string.descifrar), |
---|
| 45 | getString(R.string.compartir), |
---|
[288126d] | 46 | getString(R.string.certificados), |
---|
| 47 | getString(R.string.preferencias) }; |
---|
[37467be] | 48 | |
---|
| 49 | |
---|
| 50 | FunctionListAdapter ad = new FunctionListAdapter(this, values); |
---|
| 51 | listViewFunctions.setAdapter(ad); |
---|
[a8ff2b6] | 52 | |
---|
| 53 | |
---|
[288126d] | 54 | |
---|
| 55 | |
---|
[37467be] | 56 | /*************** Dialogos de submenus *******************/ |
---|
| 57 | //Crear dialogo de opciones para firmar |
---|
| 58 | final AlertDialog sign_dialog = makeSignatureOptionsDialog(); |
---|
[a8ff2b6] | 59 | |
---|
[6b383b3] | 60 | //Crear dialogo de opciones para compartir archivo |
---|
| 61 | final AlertDialog share_dialog = makeShareOptionsDialog(); |
---|
[37467be] | 62 | |
---|
[4528953] | 63 | //Crear dialogo de opciones para compartir cifrar archivo |
---|
| 64 | final AlertDialog certificate_dialog = makeCertificateOptionsDialog(); |
---|
| 65 | |
---|
[a8ff2b6] | 66 | |
---|
| 67 | listViewFunctions.setOnItemClickListener(new OnItemClickListener(){ |
---|
| 68 | |
---|
| 69 | @Override |
---|
| 70 | public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, |
---|
| 71 | long arg3) { |
---|
[288126d] | 72 | |
---|
[a8ff2b6] | 73 | Context context = getApplicationContext(); |
---|
| 74 | //CharSequence text = "Click!"; |
---|
| 75 | int duration = Toast.LENGTH_SHORT; |
---|
| 76 | //Toast.makeText(context, text, duration).show(); |
---|
| 77 | |
---|
| 78 | View curr = arg0.getChildAt((int) arg3); |
---|
[08c45bd] | 79 | TextView c = (TextView)curr.findViewById(R.id.textListMainMenu); |
---|
[a8ff2b6] | 80 | String function = c.getText().toString(); |
---|
| 81 | //Toast.makeText(context, function, duration).show(); |
---|
[37467be] | 82 | |
---|
[5147e01] | 83 | // seleccion de firmar |
---|
[37467be] | 84 | if(function.equals(getString(R.string.firmar))) { |
---|
| 85 | sign_dialog.show(); |
---|
| 86 | } |
---|
[a8ff2b6] | 87 | |
---|
[5147e01] | 88 | // seleccion de verificar |
---|
| 89 | if(function.equals(getString(R.string.verificar))) { |
---|
[ba6bc7c] | 90 | //Toast.makeText(context, "VERIFICAR", duration).show(); |
---|
[5147e01] | 91 | verifyBDOCSignedFile(); |
---|
| 92 | } |
---|
| 93 | |
---|
[4528953] | 94 | // seleccion de cifrar |
---|
| 95 | if(function.equals(getString(R.string.cifrar))) { |
---|
[ba6bc7c] | 96 | //Toast.makeText(context, "CIFRAR", duration).show(); |
---|
[ae1bcd1] | 97 | encryptFile(); |
---|
[4528953] | 98 | } |
---|
| 99 | |
---|
[fd4a5b9] | 100 | // seleccion de descifrar |
---|
| 101 | if(function.equals(getString(R.string.descifrar))) { |
---|
[ba6bc7c] | 102 | //Toast.makeText(context, "DESCIFRAR", duration).show(); |
---|
[fd4a5b9] | 103 | decryptFile(); |
---|
| 104 | } |
---|
[4528953] | 105 | |
---|
[3fe55cf] | 106 | // seleccion de gestionar certificados |
---|
[8fcfbf1] | 107 | if (function.equals(getString(R.string.certificados))){ |
---|
[ba6bc7c] | 108 | //Toast.makeText(context, "Gestionar repositorio", duration).show(); |
---|
[4528953] | 109 | certificate_dialog.show(); |
---|
[a8ff2b6] | 110 | |
---|
| 111 | } |
---|
| 112 | |
---|
[6b383b3] | 113 | // seleccion de compartir archivo |
---|
| 114 | if (function.equals(getString(R.string.compartir))){ |
---|
[ba6bc7c] | 115 | //Toast.makeText(context, "Compartir Archivo", duration).show(); |
---|
[6b383b3] | 116 | share_dialog.show(); |
---|
| 117 | |
---|
| 118 | } |
---|
[288126d] | 119 | // seleccion de firmar |
---|
| 120 | if(function.equals(getString(R.string.preferencias))) { |
---|
| 121 | preferences(); |
---|
| 122 | } |
---|
[6b383b3] | 123 | |
---|
[a8ff2b6] | 124 | } |
---|
[37467be] | 125 | }); //setOnItemClickListener |
---|
| 126 | } // end onCreate |
---|
[a8ff2b6] | 127 | |
---|
| 128 | @Override |
---|
| 129 | public boolean onCreateOptionsMenu(Menu menu) { |
---|
| 130 | // Inflate the menu; this adds items to the action bar if it is present. |
---|
[73b8c70] | 131 | getMenuInflater().inflate(R.menu.menu, menu); |
---|
| 132 | return true; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | @Override |
---|
| 136 | public boolean onOptionsItemSelected(MenuItem item) { |
---|
| 137 | switch (item.getItemId()) { |
---|
| 138 | case R.id.MnuAbout: |
---|
| 139 | Intent intentAbout = new Intent(TibisayMovilActivity.this,AboutActivity.class); |
---|
| 140 | startActivity(intentAbout); |
---|
| 141 | return true; |
---|
| 142 | case R.id.MnuHelp: |
---|
| 143 | Intent intent = new Intent(); |
---|
| 144 | intent.setAction(Intent.ACTION_VIEW); |
---|
| 145 | intent.addCategory(Intent.CATEGORY_BROWSABLE); |
---|
| 146 | intent.setData(Uri.parse("http://seguridad.cenditel.gob.ve/proyectos/tibisay-movil/ayuda-de-tibisay-movil/")); |
---|
| 147 | startActivity(intent); |
---|
| 148 | return true; |
---|
| 149 | default: |
---|
| 150 | return super.onOptionsItemSelected(item); |
---|
| 151 | } |
---|
[a8ff2b6] | 152 | } |
---|
| 153 | |
---|
[8fcfbf1] | 154 | |
---|
[a8ff2b6] | 155 | private void testRepository(){ |
---|
[288126d] | 156 | |
---|
| 157 | // this.keyChain = DirectKeyChain.getInstance(); |
---|
| 158 | // this.keyChain.setListView(this.viewHolder.aliases); |
---|
| 159 | // this.keyChain.setMasterActivity((Activity) this); |
---|
| 160 | // this.keyChain.choosePrivateKeyAlias(); |
---|
| 161 | |
---|
| 162 | Intent intent = new Intent(this, CertificateRepositoryActivity.class); |
---|
[09c6eb7] | 163 | startActivity(intent); |
---|
[a8ff2b6] | 164 | } |
---|
| 165 | |
---|
[37467be] | 166 | private void fileToSignHandwrittenSignature(){ |
---|
| 167 | Intent intent = new Intent(this, FileToSignHandwrittenSignatureActivity.class); |
---|
| 168 | startActivity(intent); |
---|
| 169 | } |
---|
[288126d] | 170 | |
---|
| 171 | private void filesToPKCS7Sign(){ |
---|
| 172 | Intent intent = new Intent(this, FilesToPKCS7SignActivity.class); |
---|
| 173 | startActivity(intent); |
---|
| 174 | } |
---|
[8243993] | 175 | |
---|
| 176 | private void filesToPDFSign(){ |
---|
| 177 | Intent intent = new Intent(this, FilesToPDFSignActivity.class); |
---|
| 178 | startActivity(intent); |
---|
| 179 | } |
---|
[5147e01] | 180 | |
---|
[a8ff2b6] | 181 | |
---|
[5147e01] | 182 | // lanza activity para verificar un documento firmado |
---|
| 183 | private void verifyBDOCSignedFile(){ |
---|
| 184 | //Intent intent = new Intent(this, FileToSignHandwrittenSignatureActivity.class); |
---|
| 185 | Intent intent = new Intent(this, FileToVerifySignatureActivity.class); |
---|
| 186 | startActivity(intent); |
---|
| 187 | } |
---|
[a8ff2b6] | 188 | |
---|
[4528953] | 189 | // lanza activity para compartir un documento |
---|
[6b383b3] | 190 | private void shareFile(String path){ |
---|
| 191 | Intent intent = new Intent(this, FileToShareActivity.class); |
---|
| 192 | |
---|
| 193 | intent.putExtra("path", path); |
---|
| 194 | |
---|
| 195 | startActivity(intent); |
---|
| 196 | } |
---|
[4528953] | 197 | |
---|
| 198 | // lanza activity para cifrar un documento |
---|
| 199 | private void encryptFile(){ |
---|
[ae1bcd1] | 200 | Intent intent = new Intent(this, FileToEncryptActivity.class); |
---|
| 201 | startActivity(intent); |
---|
[4528953] | 202 | } |
---|
| 203 | |
---|
[fd4a5b9] | 204 | |
---|
| 205 | // lanza activity para descifrar un documento |
---|
| 206 | private void decryptFile(){ |
---|
| 207 | Intent intent = new Intent(this, FileToDecryptActivity.class); |
---|
| 208 | startActivity(intent); |
---|
| 209 | } |
---|
| 210 | |
---|
| 211 | |
---|
[4528953] | 212 | // lanza la activity para gestionar los certificados de destinarios (cifrado) |
---|
| 213 | private void manageRecipientCertificates() { |
---|
| 214 | Intent intent = new Intent(this, EncryptionCertificatesActivity.class); |
---|
| 215 | startActivity(intent); |
---|
| 216 | } |
---|
| 217 | |
---|
[1081d4d] | 218 | |
---|
[37467be] | 219 | //Crea dialogo de opciones para firma electronica |
---|
| 220 | public AlertDialog makeSignatureOptionsDialog() { |
---|
| 221 | final String[] option = new String[] {getString(R.string.firmar_man_pdf), getString(R.string.firmar_elec_pdf), getString(R.string.firmar_pkcs7) }; |
---|
| 222 | ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, |
---|
| 223 | android.R.layout.select_dialog_item, option); |
---|
| 224 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
---|
| 225 | |
---|
| 226 | builder.setTitle(getString(R.string.seleccione_opcion)); |
---|
| 227 | builder.setAdapter(adapter, new DialogInterface.OnClickListener() { |
---|
| 228 | |
---|
| 229 | public void onClick(DialogInterface dialog, int which) { |
---|
| 230 | |
---|
| 231 | switch (which) { |
---|
| 232 | case 0: // Firma Manuscrita PDF |
---|
| 233 | Log.i("DEBUG", "antes de activity call"); |
---|
| 234 | fileToSignHandwrittenSignature(); |
---|
| 235 | break; |
---|
| 236 | case 1: // Firma Electronica PDF |
---|
[8243993] | 237 | filesToPDFSign(); |
---|
[37467be] | 238 | break; |
---|
| 239 | case 2: // Firma PKCS7 |
---|
[288126d] | 240 | filesToPKCS7Sign(); |
---|
[37467be] | 241 | break; |
---|
| 242 | |
---|
| 243 | default: |
---|
| 244 | break; |
---|
| 245 | } |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | }); |
---|
| 249 | |
---|
| 250 | return builder.create(); |
---|
| 251 | } |
---|
[288126d] | 252 | |
---|
| 253 | |
---|
| 254 | // lanza activity para preferencias |
---|
| 255 | private void preferences(){ |
---|
| 256 | Intent intent = new Intent(this, PreferencesActivity.class); |
---|
| 257 | startActivity(intent); |
---|
| 258 | } |
---|
[6b383b3] | 259 | |
---|
[4528953] | 260 | //Crea dialogo de opciones para compartir archivos |
---|
[6b383b3] | 261 | public AlertDialog makeShareOptionsDialog() { |
---|
| 262 | final String[] option = new String[] {getString(R.string.share_pdf_signed), |
---|
[c231890] | 263 | getString(R.string.share_bdoc_downloaded), getString(R.string.share_extracted_file_from_bdoc), |
---|
| 264 | getString(R.string.share_encrypted) }; |
---|
[6b383b3] | 265 | ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, |
---|
| 266 | android.R.layout.select_dialog_item, option); |
---|
| 267 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
---|
| 268 | |
---|
| 269 | builder.setTitle(getString(R.string.seleccione_opcion)); |
---|
| 270 | builder.setAdapter(adapter, new DialogInterface.OnClickListener() { |
---|
| 271 | |
---|
| 272 | public void onClick(DialogInterface dialog, int which) { |
---|
| 273 | |
---|
| 274 | switch (which) { |
---|
| 275 | case 0: // Archivo Firmado |
---|
| 276 | Log.i("DEBUG", "antes de activity call"); |
---|
| 277 | shareFile("archivoFirmado"); |
---|
| 278 | break; |
---|
| 279 | case 1: // Archivos BDOC Descargados |
---|
| 280 | shareFile("bdocDescargado"); |
---|
| 281 | break; |
---|
| 282 | case 2: // Archivos extraídos de BDOC |
---|
| 283 | shareFile("extraidoDeBdoc"); |
---|
| 284 | break; |
---|
| 285 | |
---|
[c231890] | 286 | case 3: // Archivos cifrados |
---|
| 287 | shareFile("cifrado"); |
---|
| 288 | break; |
---|
[6b383b3] | 289 | default: |
---|
| 290 | break; |
---|
| 291 | } |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | }); |
---|
| 295 | |
---|
| 296 | return builder.create(); |
---|
| 297 | } |
---|
| 298 | |
---|
[4528953] | 299 | //Crea dialogo de opciones para gestionar certificados |
---|
| 300 | public AlertDialog makeCertificateOptionsDialog() { |
---|
[3fe55cf] | 301 | ; |
---|
| 302 | final String[] option; |
---|
| 303 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH){ |
---|
[8243993] | 304 | option = new String[] {getString(R.string.manage_personal_certificates), getString(R.string.manage_certificates_for_encryption) }; |
---|
[3fe55cf] | 305 | } else { |
---|
[8243993] | 306 | option = new String[] {getString(R.string.manage_certificates_for_encryption) }; |
---|
[3fe55cf] | 307 | } |
---|
| 308 | |
---|
[4528953] | 309 | ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, |
---|
| 310 | android.R.layout.select_dialog_item, option); |
---|
| 311 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
---|
| 312 | |
---|
| 313 | builder.setTitle(getString(R.string.seleccione_opcion)); |
---|
| 314 | builder.setAdapter(adapter, new DialogInterface.OnClickListener() { |
---|
| 315 | |
---|
| 316 | public void onClick(DialogInterface dialog, int which) { |
---|
[3fe55cf] | 317 | |
---|
| 318 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH){ |
---|
| 319 | |
---|
| 320 | switch (which) { |
---|
| 321 | case 0: // Certificados personales |
---|
| 322 | testRepository(); |
---|
| 323 | break; |
---|
| 324 | case 1: // Certificados para cifrado |
---|
| 325 | manageRecipientCertificates(); |
---|
| 326 | break; |
---|
| 327 | } |
---|
[4528953] | 328 | |
---|
[3fe55cf] | 329 | } else { |
---|
| 330 | |
---|
| 331 | switch (which) { |
---|
| 332 | case 0: // Certificados para cifrado |
---|
| 333 | manageRecipientCertificates(); |
---|
| 334 | break; |
---|
| 335 | } |
---|
[4528953] | 336 | |
---|
| 337 | } |
---|
[3fe55cf] | 338 | |
---|
[4528953] | 339 | } |
---|
| 340 | |
---|
| 341 | }); |
---|
| 342 | |
---|
| 343 | return builder.create(); |
---|
| 344 | } |
---|
| 345 | |
---|
[a8ff2b6] | 346 | } |
---|