use of com.google.android.gms.common.api.Scope in project iosched by google.
the class LoginAndAuthWithGoogleApi method start.
/**
* Starts the helper. Call this from your Activity's onStart().
*/
@Override
public void start() {
Activity activity = getActivity("start()");
if (activity == null) {
return;
}
if (mStarted) {
LOGW(TAG, "Helper already started. Ignoring redundant call.");
return;
}
mStarted = true;
if (mResolving) {
// if resolving, don't reconnect the plus client
LOGD(TAG, "Helper ignoring signal to start because we're resolving a failure.");
return;
}
LOGD(TAG, "Helper starting. Connecting " + mAccountName);
if (mGoogleApiClient == null) {
LOGD(TAG, "Creating client.");
GoogleApiClient.Builder builder = new GoogleApiClient.Builder(activity);
for (String scope : AUTH_SCOPES) {
builder.addScope(new Scope(scope));
}
mGoogleApiClient = builder.addApi(Plus.API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).setAccountName(mAccountName).build();
}
LOGD(TAG, "Connecting client.");
mGoogleApiClient.connect();
}
use of com.google.android.gms.common.api.Scope in project iosched by google.
the class SwitchUserActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Configure Google API client for use with login API
GoogleSignInOptions.Builder gsoBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN);
for (String scope : LoginAndAuthWithGoogleApi.GetAuthScopes()) {
gsoBuilder.requestScopes(new Scope(scope));
}
GoogleSignInOptions gso = gsoBuilder.requestEmail().build();
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Auth.GOOGLE_SIGN_IN_API, gso).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
mGoogleApiClient.connect();
}
use of com.google.android.gms.common.api.Scope in project iosched by google.
the class AccountFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
// Inflate the layout for this fragment
mLayout = inflater.inflate(R.layout.welcome_account_fragment, container, false);
if (mActivity instanceof WelcomeFragmentContainer) {
((WelcomeFragmentContainer) mActivity).setPrimaryButtonEnabled(false);
}
// Configure Google API client for use with login API
GoogleSignInOptions.Builder gsoBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN);
for (String scope : LoginAndAuthWithGoogleApi.GetAuthScopes()) {
gsoBuilder.requestScopes(new Scope(scope));
}
GoogleSignInOptions gso = gsoBuilder.requestEmail().build();
mGoogleApiClient = new GoogleApiClient.Builder(getContext()).addApi(Auth.GOOGLE_SIGN_IN_API, gso).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
mGoogleApiClient.connect();
return mLayout;
}
use of com.google.android.gms.common.api.Scope in project easy by MehdiBenmesa.
the class ServerAuthCodeActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activitymain);
// Views
mAuthCodeTextView = (TextView) findViewById(R.id.detail);
// Button click listeners
findViewById(R.id.sign_in_button).setOnClickListener(this);
findViewById(R.id.sign_out_button).setOnClickListener(this);
findViewById(R.id.disconnect_button).setOnClickListener(this);
// For sample only: make sure there is a valid server client ID.
validateServerClientID();
// [START configure_signin]
// Configure sign-in to request offline access to the user's ID, basic
// profile, and Google Drive. The first time you request a code you will
// be able to exchange it for an access token and refresh token, which
// you should store. In subsequent calls, the code will only result in
// an access token. By asking for profile access (through
// DEFAULT_SIGN_IN) you will also get an ID Token as a result of the
// code exchange.
String serverClientId = getString(R.string.server_client_id);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestScopes(new Scope(Scopes.DRIVE_APPFOLDER)).requestServerAuthCode(serverClientId).requestEmail().build();
// [END configure_signin]
// Build GoogleAPIClient with the Google Sign-In API and the above options.
mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, /* FragmentActivity */
this).addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
}
use of com.google.android.gms.common.api.Scope in project easy by MehdiBenmesa.
the class RestApiActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activitymain);
// Views
mStatusTextView = (TextView) findViewById(R.id.status);
mDetailTextView = (TextView) findViewById(R.id.detail);
// Button listeners
findViewById(R.id.sign_in_button).setOnClickListener(this);
findViewById(R.id.sign_out_button).setOnClickListener(this);
// For this example we don't need the disconnect button
findViewById(R.id.disconnect_button).setVisibility(View.GONE);
// Restore instance state
if (savedInstanceState != null) {
mAccount = savedInstanceState.getParcelable(KEY_ACCOUNT);
}
// Configure sign-in to request the user's ID, email address, basic profile,
// and readonly access to contacts.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestScopes(new Scope(CONTACTS_SCOPE)).requestEmail().build();
// Build a GoogleApiClient with access to the Google Sign-In API and the
// options specified by gso.
mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, /* FragmentActivity */
this).addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
// Show a standard Google Sign In button. If your application does not rely on Google Sign
// In for authentication you could replace this with a "Get Google Contacts" button
// or similar.
SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
signInButton.setSize(SignInButton.SIZE_STANDARD);
}
Aggregations