Skip to content

Instantly share code, notes, and snippets.

@roman-smirnov
Created October 20, 2016 13:59
Show Gist options
  • Save roman-smirnov/fc7c9b392e8cb715e946b62e8df04d4e to your computer and use it in GitHub Desktop.
Save roman-smirnov/fc7c9b392e8cb715e946b62e8df04d4e to your computer and use it in GitHub Desktop.
/* button and background animation gist */
package roman.com.cryptobox.activities;
import android.animation.Animator;
import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ScrollView;
import roman.com.cryptobox.R;
import roman.com.cryptobox.contracts.LoginContract;
import roman.com.cryptobox.presenters.LoginPresenter;
/**
* A login screen that offers login via email/password.
*/
public class LoginActivity extends AppCompatActivity implements LoginContract.View {
//the presenter(logic module)
private LoginContract.Presenter mPresenter;
// UI references.
private EditText mPasswordEditText;
private TextInputLayout mTextInputLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mPresenter = new LoginPresenter(this);
//get the views
mPasswordEditText = (EditText) findViewById(R.id.edittext_password_login);
mTextInputLayout = (TextInputLayout) findViewById(R.id.textinputlayout_password);
// some stuff for avshi
// ApiTester tester = new ApiTester();
// tester.runScripts();
}
/**
* a listener method for the login button click event
*
* @param view the login button
*/
public void onClickLoginButton(View view) {
//call the verification logic on the presenter
mPresenter.loginButtonClicked(mPasswordEditText.getText().toString());
}
/**
* go to NotesActivity - the ones with the list view of all notes
*/
@Override
public void showNotesActivity() {
//show the user the password is correct
// will call goToNotesActivity when finished
showPasswordGood();
}
/**
* Go to the notes activity
*/
private void goToNotesActivity(){
//launch the permissions activity
Intent intent = new Intent(this, NotesActivity.class);
startActivity(intent);
finish();
}
/**
* show user an error demonstration that the password was incorrect
*/
@Override
public void showPasswordBad() {
mTextInputLayout.setError(getString(R.string.error_incorrect_password));
mPasswordEditText.requestFocus();
}
/**
* provide a nice animation to demonstrate to the user that the password was good
*/
private void showPasswordGood() {
final Button loginButton = (Button) findViewById(R.id.button_login);
final ScrollView scrollingView = (ScrollView) findViewById(R.id.login_scrollview_layout);
loginButton.setBackgroundTintList(getResources().getColorStateList(R.color.colorAccent));
// button animation
ValueAnimator animator1 = ValueAnimator.ofObject(new ArgbEvaluator(), getResources().getColor(R.color.cryptobox_blue), getResources().getColor(R.color.cryptobox_positive_green_1));
animator1.setDuration(500);
animator1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Integer color = (Integer) animation.getAnimatedValue();
if (color != null) {
loginButton.setBackgroundTintList(ColorStateList.valueOf(color));
}
}
});
// background animation
ValueAnimator animator2 = ValueAnimator.ofObject(new ArgbEvaluator(), getResources().getColor(R.color.white), getResources().getColor(R.color.cryptobox_positive_green_2));
animator2.setDuration(500);
animator2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Integer color = (Integer) animation.getAnimatedValue();
if (color != null) {
scrollingView.setBackground(new ColorDrawable(color));
}
}
});
animator1.start();
animator2.start();
loginButton.setText(getString(R.string.acitivity_login_button_text_state_2));
animator1.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
goToNotesActivity();
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment