|
@@ -0,0 +1,383 @@
|
|
|
|
|
+package com.usai.ratradefiling.my;
|
|
|
|
|
+
|
|
|
|
|
+import android.animation.Animator;
|
|
|
|
|
+import android.animation.AnimatorListenerAdapter;
|
|
|
|
|
+import android.annotation.TargetApi;
|
|
|
|
|
+import android.app.Activity;
|
|
|
|
|
+import android.app.AlertDialog.Builder;
|
|
|
|
|
+import android.content.Context;
|
|
|
|
|
+import android.content.DialogInterface;
|
|
|
|
|
+import android.content.DialogInterface.OnClickListener;
|
|
|
|
|
+import android.content.Intent;
|
|
|
|
|
+import android.os.AsyncTask;
|
|
|
|
|
+import android.os.Build;
|
|
|
|
|
+import android.os.Bundle;
|
|
|
|
|
+import android.text.TextUtils;
|
|
|
|
|
+import android.util.Log;
|
|
|
|
|
+import android.view.Gravity;
|
|
|
|
|
+import android.view.KeyEvent;
|
|
|
|
|
+import android.view.LayoutInflater;
|
|
|
|
|
+import android.view.MenuItem;
|
|
|
|
|
+import android.view.View;
|
|
|
|
|
+import android.view.inputmethod.EditorInfo;
|
|
|
|
|
+import android.view.inputmethod.InputMethodManager;
|
|
|
|
|
+import android.widget.EditText;
|
|
|
|
|
+import android.widget.TextView;
|
|
|
|
|
+import android.widget.Toast;
|
|
|
|
|
+
|
|
|
|
|
+import androidx.appcompat.app.ActionBar;
|
|
|
|
|
+import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
+
|
|
|
|
|
+import com.usai.ratradefiling.R;
|
|
|
|
|
+import com.usai.ratradefiling.TradeFilingApplication;
|
|
|
|
|
+import com.usai.ratradefiling.dataprovider.OnlineDataProvider;
|
|
|
|
|
+import com.usai.ratradefiling.dataprovider.RADataProvider;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+import org.json.JSONObject;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Activity which displays a login screen to the user, offering registration as
|
|
|
|
|
+ * well.
|
|
|
|
|
+ */
|
|
|
|
|
+public class ChangePasswordActivity extends AppCompatActivity {
|
|
|
|
|
+ private UserLoginTask mAuthTask = null;
|
|
|
|
|
+
|
|
|
|
|
+ // Values for email and password at the time of the login attempt.
|
|
|
|
|
+ // private String m_sUser;
|
|
|
|
|
+ private String m_soldPassword;
|
|
|
|
|
+ private String m_snewPassword;
|
|
|
|
|
+ private String m_snew1Password;
|
|
|
|
|
+
|
|
|
|
|
+ // UI references.
|
|
|
|
|
+ private EditText mOldpassView;
|
|
|
|
|
+ private EditText mNewpassView;
|
|
|
|
|
+ private EditText mNew1passView;
|
|
|
|
|
+ private View mLoginFormView;
|
|
|
|
|
+ private View mLoginStatusView;
|
|
|
|
|
+ private TextView mLoginStatusMessageView;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean onOptionsItemSelected(MenuItem item)
|
|
|
|
|
+ {
|
|
|
|
|
+ Intent intent = new Intent();
|
|
|
|
|
+ switch (item.getItemId())
|
|
|
|
|
+ {
|
|
|
|
|
+ case android.R.id.home:
|
|
|
|
|
+ finish();
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ return super.onOptionsItemSelected(item);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void setCustomActionBar() {
|
|
|
|
|
+ ActionBar.LayoutParams lp =new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER);
|
|
|
|
|
+ View mActionBarView = LayoutInflater.from(this).inflate(R.layout.actionbar_customtitle, null);
|
|
|
|
|
+
|
|
|
|
|
+ TextView titleview = mActionBarView.findViewById(R.id.title);
|
|
|
|
|
+ titleview.setText(getTitle());
|
|
|
|
|
+
|
|
|
|
|
+ ActionBar actionBar = getSupportActionBar();
|
|
|
|
|
+ actionBar.setCustomView(mActionBarView, lp);
|
|
|
|
|
+// actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
|
|
|
|
|
+// actionBar.setDisplayShowCustomEnabled(true);
|
|
|
|
|
+ actionBar.setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ actionBar.setDisplayShowTitleEnabled(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
|
|
+
|
|
|
|
|
+ setContentView(R.layout.activity_change_password);
|
|
|
|
|
+
|
|
|
|
|
+ setCustomActionBar();
|
|
|
|
|
+
|
|
|
|
|
+ // Set up the login form.
|
|
|
|
|
+
|
|
|
|
|
+ mOldpassView = (EditText) findViewById(R.id.old_password);
|
|
|
|
|
+
|
|
|
|
|
+ mNewpassView = (EditText) findViewById(R.id.new_password);
|
|
|
|
|
+ mNew1passView = (EditText) findViewById(R.id.new_password_confirm);
|
|
|
|
|
+ mNew1passView
|
|
|
|
|
+ .setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean onEditorAction(TextView textView, int id,
|
|
|
|
|
+ KeyEvent keyEvent) {
|
|
|
|
|
+ if (id == R.id.btn_ok || id == EditorInfo.IME_ACTION_DONE) {
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ InputMethodManager inputMethodManager = (InputMethodManager)getApplicationContext().getSystemService(
|
|
|
|
|
+ Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
+
|
|
|
|
|
+ // EditText editText =
|
|
|
|
|
+ // (EditText)findViewById(R.id.xxxx);
|
|
|
|
|
+ inputMethodManager.hideSoftInputFromWindow(
|
|
|
|
|
+ mNew1passView.getWindowToken(), 0); // ����
|
|
|
|
|
+ changepassword();
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ mLoginFormView = findViewById(R.id.login_form);
|
|
|
|
|
+ mLoginStatusView = findViewById(R.id.login_status);
|
|
|
|
|
+ mLoginStatusMessageView = (TextView) findViewById(R.id.login_status_message);
|
|
|
|
|
+
|
|
|
|
|
+ findViewById(R.id.btn_ok).setOnClickListener(
|
|
|
|
|
+ new View.OnClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View view) {
|
|
|
|
|
+ InputMethodManager inputMethodManager = (InputMethodManager)getApplicationContext().getSystemService(
|
|
|
|
|
+ Context.INPUT_METHOD_SERVICE);
|
|
|
|
|
+
|
|
|
|
|
+ // EditText editText =
|
|
|
|
|
+ // (EditText)findViewById(R.id.xxxx);
|
|
|
|
|
+ inputMethodManager.hideSoftInputFromWindow(
|
|
|
|
|
+ mNew1passView.getWindowToken(), 0); // ����
|
|
|
|
|
+ changepassword();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ findViewById(R.id.btn_close).setOnClickListener(
|
|
|
|
|
+ new View.OnClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View view) {
|
|
|
|
|
+ finish();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // @Override
|
|
|
|
|
+ // public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
|
+ // super.onCreateOptionsMenu(menu);
|
|
|
|
|
+ // getMenuInflater().inflate(R.menu.change_password, menu);
|
|
|
|
|
+ // return true;
|
|
|
|
|
+ // }
|
|
|
|
|
+ //
|
|
|
|
|
+ // /**
|
|
|
|
|
+ // * Attempts to sign in or register the account specified by the login
|
|
|
|
|
+ // form.
|
|
|
|
|
+ // * If there are form errors (invalid email, missing fields, etc.), the
|
|
|
|
|
+ // * errors are presented and no actual login attempt is made.
|
|
|
|
|
+ // */
|
|
|
|
|
+ public void changepassword() {
|
|
|
|
|
+ if (mAuthTask != null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Reset errors.
|
|
|
|
|
+ mOldpassView.setError(null);
|
|
|
|
|
+ mNewpassView.setError(null);
|
|
|
|
|
+ mNew1passView.setError(null);
|
|
|
|
|
+
|
|
|
|
|
+ // Store values at the time of the login attempt.
|
|
|
|
|
+ m_soldPassword = mOldpassView.getText().toString();
|
|
|
|
|
+ m_snewPassword = mNewpassView.getText().toString();
|
|
|
|
|
+ m_snew1Password = mNew1passView.getText().toString();
|
|
|
|
|
+
|
|
|
|
|
+ boolean cancel = false;
|
|
|
|
|
+ View focusView = null;
|
|
|
|
|
+
|
|
|
|
|
+ // Check for a valid password.
|
|
|
|
|
+ if (TextUtils.isEmpty(m_soldPassword)) {
|
|
|
|
|
+ mOldpassView.setError(getString(R.string.error_field_required));
|
|
|
|
|
+ focusView = mOldpassView;
|
|
|
|
|
+ cancel = true;
|
|
|
|
|
+ } else if (TextUtils.isEmpty(m_snewPassword)) {
|
|
|
|
|
+ mNewpassView.setError(getString(R.string.error_field_required));
|
|
|
|
|
+ focusView = mNewpassView;
|
|
|
|
|
+ cancel = true;
|
|
|
|
|
+ } else if (TextUtils.isEmpty(m_snew1Password)) {
|
|
|
|
|
+ mNew1passView.setError(getString(R.string.error_field_required));
|
|
|
|
|
+ focusView = mNew1passView;
|
|
|
|
|
+ cancel = true;
|
|
|
|
|
+ } else if (m_snewPassword.equals(m_snew1Password)==false) {
|
|
|
|
|
+ mNew1passView.setError("New passwords not same");
|
|
|
|
|
+ focusView = mNew1passView;
|
|
|
|
|
+ cancel = true;
|
|
|
|
|
+ }else if (m_soldPassword.equals(TradeFilingApplication.get_pass())==false) {
|
|
|
|
|
+ mOldpassView.setError("Wrong password");
|
|
|
|
|
+ focusView = mNew1passView;
|
|
|
|
|
+ cancel = true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (cancel) {
|
|
|
|
|
+ // There was an error; don't attempt login and focus the first
|
|
|
|
|
+ // form field with an error.
|
|
|
|
|
+ focusView.requestFocus();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // Show a progress spinner, and kick off a background task to
|
|
|
|
|
+ // perform the user login attempt.
|
|
|
|
|
+ mLoginStatusMessageView.setText(R.string.login_progress_signing_in);
|
|
|
|
|
+ showProgress(true);
|
|
|
|
|
+ mAuthTask = new UserLoginTask();
|
|
|
|
|
+ mAuthTask.execute((Void) null);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Shows the progress UI and hides the login form.
|
|
|
|
|
+ */
|
|
|
|
|
+ @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
|
|
|
|
|
+ private void showProgress(final boolean show) {
|
|
|
|
|
+ // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
|
|
|
|
|
+ // for very easy animations. If available, use these APIs to fade-in
|
|
|
|
|
+ // the progress spinner.
|
|
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
|
|
|
|
|
+ int shortAnimTime = getResources().getInteger(
|
|
|
|
|
+ android.R.integer.config_shortAnimTime);
|
|
|
|
|
+
|
|
|
|
|
+ mLoginStatusView.setVisibility(View.VISIBLE);
|
|
|
|
|
+ mLoginStatusView.animate().setDuration(shortAnimTime)
|
|
|
|
|
+ .alpha(show ? 1 : 0)
|
|
|
|
|
+ .setListener(new AnimatorListenerAdapter() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onAnimationEnd(Animator animation) {
|
|
|
|
|
+ mLoginStatusView.setVisibility(show ? View.VISIBLE
|
|
|
|
|
+ : View.GONE);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ mLoginFormView.setVisibility(View.VISIBLE);
|
|
|
|
|
+ mLoginFormView.animate().setDuration(shortAnimTime)
|
|
|
|
|
+ .alpha(show ? 0 : 1)
|
|
|
|
|
+ .setListener(new AnimatorListenerAdapter() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onAnimationEnd(Animator animation) {
|
|
|
|
|
+ mLoginFormView.setVisibility(show ? View.GONE
|
|
|
|
|
+ : View.VISIBLE);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } else
|
|
|
|
|
+ {
|
|
|
|
|
+ // The ViewPropertyAnimator APIs are not available, so simply show
|
|
|
|
|
+ // and hide the relevant UI components.
|
|
|
|
|
+ mLoginStatusView.setVisibility(show ? View.VISIBLE : View.GONE);
|
|
|
|
|
+ mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Represents an asynchronous login/registration task used to authenticate
|
|
|
|
|
+ * the user.
|
|
|
|
|
+ */
|
|
|
|
|
+ public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {
|
|
|
|
|
+ int errorcode;
|
|
|
|
|
+ JSONObject json;
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected Boolean doInBackground(Void... params) {
|
|
|
|
|
+ json = RADataProvider.change_pass( m_snewPassword);
|
|
|
|
|
+ errorcode = json.optInt("result");
|
|
|
|
|
+ if (errorcode == OnlineDataProvider.RESULT_TRUE)
|
|
|
|
|
+ return true;
|
|
|
|
|
+ else {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onPostExecute(final Boolean success) {
|
|
|
|
|
+ Log.d("onPostExecute", "entry");
|
|
|
|
|
+ mAuthTask = null;
|
|
|
|
|
+ showProgress(false);
|
|
|
|
|
+ // if (netconnect == )
|
|
|
|
|
+ // {
|
|
|
|
|
+ //
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ if (success) {
|
|
|
|
|
+ Builder builder = new Builder(ChangePasswordActivity.this);
|
|
|
|
|
+ builder.setMessage(getString(R.string.str_password_changed));
|
|
|
|
|
+
|
|
|
|
|
+ builder.setTitle(getString(R.string.str_change_success));
|
|
|
|
|
+
|
|
|
|
|
+ builder.setPositiveButton(getString(android.R.string.ok), new OnClickListener() {
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
+ dialog.dismiss();
|
|
|
|
|
+ TradeFilingApplication.put_password(m_snewPassword);
|
|
|
|
|
+// ApexTrackingApplication.put_password(m_snewPassword);
|
|
|
|
|
+ setResult(Activity.RESULT_OK, null);
|
|
|
|
|
+ finish();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ builder.create().show();
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ switch (errorcode) {
|
|
|
|
|
+ case OnlineDataProvider.RESULT_NET_NOTAVAILABLE: {
|
|
|
|
|
+ Toast toast = Toast.makeText(getApplicationContext(),
|
|
|
|
|
+ getText(R.string.msg_connection_none),
|
|
|
|
|
+ Toast.LENGTH_LONG);
|
|
|
|
|
+ toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
|
|
+ toast.show();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ case OnlineDataProvider.RESULT_NET_ERROR: {
|
|
|
|
|
+ Toast toast = Toast.makeText(getApplicationContext(),
|
|
|
|
|
+ getText(R.string.msg_net_error), Toast.LENGTH_LONG);
|
|
|
|
|
+ toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
|
|
+ toast.show();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ case OnlineDataProvider.RESULT_ERROR:
|
|
|
|
|
+ // case Network.RESULT_RESPONSE_NULL:
|
|
|
|
|
+ {
|
|
|
|
|
+ Toast toast = Toast.makeText(getApplicationContext(),
|
|
|
|
|
+ getText(R.string.msg_net_resulterror),
|
|
|
|
|
+ Toast.LENGTH_LONG);
|
|
|
|
|
+ toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
|
|
+ toast.show();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ case OnlineDataProvider.RESULT_FAILED_WITH_MESSAGE: {
|
|
|
|
|
+ Builder builder = new Builder(ChangePasswordActivity.this);
|
|
|
|
|
+ builder.setMessage(json.optString("err_msg"));
|
|
|
|
|
+
|
|
|
|
|
+ builder.setTitle(getString(R.string.str_failed_to_changepassword));
|
|
|
|
|
+
|
|
|
|
|
+ builder.setPositiveButton(getString(android.R.string.ok), new OnClickListener() {
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
+ dialog.dismiss();
|
|
|
|
|
+
|
|
|
|
|
+// RetrievePasswordActivity.this.finish();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ builder.create().show();
|
|
|
|
|
+
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ default: {
|
|
|
|
|
+ Toast toast = Toast.makeText(getApplicationContext(),
|
|
|
|
|
+ getText(R.string.msg_net_resulterror) + ":"
|
|
|
|
|
+ + errorcode, Toast.LENGTH_LONG);
|
|
|
|
|
+ toast.setGravity(Gravity.CENTER, 0, 0);
|
|
|
|
|
+ toast.show();
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onCancelled() {
|
|
|
|
|
+ mAuthTask = null;
|
|
|
|
|
+ showProgress(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|