Advertisement
Guest User

Untitled

a guest
Feb 27th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.30 KB | None | 0 0
  1. package com.system.receivingoforder;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6.  
  7. import org.json.JSONArray;
  8. import org.json.JSONException;
  9. import org.json.JSONObject;
  10.  
  11. import android.app.ListActivity;
  12. import android.graphics.Typeface;
  13. import android.os.Bundle;
  14. import android.util.Log;
  15. import android.view.View;
  16. import android.widget.ListView;
  17. import android.widget.SimpleAdapter;
  18. import android.widget.TextView;
  19. import android.widget.Toast;
  20. import com.android.volley.Request.Method;
  21. import com.android.volley.Response;
  22. import com.android.volley.VolleyError;
  23. import com.android.volley.toolbox.StringRequest;
  24. import com.system.receivingoforder.app.AppConfig;
  25. import com.system.receivingoforder.app.AppController;
  26.  
  27. public class ListOfOrders extends ListActivity{
  28.  
  29. private static final String TAG = RegisterActivity.class.getSimpleName();
  30. ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
  31.  
  32. Typeface customFont;
  33. TextView list_of_orders_txt;
  34. ListView listView1;
  35. SimpleAdapter adapter;
  36.  
  37. String[] table = new String[9999];
  38. String desc[] = new String[9999];
  39. String price[] = new String[9999];
  40. String quantity[] = new String[9999];
  41.  
  42. String num, info;
  43. int x;
  44.  
  45. @Override
  46. protected void onCreate(Bundle savedInstanceState) {
  47. // TODO Auto-generated method stub
  48. super.onCreate(savedInstanceState);
  49. setContentView(R.layout.listoforders);
  50.  
  51. customFont = Typeface.createFromAsset(getAssets(), "fonts/EraserRegular.ttf");
  52.  
  53. list_of_orders_txt = (TextView)findViewById(R.id.list_of_orders_tv);
  54. list_of_orders_txt.setTypeface(customFont);
  55.  
  56. adapter = new SimpleAdapter( this, list, R.layout.listoforders_items,
  57. new String[] {"title","subtitle"},
  58. new int[] {R.id.loo_tablenumber,R.id.loo_itemquantity} );
  59.  
  60. getOrderDetails();
  61.  
  62. }
  63.  
  64. @Override
  65. public void finish() {
  66. // TODO Auto-generated method stub
  67. super.finish();
  68. }
  69.  
  70. @Override
  71. public void onBackPressed() {
  72. // TODO Auto-generated method stub
  73. super.onBackPressed();
  74. finish();
  75. }
  76.  
  77. @Override
  78. protected void onListItemClick(ListView l, View v, int position, long id) {
  79. // TODO Auto-generated method stub
  80. super.onListItemClick(l, v, position, id);
  81. deleteOrder(table[position], desc[position], price[position], quantity[position]);
  82. }
  83.  
  84. public void getOrderDetails() {
  85. // Tag used to cancel the request
  86. String tag_string_req = "req_register";
  87.  
  88. StringRequest strReq = new StringRequest(Method.POST,
  89. AppConfig.URL_REGISTER, new Response.Listener<String>() {
  90.  
  91. @Override
  92. public void onResponse(String response) {
  93. Log.d(TAG, "Register Response: " + response.toString());
  94.  
  95. try {
  96. JSONObject jObj = new JSONObject(response);
  97. boolean error = jObj.getBoolean("error");
  98.  
  99. if (!error) {
  100. JSONObject user = jObj.getJSONObject("user");
  101.  
  102. JSONArray tablenumarray = jObj.getJSONArray("tablearray");
  103. JSONArray descarray = jObj.getJSONArray("descarray");
  104. JSONArray pricearray = jObj.getJSONArray("pricearray");
  105. JSONArray quantityarray = jObj.getJSONArray("quantityarray");
  106.  
  107. num = user.getString("prows");
  108. x = Integer.parseInt(num);
  109.  
  110. HashMap<String,String> map = new HashMap<String,String>();
  111.  
  112. for(int i=0; i<x; i++) {
  113. table[i] = tablenumarray.getString(i);
  114. //treatment[i] = treatmentarray.getString(i);
  115. desc[i] = descarray.getString(i);
  116. price[i] = pricearray.getString(i);
  117. quantity[i] = quantityarray.getString(i);
  118.  
  119. }
  120.  
  121. for(int i=0; i<x; i++) {
  122.  
  123. info = "Description: " + desc[i].toString() + " n" + "Price: " + price[i].toString() + " n" + "Quantity: " + quantity[i].toString();
  124.  
  125. map = new HashMap<String,String>();
  126. map.put("title", "Table Number: " + table[i].toString());
  127. map.put("subtitle", info);
  128. list.add(map);
  129. }
  130. setListAdapter(adapter);
  131.  
  132. } else {
  133.  
  134. // Error occurred in registration. Get the error
  135. // message
  136. String errorMsg = jObj.getString("error_msg");
  137. Toast.makeText(getApplicationContext(),
  138. errorMsg, Toast.LENGTH_LONG).show();
  139. }
  140. } catch (JSONException e) {
  141. e.printStackTrace();
  142. }
  143.  
  144. }
  145. }, new Response.ErrorListener() {
  146.  
  147. @Override
  148. public void onErrorResponse(VolleyError error) {
  149. Log.e(TAG, "Registration Error: " + error.getMessage());
  150. Toast.makeText(getApplicationContext(),
  151. error.getMessage(), Toast.LENGTH_LONG).show();
  152.  
  153. }
  154. }) {
  155.  
  156. @Override
  157. protected Map<String, String> getParams() {
  158. // Posting params to register url
  159. Map<String, String> params = new HashMap<String, String>();
  160. params.put("tag", "orderinfo");
  161.  
  162. return params;
  163. }
  164. };
  165.  
  166. // Adding request to request queue
  167. AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
  168. }
  169.  
  170. //delete Order
  171. private void deleteOrder(final String tablenum, final String desc, final String price, final String quantity) {
  172. // Tag used to cancel the request
  173. String tag_string_req = "req_registerpatient";
  174.  
  175. StringRequest strReq = new StringRequest(Method.POST,
  176. AppConfig.URL_REGISTER, new Response.Listener<String>() {
  177.  
  178. @Override
  179. public void onResponse(String response) {
  180. Log.d(TAG, "Register Response: " + response.toString());
  181.  
  182.  
  183. try {
  184. JSONObject jObj = new JSONObject(response);
  185. boolean error = jObj.getBoolean("error");
  186. if (!error) {
  187.  
  188. Toast.makeText(getApplicationContext(), "Order Deleted", Toast.LENGTH_LONG).show();
  189. } else {
  190. // Error occurred in registration. Get the error
  191. // message
  192. String errorMsg = jObj.getString("error_msg");
  193. Toast.makeText(getApplicationContext(),
  194. errorMsg, Toast.LENGTH_LONG).show();
  195. }
  196. } catch (JSONException e) {
  197. e.printStackTrace();
  198. }
  199.  
  200. }
  201. }, new Response.ErrorListener() {
  202.  
  203. @Override
  204. public void onErrorResponse(VolleyError error) {
  205. Log.e(TAG, "Registration Error: " + error.getMessage());
  206. Toast.makeText(getApplicationContext(),
  207. error.getMessage(), Toast.LENGTH_LONG).show();
  208. }
  209. }) {
  210.  
  211. @Override
  212. protected Map<String, String> getParams() {
  213. // Posting params to register url
  214. Map<String, String> params = new HashMap<String, String>();
  215. params.put("tag", "deleteorder");
  216. params.put("tablenum", tablenum);
  217. params.put("desc", desc);
  218. params.put("price", price);
  219. params.put("quantity", quantity);
  220.  
  221. //params.remove("tablenum");
  222. //params.remove("desc");
  223. //params.remove("price");
  224. //params.remove("quantity");
  225.  
  226. return params;
  227. }
  228. };
  229.  
  230. // Adding request to request queue
  231. AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
  232. }
  233. }
  234.  
  235. package com.system.receivingoforder;
  236.  
  237. import com.system.receivingoforder.app.AppConfig;
  238. import com.system.receivingoforder.app.AppController;
  239. import com.system.receivingoforder.helper.SQLiteHandler;
  240. import com.system.receivingoforder.helper.SessionManager;
  241.  
  242.  
  243. import java.util.HashMap;
  244. import java.util.Map;
  245.  
  246. import org.json.JSONException;
  247. import org.json.JSONObject;
  248.  
  249. import android.app.Activity;
  250. import android.app.ProgressDialog;
  251. import android.os.Bundle;
  252. import android.util.Log;
  253. import android.view.View;
  254. import android.widget.Button;
  255. import android.widget.EditText;
  256. import android.widget.Toast;
  257.  
  258. import com.android.volley.Request.Method;
  259. import com.android.volley.Response;
  260. import com.android.volley.VolleyError;
  261. import com.android.volley.toolbox.StringRequest;
  262.  
  263. public class RegisterActivity extends Activity {
  264. private static final String TAG = RegisterActivity.class.getSimpleName();
  265. private Button btnRegister;
  266. private EditText inputFullName;
  267. private EditText inputEmail;
  268. private EditText inputPassword;
  269. private ProgressDialog pDialog;
  270. private SessionManager session;
  271. private SQLiteHandler db;
  272.  
  273. @Override
  274. public void onCreate(Bundle savedInstanceState) {
  275. super.onCreate(savedInstanceState);
  276.  
  277.  
  278. // Progress dialog
  279. pDialog = new ProgressDialog(this);
  280. pDialog.setCancelable(false);
  281.  
  282. // Session manager
  283. session = new SessionManager(getApplicationContext());
  284.  
  285. // SQLite database handler
  286. db = new SQLiteHandler(getApplicationContext());
  287.  
  288. // Check if user is already logged in or not
  289. if (session.isLoggedIn()) {
  290. // User is already logged in. Take him to main activity
  291.  
  292.  
  293. }
  294.  
  295. // Register Button Click event
  296. btnRegister.setOnClickListener(new View.OnClickListener() {
  297. public void onClick(View view) {
  298. String name = inputFullName.getText().toString();
  299. String email = inputEmail.getText().toString();
  300. String password = inputPassword.getText().toString();
  301.  
  302. if (!name.isEmpty() && !email.isEmpty() && !password.isEmpty()) {
  303. registerUser(name, email, password);
  304. } else {
  305. Toast.makeText(getApplicationContext(),
  306. "Please enter your details!", Toast.LENGTH_LONG)
  307. .show();
  308. }
  309. }
  310. });
  311.  
  312. // Link to Login Screen
  313.  
  314. }
  315.  
  316. /**
  317. * Function to store user in MySQL database will post params(tag, name,
  318. * email, password) to register url
  319. * */
  320. private void registerUser(final String name, final String email,
  321. final String password) {
  322. // Tag used to cancel the request
  323. String tag_string_req = "req_register";
  324.  
  325. pDialog.setMessage("Registering ...");
  326. showDialog();
  327.  
  328. StringRequest strReq = new StringRequest(Method.POST,
  329. AppConfig.URL_REGISTER, new Response.Listener<String>() {
  330.  
  331. @Override
  332. public void onResponse(String response) {
  333. Log.d(TAG, "Register Response: " + response.toString());
  334. hideDialog();
  335.  
  336. try {
  337. JSONObject jObj = new JSONObject(response);
  338. boolean error = jObj.getBoolean("error");
  339. if (!error) {
  340. // User successfully stored in MySQL
  341. // Now store the user in sqlite
  342. String uid = jObj.getString("uid");
  343.  
  344. JSONObject user = jObj.getJSONObject("user");
  345. String name = user.getString("name");
  346. String email = user.getString("email");
  347. String created_at = user
  348. .getString("created_at");
  349.  
  350. // Inserting row in users table
  351. db.addUser(name, email, uid, created_at);
  352.  
  353. // Launch login activity
  354.  
  355. } else {
  356.  
  357. // Error occurred in registration. Get the error
  358. // message
  359. String errorMsg = jObj.getString("error_msg");
  360. Toast.makeText(getApplicationContext(),
  361. errorMsg, Toast.LENGTH_LONG).show();
  362. }
  363. } catch (JSONException e) {
  364. e.printStackTrace();
  365. }
  366.  
  367. }
  368. }, new Response.ErrorListener() {
  369.  
  370. @Override
  371. public void onErrorResponse(VolleyError error) {
  372. Log.e(TAG, "Registration Error: " + error.getMessage());
  373. Toast.makeText(getApplicationContext(),
  374. error.getMessage(), Toast.LENGTH_LONG).show();
  375. hideDialog();
  376. }
  377. }) {
  378.  
  379. @Override
  380. protected Map<String, String> getParams() {
  381. // Posting params to register url
  382. Map<String, String> params = new HashMap<String, String>();
  383. params.put("tag", "register");
  384. params.put("name", name);
  385. params.put("email", email);
  386. params.put("password", password);
  387.  
  388. return params;
  389. }
  390.  
  391. };
  392.  
  393. // Adding request to request queue
  394. AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
  395. }
  396.  
  397. private void showDialog() {
  398. if (!pDialog.isShowing())
  399. pDialog.show();
  400. }
  401.  
  402. private void hideDialog() {
  403. if (pDialog.isShowing())
  404. pDialog.dismiss();
  405. }
  406.  
  407. }
  408.  
  409. <?xml version="1.0" encoding="utf-8"?>
  410. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  411. android:layout_width="match_parent"
  412. android:layout_height="match_parent"
  413. android:background="@drawable/greenboard_background" >
  414.  
  415. <TextView
  416. android:id="@+id/list_of_orders_tv"
  417. android:layout_width="wrap_content"
  418. android:layout_height="wrap_content"
  419. android:layout_alignParentTop="true"
  420. android:layout_centerHorizontal="true"
  421. android:layout_marginTop="45dp"
  422. android:text="@string/list_of_orders"
  423. android:textAppearance="?android:attr/textAppearanceLarge"
  424. android:textSize="35sp" />
  425.  
  426. <ListView
  427. android:id="@+id/android:list"
  428. android:layout_width="543dp"
  429. android:layout_height="800dp"
  430. android:layout_below="@+id/list_of_orders_tv"
  431. android:layout_centerHorizontal="true" >
  432. </ListView>
  433.  
  434. </RelativeLayout>
  435.  
  436. <?xml version="1.0" encoding="utf-8"?>
  437. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  438. android:layout_width="match_parent"
  439. android:layout_height="match_parent" >
  440.  
  441. <TextView
  442. android:id="@+id/loo_tablenumber"
  443. android:layout_width="wrap_content"
  444. android:layout_height="wrap_content"
  445. android:layout_alignParentLeft="true"
  446. android:layout_alignParentTop="true"
  447. android:text="@string/table_no"
  448. android:textAppearance="?android:attr/textAppearanceLarge"
  449. android:textSize="30sp" />
  450.  
  451. <TextView
  452. android:id="@+id/loo_itemquantity"
  453. android:layout_width="wrap_content"
  454. android:layout_height="wrap_content"
  455. android:layout_alignParentLeft="true"
  456. android:layout_below="@+id/loo_tablenumber"
  457. android:text="@string/item_quantity"
  458. android:textAppearance="?android:attr/textAppearanceLarge"
  459. android:textSize="30sp" />
  460.  
  461. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement