// Path: RapidFTR-Android/src/main/java/com/rapidftr/task/ChangePasswordTask.java
// public class ChangePasswordTask extends AsyncTask<String, Boolean, Boolean> {
// 
//     private ChangePasswordService changePasswordService;
//     private String username;
//     private RapidFtrApplication context;
//     private Activity activity;
//     private String currentPassword;
//     private String newPassword;
// 
// 
//     @Inject
//     public ChangePasswordTask(ChangePasswordService changePasswordService, RapidFtrApplication context) {
//         this.changePasswordService = changePasswordService;
//         this.context = context;
//         this.username = context.getCurrentUser().getUserName();
//     }
// 
//     @Override
//     protected Boolean doInBackground(String... params) {
//         try {
//             currentPassword = params[0];
//             newPassword = params[1];
//             HttpResponse response = changePasswordService.updatePassword(currentPassword, newPassword , params[2]);
//             return response.getStatusLine().getStatusCode() == SC_OK;
//         } catch (IOException e) {
//             return false;
//         }
//     }
// 
//     @Override
//     protected void onPostExecute(Boolean result) {
//         super.onPostExecute(result);
//         if (result) {
//             activity.finish();
//             try {
//                 User user = new User(this.username, this.currentPassword).load();
//                 user.setPassword(newPassword);
//                 user.save();
//             } catch (Exception e) {
//                 Log.e("ChangePasswordTask",e.getMessage());
//             }
//             Toast.makeText(context, R.string.password_change_success, Toast.LENGTH_LONG).show();
//         } else {
//             Toast.makeText(context, R.string.password_change_failed, Toast.LENGTH_LONG).show();
//         }
//     }
// 
// 
//     public void setActivity(Activity activity) {
//         this.activity = activity;
//     }
// }


import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.rapidftr.R;
import com.rapidftr.RapidFtrApplication;
import com.rapidftr.task.ChangePasswordTask;
            public void onClick(DialogInterface dialog, int id) {
                cancelSync(RapidFtrApplication.getApplicationInstance());
                sendRequestToServer(old,new_password,confirmation);
            }
        });
        builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {}
        });

        builder.create().show();
    }
    protected void cancelSync(RapidFtrApplication context) {
        RapidFtrApplication.getApplicationInstance().cleanSyncTask();
    }

    protected boolean isPasswordSameAsConfirmPassword() {
        if (!getEditText(R.id.new_password).equals(getEditText(R.id.new_password_confirm))) {
            ((EditText) findViewById(R.id.new_password_confirm)).setError(getString(R.string.password_mismatch));
            return false;
        }
        return true;
    }

    protected boolean validatesPresenceOfMandatoryFields() {
        return validateTextFieldNotEmpty(R.id.current_password, R.string.mandatory) &
                validateTextFieldNotEmpty(R.id.new_password, R.string.mandatory) &
                validateTextFieldNotEmpty(R.id.new_password_confirm, R.string.mandatory);
    }

    protected void sendRequestToServer(String old_password, String new_password, String confirmation) {
// Path: RapidFTR-Android/src/main/java/com/rapidftr/task/ChangePasswordTask.java
// public class ChangePasswordTask extends AsyncTask<String, Boolean, Boolean> {
// 
//     private ChangePasswordService changePasswordService;
//     private String username;
//     private RapidFtrApplication context;
//     private Activity activity;
//     private String currentPassword;
//     private String newPassword;
// 
// 
//     @Inject
//     public ChangePasswordTask(ChangePasswordService changePasswordService, RapidFtrApplication context) {
//         this.changePasswordService = changePasswordService;
//         this.context = context;
//         this.username = context.getCurrentUser().getUserName();
//     }
// 
//     @Override
//     protected Boolean doInBackground(String... params) {
//         try {
//             currentPassword = params[0];
//             newPassword = params[1];
//             HttpResponse response = changePasswordService.updatePassword(currentPassword, newPassword , params[2]);
//             return response.getStatusLine().getStatusCode() == SC_OK;
//         } catch (IOException e) {
//             return false;
//         }
//     }
// 
//     @Override
//     protected void onPostExecute(Boolean result) {
//         super.onPostExecute(result);
//         if (result) {
//             activity.finish();
//             try {
//                 User user = new User(this.username, this.currentPassword).load();
//                 user.setPassword(newPassword);
//                 user.save();
//             } catch (Exception e) {
//                 Log.e("ChangePasswordTask",e.getMessage());
//             }
//             Toast.makeText(context, R.string.password_change_success, Toast.LENGTH_LONG).show();
//         } else {
//             Toast.makeText(context, R.string.password_change_failed, Toast.LENGTH_LONG).show();
//         }
//     }
// 
// 
//     public void setActivity(Activity activity) {
//         this.activity = activity;
//     }
// }


// Path: RapidFTR-Android/src/main/java/com/rapidftr/activity/ChangePasswordActivity.java
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.rapidftr.R;
import com.rapidftr.RapidFtrApplication;
import com.rapidftr.task.ChangePasswordTask;

            public void onClick(DialogInterface dialog, int id) {
                cancelSync(RapidFtrApplication.getApplicationInstance());
                sendRequestToServer(old,new_password,confirmation);
            }
        });
        builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {}
        });

        builder.create().show();
    }
    protected void cancelSync(RapidFtrApplication context) {
        RapidFtrApplication.getApplicationInstance().cleanSyncTask();
    }

    protected boolean isPasswordSameAsConfirmPassword() {
        if (!getEditText(R.id.new_password).equals(getEditText(R.id.new_password_confirm))) {
            ((EditText) findViewById(R.id.new_password_confirm)).setError(getString(R.string.password_mismatch));
            return false;
        }
        return true;
    }

    protected boolean validatesPresenceOfMandatoryFields() {
        return validateTextFieldNotEmpty(R.id.current_password, R.string.mandatory) &
                validateTextFieldNotEmpty(R.id.new_password, R.string.mandatory) &
                validateTextFieldNotEmpty(R.id.new_password_confirm, R.string.mandatory);
    }

    protected void sendRequestToServer(String old_password, String new_password, String confirmation) {
        ChangePasswordTask task = inject(ChangePasswordTask.class);