Search in sources :

Example 6 with SignInButton

use of com.google.android.gms.common.SignInButton in project Pokemap by omkarmoghe.

the class LoginActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mNianticManager = NianticManager.getInstance();
    mGoogleManager = GoogleManager.getInstance();
    mPref = new PokemapSharedPreferences(this);
    setContentView(R.layout.activity_login);
    mNianticAuthListener = new NianticManager.AuthListener() {

        @Override
        public void authSuccessful() {
            finishLogin();
        }

        @Override
        public void authFailed(String message, String provider) {
            switch(provider) {
                case LoginInfo.PROVIDER_PTC:
                    showPTCLoginFailed();
                    break;
                case LoginInfo.PROVIDER_GOOGLE:
                    showGoogleLoginFailed();
                    break;
            }
            Log.d(TAG, "authFailed() called with: message = [" + message + "]");
        }
    };
    mNianticLoginListener = new NianticManager.LoginListener() {

        @Override
        public void authSuccessful(String authToken) {
            Log.d(TAG, "authSuccessful() called with: authToken = [" + authToken + "]");
            PtcLoginInfo info = new PtcLoginInfo(authToken, mUsernameView.getText().toString(), mPasswordView.getText().toString());
            mPref.setLoginInfo(info);
            mNianticManager.setLoginInfo(LoginActivity.this, info, mNianticAuthListener);
        }

        @Override
        public void authFailed(String message) {
            Log.e(TAG, "Failed to authenticate. authFailed() called with: message = [" + message + "]");
            showPTCLoginFailed();
        }
    };
    mGoogleLoginListener = new GoogleManager.LoginListener() {

        @Override
        public void authSuccessful(String authToken, String refreshToken) {
            GoogleLoginInfo info = new GoogleLoginInfo(authToken, refreshToken);
            Log.d(TAG, "authSuccessful() called with: authToken = [" + authToken + "]");
            mPref.setLoginInfo(info);
            mNianticManager.setLoginInfo(LoginActivity.this, info, mNianticAuthListener);
        }

        @Override
        public void authFailed(String message) {
            Log.d(TAG, "Failed to authenticate. authFailed() called with: message = [" + message + "]");
            showGoogleLoginFailed();
        }

        @Override
        public void authRequested(GoogleService.AuthRequest body) {
        //Do nothing
        }
    };
    findViewById(R.id.txtDisclaimer).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            new AlertDialog.Builder(LoginActivity.this).setTitle(getString(R.string.login_warning_title)).setMessage(Html.fromHtml(getString(R.string.login_warning))).setPositiveButton(android.R.string.ok, null).show();
        }
    });
    // Set up the triggerAutoLogin form.
    mUsernameView = (AutoCompleteTextView) findViewById(R.id.username);
    mPasswordView = (EditText) findViewById(R.id.password);
    mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
            if (id == R.id.login || id == EditorInfo.IME_NULL) {
                validatePTCLoginForm();
                return true;
            }
            return false;
        }
    });
    LoginInfo loginInfo = mPref.getLoginInfo();
    if (loginInfo != null && loginInfo instanceof PtcLoginInfo) {
        mUsernameView.setText(((PtcLoginInfo) loginInfo).getUsername());
        mPasswordView.setText(((PtcLoginInfo) loginInfo).getPassword());
    }
    Button signInButton = (Button) findViewById(R.id.email_sign_in_button);
    signInButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            validatePTCLoginForm();
        }
    });
    mLoginFormView = findViewById(R.id.login_form);
    mProgressView = findViewById(R.id.login_progress);
    SignInButton signInButtonGoogle = (SignInButton) findViewById(R.id.sign_in_button);
    signInButtonGoogle.setSize(SignInButton.SIZE_WIDE);
    signInButtonGoogle.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            GoogleAuthActivity.startForResult(LoginActivity.this, REQUEST_USER_AUTH);
        }
    });
    triggerAutoLogin();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) LoginInfo(com.omkarmoghe.pokemap.models.login.LoginInfo) PtcLoginInfo(com.omkarmoghe.pokemap.models.login.PtcLoginInfo) GoogleLoginInfo(com.omkarmoghe.pokemap.models.login.GoogleLoginInfo) PtcLoginInfo(com.omkarmoghe.pokemap.models.login.PtcLoginInfo) GoogleLoginInfo(com.omkarmoghe.pokemap.models.login.GoogleLoginInfo) PokemapSharedPreferences(com.omkarmoghe.pokemap.controllers.app_preferences.PokemapSharedPreferences) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) KeyEvent(android.view.KeyEvent) SignInButton(com.google.android.gms.common.SignInButton) NianticManager(com.omkarmoghe.pokemap.controllers.net.NianticManager) Button(android.widget.Button) SignInButton(com.google.android.gms.common.SignInButton) GoogleService(com.omkarmoghe.pokemap.controllers.net.GoogleService) OnClickListener(android.view.View.OnClickListener) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) GoogleManager(com.omkarmoghe.pokemap.controllers.net.GoogleManager)

