├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── edu │ │ └── galileo │ │ └── mvp │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── edu │ │ │ └── galileo │ │ │ └── mvp │ │ │ └── LoginActivity.java │ └── res │ │ ├── layout │ │ └── activity_login.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── edu │ └── galileo │ └── mvp │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 14 | 26 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 53 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.1" 6 | defaultConfig { 7 | applicationId "edu.galileo.mvp" 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.3.0' 28 | compile 'com.android.support:design:25.3.0' 29 | testCompile 'junit:junit:4.12' 30 | } 31 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/fanzueto/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/edu/galileo/mvp/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package edu.galileo.mvp; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | 20 | @Test 21 | public void useAppContext() throws Exception { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getTargetContext(); 24 | 25 | assertEquals("edu.galileo.mvp", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 17 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/java/edu/galileo/mvp/LoginActivity.java: -------------------------------------------------------------------------------- 1 | package edu.galileo.mvp; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorListenerAdapter; 5 | import android.os.AsyncTask; 6 | import android.os.Bundle; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.text.TextUtils; 9 | import android.view.View; 10 | import android.view.View.OnClickListener; 11 | import android.widget.AutoCompleteTextView; 12 | import android.widget.Button; 13 | import android.widget.EditText; 14 | import android.widget.Toast; 15 | 16 | /** 17 | * A login screen that offers login via email/password. 18 | */ 19 | public class LoginActivity extends AppCompatActivity { 20 | 21 | /** 22 | * A dummy authentication store containing known user names and passwords. 23 | * TODO: remove after connecting to a real authentication system. 24 | */ 25 | private static final String[] DUMMY_CREDENTIALS = new String[] { 26 | "test@galileo.edu", "testtest" 27 | }; 28 | /** 29 | * Keep track of the login task to ensure we can cancel it if requested. 30 | */ 31 | private UserLoginTask mAuthTask = null; 32 | 33 | // UI references. 34 | private AutoCompleteTextView mEmailView; 35 | private EditText mPasswordView; 36 | private View mProgressView; 37 | private View mLoginFormView; 38 | 39 | @Override 40 | protected void onCreate(Bundle savedInstanceState) { 41 | super.onCreate(savedInstanceState); 42 | setContentView(R.layout.activity_login); 43 | // Set up the login form. 44 | mEmailView = (AutoCompleteTextView) findViewById(R.id.email); 45 | 46 | mPasswordView = (EditText) findViewById(R.id.password); 47 | 48 | Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button); 49 | mEmailSignInButton.setOnClickListener(new OnClickListener() { 50 | 51 | @Override 52 | public void onClick(View view) { 53 | attemptLogin(); 54 | } 55 | }); 56 | 57 | mLoginFormView = findViewById(R.id.login_form); 58 | mProgressView = findViewById(R.id.login_progress); 59 | } 60 | 61 | /** 62 | * Attempts to sign in or register the account specified by the login form. 63 | * If there are form errors (invalid email, missing fields, etc.), the 64 | * errors are presented and no actual login attempt is made. 65 | */ 66 | private void attemptLogin() { 67 | if (mAuthTask != null) { 68 | return; 69 | } 70 | 71 | // Reset errors. 72 | mEmailView.setError(null); 73 | mPasswordView.setError(null); 74 | 75 | // Store values at the time of the login attempt. 76 | String email = mEmailView.getText().toString(); 77 | String password = mPasswordView.getText().toString(); 78 | 79 | boolean cancel = false; 80 | View focusView = null; 81 | 82 | // Check for a valid password, if the user entered one. 83 | if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) { 84 | mPasswordView.setError(getString(R.string.error_invalid_password)); 85 | focusView = mPasswordView; 86 | cancel = true; 87 | } 88 | 89 | // Check for a valid email address. 90 | if (TextUtils.isEmpty(email)) { 91 | mEmailView.setError(getString(R.string.error_field_required)); 92 | focusView = mEmailView; 93 | cancel = true; 94 | } else if (!isEmailValid(email)) { 95 | mEmailView.setError(getString(R.string.error_invalid_email)); 96 | focusView = mEmailView; 97 | cancel = true; 98 | } 99 | 100 | if (cancel) { 101 | // There was an error; don't attempt login and focus the first 102 | // form field with an error. 103 | focusView.requestFocus(); 104 | } else { 105 | // Show a progress spinner, and kick off a background task to 106 | // perform the user login attempt. 107 | showProgress(true); 108 | mAuthTask = new UserLoginTask(email, password); 109 | mAuthTask.execute((Void) null); 110 | } 111 | } 112 | 113 | private boolean isEmailValid(String email) { 114 | //TODO: Replace this with your own logic 115 | return email.contains("@"); 116 | } 117 | 118 | private boolean isPasswordValid(String password) { 119 | //TODO: Replace this with your own logic 120 | return password.length() > 4; 121 | } 122 | 123 | /** 124 | * Shows the progress UI and hides the login form. 125 | */ 126 | public void showProgress(final boolean show) { 127 | int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime); 128 | 129 | mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); 130 | mLoginFormView.animate().setDuration(shortAnimTime).alpha( 131 | show ? 0 : 1).setListener(new AnimatorListenerAdapter() { 132 | 133 | @Override 134 | public void onAnimationEnd(Animator animation) { 135 | mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); 136 | } 137 | }); 138 | 139 | mProgressView.setVisibility(show ? View.VISIBLE : View.GONE); 140 | mProgressView.animate().setDuration(shortAnimTime).alpha( 141 | show ? 1 : 0).setListener(new AnimatorListenerAdapter() { 142 | 143 | @Override 144 | public void onAnimationEnd(Animator animation) { 145 | mProgressView.setVisibility(show ? View.VISIBLE : View.GONE); 146 | } 147 | }); 148 | } 149 | 150 | /** 151 | * Represents an asynchronous login/registration task used to authenticate 152 | * the user. 153 | */ 154 | public class UserLoginTask extends AsyncTask { 155 | 156 | private final String mEmail; 157 | private final String mPassword; 158 | 159 | UserLoginTask(String email, String password) { 160 | mEmail = email; 161 | mPassword = password; 162 | } 163 | 164 | @Override 165 | protected Boolean doInBackground(Void... params) { 166 | // TODO: attempt authentication against a network service. 167 | 168 | try { 169 | // Simulate network access. 170 | Thread.sleep(2000); 171 | } catch (InterruptedException e) { 172 | return false; 173 | } 174 | 175 | for (String credential : DUMMY_CREDENTIALS) { 176 | String[] pieces = credential.split(":"); 177 | if (pieces[0].equals(mEmail)) { 178 | // Account exists, return true if the password matches. 179 | return pieces[1].equals(mPassword); 180 | } 181 | } 182 | 183 | // TODO: register the new account here. 184 | return true; 185 | } 186 | 187 | @Override 188 | protected void onPostExecute(final Boolean success) { 189 | mAuthTask = null; 190 | showProgress(false); 191 | 192 | if (success) { 193 | Toast.makeText(LoginActivity.this, "Success", Toast.LENGTH_SHORT).show(); 194 | } else { 195 | mPasswordView.setError(getString(R.string.error_incorrect_password)); 196 | mPasswordView.requestFocus(); 197 | } 198 | } 199 | 200 | @Override 201 | protected void onCancelled() { 202 | mAuthTask = null; 203 | showProgress(false); 204 | } 205 | } 206 | } 207 | 208 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_login.xml: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 21 | 22 | 26 | 27 | 32 | 33 | 36 | 37 | 45 | 46 | 47 | 48 | 51 | 52 | 63 | 64 | 65 | 66 |