Java Code Examples for com.google.android.gms.common.api.PendingResult#setResultCallback()

The following examples show how to use com.google.android.gms.common.api.PendingResult#setResultCallback() . 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: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
@OnClick(R.id.btn_start_session)
public void startSession() {
    mSession = new Session.Builder()
            .setName(SESSION_NAME)
            .setIdentifier(getString(R.string.app_name) + " " + System.currentTimeMillis())
            .setDescription("Yoga Session Description")
            .setStartTime(Calendar.getInstance().getTimeInMillis(), TimeUnit.MILLISECONDS)
            .setActivity(FitnessActivities.YOGA)
            .build();

    PendingResult<Status> pendingResult =
            Fitness.SessionsApi.startSession(mGoogleApiClient, mSession);

    pendingResult.setResultCallback(
            new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    if (status.isSuccess()) {
                        Log.i("Tuts+", "Successfully started session");
                    } else {
                        Log.i("Tuts+", "Failed to start session: " + status.getStatusMessage());
                    }
                }
            }
    );
}
 
Example 2
Source File: MainActivity.java    From DronesWear with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void onButtonClicked()
{
    PendingResult<DataApi.DataItemResult> pendingResult = Message.sendActionMessage(mGoogleApiClient);
    pendingResult.setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
        @Override
        public void onResult(@NonNull DataApi.DataItemResult dataItemResult) {
            Message.emptyActionMessage(mGoogleApiClient);
        }
    });

    Intent intent = new Intent(this, ConfirmationActivity.class);
    intent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE,
            ConfirmationActivity.SUCCESS_ANIMATION);
    intent.putExtra(ConfirmationActivity.EXTRA_MESSAGE,
            getString(R.string.action_sent));
    startActivity(intent);
}
 
Example 3
Source File: NearbyBackgroundSubscription.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void setLocalNodeName () {
    forceGoogleApiConnect();
    PendingResult<NodeApi.GetLocalNodeResult> result = Wearable.NodeApi.getLocalNode(googleApiClient);
    result.setResultCallback(new ResultCallback<NodeApi.GetLocalNodeResult>() {
        @Override
        public void onResult(NodeApi.GetLocalNodeResult getLocalNodeResult) {
            if (!getLocalNodeResult.getStatus().isSuccess()) {
                Log.e(TAG, "ERROR: failed to getLocalNode Status=" + getLocalNodeResult.getStatus().getStatusMessage());
            } else {
                Log.d(TAG, "getLocalNode Status=: " + getLocalNodeResult.getStatus().getStatusMessage());
                Node getnode = getLocalNodeResult.getNode();
                localnode = getnode != null ? getnode.getDisplayName() + "|" + getnode.getId() : "";
                Log.d(TAG, "setLocalNodeName.  localnode=" + localnode);
            }
        }
    });
}
 
Example 5
Source File: ConnectionHelper.java    From OkWear with Apache License 2.0 6 votes vote down vote up
/**
 * send message
 * you don't have to send anything
 *
 * @param node     送信先node
 * @param payload
 * @param path
 * @param listener
 */
public void sendMessage(@NonNull final Node node, @Nullable final byte[] payload,
                        @NonNull final String path, @Nullable final SendResultListener<MessageApi.SendMessageResult> listener) {
    final PendingResult<MessageApi.SendMessageResult> messageResult =
            Wearable.MessageApi.sendMessage(mGoogleApiClient, node.getId(), path, payload);
    messageResult.setResultCallback(new ResultCallback<MessageApi.SendMessageResult>() {
        @Override
        public void onResult(final MessageApi.SendMessageResult sendMessageResult) {
            Log.d(TAG, "Status: " + sendMessageResult.getStatus());
            if (listener != null) {
                listener.onResult(sendMessageResult);
            }
        }
    });

}
 
