1 | /* |
---|
2 | Tibisay Movil |
---|
3 | |
---|
4 | Copyright (C) 2013 Antonio Araujo (aaraujo@cenditel.gob.ve), Jose Ruiz |
---|
5 | (jruiz@cenditel.gob.ve), Fundacion Centro Nacional de Desarrollo e |
---|
6 | Investigacion en Tecnologias Libres - CENDITEL. |
---|
7 | |
---|
8 | La Fundación CENDITEL concede permiso para usar, copiar, distribuir y/o |
---|
9 | modificar este programa, reconociendo el derecho que la humanidad posee al |
---|
10 | libre acceso al conocimiento, bajo los términos de la licencia de software |
---|
11 | GPL versión 2.0 de la Free Software Foundation. |
---|
12 | |
---|
13 | Este programa se distribuye con la esperanza de que sea util, pero SIN |
---|
14 | NINGUNA GARANTIA; tampoco las implicitas garantias de MERCANTILIDAD o |
---|
15 | ADECUACION A UN PROPOSITO PARTICULAR. |
---|
16 | |
---|
17 | Para mayor información sobre los términos de la licencia ver el archivo |
---|
18 | llamado "gpl-2.0.txt" en ingles. |
---|
19 | */ |
---|
20 | |
---|
21 | package ve.gob.cenditel.tibisaymovil; |
---|
22 | |
---|
23 | import android.net.Uri; |
---|
24 | import android.os.Build; |
---|
25 | import android.os.Bundle; |
---|
26 | //import android.annotation.SuppressLint; |
---|
27 | //import android.app.ActionBar; |
---|
28 | import android.app.Activity; |
---|
29 | import android.app.AlertDialog; |
---|
30 | import android.content.Context; |
---|
31 | import android.content.DialogInterface; |
---|
32 | import android.content.Intent; |
---|
33 | import android.util.Log; |
---|
34 | import android.view.Menu; |
---|
35 | import android.view.MenuItem; |
---|
36 | import android.view.View; |
---|
37 | import android.view.Window; |
---|
38 | import android.widget.AdapterView; |
---|
39 | import android.widget.AdapterView.OnItemClickListener; |
---|
40 | import android.widget.ArrayAdapter; |
---|
41 | import android.widget.GridView; |
---|
42 | import android.widget.ListView; |
---|
43 | import android.widget.TextView; |
---|
44 | import android.widget.Toast; |
---|
45 | |
---|
46 | //import android.support.v7.app.ActionBar; |
---|
47 | //import android.support.v7.app.ActionBarActivity; |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | public class TibisayMovilActivity extends Activity { |
---|
52 | //public class TibisayMovilActivity extends ActionBarActivity { |
---|
53 | |
---|
54 | |
---|
55 | public DirectKeyChain keyChain; |
---|
56 | |
---|
57 | //@SuppressLint("NewApi") |
---|
58 | @Override |
---|
59 | protected void onCreate(Bundle savedInstanceState) { |
---|
60 | super.onCreate(savedInstanceState); |
---|
61 | |
---|
62 | final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); |
---|
63 | //setContentView(R.layout.activity_main); |
---|
64 | |
---|
65 | setContentView(R.layout.activity_grid_main); |
---|
66 | |
---|
67 | |
---|
68 | if(customTitleSupported) |
---|
69 | getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); |
---|
70 | |
---|
71 | // no funciona |
---|
72 | //if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){ |
---|
73 | //requestWindowFeature(Window.FEATURE_ACTION_BAR); |
---|
74 | //ActionBar actionBar = this.getActionBar(); |
---|
75 | //actionBar.show(); |
---|
76 | //} |
---|
77 | |
---|
78 | // listview de funciones |
---|
79 | //final ListView listViewFunctions = (ListView) findViewById(R.id.listViewFunctions); |
---|
80 | |
---|
81 | |
---|
82 | //final GridView gridViewFunctions = (GridView) findViewById(R.id.mainGridview); |
---|
83 | |
---|
84 | String[] values = new String[] {getString(R.string.firmar), |
---|
85 | getString(R.string.verificar), |
---|
86 | getString(R.string.certificados), |
---|
87 | getString(R.string.cifrar), |
---|
88 | getString(R.string.descifrar), |
---|
89 | getString(R.string.compartir), |
---|
90 | getString(R.string.preferencias), |
---|
91 | getString(R.string.ayuda), |
---|
92 | getString(R.string.acercade)}; |
---|
93 | |
---|
94 | |
---|
95 | //FunctionListAdapter ad = new FunctionListAdapter(this, values); |
---|
96 | //listViewFunctions.setAdapter(ad); |
---|
97 | |
---|
98 | //grid de funciones |
---|
99 | final GridView gridViewMenu = (GridView) findViewById(R.id.mainGridView); |
---|
100 | ImageMenuAdapter imageMenuAdapter = new ImageMenuAdapter(this, values); |
---|
101 | gridViewMenu.setAdapter(imageMenuAdapter); |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | |
---|
106 | /*************** Dialogos de submenus *******************/ |
---|
107 | //Crear dialogo de opciones para firmar |
---|
108 | final AlertDialog sign_dialog = makeSignatureOptionsDialog(); |
---|
109 | |
---|
110 | //Crear dialogo de opciones para compartir archivo |
---|
111 | final AlertDialog share_dialog = makeShareOptionsDialog(); |
---|
112 | |
---|
113 | //Crear dialogo de opciones para compartir cifrar archivo |
---|
114 | final AlertDialog certificate_dialog = makeCertificateOptionsDialog(); |
---|
115 | |
---|
116 | //listViewFunctions.setOnItemClickListener(new OnItemClickListener(){ |
---|
117 | gridViewMenu.setOnItemClickListener(new OnItemClickListener(){ |
---|
118 | |
---|
119 | @Override |
---|
120 | public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, |
---|
121 | long arg3) { |
---|
122 | |
---|
123 | Context context = getApplicationContext(); |
---|
124 | //CharSequence text = "Click!"; |
---|
125 | int duration = Toast.LENGTH_SHORT; |
---|
126 | //Toast.makeText(context, text, duration).show(); |
---|
127 | |
---|
128 | //View curr = arg0.getChildAt((int) arg3); |
---|
129 | View curr = arg0.getChildAt((int) arg2); |
---|
130 | //TextView c = (TextView)curr.findViewById(R.id.textListMainMenu); |
---|
131 | TextView c = (TextView)curr.findViewById(R.id.textGridMainMenu); |
---|
132 | |
---|
133 | String function = c.getText().toString(); |
---|
134 | //Toast.makeText(context, function, duration).show(); |
---|
135 | |
---|
136 | // seleccion de firmar |
---|
137 | if(function.equals(getString(R.string.firmar))) { |
---|
138 | sign_dialog.show(); |
---|
139 | } |
---|
140 | |
---|
141 | // seleccion de verificar |
---|
142 | if(function.equals(getString(R.string.verificar))) { |
---|
143 | //Toast.makeText(context, "VERIFICAR", duration).show(); |
---|
144 | verifyBDOCSignedFile(); |
---|
145 | } |
---|
146 | |
---|
147 | // seleccion de cifrar |
---|
148 | if(function.equals(getString(R.string.cifrar))) { |
---|
149 | //Toast.makeText(context, "CIFRAR", duration).show(); |
---|
150 | encryptFile(); |
---|
151 | } |
---|
152 | |
---|
153 | // seleccion de descifrar |
---|
154 | if(function.equals(getString(R.string.descifrar))) { |
---|
155 | //Toast.makeText(context, "DESCIFRAR", duration).show(); |
---|
156 | decryptFile(); |
---|
157 | } |
---|
158 | |
---|
159 | // seleccion de gestionar certificados |
---|
160 | if (function.equals(getString(R.string.certificados))){ |
---|
161 | //Toast.makeText(context, "Gestionar repositorio", duration).show(); |
---|
162 | certificate_dialog.show(); |
---|
163 | |
---|
164 | } |
---|
165 | |
---|
166 | // seleccion de compartir archivo |
---|
167 | if (function.equals(getString(R.string.compartir))){ |
---|
168 | //Toast.makeText(context, "Compartir Archivo", duration).show(); |
---|
169 | share_dialog.show(); |
---|
170 | |
---|
171 | } |
---|
172 | |
---|
173 | // seleccion de preferencias |
---|
174 | if(function.equals(getString(R.string.preferencias))) { |
---|
175 | preferences(); |
---|
176 | } |
---|
177 | |
---|
178 | // seleccion de ayuda |
---|
179 | if(function.equals(getString(R.string.ayuda))) { |
---|
180 | Intent intent = new Intent(); |
---|
181 | intent.setAction(Intent.ACTION_VIEW); |
---|
182 | intent.addCategory(Intent.CATEGORY_BROWSABLE); |
---|
183 | intent.setData(Uri.parse("http://seguridad.cenditel.gob.ve/proyectos/tibisay-movil/ayuda-de-tibisay-movil/")); |
---|
184 | startActivity(intent); |
---|
185 | } |
---|
186 | |
---|
187 | // seleccion de acerca de |
---|
188 | if(function.equals(getString(R.string.acercade))) { |
---|
189 | Intent intentAbout = new Intent(TibisayMovilActivity.this,AboutActivity.class); |
---|
190 | startActivity(intentAbout); |
---|
191 | } |
---|
192 | |
---|
193 | } |
---|
194 | }); //setOnItemClickListener |
---|
195 | } // end onCreate |
---|
196 | |
---|
197 | @Override |
---|
198 | public boolean onCreateOptionsMenu(Menu menu) { |
---|
199 | // Inflate the menu; this adds items to the action bar if it is present. |
---|
200 | getMenuInflater().inflate(R.menu.menu, menu); |
---|
201 | return true; |
---|
202 | } |
---|
203 | |
---|
204 | @Override |
---|
205 | public boolean onOptionsItemSelected(MenuItem item) { |
---|
206 | switch (item.getItemId()) { |
---|
207 | case R.id.MnuAbout: |
---|
208 | Intent intentAbout = new Intent(TibisayMovilActivity.this,AboutActivity.class); |
---|
209 | startActivity(intentAbout); |
---|
210 | return true; |
---|
211 | case R.id.MnuHelp: |
---|
212 | Intent intent = new Intent(); |
---|
213 | intent.setAction(Intent.ACTION_VIEW); |
---|
214 | intent.addCategory(Intent.CATEGORY_BROWSABLE); |
---|
215 | intent.setData(Uri.parse("http://seguridad.cenditel.gob.ve/proyectos/tibisay-movil/ayuda-de-tibisay-movil/")); |
---|
216 | startActivity(intent); |
---|
217 | return true; |
---|
218 | default: |
---|
219 | return super.onOptionsItemSelected(item); |
---|
220 | } |
---|
221 | } |
---|
222 | |
---|
223 | |
---|
224 | private void testRepository(){ |
---|
225 | |
---|
226 | // this.keyChain = DirectKeyChain.getInstance(); |
---|
227 | // this.keyChain.setListView(this.viewHolder.aliases); |
---|
228 | // this.keyChain.setMasterActivity((Activity) this); |
---|
229 | // this.keyChain.choosePrivateKeyAlias(); |
---|
230 | |
---|
231 | Intent intent = new Intent(this, CertificateRepositoryActivity.class); |
---|
232 | startActivity(intent); |
---|
233 | } |
---|
234 | |
---|
235 | private void fileToSignHandwrittenSignature(){ |
---|
236 | Intent intent = new Intent(this, FileToSignHandwrittenSignatureActivity.class); |
---|
237 | startActivity(intent); |
---|
238 | } |
---|
239 | |
---|
240 | private void filesToPKCS7Sign(){ |
---|
241 | Intent intent = new Intent(this, FilesToPKCS7SignActivity.class); |
---|
242 | startActivity(intent); |
---|
243 | } |
---|
244 | |
---|
245 | private void filesToPDFSign(){ |
---|
246 | Intent intent = new Intent(this, FilesToPDFSignActivity.class); |
---|
247 | startActivity(intent); |
---|
248 | } |
---|
249 | |
---|
250 | |
---|
251 | // lanza activity para verificar un documento firmado |
---|
252 | private void verifyBDOCSignedFile(){ |
---|
253 | //Intent intent = new Intent(this, FileToSignHandwrittenSignatureActivity.class); |
---|
254 | Intent intent = new Intent(this, FileToVerifySignatureActivity.class); |
---|
255 | startActivity(intent); |
---|
256 | } |
---|
257 | |
---|
258 | // lanza activity para compartir un documento |
---|
259 | private void shareFile(String path){ |
---|
260 | Intent intent = new Intent(this, FileToShareActivity.class); |
---|
261 | |
---|
262 | intent.putExtra("path", path); |
---|
263 | |
---|
264 | startActivity(intent); |
---|
265 | } |
---|
266 | |
---|
267 | // lanza activity para cifrar un documento |
---|
268 | private void encryptFile(){ |
---|
269 | Intent intent = new Intent(this, FileToEncryptActivity.class); |
---|
270 | startActivity(intent); |
---|
271 | } |
---|
272 | |
---|
273 | |
---|
274 | // lanza activity para descifrar un documento |
---|
275 | private void decryptFile(){ |
---|
276 | Intent intent = new Intent(this, FileToDecryptActivity.class); |
---|
277 | startActivity(intent); |
---|
278 | } |
---|
279 | |
---|
280 | |
---|
281 | // lanza la activity para gestionar los certificados de destinarios (cifrado) |
---|
282 | private void manageRecipientCertificates() { |
---|
283 | Intent intent = new Intent(this, EncryptionCertificatesActivity.class); |
---|
284 | startActivity(intent); |
---|
285 | } |
---|
286 | |
---|
287 | |
---|
288 | //Crea dialogo de opciones para firma electronica |
---|
289 | public AlertDialog makeSignatureOptionsDialog() { |
---|
290 | final String[] option = new String[] {getString(R.string.firmar_man_pdf), getString(R.string.firmar_elec_pdf), getString(R.string.firmar_pkcs7) }; |
---|
291 | ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, |
---|
292 | android.R.layout.select_dialog_item, option); |
---|
293 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
---|
294 | |
---|
295 | builder.setTitle(getString(R.string.seleccione_opcion)); |
---|
296 | builder.setAdapter(adapter, new DialogInterface.OnClickListener() { |
---|
297 | |
---|
298 | public void onClick(DialogInterface dialog, int which) { |
---|
299 | |
---|
300 | switch (which) { |
---|
301 | case 0: // Firma Manuscrita PDF |
---|
302 | Log.i("DEBUG", "antes de activity call"); |
---|
303 | fileToSignHandwrittenSignature(); |
---|
304 | break; |
---|
305 | case 1: // Firma Electronica PDF |
---|
306 | filesToPDFSign(); |
---|
307 | break; |
---|
308 | case 2: // Firma PKCS7 |
---|
309 | filesToPKCS7Sign(); |
---|
310 | break; |
---|
311 | |
---|
312 | default: |
---|
313 | break; |
---|
314 | } |
---|
315 | } |
---|
316 | |
---|
317 | }); |
---|
318 | |
---|
319 | return builder.create(); |
---|
320 | } |
---|
321 | |
---|
322 | |
---|
323 | // lanza activity para preferencias |
---|
324 | private void preferences(){ |
---|
325 | Intent intent = new Intent(this, PreferencesActivity.class); |
---|
326 | startActivity(intent); |
---|
327 | } |
---|
328 | |
---|
329 | //Crea dialogo de opciones para compartir archivos |
---|
330 | public AlertDialog makeShareOptionsDialog() { |
---|
331 | final String[] option = new String[] {getString(R.string.share_pdf_signed), |
---|
332 | getString(R.string.share_bdoc_downloaded), getString(R.string.share_extracted_file_from_bdoc), |
---|
333 | getString(R.string.share_encrypted) }; |
---|
334 | ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, |
---|
335 | android.R.layout.select_dialog_item, option); |
---|
336 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
---|
337 | |
---|
338 | builder.setTitle(getString(R.string.seleccione_opcion)); |
---|
339 | builder.setAdapter(adapter, new DialogInterface.OnClickListener() { |
---|
340 | |
---|
341 | public void onClick(DialogInterface dialog, int which) { |
---|
342 | |
---|
343 | switch (which) { |
---|
344 | case 0: // Archivo Firmado |
---|
345 | Log.i("DEBUG", "antes de activity call"); |
---|
346 | shareFile("archivoFirmado"); |
---|
347 | break; |
---|
348 | case 1: // Archivos BDOC Descargados |
---|
349 | shareFile("bdocDescargado"); |
---|
350 | break; |
---|
351 | case 2: // Archivos extraídos de BDOC |
---|
352 | shareFile("extraidoDeBdoc"); |
---|
353 | break; |
---|
354 | |
---|
355 | case 3: // Archivos cifrados |
---|
356 | shareFile("cifrado"); |
---|
357 | break; |
---|
358 | default: |
---|
359 | break; |
---|
360 | } |
---|
361 | } |
---|
362 | |
---|
363 | }); |
---|
364 | |
---|
365 | return builder.create(); |
---|
366 | } |
---|
367 | |
---|
368 | //Crea dialogo de opciones para gestionar certificados |
---|
369 | public AlertDialog makeCertificateOptionsDialog() { |
---|
370 | ; |
---|
371 | final String[] option; |
---|
372 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH){ |
---|
373 | option = new String[] {getString(R.string.manage_personal_certificates), getString(R.string.manage_certificates_for_encryption) }; |
---|
374 | } else { |
---|
375 | option = new String[] {getString(R.string.manage_certificates_for_encryption) }; |
---|
376 | } |
---|
377 | |
---|
378 | ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, |
---|
379 | android.R.layout.select_dialog_item, option); |
---|
380 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
---|
381 | |
---|
382 | builder.setTitle(getString(R.string.seleccione_opcion)); |
---|
383 | builder.setAdapter(adapter, new DialogInterface.OnClickListener() { |
---|
384 | |
---|
385 | public void onClick(DialogInterface dialog, int which) { |
---|
386 | |
---|
387 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH){ |
---|
388 | |
---|
389 | switch (which) { |
---|
390 | case 0: // Certificados personales |
---|
391 | testRepository(); |
---|
392 | break; |
---|
393 | case 1: // Certificados para cifrado |
---|
394 | manageRecipientCertificates(); |
---|
395 | break; |
---|
396 | } |
---|
397 | |
---|
398 | } else { |
---|
399 | |
---|
400 | switch (which) { |
---|
401 | case 0: // Certificados para cifrado |
---|
402 | manageRecipientCertificates(); |
---|
403 | break; |
---|
404 | } |
---|
405 | |
---|
406 | } |
---|
407 | |
---|
408 | } |
---|
409 | |
---|
410 | }); |
---|
411 | |
---|
412 | return builder.create(); |
---|
413 | } |
---|
414 | |
---|
415 | } |
---|