Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <resources>
- <string name="country_prompt">Choose a country</string>
- <string name="ip">http://192.168.10.45/</string>
- </resources>
- public class Login extends AppCompatActivity {
- Button sync_data,login;
- EditText username,pwd;
- Requests rq;
- String ipadd;
- Context c;
- SharedPreferences sp;
- dal d = new dal(this);
- dal.DBHelper a = d.new DBHelper(this);
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.login);
- getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
- final Animation myanim = AnimationUtils.loadAnimation(Login.this, R.anim.btnanim);
- ipadd = getResources().getString(R.string.ip);
- sp=getSharedPreferences("login",MODE_PRIVATE);
- login = (Button)findViewById(R.id.btnLogin);
- sync_data = (Button)findViewById(R.id.sync_data);
- username = (EditText)findViewById(R.id.txtUsername);
- pwd = (EditText)findViewById(R.id.txtPassword);
- login.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View arg0) {
- arg0.startAnimation(myanim);
- InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(username.getWindowToken(), 0);
- imm.hideSoftInputFromWindow(pwd.getWindowToken(), 0);
- String Username = username.getText().toString();
- String password = pwd.getText().toString();
- if (username.length() > 0 && password.length() > 0) {
- try {
- if (a.Login(Username, password)) {
- SharedPreferences.Editor s=sp.edit();
- s.putString("name",username.getText().toString());
- s.commit();
- Intent i = new Intent(Login.this, MainPage.class);
- startActivity(i);
- Toast.makeText(Login.this,
- "Successfully Logged In", Toast.LENGTH_LONG)
- .show();
- } else {
- Toast.makeText(Login.this,
- "Invalid username or password",
- Toast.LENGTH_LONG).show();
- }
- } catch (Exception e) {
- Toast.makeText(Login.this, "Some problem occurred",
- Toast.LENGTH_LONG).show();
- }
- } else {
- Toast.makeText(Login.this,
- "Username or Password is empty", Toast.LENGTH_LONG).show();
- }
- }
- });
- sync_data.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- rq = new Requests();
- rq.GetRequest(ipadd + "fetch_waiter.php", Login.this, new Requests.VolleyCallback() {
- @Override
- public void onSuccess(String value) {
- if (value != null) {
- //System.out.println(ipadd + "/pull/prod.php");
- System.out.println("valuu: " + value);
- ProdData ProdData = new ProdData(c);
- /* d.open();
- d.insertprod(jsonArray);
- d.close();*/
- try {
- JSONArray Ja = new JSONArray(value);
- JSONObject obj = Ja.getJSONObject(0);
- d.open();
- // Dal.insertProduct(Ja);
- d.insertSignIn(Ja);
- d.close();
- /*Intent i = new Intent(Login.this, MainActivity.class);
- startActivity(i);*/
- } catch (JSONException e) {
- e.printStackTrace();
- }
- Toast.makeText(Login.this, value, Toast.LENGTH_SHORT).show();
- Type listType = new TypeToken<ArrayList<Detail>>() {
- }.getType();
- /*Atypes = null;
- Atypes = new Gson().fromJson(String.valueOf(value), listType);*/
- } else {
- Log.e("ServiceHandler", "Couldn't get any data from the url");
- }
- }
- });
- ///////////////////member service//////////////////////////////
- rq.GetRequest(ipadd + "fetch_member.php", Login.this, new Requests.VolleyCallback() {
- @Override
- public void onSuccess(String value) {
- if (value != null) {
- //System.out.println(ipadd + "/pull/prod.php");
- System.out.println("valuu: " + value);
- ProdData ProdData = new ProdData(c);
- /* d.open();
- d.insertprod(jsonArray);
- d.close();*/
- try {
- JSONArray Ja = new JSONArray(value);
- JSONObject obj = Ja.getJSONObject(0);
- d.open();
- // Dal.insertProduct(Ja);
- d.insertMember(Ja);
- d.close();
- /*Intent i = new Intent(Login.this, MainActivity.class);
- startActivity(i);*/
- } catch (JSONException e) {
- e.printStackTrace();
- }
- Toast.makeText(Login.this, value, Toast.LENGTH_SHORT).show();
- Type listType = new TypeToken<ArrayList<Detail>>() {
- }.getType();
- /*Atypes = null;
- Atypes = new Gson().fromJson(String.valueOf(value), listType);*/
- } else {
- Log.e("ServiceHandler", "Couldn't get any data from the url");
- }
- }
- });
- /////////////////product service///////////////////
- rq.GetRequest(ipadd + "fetch_item.php", Login.this, new Requests.VolleyCallback() {
- @Override
- public void onSuccess(String value) {
- if (value != null) {
- //System.out.println(ipadd + "/pull/prod.php");
- System.out.println("valuu: " + value);
- ProdData ProdData = new ProdData(c);
- /* d.open();
- d.insertprod(jsonArray);
- d.close();*/
- try {
- JSONArray Ja = new JSONArray(value);
- JSONObject obj = Ja.getJSONObject(0);
- d.open();
- // Dal.insertProduct(Ja);
- d.insertProduct(Ja);
- d.close();
- /*Intent i = new Intent(Login.this, MainActivity.class);
- startActivity(i);*/
- } catch (JSONException e) {
- e.printStackTrace();
- }
- Toast.makeText(Login.this, value, Toast.LENGTH_SHORT).show();
- Type listType = new TypeToken<ArrayList<Detail>>() {
- }.getType();
- /*Atypes = null;
- Atypes = new Gson().fromJson(String.valueOf(value), listType);*/
- } else {
- Log.e("ServiceHandler", "Couldn't get any data from the url");
- }
- }
- });
- /////////////////table service///////////////////
- rq.GetRequest(ipadd + "fetch_table.php", Login.this, new Requests.VolleyCallback() {
- @Override
- public void onSuccess(String value) {
- if (value != null) {
- //System.out.println(ipadd + "/pull/prod.php");
- System.out.println("valuu: " + value);
- ProdData ProdData = new ProdData(c);
- /* d.open();
- d.insertprod(jsonArray);
- d.close();*/
- try {
- JSONArray Ja = new JSONArray(value);
- JSONObject obj = Ja.getJSONObject(0);
- d.open();
- // Dal.insertProduct(Ja);
- d.insertTable(Ja);
- d.close();
- /*Intent i = new Intent(Login.this, MainActivity.class);
- startActivity(i);*/
- } catch (JSONException e) {
- e.printStackTrace();
- }
- Toast.makeText(Login.this, value, Toast.LENGTH_SHORT).show();
- Type listType = new TypeToken<ArrayList<Detail>>() {
- }.getType();
- /*Atypes = null;
- Atypes = new Gson().fromJson(String.valueOf(value), listType);*/
- } else {
- Log.e("ServiceHandler", "Couldn't get any data from the url");
- }
- }
- });
- /////////////////household service///////////////////
- rq.GetRequest(ipadd + "fetch_mem_hous_vw.php", Login.this, new Requests.VolleyCallback() {
- @Override
- public void onSuccess(String value) {
- if (value != null) {
- //System.out.println(ipadd + "/pull/prod.php");
- System.out.println("valuu: " + value);
- ProdData ProdData = new ProdData(c);
- /* d.open();
- d.insertprod(jsonArray);
- d.close();*/
- try {
- JSONArray Ja = new JSONArray(value);
- JSONObject obj = Ja.getJSONObject(0);
- d.open();
- // Dal.insertProduct(Ja);
- d.insertHOUSEHOLD(Ja);
- d.close();
- /*Intent i = new Intent(Login.this, MainActivity.class);
- startActivity(i);*/
- } catch (JSONException e) {
- e.printStackTrace();
- }
- Toast.makeText(Login.this, value, Toast.LENGTH_SHORT).show();
- Type listType = new TypeToken<ArrayList<Detail>>() {
- }.getType();
- /*Atypes = null;
- Atypes = new Gson().fromJson(String.valueOf(value), listType);*/
- } else {
- Log.e("ServiceHandler", "Couldn't get any data from the url");
- }
- }
- });
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment