Example usage for com.google.api.client.googleapis.extensions.android.gms.auth GoogleAccountCredential usingAudience

List of usage examples for com.google.api.client.googleapis.extensions.android.gms.auth GoogleAccountCredential usingAudience

Introduction

In this page you can find the example usage for com.google.api.client.googleapis.extensions.android.gms.auth GoogleAccountCredential usingAudience.

Prototype

public static GoogleAccountCredential usingAudience(Context context, String audience) 

Source Link

Document

Sets the audience scope to use with Google Cloud Endpoints.

Usage

From source file:at.ameise.moodtracker.app.activity.SignInActivity.java

License:Open Source License

/**
 * Retrieves the previously used account name from the application preferences and checks if the
 * credential object can be set to this account.
 * @return a boolean indicating if the user is signed in or not
 *///from  w ww . j  av  a  2s  . c om
public static boolean isSignedIn(final Context context) {

    if (credential == null)
        credential = GoogleAccountCredential.usingAudience(context, ApiConstant.AUDIENCE_ANDROID_CLIENT_ID);

    String accountName = context
            .getSharedPreferences(PreferenceConstant.APPLICATION_PREFERENCES, Context.MODE_PRIVATE)
            .getString(PreferenceConstant.KEY_ACCOUNT_NAME, null);

    credential.setSelectedAccountName(accountName);

    return credential.getSelectedAccount() != null;
}

From source file:ch.hesso.master.sweetcity.utils.AuthUtils.java

License:Apache License

private AuthUtils(Activity context) {
    this.callbackAccount = new AccountCallbackImpl(context);
    this.settings = context.getSharedPreferences(Constants.PROJECT_NAME, 0);
    this.setContext(context);

    credential = GoogleAccountCredential.usingAudience(context, Constants.AUDIENCE);
    saveAccountName(getAccountName());/* w w  w .ja  v  a2 s.  c o m*/
}

From source file:com.battlelancer.seriesguide.backend.CloudSetupFragment.java

License:Apache License

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mCredential = GoogleAccountCredential.usingAudience(getActivity(), HexagonSettings.AUDIENCE);
    setAccountName(HexagonSettings.getAccountName(getActivity()));

    updateViewsStates(false);//from w w  w  .  j  a  v a  2s .  c  o m

    // lock down UI if task is still running
    if (mHexagonSetupTask != null && mHexagonSetupTask.getStatus() != AsyncTask.Status.FINISHED) {
        setProgressLock(true); // prevent duplicate tasks
    }
}

From source file:com.battlelancer.seriesguide.backend.HexagonTools.java

License:Apache License

/**
 * Checks if the given Google account exists and can be accessed.
 *///from w w  w . j  av a2s . co m
public static boolean validateAccount(Context context, String accountName) {
    GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(context.getApplicationContext(),
            HexagonSettings.AUDIENCE);
    // set account, credential tries to fetch Google account from Android AccountManager
    credential.setSelectedAccountName(accountName);

    if (credential.getSelectedAccountName() == null) {
        Timber.e("validateAccount: failed to get Google account from AccountManager.");
        return false;
    }

    return true;
}

From source file:com.battlelancer.seriesguide.backend.HexagonTools.java

License:Apache License

/**
 * Get the Google account credentials used for talking with Hexagon.
 *
 * <p>Make sure to check {@link GoogleAccountCredential#getSelectedAccountName()} is not null
 * (is null if e.g. do not have permission to access the account or the account was removed).
 *///from  ww  w. j  av a  2s.c  o m
public synchronized static GoogleAccountCredential getAccountCredential(Context context) {
    if (credential == null) {
        credential = GoogleAccountCredential.usingAudience(context.getApplicationContext(),
                HexagonSettings.AUDIENCE);
    }
    // try to restore account name if none is set
    if (credential.getSelectedAccountName() == null) {
        credential.setSelectedAccountName(HexagonSettings.getAccountName(context));
    }
    return credential;
}

From source file:com.dealbreaker.cloud.backend.core.CloudBackendFragment.java

License:Apache License

