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

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

Introduction

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

Prototype

public static GoogleAccountCredential usingOAuth2(Context context, Collection<String> scopes) 

Source Link

Document

Constructs a new instance using OAuth 2.0 scopes.

Usage

From source file:com.itime.team.itime.activities.ImportGoogleCalendarActivity.java

License:Apache License

/**
 * Create the main activity.//from  www .  ja v a  2  s  . c  o m
 * @param savedInstanceState previously saved instance data.
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    LinearLayout activityLayout = new LinearLayout(this);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    activityLayout.setLayoutParams(lp);
    activityLayout.setOrientation(LinearLayout.VERTICAL);
    activityLayout.setPadding(16, 16, 16, 16);

    ViewGroup.LayoutParams tlp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);

    mCallApiButton = new Button(this);
    mCallApiButton.setText(BUTTON_TEXT);
    mCallApiButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mCallApiButton.setEnabled(false);
            mOutputText.setText("");
            getResultsFromApi();
            mCallApiButton.setEnabled(true);
        }
    });
    activityLayout.addView(mCallApiButton);

    mOutputText = new TextView(this);
    mOutputText.setLayoutParams(tlp);
    mOutputText.setPadding(16, 16, 16, 16);
    mOutputText.setVerticalScrollBarEnabled(true);
    mOutputText.setMovementMethod(new ScrollingMovementMethod());
    mOutputText.setText("Click the \'" + BUTTON_TEXT + "\' button to import.");
    activityLayout.addView(mOutputText);

    mProgress = new ProgressDialog(this);
    mProgress.setMessage("Calling Google Calendar API ...");
    mProgress.setCancelable(false);
    mProgress.setCanceledOnTouchOutside(false);

    setContentView(activityLayout);

    // Initialize credentials and service object.
    mCredential = GoogleAccountCredential.usingOAuth2(getApplicationContext(), Arrays.asList(SCOPES))
            .setBackOff(new ExponentialBackOff());
}

From source file:com.jefftharris.passwdsafe.sync.gdrive.GDriveProvider.java

License:Open Source License

/** Get the Google account credential */
private static GoogleAccountCredential getAcctCredential(Context ctx) {
    return GoogleAccountCredential.usingOAuth2(ctx, Collections.singletonList(DriveScopes.DRIVE));
}

From source file:com.kondi.android.classroomscheduler.attendance.AttendanceActivity.java

License:Apache License

@Override
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    mProgressBar = new ProgressBar(this);
    setContentView(mProgressBar);//from w w  w  . j  a  v a  2  s  .c om
    Intent intent = getIntent();
    organizer = intent.getStringExtra(CALENDAR_ID);
    time = intent.getStringExtra(START_TIME);
    Log.v(organizer, time);
    // Google Accounts
    credential = GoogleAccountCredential.usingOAuth2(this, Collections.singleton(CalendarScopes.CALENDAR));
    SharedPreferences settings = getPreferences(Context.MODE_PRIVATE);
    credential.setSelectedAccountName(settings.getString(PREF_ACCOUNT_NAME, null));
    // Calendar client
    client = new com.google.api.services.calendar.Calendar.Builder(transport, jsonFactory, credential)
            .setApplicationName("822175141607-n8r6ojmdgo96b35sd829tg532pv104vs.apps.googleusercontent.com")
            .build();
    loadParticipants();
}

From source file:com.kondi.android.classroomscheduler.attendance.CalendarSampleActivity.java

License:Apache License

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // enable logging
    Logger.getLogger("com.google.api.client").setLevel(LOGGING_LEVEL);
    // view and menu
    setContentView(R.layout.calendarlist);
    listView = (ListView) findViewById(R.id.list);
    registerForContextMenu(listView);/*from w  w w  .  j av  a 2  s . co m*/
    // Google Accounts
    credential = GoogleAccountCredential.usingOAuth2(this, Collections.singleton(CalendarScopes.CALENDAR));
    SharedPreferences settings = getPreferences(Context.MODE_PRIVATE);
    credential.setSelectedAccountName(settings.getString(PREF_ACCOUNT_NAME, null));
    // Calendar client
    client = new com.google.api.services.calendar.Calendar.Builder(transport, jsonFactory, credential)
            .setApplicationName("Google-CalendarAndroidSample/1.0").build();

}

From source file:com.mariovinay.android.spartandrive.authentication.BaseActivity.java

License:Open Source License

@Override
protected void onCreate(Bundle b) {
    super.onCreate(b);
    // Initialize credentials and service object.
    SharedPreferences settings = getPreferences(Context.MODE_PRIVATE);
    mCredential = GoogleAccountCredential.usingOAuth2(getApplicationContext(), Arrays.asList(SCOPES))
            .setBackOff(new ExponentialBackOff())
            .setSelectedAccountName(settings.getString(PREF_ACCOUNT_NAME, null));
}

