Last active
January 3, 2016 00:11
-
-
Save danylovolokh/7b95dfe367b280be89e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LoginActivity extends AppCompatActivity { | |
//... some fields here | |
private BroadcastReceiver mLoginBroadcastReceiver; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_login); | |
mLogin = (TextView) findViewById(R.id.login); | |
mPassword = (TextView) findViewById(R.id.password); | |
Button performLoginButton = (Button) findViewById(R.id.perform_login); | |
performLoginButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
String login = mLogin.getText().toString(); | |
String password = mPassword.getText().toString(); | |
performLoginViaService(login, password); | |
} | |
}); | |
} | |
private void performLoginViaService(String login, String password) { | |
mLoginBroadcastReceiver = new BroadcastReceiver() { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
unregisterReceiver(this); | |
mLoginBroadcastReceiver = null; | |
LoginResponse loginResponse = LoginResponse.getLoginResponse(intent); | |
handleLoginResponse(loginResponse); | |
} | |
}; | |
registerReceiver(mLoginBroadcastReceiver, new IntentFilter(LOGIN_RECEIVER_FILTER)); | |
LoginService.performAsyncLogin(this, LOGIN_RECEIVER_FILTER, login, password); | |
} | |
/** | |
* This is a method that will be overridden in order to test response. | |
*/ | |
@VisibleForTesting | |
public void handleLoginResponse(LoginResponse loginResponse) { | |
// handle login response here | |
} | |
// some code here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a LoginActivity that perform simple login with a help of service.