1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
class AuthenticatedActivity extends Activity
{
private final static int AUTHENTICATION_REQUEST = -823;
private static Authentication auth; //<= classe à définir
public void onResume() {
if (auth == null) {
onAuthFailed(false);
} else {
onAuthSuccess(auth);
}
}
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == AUTHENTICATION_REQUEST) {
if (resultCode == RESULT_OK) {
auth = new Authentication(data.getBundle());
onAuthSuccess(auth);
} else
onAuthFailed(true);
} else
super.onActivityResult(requestCode,resultCode,data);
}
public void onAuthFailed(boolean afterLogin)
{
if (!afterLogin) {
startActivityForResult(
new Intent(this,LoginActivity.class),
AUTHENTICATION_REQUEST);
} else
finish();
}
// Callback when someone logged in.
public abstract void onAuthSuccess(Authentication a);
} |
Partager