Guest User

Untitled

a guest
Dec 13th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.24 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <resources>
  3. <resources>
  4.  
  5. <string name="country_prompt">Choose a country</string>
  6.  
  7. <string name="ip">http://192.168.10.45/</string>
  8.  
  9.  
  10. </resources>
  11.  
  12. public class Login extends AppCompatActivity {
  13.  
  14.  
  15. Button sync_data,login;
  16. EditText username,pwd;
  17.  
  18. Requests rq;
  19.  
  20. String ipadd;
  21.  
  22. Context c;
  23. SharedPreferences sp;
  24.  
  25. dal d = new dal(this);
  26. dal.DBHelper a = d.new DBHelper(this);
  27.  
  28. @Override
  29. protected void onCreate(Bundle savedInstanceState) {
  30. super.onCreate(savedInstanceState);
  31. setContentView(R.layout.login);
  32.  
  33. getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
  34.  
  35.  
  36. final Animation myanim = AnimationUtils.loadAnimation(Login.this, R.anim.btnanim);
  37.  
  38. ipadd = getResources().getString(R.string.ip);
  39.  
  40.  
  41. sp=getSharedPreferences("login",MODE_PRIVATE);
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. login = (Button)findViewById(R.id.btnLogin);
  49. sync_data = (Button)findViewById(R.id.sync_data);
  50. username = (EditText)findViewById(R.id.txtUsername);
  51. pwd = (EditText)findViewById(R.id.txtPassword);
  52.  
  53.  
  54.  
  55. login.setOnClickListener(new View.OnClickListener() {
  56.  
  57. @Override
  58. public void onClick(View arg0) {
  59.  
  60. arg0.startAnimation(myanim);
  61.  
  62.  
  63.  
  64.  
  65. InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
  66. imm.hideSoftInputFromWindow(username.getWindowToken(), 0);
  67. imm.hideSoftInputFromWindow(pwd.getWindowToken(), 0);
  68. String Username = username.getText().toString();
  69. String password = pwd.getText().toString();
  70. if (username.length() > 0 && password.length() > 0) {
  71. try {
  72.  
  73. if (a.Login(Username, password)) {
  74.  
  75.  
  76.  
  77. SharedPreferences.Editor s=sp.edit();
  78. s.putString("name",username.getText().toString());
  79.  
  80.  
  81. s.commit();
  82.  
  83. Intent i = new Intent(Login.this, MainPage.class);
  84. startActivity(i);
  85.  
  86. Toast.makeText(Login.this,
  87. "Successfully Logged In", Toast.LENGTH_LONG)
  88. .show();
  89. } else {
  90. Toast.makeText(Login.this,
  91. "Invalid username or password",
  92. Toast.LENGTH_LONG).show();
  93. }
  94.  
  95. } catch (Exception e) {
  96. Toast.makeText(Login.this, "Some problem occurred",
  97. Toast.LENGTH_LONG).show();
  98.  
  99. }
  100. } else {
  101. Toast.makeText(Login.this,
  102. "Username or Password is empty", Toast.LENGTH_LONG).show();
  103. }
  104. }
  105. });
  106.  
  107.  
  108.  
  109.  
  110. sync_data.setOnClickListener(new View.OnClickListener() {
  111. @Override
  112. public void onClick(View v) {
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119. rq = new Requests();
  120. rq.GetRequest(ipadd + "fetch_waiter.php", Login.this, new Requests.VolleyCallback() {
  121. @Override
  122. public void onSuccess(String value) {
  123.  
  124.  
  125. if (value != null) {
  126. //System.out.println(ipadd + "/pull/prod.php");
  127. System.out.println("valuu: " + value);
  128.  
  129.  
  130. ProdData ProdData = new ProdData(c);
  131.  
  132. /* d.open();
  133. d.insertprod(jsonArray);
  134. d.close();*/
  135.  
  136. try {
  137. JSONArray Ja = new JSONArray(value);
  138. JSONObject obj = Ja.getJSONObject(0);
  139.  
  140.  
  141.  
  142. d.open();
  143. // Dal.insertProduct(Ja);
  144.  
  145. d.insertSignIn(Ja);
  146.  
  147. d.close();
  148.  
  149. /*Intent i = new Intent(Login.this, MainActivity.class);
  150. startActivity(i);*/
  151.  
  152.  
  153.  
  154.  
  155. } catch (JSONException e) {
  156. e.printStackTrace();
  157. }
  158.  
  159.  
  160. Toast.makeText(Login.this, value, Toast.LENGTH_SHORT).show();
  161.  
  162. Type listType = new TypeToken<ArrayList<Detail>>() {
  163. }.getType();
  164.  
  165.  
  166. /*Atypes = null;
  167. Atypes = new Gson().fromJson(String.valueOf(value), listType);*/
  168.  
  169. } else {
  170. Log.e("ServiceHandler", "Couldn't get any data from the url");
  171.  
  172.  
  173. }
  174.  
  175.  
  176. }
  177.  
  178.  
  179. });
  180.  
  181.  
  182.  
  183. ///////////////////member service//////////////////////////////
  184.  
  185. rq.GetRequest(ipadd + "fetch_member.php", Login.this, new Requests.VolleyCallback() {
  186. @Override
  187. public void onSuccess(String value) {
  188.  
  189.  
  190. if (value != null) {
  191. //System.out.println(ipadd + "/pull/prod.php");
  192. System.out.println("valuu: " + value);
  193.  
  194.  
  195. ProdData ProdData = new ProdData(c);
  196.  
  197. /* d.open();
  198. d.insertprod(jsonArray);
  199. d.close();*/
  200.  
  201. try {
  202. JSONArray Ja = new JSONArray(value);
  203. JSONObject obj = Ja.getJSONObject(0);
  204.  
  205.  
  206.  
  207. d.open();
  208. // Dal.insertProduct(Ja);
  209.  
  210. d.insertMember(Ja);
  211.  
  212. d.close();
  213.  
  214. /*Intent i = new Intent(Login.this, MainActivity.class);
  215. startActivity(i);*/
  216.  
  217.  
  218.  
  219.  
  220. } catch (JSONException e) {
  221. e.printStackTrace();
  222. }
  223.  
  224.  
  225. Toast.makeText(Login.this, value, Toast.LENGTH_SHORT).show();
  226.  
  227. Type listType = new TypeToken<ArrayList<Detail>>() {
  228. }.getType();
  229.  
  230.  
  231. /*Atypes = null;
  232. Atypes = new Gson().fromJson(String.valueOf(value), listType);*/
  233.  
  234. } else {
  235. Log.e("ServiceHandler", "Couldn't get any data from the url");
  236.  
  237.  
  238. }
  239.  
  240.  
  241. }
  242.  
  243.  
  244. });
  245.  
  246.  
  247.  
  248.  
  249.  
  250. /////////////////product service///////////////////
  251.  
  252. rq.GetRequest(ipadd + "fetch_item.php", Login.this, new Requests.VolleyCallback() {
  253. @Override
  254. public void onSuccess(String value) {
  255.  
  256.  
  257. if (value != null) {
  258. //System.out.println(ipadd + "/pull/prod.php");
  259. System.out.println("valuu: " + value);
  260.  
  261.  
  262. ProdData ProdData = new ProdData(c);
  263.  
  264. /* d.open();
  265. d.insertprod(jsonArray);
  266. d.close();*/
  267.  
  268. try {
  269. JSONArray Ja = new JSONArray(value);
  270. JSONObject obj = Ja.getJSONObject(0);
  271.  
  272.  
  273.  
  274. d.open();
  275. // Dal.insertProduct(Ja);
  276.  
  277. d.insertProduct(Ja);
  278.  
  279. d.close();
  280.  
  281. /*Intent i = new Intent(Login.this, MainActivity.class);
  282. startActivity(i);*/
  283.  
  284.  
  285.  
  286.  
  287. } catch (JSONException e) {
  288. e.printStackTrace();
  289. }
  290.  
  291.  
  292. Toast.makeText(Login.this, value, Toast.LENGTH_SHORT).show();
  293.  
  294. Type listType = new TypeToken<ArrayList<Detail>>() {
  295. }.getType();
  296.  
  297.  
  298. /*Atypes = null;
  299. Atypes = new Gson().fromJson(String.valueOf(value), listType);*/
  300.  
  301. } else {
  302. Log.e("ServiceHandler", "Couldn't get any data from the url");
  303.  
  304.  
  305. }
  306.  
  307.  
  308. }
  309.  
  310.  
  311. });
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318. /////////////////table service///////////////////
  319.  
  320. rq.GetRequest(ipadd + "fetch_table.php", Login.this, new Requests.VolleyCallback() {
  321. @Override
  322. public void onSuccess(String value) {
  323.  
  324.  
  325. if (value != null) {
  326. //System.out.println(ipadd + "/pull/prod.php");
  327. System.out.println("valuu: " + value);
  328.  
  329.  
  330. ProdData ProdData = new ProdData(c);
  331.  
  332. /* d.open();
  333. d.insertprod(jsonArray);
  334. d.close();*/
  335.  
  336. try {
  337. JSONArray Ja = new JSONArray(value);
  338. JSONObject obj = Ja.getJSONObject(0);
  339.  
  340.  
  341.  
  342. d.open();
  343. // Dal.insertProduct(Ja);
  344.  
  345. d.insertTable(Ja);
  346.  
  347. d.close();
  348.  
  349. /*Intent i = new Intent(Login.this, MainActivity.class);
  350. startActivity(i);*/
  351.  
  352.  
  353.  
  354.  
  355. } catch (JSONException e) {
  356. e.printStackTrace();
  357. }
  358.  
  359.  
  360. Toast.makeText(Login.this, value, Toast.LENGTH_SHORT).show();
  361.  
  362. Type listType = new TypeToken<ArrayList<Detail>>() {
  363. }.getType();
  364.  
  365.  
  366. /*Atypes = null;
  367. Atypes = new Gson().fromJson(String.valueOf(value), listType);*/
  368.  
  369. } else {
  370. Log.e("ServiceHandler", "Couldn't get any data from the url");
  371.  
  372.  
  373. }
  374.  
  375.  
  376. }
  377.  
  378.  
  379. });
  380.  
  381.  
  382.  
  383. /////////////////household service///////////////////
  384.  
  385. rq.GetRequest(ipadd + "fetch_mem_hous_vw.php", Login.this, new Requests.VolleyCallback() {
  386. @Override
  387. public void onSuccess(String value) {
  388.  
  389.  
  390. if (value != null) {
  391. //System.out.println(ipadd + "/pull/prod.php");
  392. System.out.println("valuu: " + value);
  393.  
  394.  
  395. ProdData ProdData = new ProdData(c);
  396.  
  397. /* d.open();
  398. d.insertprod(jsonArray);
  399. d.close();*/
  400.  
  401. try {
  402. JSONArray Ja = new JSONArray(value);
  403. JSONObject obj = Ja.getJSONObject(0);
  404.  
  405.  
  406.  
  407. d.open();
  408. // Dal.insertProduct(Ja);
  409.  
  410. d.insertHOUSEHOLD(Ja);
  411.  
  412. d.close();
  413.  
  414. /*Intent i = new Intent(Login.this, MainActivity.class);
  415. startActivity(i);*/
  416.  
  417.  
  418.  
  419.  
  420. } catch (JSONException e) {
  421. e.printStackTrace();
  422. }
  423.  
  424.  
  425. Toast.makeText(Login.this, value, Toast.LENGTH_SHORT).show();
  426.  
  427. Type listType = new TypeToken<ArrayList<Detail>>() {
  428. }.getType();
  429.  
  430.  
  431. /*Atypes = null;
  432. Atypes = new Gson().fromJson(String.valueOf(value), listType);*/
  433.  
  434. } else {
  435. Log.e("ServiceHandler", "Couldn't get any data from the url");
  436.  
  437.  
  438. }
  439.  
  440.  
  441. }
  442.  
  443.  
  444. });
  445.  
  446.  
  447.  
  448.  
  449.  
  450. }
  451. });
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460. }
  461.  
  462.  
  463.  
  464. }
Add Comment
Please, Sign In to add comment