Skip to content

Instantly share code, notes, and snippets.

Created January 18, 2017 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/9b542537948409ffb0846cb22ca3c801 to your computer and use it in GitHub Desktop.
Save anonymous/9b542537948409ffb0846cb22ca3c801 to your computer and use it in GitHub Desktop.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_login);
getAllWidgets();
util = getIntent().getParcelableExtra("util");
Log.e("TAG", "util===" + util);
SharedPreferences sitePrefs = UserLoginActivity.this.getSharedPreferences(ApplicationUtil.SITE_PREF, Context.MODE_PRIVATE);
siteUrl = sitePrefs.getString("siteUrl", null);
String siteUrl = ApplicationUtil.getSiteUrl();
Log.i("LOGIN ACTIVITY", "URL===>" + siteUrl);
userPrefs = UserLoginActivity.this.getSharedPreferences(ApplicationUtil.USER_PREF, Context.MODE_PRIVATE);
edUsername.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() < 1) {
ilUsername.setErrorEnabled(true);
ilUsername.setError("Please enter username");
}
if (s.length() > 0) {
ilUsername.setError(null);
ilUsername.setErrorEnabled(false);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
edPassword.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() < 1) {
ilPassword.setErrorEnabled(true);
ilPassword.setError("Please enter password");
}
if (s.length() > 0) {
ilPassword.setError(null);
ilPassword.setErrorEnabled(false);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
btnLogin.setOnClickListener(this);
btnChangeURL.setOnClickListener(this);
}
public void getAllWidgets() {
btnLogin = (Button) findViewById(R.id.activity_user_login_btn);
btnChangeURL = (Button) findViewById(R.id.activity_user_login_change_url_btn);
ilUsername=(TextInputLayout) findViewById(R.id.activity_user_login_username_til);
ilPassword=(TextInputLayout) findViewById(R.id.activity_user_login_password_til);
layout = (LinearLayout) findViewById(R.id.activity_login_parent_layout);
edUsername = (EditText) findViewById(R.id.activity_user_login_username_et);
edPassword = (EditText) findViewById(R.id.activity_user_login_password_et);
}
@Override
public void onClick(View view) {
final boolean isNoError;
switch (view.getId())
{
case R.id.activity_user_login_btn:
isNoError = checkValidation();
if (isNoError) {
LoginUser(); // Webcall method
}
break;
case R.id.activity_user_login_change_url_btn:
SharedPreferences sitePrefs = UserLoginActivity.this.getSharedPreferences(ApplicationUtil.SITE_PREF,
Context.MODE_PRIVATE);
SharedPreferences userPref = UserLoginActivity.this.getSharedPreferences(ApplicationUtil.USER_PREF,
Context.MODE_PRIVATE);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(UserLoginActivity.this);
SharedPreferences.Editor edit = userPref.edit();
edit.clear();
edit.apply();
SharedPreferences.Editor editor=sitePrefs.edit();
editor.clear();
editor.apply();
SharedPreferences.Editor editor1 = preferences.edit();
editor1.clear();
editor1.apply();
Intent i = new Intent(UserLoginActivity.this, ChangeURLActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
overridePendingTransition(R.anim.left_in, R.anim.right_out);
finish();
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment