Search in sources :

Example 21 with JSObject

use of com.getcapacitor.JSObject in project capacitor-file-picker by robingenz.

the class FilePickerPlugin method createPickFilesResult.

private JSObject createPickFilesResult(@Nullable Intent data, boolean readData) {
    JSObject callResult = new JSObject();
    List<JSObject> filesResultList = new ArrayList<>();
    if (data == null) {
        callResult.put("files", JSArray.from(filesResultList));
        return callResult;
    }
    List<Uri> uris = new ArrayList<>();
    if (data.getClipData() == null) {
        Uri uri = data.getData();
        uris.add(uri);
    } else {
        for (int i = 0; i < data.getClipData().getItemCount(); i++) {
            Uri uri = data.getClipData().getItemAt(i).getUri();
            uris.add(uri);
        }
    }
    for (int i = 0; i < uris.size(); i++) {
        Uri uri = uris.get(i);
        JSObject fileResult = new JSObject();
        fileResult.put("path", implementation.getPathFromUri(uri));
        fileResult.put("name", implementation.getNameFromUri(uri));
        if (readData) {
            fileResult.put("data", implementation.getDataFromUri(uri));
        }
        fileResult.put("mimeType", implementation.getMimeTypeFromUri(uri));
        fileResult.put("size", implementation.getSizeFromUri(uri));
        filesResultList.add(fileResult);
    }
    callResult.put("files", JSArray.from(filesResultList.toArray()));
    return callResult;
}
Also used : ArrayList(java.util.ArrayList) JSObject(com.getcapacitor.JSObject) Uri(android.net.Uri)

Example 22 with JSObject

use of com.getcapacitor.JSObject in project capacitor-firebase by robingenz.

the class AppleAuthProviderHandler method applySignInConfig.

private void applySignInConfig(PluginCall call, OAuthProvider.Builder provider) {
    JSArray customParameters = call.getArray("customParameters");
    if (customParameters != null) {
        try {
            List<Object> customParametersList = customParameters.toList();
            for (int i = 0; i < customParametersList.size(); i++) {
                JSObject customParameter = JSObject.fromJSONObject((JSONObject) customParametersList.get(i));
                String key = customParameter.getString("key");
                String value = customParameter.getString("value");
                if (key == null || value == null) {
                    continue;
                }
                provider.addCustomParameter(key, value);
            }
        } catch (JSONException exception) {
            Log.e(FirebaseAuthenticationPlugin.TAG, "applySignInConfig failed.", exception);
        }
    }
}
Also used : JSArray(com.getcapacitor.JSArray) JSObject(com.getcapacitor.JSObject) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) JSObject(com.getcapacitor.JSObject)

Example 23 with JSObject

use of com.getcapacitor.JSObject in project capacitor-firebase by robingenz.

the class PhoneAuthProviderHandler method createCallbacks.

private PhoneAuthProvider.OnVerificationStateChangedCallbacks createCallbacks(PluginCall call) {
    return new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {

        @Override
        public void onVerificationCompleted(PhoneAuthCredential credential) {
            pluginImplementation.handleSuccessfulSignIn(call, credential, null);
        }

        @Override
        public void onVerificationFailed(FirebaseException exception) {
            pluginImplementation.handleFailedSignIn(call, null, exception);
        }

        @Override
        public void onCodeSent(@NonNull String verificationId, @NonNull PhoneAuthProvider.ForceResendingToken token) {
            JSObject result = FirebaseAuthenticationHelper.createSignInResult(null, null, null);
            result.put("verificationId", verificationId);
            call.resolve(result);
        }
    };
}
Also used : FirebaseException(com.google.firebase.FirebaseException) NonNull(androidx.annotation.NonNull) JSObject(com.getcapacitor.JSObject) PhoneAuthCredential(com.google.firebase.auth.PhoneAuthCredential)

Example 24 with JSObject

use of com.getcapacitor.JSObject in project capacitor-firebase by robingenz.

the class FirebaseAppPlugin method getName.

@PluginMethod
public void getName(PluginCall call) {
    JSObject ret = new JSObject();
    ret.put("name", firebaseAppInstance.getName());
    call.resolve(ret);
}
Also used : JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 25 with JSObject

use of com.getcapacitor.JSObject in project capacitor-firebase by robingenz.

the class FirebaseAuthentication method signInWithCustomToken.

public void signInWithCustomToken(PluginCall call) {
    boolean skipNativeAuth = this.config.getSkipNativeAuth();
    if (skipNativeAuth) {
        call.reject(ERROR_CUSTOM_TOKEN_SKIP_NATIVE_AUTH);
        return;
    }
    String token = call.getString("token", "");
    firebaseAuthInstance.signInWithCustomToken(token).addOnCompleteListener(plugin.getActivity(), new OnCompleteListener<AuthResult>() {

        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if (task.isSuccessful()) {
                Log.d(FirebaseAuthenticationPlugin.TAG, "signInWithCustomToken succeeded.");
                FirebaseUser user = getCurrentUser();
                JSObject signInResult = FirebaseAuthenticationHelper.createSignInResult(user, null, null);
                call.resolve(signInResult);
            } else {
                Log.e(FirebaseAuthenticationPlugin.TAG, "signInWithCustomToken failed.", task.getException());
                call.reject(ERROR_SIGN_IN_FAILED);
            }
        }
    }).addOnFailureListener(plugin.getActivity(), new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception exception) {
            Log.e(FirebaseAuthenticationPlugin.TAG, "signInWithCustomToken failed.", exception);
            call.reject(ERROR_SIGN_IN_FAILED);
        }
    });
}
Also used : OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) Task(com.google.android.gms.tasks.Task) NonNull(androidx.annotation.NonNull) JSObject(com.getcapacitor.JSObject) FirebaseUser(com.google.firebase.auth.FirebaseUser) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Aggregations

JSObject (com.getcapacitor.JSObject)169 PluginMethod (com.getcapacitor.PluginMethod)93 JSONException (org.json.JSONException)28 JSONObject (org.json.JSONObject)20 MyRunnable (com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable)16 JSArray (com.getcapacitor.JSArray)14 Radar (io.radar.sdk.Radar)12 Uri (android.net.Uri)11 Location (android.location.Location)9 JSONArray (org.json.JSONArray)7 ArrayList (java.util.ArrayList)6 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)6 ParseException (java.text.ParseException)5 Intent (android.content.Intent)4 FirebaseUser (com.google.firebase.auth.FirebaseUser)4 Gson (com.google.gson.Gson)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4