/**
 * Subclasses may override this to execute initialization of the activity.
 * If it uses any CloudBackend features, it should be executed inside
 * {@link #onCreateFinished()} that will be called after CloudBackend
 * initializations such as user authentication.
 *//*from   w w  w.j a va  2  s . c  om*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // init backend
    mCloudBackend = new CloudBackendMessaging(getActivity());

    // create credential
    mCredential = GoogleAccountCredential.usingAudience(getActivity(), Consts.AUTH_AUDIENCE);
    mCloudBackend.setCredential(mCredential);

    signInAndSubscribe(false);

    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mMsgReceiver,
            new IntentFilter(GCMIntentService.BROADCAST_ON_MESSAGE));
}

From source file:com.dogar.geodesic.map.MainActivity.java

License:Apache License

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Account stuff
    settings = getSharedPreferences("Geodesic", 0);
    credential = GoogleAccountCredential.usingAudience(this, AUDIENCE);
    setAccountName(settings.getString("ACCOUNT_NAME", null));
    if (credential.getSelectedAccountName() != null) {
        // Already signed in, begin app!
        Toast.makeText(getBaseContext(), "Logged in with : " + credential.getSelectedAccountName(),
                Toast.LENGTH_LONG).show();
        if (savedInstanceState == null) {
            setGMFragment();/*from   w  w  w.  j  a  v a2  s  . com*/
        }
    } else {
        // Not signed in, show login window or request an account.
        chooseAccount();
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTitle = mDrawerTitle = getTitle();

    mIcons = getResources().obtainTypedArray(R.array.nav_items_icons);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
    mAdapter = new NavDrawerListAdapter(this);
    mHeaders = getResources().getStringArray(R.array.menu_headers);

    mAdapter.addHeader(accountName);
    /******************* Actions *********************/
    actionTitles = getResources().getStringArray(R.array.actions_types);
    mAdapter.addHeader(mHeaders[0]);
    int i;
    for (i = 0; i < actionTitles.length; i++)
        mAdapter.addItem(actionTitles[i], mIcons.getResourceId(i, -1));
    mIcons.recycle();
    /******************* About *********************/
    mAdapter.addHeader(mHeaders[1]);
    helpTitles = getResources().getStringArray(R.array.help_items);
    mAdapter.addItem(helpTitles[0], mIcons.getResourceId(i++, -1));

    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    mDrawerList.setAdapter(mAdapter);

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to
            // onPrepareOptionsMenu()
        }

        public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, slideOffset);
            mDrawerLayout.bringChildToFront(drawerView);
            mDrawerLayout.requestLayout();
            mDrawerLayout.setScrimColor(Color.TRANSPARENT);
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to
            // onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    mDrawerLayout.setDrawerListener(mDrawerToggle);

}

From source file:com.ericrgon.CloudBackendActivity.java

License:Apache License

/**
 * Subclasses may override this to execute initialization of the activity. If
 * it uses any CloudBackend features, it should be executed inside
 * {@link #onPostCreate()} that will be called after CloudBackend
 * initializations such as user authentication.
 *///from  w  ww. j  av  a 2  s.c o  m
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // init backend
    cloudBackend = new CloudBackendMessaging(this);

    // create credential
    credential = GoogleAccountCredential.usingAudience(this, Consts.AUTH_AUDIENCE);
    cloudBackend.setCredential(credential);

    // if auth enabled, get account name from the shared pref
    if (isAuthEnabled()) {
        String accountName = cloudBackend.getSharedPreferences().getString(PREF_KEY_ACCOUNT_NAME, null);
        if (accountName == null) {
            // let user pick an account
            super.startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
            return; // continue init in onActivityResult
        } else {
            credential.setSelectedAccountName(accountName);
        }
    }

    // post create initialization
    _onPostCreate();
}

From source file:com.example.authsample.MainActivity.java

License:Apache License

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    CloudBackendMessaging cloudBackend = getCloudBackend();

    // create credential
    credential = GoogleAccountCredential.usingAudience(this, Consts.AUTH_AUDIENCE);
    cloudBackend.setCredential(credential);

    // get account name from the shared pref
    String accountName = PreferenceManager.getDefaultSharedPreferences(this).getString(PREF_KEY_ACCOUNT_NAME,
            null);/* w w w .j  a  v  a 2 s  . c  om*/
    if (accountName == null) {
        // let user pick an account
        startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
        return; // continue init in onActivityResult
    } else {
        credential.setSelectedAccountName(accountName);
    }

    mEditText = (EditText) findViewById(R.id.edit_text);
    mSendBtn = findViewById(R.id.send_btn);
}

From source file:com.google.cloud.backend.android.CloudBackendSherlockFragmentActivity.java

License:Apache License

/**
 * Subclasses may override this to execute initialization of the activity. If
 * it uses any CloudBackend features, it should be executed inside
 * {@link #onPostCreate()} that will be called after CloudBackend
 * initializations such as user authentication.
 *///  w w w.  ja  v  a  2 s.c om
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // init backend
    cloudBackend = new CloudBackendMessaging(this);

    // create credential
    credential = GoogleAccountCredential.usingAudience(this, Consts.AUTH_AUDIENCE);
    cloudBackend.setCredential(credential);

    // if auth enabled, get account name from the shared pref
    if (isAuthEnabled()) {
        String accountName = getPreferencesAccountName();
        if (accountName == null) {
            // let user pick an account
            super.startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
            return; // continue init in onActivityResult
        } else {
            credential.setSelectedAccountName(accountName);
        }
    }

    // post create initialization
    _onPostCreate();
}