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