Search in sources :

Example 1 with PluginCall

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");
    }
}
Also used : PluginCall(com.getcapacitor.PluginCall) PluginMethod(com.getcapacitor.PluginMethod)

Example 2 with PluginCall

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);
}
Also used : PermissionState(com.getcapacitor.PermissionState) HashMap(java.util.HashMap) PluginCall(com.getcapacitor.PluginCall) JSObject(com.getcapacitor.JSObject) Test(org.junit.Test)

Example 3 with PluginCall

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);
}
Also used : PluginCall(com.getcapacitor.PluginCall)

Example 4 with PluginCall

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"));
}
Also used : JSONObject(org.json.JSONObject) PluginCall(com.getcapacitor.PluginCall) JSObject(com.getcapacitor.JSObject) Test(org.junit.Test)

Example 5 with PluginCall

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();
        }
    }
}
Also used : PluginCall(com.getcapacitor.PluginCall)

Aggregations

PluginCall (com.getcapacitor.PluginCall)5 JSObject (com.getcapacitor.JSObject)2 Test (org.junit.Test)2 PermissionState (com.getcapacitor.PermissionState)1 PluginMethod (com.getcapacitor.PluginMethod)1 HashMap (java.util.HashMap)1 JSONObject (org.json.JSONObject)1