@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; }
@Override public void onDetach() { super.onDetach(); mSelectedAccount = null; mGoogleApiClient.disconnect(); mGoogleApiClient = null; }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); if (requestCode == SIGN_IN_RESULT) { GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); handleSignInResult(result); } }
@Override public Fragment getFragment(FragmentManager fragmentManager, int action) { mWelcomeFragment = (WelcomeFragment) fragmentManager.findFragmentByTag(getKey()); if (mWelcomeFragment == null) { Bundle args = new Bundle(); args.putString(Page.KEY_PAGE_ARGUMENT, getKey()); args.putInt(Page.KEY_PAGE_ACTION, action); mWelcomeFragment = new WelcomeFragment(); mWelcomeFragment.setArguments(args); } return mWelcomeFragment; }