@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer); mTitle = getTitle(); // Set up the drawer. mNavigationDrawerFragment.setUp( R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout)); // Set up fragments if (savedInstanceState == null) { fitnessFragment = new FitnessFragment(); getFragmentManager().beginTransaction().add(R.id.container, fitnessFragment).commit(); } if (savedInstanceState != null) { authInProgress = savedInstanceState.getBoolean(AUTH_PENDING); } // Build API to Google Play Service and subscriber to Fitness API mGoogleApiSubscription = new GoogleApiSubscription(authInProgress, this); mGoogleApiSubscription.buildFitnessClient(); authInProgress = mGoogleApiSubscription.isAuthInProgress(); }
@Override protected void onStop() { super.onStop(); if (mGoogleApiSubscription.isConnected()) { Log.i(TAG, "Disconnecting from Google API"); mGoogleApiSubscription.disconnect(); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_OAUTH) { authInProgress = false; mGoogleApiSubscription.setAuthInProgress(authInProgress); if (resultCode == RESULT_OK) { // Make sure the app is not already connected or attempting to connect if (!mGoogleApiSubscription.isConnecting() && !mGoogleApiSubscription.isConnected()) { mGoogleApiSubscription.connect(); } } } }
@Override public void onStart() { super.onStart(); // Connect to the Fitness API Log.d(TAG, "Connecting..."); mGoogleApiSubscription.connect(); }
@Override protected void onResume() { super.onResume(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(GoogleApiSubscription.SUBSCRIPTION_LIST_RECEIVED); registerReceiver(mReceiver, intentFilter); // Get data new GoogleApiSubscription.requestDataTask(stepListener) .execute(GoogleApiSubscription.queryStepData()); new GoogleApiSubscription.requestDataTask(activityListener) .execute(GoogleApiSubscription.queryActivityData(TimeUnit.DAYS)); new GoogleApiSubscription.requestDataTask(calorieListener) .execute(GoogleApiSubscription.queryCalorieData(TimeUnit.DAYS)); // Try new method // new GoogleApiSubscription.requestDataTask(genericListener).execute( // GoogleApiSubscription.dataRequestObject()); }
@Override public void onButtonClick(String text, int position) { mGoogleApiSubscription.listSubscriptions(); }