Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.abc.ukm_project1;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.content.Intent;
- import android.net.Uri;
- import android.os.AsyncTask;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ArrayAdapter;
- import android.widget.Button;
- import android.widget.TextView;
- import android.widget.Toast;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.ArrayList;
- /**
- * Created by Cisco on 10/2/2017.
- */
- public class CustomRowAdapter extends ArrayAdapter<users>
- {
- private final Context context;
- private final ArrayList<users> users_list;
- private ProgressDialog pDialog;
- JSONParser jsonParser = new JSONParser();
- private static final String url_login = "http://10.3.68.191/server/resetusers.php";
- public CustomRowAdapter(Context context, ArrayList<users> users_list)
- {
- super(context,R.layout.rowlayout,users_list);
- this.context=context;
- this.users_list=users_list;
- }
- public View getView(int position, View convertView, ViewGroup parent)
- {
- LayoutInflater inflater = (LayoutInflater) context
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
- final TextView tfullname = (TextView) rowView.findViewById(R.id.tfullname);
- final TextView tusername = (TextView) rowView.findViewById(R.id.tusername);
- users obj = users_list.get(position);
- tfullname.setText(obj.fullname);
- tusername.setText(obj.username);
- Button btnreset = (Button) rowView.findViewById(R.id.btnreset);
- btnreset.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- new resetusers().execute(tusername.getText().toString(),null,null);
- }
- });
- return rowView;
- }
- class resetusers extends AsyncTask<String, String, String>
- {
- protected void onPreExecute()
- {
- super.onPreExecute();
- pDialog = new ProgressDialog(context);
- pDialog.setMessage("Reseting user password. Please wait...");
- pDialog.setIndeterminate(false);
- pDialog.setCancelable(true);
- pDialog.show();
- }
- protected String doInBackground(String... params)
- {
- int success;
- try
- {
- Uri.Builder builder = new Uri.Builder()
- .appendQueryParameter("username", params[0]);
- String query = builder.build().getEncodedQuery();
- JSONObject json = jsonParser.makeHttpRequest(url_login, query);
- if(json !=null)
- {
- Log.d("resettinguser", json.toString());
- success = json.getInt("result");
- if (success == 1)
- {
- ((Activity) context).runOnUiThread(new Runnable()
- {
- public void run()
- {
- Toast.makeText(context, "Reset is success", Toast.LENGTH_LONG).show();
- }
- });
- }
- else
- {
- ((Activity)context).runOnUiThread(new Runnable()
- {
- public void run()
- {
- Toast.makeText(context, "Reset failed", Toast.LENGTH_LONG).show();
- }
- });
- }
- }
- else
- {
- ((Activity)context).runOnUiThread(new Runnable()
- {
- public void run()
- {
- Toast.makeText(context,"Unable to contact server",Toast.LENGTH_LONG).show();
- }
- });
- return null;
- }
- }
- catch (JSONException e)
- {
- e.printStackTrace();
- }
- return null;
- }
- protected void onPostExecute(String file_url)
- {
- pDialog.dismiss();
- }
- }
- }
- package com.abc.ukm_project1;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.widget.ArrayAdapter;
- import android.widget.ListView;
- import android.widget.Toast;
- import org.json.JSONObject;
- import java.util.ArrayList;
- /**
- * Created by Cisco on 9/26/2017.
- */
- public class usersactivity extends Activity {
- ListView listview1;
- private ProgressDialog pDialog;
- JSONParser jsonParser = new JSONParser();
- private static final String url_login = "http://10.3.68.191/server/getusers.php";
- public void onCreate(Bundle b) {
- super.onCreate(b);
- setContentView(R.layout.userslayout);
- listview1 = (ListView) findViewById(R.id.listview1);
- new getlistview().execute();
- }
- class getlistview extends AsyncTask<String, String, String> {
- protected void onPreExecute() {
- super.onPreExecute();
- pDialog = new ProgressDialog(usersactivity.this);
- pDialog.setMessage("Loading ListView. Please wait...");
- pDialog.setIndeterminate(false);
- pDialog.setCancelable(true);
- pDialog.show();
- }
- protected String doInBackground(String... params) {
- try {
- JSONObject json = jsonParser.makeHttpRequest(url_login, "");
- final ArrayList<users> users_list = new ArrayList<>();
- if (json != null) {
- int k = 0;
- while (k < json.getJSONArray("fullname").length()) {
- users obj = new users();
- obj.username = json.getJSONArray("username").getString(k);
- obj.fullname = json.getJSONArray("fullname").getString(k);
- users_list.add(obj);
- k++;
- }
- usersactivity.this.runOnUiThread(new Runnable() {
- public void run() {
- //String[] data = users.toArray(new String[users.size()]);
- CustomRowAdapter adapter = new CustomRowAdapter(usersactivity.this, users_list);
- ListView listView = (ListView) findViewById(R.id.listview1);
- listView.setAdapter(adapter);
- }
- });
- } else {
- usersactivity.this.runOnUiThread(new Runnable() {
- public void run() {
- Toast.makeText(usersactivity.this, "Unable to contact server", Toast.LENGTH_LONG).show();
- }
- });
- return null;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- protected void onPostExecute(String file_url) {
- pDialog.dismiss();
- }
- }
- }
- package com.abc.ukm_project1;
- /**
- * Created by Cisco on 10/3/2017.
- */
- public class users {
- public String username;
- public String fullname;
- }
- <?php
- include "newdb.php";
- $dbcon=connect_db();
- ?>
- <?php
- $flag=0;
- $statement="SELECT username,fullname FROM users";
- $result=mysqli_query($dbcon,$statement);
- $myObj=new \stdClass();
- $i=0;
- while($row=mysqli_fetch_array($result) )
- {
- $myObj->username[$i] = $row['username'];
- $myObj->fullname[$i] = $row['fullname'];
- $i++;
- }
- close_db();
- $myJSON = json_encode($myObj);
- echo $myJSON;
- exit();
- ?>
- <?php
- include "newdb.php";
- $dbcon=connect_db();
- ?>
- <?php
- $username=$_POST["username"];
- //$username='selva';
- //$password='password';
- $flag=0;
- $statement="UPDATE users SET password = '12345' where username = '$username'";
- //echo $statement;
- //exit();
- if (mysqli_query($dbcon, $statement))
- {
- $myObj=new \stdClass();
- $myObj->result = "1";
- $myJSON = json_encode($myObj);
- echo $myJSON;
- exit();
- }
- else
- {
- $myObj=new \stdClass();
- $myObj->result = "2";
- $myJSON = json_encode($myObj);
- echo $myJSON;
- exit();
- }
- close_db();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement