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