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