android application/app/src/main/java/com/slensky/focussis/activities/MainActivity.java
@Override
    protected void onActivityResult(
            int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch(requestCode) {
            case REQUEST_GOOGLE_PLAY_SERVICES:
                if (resultCode != RESULT_OK) {
                    new MaterialDialog.Builder(this)
                            .content(R.string.needs_play_services)
                            .positiveText(R.string.ok)
                            .show();
                } else {
                    getResultsFromApi();
                }
                break;
            case REQUEST_ACCOUNT_PICKER:
                Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
                try {
                    GoogleSignInAccount account = task.getResult(ApiException.class);
                    credential.setSelectedAccount(new Account(account.getEmail(), getPackageName()));
                    // if the settings fragment is selected, update the description of the preference
                    if (currentFragment instanceof SettingsFragment) {
                        ((SettingsFragment) currentFragment).updateAccountPreference();
                    }
                    else {
                        getResultsFromApi();
                    }
                    Log.i(TAG, account.getEmail());
                } catch (ApiException e) {
                    if (e.getStatusCode() == CommonStatusCodes.NETWORK_ERROR || e.getStatusCode() == CommonStatusCodes.TIMEOUT) {
                        Toast.makeText(this, R.string.network_error_timeout, Toast.LENGTH_LONG).show();
                    }
                    else {
                        Log.e(TAG, "Unexpected APIException while choosing account!");
                        e.printStackTrace();
                        Toast.makeText(this, R.string.network_error_unknown, Toast.LENGTH_LONG).show();
                    }
                }
                break;
            case REQUEST_AUTHORIZATION:
                if (resultCode == RESULT_OK) {
                    getResultsFromApi();
                }
                break;
        }
    }
/**
     * Called when an activity launched here (specifically, AccountPicker
     * and authorization) exits, giving you the requestCode you started it with,
     * the resultCode it returned, and any additional data from it.
     * @param requestCode code indicating which activity result is incoming.
     * @param resultCode code indicating the result of the incoming
     *     activity result.
     * @param data Intent (containing result data) returned by incoming
     *     activity result.
     */
Called when an activity launched here (specifically, AccountPicker
and authorization) exits, giving you the requestCode you started it with,
the resultCode it returned, and any additional data from it.
@param requestCode code indicating which activity result is incoming.
@param resultCode code indicating the result of the incoming
activity result.
@param data Intent (containing result data) returned by incoming
activity result.
Called when an activity launched here ( specifically AccountPicker and authorization ) exits giving you the requestCode you started it with the resultCode it returned and any additional data from it . @param requestCode code indicating which activity result is incoming . @param resultCode code indicating the result of the incoming activity result . @param data Intent ( containing result data ) returned by incoming activity result .
@Override
    protected void onActivityResult(
            int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch(requestCode) {
            case REQUEST_GOOGLE_PLAY_SERVICES:
                if (resultCode != RESULT_OK) {
                    new MaterialDialog.Builder(this)
                            .content(R.string.needs_play_services)
                            .positiveText(R.string.ok)
                            .show();
                } else {
                    getResultsFromApi();
                }
                break;
            case REQUEST_ACCOUNT_PICKER:
                Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
                try {
                    GoogleSignInAccount account = task.getResult(ApiException.class);
                    credential.setSelectedAccount(new Account(account.getEmail(), getPackageName()));
                    if (currentFragment instanceof SettingsFragment) {
                        ((SettingsFragment) currentFragment).updateAccountPreference();
                    }
                    else {
                        getResultsFromApi();
                    }
                    Log.i(TAG, account.getEmail());
                } catch (ApiException e) {
                    if (e.getStatusCode() == CommonStatusCodes.NETWORK_ERROR || e.getStatusCode() == CommonStatusCodes.TIMEOUT) {
                        Toast.makeText(this, R.string.network_error_timeout, Toast.LENGTH_LONG).show();
                    }
                    else {
                        Log.e(TAG, "Unexpected APIException while choosing account!");
                        e.printStackTrace();
                        Toast.makeText(this, R.string.network_error_unknown, Toast.LENGTH_LONG).show();
                    }
                }
                break;
            case REQUEST_AUTHORIZATION:
                if (resultCode == RESULT_OK) {
                    getResultsFromApi();
                }
                break;
        }
    }
@ Override protected void onActivityResult ( int requestCode , int resultCode , Intent data ) { super . onActivityResult ( requestCode , resultCode , data ) ; switch ( requestCode ) { case REQUEST_GOOGLE_PLAY_SERVICES : if ( resultCode != RESULT_OK ) { new MaterialDialog . Builder ( this ) . content ( R . string . needs_play_services ) . positiveText ( R . string . ok ) . show ( ) ; } else { getResultsFromApi ( ) ; } break ; case REQUEST_ACCOUNT_PICKER : Task < GoogleSignInAccount > task = GoogleSignIn . getSignedInAccountFromIntent ( data ) ; try { GoogleSignInAccount account = task . getResult ( ApiException . class ) ; credential . setSelectedAccount ( new Account ( account . getEmail ( ) , getPackageName ( ) ) ) ; if ( currentFragment instanceof SettingsFragment ) { ( ( SettingsFragment ) currentFragment ) . updateAccountPreference ( ) ; } else { getResultsFromApi ( ) ; } Log . i ( TAG , account . getEmail ( ) ) ; } catch ( ApiException e ) { if ( e . getStatusCode ( ) == CommonStatusCodes . NETWORK_ERROR || e . getStatusCode ( ) == CommonStatusCodes . TIMEOUT ) { Toast . makeText ( this , R . string . network_error_timeout , Toast . LENGTH_LONG ) . show ( ) ; } else { Log . e ( TAG , "Unexpected APIException while choosing account!" ) ; e . printStackTrace ( ) ; Toast . makeText ( this , R . string . network_error_unknown , Toast . LENGTH_LONG ) . show ( ) ; } } break ; case REQUEST_AUTHORIZATION : if ( resultCode == RESULT_OK ) { getResultsFromApi ( ) ; } break ; } }
Called when an activity launched here (specifically, AccountPicker
 and authorization) exits, giving you the requestCode you started it with,
 the resultCode it returned, and any additional data from it.
Called when an activity launched here ( specifically AccountPicker and authorization ) exits giving you the requestCode you started it with the resultCode it returned and any additional data from it .
// if the settings fragment is selected, update the description of the preference