Example 6
Source File: MainActivity.java    From DronesWear with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
@OnClick(R.id.btn_stop_session)
public void stopSession() {

    PendingResult<SessionStopResult> pendingResult =
            Fitness.SessionsApi.stopSession(mGoogleApiClient, mSession.getIdentifier());

    pendingResult.setResultCallback(new ResultCallback<SessionStopResult>() {
        @Override
        public void onResult(SessionStopResult sessionStopResult) {
            if( sessionStopResult.getStatus().isSuccess() ) {
                Log.i("Tuts+", "Successfully stopped session");
                if( sessionStopResult.getSessions() != null && !sessionStopResult.getSessions().isEmpty() ) {
                    Log.i("Tuts+", "Session name: " + sessionStopResult.getSessions().get(0).getName());
                    Log.i("Tuts+", "Session start: " + sessionStopResult.getSessions().get(0).getStartTime(TimeUnit.MILLISECONDS));
                    Log.i("Tuts+", "Session end: " + sessionStopResult.getSessions().get(0).getEndTime(TimeUnit.MILLISECONDS));
                }
            } else {
                Log.i("Tuts+", "Failed to stop session: " + sessionStopResult.getStatus().getStatusMessage());
            }
        }

    });
}
 
Example 8
Source File: RecipeActivity.java    From search-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onStop(){
    super.onStop();

    if (recipe != null) {
        final Uri APP_URI = BASE_APP_URI.buildUpon().appendPath(recipe.getId()).build();
        PendingResult<Status> result = AppIndex.AppIndexApi.viewEnd(mClient, this, APP_URI);

        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();
    }
}
 
Example 9
Source File: ListenerService.java    From AndroidAPS with GNU Affero General Public License v3.0 6 votes vote down vote up
private void setLocalNodeName() {
    forceGoogleApiConnect();
    PendingResult<NodeApi.GetLocalNodeResult> result = Wearable.NodeApi.getLocalNode(googleApiClient);
    result.setResultCallback(new ResultCallback<NodeApi.GetLocalNodeResult>() {

        @Override
        public void onResult(NodeApi.GetLocalNodeResult getLocalNodeResult) {
            if (!getLocalNodeResult.getStatus().isSuccess()) {
                Log.e(TAG, "ERROR: failed to getLocalNode Status="
                    + getLocalNodeResult.getStatus().getStatusMessage());
            } else {
                Log.d(TAG, "getLocalNode Status=: " + getLocalNodeResult.getStatus().getStatusMessage());
                Node getnode = getLocalNodeResult.getNode();
                localnode = getnode != null ? getnode.getDisplayName() + "|" + getnode.getId() : "";
                Log.d(TAG, "setLocalNodeName.  localnode=" + localnode);
            }
        }
    });
}
 
Example 10
Source File: NearbyBackgroundSubscription.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@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 11
Source File: LocationSwitch.java    From react-native-location-switch with Apache License 2.0 6 votes vote down vote up
public void displayLocationSettingsRequest(final Activity activity) {
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(activity)
            .addApi(LocationServices.API).build();
    googleApiClient.connect();

    LocationRequest locationRequest = LocationRequest.create();
    locationRequest.setPriority(mAccuracy);
    locationRequest.setInterval(mInterval);
    locationRequest.setFastestInterval(mInterval / 2);

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(locationRequest);
    builder.setAlwaysShow(false);

    final PendingResult<LocationSettingsResult> result =
            LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
    result.setResultCallback(new LocationResultCallback(activity));
}
 
Example 12
Source File: AutoCompleteLocation.java    From AutocompleteLocation with Apache License 2.0 5 votes vote down vote up
@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: MainActivity.java    From Android-nRF-BLE-Joiner with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createLocationRequestForResult(){
    mLocationRequestBalancedPowerAccuracy = new LocationRequest();
    final LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
            .addLocationRequest(mLocationRequestBalancedPowerAccuracy)
            .setAlwaysShow(true);
    PendingResult<LocationSettingsResult> result =
            LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());

    result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
        @Override
        public void onResult(LocationSettingsResult locationSettingsResult) {
            Log.v("BLE", locationSettingsResult.getStatus().getStatusMessage());
            LocationSettingsStates states = locationSettingsResult.getLocationSettingsStates();
            if(states.isLocationUsable()) {
                checkForLocationPermissionsAndScan();
                return;
            }

            final Status status = locationSettingsResult.getStatus();
            switch(status.getStatusCode()){
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    mLocationServicesRequestApproved = false;
                    try {
                        status.startResolutionForResult(MainActivity.this, REQUEST_LOCATION_SERVICES);
                    } catch (IntentSender.SendIntentException e) {
                        e.printStackTrace();
                    }
                    break;
                case LocationSettingsStatusCodes.SUCCESS:
                    mLocationServicesRequestApproved = true;
                    checkForLocationPermissionsAndScan();
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                    showPermissionRationaleFragment(R.string.rationale_location_cancel_message, 0);
                    break;
            }
        }
    });
}
 
