PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/app/src/main/java/com/ch/yatta/fresh/com/yatta/All_confirmed_visitors.java

https://bitbucket.org/izoneafricaltd/yatta_spin_the_wheel
Java | 398 lines | 239 code | 75 blank | 84 comment | 18 complexity | cbf331b4632e244cd023942bc36928f5 MD5 | raw file
  1. package com.ch.chewing.fresh.com.fresh_chewing_gum;
  2. import android.app.AlertDialog;
  3. import android.app.ListActivity;
  4. import android.app.ProgressDialog;
  5. import android.content.DialogInterface;
  6. import android.content.Intent;
  7. import android.os.AsyncTask;
  8. import android.os.Bundle;
  9. import android.util.Log;
  10. import android.view.KeyEvent;
  11. import android.view.Menu;
  12. import android.view.MenuItem;
  13. import android.view.View;
  14. import android.widget.AdapterView;
  15. import android.widget.EditText;
  16. import android.widget.ImageView;
  17. import android.widget.ListAdapter;
  18. import android.widget.ListView;
  19. import android.widget.SimpleAdapter;
  20. import android.widget.TextView;
  21. import android.widget.Toast;
  22. import org.apache.http.HttpEntity;
  23. import org.apache.http.HttpResponse;
  24. import org.apache.http.NameValuePair;
  25. import org.apache.http.StatusLine;
  26. import org.apache.http.client.ClientProtocolException;
  27. import org.apache.http.client.HttpClient;
  28. import org.apache.http.client.entity.UrlEncodedFormEntity;
  29. import org.apache.http.client.methods.HttpPost;
  30. import org.apache.http.impl.client.DefaultHttpClient;
  31. import org.apache.http.message.BasicNameValuePair;
  32. import org.json.JSONArray;
  33. import org.json.JSONException;
  34. import org.json.JSONObject;
  35. import java.io.BufferedReader;
  36. import java.io.IOException;
  37. import java.io.InputStream;
  38. import java.io.InputStreamReader;
  39. import java.util.ArrayList;
  40. import java.util.HashMap;
  41. import java.util.List;
  42. public class All_confirmed_visitors extends ListActivity {
  43. // Connection detector
  44. ConnectionDetector cd;
  45. // Alert dialog manager
  46. AlertDialogManager alert = new AlertDialogManager();
  47. // Progress Dialog
  48. private ProgressDialog pDialog;
  49. // Creating JSON Parser object
  50. JSONParser jsonParser = new JSONParser();
  51. ArrayList<HashMap<String, String>> taskList;
  52. // tasks JSONArray
  53. JSONArray tasks = null;
  54. // category id
  55. String task_id, task_name;
  56. String Vax;
  57. EditText searc_varX;
  58. // tasks JSON url
  59. // id - should be posted as GET params to get task list (ex: id = 5)
  60. private static final String URL_TASKS = "http://izonestudio.net/yatta_spin/fetch_data2.php";
  61. // ALL JSON node names
  62. private static final String TAG_TASK_JSON = "saerchz";
  63. private static final String TAG_VIS_ID = "id";
  64. private static final String TAG_VIS_FULLNAME = "name_xc";
  65. private static final String TAG_VIS_TEL = "tel_xc";
  66. private static final String TAG_VIS_EMAIL = "email_xc";
  67. private static final String TAG_VIS_STATUS = "status";
  68. private static final String TAG_VIS_DATE= "date_x";
  69. private static final String TAG_VIS_SEARCH= "sVarSearch";
  70. @Override
  71. public void onCreate(Bundle savedInstanceState) {
  72. super.onCreate(savedInstanceState);
  73. setContentView(R.layout.all__brands);
  74. ImageView cancel=(ImageView) findViewById(R.id.cancel_4);
  75. cancel.setOnClickListener(new View.OnClickListener() {
  76. @Override
  77. public void onClick(View v) {
  78. finish();
  79. Intent i=new Intent(getApplicationContext(), Register_user.class);
  80. startActivity(i);
  81. }
  82. });
  83. cd = new ConnectionDetector(getApplicationContext());
  84. if (!cd.isConnectingToInternet()) {
  85. Toast.makeText(getApplicationContext(), "No internet !! Please access internet connection.", Toast.LENGTH_LONG).show();
  86. }else{
  87. taskList = new ArrayList<HashMap<String, String>>();
  88. // Loading task in Background Thread
  89. new LoadTasks().execute();
  90. }
  91. // get listview
  92. ListView lv = getListView();
  93. /**
  94. * Listview on item click listener
  95. * SingletaskActivity will be lauched by passing task id, cat id
  96. * */
  97. //////////////////////////////////////////////////////////////////////////////////////////////////////
  98. lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  99. @Override
  100. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  101. //String idx= ((TextView) view.findViewById(R.id.xsh_shop_id)).getText().toString();
  102. // String name= ((TextView) view.findViewById(R.id.xsh_shop_id)).getText().toString();
  103. //Intent i=new Intent(getApplicationContext(), Search_visitors.class);
  104. //i.putExtra("shop_id", idx);
  105. ///startActivity(i);
  106. //String serial_no = ((TextView) view.findViewById(R.id.sf_sc_pin)).getText().toString();
  107. //String idx = ((TextView) view.findViewById(R.id.task_name)).getText().toString();
  108. //String descX = ((TextView) view.findViewById(R.id.task_desc)).getText().toString();
  109. Intent i = new Intent(getApplicationContext(), Register_user.class);
  110. //i.putExtra("n_id", idx);
  111. // i.putExtra("n_name", name);
  112. //i.putExtra("task_desc", descX);
  113. startActivity(i);
  114. }
  115. });
  116. //finish();
  117. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  118. }
  119. @Override
  120. protected void onStop() {
  121. super.onStop();
  122. finish();
  123. }
  124. @Override
  125. protected void onDestroy() {
  126. super.onDestroy();
  127. finish();
  128. }
  129. @Override
  130. public boolean onKeyDown(int keyCode, KeyEvent event) {
  131. if(keyCode== KeyEvent.KEYCODE_BACK) {
  132. // Toast.makeText(getApplicationContext(), "back press", Toast.LENGTH_LONG).show();
  133. }else{
  134. }
  135. return false;
  136. // Disable back button..............
  137. }
  138. @Override
  139. public boolean onCreateOptionsMenu(Menu menu) {
  140. // Inflate the menu; this adds items to the action bar if it is present.
  141. getMenuInflater().inflate(R.menu.menu_main, menu);
  142. return true;
  143. }
  144. @Override
  145. public boolean onOptionsItemSelected(MenuItem item) {
  146. // Handle action bar item clicks here. The action bar will
  147. // automatically handle clicks on the Home/Up button, so long
  148. // as you specify a parent activity in AndroidManifest.xml.
  149. int id = item.getItemId();
  150. //noinspection SimplifiableIfStatement
  151. if (id == R.id.action_settings) {
  152. //logout();
  153. return true;
  154. }
  155. if (id == R.id.action_settings) {
  156. //logout();
  157. return true;
  158. }
  159. return super.onOptionsItemSelected(item);
  160. }
  161. public String getHttpPost(String url,List<NameValuePair> params) {
  162. StringBuilder str = new StringBuilder();
  163. HttpClient client = new DefaultHttpClient();
  164. HttpPost httpPost = new HttpPost(url);
  165. try {
  166. httpPost.setEntity(new UrlEncodedFormEntity(params));
  167. HttpResponse response = client.execute(httpPost);
  168. StatusLine statusLine = response.getStatusLine();
  169. int statusCode = statusLine.getStatusCode();
  170. if (statusCode == 200) { // Status OK
  171. HttpEntity entity = response.getEntity();
  172. InputStream content = entity.getContent();
  173. BufferedReader reader = new BufferedReader(new InputStreamReader(content));
  174. String line;
  175. while ((line = reader.readLine()) != null) {
  176. str.append(line);
  177. }
  178. } else {
  179. Log.e("Log", "Failed to download result..");
  180. }
  181. } catch (ClientProtocolException e) {
  182. e.printStackTrace();
  183. } catch (IOException e) {
  184. e.printStackTrace();
  185. }
  186. return str.toString();
  187. }
  188. /**
  189. * Background Async Task to Load all tasks under one category
  190. * */
  191. class LoadTasks extends AsyncTask<String, String, String> {
  192. /**
  193. * Before starting background thread Show Progress Dialog
  194. * */
  195. @Override
  196. protected void onPreExecute() {
  197. super.onPreExecute();
  198. pDialog = new ProgressDialog(All_confirmed_visitors.this);
  199. pDialog.setMessage("Loading...");
  200. pDialog.setIndeterminate(false);
  201. pDialog.setCancelable(false);
  202. pDialog.show();
  203. }
  204. /**
  205. * getting tasks json and parsing
  206. * */
  207. protected String doInBackground(String... args) {
  208. // Building Parameters
  209. List<NameValuePair> params = new ArrayList<NameValuePair>();
  210. //String cf="france";
  211. // post category id as GET parameter
  212. params.add(new BasicNameValuePair(TAG_VIS_SEARCH, Vax));
  213. //params.add(new BasicNameValuePair(TAG_DATE, task_datec));
  214. // getting JSON string from URL
  215. String json = jsonParser.makeHttpRequest(URL_TASKS, "GET",
  216. params);
  217. // Check your log cat for JSON reponse
  218. Log.d("task List JSON: ", json);
  219. try {
  220. JSONObject jObj = new JSONObject(json);
  221. if (jObj != null) {
  222. tasks = jObj.getJSONArray(TAG_TASK_JSON);
  223. /// String categ_id = jObj.getString(TAG_ID);
  224. //task_name = jObj.getString(TAG_CATEGORY);
  225. /*String categ_id = jObj.getString(TAG_ID);
  226. task_name = jObj.getString(TAG_CATEGORY);
  227. String categ_id = jObj.getString(TAG_ID);
  228. task_name = jObj.getString(TAG_CATEGORY);*/
  229. if (tasks != null) {
  230. // looping through All tasks
  231. for (int i = 0; i < tasks.length(); i++) {
  232. JSONObject c = tasks.getJSONObject(i);
  233. // Storing each json item in variable
  234. String s_vis_id = c.getString(TAG_VIS_ID);
  235. ///String s_vis_imei= c.getString(TAG_VIS_IMEI);
  236. String s_vis_fullname = c.getString(TAG_VIS_FULLNAME);
  237. String s_vis_tel= c.getString(TAG_VIS_TEL);
  238. String s_vis_email = c.getString(TAG_VIS_EMAIL);
  239. String s_vis_status= c.getString(TAG_VIS_STATUS);
  240. //String s_vis_cat = c.getString(TAG_VIS_CAT);
  241. // String s_vis_inv= c.getString(TAG_VIS_INV);
  242. String s_vis_date = c.getString(TAG_VIS_DATE);
  243. // creating new HashMap
  244. HashMap<String, String> map = new HashMap<String, String>();
  245. // adding each child node to HashMap key => value
  246. //map.put(TAG_ID, id);
  247. map.put(TAG_VIS_ID, s_vis_id);
  248. // map.put(TAG_VIS_IMEI, s_vis_imei);
  249. map.put(TAG_VIS_FULLNAME, s_vis_fullname);
  250. map.put(TAG_VIS_TEL, s_vis_tel);
  251. map.put(TAG_VIS_EMAIL, s_vis_email);
  252. map.put(TAG_VIS_STATUS, s_vis_status);
  253. // map.put(TAG_VIS_CAT, s_vis_cat);
  254. // map.put(TAG_VIS_INV, s_vis_inv);
  255. map.put(TAG_VIS_DATE, s_vis_date);
  256. //map.put(TAG_SHOP_BILL, s_shop_bill);
  257. //map.put(TAG_SHOP_DATE, s_shop_date);
  258. // adding HashList to ArrayList
  259. taskList.add(map);
  260. }
  261. } else {
  262. Log.d("tasks: ", "null");
  263. Toast.makeText(getApplicationContext(), "Results empty", Toast.LENGTH_LONG).show();
  264. finish();
  265. }
  266. }
  267. } catch (JSONException e) {
  268. e.printStackTrace();
  269. }
  270. return null;
  271. }
  272. /**
  273. * After completing background task Dismiss the progress dialog
  274. * **/
  275. protected void onPostExecute(String file_url) {
  276. if(taskList.size() > 0) {
  277. // dismiss the dialog after getting all tasks
  278. pDialog.dismiss();
  279. // updating UI from Background Thread
  280. runOnUiThread(new Runnable() {
  281. public void run() {
  282. ListAdapter adapter = new SimpleAdapter(
  283. All_confirmed_visitors.this, taskList,
  284. R.layout.visitors_ui,
  285. new String[]{
  286. //TAG_VIS_ID,
  287. TAG_VIS_FULLNAME,
  288. TAG_VIS_TEL,
  289. TAG_VIS_EMAIL,
  290. TAG_VIS_STATUS,
  291. //TAG_VIS_CAT,
  292. //TAG_VIS_INV,
  293. TAG_VIS_DATE
  294. },
  295. new int[]{
  296. //R.id.id_no,
  297. R.id.txt_namex,
  298. R.id.txt_tel,
  299. R.id.txt_email,
  300. R.id.txt_status,
  301. R.id.txt_date
  302. });// updating listview
  303. setListAdapter(adapter);
  304. // Change Activity Title with category name
  305. setTitle(task_name);
  306. }
  307. });
  308. }else{
  309. AlertDialog.Builder builder = new AlertDialog.Builder(All_confirmed_visitors.this);
  310. builder.setMessage("Data not available!")
  311. .setCancelable(false)
  312. .setPositiveButton("OK", new DialogInterface.OnClickListener() {
  313. public void onClick(DialogInterface dialog, int id) {
  314. //do things
  315. finish();
  316. }
  317. });
  318. AlertDialog alert = builder.create();
  319. alert.show();
  320. }
  321. }
  322. }
  323. }