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 java.io.File; |
---|
24 | import java.text.SimpleDateFormat; |
---|
25 | import java.util.ArrayList; |
---|
26 | import java.util.Collections; |
---|
27 | import java.util.Date; |
---|
28 | |
---|
29 | import ve.gob.cenditel.tibisaymovil.R; |
---|
30 | import android.app.Activity; |
---|
31 | import android.app.AlertDialog; |
---|
32 | import android.content.DialogInterface; |
---|
33 | import android.content.Intent; |
---|
34 | import android.graphics.drawable.Drawable; |
---|
35 | import android.net.Uri; |
---|
36 | import android.os.Bundle; |
---|
37 | import android.os.Environment; |
---|
38 | import android.util.Log; |
---|
39 | import android.view.LayoutInflater; |
---|
40 | import android.view.View; |
---|
41 | import android.view.ViewGroup; |
---|
42 | import android.view.View.OnClickListener; |
---|
43 | import android.view.Window; |
---|
44 | import android.webkit.MimeTypeMap; |
---|
45 | import android.widget.AdapterView; |
---|
46 | import android.widget.ArrayAdapter; |
---|
47 | import android.widget.BaseAdapter; |
---|
48 | import android.widget.ImageView; |
---|
49 | import android.widget.LinearLayout; |
---|
50 | import android.widget.ListView; |
---|
51 | import android.widget.RadioButton; |
---|
52 | import android.widget.TextView; |
---|
53 | import android.widget.AdapterView.OnItemClickListener; |
---|
54 | import android.widget.Toast; |
---|
55 | |
---|
56 | public class FileToDecryptActivity extends Activity implements OnItemClickListener, OnClickListener { |
---|
57 | |
---|
58 | private File cwd; |
---|
59 | private File selected; |
---|
60 | private FileBrowserView viewHolder; |
---|
61 | private FileListAdapter listAdapter; |
---|
62 | private String filterMImeType = "application/*"; |
---|
63 | |
---|
64 | // cadena que mantiene la ruta del archivo a compartir |
---|
65 | private String fileToDecrypt = null; |
---|
66 | |
---|
67 | @Override |
---|
68 | protected void onCreate(Bundle savedInstanceState) { |
---|
69 | //Estilando la barra de titulo |
---|
70 | final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); |
---|
71 | |
---|
72 | super.onCreate(savedInstanceState); |
---|
73 | |
---|
74 | this.viewHolder = new FileBrowserView(); |
---|
75 | |
---|
76 | if (savedInstanceState != null) { |
---|
77 | if(savedInstanceState.getString("selected") != null) |
---|
78 | this.selected = new File(savedInstanceState.getString("selected")); |
---|
79 | |
---|
80 | if (this.selected != null) { |
---|
81 | |
---|
82 | FileToDecryptActivity.this.updateButton |
---|
83 | (FileToDecryptActivity.this.viewHolder.accept,true); |
---|
84 | |
---|
85 | } |
---|
86 | |
---|
87 | this.cwd = new File(savedInstanceState.getString("cwd")); |
---|
88 | this.viewHolder.fileList.setAdapter(this.listAdapter = new FileListAdapter(this.cwd.getAbsolutePath(), filterMImeType)); |
---|
89 | |
---|
90 | } else { |
---|
91 | this.selected = null; |
---|
92 | this.viewHolder.fileList.setAdapter(this.listAdapter = new FileListAdapter()); |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | boolean enabled = false; |
---|
97 | if (this.selected != null) |
---|
98 | enabled = this.viewHolder.accept.isEnabled(); |
---|
99 | |
---|
100 | FileToDecryptActivity.this.updateButton |
---|
101 | (FileToDecryptActivity.this.viewHolder.accept,enabled); |
---|
102 | |
---|
103 | //Estilando Barra de titulo |
---|
104 | if(customTitleSupported) |
---|
105 | getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | /** |
---|
110 | * Provides the data to be shown in the file browser ListView. |
---|
111 | * |
---|
112 | * @author José M. Prieto (jmprieto@emergya.com) |
---|
113 | */ |
---|
114 | private class FileListAdapter extends BaseAdapter { |
---|
115 | |
---|
116 | private final ArrayList<File> directories; |
---|
117 | private final ArrayList<File> files; |
---|
118 | |
---|
119 | private FileListAdapter() { |
---|
120 | this("/",filterMImeType); |
---|
121 | } |
---|
122 | |
---|
123 | private FileListAdapter(String location) { |
---|
124 | this(location, ""); |
---|
125 | } |
---|
126 | |
---|
127 | private FileListAdapter(String location, String filterMimeType) { |
---|
128 | |
---|
129 | directories = new ArrayList<File>(); |
---|
130 | files = new ArrayList<File>(); |
---|
131 | |
---|
132 | //Obtiene etiqueta que se colocará antes del path que visualizará el usuario |
---|
133 | String toPathText = FileToDecryptActivity.this.getString(R.string.pathstring)+": "; |
---|
134 | //Coloca el texto de la etiqueta en la vista |
---|
135 | FileToDecryptActivity.this.viewHolder.pathString.setText(toPathText); |
---|
136 | //Coloca el texto con el path actual |
---|
137 | FileToDecryptActivity.this.viewHolder.path.setText(location); |
---|
138 | //Crea un objeto file cwd con la ubicacion dada en location |
---|
139 | FileToDecryptActivity.this.cwd = new File(location); |
---|
140 | //Obtiene el directorio padre del objeto file cwd |
---|
141 | File parent = FileToDecryptActivity.this.cwd.getParentFile(); |
---|
142 | //Si tiene un padre, lo agrega en la posición cero de la lista de directorios |
---|
143 | |
---|
144 | if (parent != null) { |
---|
145 | directories.add(0, parent); |
---|
146 | } |
---|
147 | |
---|
148 | //Crea un arreglo con las lista de archivos contenidos en el directorio cwd |
---|
149 | File[] ls = FileToDecryptActivity.this.cwd.listFiles(); |
---|
150 | if (ls != null) { |
---|
151 | for (File f : ls) { //recorre todos los archivos contenidos en el directorio |
---|
152 | |
---|
153 | if (FsUtils.isHiddenOrNotReadable(f)) { // Si son ocultos no hace nada |
---|
154 | continue; |
---|
155 | } |
---|
156 | // Si son directorios los agrega a la lista de directorios a partir de la posición 1 |
---|
157 | // En la posición 0 se encuentra el directorio padre |
---|
158 | if (f.isDirectory()) { |
---|
159 | directories.add(f); |
---|
160 | } else // De lo contrario lo agrega a la lista de archivos |
---|
161 | { |
---|
162 | //Valida tipo de archivo a mostrar |
---|
163 | Uri selectedUri = Uri.fromFile(f); |
---|
164 | String fileExtension = MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString()); |
---|
165 | String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension); |
---|
166 | |
---|
167 | // Toast.makeText(FileToDecryptActivity.this, |
---|
168 | // "FileExtension: " + fileExtension + "\n" + |
---|
169 | // "MimeType: " + mimeType, |
---|
170 | // Toast.LENGTH_LONG).show(); |
---|
171 | |
---|
172 | |
---|
173 | // en principio no filtrar ningun archivo |
---|
174 | if(filterMimeType.isEmpty() || filterMimeType == mimeType || fileExtension.equals("cdoc")) |
---|
175 | files.add(f); |
---|
176 | |
---|
177 | } |
---|
178 | } |
---|
179 | } |
---|
180 | |
---|
181 | Collections.sort(directories); // Ordena los directorios alfabeticamente |
---|
182 | Collections.sort(files); // Ordena los archivos alfabeticamente |
---|
183 | } |
---|
184 | |
---|
185 | /** |
---|
186 | * Retorna cantidad total de elementos que se listarán en el directorio. |
---|
187 | */ |
---|
188 | @Override |
---|
189 | public int getCount() { |
---|
190 | |
---|
191 | return directories.size() + files.size(); |
---|
192 | |
---|
193 | } |
---|
194 | |
---|
195 | /** |
---|
196 | * Dada una posición en el listado del directorio, retorna un archivo o directorio |
---|
197 | * según corresponda. |
---|
198 | */ |
---|
199 | @Override |
---|
200 | public File getItem(int position) { |
---|
201 | |
---|
202 | if (position < directories.size()) { |
---|
203 | return directories.get(position); |
---|
204 | } else { |
---|
205 | return files.get(position - directories.size()); |
---|
206 | } |
---|
207 | } |
---|
208 | |
---|
209 | /** |
---|
210 | * Retorna un código hash para el archivo, permite comparar si dos archivos son los mismos |
---|
211 | */ |
---|
212 | @Override |
---|
213 | public long getItemId(int position) { |
---|
214 | |
---|
215 | return getItem(position).hashCode(); |
---|
216 | } |
---|
217 | |
---|
218 | /** |
---|
219 | * Crea la visualización de cada item del fileBrowser |
---|
220 | */ |
---|
221 | @Override |
---|
222 | public View getView(int position, View convertView, ViewGroup parent) { |
---|
223 | |
---|
224 | //Crea la vista de cada fila del filebrowser a partir del layout |
---|
225 | if (convertView == null) { |
---|
226 | LayoutInflater inflater = LayoutInflater.from(FileToDecryptActivity.this); |
---|
227 | convertView = inflater.inflate(R.layout.file_to_verify_bdoc_signature_item, parent, false); |
---|
228 | } |
---|
229 | |
---|
230 | // Se enlaza a cada componente del layout |
---|
231 | ImageView image = (ImageView) convertView.findViewById(R.id.type_image); |
---|
232 | TextView fileName = (TextView) convertView.findViewById(R.id.filename_text); |
---|
233 | TextView modified = (TextView) convertView.findViewById(R.id.filename_modified); |
---|
234 | |
---|
235 | // Se obtiene el archivo ubicado en position |
---|
236 | File file = getItem(position); |
---|
237 | |
---|
238 | //RadioButton |
---|
239 | RadioButton radio = (RadioButton) convertView.findViewById(R.id.file_radio); |
---|
240 | radio.setFocusable(false); |
---|
241 | |
---|
242 | // Se asignan los iconos según el tipo de archivo y se oculta el radio en los directorios |
---|
243 | if (file.isDirectory()) { |
---|
244 | image.setImageResource(R.drawable.ic_carpeta_verde); |
---|
245 | radio.setVisibility(View.INVISIBLE); |
---|
246 | radio.setChecked(false); |
---|
247 | } else { |
---|
248 | image.setImageResource(R.drawable.ic_archivo_verde); |
---|
249 | radio.setVisibility(View.VISIBLE); |
---|
250 | |
---|
251 | if (FileToDecryptActivity.this.selected == null || |
---|
252 | FileToDecryptActivity.this.selected.hashCode() != file.hashCode()){ |
---|
253 | radio.setChecked(false); |
---|
254 | } else{ |
---|
255 | radio.setChecked(true); |
---|
256 | } |
---|
257 | } |
---|
258 | |
---|
259 | // Si es el directorio que hace referencia al padre le coloca como nombre ".." |
---|
260 | if (file.isDirectory() && position == 0 && ! "/".equals(FileToDecryptActivity.this.cwd.getAbsolutePath())) { |
---|
261 | fileName.setText(".."); |
---|
262 | } else { |
---|
263 | fileName.setText(file.getName()); |
---|
264 | } |
---|
265 | |
---|
266 | |
---|
267 | //Datos de modificación del archivo |
---|
268 | SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); |
---|
269 | Date date = new Date(file.lastModified()); |
---|
270 | |
---|
271 | String dateString = FileToDecryptActivity.this.getString(R.string.modified)+": "; |
---|
272 | if (file.lastModified()>0) |
---|
273 | modified.setText(dateString+sdf.format(date)); |
---|
274 | else |
---|
275 | modified.setText(dateString+"-"); |
---|
276 | |
---|
277 | return convertView; |
---|
278 | } |
---|
279 | |
---|
280 | /** |
---|
281 | * Controla la selección de cada item del fileBrowser |
---|
282 | */ |
---|
283 | public void select(ListView parent, int position) { |
---|
284 | |
---|
285 | File item = getItem(position); |
---|
286 | //Si es un directorio el seleccionado se hace un llamado del fileBrowser del directorio |
---|
287 | if (item.isDirectory()) { |
---|
288 | parent.setAdapter(FileToDecryptActivity.this.listAdapter = new FileListAdapter(item.getAbsolutePath(), filterMImeType)); |
---|
289 | } else { // Si es un archivo |
---|
290 | |
---|
291 | //Se agrega el archivo a la lista de seleccionados si no se encuentra en la misma |
---|
292 | if (FileToDecryptActivity.this.selected == null || |
---|
293 | FileToDecryptActivity.this.selected.hashCode() != item.hashCode()){ |
---|
294 | |
---|
295 | FileToDecryptActivity.this.selected = item; |
---|
296 | |
---|
297 | FileToDecryptActivity.this.updateButton(FileToDecryptActivity.this.viewHolder.accept,true); |
---|
298 | |
---|
299 | } |
---|
300 | else{ // De lo contrario se elimina de la lista de seleccionados |
---|
301 | |
---|
302 | FileToDecryptActivity.this.selected = null; |
---|
303 | FileToDecryptActivity.this.updateButton(FileToDecryptActivity.this.viewHolder.accept,false); |
---|
304 | |
---|
305 | } |
---|
306 | notifyDataSetChanged(); |
---|
307 | } |
---|
308 | } |
---|
309 | } |
---|
310 | |
---|
311 | |
---|
312 | |
---|
313 | |
---|
314 | @Override |
---|
315 | protected void onSaveInstanceState(Bundle outState) { |
---|
316 | super.onSaveInstanceState(outState); |
---|
317 | |
---|
318 | outState.putParcelable("intent", this.getIntent()); |
---|
319 | outState.putString("cwd", this.cwd.getAbsolutePath()); |
---|
320 | if(this.selected != null) |
---|
321 | outState.putString("selected", this.selected.getAbsolutePath()); |
---|
322 | |
---|
323 | } |
---|
324 | |
---|
325 | private void updateButton(View v, boolean bool) { |
---|
326 | try{ |
---|
327 | |
---|
328 | v.setEnabled(bool); |
---|
329 | if (v instanceof TextView){ |
---|
330 | Drawable icon = ((TextView)v).getCompoundDrawables()[1]; |
---|
331 | if (icon!=null) |
---|
332 | if (bool) |
---|
333 | icon.setAlpha(255); |
---|
334 | else |
---|
335 | icon.setAlpha(127); |
---|
336 | } |
---|
337 | if (v instanceof ImageView){ |
---|
338 | ImageView result = (ImageView) v; |
---|
339 | if (bool) |
---|
340 | result.setAlpha(255); |
---|
341 | else |
---|
342 | result.setAlpha(127); |
---|
343 | } |
---|
344 | |
---|
345 | }catch(NullPointerException e){} |
---|
346 | |
---|
347 | } |
---|
348 | |
---|
349 | private void updateButton(LinearLayout layout, boolean bool) { |
---|
350 | try{ |
---|
351 | layout.setEnabled(bool); |
---|
352 | for (int i=0; i<layout.getChildCount();i++){ |
---|
353 | this.updateButton(layout.getChildAt(i), bool); |
---|
354 | } |
---|
355 | }catch(NullPointerException e){} |
---|
356 | |
---|
357 | } |
---|
358 | |
---|
359 | |
---|
360 | |
---|
361 | /** |
---|
362 | * Holds references to view objects. |
---|
363 | * |
---|
364 | * @author José M. Prieto (jmprieto@emergya.com) |
---|
365 | */ |
---|
366 | private class FileBrowserView { |
---|
367 | |
---|
368 | public ListView fileList; |
---|
369 | public TextView path; |
---|
370 | public LinearLayout accept; |
---|
371 | public LinearLayout clear; |
---|
372 | public TextView pathString; |
---|
373 | |
---|
374 | public FileBrowserView() { |
---|
375 | |
---|
376 | setContentView(R.layout.activity_file_to_decrypt); |
---|
377 | this.path = (TextView) findViewById(R.id.path); |
---|
378 | this.pathString = (TextView) findViewById(R.id.pathstring); |
---|
379 | |
---|
380 | this.fileList = (ListView) findViewById(R.id.file_list); |
---|
381 | this.fileList.setOnItemClickListener(FileToDecryptActivity.this); |
---|
382 | this.fileList.setItemsCanFocus(true); |
---|
383 | |
---|
384 | |
---|
385 | this.clear = (LinearLayout) findViewById(R.id.button_clear_zone); |
---|
386 | this.clear.setOnClickListener(FileToDecryptActivity.this); |
---|
387 | |
---|
388 | this.accept = (LinearLayout) findViewById(R.id.button_accept_zone); |
---|
389 | this.accept.setOnClickListener(FileToDecryptActivity.this); |
---|
390 | |
---|
391 | } |
---|
392 | } |
---|
393 | |
---|
394 | @Override |
---|
395 | public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
---|
396 | |
---|
397 | |
---|
398 | if (parent.getId() == R.id.file_list) { // user selects a file |
---|
399 | this.listAdapter.select((ListView) parent, position); |
---|
400 | |
---|
401 | } else { // user de-selects a file |
---|
402 | //this.listAdapter.addIfSameDirectory(selectedAdapter.doUnselect((ListView) parent, position)); |
---|
403 | |
---|
404 | } |
---|
405 | //this.viewHolder.numSelected.setText(Integer.toString(this.selected.size())); |
---|
406 | } |
---|
407 | |
---|
408 | @Override |
---|
409 | public void onClick(View v) { |
---|
410 | |
---|
411 | switch (v.getId()) { |
---|
412 | |
---|
413 | |
---|
414 | case R.id.button_clear_zone: |
---|
415 | |
---|
416 | this.selected = null; |
---|
417 | this.listAdapter.notifyDataSetChanged(); |
---|
418 | |
---|
419 | //this.viewHolder.numSelected.setText(""+this.selected.size()); |
---|
420 | this.updateButton(this.viewHolder.accept, false); |
---|
421 | break; |
---|
422 | |
---|
423 | |
---|
424 | |
---|
425 | case R.id.button_accept_zone: |
---|
426 | |
---|
427 | // lanzar intent para compartir el archivo seleccionado |
---|
428 | fileToDecrypt = FileToDecryptActivity.this.selected.getAbsolutePath(); |
---|
429 | |
---|
430 | //Toast.makeText(getApplicationContext(), "FileToDecryptActivity: "+fileToDecrypt, Toast.LENGTH_SHORT).show(); |
---|
431 | |
---|
432 | |
---|
433 | |
---|
434 | selectPKCS12ToDecrypt(fileToDecrypt); |
---|
435 | |
---|
436 | break; |
---|
437 | |
---|
438 | } |
---|
439 | } |
---|
440 | |
---|
441 | |
---|
442 | // funcion para compartir el archivo |
---|
443 | private void shareIt() { |
---|
444 | |
---|
445 | Intent shareIntent = new Intent(); |
---|
446 | shareIntent.setAction(Intent.ACTION_SEND); |
---|
447 | File file = new File(fileToDecrypt); |
---|
448 | |
---|
449 | |
---|
450 | Uri uri = Uri.fromFile(file); |
---|
451 | Log.i("DEBUG", file.getPath()); |
---|
452 | //Log.d("******", getMimeType(file.getPath())); |
---|
453 | //shareIntent.setDataAndType(uri, getMimeType(file.getPath())); |
---|
454 | shareIntent.putExtra(Intent.EXTRA_STREAM, uri); |
---|
455 | shareIntent.setType("application/*"); |
---|
456 | startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share_it_using))); |
---|
457 | } |
---|
458 | |
---|
459 | |
---|
460 | /** |
---|
461 | * Selecciona el certificado del destinatario del directorio de certificados |
---|
462 | * para cifrado |
---|
463 | * @return void |
---|
464 | */ |
---|
465 | // funcion para desplegar el gestor de certificados de destinatarios para cifrar |
---|
466 | private void selectPKCS12ToDecrypt(String fileToDecrypt) { |
---|
467 | |
---|
468 | // desplegar la actividad de gestor de certificados de destinatarios |
---|
469 | |
---|
470 | // chequear disponibilidad de directorio de certificados |
---|
471 | if (!checkDecryptedDirectoryAvailability()){ |
---|
472 | //Toast.makeText(getApplicationContext(), "FileToDecryptActivity: directorio no disponible", Toast.LENGTH_SHORT).show(); |
---|
473 | |
---|
474 | finish(); |
---|
475 | return; |
---|
476 | }else{ |
---|
477 | // lanzar el activity SelectCeritificateToEncryptActivity |
---|
478 | Intent intent = new Intent(this, PKCS12ToDecryptActivity.class); |
---|
479 | intent.putExtra("fileToDecrypt", fileToDecrypt); |
---|
480 | startActivity(intent); |
---|
481 | |
---|
482 | } |
---|
483 | |
---|
484 | |
---|
485 | |
---|
486 | |
---|
487 | |
---|
488 | } // fin de selectPKCS12ToDecrypt() |
---|
489 | |
---|
490 | /** |
---|
491 | * Chequea la disponibilidad del directorio de /TibisayMovil/CertificatesToEncrypt |
---|
492 | * @return boolean |
---|
493 | */ |
---|
494 | private boolean checkDecryptedDirectoryAvailability() { |
---|
495 | // verificar acceso al directorio /mnt/sdcard/TibisayMovil/DecryptedFiles |
---|
496 | boolean mExternalStorageAvailable = false; |
---|
497 | boolean mExternalStorageWriteable = false; |
---|
498 | String state = Environment.getExternalStorageState(); |
---|
499 | |
---|
500 | String decryptedDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + |
---|
501 | getResources().getString(R.string.app_name) + "/" + |
---|
502 | getResources().getString(R.string.decrypted_dir_files) + "/"; |
---|
503 | |
---|
504 | AlertDialog.Builder builder = new AlertDialog.Builder(FileToDecryptActivity.this); |
---|
505 | |
---|
506 | |
---|
507 | if (Environment.MEDIA_MOUNTED.equals(state)) { |
---|
508 | // We can read and write the media |
---|
509 | mExternalStorageAvailable = mExternalStorageWriteable = true; |
---|
510 | //Toast.makeText(getApplicationContext(), "We can read and write the media", Toast.LENGTH_SHORT).show(); |
---|
511 | |
---|
512 | // Crear directorio CertificatesToEncrypt donde se almacenan los certificados de |
---|
513 | // destinatarios para cifrado |
---|
514 | /* |
---|
515 | String decryptedDir = Environment.getExternalStorageDirectory() + "/" + |
---|
516 | getResources().getString(R.string.app_name) + "/" + |
---|
517 | getResources().getString(R.string.certificates_dir) + "/"; |
---|
518 | */ |
---|
519 | if (prepareDirectory(decryptedDir)){ |
---|
520 | return true; |
---|
521 | }else{ |
---|
522 | builder.setMessage("No existe el directorio "+decryptedDir+" para almacenar certificados.").setTitle("Error:"); |
---|
523 | |
---|
524 | } |
---|
525 | |
---|
526 | } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { |
---|
527 | // We can only read the media |
---|
528 | mExternalStorageAvailable = true; |
---|
529 | mExternalStorageWriteable = false; |
---|
530 | //Toast.makeText(getApplicationContext(), "We can only read the media", Toast.LENGTH_SHORT).show(); |
---|
531 | |
---|
532 | builder.setMessage("Directorio "+decryptedDir+ " montado de solo lectura. No se pueden almancenar certificados.").setTitle("Error:"); |
---|
533 | |
---|
534 | |
---|
535 | } else { |
---|
536 | // Something else is wrong. It may be one of many other states, but all we need |
---|
537 | // to know is we can neither read nor write |
---|
538 | mExternalStorageAvailable = mExternalStorageWriteable = false; |
---|
539 | //Toast.makeText(getApplicationContext(), "we can neither read nor write", Toast.LENGTH_SHORT).show(); |
---|
540 | |
---|
541 | builder.setMessage("Directorio "+decryptedDir+ " no está disponible. No se pueden almancenar certificados.").setTitle("Error:"); |
---|
542 | |
---|
543 | } |
---|
544 | |
---|
545 | |
---|
546 | builder.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() { |
---|
547 | public void onClick(DialogInterface dialog, int id) { |
---|
548 | // User cancelled the dialog |
---|
549 | FileToDecryptActivity.this.finish(); |
---|
550 | } |
---|
551 | }); |
---|
552 | AlertDialog dialog = builder.create(); |
---|
553 | dialog.show(); |
---|
554 | return false; |
---|
555 | } // fin de checkdecryptedDirectoryAvailability |
---|
556 | |
---|
557 | |
---|
558 | /** |
---|
559 | * Prepara directorio |
---|
560 | * @return boolean |
---|
561 | */ |
---|
562 | boolean prepareDirectory(String dir) |
---|
563 | { |
---|
564 | try |
---|
565 | { |
---|
566 | if (makedirs(dir)) |
---|
567 | { |
---|
568 | return true; |
---|
569 | } else { |
---|
570 | return false; |
---|
571 | } |
---|
572 | } catch (Exception e) |
---|
573 | { |
---|
574 | e.printStackTrace(); |
---|
575 | //Toast.makeText(this, "Could not initiate File System.. Is Sdcard mounted properly?", Toast.LENGTH_LONG).show(); |
---|
576 | Toast.makeText(this, "No se pudo iniciar el sistema de archivos. ¿Está la SDCARD montada?", Toast.LENGTH_LONG).show(); |
---|
577 | return false; |
---|
578 | } |
---|
579 | } |
---|
580 | |
---|
581 | /** |
---|
582 | * Crea directorio utilizando la variable tmpDir |
---|
583 | * @return boolean |
---|
584 | */ |
---|
585 | private boolean makedirs(String dir) |
---|
586 | { |
---|
587 | //File tempdir = new File(extractedDirFiles); |
---|
588 | File tempdir = new File(dir); |
---|
589 | if (!tempdir.exists()) |
---|
590 | tempdir.mkdirs(); |
---|
591 | return (tempdir.isDirectory()); |
---|
592 | } |
---|
593 | |
---|
594 | |
---|
595 | } |
---|
596 | |
---|