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