1 | package ve.gob.cenditel.tibisaymovil; |
---|
2 | |
---|
3 | import ve.gob.cenditel.tibisaymovil.R.color; |
---|
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.View; |
---|
14 | import android.view.Window; |
---|
15 | import android.widget.AdapterView; |
---|
16 | import android.widget.AdapterView.OnItemClickListener; |
---|
17 | import android.widget.ArrayAdapter; |
---|
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 | |
---|
30 | final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); |
---|
31 | setContentView(R.layout.activity_main); |
---|
32 | if(customTitleSupported) |
---|
33 | getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); |
---|
34 | |
---|
35 | // listview de funciones |
---|
36 | final ListView listViewFunctions = (ListView) findViewById(R.id.listViewFunctions); |
---|
37 | |
---|
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); |
---|
48 | |
---|
49 | |
---|
50 | /*************** Dialogos de submenus *******************/ |
---|
51 | //Crear dialogo de opciones para firmar |
---|
52 | final AlertDialog sign_dialog = makeSignatureOptionsDialog(); |
---|
53 | |
---|
54 | //Crear dialogo de opciones para compartir archivo |
---|
55 | final AlertDialog share_dialog = makeShareOptionsDialog(); |
---|
56 | |
---|
57 | //Crear dialogo de opciones para compartir cifrar archivo |
---|
58 | final AlertDialog certificate_dialog = makeCertificateOptionsDialog(); |
---|
59 | |
---|
60 | |
---|
61 | listViewFunctions.setOnItemClickListener(new OnItemClickListener(){ |
---|
62 | |
---|
63 | @Override |
---|
64 | public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, |
---|
65 | long arg3) { |
---|
66 | // TODO Auto-generated method stub |
---|
67 | Context context = getApplicationContext(); |
---|
68 | //CharSequence text = "Click!"; |
---|
69 | int duration = Toast.LENGTH_SHORT; |
---|
70 | //Toast.makeText(context, text, duration).show(); |
---|
71 | |
---|
72 | View curr = arg0.getChildAt((int) arg3); |
---|
73 | TextView c = (TextView)curr.findViewById(R.id.textListMainMenu); |
---|
74 | String function = c.getText().toString(); |
---|
75 | //Toast.makeText(context, function, duration).show(); |
---|
76 | |
---|
77 | // seleccion de firmar |
---|
78 | if(function.equals(getString(R.string.firmar))) { |
---|
79 | sign_dialog.show(); |
---|
80 | } |
---|
81 | |
---|
82 | // seleccion de verificar |
---|
83 | if(function.equals(getString(R.string.verificar))) { |
---|
84 | Toast.makeText(context, "VERIFICAR", duration).show(); |
---|
85 | verifyBDOCSignedFile(); |
---|
86 | } |
---|
87 | |
---|
88 | // seleccion de cifrar |
---|
89 | if(function.equals(getString(R.string.cifrar))) { |
---|
90 | Toast.makeText(context, "CIFRAR", duration).show(); |
---|
91 | encryptFile(); |
---|
92 | } |
---|
93 | |
---|
94 | |
---|
95 | // seleccion de gestionar certificados |
---|
96 | if (function.equals("Certificados")){ |
---|
97 | Toast.makeText(context, "Gestionar repositorio", duration).show(); |
---|
98 | |
---|
99 | certificate_dialog.show(); |
---|
100 | /* |
---|
101 | |
---|
102 | // Chequeo de version del API de Android para creacion de repositorio |
---|
103 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH){ |
---|
104 | //RelativeLayout certTab = (RelativeLayout) this.findViewById(R.id.linetab2); |
---|
105 | //certTab.setVisibility(View.VISIBLE); |
---|
106 | //this.tabsListener.setKeyChainController(this.keyChainController); |
---|
107 | Toast.makeText(context, "API < 4.0", duration).show(); |
---|
108 | } |
---|
109 | |
---|
110 | //manageKeyChain(); |
---|
111 | |
---|
112 | // lanzar activity de gestion de repositorio |
---|
113 | testRepository(); |
---|
114 | |
---|
115 | */ |
---|
116 | } |
---|
117 | |
---|
118 | // seleccion de compartir archivo |
---|
119 | if (function.equals(getString(R.string.compartir))){ |
---|
120 | Toast.makeText(context, "Compartir Archivo", duration).show(); |
---|
121 | share_dialog.show(); |
---|
122 | |
---|
123 | } |
---|
124 | |
---|
125 | } |
---|
126 | }); //setOnItemClickListener |
---|
127 | } // end onCreate |
---|
128 | |
---|
129 | @Override |
---|
130 | public boolean onCreateOptionsMenu(Menu menu) { |
---|
131 | // Inflate the menu; this adds items to the action bar if it is present. |
---|
132 | getMenuInflater().inflate(R.menu.main, menu); |
---|
133 | return true; |
---|
134 | } |
---|
135 | |
---|
136 | /* |
---|
137 | @Override |
---|
138 | public void setAlias(String alias) { |
---|
139 | |
---|
140 | if (alias == null) { |
---|
141 | finish(); |
---|
142 | return; |
---|
143 | } |
---|
144 | |
---|
145 | this.privateKeyAlias = alias; |
---|
146 | |
---|
147 | //Intent intent = new Intent(this, CertValidatorActivity.class); |
---|
148 | //intent.putExtra(IntentExtraField.ALIAS, alias); |
---|
149 | //intent.putParcelableArrayListExtra(IntentExtraField.FILES, TypeUtils.convertToUriArrayList(this.selected)); |
---|
150 | //startActivityForResult(intent, ActivityResult.CHECK_CERTIFICATE_VALIDITY); |
---|
151 | |
---|
152 | } |
---|
153 | */ |
---|
154 | |
---|
155 | // private void manageKeyChain(){ |
---|
156 | // // |
---|
157 | // //Intent intent = new Intent(this, PKCS12FilePickerActivity.class); |
---|
158 | // //startActivityForResult(intent, ActivityResult.IMPORT_CERTIFICATE); |
---|
159 | // //KeyChainStrategy.getInstance().choosePrivateKeyAlias(); |
---|
160 | // } |
---|
161 | |
---|
162 | private void testRepository(){ |
---|
163 | Intent intent = new Intent(this, CertificateRepositoryActivity.class); |
---|
164 | startActivity(intent); |
---|
165 | } |
---|
166 | |
---|
167 | private void fileToSignHandwrittenSignature(){ |
---|
168 | Intent intent = new Intent(this, FileToSignHandwrittenSignatureActivity.class); |
---|
169 | startActivity(intent); |
---|
170 | } |
---|
171 | |
---|
172 | |
---|
173 | // lanza activity para verificar un documento firmado |
---|
174 | private void verifyBDOCSignedFile(){ |
---|
175 | //Intent intent = new Intent(this, FileToSignHandwrittenSignatureActivity.class); |
---|
176 | Intent intent = new Intent(this, FileToVerifySignatureActivity.class); |
---|
177 | startActivity(intent); |
---|
178 | } |
---|
179 | |
---|
180 | // lanza activity para compartir un documento |
---|
181 | private void shareFile(String path){ |
---|
182 | Intent intent = new Intent(this, FileToShareActivity.class); |
---|
183 | |
---|
184 | intent.putExtra("path", path); |
---|
185 | |
---|
186 | startActivity(intent); |
---|
187 | } |
---|
188 | |
---|
189 | // lanza activity para cifrar un documento |
---|
190 | private void encryptFile(){ |
---|
191 | Intent intent = new Intent(this, FileToEncryptActivity.class); |
---|
192 | startActivity(intent); |
---|
193 | } |
---|
194 | |
---|
195 | // lanza la activity para gestionar los certificados de destinarios (cifrado) |
---|
196 | private void manageRecipientCertificates() { |
---|
197 | Intent intent = new Intent(this, EncryptionCertificatesActivity.class); |
---|
198 | startActivity(intent); |
---|
199 | } |
---|
200 | |
---|
201 | |
---|
202 | //Crea dialogo de opciones para firma electronica |
---|
203 | public AlertDialog makeSignatureOptionsDialog() { |
---|
204 | final String[] option = new String[] {getString(R.string.firmar_man_pdf), getString(R.string.firmar_elec_pdf), getString(R.string.firmar_pkcs7) }; |
---|
205 | ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, |
---|
206 | android.R.layout.select_dialog_item, option); |
---|
207 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
---|
208 | |
---|
209 | builder.setTitle(getString(R.string.seleccione_opcion)); |
---|
210 | builder.setAdapter(adapter, new DialogInterface.OnClickListener() { |
---|
211 | |
---|
212 | public void onClick(DialogInterface dialog, int which) { |
---|
213 | |
---|
214 | switch (which) { |
---|
215 | case 0: // Firma Manuscrita PDF |
---|
216 | Log.i("DEBUG", "antes de activity call"); |
---|
217 | fileToSignHandwrittenSignature(); |
---|
218 | break; |
---|
219 | case 1: // Firma Electronica PDF |
---|
220 | |
---|
221 | break; |
---|
222 | case 2: // Firma PKCS7 |
---|
223 | |
---|
224 | break; |
---|
225 | |
---|
226 | default: |
---|
227 | break; |
---|
228 | } |
---|
229 | } |
---|
230 | |
---|
231 | }); |
---|
232 | |
---|
233 | return builder.create(); |
---|
234 | } |
---|
235 | |
---|
236 | //Crea dialogo de opciones para compartir archivos |
---|
237 | public AlertDialog makeShareOptionsDialog() { |
---|
238 | final String[] option = new String[] {getString(R.string.share_pdf_signed), |
---|
239 | getString(R.string.share_bdoc_downloaded), getString(R.string.share_extracted_file_from_bdoc), |
---|
240 | getString(R.string.share_encrypted) }; |
---|
241 | ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, |
---|
242 | android.R.layout.select_dialog_item, option); |
---|
243 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
---|
244 | |
---|
245 | builder.setTitle(getString(R.string.seleccione_opcion)); |
---|
246 | builder.setAdapter(adapter, new DialogInterface.OnClickListener() { |
---|
247 | |
---|
248 | public void onClick(DialogInterface dialog, int which) { |
---|
249 | |
---|
250 | switch (which) { |
---|
251 | case 0: // Archivo Firmado |
---|
252 | Log.i("DEBUG", "antes de activity call"); |
---|
253 | shareFile("archivoFirmado"); |
---|
254 | break; |
---|
255 | case 1: // Archivos BDOC Descargados |
---|
256 | shareFile("bdocDescargado"); |
---|
257 | break; |
---|
258 | case 2: // Archivos extraídos de BDOC |
---|
259 | shareFile("extraidoDeBdoc"); |
---|
260 | break; |
---|
261 | |
---|
262 | case 3: // Archivos cifrados |
---|
263 | shareFile("cifrado"); |
---|
264 | break; |
---|
265 | default: |
---|
266 | break; |
---|
267 | } |
---|
268 | } |
---|
269 | |
---|
270 | }); |
---|
271 | |
---|
272 | return builder.create(); |
---|
273 | } |
---|
274 | |
---|
275 | //Crea dialogo de opciones para gestionar certificados |
---|
276 | public AlertDialog makeCertificateOptionsDialog() { |
---|
277 | final String[] option = new String[] {getString(R.string.manage_personal_certificates), getString(R.string.manage_certificates_for_encryption) }; |
---|
278 | ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, |
---|
279 | android.R.layout.select_dialog_item, option); |
---|
280 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
---|
281 | |
---|
282 | builder.setTitle(getString(R.string.seleccione_opcion)); |
---|
283 | builder.setAdapter(adapter, new DialogInterface.OnClickListener() { |
---|
284 | |
---|
285 | public void onClick(DialogInterface dialog, int which) { |
---|
286 | |
---|
287 | switch (which) { |
---|
288 | case 0: // Certificados personales |
---|
289 | Log.i("DEBUG", "antes de activity call"); |
---|
290 | |
---|
291 | break; |
---|
292 | case 1: // Certificados para cifrado |
---|
293 | Toast.makeText(getApplicationContext(), "Lanzar certificados de destinatarios", Toast.LENGTH_SHORT).show(); |
---|
294 | manageRecipientCertificates(); |
---|
295 | break; |
---|
296 | |
---|
297 | default: |
---|
298 | break; |
---|
299 | } |
---|
300 | } |
---|
301 | |
---|
302 | }); |
---|
303 | |
---|
304 | return builder.create(); |
---|
305 | } |
---|
306 | |
---|
307 | } |
---|