use of com.getcapacitor.PluginCall in project capacitor-plugins by ionic-team.
the class GeolocationPlugin method clearWatch.
/**
* Removes an active geolocation watch.
*
* @param call Plugin call
*/
@SuppressWarnings("MissingPermission")
@PluginMethod
public void clearWatch(PluginCall call) {
String callbackId = call.getString("id");
if (callbackId != null) {
PluginCall removed = watchingCalls.remove(callbackId);
if (removed != null) {
removed.release(bridge);
}
if (watchingCalls.size() == 0) {
implementation.clearLocationUpdates();
}
call.resolve();
} else {
call.reject("Watch call id must be provided");
}
}
use of com.getcapacitor.PluginCall in project capacitor-radar by radarlabs.
the class PermissionsTest method testGetLocationPermissionsStatus.
@Test
public void testGetLocationPermissionsStatus() {
PluginCall pluginCall = mock(PluginCall.class);
Map<String, PermissionState> states = new HashMap<>();
states.put(Manifest.permission.ACCESS_FINE_LOCATION, mGpsLocationPermission);
states.put(Manifest.permission.ACCESS_COARSE_LOCATION, mWifiLocationPermission);
states.put(Manifest.permission.ACCESS_BACKGROUND_LOCATION, mBackgroundLocationPermission);
when(mBridge.getPermissionStates(eq(mPlugin))).thenReturn(states);
mPlugin.getLocationPermissionsStatus(pluginCall);
String expectedStatus;
if (isGranted(mGpsLocationPermission) || isGranted(mWifiLocationPermission)) {
if (isGranted(mBackgroundLocationPermission)) {
expectedStatus = "GRANTED_BACKGROUND";
} else {
expectedStatus = "GRANTED_FOREGROUND";
}
} else if (isDenied(mGpsLocationPermission) || isDenied(mWifiLocationPermission)) {
expectedStatus = "DENIED";
} else {
expectedStatus = "NOT_DETERMINED";
}
ArgumentCaptor<JSObject> captor = ArgumentCaptor.forClass(JSObject.class);
verify(pluginCall).resolve(captor.capture());
JSObject json = captor.getValue();
assertNotNull(json);
String actualStatus = json.getString("status");
assertEquals(expectedStatus, actualStatus);
}
use of com.getcapacitor.PluginCall in project capacitor-radar by radarlabs.
the class RadarPluginTest method initializeSdk.
private void initializeSdk() {
PluginCall initializer = mock(PluginCall.class);
when(initializer.getString(matches("publishableKey"))).thenReturn("prj_test_pk_0000000000000000000000000000000000000000");
mPlugin.initialize(initializer);
}
use of com.getcapacitor.PluginCall in project capacitor-radar by radarlabs.
the class RadarPluginTest method testSetMetadata.
@Test
public void testSetMetadata() {
initializeSdk();
assertNull(Radar.getMetadata());
PluginCall pluginCall = mock(PluginCall.class);
JSObject metadata = new JSObject();
String value = UUID.randomUUID().toString();
metadata.put("test", value);
when(pluginCall.getObject(matches("metadata"))).thenReturn(metadata);
mPlugin.setMetadata(pluginCall);
JSONObject json = Radar.getMetadata();
assertNotNull(json);
assertEquals(value, json.optString("test"));
}
use of com.getcapacitor.PluginCall in project capacitor-google-fit by perfood.
the class GoogleFitPlugin method handleOnActivityResult.
@Override
protected void handleOnActivityResult(int requestCode, int resultCode, Intent data) {
super.handleOnActivityResult(requestCode, resultCode, data);
PluginCall savedCall = getSavedCall();
if (requestCode == GOOGLE_FIT_PERMISSIONS_REQUEST_CODE) {
savedCall.resolve();
} else if (requestCode == RC_SIGN_IN) {
if (!GoogleSignIn.hasPermissions(this.getAccount(), getFitnessSignInOptions())) {
this.requestPermissions();
} else {
savedCall.resolve();
}
}
}
Aggregations