[a8ff2b6] | 1 | package ve.gob.cenditel.tibisaymovil; |
---|
| 2 | |
---|
[a8bb2bb] | 3 | import ve.gob.cenditel.tibisaymovil.R.color; |
---|
[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; |
---|
| 13 | import android.view.View; |
---|
[08c45bd] | 14 | import android.view.Window; |
---|
[a8ff2b6] | 15 | import android.widget.AdapterView; |
---|
| 16 | import android.widget.AdapterView.OnItemClickListener; |
---|
[37467be] | 17 | import android.widget.ArrayAdapter; |
---|
[a8ff2b6] | 18 | import android.widget.ListView; |
---|
| 19 | import android.widget.TextView; |
---|
| 20 | import android.widget.Toast; |
---|
| 21 | |
---|
| 22 | //public class TibisayMovilActivity extends KeyChainClientActivity { |
---|
| 23 | //implements OnItemClickListener, OnClickListener { |
---|
| 24 | public class TibisayMovilActivity extends Activity { |
---|
| 25 | |
---|
| 26 | @Override |
---|
| 27 | protected void onCreate(Bundle savedInstanceState) { |
---|
| 28 | super.onCreate(savedInstanceState); |
---|
| 29 | |
---|
[08c45bd] | 30 | final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); |
---|
| 31 | setContentView(R.layout.activity_main); |
---|
[37467be] | 32 | if(customTitleSupported) |
---|
| 33 | getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); |
---|
[08c45bd] | 34 | |
---|
[a8ff2b6] | 35 | // listview de funciones |
---|
| 36 | final ListView listViewFunctions = (ListView) findViewById(R.id.listViewFunctions); |
---|
| 37 | |
---|
[37467be] | 38 | String[] values = new String[] {getString(R.string.firmar), |
---|
| 39 | getString(R.string.verificar), |
---|
| 40 | getString(R.string.cifrar), |
---|
| 41 | getString(R.string.descifrar), |
---|
| 42 | getString(R.string.compartir), |
---|
| 43 | getString(R.string.certificados) }; |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | FunctionListAdapter ad = new FunctionListAdapter(this, values); |
---|
| 47 | listViewFunctions.setAdapter(ad); |
---|
[a8ff2b6] | 48 | |
---|
| 49 | |
---|
[37467be] | 50 | /*************** Dialogos de submenus *******************/ |
---|
| 51 | //Crear dialogo de opciones para firmar |
---|
| 52 | final AlertDialog sign_dialog = makeSignatureOptionsDialog(); |
---|
[a8ff2b6] | 53 | |
---|
[6b383b3] | 54 | //Crear dialogo de opciones para compartir archivo |
---|
| 55 | final AlertDialog share_dialog = makeShareOptionsDialog(); |
---|
[37467be] | 56 | |
---|
[a8ff2b6] | 57 | |
---|
| 58 | listViewFunctions.setOnItemClickListener(new OnItemClickListener(){ |
---|
| 59 | |
---|
| 60 | @Override |
---|
| 61 | public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, |
---|
| 62 | long arg3) { |
---|
| 63 | // TODO Auto-generated method stub |
---|
| 64 | Context context = getApplicationContext(); |
---|
| 65 | //CharSequence text = "Click!"; |
---|
| 66 | int duration = Toast.LENGTH_SHORT; |
---|
| 67 | //Toast.makeText(context, text, duration).show(); |
---|
| 68 | |
---|
| 69 | View curr = arg0.getChildAt((int) arg3); |
---|
[08c45bd] | 70 | TextView c = (TextView)curr.findViewById(R.id.textListMainMenu); |
---|
[a8ff2b6] | 71 | String function = c.getText().toString(); |
---|
| 72 | //Toast.makeText(context, function, duration).show(); |
---|
[37467be] | 73 | |
---|
[5147e01] | 74 | // seleccion de firmar |
---|
[37467be] | 75 | if(function.equals(getString(R.string.firmar))) { |
---|
| 76 | sign_dialog.show(); |
---|
| 77 | } |
---|
[a8ff2b6] | 78 | |
---|
[5147e01] | 79 | // seleccion de verificar |
---|
| 80 | if(function.equals(getString(R.string.verificar))) { |
---|
| 81 | Toast.makeText(context, "VERIFICAR", duration).show(); |
---|
| 82 | verifyBDOCSignedFile(); |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | // seleccion de gestionar certificados |
---|
[a8ff2b6] | 86 | if (function.equals("Certificados")){ |
---|
[37467be] | 87 | Toast.makeText(context, "Gestionar repositorio", duration).show(); |
---|
[a8ff2b6] | 88 | |
---|
[09c6eb7] | 89 | // Chequeo de version del API de Android para creacion de repositorio |
---|
| 90 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH){ |
---|
| 91 | //RelativeLayout certTab = (RelativeLayout) this.findViewById(R.id.linetab2); |
---|
| 92 | //certTab.setVisibility(View.VISIBLE); |
---|
| 93 | //this.tabsListener.setKeyChainController(this.keyChainController); |
---|
| 94 | Toast.makeText(context, "API < 4.0", duration).show(); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | //manageKeyChain(); |
---|
[a8ff2b6] | 98 | |
---|
| 99 | // lanzar activity de gestion de repositorio |
---|
[37467be] | 100 | testRepository(); |
---|
[a8ff2b6] | 101 | } |
---|
| 102 | |
---|
[6b383b3] | 103 | // seleccion de compartir archivo |
---|
| 104 | if (function.equals(getString(R.string.compartir))){ |
---|
| 105 | Toast.makeText(context, "Compartir Archivo", duration).show(); |
---|
| 106 | share_dialog.show(); |
---|
| 107 | |
---|
| 108 | } |
---|
| 109 | |
---|
[a8ff2b6] | 110 | } |
---|
[37467be] | 111 | }); //setOnItemClickListener |
---|
| 112 | } // end onCreate |
---|
[a8ff2b6] | 113 | |
---|
| 114 | @Override |
---|
| 115 | public boolean onCreateOptionsMenu(Menu menu) { |
---|
| 116 | // Inflate the menu; this adds items to the action bar if it is present. |
---|
| 117 | getMenuInflater().inflate(R.menu.main, menu); |
---|
| 118 | return true; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | /* |
---|
| 122 | @Override |
---|
| 123 | public void setAlias(String alias) { |
---|
| 124 | |
---|
| 125 | if (alias == null) { |
---|
| 126 | finish(); |
---|
| 127 | return; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | this.privateKeyAlias = alias; |
---|
| 131 | |
---|
| 132 | //Intent intent = new Intent(this, CertValidatorActivity.class); |
---|
| 133 | //intent.putExtra(IntentExtraField.ALIAS, alias); |
---|
| 134 | //intent.putParcelableArrayListExtra(IntentExtraField.FILES, TypeUtils.convertToUriArrayList(this.selected)); |
---|
| 135 | //startActivityForResult(intent, ActivityResult.CHECK_CERTIFICATE_VALIDITY); |
---|
| 136 | |
---|
| 137 | } |
---|
| 138 | */ |
---|
| 139 | |
---|
[37467be] | 140 | // private void manageKeyChain(){ |
---|
| 141 | // // |
---|
| 142 | // //Intent intent = new Intent(this, PKCS12FilePickerActivity.class); |
---|
| 143 | // //startActivityForResult(intent, ActivityResult.IMPORT_CERTIFICATE); |
---|
| 144 | // //KeyChainStrategy.getInstance().choosePrivateKeyAlias(); |
---|
| 145 | // } |
---|
[a8ff2b6] | 146 | |
---|
| 147 | private void testRepository(){ |
---|
[09c6eb7] | 148 | Intent intent = new Intent(this, CertificateRepositoryActivity.class); |
---|
| 149 | startActivity(intent); |
---|
[a8ff2b6] | 150 | } |
---|
| 151 | |
---|
[37467be] | 152 | private void fileToSignHandwrittenSignature(){ |
---|
| 153 | Intent intent = new Intent(this, FileToSignHandwrittenSignatureActivity.class); |
---|
| 154 | startActivity(intent); |
---|
| 155 | } |
---|
[5147e01] | 156 | |
---|
[a8ff2b6] | 157 | |
---|
[5147e01] | 158 | // lanza activity para verificar un documento firmado |
---|
| 159 | private void verifyBDOCSignedFile(){ |
---|
| 160 | //Intent intent = new Intent(this, FileToSignHandwrittenSignatureActivity.class); |
---|
| 161 | Intent intent = new Intent(this, FileToVerifySignatureActivity.class); |
---|
| 162 | startActivity(intent); |
---|
| 163 | } |
---|
[a8ff2b6] | 164 | |
---|
[6b383b3] | 165 | private void shareFile(String path){ |
---|
| 166 | Intent intent = new Intent(this, FileToShareActivity.class); |
---|
| 167 | |
---|
| 168 | intent.putExtra("path", path); |
---|
| 169 | |
---|
| 170 | startActivity(intent); |
---|
| 171 | } |
---|
| 172 | |
---|
[37467be] | 173 | //Crea dialogo de opciones para firma electronica |
---|
| 174 | public AlertDialog makeSignatureOptionsDialog() { |
---|
| 175 | final String[] option = new String[] {getString(R.string.firmar_man_pdf), getString(R.string.firmar_elec_pdf), getString(R.string.firmar_pkcs7) }; |
---|
| 176 | ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, |
---|
| 177 | android.R.layout.select_dialog_item, option); |
---|
| 178 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
---|
| 179 | |
---|
| 180 | builder.setTitle(getString(R.string.seleccione_opcion)); |
---|
| 181 | builder.setAdapter(adapter, new DialogInterface.OnClickListener() { |
---|
| 182 | |
---|
| 183 | public void onClick(DialogInterface dialog, int which) { |
---|
| 184 | |
---|
| 185 | switch (which) { |
---|
| 186 | case 0: // Firma Manuscrita PDF |
---|
| 187 | Log.i("DEBUG", "antes de activity call"); |
---|
| 188 | fileToSignHandwrittenSignature(); |
---|
| 189 | break; |
---|
| 190 | case 1: // Firma Electronica PDF |
---|
| 191 | |
---|
| 192 | break; |
---|
| 193 | case 2: // Firma PKCS7 |
---|
| 194 | |
---|
| 195 | break; |
---|
| 196 | |
---|
| 197 | default: |
---|
| 198 | break; |
---|
| 199 | } |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | }); |
---|
| 203 | |
---|
| 204 | return builder.create(); |
---|
| 205 | } |
---|
[6b383b3] | 206 | |
---|
| 207 | //Crea dialogo de opciones para firma electronica |
---|
| 208 | public AlertDialog makeShareOptionsDialog() { |
---|
| 209 | final String[] option = new String[] {getString(R.string.share_pdf_signed), |
---|
| 210 | getString(R.string.share_bdoc_downloaded), getString(R.string.share_extracted_file_from_bdoc) }; |
---|
| 211 | ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, |
---|
| 212 | android.R.layout.select_dialog_item, option); |
---|
| 213 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
---|
| 214 | |
---|
| 215 | builder.setTitle(getString(R.string.seleccione_opcion)); |
---|
| 216 | builder.setAdapter(adapter, new DialogInterface.OnClickListener() { |
---|
| 217 | |
---|
| 218 | public void onClick(DialogInterface dialog, int which) { |
---|
| 219 | |
---|
| 220 | switch (which) { |
---|
| 221 | case 0: // Archivo Firmado |
---|
| 222 | Log.i("DEBUG", "antes de activity call"); |
---|
| 223 | shareFile("archivoFirmado"); |
---|
| 224 | break; |
---|
| 225 | case 1: // Archivos BDOC Descargados |
---|
| 226 | shareFile("bdocDescargado"); |
---|
| 227 | break; |
---|
| 228 | case 2: // Archivos extraídos de BDOC |
---|
| 229 | shareFile("extraidoDeBdoc"); |
---|
| 230 | break; |
---|
| 231 | |
---|
| 232 | default: |
---|
| 233 | break; |
---|
| 234 | } |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | }); |
---|
| 238 | |
---|
| 239 | return builder.create(); |
---|
| 240 | } |
---|
| 241 | |
---|
[a8ff2b6] | 242 | } |
---|