From source file:com.moodletest.CalendarSampleActivity.java

License:Apache License

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // enable logging
    Logger.getLogger("com.google.api.client").setLevel(LOGGING_LEVEL);
    // view and menu
    setContentView(R.layout.calendarlist);
    listView = (ListView) findViewById(R.id.list);
    registerForContextMenu(listView);//from  www.  ja va  2 s .  c  o  m
    // Google Accounts
    credential = GoogleAccountCredential.usingOAuth2(this, Collections.singleton(CalendarScopes.CALENDAR));
    SharedPreferences settings = getPreferences(Context.MODE_PRIVATE);
    credential.setSelectedAccountName(settings.getString(PREF_ACCOUNT_NAME, null));
    // Calendar client
    client = new com.google.api.services.calendar.Calendar.Builder(transport, jsonFactory, credential)
            .setApplicationName("Google-CalendarAndroidSample/1.0").build();
}

From source file:com.sickboots.ytube.MainActivity.java

License:Apache License

@Override
protected void onCreate(Bundle savedInstanceState) {
    getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);

    // Check to see if the proper keys and playlist IDs have been set up
    if (!isCorrectlyConfigured()) {
        setContentView(R.layout.developer_setup_required);
        showMissingConfigurations();/*  w  w w. ja  v a2 s .c om*/
    } else {
        setContentView(R.layout.activity_main);

        ensureFetcher();

        credential = GoogleAccountCredential.usingOAuth2(getApplicationContext(), Arrays.asList(Auth.SCOPES));
        // set exponential backoff policy
        credential.setBackOff(new ExponentialBackOff());

        if (savedInstanceState != null) {
            mChosenAccountName = savedInstanceState.getString(ACCOUNT_KEY);
        } else {
            loadAccount();
        }

        credential.setSelectedAccountName(mChosenAccountName);

        mUploadsListFragment = (UploadsListFragment) getFragmentManager().findFragmentById(R.id.list_fragment);
    }
}

From source file:com.smedic.tubtub.YouTubeSearch.java

License:Apache License

public YouTubeSearch(Activity activity, Fragment playlistFragment) {
    this.activity = activity;
    this.playlistFragment = playlistFragment;
    handler = new Handler();
    credential = GoogleAccountCredential.usingOAuth2(activity.getApplicationContext(),
            Arrays.asList(Auth.SCOPES));
    credential.setBackOff(new ExponentialBackOff());
    appName = activity.getResources().getString(R.string.app_name);
}

From source file:com.spjanson.restdemo.REST.java

License:Open Source License

/************************************************************************************************
 * initialize Google Drive Api//from  ww w .  ja v  a  2 s . co  m
 * @param act   activity context
 */
static boolean init(Activity act) { //UT.lg( "REST init " + email);
    if (act != null)
        try {
            String email = UT.AM.getEmail();
            if (email != null) {
                mConnCBs = (ConnectCBs) act;
                mGOOSvc = new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(),
                        GoogleAccountCredential
                                .usingOAuth2(UT.acx, Collections.singletonList(DriveScopes.DRIVE_FILE))
                                .setSelectedAccountName(email)).build();
                return true;
            }
        } catch (Exception e) {
            UT.le(e);
        }
    return false;
}

From source file:com.survivingwithandroid.accountnavigationdrawer.MainActivity.java

License:Apache License

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    String[] itmes = getResources().getStringArray(R.array.items_array);

    frame = (FrameLayout) findViewById(R.id.content_frame);

    Spinner spinner = (Spinner) findViewById(R.id.spinnerAccount);

    String[] items = new String[] { "item1", "item2", "item3" };

    AccountManager accMgr = AccountManager.get(this);

    Account[] accountList = accMgr.getAccounts();
    final String[] accountNames = new String[accountList.length + 1];
    int i = 1;//  www . ja v  a2s.c o m
    accountNames[0] = getResources().getString(R.string.infospinner);

    for (Account account : accountList) {
        String name = account.name;
        accountNames[i++] = name;
    }

    ArrayAdapter<String> adp = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            accountNames);
    spinner.setAdapter(adp);

    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            System.out.println("Pos [" + position + "]");
            if (position == 0)
                return;

            String currentAccount = accountNames[position];
            credential = GoogleAccountCredential.usingOAuth2(MainActivity.this, DriveScopes.DRIVE);
            credential.setSelectedAccountName(currentAccount);
            service = getDriveService(credential);
            AsyncAuth auth = new AsyncAuth();
            auth.execute("");
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, itmes));

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);
    // We should handle actionbar event correctly
}