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 | //public class TibisayMovilActivity extends KeyChainClientActivity { |
---|
22 | //implements OnItemClickListener, OnClickListener { |
---|
23 | public class TibisayMovilActivity extends Activity { |
---|
24 | |
---|
25 | |
---|
26 | public DirectKeyChain keyChain; |
---|
27 | |
---|
28 | @Override |
---|
29 | protected void onCreate(Bundle savedInstanceState) { |
---|
30 | super.onCreate(savedInstanceState); |
---|
31 | |
---|
32 | final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); |
---|
33 | setContentView(R.layout.activity_main); |
---|
34 | if(customTitleSupported) |
---|
35 | getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); |
---|
36 | |
---|
37 | // listview de funciones |
---|
38 | final ListView listViewFunctions = (ListView) findViewById(R.id.listViewFunctions); |
---|
39 | |
---|
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), |
---|
45 | getString(R.string.certificados), |
---|
46 | getString(R.string.preferencias) }; |
---|
47 | |
---|
48 | |
---|
49 | FunctionListAdapter ad = new FunctionListAdapter(this, values); |
---|
50 | listViewFunctions.setAdapter(ad); |
---|
51 | |
---|
52 | |
---|
53 | |
---|
54 | |
---|
55 | /*************** Dialogos de submenus *******************/ |
---|
56 | //Crear dialogo de opciones para firmar |
---|
57 | final AlertDialog sign_dialog = makeSignatureOptionsDialog(); |
---|
58 | |
---|
59 | //Crear dialogo de opciones para compartir archivo |
---|
60 | final AlertDialog share_dialog = makeShareOptionsDialog(); |
---|
61 | |
---|
62 | //Crear dialogo de opciones para compartir cifrar archivo |
---|
63 | final AlertDialog certificate_dialog = makeCertificateOptionsDialog(); |
---|
64 | |
---|
65 | |
---|
66 | listViewFunctions.setOnItemClickListener(new OnItemClickListener(){ |
---|
67 | |
---|
68 | @Override |
---|
69 | public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, |
---|
70 | long arg3) { |
---|
71 | |
---|
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); |
---|
78 | TextView c = (TextView)curr.findViewById(R.id.textListMainMenu); |
---|
79 | String function = c.getText().toString(); |
---|
80 | //Toast.makeText(context, function, duration).show(); |
---|
81 | |
---|
82 | // seleccion de firmar |
---|
83 | if(function.equals(getString(R.string.firmar))) { |
---|
84 | sign_dialog.show(); |
---|
85 | } |
---|
86 | |
---|
87 | // seleccion de verificar |
---|
88 | if(function.equals(getString(R.string.verificar))) { |
---|
89 | Toast.makeText(context, "VERIFICAR", duration).show(); |
---|
90 | verifyBDOCSignedFile(); |
---|
91 | } |
---|
92 | |
---|
93 | // seleccion de cifrar |
---|
94 | if(function.equals(getString(R.string.cifrar))) { |
---|
95 | Toast.makeText(context, "CIFRAR", duration).show(); |
---|
96 | encryptFile(); |
---|
97 | } |
---|
98 | |
---|
99 | |
---|
100 | // seleccion de gestionar certificados |
---|
101 | if (function.equals("Certificados")){ |
---|
102 | Toast.makeText(context, "Gestionar repositorio", duration).show(); |
---|
103 | |
---|
104 | certificate_dialog.show(); |
---|
105 | /* |
---|
106 | |
---|
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(); |
---|
113 | |
---|
114 | } |
---|
115 | |
---|
116 | //manageKeyChain(); |
---|
117 | |
---|
118 | // lanzar activity de gestion de repositorio |
---|
119 | testRepository(); |
---|
120 | |
---|
121 | */ |
---|
122 | } |
---|
123 | |
---|
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 | |
---|
129 | } |
---|
130 | // seleccion de firmar |
---|
131 | if(function.equals(getString(R.string.preferencias))) { |
---|
132 | preferences(); |
---|
133 | } |
---|
134 | |
---|
135 | } |
---|
136 | }); //setOnItemClickListener |
---|
137 | } // end onCreate |
---|
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 | |
---|
165 | // private void manageKeyChain(){ |
---|
166 | // // |
---|
167 | // //Intent intent = new Intent(this, PKCS12FilePickerActivity.class); |
---|
168 | // //startActivityForResult(intent, ActivityResult.IMPORT_CERTIFICATE); |
---|
169 | // //KeyChainStrategy.getInstance().choosePrivateKeyAlias(); |
---|
170 | // } |
---|
171 | |
---|
172 | private void testRepository(){ |
---|
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); |
---|
180 | startActivity(intent); |
---|
181 | } |
---|
182 | |
---|
183 | private void fileToSignHandwrittenSignature(){ |
---|
184 | Intent intent = new Intent(this, FileToSignHandwrittenSignatureActivity.class); |
---|
185 | startActivity(intent); |
---|
186 | } |
---|
187 | |
---|
188 | private void filesToPKCS7Sign(){ |
---|
189 | Intent intent = new Intent(this, FilesToPKCS7SignActivity.class); |
---|
190 | startActivity(intent); |
---|
191 | } |
---|
192 | |
---|
193 | |
---|
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 | } |
---|
200 | |
---|
201 | // lanza activity para compartir un documento |
---|
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 | } |
---|
209 | |
---|
210 | // lanza activity para cifrar un documento |
---|
211 | private void encryptFile(){ |
---|
212 | Intent intent = new Intent(this, FileToEncryptActivity.class); |
---|
213 | startActivity(intent); |
---|
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 | |
---|
222 | |
---|
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 |
---|
244 | filesToPKCS7Sign(); |
---|
245 | break; |
---|
246 | |
---|
247 | default: |
---|
248 | break; |
---|
249 | } |
---|
250 | } |
---|
251 | |
---|
252 | }); |
---|
253 | |
---|
254 | return builder.create(); |
---|
255 | } |
---|
256 | |
---|
257 | |
---|
258 | // lanza activity para preferencias |
---|
259 | private void preferences(){ |
---|
260 | Intent intent = new Intent(this, PreferencesActivity.class); |
---|
261 | startActivity(intent); |
---|
262 | } |
---|
263 | |
---|
264 | //Crea dialogo de opciones para compartir archivos |
---|
265 | public AlertDialog makeShareOptionsDialog() { |
---|
266 | final String[] option = new String[] {getString(R.string.share_pdf_signed), |
---|
267 | getString(R.string.share_bdoc_downloaded), getString(R.string.share_extracted_file_from_bdoc), |
---|
268 | getString(R.string.share_encrypted) }; |
---|
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 | |
---|
290 | case 3: // Archivos cifrados |
---|
291 | shareFile("cifrado"); |
---|
292 | break; |
---|
293 | default: |
---|
294 | break; |
---|
295 | } |
---|
296 | } |
---|
297 | |
---|
298 | }); |
---|
299 | |
---|
300 | return builder.create(); |
---|
301 | } |
---|
302 | |
---|
303 | //Crea dialogo de opciones para gestionar certificados |
---|
304 | public AlertDialog makeCertificateOptionsDialog() { |
---|
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 | |
---|
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) { |
---|
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 | } |
---|
332 | |
---|
333 | } else { |
---|
334 | |
---|
335 | switch (which) { |
---|
336 | case 0: // Certificados para cifrado |
---|
337 | manageRecipientCertificates(); |
---|
338 | break; |
---|
339 | } |
---|
340 | |
---|
341 | } |
---|
342 | |
---|
343 | } |
---|
344 | |
---|
345 | }); |
---|
346 | |
---|
347 | return builder.create(); |
---|
348 | } |
---|
349 | |
---|
350 | } |
---|