com.google.android.gms.common.api.PendingResult Java Examples
The following examples show how to use
com.google.android.gms.common.api.PendingResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UARTConfigurationsActivity.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * This method read the UART configurations from the DataApi and populates the adapter with them. */ private void populateConfigurations() { if (googleApiClient.isConnected()) { final PendingResult<DataItemBuffer> results = Wearable.DataApi.getDataItems(googleApiClient, Uri.parse("wear:" + Constants.UART.CONFIGURATIONS), DataApi.FILTER_PREFIX); results.setResultCallback(dataItems -> { final List<UartConfiguration> configurations = new ArrayList<>(dataItems.getCount()); for (int i = 0; i < dataItems.getCount(); ++i) { final DataItem item = dataItems.get(i); final long id = ContentUris.parseId(item.getUri()); final DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap(); final UartConfiguration configuration = new UartConfiguration(dataMap, id); configurations.add(configuration); } adapter.setConfigurations(configurations); dataItems.release(); }); } }
Example #2
Source File: GoogleFitSessionManager.java From JayPS-AndroidApp with MIT License | 6 votes |
@Override public void saveActiveSession(final long endTime) { PendingResult<SessionStopResult> pendingResult = _sessionsApi.stopSession(_googleAPIClient, _sessionIdentifier); pendingResult.setResultCallback(new ResultCallback<SessionStopResult>() { @Override public void onResult(SessionStopResult sessionStopResult) { if (sessionStopResult.getSessions().size() > 0) { for (Session session : sessionStopResult.getSessions()) { buildDataPoints(session, endTime); insertDataPoints(session); } } _sessionDataList.clear(); } }); }
Example #3
Source File: RecipeActivity.java From io2015-codelabs with Apache License 2.0 | 6 votes |
@Override public void onStop(){ if (recipe != null) { final String TITLE = recipe.getTitle(); final Uri APP_URI = BASE_APP_URI.buildUpon().appendPath(recipe.getId()).build(); Action viewAction = Action.newAction(Action.TYPE_VIEW, TITLE, APP_URI); PendingResult<Status> result = AppIndex.AppIndexApi.end(mClient, viewAction); result.setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status status) { if (status.isSuccess()) { Log.d(TAG, "App Indexing API: Recorded recipe " + recipe.getTitle() + " view end successfully."); } else { Log.e(TAG, "App Indexing API: There was an error recording the recipe view." + status.toString()); } } }); mClient.disconnect(); super.onStop(); } }
Example #4
Source File: NearbyBackgroundSubscription.java From AndroidChromium with Apache License 2.0 | 6 votes |
@Override protected void onConnected() { PendingResult<Status> pendingResult = null; String actionStr = null; if (mAction == SUBSCRIBE) { pendingResult = Nearby.Messages.subscribe( getGoogleApiClient(), createNearbySubscribeIntent(), createSubscribeOptions()); actionStr = "background subscribe"; } else { pendingResult = Nearby.Messages.unsubscribe( getGoogleApiClient(), createNearbySubscribeIntent()); actionStr = "background unsubscribe"; } pendingResult.setResultCallback(new SimpleResultCallback(actionStr) { @Override public void onResult(final Status status) { super.onResult(status); disconnect(); if (mCallback != null) { mCallback.run(); } } }); }
Example #5
Source File: GoogleApiClientWrapper.java From android-play-games-in-motion with Apache License 2.0 | 6 votes |
/** * Starts a new session for Fit data. This will take care of registering all the sensors, * recording the sensor data, and registering the data set as a session to Google Fit. * @param dataTypeSettings Types of data to listen to, in an array. * @param sessionDescription The description of the session. * @param listener The OnDataPointListener to receive sensor events. */ public void startFitDataSession(FitDataTypeSetting[] dataTypeSettings, String sessionDescription, OnDataPointListener listener) { for (FitDataTypeSetting dataTypeSetting : dataTypeSettings) { registerFitDataListener(dataTypeSetting, listener); startRecordingFitData(dataTypeSetting); } Session session = new Session.Builder() .setName(SESSION_NAME) .setDescription(sessionDescription) .setActivity(FitnessActivities.RUNNING_JOGGING) .setStartTime(System.currentTimeMillis(), TimeUnit.MILLISECONDS) .build(); PendingResult<Status> pendingResult = Fitness.SessionsApi.startSession(mGoogleApiClient, session); pendingResult.setResultCallback(new FitResultCallback<Status>( this, FitResultCallback.RegisterType.SESSION, null /* dataType */, true /* subscribe */)); }
Example #6
Source File: MainActivity.java From DronesWear with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected void onPause() { super.onPause(); Message.sendInteractionTypeMessage(InteractionType.NONE, mGoogleApiClient); PendingResult<DataApi.DataItemResult> pendingResult = Message.sendActionTypeMessage(ActionType.NONE, mGoogleApiClient); pendingResult.setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(@NonNull DataApi.DataItemResult dataItemsResult) { if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) { Wearable.DataApi.removeListener(mGoogleApiClient, MainActivity.this); mGoogleApiClient.disconnect(); } } }); mDiscoverer.cleanup(); }
Example #7
Source File: WearableApi.java From LibreAlarm with GNU General Public License v3.0 | 6 votes |
public static void sendMessage(final GoogleApiClient client, final String command, final byte[] message, final ResultCallback<MessageApi.SendMessageResult> listener) { new Thread(new Runnable() { @Override public void run() { NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes( client ).await(); for(Node node : nodes.getNodes()) { Log.i(TAG, "sending to " + node.getId() + ", command: " + command); PendingResult<MessageApi.SendMessageResult> pR = Wearable.MessageApi.sendMessage(client, node.getId(), command, message); if (listener != null) pR.setResultCallback(listener); } } }).start(); }
Example #8
Source File: ArtistActivity.java From io2014-codelabs with Apache License 2.0 | 6 votes |
private void recordAppIndexingView() { PendingResult<Status> result = AppIndex.AppIndexApi.view( mGoogleApiClient, ArtistActivity.this, getIntent(), mArtist.getName(), Uri.parse(mArtist.getUrl()), null); result.setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status status) { if (status.isSuccess()) { Log.d(TAG, "App Indexing API: Recorded artist " + mArtist.getName() + " view successfully."); } else { Log.e(TAG, "App Indexing API: There was an error recording the artist view." + status.toString()); } } }); }
Example #9
Source File: ListenerService.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
private void sendMessagePayload(Node node, String pathdesc, final String path, byte[] payload) { Log.d(TAG, "Benchmark: doInBackground sendMessagePayload " + pathdesc + "=" + path + " nodeID=" + node.getId() + " nodeName=" + node.getDisplayName() + ((payload != null) ? (" payload.length=" + payload.length) : "")); //ORIGINAL ASYNC METHOD PendingResult<MessageApi.SendMessageResult> result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), path, payload); result.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() { @Override public void onResult(MessageApi.SendMessageResult sendMessageResult) { if (!sendMessageResult.getStatus().isSuccess()) { Log.e(TAG, "sendMessagePayload ERROR: failed to send request " + path + " Status=" + sendMessageResult.getStatus().getStatusMessage()); } else { Log.d(TAG, "sendMessagePayload Sent request " + node.getDisplayName() + " " + path + " Status=: " + sendMessageResult.getStatus().getStatusMessage()); } } }); //TEST************************************************************************** DataMap datamap; if (bBenchmarkBgs && path.equals(SYNC_BGS_PATH)) { //bBenchmarkBgs = runBenchmarkTest(node, pathdesc+"_BM", path+"_BM", payload, bBenchmarkDup); datamap = getWearTransmitterData(1000, 0, 0);//generate 1000 records of test data if (datamap != null) { bBenchmarkBgs = runBenchmarkTest(node, pathdesc + "_BM", path + "_BM", datamap.toByteArray(), false); } } else if (bBenchmarkLogs && path.equals(SYNC_LOGS_PATH)) { //bBenchmarkLogs = runBenchmarkTest(node, pathdesc+"_BM", path+"_BM", payload, bBenchmarkDup); datamap = getWearLogData(1000, 0, 0, -1);//generate 1000 records of test data if (datamap != null) { bBenchmarkLogs = runBenchmarkTest(node, pathdesc + "_BM", path + "_BM", datamap.toByteArray(), false); } } //Random Test if (bBenchmarkRandom) { final byte[] randomBytes = new byte[200000]; ThreadLocalRandom.current().nextBytes(randomBytes); bBenchmarkRandom = runBenchmarkTest(node, pathdesc + "_BM_RAND", path + "_BM_RAND", randomBytes, false); Log.i(TAG, "Benchmark: DONE!"); } //****************************************************************************** }
Example #10
Source File: SnapshotCoordinator.java From Trivia-Knowledge with Apache License 2.0 | 5 votes |
@Override public PendingResult<OpenSnapshotResult> open(GoogleApiClient googleApiClient, final String filename, boolean createIfNotFound) { // check if the file is already open if (!isAlreadyOpen(filename)) { setIsOpening(filename); try { return new CoordinatedPendingResult<>( Games.Snapshots.open(googleApiClient, filename, createIfNotFound), new ResultListener() { @Override public void onResult(Result result) { // if open failed, set the file to closed, otherwise, keep it open. if (!result.getStatus().isSuccess()) { Log.d(TAG, "Open was not a success: " + result.getStatus() + " for filename " + filename); setClosed(filename); } else { Log.d(TAG, "Open successful: " + filename); } } }); } catch (RuntimeException e) { // catch runtime exceptions here - they should not happen, but they do. // mark the file as closed so it can be attempted to be opened again. setClosed(filename); throw e; } } else { // a more sophisticated solution could attach this operation to a future // that would be triggered by closing the file, but this will at least avoid // corrupting the data with non-resolvable conflicts. throw new IllegalStateException(filename + " is already open"); } }
Example #11
Source File: ListenerService.java From xDrip with GNU General Public License v3.0 | 5 votes |
private void sendMessagePayload(Node node, String pathdesc, final String path, byte[] payload) { Log.d(TAG, "Benchmark: doInBackground sendMessagePayload " + pathdesc + "=" + path + " nodeID=" + node.getId() + " nodeName=" + node.getDisplayName() + ((payload != null) ? (" payload.length=" + payload.length) : "")); //ORIGINAL ASYNC METHOD PendingResult<MessageApi.SendMessageResult> result = Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), path, payload); result.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() { @Override public void onResult(MessageApi.SendMessageResult sendMessageResult) { if (!sendMessageResult.getStatus().isSuccess()) { Log.e(TAG, "sendMessagePayload ERROR: failed to send request " + path + " Status=" + sendMessageResult.getStatus().getStatusMessage()); } else { Log.d(TAG, "sendMessagePayload Sent request " + node.getDisplayName() + " " + path + " Status=: " + sendMessageResult.getStatus().getStatusMessage()); } } }); //TEST************************************************************************** DataMap datamap; if (bBenchmarkBgs && path.equals(SYNC_BGS_PATH)) { //bBenchmarkBgs = runBenchmarkTest(node, pathdesc+"_BM", path+"_BM", payload, bBenchmarkDup); datamap = getWearTransmitterData(1000, 0, 0);//generate 1000 records of test data if (datamap != null) { bBenchmarkBgs = runBenchmarkTest(node, pathdesc + "_BM", path + "_BM", datamap.toByteArray(), false); } } else if (bBenchmarkLogs && path.equals(SYNC_LOGS_PATH)) { //bBenchmarkLogs = runBenchmarkTest(node, pathdesc+"_BM", path+"_BM", payload, bBenchmarkDup); datamap = getWearLogData(1000, 0, 0, -1);//generate 1000 records of test data if (datamap != null) { bBenchmarkLogs = runBenchmarkTest(node, pathdesc + "_BM", path + "_BM", datamap.toByteArray(), false); } } //Random Test if (bBenchmarkRandom) { final byte[] randomBytes = new byte[200000]; ThreadLocalRandom.current().nextBytes(randomBytes); bBenchmarkRandom = runBenchmarkTest(node, pathdesc + "_BM_RAND", path + "_BM_RAND", randomBytes, false); Log.i(TAG, "Benchmark: DONE!"); } //****************************************************************************** }
Example #12
Source File: AutoCompleteLocation.java From AutocompleteLocation with Apache License 2.0 | 5 votes |
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { UIUtils.hideKeyboard(AutoCompleteLocation.this.getContext(), AutoCompleteLocation.this); final AutocompletePrediction item = mAutoCompleteAdapter.getItem(position); if (item != null) { final String placeId = item.getPlaceId(); PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId); placeResult.setResultCallback(mUpdatePlaceDetailsCallback); } }
Example #13
Source File: TimeAttendantFastFragment.java From iBeacon-Android with Apache License 2.0 | 5 votes |
private synchronized void displayLocationSettingsRequest() { LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest); builder.setAlwaysShow(true); //for fix deprecate code -> https://developers.google.com/android/reference/com/google/android/gms/location/SettingsClient PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build()); result.setResultCallback(this); }
Example #14
Source File: SnapshotCoordinator.java From Trivia-Knowledge with Apache License 2.0 | 5 votes |
@Override public PendingResult<OpenSnapshotResult> open(GoogleApiClient googleApiClient, final SnapshotMetadata snapshotMetadata, int conflictPolicy) { // check if the file is already open if (!isAlreadyOpen(snapshotMetadata.getUniqueName())) { setIsOpening(snapshotMetadata.getUniqueName()); try { return new CoordinatedPendingResult<>(Games.Snapshots.open( googleApiClient, snapshotMetadata, conflictPolicy), new ResultListener() { @Override public void onResult(Result result) { // if open failed, set the file to closed, otherwise, keep it open. if (!result.getStatus().isSuccess()) { Log.d(TAG, "Open was not a success: " + result.getStatus() + " for filename " + snapshotMetadata.getUniqueName()); setClosed(snapshotMetadata.getUniqueName()); } else { Log.d(TAG, "Open was successful: " + snapshotMetadata.getUniqueName()); } } }); } catch (RuntimeException e) { setClosed(snapshotMetadata.getUniqueName()); throw e; } } else { throw new IllegalStateException(snapshotMetadata.getUniqueName() + " is already open"); } }
Example #15
Source File: SnapshotCoordinator.java From Asteroid with Apache License 2.0 | 5 votes |
@Override public PendingResult<OpenSnapshotResult> open(GoogleApiClient googleApiClient, final SnapshotMetadata snapshotMetadata, int conflictPolicy) { // check if the file is already open if (!isAlreadyOpen(snapshotMetadata.getUniqueName())) { setIsOpening(snapshotMetadata.getUniqueName()); try { return new CoordinatedPendingResult<>(Games.Snapshots.open( googleApiClient, snapshotMetadata, conflictPolicy), result -> { // if open failed, set the file to closed, otherwise, keep it open. if (!result.getStatus().isSuccess()) { Log.d(TAG, "Open was not a success: " + result.getStatus() + " for filename " + snapshotMetadata.getUniqueName()); setClosed(snapshotMetadata.getUniqueName()); } else { Log.d(TAG, "Open was successful: " + snapshotMetadata.getUniqueName()); } }); } catch (RuntimeException e) { setClosed(snapshotMetadata.getUniqueName()); throw e; } } else { throw new IllegalStateException(snapshotMetadata.getUniqueName() + " is already open"); } }
Example #16
Source File: SnapshotCoordinator.java From Trivia-Knowledge with Apache License 2.0 | 5 votes |
@Override public PendingResult<CommitSnapshotResult> commitAndClose(GoogleApiClient googleApiClient, final Snapshot snapshot, SnapshotMetadataChange snapshotMetadataChange) { if (isAlreadyOpen(snapshot.getMetadata().getUniqueName()) && !isAlreadyClosing(snapshot.getMetadata().getUniqueName())) { setIsClosing(snapshot.getMetadata().getUniqueName()); try { return new CoordinatedPendingResult<>( Games.Snapshots.commitAndClose(googleApiClient, snapshot, snapshotMetadataChange), new ResultListener() { @Override public void onResult(Result result) { // even if commit and close fails, the file is closed. Log.d(TAG, "CommitAndClose complete, closing " + snapshot.getMetadata().getUniqueName()); setClosed(snapshot.getMetadata().getUniqueName()); } }); } catch (RuntimeException e) { setClosed(snapshot.getMetadata().getUniqueName()); throw e; } } else { throw new IllegalStateException(snapshot.getMetadata().getUniqueName() + " is either closed or is closing"); } }
Example #17
Source File: SnapshotCoordinator.java From Trivia-Knowledge with Apache License 2.0 | 5 votes |
@Override public PendingResult<OpenSnapshotResult> resolveConflict(GoogleApiClient googleApiClient, String conflictId, String snapshotId, SnapshotMetadataChange snapshotMetadataChange, SnapshotContents snapshotContents) { // Since the unique name of the snapshot is unknown, this resolution method cannot be safely // used. Please use another method of resolution. throw new IllegalStateException("resolving conflicts with ids is not supported."); }
Example #18
Source File: WearRequestHandler.java From CrossBow with Apache License 2.0 | 5 votes |
private void sendResultToWear(String sourceNodeID, boolean success, String uuid, NetworkResponse networkResponse) { WearNetworkResponse wearNetworkResponse = new WearNetworkResponse(success, uuid, networkResponse); byte[] data = wearNetworkResponse.toByteArray(); PendingResult<MessageApi.SendMessageResult> result = Wearable.MessageApi.sendMessage(googleApiClient, sourceNodeID, "/crossbow_wear/" + uuid, data); result.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() { @Override public void onResult(MessageApi.SendMessageResult sendMessageResult) { Log.i("TAG", "Request sent back result = " + sendMessageResult.getStatus().isSuccess()); } }); }
Example #19
Source File: WatchFaceConfigActivity.java From AndroidDemoProjects with Apache License 2.0 | 5 votes |
@Override public void onClick(WearableListView.ViewHolder viewHolder) { BackgroundItemViewHolder holder = (BackgroundItemViewHolder) viewHolder; PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(WatchFace.DATA_LAYER_PATH); putDataMapRequest.getDataMap().putLong( WatchFace.KEY_TIME, new Date().getTime() ); putDataMapRequest.getDataMap().putInt(WatchFace.KEY_BACKGROUND_POSITION, holder.getPosition()); PutDataRequest putDataReq = putDataMapRequest.asPutDataRequest(); PendingResult<DataApi.DataItemResult> result = Wearable.DataApi.putDataItem( mGoogleApiClient, putDataReq ); finish(); }
Example #20
Source File: RecipeActivity.java From search-samples with Apache License 2.0 | 5 votes |
@Override public void onStart(){ super.onStart(); if (recipe != null) { // Connect your client mClient.connect(); // Define a title for your current page, shown in autocompletion UI final String TITLE = recipe.getTitle(); final Uri APP_URI = BASE_APP_URI.buildUpon().appendPath(recipe.getId()).build(); final Uri WEB_URL = Uri.parse(recipe.getUrl()); // Call the App Indexing API view method PendingResult<Status> result = AppIndex.AppIndexApi.view(mClient, this, APP_URI, TITLE, WEB_URL, null); result.setResultCallback(new ResultCallback<Status>() { @Override public void onResult(Status status) { if (status.isSuccess()) { Log.d(TAG, "App Indexing API: Recorded recipe " + recipe.getTitle() + " view successfully."); } else { Log.e(TAG, "App Indexing API: There was an error recording the recipe view." + status.toString()); } } }); } }
Example #21
Source File: PlaceAutocompleteAdapter.java From place-search-dialog with Apache License 2.0 | 5 votes |
/** * Submits an autocomplete query to the Places Geo Data Autocomplete API. * Results are returned as frozen AutocompletePrediction objects, ready to be cached. * objects to store the Place ID and description that the API returns. * Returns an empty list if no results were found. * Returns null if the API client is not available or the query did not complete * successfully. * This method MUST be called off the main UI thread, as it will block until data is returned * from the API, which may include a network request. * * @param constraint Autocomplete query string * @return Results from the autocomplete API or null if the query was not successful. * @see Places#GEO_DATA_API#getAutocomplete(CharSequence) * @see AutocompletePrediction#freeze() */ private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) { if (mGoogleApiClient.isConnected()) { Log.i(TAG, "Starting autocomplete query for: " + constraint); // Submit the query to the autocomplete API and retrieve a PendingResult that will // contain the results when the query completes. PendingResult<AutocompletePredictionBuffer> results = Places.GeoDataApi .getAutocompletePredictions(mGoogleApiClient, constraint.toString(), mBounds, mPlaceFilter); // This method should have been called off the main UI thread. Block and wait for at most 60s // for a result from the API. AutocompletePredictionBuffer autocompletePredictions = results .await(60, TimeUnit.SECONDS); // Confirm that the query completed successfully, otherwise return null final Status status = autocompletePredictions.getStatus(); if (!status.isSuccess()) { Toast.makeText(getContext(), "Error contacting API: " + status.toString(), Toast.LENGTH_SHORT).show(); Log.e(TAG, "Error getting autocomplete prediction API call: " + status.toString()); autocompletePredictions.release(); return null; } Log.i(TAG, "Query completed. Received " + autocompletePredictions.getCount() + " predictions."); // Freeze the results immutable representation that can be stored safely. return DataBufferUtils.freezeAndClose(autocompletePredictions); } Log.e(TAG, "Google API client is not connected for autocomplete query."); return null; }
Example #22
Source File: GoogleApiMessenger.java From Sensor-Data-Logger with Apache License 2.0 | 5 votes |
public void updateLocalNode() { PendingResult<NodeApi.GetLocalNodeResult> pendingResult = Wearable.NodeApi.getLocalNode(googleApiClient); pendingResult.setResultCallback(new ResultCallback<NodeApi.GetLocalNodeResult>() { @Override public void onResult(@NonNull NodeApi.GetLocalNodeResult getLocalNodeResult) { status.setLocalNode(getLocalNodeResult.getNode()); status.updated(statusUpdateHandler); wearableApiAvailable = getLocalNodeResult.getNode() != null; } }); }
Example #23
Source File: WearableApi.java From LibreAlarm with GNU General Public License v3.0 | 5 votes |
private static boolean sendData(GoogleApiClient client, PutDataMapRequest putDataMapReq, ResultCallback<DataApi.DataItemResult> listener) { if (client.isConnected()) { Log.i(TAG, "update settings"); putDataMapReq.setUrgent(); PutDataRequest putDataReq = putDataMapReq.asPutDataRequest(); PendingResult<DataApi.DataItemResult> pR = Wearable.DataApi.putDataItem(client, putDataReq); if (listener != null) pR.setResultCallback(listener); return true; } return false; }
Example #24
Source File: Message.java From DronesWear with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static PendingResult<DataApi.DataItemResult> sendJoystickMessage(JoystickData joystickData, GoogleApiClient googleApiClient) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(JOYSTICK_PATH); joystickMessageUri = dataMapRequest.getUri(); DataMap dataMap = dataMapRequest.getDataMap(); //Data set dataMap.putFloatArray(VALUE_STR, new float[]{joystickData.getPercentX(), joystickData.getPercentY()}); // Data Push PutDataRequest request = dataMapRequest.asPutDataRequest(); PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(googleApiClient, request); return pendingResult; }
Example #25
Source File: Message.java From DronesWear with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static PendingResult<DataApi.DataItemResult> sendActionMessage(GoogleApiClient googleApiClient) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(ACTION_PATH); actionMessageUri = dataMapRequest.getUri(); // Data Push PutDataRequest request = dataMapRequest.asPutDataRequest(); PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(googleApiClient, request); return pendingResult; }
Example #26
Source File: Message.java From DronesWear with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static PendingResult<DataApi.DeleteDataItemsResult> emptyActionMessage(GoogleApiClient googleApiClient) { PendingResult<DataApi.DeleteDataItemsResult> pendingResult = null; if (actionMessageUri != null) { pendingResult = Wearable.DataApi.deleteDataItems(googleApiClient, actionMessageUri); } return pendingResult; }
Example #27
Source File: PlaceAutocompleteAdapter.java From ExamplesAndroid with Apache License 2.0 | 5 votes |
/** * Submits an autocomplete query to the Places Geo Data Autocomplete API. * Results are returned as frozen AutocompletePrediction objects, ready to be cached. * objects to store the Place ID and description that the API returns. * Returns an empty list if no results were found. * Returns null if the API client is not available or the query did not complete * successfully. * This method MUST be called off the main UI thread, as it will block until data is returned * from the API, which may include a network request. * * @param constraint Autocomplete query string * @return Results from the autocomplete API or null if the query was not successful. * @see Places#GEO_DATA_API#getAutocomplete(CharSequence) * @see AutocompletePrediction#freeze() */ private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) { if (mGoogleApiClient.isConnected()) { // Submit the query to the autocomplete API and retrieve a PendingResult that will // contain the results when the query completes. PendingResult<AutocompletePredictionBuffer> results = Places.GeoDataApi .getAutocompletePredictions(mGoogleApiClient, constraint.toString(), mBounds, mPlaceFilter); // This method should have been called off the main UI thread. Block and wait for at most 60s // for a result from the API. AutocompletePredictionBuffer autocompletePredictions = results .await(60, TimeUnit.SECONDS); // Confirm that the query completed successfully, otherwise return null final Status status = autocompletePredictions.getStatus(); if (!status.isSuccess()) { Toast.makeText(getContext(), "Error contacting API: " + status.toString(), Toast.LENGTH_SHORT).show(); autocompletePredictions.release(); return null; } // Freeze the results immutable representation that can be stored safely. return DataBufferUtils.freezeAndClose(autocompletePredictions); } return null; }
Example #28
Source File: LocationController.java From Telegram with GNU General Public License v2.0 | 5 votes |
@Override public void onConnected(Bundle bundle) { wasConnectedToPlayServices = true; try { if (Build.VERSION.SDK_INT >= 21) { LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest); PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build()); result.setResultCallback(locationSettingsResult -> { final Status status = locationSettingsResult.getStatus(); switch (status.getStatusCode()) { case LocationSettingsStatusCodes.SUCCESS: startFusedLocationRequest(true); break; case LocationSettingsStatusCodes.RESOLUTION_REQUIRED: Utilities.stageQueue.postRunnable(() -> { if (lookingForPeopleNearby || !sharingLocations.isEmpty()) { AndroidUtilities.runOnUIThread(() -> getNotificationCenter().postNotificationName(NotificationCenter.needShowPlayServicesAlert, status)); } }); break; case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: Utilities.stageQueue.postRunnable(() -> { playServicesAvailable = false; try { googleApiClient.disconnect(); start(); } catch (Throwable ignore) { } }); break; } }); } else { startFusedLocationRequest(true); } } catch (Throwable e) { FileLog.e(e); } }
Example #29
Source File: ConnectionHelper.java From OkWear with Apache License 2.0 | 5 votes |
public void getNodes(@NonNull final NodeChangeListener listener) { final List<Node> nodeList = new ArrayList<>(); final PendingResult<NodeApi.GetConnectedNodesResult> nodes = Wearable.NodeApi.getConnectedNodes(mGoogleApiClient); nodes.setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() { @Override public void onResult(NodeApi.GetConnectedNodesResult result) { for (Node node : result.getNodes()) { nodeList.add(node); listener.onReceiveNodes(nodeList); } } }); }
Example #30
Source File: ConnectionHelper.java From OkWear with Apache License 2.0 | 5 votes |
/** * you need to renew the data if it uses same key * * @param request * @param listener */ public void syncData(@NonNull final PutDataRequest request, @Nullable final SendResultListener<DataApi.DataItemResult> listener) { final PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(mGoogleApiClient, request); pendingResult.setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(DataApi.DataItemResult dataItemResult) { if (listener != null) { listener.onResult(dataItemResult); } } }); }