use of com.google.android.gms.common.ConnectionResult in project android-diplicity by zond.
the class RetrofitActivity method onPostCreate.
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().requestServerAuthCode(OAUTH2_CLIENT_ID).build();
mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, /* FragmentActivity */
new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
App.firebaseCrashReport("Failed connecting to Google login API: " + connectionResult.getErrorMessage());
Toast.makeText(RetrofitActivity.this, R.string.login_failed, Toast.LENGTH_LONG).show();
}
}).addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefsListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
if (s.equals(API_URL_PREF_KEY)) {
recreateServices();
}
}
};
prefs.registerOnSharedPreferenceChangeListener(prefsListener);
recreateServices();
}
use of com.google.android.gms.common.ConnectionResult in project android by testpress.
the class LoginActivity method onCreate.
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
Injector.inject(this);
accountManager = AccountManager.get(this);
final Intent intent = getIntent();
username = intent.getStringExtra(PARAM_USERNAME);
authTokenType = intent.getStringExtra(PARAM_AUTHTOKEN_TYPE);
confirmCredentials = intent.getBooleanExtra(PARAM_CONFIRM_CREDENTIALS, false);
requestNewAccount = username == null;
if (AccessToken.getCurrentAccessToken() != null) {
LoginManager.getInstance().logOut();
}
setContentView(layout.login_activity);
ButterKnife.inject(this);
UIUtils.setIndeterminateDrawable(this, progressBar, 4);
passwordText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
if (actionId == IME_ACTION_SEND && signInButton.isEnabled()) {
signIn();
return true;
}
return false;
}
});
usernameText.addTextChangedListener(watcher);
usernameText.setSingleLine();
passwordText.addTextChangedListener(watcher);
passwordText.setTypeface(Typeface.DEFAULT);
passwordText.setTransformationMethod(new PasswordTransformationMethod());
callbackManager = CallbackManager.Factory.create();
fbLoginButton.invalidate();
fbLoginButton.setReadPermissions("email");
fbLoginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
loginLayout.setVisibility(View.GONE);
username = loginResult.getAccessToken().getUserId();
authenticate(loginResult.getAccessToken().getUserId(), loginResult.getAccessToken().getToken(), TestpressSdk.Provider.FACEBOOK);
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
if (error.getMessage().contains("CONNECTION_FAILURE")) {
showAlert(getString(R.string.no_internet_try_again));
} else {
Log.e("Facebook sign in error", "check hashes");
showAlert(getString(R.string.something_went_wrong_please_try_after));
}
}
});
GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().requestIdToken(getString(R.string.server_client_id)).build();
googleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
if (connectionResult.getErrorMessage() != null) {
showAlert(connectionResult.getErrorMessage());
} else {
showAlert(connectionResult.toString());
}
}
}).addApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions).build();
orLabel.setTypeface(TestpressSdk.getRubikMediumFont(this));
DaoSession daoSession = ((TestpressApplication) getApplicationContext()).getDaoSession();
instituteSettingsDao = daoSession.getInstituteSettingsDao();
List<InstituteSettings> instituteSettingsList = instituteSettingsDao.queryBuilder().where(InstituteSettingsDao.Properties.BaseUrl.eq(Constants.Http.URL_BASE)).list();
if (instituteSettingsList.size() == 0) {
getInstituteSettings();
} else {
instituteSettings = instituteSettingsList.get(0);
updateInstituteSpecificFields();
}
}
use of com.google.android.gms.common.ConnectionResult in project iNaturalistAndroid by inaturalist.
the class INaturalistService method getLocation.
private void getLocation(final IOnLocation callback) {
if (!mApp.isLocationEnabled(null)) {
Log.e(TAG, "getLocation: Location not enabled");
// Location not enabled
new Thread(new Runnable() {
@Override
public void run() {
callback.onLocation(null);
}
}).start();
return;
}
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
Log.e(TAG, "getLocation: resultCode = " + resultCode);
if (ConnectionResult.SUCCESS == resultCode) {
// User Google Play services if available
if ((mLocationClient != null) && (mLocationClient.isConnected())) {
// Location client already initialized and connected - use it
new Thread(new Runnable() {
@Override
public void run() {
callback.onLocation(getLastKnownLocationFromClient());
}
}).start();
} else {
// Connect to the place services
mLocationClient = new GoogleApiClient.Builder(this).addApi(LocationServices.API).addConnectionCallbacks(new ConnectionCallbacks() {
@Override
public void onConnected(Bundle bundle) {
// Connected successfully
new Thread(new Runnable() {
@Override
public void run() {
callback.onLocation(getLastKnownLocationFromClient());
mLocationClient.disconnect();
}
}).start();
}
@Override
public void onConnectionSuspended(int i) {
}
}).addOnConnectionFailedListener(new OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
// Couldn't connect
new Thread(new Runnable() {
@Override
public void run() {
callback.onLocation(null);
mLocationClient.disconnect();
}
}).start();
}
}).build();
mLocationClient.connect();
}
} else {
// Use GPS alone for place
new Thread(new Runnable() {
@Override
public void run() {
callback.onLocation(getLocationFromGPS());
}
}).start();
}
}
use of com.google.android.gms.common.ConnectionResult in project braintree_android by braintree.
the class BraintreeFragment method getGoogleApiClient.
protected GoogleApiClient getGoogleApiClient() {
if (getActivity() == null) {
postCallback(new GoogleApiClientException(ErrorType.NotAttachedToActivity, 1));
return null;
}
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(getActivity()).addApi(Wallet.API, new Wallet.WalletOptions.Builder().setEnvironment(GooglePayment.getEnvironment(getConfiguration().getAndroidPay())).setTheme(WalletConstants.THEME_LIGHT).build()).build();
}
if (!mGoogleApiClient.isConnected() && !mGoogleApiClient.isConnecting()) {
mGoogleApiClient.registerConnectionCallbacks(new ConnectionCallbacks() {
@Override
public void onConnected(Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
postCallback(new GoogleApiClientException(ErrorType.ConnectionSuspended, i));
}
});
mGoogleApiClient.registerConnectionFailedListener(new OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
postCallback(new GoogleApiClientException(ErrorType.ConnectionFailed, connectionResult.getErrorCode()));
}
});
mGoogleApiClient.connect();
}
return mGoogleApiClient;
}
use of com.google.android.gms.common.ConnectionResult in project Talon-for-Twitter by klinker24.
the class TweetWearableService method onMessageReceived.
@Override
public void onMessageReceived(MessageEvent messageEvent) {
final WearableUtils wearableUtils = new WearableUtils();
final BitmapLruCache cache = App.getInstance(this).getBitmapCache();
if (markReadHandler == null) {
markReadHandler = new Handler();
}
final String message = new String(messageEvent.getData());
Log.d(TAG, "got message: " + message);
final GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).build();
ConnectionResult connectionResult = googleApiClient.blockingConnect(30, TimeUnit.SECONDS);
if (!connectionResult.isSuccess()) {
Log.e(TAG, "Failed to connect to GoogleApiClient.");
return;
}
if (message.equals(KeyProperties.GET_DATA_MESSAGE)) {
AppSettings settings = AppSettings.getInstance(this);
Cursor tweets = HomeDataSource.getInstance(this).getWearCursor(settings.currentAccount);
PutDataMapRequest dataMap = PutDataMapRequest.create(KeyProperties.PATH);
ArrayList<String> names = new ArrayList<String>();
ArrayList<String> screennames = new ArrayList<String>();
ArrayList<String> bodies = new ArrayList<String>();
ArrayList<String> ids = new ArrayList<String>();
if (tweets != null && tweets.moveToLast()) {
do {
String name = tweets.getString(tweets.getColumnIndex(HomeSQLiteHelper.COLUMN_NAME));
String screenname = tweets.getString(tweets.getColumnIndex(HomeSQLiteHelper.COLUMN_SCREEN_NAME));
String pic = tweets.getString(tweets.getColumnIndex(HomeSQLiteHelper.COLUMN_PRO_PIC));
String body = tweets.getString(tweets.getColumnIndex(HomeSQLiteHelper.COLUMN_TEXT));
long id = tweets.getLong(tweets.getColumnIndex(HomeSQLiteHelper.COLUMN_TWEET_ID));
String retweeter;
try {
retweeter = tweets.getString(tweets.getColumnIndex(HomeSQLiteHelper.COLUMN_RETWEETER));
} catch (Exception e) {
retweeter = "";
}
screennames.add(screenname);
names.add(name);
if (TextUtils.isEmpty(retweeter)) {
body = pic + KeyProperties.DIVIDER + body + KeyProperties.DIVIDER;
} else {
body = pic + KeyProperties.DIVIDER + body + "<br><br>" + getString(R.string.retweeter) + retweeter + KeyProperties.DIVIDER;
}
bodies.add(Html.fromHtml(body.replace("<p>", KeyProperties.LINE_BREAK)).toString());
ids.add(id + "");
} while (tweets.moveToPrevious() && tweets.getCount() - tweets.getPosition() < MAX_ARTICLES_TO_SYNC);
tweets.close();
}
dataMap.getDataMap().putStringArrayList(KeyProperties.KEY_USER_NAME, names);
dataMap.getDataMap().putStringArrayList(KeyProperties.KEY_USER_SCREENNAME, screennames);
dataMap.getDataMap().putStringArrayList(KeyProperties.KEY_TWEET, bodies);
dataMap.getDataMap().putStringArrayList(KeyProperties.KEY_ID, ids);
// light background with orange accent or theme color accent
dataMap.getDataMap().putInt(KeyProperties.KEY_PRIMARY_COLOR, Color.parseColor("#dddddd"));
if (settings.addonTheme) {
dataMap.getDataMap().putInt(KeyProperties.KEY_ACCENT_COLOR, settings.accentInt);
} else {
dataMap.getDataMap().putInt(KeyProperties.KEY_ACCENT_COLOR, getResources().getColor(R.color.orange_primary_color));
}
dataMap.getDataMap().putLong(KeyProperties.KEY_DATE, System.currentTimeMillis());
for (String node : wearableUtils.getNodes(googleApiClient)) {
byte[] bytes = dataMap.asPutDataRequest().getData();
Wearable.MessageApi.sendMessage(googleApiClient, node, KeyProperties.PATH, bytes);
Log.v(TAG, "sent " + bytes.length + " bytes of data to node " + node);
}
} else if (message.startsWith(KeyProperties.MARK_READ_MESSAGE)) {
markReadHandler.removeCallbacksAndMessages(null);
markReadHandler.postDelayed(new Runnable() {
@Override
public void run() {
String[] messageContent = message.split(KeyProperties.DIVIDER);
final long id = Long.parseLong(messageContent[1]);
final AppSettings settings = AppSettings.getInstance(TweetWearableService.this);
try {
HomeDataSource.getInstance(TweetWearableService.this).markPosition(settings.currentAccount, id);
} catch (Throwable t) {
t.printStackTrace();
}
sendBroadcast(new Intent("com.klinker.android.twitter.CLEAR_PULL_UNREAD"));
final SharedPreferences sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
// mark tweetmarker if they use it
if (AppSettings.getInstance(TweetWearableService.this).tweetmarker) {
new Thread(new Runnable() {
@Override
public void run() {
TweetMarkerHelper helper = new TweetMarkerHelper(settings.currentAccount, sharedPrefs.getString("twitter_screen_name_" + settings.currentAccount, ""), Utils.getTwitter(TweetWearableService.this, settings), sharedPrefs);
helper.sendCurrentId("timeline", id);
startService(new Intent(TweetWearableService.this, HandleScrollService.class));
}
}).start();
} else {
startService(new Intent(TweetWearableService.this, HandleScrollService.class));
}
}
}, 5000);
} else if (message.startsWith(KeyProperties.REQUEST_FAVORITE)) {
final long tweetId = Long.parseLong(message.split(KeyProperties.DIVIDER)[1]);
new Thread(new Runnable() {
@Override
public void run() {
try {
Utils.getTwitter(TweetWearableService.this, AppSettings.getInstance(TweetWearableService.this)).createFavorite(tweetId);
} catch (Exception e) {
}
}
}).start();
} else if (message.startsWith(KeyProperties.REQUEST_COMPOSE)) {
final String status = message.split(KeyProperties.DIVIDER)[1];
new Thread(new Runnable() {
@Override
public void run() {
try {
Utils.getTwitter(TweetWearableService.this, AppSettings.getInstance(TweetWearableService.this)).updateStatus(status);
} catch (Exception e) {
}
}
}).start();
} else if (message.startsWith(KeyProperties.REQUEST_RETWEET)) {
final long tweetId = Long.parseLong(message.split(KeyProperties.DIVIDER)[1]);
new Thread(new Runnable() {
@Override
public void run() {
try {
Utils.getTwitter(TweetWearableService.this, AppSettings.getInstance(TweetWearableService.this)).retweetStatus(tweetId);
} catch (Exception e) {
}
}
}).start();
} else if (message.startsWith(KeyProperties.REQUEST_REPLY)) {
final String tweet = message.split(KeyProperties.DIVIDER)[1];
final long replyToId = Long.parseLong(message.split(KeyProperties.DIVIDER)[2]);
final StatusUpdate status = new StatusUpdate(tweet);
status.setInReplyToStatusId(replyToId);
new Thread(new Runnable() {
@Override
public void run() {
try {
Utils.getTwitter(TweetWearableService.this, AppSettings.getInstance(TweetWearableService.this)).updateStatus(status);
} catch (Exception e) {
}
}
}).start();
} else if (message.startsWith(KeyProperties.REQUEST_IMAGE)) {
final String url = message.split(KeyProperties.DIVIDER)[1];
Bitmap image = null;
try {
cache.get(url).getBitmap();
} catch (Exception e) {
}
if (image != null) {
image = adjustImage(image);
sendImage(image, url, wearableUtils, googleApiClient);
} else {
// download it
new Thread(new Runnable() {
@Override
public void run() {
try {
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
InputStream is = new BufferedInputStream(conn.getInputStream());
Bitmap image = decodeSampledBitmapFromResourceMemOpt(is, 500, 500);
try {
is.close();
} catch (Exception e) {
}
try {
conn.disconnect();
} catch (Exception e) {
}
cache.put(url, image);
image = adjustImage(image);
sendImage(image, url, wearableUtils, googleApiClient);
} catch (Exception e) {
}
}
}).start();
}
} else {
Log.e(TAG, "message not recognized");
}
}
Aggregations