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 | |
---|
58 | listViewFunctions.setOnItemClickListener(new OnItemClickListener(){ |
---|
59 | |
---|
60 | @Override |
---|
61 | public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, |
---|
62 | long arg3) { |
---|
63 | // TODO Auto-generated method stub |
---|
64 | Context context = getApplicationContext(); |
---|
65 | //CharSequence text = "Click!"; |
---|
66 | int duration = Toast.LENGTH_SHORT; |
---|
67 | //Toast.makeText(context, text, duration).show(); |
---|
68 | |
---|
69 | View curr = arg0.getChildAt((int) arg3); |
---|
70 | TextView c = (TextView)curr.findViewById(R.id.textListMainMenu); |
---|
71 | String function = c.getText().toString(); |
---|
72 | //Toast.makeText(context, function, duration).show(); |
---|
73 | |
---|
74 | // seleccion de firmar |
---|
75 | if(function.equals(getString(R.string.firmar))) { |
---|
76 | sign_dialog.show(); |
---|
77 | } |
---|
78 | |
---|
79 | // seleccion de verificar |
---|
80 | if(function.equals(getString(R.string.verificar))) { |
---|
81 | Toast.makeText(context, "VERIFICAR", duration).show(); |
---|
82 | verifyBDOCSignedFile(); |
---|
83 | } |
---|
84 | |
---|
85 | // seleccion de gestionar certificados |
---|
86 | if (function.equals("Certificados")){ |
---|
87 | Toast.makeText(context, "Gestionar repositorio", duration).show(); |
---|
88 | |
---|
89 | // Chequeo de version del API de Android para creacion de repositorio |
---|
90 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH){ |
---|
91 | //RelativeLayout certTab = (RelativeLayout) this.findViewById(R.id.linetab2); |
---|
92 | //certTab.setVisibility(View.VISIBLE); |
---|
93 | //this.tabsListener.setKeyChainController(this.keyChainController); |
---|
94 | Toast.makeText(context, "API < 4.0", duration).show(); |
---|
95 | } |
---|
96 | |
---|
97 | //manageKeyChain(); |
---|
98 | |
---|
99 | // lanzar activity de gestion de repositorio |
---|
100 | testRepository(); |
---|
101 | } |
---|
102 | |
---|
103 | // seleccion de compartir archivo |
---|
104 | if (function.equals(getString(R.string.compartir))){ |
---|
105 | Toast.makeText(context, "Compartir Archivo", duration).show(); |
---|
106 | share_dialog.show(); |
---|
107 | |
---|
108 | } |
---|
109 | |
---|
110 | } |
---|
111 | }); //setOnItemClickListener |
---|
112 | } // end onCreate |
---|
113 | |
---|
114 | @Override |
---|
115 | public boolean onCreateOptionsMenu(Menu menu) { |
---|
116 | // Inflate the menu; this adds items to the action bar if it is present. |
---|
117 | getMenuInflater().inflate(R.menu.main, menu); |
---|
118 | return true; |
---|
119 | } |
---|
120 | |
---|
121 | /* |
---|
122 | @Override |
---|
123 | public void setAlias(String alias) { |
---|
124 | |
---|
125 | if (alias == null) { |
---|
126 | finish(); |
---|
127 | return; |
---|
128 | } |
---|
129 | |
---|
130 | this.privateKeyAlias = alias; |
---|
131 | |
---|
132 | //Intent intent = new Intent(this, CertValidatorActivity.class); |
---|
133 | //intent.putExtra(IntentExtraField.ALIAS, alias); |
---|
134 | //intent.putParcelableArrayListExtra(IntentExtraField.FILES, TypeUtils.convertToUriArrayList(this.selected)); |
---|
135 | //startActivityForResult(intent, ActivityResult.CHECK_CERTIFICATE_VALIDITY); |
---|
136 | |
---|
137 | } |
---|
138 | */ |
---|
139 | |
---|
140 | // private void manageKeyChain(){ |
---|
141 | // // |
---|
142 | // //Intent intent = new Intent(this, PKCS12FilePickerActivity.class); |
---|
143 | // //startActivityForResult(intent, ActivityResult.IMPORT_CERTIFICATE); |
---|
144 | // //KeyChainStrategy.getInstance().choosePrivateKeyAlias(); |
---|
145 | // } |
---|
146 | |
---|
147 | private void testRepository(){ |
---|
148 | Intent intent = new Intent(this, CertificateRepositoryActivity.class); |
---|
149 | startActivity(intent); |
---|
150 | } |
---|
151 | |
---|
152 | private void fileToSignHandwrittenSignature(){ |
---|
153 | Intent intent = new Intent(this, FileToSignHandwrittenSignatureActivity.class); |
---|
154 | startActivity(intent); |
---|
155 | } |
---|
156 | |
---|
157 | |
---|
158 | // lanza activity para verificar un documento firmado |
---|
159 | private void verifyBDOCSignedFile(){ |
---|
160 | //Intent intent = new Intent(this, FileToSignHandwrittenSignatureActivity.class); |
---|
161 | Intent intent = new Intent(this, FileToVerifySignatureActivity.class); |
---|
162 | startActivity(intent); |
---|
163 | } |
---|
164 | |
---|
165 | private void shareFile(String path){ |
---|
166 | Intent intent = new Intent(this, FileToShareActivity.class); |
---|
167 | |
---|
168 | intent.putExtra("path", path); |
---|
169 | |
---|
170 | startActivity(intent); |
---|
171 | } |
---|
172 | |
---|
173 | //Crea dialogo de opciones para firma electronica |
---|
174 | public AlertDialog makeSignatureOptionsDialog() { |
---|
175 | final String[] option = new String[] {getString(R.string.firmar_man_pdf), getString(R.string.firmar_elec_pdf), getString(R.string.firmar_pkcs7) }; |
---|
176 | ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, |
---|
177 | android.R.layout.select_dialog_item, option); |
---|
178 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
---|
179 | |
---|
180 | builder.setTitle(getString(R.string.seleccione_opcion)); |
---|
181 | builder.setAdapter(adapter, new DialogInterface.OnClickListener() { |
---|
182 | |
---|
183 | public void onClick(DialogInterface dialog, int which) { |
---|
184 | |
---|
185 | switch (which) { |
---|
186 | case 0: // Firma Manuscrita PDF |
---|
187 | Log.i("DEBUG", "antes de activity call"); |
---|
188 | fileToSignHandwrittenSignature(); |
---|
189 | break; |
---|
190 | case 1: // Firma Electronica PDF |
---|
191 | |
---|
192 | break; |
---|
193 | case 2: // Firma PKCS7 |
---|
194 | |
---|
195 | break; |
---|
196 | |
---|
197 | default: |
---|
198 | break; |
---|
199 | } |
---|
200 | } |
---|
201 | |
---|
202 | }); |
---|
203 | |
---|
204 | return builder.create(); |
---|
205 | } |
---|
206 | |
---|
207 | //Crea dialogo de opciones para firma electronica |
---|
208 | public AlertDialog makeShareOptionsDialog() { |
---|
209 | final String[] option = new String[] {getString(R.string.share_pdf_signed), |
---|
210 | getString(R.string.share_bdoc_downloaded), getString(R.string.share_extracted_file_from_bdoc) }; |
---|
211 | ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, |
---|
212 | android.R.layout.select_dialog_item, option); |
---|
213 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
---|
214 | |
---|
215 | builder.setTitle(getString(R.string.seleccione_opcion)); |
---|
216 | builder.setAdapter(adapter, new DialogInterface.OnClickListener() { |
---|
217 | |
---|
218 | public void onClick(DialogInterface dialog, int which) { |
---|
219 | |
---|
220 | switch (which) { |
---|
221 | case 0: // Archivo Firmado |
---|
222 | Log.i("DEBUG", "antes de activity call"); |
---|
223 | shareFile("archivoFirmado"); |
---|
224 | break; |
---|
225 | case 1: // Archivos BDOC Descargados |
---|
226 | shareFile("bdocDescargado"); |
---|
227 | break; |
---|
228 | case 2: // Archivos extraídos de BDOC |
---|
229 | shareFile("extraidoDeBdoc"); |
---|
230 | break; |
---|
231 | |
---|
232 | default: |
---|
233 | break; |
---|
234 | } |
---|
235 | } |
---|
236 | |
---|
237 | }); |
---|
238 | |
---|
239 | return builder.create(); |
---|
240 | } |
---|
241 | |
---|
242 | } |
---|