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 | |
---|
24 | import java.io.File; |
---|
25 | |
---|
26 | import android.app.Activity; |
---|
27 | import android.app.AlertDialog; |
---|
28 | import android.content.DialogInterface; |
---|
29 | import android.content.Intent; |
---|
30 | import android.net.Uri; |
---|
31 | import android.os.Bundle; |
---|
32 | import android.util.Log; |
---|
33 | import android.view.View; |
---|
34 | import android.view.View.OnClickListener; |
---|
35 | import android.view.Window; |
---|
36 | import android.webkit.MimeTypeMap; |
---|
37 | import android.widget.LinearLayout; |
---|
38 | import android.widget.TextView; |
---|
39 | import android.widget.Toast; |
---|
40 | |
---|
41 | public class DecryptionResultActivity extends Activity{ |
---|
42 | private String fileToDecrypt; |
---|
43 | private String decryptedFile; |
---|
44 | private String recipient; |
---|
45 | private String pathFileSigned; |
---|
46 | private LinearLayout button_share; |
---|
47 | private LinearLayout button_finish; |
---|
48 | |
---|
49 | @Override |
---|
50 | protected void onCreate(Bundle savedInstanceState) { |
---|
51 | |
---|
52 | //Capturando archivo original |
---|
53 | fileToDecrypt = getIntent().getExtras().getString("fileToDecrypt"); |
---|
54 | |
---|
55 | //Capturando archivo cifrado |
---|
56 | decryptedFile = getIntent().getExtras().getString("decryptedFile"); |
---|
57 | |
---|
58 | //Capturando destinatario |
---|
59 | //recipient = getIntent().getExtras().getString("recipient"); |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | //Estilando la barra de titulo |
---|
64 | final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); |
---|
65 | |
---|
66 | super.onCreate(savedInstanceState); |
---|
67 | setContentView(R.layout.activity_decryption_result); |
---|
68 | //Estilando Barra de titulo |
---|
69 | if(customTitleSupported) |
---|
70 | getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar); |
---|
71 | |
---|
72 | TextView archivo_original_a_descifrar = (TextView) this.findViewById(R.id.archivo_original_pdf); |
---|
73 | TextView archivo_descifrado = (TextView) this.findViewById(R.id.archivo_descifrado); |
---|
74 | //TextView destinatario = (TextView) this.findViewById(R.id.destinatario); |
---|
75 | |
---|
76 | |
---|
77 | archivo_original_a_descifrar.setText(fileToDecrypt); |
---|
78 | archivo_descifrado.setText(decryptedFile); |
---|
79 | |
---|
80 | |
---|
81 | LinearLayout layoutDecryptedFileAndArror = (LinearLayout) this.findViewById(R.id.layout_decrypted_file_and_arrow); |
---|
82 | |
---|
83 | OnClickListener decryptedFileListener = new OnClickListener() { |
---|
84 | public void onClick(View v) { |
---|
85 | // do something when the button is clicked |
---|
86 | //Toast.makeText(getApplicationContext(), "**CLICK SOBRE EL TEXTVIEW***", Toast.LENGTH_LONG).show(); |
---|
87 | |
---|
88 | openIt(decryptedFile, getMimeType(decryptedFile)); |
---|
89 | } |
---|
90 | }; |
---|
91 | layoutDecryptedFileAndArror.setOnClickListener(decryptedFileListener); |
---|
92 | |
---|
93 | |
---|
94 | button_share = (LinearLayout) this.findViewById(R.id.button_remove_certificate_zone); |
---|
95 | button_finish = (LinearLayout) this.findViewById(R.id.button_add_certificate_zone); |
---|
96 | |
---|
97 | |
---|
98 | |
---|
99 | button_finish.setOnClickListener(new OnClickListener() |
---|
100 | { |
---|
101 | public void onClick(View v) |
---|
102 | { |
---|
103 | Intent oIntent = new Intent(DecryptionResultActivity.this, TibisayMovilActivity.class); |
---|
104 | oIntent.setAction(Intent.ACTION_VIEW); |
---|
105 | oIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); |
---|
106 | startActivity(oIntent); |
---|
107 | finish(); |
---|
108 | } |
---|
109 | }); |
---|
110 | |
---|
111 | button_share.setOnClickListener(new OnClickListener() |
---|
112 | { |
---|
113 | public void onClick(View v) |
---|
114 | { |
---|
115 | shareIt(); |
---|
116 | } |
---|
117 | }); |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | // funcion para compartir el documento |
---|
122 | private void shareIt() { |
---|
123 | |
---|
124 | Intent shareIntent = new Intent(); |
---|
125 | shareIntent.setAction(Intent.ACTION_SEND); |
---|
126 | File file = new File(decryptedFile); |
---|
127 | |
---|
128 | |
---|
129 | Uri uri = Uri.fromFile(file); |
---|
130 | Log.i("DEBUG", file.getPath()); |
---|
131 | //Log.d("******", getMimeType(file.getPath())); |
---|
132 | //shareIntent.setDataAndType(uri, getMimeType(file.getPath())); |
---|
133 | shareIntent.putExtra(Intent.EXTRA_STREAM, uri); |
---|
134 | shareIntent.setType("application/*"); |
---|
135 | startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.share_it_using))); |
---|
136 | } |
---|
137 | |
---|
138 | // funcion para obtener el tipo mime de un archivo |
---|
139 | public static String getMimeType(String url) |
---|
140 | { |
---|
141 | String extension = url.substring(url.lastIndexOf(".")); |
---|
142 | String mimeTypeMap = MimeTypeMap.getFileExtensionFromUrl(extension); |
---|
143 | String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(mimeTypeMap); |
---|
144 | return mimeType; |
---|
145 | } |
---|
146 | |
---|
147 | |
---|
148 | // funcion para lanzar un intent que abra un archivo |
---|
149 | private void openIt(String decryptedFile, String mimeType) { |
---|
150 | |
---|
151 | Intent shareIntent = new Intent(); |
---|
152 | shareIntent.setAction(Intent.ACTION_VIEW); |
---|
153 | File file = new File(decryptedFile); |
---|
154 | Uri uri = Uri.fromFile(file); |
---|
155 | Log.i("DEBUG", file.getPath()); |
---|
156 | shareIntent.setDataAndType(uri, mimeType); |
---|
157 | startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.open_it_using))); |
---|
158 | } |
---|
159 | |
---|
160 | |
---|
161 | /** |
---|
162 | * Crea un dialogo con el titulo y mensaje como argumentos y lo despliega |
---|
163 | * |
---|
164 | * @return void |
---|
165 | */ |
---|
166 | public void showDialog(String title, String msg) { |
---|
167 | |
---|
168 | // 1. Instantiate an AlertDialog.Builder with its constructor |
---|
169 | AlertDialog.Builder builder = new AlertDialog.Builder(DecryptionResultActivity.this); |
---|
170 | |
---|
171 | // 2. Chain together various setter methods to set the dialog characteristics |
---|
172 | builder.setMessage(msg) |
---|
173 | .setTitle(title); |
---|
174 | |
---|
175 | builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { |
---|
176 | public void onClick(DialogInterface dialog, int id) { |
---|
177 | // User clicked OK button |
---|
178 | Toast.makeText(getApplicationContext(), "User clicked OK button", Toast.LENGTH_LONG).show(); |
---|
179 | |
---|
180 | } |
---|
181 | }); |
---|
182 | |
---|
183 | // 3. Get the AlertDialog from create() |
---|
184 | AlertDialog dialog = builder.create(); |
---|
185 | dialog.show(); |
---|
186 | |
---|
187 | } |
---|
188 | |
---|
189 | } |
---|