-
-
Save bkawakami/b6e3c915094ba9ccca7d to your computer and use it in GitHub Desktop.
LoginActivity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.domain.app; | |
import android.app.Activity; | |
import android.app.ProgressDialog; | |
import android.content.Intent; | |
import android.content.IntentSender; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.Toast; | |
import com.google.android.gms.common.*; | |
import com.google.android.gms.common.GooglePlayServicesClient.*; | |
import com.google.android.gms.plus.PlusClient; | |
public class LoginActivity extends Activity implements View.OnClickListener, | |
ConnectionCallbacks, OnConnectionFailedListener { | |
private static final String TAG = "LoginActivity"; | |
private static final int REQUEST_CODE_RESOLVE_ERR = 9000; | |
private ProgressDialog mConnectionProgressDialog; | |
private PlusClient mPlusClient; | |
private ConnectionResult mConnectionResult; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
mPlusClient = new PlusClient.Builder(this, this, this) | |
.setActions( | |
"http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity") | |
.setScopes("PLUS_LOGIN") | |
.build(); | |
// A barra de progresso deve ser exibida se a falha de conexão não for resolvida. | |
mConnectionProgressDialog = new ProgressDialog(this); | |
mConnectionProgressDialog.setMessage("Signing in..."); | |
} | |
@Override | |
protected void onStart() { | |
super.onStart(); | |
mPlusClient.connect(); | |
} | |
@Override | |
protected void onStop() { | |
super.onStop(); | |
mPlusClient.disconnect(); | |
} | |
@Override | |
public void onConnectionFailed(ConnectionResult result) { | |
if (result.hasResolution()) { | |
try { | |
result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR); | |
} catch (IntentSender.SendIntentException e) { | |
mPlusClient.connect(); | |
} | |
} | |
// Salvar o resultado e solucionar a falha de conexão mediante clique do usuário. | |
mConnectionResult = result; | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int responseCode, Intent intent) { | |
if (requestCode == REQUEST_CODE_RESOLVE_ERR && responseCode == RESULT_OK) { | |
mConnectionResult = null; | |
mPlusClient.connect(); | |
} | |
} | |
@Override | |
public void onConnected(Bundle bundle) { | |
String accountName = mPlusClient.getAccountName(); | |
Toast.makeText(this, accountName + " is connected.", Toast.LENGTH_LONG).show(); | |
} | |
@Override | |
public void onDisconnected() { | |
Log.d(TAG, "disconnected"); | |
} | |
@Override | |
public void onClick(View v) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment