Here are the examples of the java api com.getcapacitor.PluginCall.getString() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
91 Examples
18
Source : CapacitorGoogleMaps.java
with MIT License
from hemangsk
with MIT License
from hemangsk
@PluginMethod()
public void setMapStyle(PluginCall call) {
/*
https://mapstyle.withgoogle.com/
*/
final String mapStyle = call.getString("jsonString", "");
getBridge().executeOnMainThread(new Runnable() {
@Override
public void run() {
MapStyleOptions mapStyleOptions = new MapStyleOptions(mapStyle);
googleMap.setMapStyle(mapStyleOptions);
}
});
}
18
Source : Filesystem.java
with MIT License
from DoFabien
with MIT License
from DoFabien
/**
* Reads the directory parameter from the plugin call
* @param call the plugin call
*/
private String getDirectoryParameter(PluginCall call) {
return call.getString("directory");
}
18
Source : AdOptionsTest.java
with MIT License
from capacitor-community
with MIT License
from capacitor-community
@BeforeEach
public void beforeEach() {
reset(pluginCallMock);
// Dummy Returns
when(pluginCallMock.getString(anyString(), anyString())).thenReturn("DEFAULT_RETURN");
}
18
Source : CapacitorFirebaseAuth.java
with MIT License
from baumblatt
with MIT License
from baumblatt
private ProviderHandler getProviderHandler(PluginCall call) {
String providerId = call.getString("providerId", null);
return this.providerHandlers.get(providerId);
}
17
Source : DownloaderPlugin.java
with MIT License
from triniwiz
with MIT License
from triniwiz
@PluginMethod()
public void resume(PluginCall call) {
String id = call.getString("id");
Manager manager = Manager.getInstance();
manager.resume(id);
}
17
Source : DownloaderPlugin.java
with MIT License
from triniwiz
with MIT License
from triniwiz
@PluginMethod()
public void pause(PluginCall call) {
String id = call.getString("id");
Manager manager = Manager.getInstance();
manager.pause(id);
}
17
Source : DownloaderPlugin.java
with MIT License
from triniwiz
with MIT License
from triniwiz
@PluginMethod()
public void cancel(PluginCall call) {
String id = call.getString("id");
Manager manager = Manager.getInstance();
manager.cancel(id);
}
17
Source : CapacitorGoogleMaps.java
with MIT License
from hemangsk
with MIT License
from hemangsk
@PluginMethod()
public void setMapType(PluginCall call) {
String specifiedMapType = call.getString("type", "normal");
Integer mapType;
switch(specifiedMapType) {
case "hybrid":
mapType = GoogleMap.MAP_TYPE_HYBRID;
break;
case "satellite":
mapType = GoogleMap.MAP_TYPE_SATELLITE;
break;
case "terrain":
mapType = GoogleMap.MAP_TYPE_TERRAIN;
break;
case "none":
mapType = GoogleMap.MAP_TYPE_NONE;
break;
default:
mapType = GoogleMap.MAP_TYPE_NORMAL;
}
final Integer selectedMapType = mapType;
getBridge().getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
googleMap.setMapType(selectedMapType);
}
});
call.success();
}
17
Source : Geolocation.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@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) {
locationManager.removeUpdates(locationListener);
}
call.success();
}
17
Source : Filesystem.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@PluginMethod()
public void deleteFile(PluginCall call) {
saveCall(call);
String file = call.getString("path");
String directory = getDirectoryParameter(call);
File fileObject = getFileObject(file, directory);
if (!isPublicDirectory(directory) || isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_DELETE_FILE_PERMISSIONS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
if (!fileObject.exists()) {
call.error("File does not exist");
return;
}
boolean deleted = fileObject.delete();
if (deleted == false) {
call.error("Unable to delete file");
} else {
call.success();
}
}
}
17
Source : Filesystem.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@PluginMethod()
public void mkdir(PluginCall call) {
saveCall(call);
String path = call.getString("path");
String directory = getDirectoryParameter(call);
boolean intermediate = call.getBoolean("createIntermediateDirectories", false).booleanValue();
File fileObject = getFileObject(path, directory);
if (fileObject.exists()) {
call.error("Directory exists");
return;
}
if (!isPublicDirectory(directory) || isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_WRITE_FOLDER_PERMISSIONS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
boolean created = false;
if (intermediate) {
created = fileObject.mkdirs();
} else {
created = fileObject.mkdir();
}
if (created == false) {
call.error("Unable to create directory, unknown reason");
} else {
call.success();
}
}
}
17
Source : Filesystem.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@PluginMethod()
public void rmdir(PluginCall call) {
saveCall(call);
String path = call.getString("path");
String directory = getDirectoryParameter(call);
Boolean recursive = call.getBoolean("recursive", false);
File fileObject = getFileObject(path, directory);
if (!isPublicDirectory(directory) || isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_DELETE_FOLDER_PERMISSIONS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
if (!fileObject.exists()) {
call.error("Directory does not exist");
return;
}
if (fileObject.isDirectory() && fileObject.listFiles().length != 0 && !recursive) {
call.error("Directory is not empty");
return;
}
boolean deleted = false;
try {
deleteRecursively(fileObject);
deleted = true;
} catch (IOException ignored) {
}
if (deleted == false) {
call.error("Unable to delete directory, unknown reason");
} else {
call.success();
}
}
}
17
Source : Filesystem.java
with MIT License
from DoFabien
with MIT License
from DoFabien
private void saveFile(PluginCall call, File file, String data) {
String encoding = call.getString("encoding");
boolean append = call.getBoolean("append", false);
Charset charset = this.getEncoding(encoding);
if (encoding != null && charset == null) {
call.error("Unsupported encoding provided: " + encoding);
return;
}
// if charset is not null replacedume its a plain text file the user wants to save
boolean success = false;
if (charset != null) {
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, append), charset))) {
writer.write(data);
success = true;
} catch (IOException e) {
Log.e(getLogTag(), "Creating text file '" + file.getPath() + "' with charset '" + charset + "' failed. Error: " + e.getMessage(), e);
}
} else {
// remove header from dataURL
if (data.indexOf(",") != -1) {
data = data.split(",")[1];
}
try (FileOutputStream fos = new FileOutputStream(file, append)) {
fos.write(Base64.decode(data, Base64.NO_WRAP));
success = true;
} catch (IOException e) {
Log.e(getLogTag(), "Creating binary file '" + file.getPath() + "' failed. Error: " + e.getMessage(), e);
}
}
if (success) {
// update mediaStore index only if file was written to external storage
if (isPublicDirectory(getDirectoryParameter(call))) {
MediaScannerConnection.scanFile(getContext(), new String[] { file.getAbsolutePath() }, null, null);
}
Log.d(getLogTag(), "File '" + file.getAbsolutePath() + "' saved!");
call.success();
} else {
call.error("FILE_NOTCREATED");
}
}
17
Source : Filesystem.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@PluginMethod()
public void writeFile(PluginCall call) {
saveCall(call);
String path = call.getString("path");
String data = call.getString("data");
if (path == null) {
Log.e(getLogTag(), "No path or filename retrieved from call");
call.error("NO_PATH");
return;
}
if (data == null) {
Log.e(getLogTag(), "No data retrieved from call");
call.error("NO_DATA");
return;
}
String directory = getDirectoryParameter(call);
if (directory != null) {
if (!isPublicDirectory(directory) || isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_WRITE_FILE_PERMISSIONS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
// create directory because it might not exist
File androidDir = getDirectory(directory);
if (androidDir != null) {
if (androidDir.exists() || androidDir.mkdirs()) {
// path might include directories as well
File fileObject = new File(androidDir, path);
if (fileObject.getParentFile().exists() || fileObject.getParentFile().mkdirs()) {
saveFile(call, fileObject, data);
}
} else {
Log.e(getLogTag(), "Not able to create '" + directory + "'!");
call.error("NOT_CREATED_DIR");
}
} else {
Log.e(getLogTag(), "Directory ID '" + directory + "' is not supported by plugin");
call.error("INVALID_DIR");
}
}
} else {
// check if file://
Uri u = Uri.parse(path);
if ("file".equals(u.getScheme())) {
File fileObject = new File(u.getPath());
// do not know where the file is being store so checking the permission to be secure
// TODO to prevent permission checking we need a property from the call
if (isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_WRITE_FILE_PERMISSIONS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
if (fileObject.getParentFile().exists() || fileObject.getParentFile().mkdirs()) {
saveFile(call, fileObject, data);
}
}
}
}
}
17
Source : Filesystem.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@PluginMethod()
public void readFile(PluginCall call) {
saveCall(call);
String file = call.getString("path");
String data = call.getString("data");
String directory = getDirectoryParameter(call);
String encoding = call.getString("encoding");
Charset charset = this.getEncoding(encoding);
if (encoding != null && charset == null) {
call.error("Unsupported encoding provided: " + encoding);
return;
}
if (!isPublicDirectory(directory) || isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_READ_FILE_PERMISSIONS, Manifest.permission.READ_EXTERNAL_STORAGE)) {
try {
InputStream is = getInputStream(file, directory);
String dataStr;
if (charset != null) {
dataStr = readFilereplacedtring(is, charset.name());
} else {
dataStr = readFileAsBase64EncodedData(is);
}
JSObject ret = new JSObject();
ret.putOpt("data", dataStr);
call.success(ret);
} catch (FileNotFoundException ex) {
call.error("File does not exist", ex);
} catch (IOException ex) {
call.error("Unable to read file", ex);
} catch (JSONException ex) {
call.error("Unable to return value for reading file", ex);
}
}
}
16
Source : AdMob.java
with MIT License
from rahadur
with MIT License
from rahadur
// Prepare a RewardVideoAd
@PluginMethod()
public void prepareRewardVideoAd(final PluginCall call) {
this.call = call;
/* dedicated test ad unit ID for Android rewarded video:
ca-app-pub-3940256099942544/5224354917
*/
final String adId = call.getString("adId", "ca-app-pub-3940256099942544/5224354917");
try {
mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(getContext());
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mRewardedVideoAd.loadAd(adId, new AdRequest.Builder().build());
mRewardedVideoAd.setRewardedVideoAdListener(new RewardedVideoAdListener() {
@Override
public void onRewardedVideoAdLoaded() {
call.success(new JSObject().put("value", true));
notifyListeners("onRewardedVideoAdLoaded", new JSObject().put("value", true));
}
@Override
public void onRewardedVideoAdOpened() {
notifyListeners("onRewardedVideoAdOpened", new JSObject().put("value", true));
}
@Override
public void onRewardedVideoStarted() {
notifyListeners("onRewardedVideoStarted", new JSObject().put("value", true));
}
@Override
public void onRewardedVideoAdClosed() {
notifyListeners("onRewardedVideoAdClosed", new JSObject().put("value", true));
}
@Override
public void onRewarded(RewardItem rewardItem) {
notifyListeners("onRewarded", new JSObject().put("value", true));
}
@Override
public void onRewardedVideoAdLeftApplication() {
notifyListeners("onRewardedVideoAdLeftApplication", new JSObject().put("value", true));
}
@Override
public void onRewardedVideoAdFailedToLoad(int i) {
notifyListeners("onRewardedVideoAdFailedToLoad", new JSObject().put("value", true));
}
@Override
public void onRewardedVideoCompleted() {
notifyListeners("onRewardedVideoCompleted", new JSObject().put("value", true));
}
});
}
});
} catch (Exception ex) {
call.error(ex.getLocalizedMessage(), ex);
}
}
16
Source : CapacitorGoogleMaps.java
with MIT License
from hemangsk
with MIT License
from hemangsk
@PluginMethod()
public void addMarker(PluginCall call) {
final Double lareplacedude = call.getDouble("lareplacedude", 0d);
final Double longitude = call.getDouble("longitude", 0d);
final Float opacity = call.getFloat("opacity", 1.0f);
final String replacedle = call.getString("replacedle", "");
final String snippet = call.getString("snippet", "");
final Boolean isFlat = call.getBoolean("isFlat", true);
getBridge().getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
LatLng latLng = new LatLng(lareplacedude, longitude);
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.alpha(opacity);
markerOptions.replacedle(replacedle);
markerOptions.snippet(snippet);
markerOptions.flat(isFlat);
googleMap.addMarker(markerOptions);
}
});
call.resolve();
}
16
Source : WebView.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@PluginMethod()
public void setServerBasePath(PluginCall call) {
String path = call.getString("path");
bridge.setServerBasePath(path);
call.success();
}
16
Source : StatusBar.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@PluginMethod()
public void setStyle(final PluginCall call) {
final String style = call.getString("style");
if (style == null) {
call.error("Style must be provided");
return;
}
getBridge().executeOnMainThread(new Runnable() {
@Override
public void run() {
Window window = getActivity().getWindow();
View decorView = window.getDecorView();
int visibilityFlags = decorView.getSystemUiVisibility();
if (style.equals("DARK")) {
decorView.setSystemUiVisibility(visibilityFlags & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
decorView.setSystemUiVisibility(visibilityFlags | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
call.success();
}
});
}
16
Source : StatusBar.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@PluginMethod()
public void setBackgroundColor(final PluginCall call) {
final String color = call.getString("color");
if (color == null) {
call.error("Color must be provided");
return;
}
getBridge().executeOnMainThread(new Runnable() {
@Override
public void run() {
Window window = getActivity().getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
try {
window.setStatusBarColor(Color.parseColor(color.toUpperCase()));
call.success();
} catch (IllegalArgumentException ex) {
call.error("Invalid color provided. Must be a hex string (ex: #ff0000");
}
}
});
}
16
Source : PushNotifications.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@PluginMethod()
public void deleteChannel(PluginCall call) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
String channelId = call.getString("id");
notificationManager.deleteNotificationChannel(channelId);
call.success();
} else {
call.unavailable();
}
}
16
Source : Permissions.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@PluginMethod
public void query(PluginCall call) {
String name = call.getString("name");
switch(name) {
case "camera":
checkCamera(call);
break;
case "photos":
checkPhotos(call);
break;
case "geolocation":
checkGeo(call);
break;
case "notifications":
checkNotifications(call);
break;
case "clipboard-read":
case "clipboard-write":
checkClipboard(call);
break;
default:
call.reject("Unknown permission type");
}
}
16
Source : Filesystem.java
with MIT License
from DoFabien
with MIT License
from DoFabien
private void _copy(PluginCall call, boolean doRename) {
saveCall(call);
String from = call.getString("from");
String to = call.getString("to");
String directory = call.getString("directory");
String toDirectory = call.getString("toDirectory");
if (toDirectory == null) {
toDirectory = directory;
}
if (from == null || from.isEmpty() || to == null || to.isEmpty()) {
call.error("Both to and from must be provided");
return;
}
File fromObject = getFileObject(from, directory);
File toObject = getFileObject(to, toDirectory);
replacedert fromObject != null;
replacedert toObject != null;
if (toObject.equals(fromObject)) {
call.success();
return;
}
if (!fromObject.exists()) {
call.error("The source object does not exist");
return;
}
if (toObject.getParentFile().isFile()) {
call.error("The parent object of the destination is a file");
return;
}
if (!toObject.getParentFile().exists()) {
call.error("The parent object of the destination does not exist");
return;
}
if (isPublicDirectory(directory) || isPublicDirectory(toDirectory)) {
if (doRename) {
if (!isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_RENAME_PERMISSIONS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
return;
}
} else {
if (!isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_COPY_PERMISSIONS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
return;
}
}
}
if (toObject.isDirectory()) {
call.error("Cannot overwrite a directory");
return;
}
toObject.delete();
replacedert fromObject != null;
boolean modified = false;
if (doRename) {
modified = fromObject.renameTo(toObject);
} else {
try {
copyRecursively(fromObject, toObject);
modified = true;
} catch (IOException ignored) {
}
}
if (!modified) {
call.error("Unable to perform action, unknown reason");
return;
}
call.success();
}
16
Source : Filesystem.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@PluginMethod()
public void getUri(PluginCall call) {
saveCall(call);
String path = call.getString("path");
String directory = getDirectoryParameter(call);
File fileObject = getFileObject(path, directory);
if (!isPublicDirectory(directory) || isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_URI_PERMISSIONS, Manifest.permission.READ_EXTERNAL_STORAGE)) {
JSObject data = new JSObject();
data.put("uri", Uri.fromFile(fileObject).toString());
call.success(data);
}
}
16
Source : Filesystem.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@PluginMethod()
public void readdir(PluginCall call) {
saveCall(call);
String path = call.getString("path");
String directory = getDirectoryParameter(call);
File fileObject = getFileObject(path, directory);
if (!isPublicDirectory(directory) || isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_READ_FOLDER_PERMISSIONS, Manifest.permission.READ_EXTERNAL_STORAGE)) {
if (fileObject != null && fileObject.exists()) {
String[] files = fileObject.list();
JSObject ret = new JSObject();
ret.put("files", JSArray.from(files));
call.success(ret);
} else {
call.error("Directory does not exist");
}
}
}
16
Source : Camera.java
with MIT License
from DoFabien
with MIT License
from DoFabien
public void processCameraImage(PluginCall call, Intent data) {
boolean saveToGallery = call.getBoolean("saveToGallery", CameraSettings.DEFAULT_SAVE_IMAGE_TO_GALLERY);
CameraResultType resultType = getResultType(call.getString("resultType"));
if (imageFileSavePath == null) {
call.error(IMAGE_PROCESS_NO_FILE_ERROR);
return;
}
if (saveToGallery) {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(imageFileSavePath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
getActivity().sendBroadcast(mediaScanIntent);
}
// Load the image as a Bitmap
File f = new File(imageFileSavePath);
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Uri contentUri = Uri.fromFile(f);
Bitmap bitmap = BitmapFactory.decodeFile(imageFileSavePath, bmOptions);
if (bitmap == null) {
call.error("User cancelled photos app");
return;
}
returnResult(call, bitmap, contentUri);
}
16
Source : Camera.java
with MIT License
from DoFabien
with MIT License
from DoFabien
private CameraSettings getSettings(PluginCall call) {
CameraSettings settings = new CameraSettings();
settings.setResultType(getResultType(call.getString("resultType")));
settings.setSaveToGallery(call.getBoolean("saveToGallery", CameraSettings.DEFAULT_SAVE_IMAGE_TO_GALLERY));
settings.setAllowEditing(call.getBoolean("allowEditing", false));
settings.setQuality(call.getInt("quality", CameraSettings.DEFAULT_QUALITY));
settings.setWidth(call.getInt("width", 0));
settings.setHeight(call.getInt("height", 0));
settings.setShouldResize(settings.getWidth() > 0 || settings.getHeight() > 0);
settings.setShouldCorrectOrientation(call.getBoolean("correctOrientation", CameraSettings.DEFAULT_CORRECT_ORIENTATION));
try {
settings.setSource(CameraSource.valueOf(call.getString("source", CameraSource.PROMPT.getSource())));
} catch (IllegalArgumentException ex) {
settings.setSource(CameraSource.PROMPT);
}
return settings;
}
16
Source : CameraPreview.java
with MIT License
from capacitor-community
with MIT License
from capacitor-community
private void startCamera(final PluginCall call) {
String position = call.getString("position");
if (position == null || position.isEmpty() || "rear".equals(position)) {
position = "back";
} else {
position = "front";
}
final Integer x = call.getInt("x", 0);
final Integer y = call.getInt("y", 0);
final Integer width = call.getInt("width", 0);
final Integer height = call.getInt("height", 0);
final Integer paddingBottom = call.getInt("paddingBottom", 0);
final Boolean toBack = call.getBoolean("toBack", false);
final Boolean storeToFile = call.getBoolean("storeToFile", false);
final Boolean disableExifHeaderStripping = call.getBoolean("disableExifHeaderStripping", true);
fragment = new CameraActivity();
fragment.setEventListener(this);
fragment.defaultCamera = position;
fragment.tapToTakePicture = false;
fragment.dragEnabled = false;
fragment.tapToFocus = true;
fragment.disableExifHeaderStripping = disableExifHeaderStripping;
fragment.storeToFile = storeToFile;
fragment.toBack = toBack;
bridge.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
DisplayMetrics metrics = getBridge().getActivity().getResources().getDisplayMetrics();
// offset
int computedX = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, x, metrics);
int computedY = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, y, metrics);
// size
int computedWidth;
int computedHeight;
int computedPaddingBottom;
if (paddingBottom != 0) {
computedPaddingBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, paddingBottom, metrics);
} else {
computedPaddingBottom = 0;
}
if (width != 0) {
computedWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, width, metrics);
} else {
Display defaultDisplay = getBridge().getActivity().getWindowManager().getDefaultDisplay();
final Point size = new Point();
defaultDisplay.getSize(size);
computedWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, size.x, metrics);
}
if (height != 0) {
computedHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, height, metrics) - computedPaddingBottom;
} else {
Display defaultDisplay = getBridge().getActivity().getWindowManager().getDefaultDisplay();
final Point size = new Point();
defaultDisplay.getSize(size);
computedHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, size.y, metrics) - computedPaddingBottom;
}
fragment.setRect(computedX, computedY, computedWidth, computedHeight);
FrameLayout containerView = getBridge().getActivity().findViewById(containerViewId);
if (containerView == null) {
containerView = new FrameLayout(getActivity().getApplicationContext());
containerView.setId(containerViewId);
getBridge().getWebView().setBackgroundColor(Color.TRANSPARENT);
((ViewGroup) getBridge().getWebView().getParent()).addView(containerView);
if (toBack == true) {
getBridge().getWebView().getParent().bringChildToFront(getBridge().getWebView());
}
FragmentManager fragmentManager = getBridge().getActivity().getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(containerView.getId(), fragment);
fragmentTransaction.commit();
call.success();
} else {
call.reject("camera already started");
}
}
});
}
16
Source : BackgroundGeolocation.java
with MIT License
from capacitor-community
with MIT License
from capacitor-community
@PluginMethod()
public void removeWatcher(PluginCall call) {
String callbackId = call.getString("id");
if (callbackId == null) {
call.error("Missing id.");
return;
}
service.removeWatcher(callbackId);
PluginCall savedCall = bridge.getSavedCall(callbackId);
if (savedCall != null) {
savedCall.release(bridge);
}
call.success();
}
15
Source : DownloaderPlugin.java
with MIT License
from triniwiz
with MIT License
from triniwiz
@PluginMethod()
public void getStatus(PluginCall call) {
String id = call.getString("id");
DownloadData data = downloadsData.get(id);
JSObject jsObject = new JSObject();
if (data != null) {
jsObject.put("value", data.getStatus());
}
call.resolve(jsObject);
}
15
Source : DownloaderPlugin.java
with MIT License
from triniwiz
with MIT License
from triniwiz
@PluginMethod()
public void getPath(PluginCall call) {
String id = call.getString("id");
DownloadData data = downloadsData.get(id);
JSObject jsObject = new JSObject();
if (data != null) {
jsObject.put("value", data.getPath());
}
call.resolve(jsObject);
}
15
Source : AdMob.java
with MIT License
from rahadur
with MIT License
from rahadur
// Prepare intersreplacedial Ad
@PluginMethod()
public void prepareIntersreplacedial(final PluginCall call) {
this.call = call;
/* dedicated test ad unit ID for Android intersreplacedials:
ca-app-pub-3940256099942544/1033173712
*/
String adId = call.getString("adId", "ca-app-pub-3940256099942544/1033173712");
try {
mIntersreplacedialAd = new IntersreplacedialAd(getContext());
mIntersreplacedialAd.setAdUnitId(adId);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mIntersreplacedialAd.loadAd(new AdRequest.Builder().build());
mIntersreplacedialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
notifyListeners("onAdLoaded", new JSObject().put("value", true));
call.success(new JSObject().put("value", true));
super.onAdLoaded();
}
@Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
notifyListeners("onAdFailedToLoad", new JSObject().put("errorCode", errorCode));
super.onAdFailedToLoad(errorCode);
}
@Override
public void onAdOpened() {
// Code to be executed when the ad is displayed.
notifyListeners("onAdOpened", new JSObject().put("value", true));
super.onAdOpened();
}
@Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
notifyListeners("onAdLeftApplication", new JSObject().put("value", true));
super.onAdLeftApplication();
}
@Override
public void onAdClosed() {
// Code to be executed when when the intersreplacedial ad is closed.
notifyListeners("onAdClosed", new JSObject().put("value", true));
super.onAdClosed();
}
});
}
});
} catch (Exception ex) {
call.error(ex.getLocalizedMessage(), ex);
}
}
15
Source : SecureStoragePlugin.java
with MIT License
from martinkasa
with MIT License
from martinkasa
@PluginMethod()
public void get(PluginCall call) {
String key = call.getString("key");
try {
call.resolve(this._get(key));
} catch (Exception exception) {
call.reject(exception.getMessage(), exception);
}
}
15
Source : SecureStoragePlugin.java
with MIT License
from martinkasa
with MIT License
from martinkasa
@PluginMethod()
public void set(PluginCall call) {
String key = call.getString("key");
String value = call.getString("value");
try {
call.resolve(this._set(key, value));
} catch (Exception exception) {
call.reject(exception.getMessage(), exception);
}
}
15
Source : SecureStoragePlugin.java
with MIT License
from martinkasa
with MIT License
from martinkasa
@PluginMethod()
public void remove(PluginCall call) {
String key = call.getString("key");
try {
call.resolve(this._remove(key));
} catch (Exception exception) {
call.reject(exception.getMessage(), exception);
}
}
15
Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau
with MIT License
from jepiqueau
@PluginMethod
public void pause(final PluginCall call) {
saveCall(call);
JSObject ret = new JSObject();
ret.put("method", "pause");
String playerId = call.getString("playerId");
if (playerId == null) {
ret.put("result", false);
ret.put("message", "Must provide a PlayerId");
call.success(ret);
return;
}
if (mode.equals("fullscreen") && fsPlayerId.equals(playerId)) {
bridge.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
fsFragment.pause();
JSObject data = new JSObject();
data.put("result", true);
data.put("method", "pause");
data.put("value", true);
call.success(data);
}
});
} else {
ret.put("result", false);
ret.put("message", "player is not defined");
call.success(ret);
}
}
15
Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau
with MIT License
from jepiqueau
@PluginMethod
public void echo(PluginCall call) {
String value = call.getString("value");
JSObject ret = new JSObject();
ret.put("value", value);
call.success(ret);
}
15
Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau
with MIT License
from jepiqueau
@PluginMethod
public void setVolume(final PluginCall call) {
saveCall(call);
JSObject ret = new JSObject();
ret.put("method", "setVolume");
String playerId = call.getString("playerId");
if (playerId == null) {
ret.put("result", false);
ret.put("message", "Must provide a PlayerId");
call.success(ret);
return;
}
String value = call.getString("volume");
if (value == null) {
ret.put("result", false);
ret.put("method", "setVolume");
ret.put("message", "Must provide a volume value");
call.success(ret);
return;
}
final Float volume = Float.valueOf(value.trim());
if (mode.equals("fullscreen") && fsPlayerId.equals(playerId)) {
bridge.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
fsFragment.setVolume(volume);
JSObject ret = new JSObject();
ret.put("result", true);
ret.put("method", "setVolume");
ret.put("value", volume);
call.success(ret);
}
});
} else {
ret.put("result", false);
ret.put("message", "player is not defined");
call.success(ret);
}
}
15
Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau
with MIT License
from jepiqueau
@PluginMethod
public void isPlaying(final PluginCall call) {
saveCall(call);
JSObject ret = new JSObject();
ret.put("method", "isPlaying");
String playerId = call.getString("playerId");
if (playerId == null) {
ret.put("result", false);
ret.put("message", "Must provide a PlayerId");
call.success(ret);
return;
}
if (mode.equals("fullscreen") && fsPlayerId.equals(playerId)) {
bridge.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
boolean playing = fsFragment.isPlaying();
JSObject data = new JSObject();
data.put("result", true);
data.put("method", "isPlaying");
data.put("value", playing);
call.success(data);
}
});
} else {
ret.put("result", false);
ret.put("message", "player is not defined");
call.success(ret);
}
}
15
Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau
with MIT License
from jepiqueau
@PluginMethod
public void play(final PluginCall call) {
saveCall(call);
JSObject ret = new JSObject();
ret.put("method", "play");
String playerId = call.getString("playerId");
if (playerId == null) {
ret.put("result", false);
ret.put("message", "Must provide a PlayerId");
call.success(ret);
return;
}
if (mode.equals("fullscreen") && fsPlayerId.equals(playerId)) {
bridge.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
fsFragment.play();
boolean playing = fsFragment.isPlaying();
JSObject data = new JSObject();
data.put("result", true);
data.put("method", "play");
data.put("value", true);
call.success(data);
}
});
} else {
ret.put("result", false);
ret.put("message", "player is not defined");
call.success(ret);
}
}
15
Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau
with MIT License
from jepiqueau
@PluginMethod
public void getVolume(final PluginCall call) {
saveCall(call);
JSObject ret = new JSObject();
ret.put("method", "getVolume");
String playerId = call.getString("playerId");
if (playerId == null) {
ret.put("result", false);
ret.put("message", "Must provide a PlayerId");
call.success(ret);
return;
}
if (mode.equals("fullscreen") && fsPlayerId.equals(playerId)) {
bridge.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Float volume = fsFragment.getVolume();
JSObject ret = new JSObject();
ret.put("result", true);
ret.put("method", "getVolume");
ret.put("value", volume);
call.success(ret);
}
});
} else {
ret.put("result", false);
ret.put("message", "player is not defined");
call.success(ret);
}
}
15
Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau
with MIT License
from jepiqueau
@PluginMethod
public void getDuration(final PluginCall call) {
saveCall(call);
JSObject ret = new JSObject();
ret.put("method", "getDuration");
String playerId = call.getString("playerId");
if (playerId == null) {
ret.put("result", false);
ret.put("message", "Must provide a PlayerId");
call.success(ret);
return;
}
if (mode.equals("fullscreen") && fsPlayerId.equals(playerId)) {
bridge.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
JSObject ret = new JSObject();
ret.put("method", "getDuration");
int duration = fsFragment.getDuration();
ret.put("result", true);
ret.put("value", duration);
call.success(ret);
}
});
} else {
ret.put("result", false);
ret.put("message", "player is not defined");
call.success(ret);
}
}
15
Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau
with MIT License
from jepiqueau
@PluginMethod
public void getCurrentTime(final PluginCall call) {
saveCall(call);
JSObject ret = new JSObject();
ret.put("method", "getCurrentTime");
String playerId = call.getString("playerId");
if (playerId == null) {
ret.put("result", false);
ret.put("message", "Must provide a PlayerId");
call.success(ret);
return;
}
if (mode.equals("fullscreen") && fsPlayerId.equals(playerId)) {
bridge.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
JSObject ret = new JSObject();
ret.put("method", "getCurrentTime");
int curTime = fsFragment.getCurrentTime();
ret.put("result", true);
ret.put("value", curTime);
call.success(ret);
}
});
} else {
ret.put("result", false);
ret.put("message", "player is not defined");
call.success(ret);
}
}
15
Source : CapacitorVideoPlayer.java
with MIT License
from jepiqueau
with MIT License
from jepiqueau
@PluginMethod
public void getMuted(final PluginCall call) {
saveCall(call);
JSObject ret = new JSObject();
ret.put("method", "getMuted");
String playerId = call.getString("playerId");
if (playerId == null) {
ret.put("result", false);
ret.put("message", "Must provide a PlayerId");
call.success(ret);
return;
}
if (mode.equals("fullscreen") && fsPlayerId.equals(playerId)) {
bridge.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
boolean value = fsFragment.getMuted();
JSObject ret = new JSObject();
ret.put("result", true);
ret.put("method", "getMuted");
ret.put("value", value);
call.success(ret);
}
});
} else {
ret.put("result", false);
ret.put("message", "player is not defined");
call.success(ret);
}
}
15
Source : Toast.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@PluginMethod()
public void show(PluginCall call) {
CharSequence text = call.getString("text");
if (text == null) {
call.error("Must provide text");
return;
}
String durationType = call.getString("durationType", "short");
int duration = android.widget.Toast.LENGTH_SHORT;
if ("long".equals(durationType)) {
duration = android.widget.Toast.LENGTH_LONG;
}
android.widget.Toast toast = android.widget.Toast.makeText(getContext(), text, duration);
toast.show();
call.success();
}
15
Source : Storage.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@PluginMethod()
public void remove(PluginCall call) {
String key = call.getString("key");
if (key == null) {
call.reject("Must provide key");
return;
}
editor.remove(key);
editor.apply();
call.resolve();
}
15
Source : Storage.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@PluginMethod()
public void set(PluginCall call) {
String key = call.getString("key");
if (key == null) {
call.reject("Must provide key");
return;
}
String value = call.getString("value");
editor.putString(key, value);
editor.apply();
call.resolve();
}
15
Source : PushNotifications.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@PluginMethod()
public void createChannel(PluginCall call) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
JSObject channel = new JSObject();
channel.put(CHANNEL_ID, call.getString(CHANNEL_ID));
channel.put(CHANNEL_NAME, call.getString(CHANNEL_NAME));
channel.put(CHANNEL_DESCRIPTION, call.getString(CHANNEL_DESCRIPTION, ""));
channel.put(CHANNEL_VISIBILITY, call.getInt(CHANNEL_VISIBILITY, NotificationCompat.VISIBILITY_PUBLIC));
channel.put(CHANNEL_IMPORTANCE, call.getInt(CHANNEL_IMPORTANCE));
createChannel(channel);
call.success();
} else {
call.unavailable();
}
}
15
Source : Filesystem.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@PluginMethod()
public void stat(PluginCall call) {
saveCall(call);
String path = call.getString("path");
String directory = getDirectoryParameter(call);
File fileObject = getFileObject(path, directory);
if (!isPublicDirectory(directory) || isStoragePermissionGranted(PluginRequestCodes.FILESYSTEM_REQUEST_STAT_PERMISSIONS, Manifest.permission.READ_EXTERNAL_STORAGE)) {
if (!fileObject.exists()) {
call.error("File does not exist");
return;
}
JSObject data = new JSObject();
data.put("type", fileObject.isDirectory() ? "directory" : "file");
data.put("size", fileObject.length());
data.put("ctime", null);
data.put("mtime", fileObject.lastModified());
data.put("uri", Uri.fromFile(fileObject).toString());
call.success(data);
}
}
15
Source : BackgroundTask.java
with MIT License
from DoFabien
with MIT License
from DoFabien
@PluginMethod()
public void finish(PluginCall call) {
String taskId = call.getString("taskId");
if (taskId == null) {
call.error("Must provide taskId");
return;
}
call.success();
}
See More Examples