Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.kismec.kismecapp1;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.net.Uri;
- import android.os.AsyncTask;
- import android.support.annotation.NonNull;
- 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 selva on 11/11/2017.
- */
- public class rowlayoutadapter extends ArrayAdapter<users>
- {
- private ProgressDialog pDialog;
- JSONParser jsonParser = new JSONParser();
- private static final String url_login = "http://172.16.140.100/ukm/resetuser.php";
- private final Context context;
- private final ArrayList<users> users_list;
- public rowlayoutadapter(@NonNull 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 resetuser().execute(tusername.getText().toString(),null,null);
- }
- });
- return rowView;
- }
- class resetuser 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();
- }
- }
- }
- resetuser.php
- <?php
- include "newdb.php";
- $dbcon=connect_db();
- ?>
- <?php
- $username=$_POST["username"];
- $flag=0;
- $statement="update users set password='123456' where username='$username'";
- 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