1 | package ve.gob.cenditel.tibisaymovil; |
---|
2 | |
---|
3 | import android.net.Uri; |
---|
4 | import android.os.Build; |
---|
5 | import android.os.Bundle; |
---|
6 | import android.app.Activity; |
---|
7 | import android.app.AlertDialog; |
---|
8 | import android.content.Context; |
---|
9 | import android.content.DialogInterface; |
---|
10 | import android.content.Intent; |
---|
11 | import android.util.Log; |
---|
12 | import android.view.Menu; |
---|
13 | import android.view.MenuItem; |
---|
14 | import android.view.View; |
---|
15 | import android.view.Window; |
---|
16 | import android.widget.AdapterView; |
---|
17 | import android.widget.AdapterView.OnItemClickListener; |
---|
18 | import android.widget.ArrayAdapter; |
---|
19 | import android.widget.ListView; |
---|
20 | import android.widget.TextView; |
---|
21 | import android.widget.Toast; |
---|
22 | |
---|
23 | |
---|
24 | public class TibisayMovilActivity extends Activity { |
---|
25 | |
---|
26 | |
---|
27 | public DirectKeyChain keyChain; |
---|
28 | |
---|
29 | @Override |
---|
30 | protected void onCreate(Bundle savedInstanceState) { |
---|
31 | super.onCreate(savedInstanceState); |
---|
32 | |
---|
33 | final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); |
---|
34 | setContentView(R.layout.activity_main); |
---|
35 | if(customTitleSupported) |
---|
36 | getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); |
---|
37 | |
---|
38 | // listview de funciones |
---|
39 | final ListView listViewFunctions = (ListView) findViewById(R.id.listViewFunctions); |
---|
40 | |
---|
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), |
---|
46 | getString(R.string.certificados), |
---|
47 | getString(R.string.preferencias) }; |
---|
48 | |
---|
49 | |
---|
50 | FunctionListAdapter ad = new FunctionListAdapter(this, values); |
---|
51 | listViewFunctions.setAdapter(ad); |
---|
52 | |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | /*************** Dialogos de submenus *******************/ |
---|
57 | //Crear dialogo de opciones para firmar |
---|
58 | final AlertDialog sign_dialog = makeSignatureOptionsDialog(); |
---|
59 | |
---|
60 | //Crear dialogo de opciones para compartir archivo |
---|
61 | final AlertDialog share_dialog = makeShareOptionsDialog(); |
---|
62 | |
---|
63 | //Crear dialogo de opciones para compartir cifrar archivo |
---|
64 | final AlertDialog certificate_dialog = makeCertificateOptionsDialog(); |
---|
65 | |
---|
66 | |
---|
67 | listViewFunctions.setOnItemClickListener(new OnItemClickListener(){ |
---|
68 | |
---|
69 | @Override |
---|
70 | public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, |
---|
71 | long arg3) { |
---|
72 | |
---|
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); |
---|
79 | TextView c = (TextView)curr.findViewById(R.id.textListMainMenu); |
---|
80 | String function = c.getText().toString(); |
---|
81 | //Toast.makeText(context, function, duration).show(); |
---|
82 | |
---|
83 | // seleccion de firmar |
---|
84 | if(function.equals(getString(R.string.firmar))) { |
---|
85 | sign_dialog.show(); |
---|
86 | } |
---|
87 | |
---|
88 | // seleccion de verificar |
---|
89 | if(function.equals(getString(R.string.verificar))) { |
---|
90 | //Toast.makeText(context, "VERIFICAR", duration).show(); |
---|
91 | verifyBDOCSignedFile(); |
---|
92 | } |
---|
93 | |
---|
94 | // seleccion de cifrar |
---|
95 | if(function.equals(getString(R.string.cifrar))) { |
---|
96 | //Toast.makeText(context, "CIFRAR", duration).show(); |
---|
97 | encryptFile(); |
---|
98 | } |
---|
99 | |
---|
100 | // seleccion de descifrar |
---|
101 | if(function.equals(getString(R.string.descifrar))) { |
---|
102 | //Toast.makeText(context, "DESCIFRAR", duration).show(); |
---|
103 | decryptFile(); |
---|
104 | } |
---|
105 | |
---|
106 | // seleccion de gestionar certificados |
---|
107 | if (function.equals(getString(R.string.certificados))){ |
---|
108 | //Toast.makeText(context, "Gestionar repositorio", duration).show(); |
---|
109 | certificate_dialog.show(); |
---|
110 | |
---|
111 | } |
---|
112 | |
---|
113 | // seleccion de compartir archivo |
---|
114 | if (function.equals(getString(R.string.compartir))){ |
---|
115 | //Toast.makeText(context, "Compartir Archivo", duration).show(); |
---|
116 | share_dialog.show(); |
---|
117 | |
---|
118 | } |
---|
119 | // seleccion de firmar |
---|
120 | if(function.equals(getString(R.string.preferencias))) { |
---|
121 | preferences(); |
---|
122 | } |
---|
123 | |
---|
124 | } |
---|
125 | }); //setOnItemClickListener |
---|
126 | } // end onCreate |
---|
127 | |
---|
128 | @Override |
---|
129 | public boolean onCreateOptionsMenu(Menu menu) { |
---|
130 | // Inflate the menu; this adds items to the action bar if it is present. |
---|
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 | } |
---|
152 | } |
---|
153 | |
---|
154 | |
---|
155 | private void testRepository(){ |
---|
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); |
---|
163 | startActivity(intent); |
---|
164 | } |
---|
165 | |
---|
166 | private void fileToSignHandwrittenSignature(){ |
---|
167 | Intent intent = new Intent(this, FileToSignHandwrittenSignatureActivity.class); |
---|
168 | startActivity(intent); |
---|
169 | } |
---|
170 | |
---|
171 | private void filesToPKCS7Sign(){ |
---|
172 | Intent intent = new Intent(this, FilesToPKCS7SignActivity.class); |
---|
173 | startActivity(intent); |
---|
174 | } |
---|
175 | |
---|
176 | private void filesToPDFSign(){ |
---|
177 | Intent intent = new Intent(this, FilesToPDFSignActivity.class); |
---|
178 | startActivity(intent); |
---|
179 | } |
---|
180 | |
---|
181 | |
---|
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 | } |
---|
188 | |
---|
189 | // lanza activity para compartir un documento |
---|
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 | } |
---|
197 | |
---|
198 | // lanza activity para cifrar un documento |
---|
199 | private void encryptFile(){ |
---|
200 | Intent intent = new Intent(this, FileToEncryptActivity.class); |
---|
201 | startActivity(intent); |
---|
202 | } |
---|
203 | |
---|
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 | |
---|
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 | |
---|
218 | |
---|
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 |
---|
237 | filesToPDFSign(); |
---|
238 | break; |
---|
239 | case 2: // Firma PKCS7 |
---|
240 | filesToPKCS7Sign(); |
---|
241 | break; |
---|
242 | |
---|
243 | default: |
---|
244 | break; |
---|
245 | } |
---|
246 | } |
---|
247 | |
---|
248 | }); |
---|
249 | |
---|
250 | return builder.create(); |
---|
251 | } |
---|
252 | |
---|
253 | |
---|
254 | // lanza activity para preferencias |
---|
255 | private void preferences(){ |
---|
256 | Intent intent = new Intent(this, PreferencesActivity.class); |
---|
257 | startActivity(intent); |
---|
258 | } |
---|
259 | |
---|
260 | //Crea dialogo de opciones para compartir archivos |
---|
261 | public AlertDialog makeShareOptionsDialog() { |
---|
262 | final String[] option = new String[] {getString(R.string.share_pdf_signed), |
---|
263 | getString(R.string.share_bdoc_downloaded), getString(R.string.share_extracted_file_from_bdoc), |
---|
264 | getString(R.string.share_encrypted) }; |
---|
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 | |
---|
286 | case 3: // Archivos cifrados |
---|
287 | shareFile("cifrado"); |
---|
288 | break; |
---|
289 | default: |
---|
290 | break; |
---|
291 | } |
---|
292 | } |
---|
293 | |
---|
294 | }); |
---|
295 | |
---|
296 | return builder.create(); |
---|
297 | } |
---|
298 | |
---|
299 | //Crea dialogo de opciones para gestionar certificados |
---|
300 | public AlertDialog makeCertificateOptionsDialog() { |
---|
301 | ; |
---|
302 | final String[] option; |
---|
303 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH){ |
---|
304 | option = new String[] {getString(R.string.manage_personal_certificates), getString(R.string.manage_certificates_for_encryption) }; |
---|
305 | } else { |
---|
306 | option = new String[] {getString(R.string.manage_certificates_for_encryption) }; |
---|
307 | } |
---|
308 | |
---|
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) { |
---|
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 | } |
---|
328 | |
---|
329 | } else { |
---|
330 | |
---|
331 | switch (which) { |
---|
332 | case 0: // Certificados para cifrado |
---|
333 | manageRecipientCertificates(); |
---|
334 | break; |
---|
335 | } |
---|
336 | |
---|
337 | } |
---|
338 | |
---|
339 | } |
---|
340 | |
---|
341 | }); |
---|
342 | |
---|
343 | return builder.create(); |
---|
344 | } |
---|
345 | |
---|
346 | } |
---|