Example 14
Source File: TimeAttendantFastFragment.java    From iBeacon-Android with Apache License 2.0 5 votes vote down vote up
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 15
Source File: RxLocationBaseOnSubscribe.java    From RxGps with Apache License 2.0 5 votes vote down vote up
protected final <T extends Result> void setupLocationPendingResult(PendingResult<T> pendingResult, ResultCallback<T> resultCallback) {
    if (timeoutTime != null && timeoutUnit != null) {
        pendingResult.setResultCallback(resultCallback, timeoutTime, timeoutUnit);
    } else {
        pendingResult.setResultCallback(resultCallback);
    }
}
 
Example 16
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
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 17
Source File: WearRequestHandler.java    From CrossBow with Apache License 2.0 5 votes vote down vote up
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 18
Source File: GoogleApiMessenger.java    From Sensor-Data-Logger with Apache License 2.0 5 votes vote down vote up
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 19
Source File: WatchFaceCompanionConfigActivity.java    From american-sunsets-watch-face with Apache License 2.0 5 votes vote down vote up
private void updateConfigDataItemAndUiOnStartup() {

        Log.d(TAG, "updateConfigDataItemAndUiOnStartup...");

        PendingResult<DataItemBuffer> results = Wearable.DataApi.getDataItems(mGoogleApiClient);
        results.setResultCallback(new ResultCallback<DataItemBuffer>() {
            @Override
            public void onResult(DataItemBuffer dataItems) {
                if (dataItems.getCount() != 0) {
                    DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItems.get(0));

                    // IMAGE
                    int value = dataMapItem.getDataMap().getInt(SunsetsWatchFaceUtil.KEY_BACKGROUND_COLOR);
                    updateUiForKey(SunsetsWatchFaceUtil.KEY_BACKGROUND_COLOR, value);

                    //BATTERY SAVING MODE
                    int value2 = dataMapItem.getDataMap().getInt(SunsetsWatchFaceUtil.KEY_FLUID_MODE);
                    updateUiForKey(SunsetsWatchFaceUtil.KEY_FLUID_MODE, value2);

                    Log.d(TAG, "aggiorno a startup background...");
                }

                dataItems.release();
            }
        });

    }
 
Example 20
Source File: ShadowsocksApplication.java    From ShadowsocksRR with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    app = this;
    // init toast utils
    ToastUtils.init(getApplicationContext());
    initVariable();

    if (!BuildConfig.DEBUG) {
        java.lang.System.setProperty(LocalLog.LOCAL_LOG_LEVEL_PROPERTY, "ERROR");
    }
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    checkChineseLocale(getResources().getConfiguration());
    TagManager tm = TagManager.getInstance(this);
    PendingResult<ContainerHolder> pending = tm.loadContainerPreferNonDefault("GTM-NT8WS8", R.raw.gtm_default_container);
    ResultCallback<ContainerHolder> callback = new ResultCallback<ContainerHolder>() {
        @Override
        public void onResult(@NonNull ContainerHolder holder) {
            if (!holder.getStatus().isSuccess()) {
                return;
            }
            containerHolder = holder;
            Container container = holder.getContainer();
            container.registerFunctionCallMacroCallback(SIG_FUNC, new Container.FunctionCallMacroCallback() {
                @Override
                public Object getValue(String functionName, Map<String, Object> parameters) {
                    if (SIG_FUNC.equals(functionName)) {
                        return Utils.getSignature(getApplicationContext());
                    } else {
                        return null;
                    }
                }
            });
        }
    };
    pending.setResultCallback(callback, 2, TimeUnit.SECONDS);
    JobManager.create(this).addJobCreator(new DonaldTrump());

    if (settings.getBoolean(Constants.Key.tfo, false) && TcpFastOpen.supported()) {
        mThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                TcpFastOpen.enabled(settings.getBoolean(Constants.Key.tfo, false));
            }
        });
    }
}