1 | package ve.gob.cenditel.tibisaymovil; |
---|
2 | |
---|
3 | import android.os.Build; |
---|
4 | import android.os.Bundle; |
---|
5 | import android.app.Activity; |
---|
6 | import android.app.AlertDialog; |
---|
7 | import android.content.Context; |
---|
8 | import android.content.DialogInterface; |
---|
9 | import android.content.Intent; |
---|
10 | import android.util.Log; |
---|
11 | import android.view.Menu; |
---|
12 | import android.view.View; |
---|
13 | import android.view.Window; |
---|
14 | import android.widget.AdapterView; |
---|
15 | import android.widget.AdapterView.OnItemClickListener; |
---|
16 | import android.widget.ArrayAdapter; |
---|
17 | import android.widget.ListView; |
---|
18 | import android.widget.TextView; |
---|
19 | import android.widget.Toast; |
---|
20 | |
---|
21 | |
---|
22 | public class TibisayMovilActivity extends Activity { |
---|
23 | |
---|
24 | |
---|
25 | public DirectKeyChain keyChain; |
---|
26 | |
---|
27 | @Override |
---|
28 | protected void onCreate(Bundle savedInstanceState) { |
---|
29 | super.onCreate(savedInstanceState); |
---|
30 | |
---|
31 | final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); |
---|
32 | setContentView(R.layout.activity_main); |
---|
33 | if(customTitleSupported) |
---|
34 | getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); |
---|
35 | |
---|
36 | // listview de funciones |
---|
37 | final ListView listViewFunctions = (ListView) findViewById(R.id.listViewFunctions); |
---|
38 | |
---|
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), |
---|
44 | getString(R.string.certificados), |
---|
45 | getString(R.string.preferencias) }; |
---|
46 | |
---|
47 | |
---|
48 | FunctionListAdapter ad = new FunctionListAdapter(this, values); |
---|
49 | listViewFunctions.setAdapter(ad); |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | |
---|
54 | /*************** Dialogos de submenus *******************/ |
---|
55 | //Crear dialogo de opciones para firmar |
---|
56 | final AlertDialog sign_dialog = makeSignatureOptionsDialog(); |
---|
57 | |
---|
58 | //Crear dialogo de opciones para compartir archivo |
---|
59 | final AlertDialog share_dialog = makeShareOptionsDialog(); |
---|
60 | |
---|
61 | //Crear dialogo de opciones para compartir cifrar archivo |
---|
62 | final AlertDialog certificate_dialog = makeCertificateOptionsDialog(); |
---|
63 | |
---|
64 | |
---|
65 | listViewFunctions.setOnItemClickListener(new OnItemClickListener(){ |
---|
66 | |
---|
67 | @Override |
---|
68 | public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, |
---|
69 | long arg3) { |
---|
70 | |
---|
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); |
---|
77 | TextView c = (TextView)curr.findViewById(R.id.textListMainMenu); |
---|
78 | String function = c.getText().toString(); |
---|
79 | //Toast.makeText(context, function, duration).show(); |
---|
80 | |
---|
81 | // seleccion de firmar |
---|
82 | if(function.equals(getString(R.string.firmar))) { |
---|
83 | sign_dialog.show(); |
---|
84 | } |
---|
85 | |
---|
86 | // seleccion de verificar |
---|
87 | if(function.equals(getString(R.string.verificar))) { |
---|
88 | Toast.makeText(context, "VERIFICAR", duration).show(); |
---|
89 | verifyBDOCSignedFile(); |
---|
90 | } |
---|
91 | |
---|
92 | // seleccion de cifrar |
---|
93 | if(function.equals(getString(R.string.cifrar))) { |
---|
94 | Toast.makeText(context, "CIFRAR", duration).show(); |
---|
95 | encryptFile(); |
---|
96 | } |
---|
97 | |
---|
98 | // seleccion de descifrar |
---|
99 | if(function.equals(getString(R.string.descifrar))) { |
---|
100 | Toast.makeText(context, "DESCIFRAR", duration).show(); |
---|
101 | decryptFile(); |
---|
102 | } |
---|
103 | |
---|
104 | // seleccion de gestionar certificados |
---|
105 | if (function.equals(getString(R.string.certificados))){ |
---|
106 | Toast.makeText(context, "Gestionar repositorio", duration).show(); |
---|
107 | certificate_dialog.show(); |
---|
108 | |
---|
109 | } |
---|
110 | |
---|
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 | } |
---|
117 | // seleccion de firmar |
---|
118 | if(function.equals(getString(R.string.preferencias))) { |
---|
119 | preferences(); |
---|
120 | } |
---|
121 | |
---|
122 | } |
---|
123 | }); //setOnItemClickListener |
---|
124 | } // end onCreate |
---|
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 | |
---|
133 | |
---|
134 | private void testRepository(){ |
---|
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); |
---|
142 | startActivity(intent); |
---|
143 | } |
---|
144 | |
---|
145 | private void fileToSignHandwrittenSignature(){ |
---|
146 | Intent intent = new Intent(this, FileToSignHandwrittenSignatureActivity.class); |
---|
147 | startActivity(intent); |
---|
148 | } |
---|
149 | |
---|
150 | private void filesToPKCS7Sign(){ |
---|
151 | Intent intent = new Intent(this, FilesToPKCS7SignActivity.class); |
---|
152 | startActivity(intent); |
---|
153 | } |
---|
154 | |
---|
155 | private void filesToPDFSign(){ |
---|
156 | Intent intent = new Intent(this, FilesToPDFSignActivity.class); |
---|
157 | startActivity(intent); |
---|
158 | } |
---|
159 | |
---|
160 | |
---|
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 | } |
---|
167 | |
---|
168 | // lanza activity para compartir un documento |
---|
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 | } |
---|
176 | |
---|
177 | // lanza activity para cifrar un documento |
---|
178 | private void encryptFile(){ |
---|
179 | Intent intent = new Intent(this, FileToEncryptActivity.class); |
---|
180 | startActivity(intent); |
---|
181 | } |
---|
182 | |
---|
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 | |
---|
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 | |
---|
197 | |
---|
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 |
---|
216 | filesToPDFSign(); |
---|
217 | break; |
---|
218 | case 2: // Firma PKCS7 |
---|
219 | filesToPKCS7Sign(); |
---|
220 | break; |
---|
221 | |
---|
222 | default: |
---|
223 | break; |
---|
224 | } |
---|
225 | } |
---|
226 | |
---|
227 | }); |
---|
228 | |
---|
229 | return builder.create(); |
---|
230 | } |
---|
231 | |
---|
232 | |
---|
233 | // lanza activity para preferencias |
---|
234 | private void preferences(){ |
---|
235 | Intent intent = new Intent(this, PreferencesActivity.class); |
---|
236 | startActivity(intent); |
---|
237 | } |
---|
238 | |
---|
239 | //Crea dialogo de opciones para compartir archivos |
---|
240 | public AlertDialog makeShareOptionsDialog() { |
---|
241 | final String[] option = new String[] {getString(R.string.share_pdf_signed), |
---|
242 | getString(R.string.share_bdoc_downloaded), getString(R.string.share_extracted_file_from_bdoc), |
---|
243 | getString(R.string.share_encrypted) }; |
---|
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 | |
---|
265 | case 3: // Archivos cifrados |
---|
266 | shareFile("cifrado"); |
---|
267 | break; |
---|
268 | default: |
---|
269 | break; |
---|
270 | } |
---|
271 | } |
---|
272 | |
---|
273 | }); |
---|
274 | |
---|
275 | return builder.create(); |
---|
276 | } |
---|
277 | |
---|
278 | //Crea dialogo de opciones para gestionar certificados |
---|
279 | public AlertDialog makeCertificateOptionsDialog() { |
---|
280 | ; |
---|
281 | final String[] option; |
---|
282 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH){ |
---|
283 | option = new String[] {getString(R.string.manage_personal_certificates), getString(R.string.manage_certificates_for_encryption) }; |
---|
284 | } else { |
---|
285 | option = new String[] {getString(R.string.manage_certificates_for_encryption) }; |
---|
286 | } |
---|
287 | |
---|
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) { |
---|
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 | } |
---|
307 | |
---|
308 | } else { |
---|
309 | |
---|
310 | switch (which) { |
---|
311 | case 0: // Certificados para cifrado |
---|
312 | manageRecipientCertificates(); |
---|
313 | break; |
---|
314 | } |
---|
315 | |
---|
316 | } |
---|
317 | |
---|
318 | } |
---|
319 | |
---|
320 | }); |
---|
321 | |
---|
322 | return builder.create(); |
---|
323 | } |
---|
324 | |
---|
325 | } |
---|