Example 7 with SignInButton

use of com.google.android.gms.common.SignInButton in project easy by MehdiBenmesa.

the class StartActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_start);
    // Views
    mStatusTextView = (TextView) findViewById(R.id.status);
    // Button listeners
    findViewById(R.id.sign_in_button).setOnClickListener(this);
    // [START configure_signin]
    // Configure sign-in to request the user's ID, email address, and basic
    // profile. ID and basic profile are included in DEFAULT_SIGN_IN.
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().requestIdToken(getString(R.string.server_client_id)).build();
    // [END configure_signin]
    // [START build_client]
    // 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();
    // [END build_client]
    // [START customize_button]
    // Set the dimensions of the sign-in button.
    SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
    signInButton.setSize(SignInButton.SIZE_STANDARD);
// [END customize_button]
}
Also used : SignInButton(com.google.android.gms.common.SignInButton) GoogleSignInOptions(com.google.android.gms.auth.api.signin.GoogleSignInOptions)

Example 8 with SignInButton

use of com.google.android.gms.common.SignInButton 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);
}
Also used : SignInButton(com.google.android.gms.common.SignInButton) Scope(com.google.android.gms.common.api.Scope) GoogleSignInOptions(com.google.android.gms.auth.api.signin.GoogleSignInOptions)

Example 9 with SignInButton

use of com.google.android.gms.common.SignInButton in project android by JetBrains.

the class LoginActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    // Find the Google+ sign in button.
    mPlusSignInButton = (SignInButton) findViewById(R.id.plus_sign_in_button);
    if (supportsGooglePlayServices()) {
        // Set a listener to connect the user when the G+ button is clicked.
        mPlusSignInButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                signIn();
            }
        });
    } else {
        // Don't offer G+ sign in if the app's version is too low to support Google Play
        // Services.
        mPlusSignInButton.setVisibility(View.GONE);
        return;
    }
    // Set up the login form.
    mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
    populateAutoComplete();
    mPasswordView = (EditText) findViewById(R.id.password);
    mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
            if (id == R.id.login || id == EditorInfo.IME_NULL) {
                attemptLogin();
                return true;
            }
            return false;
        }
    });
    Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button);
    mEmailSignInButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            attemptLogin();
        }
    });
    mLoginFormView = findViewById(R.id.login_form);
    mProgressView = findViewById(R.id.login_progress);
    mEmailLoginFormView = findViewById(R.id.email_login_form);
    mSignOutButtons = findViewById(R.id.plus_sign_out_buttons);
}
Also used : KeyEvent(android.view.KeyEvent) Button(android.widget.Button) SignInButton(com.google.android.gms.common.SignInButton) OnClickListener(android.view.View.OnClickListener) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView)

Aggregations

SignInButton (com.google.android.gms.common.SignInButton)9 GoogleSignInOptions (com.google.android.gms.auth.api.signin.GoogleSignInOptions)6 Scope (com.google.android.gms.common.api.Scope)4 TextView (android.widget.TextView)3 KeyEvent (android.view.KeyEvent)2 View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 AutoCompleteTextView (android.widget.AutoCompleteTextView)2 Button (android.widget.Button)2 AlertDialog (android.support.v7.app.AlertDialog)1 GoogleApiClient (com.google.android.gms.common.api.GoogleApiClient)1 PokemapSharedPreferences (com.omkarmoghe.pokemap.controllers.app_preferences.PokemapSharedPreferences)1 GoogleManager (com.omkarmoghe.pokemap.controllers.net.GoogleManager)1 GoogleService (com.omkarmoghe.pokemap.controllers.net.GoogleService)1 NianticManager (com.omkarmoghe.pokemap.controllers.net.NianticManager)1 GoogleLoginInfo (com.omkarmoghe.pokemap.models.login.GoogleLoginInfo)1 LoginInfo (com.omkarmoghe.pokemap.models.login.LoginInfo)1 PtcLoginInfo (com.omkarmoghe.pokemap.models.login.PtcLoginInfo)1