Exp 28
Exp 28
android:layout_marginTop="8dp"
android:layout_marginEnd="24dp"
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLay android:autofillHints="@string/prompt_passwor
out d"
android:hint="@string/prompt_password"
xmlns:android="http://schemas.android.com/ap
k/res/android"
android:imeActionLabel="@string/action_sign_in
xmlns:app="http://schemas.android.com/apk/re _short"
s-auto" android:imeOptions="actionDone"
android:inputType="textPassword"
xmlns:tools="http://schemas.android.com/tools" android:selectAllOnFocus="true"
app:layout_constraintEnd_toEndOf="parent"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" app:layout_constraintStart_toStartOf="parent"
android:paddingLeft="@dimen/activity_horizont app:layout_constraintTop_toBottomOf="@+id/us
al_margin" ername" />
android:paddingTop="@dimen/activity_vertical_ <Button
margin" android:id="@+id/login"
android:layout_width="wrap_content"
android:paddingRight="@dimen/activity_horizon android:layout_height="wrap_content"
android:layout_gravity="start"
tal_margin"
android:layout_marginStart="48dp"
android:paddingBottom="@dimen/activity_verti android:layout_marginTop="16dp"
cal_margin" android:layout_marginEnd="48dp"
tools:context=".ui.login.LoginActivity"> android:layout_marginBottom="64dp"
android:enabled="false"
<EditText android:text="@string/action_sign_in"
android:id="@+id/username"
android:layout_width="0dp" app:layout_constraintBottom_toBottomOf="pare
android:layout_height="wrap_content" nt"
android:layout_marginStart="24dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="96dp"
android:layout_marginEnd="24dp" app:layout_constraintStart_toStartOf="parent"
android:autofillHints="@string/prompt_email" app:layout_constraintTop_toBottomOf="@+id/p
android:hint="@string/prompt_email" assword"
android:inputType="textEmailAddress" app:layout_constraintVertical_bias="0.2" />
android:selectAllOnFocus="true" <TextView
android:id="@+id/textView"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="wrap_content"
app:layout_constraintStart_toStartOf="parent" android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent" android:text="asdf"
/> tools:layout_editor_absoluteX="46dp"
tools:layout_editor_absoluteY="414dp" />
<EditText <ProgressBar
android:id="@+id/password" android:id="@+id/loading"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="24dp" android:layout_gravity="center"
android:layout_marginStart="32dp" ry;
android:layout_marginTop="64dp"
android:layout_marginEnd="32dp" public class LoginActivity extends
android:layout_marginBottom="64dp" AppCompatActivity {
android:visibility="gone"
private LoginViewModel loginViewModel;
app:layout_constraintBottom_toBottomOf="pare
nt" @Override
public void onCreate(Bundle
app:layout_constraintEnd_toEndOf="@+id/pass savedInstanceState) {
word" super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
app:layout_constraintStart_toStartOf="@+id/pas loginViewModel =
sword" ViewModelProviders.of(this, new
app:layout_constraintTop_toTopOf="parent" LoginViewModelFactory())
app:layout_constraintVertical_bias="0.3" /> .get(LoginViewModel.class);
final TextView tv =
(TextView)findViewById(R.id.textView);
</androidx.constraintlayout.widget.ConstraintLa final EditText usernameEditText =
yout> findViewById(R.id.username);
final EditText passwordEditText =
findViewById(R.id.password);
final Button loginButton =
findViewById(R.id.login);
final ProgressBar loadingProgressBar =
LoginActivity.java
findViewById(R.id.loading);
package com.example.login2.ui.login; tv.setText(" ");
loadingProgressBar.setVisibility(View.GONE); loginViewModel.login(usernameEditText.getText()
if (loginResult.getError() != null) { .toString(),
showLoginFailed(loginResult.getError()); passwordEditText.getText().toString());
} }
if (loginResult.getSuccess() != null) { return false;
}
updateUiWithUser(loginResult.getSuccess()); });
}
setResult(Activity.RESULT_OK); loginButton.setOnClickListener(new
View.OnClickListener() {
//Complete and destroy login activity @Override
once successful public void onClick(View v) {
finish(); String name,pass;
} name =
}); usernameEditText.getText().toString();
pass =
TextWatcher afterTextChangedListener = new passwordEditText.getText().toString();
TextWatcher() {
@Override if(name.equalsIgnoreCase("MHSSP") &&
public void pass.equalsIgnoreCase("MHSSP123"))
beforeTextChanged(CharSequence s, int start, int {
count, int after) {
// ignore //Toast.makeText(getApplicationContext(),"Login
} Successful",Toast.LENGTH_LONG).show();
tv.setText("Login Successful");
@Override }
public void onTextChanged(CharSequence else
s, int start, int before, int count) { {
// ignore
} Toast.makeText(getApplicationContext(),"Login
Unsuccessful",Toast.LENGTH_LONG).show();
@Override //tv.setText("Login Successful");
public void afterTextChanged(Editable s) { }
}
loginViewModel.loginDataChanged(usernameEdit });
Text.getText().toString(), }
LoginResult.java
package com.example.login2.ui.login;
import androidx.annotation.Nullable;
/**
* Authentication result : success (user details) or
error message.
*/
class LoginResult {
@Nullable
private LoggedInUserView success;
@Nullable
private Integer error;
LoginResult(@Nullable LoggedInUserView
success) {
this.success = success;
}
@Nullable
LoggedInUserView getSuccess() {
return success;
}
@Nullable
Integer getError() {
return error;
}
}