Java Code Examples for org.robovm.objc.block.VoidBlock1#invoke()

The following examples show how to use org.robovm.objc.block.VoidBlock1#invoke() . 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: DesktopImageBridge.java    From CrossMobile with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void requestPhotoAlbum(VoidBlock1<CGImage> resultImg) {
    if (resultImg == null)
        return;
    if (fd == null) {
        fd = new FileDialog((Frame) null, "Please select an image", FileDialog.LOAD);
        fd.setDirectory(System.getProperty("user.home"));
        fd.setFilenameFilter((dir, name) -> {
            name = name.toLowerCase();
            return name.endsWith(".png") ||
                    name.endsWith(".jpg") ||
                    name.endsWith(".jpeg") ||
                    name.endsWith(".bmp");
        });
        fd.setMultipleMode(false);
    }
    fd.setFile("*.jpg;*.jpeg;*.png;*.bmp");
    fd.setVisible(true);
    File[] files = fd.getFiles();
    CGImage cgimage = files != null && files.length > 0 ? cgimage(files[0].getAbsolutePath(), null) : null;
    resultImg.invoke(cgimage);
}
 
Example 2
Source File: UIViewController.java    From CrossMobile with GNU Lesser General Public License v3.0 6 votes vote down vote up
@CMSelector("- (void)transitionFromViewController:(UIViewController *)fromViewController \n" +
        "                    toViewController:(UIViewController *)toViewController \n" +
        "                            duration:(NSTimeInterval)duration \n" +
        "                             options:(UIViewAnimationOptions)options \n" +
        "                          animations:(void (^)(void))animations \n" +
        "                          completion:(void (^)(BOOL finished))completion;")
public void transitionFromViewController(UIViewController fromViewController, UIViewController toViewController, double duration, int options, Runnable animations, VoidBlock1<Boolean> completion) {
    if (fromViewController.pcontroller == null || toViewController.pcontroller == null || !toViewController.pcontroller.equals(fromViewController.pcontroller)) {
        Native.system().error("'Children view controllers " + fromViewController + " and " + toViewController + " must have a common parent view controller when calling transitionFromViewController(...)'", new RuntimeException());
    }
    fromViewController.beginAppearanceTransition(false, duration > 0);
    toViewController.beginAppearanceTransition(true, duration > 0);
    fromViewController.pcontroller.view.addSubview(toViewController.view());
    if (duration == 0) {
        fromViewController.view.removeFromSuperview();
        completion.invoke(true);
    } else
        UIView.animateWithDuration(duration, 0, options, animations::run, input -> {
            if (input) {
                fromViewController.view.removeFromSuperview();
                completion.invoke(input);
                fromViewController.endAppearanceTransition();
                toViewController.endAppearanceTransition();
            }
        });
}
 
Example 3
Source File: FirebaseInitializer.java    From CrossMobile with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void initLaunchOptions(android.content.Intent activity, VoidBlock1<Map<String, Object>> callback) {
    android.os.Bundle extras = activity.getExtras();
    if (extras != null && extras.getString("google.message_id") != null) {
        HashMap<String, Object> remoteNotifications = new HashMap<>();
        for (String key : extras.keySet())
            remoteNotifications.put(key, extras.get(key));
        callback.invoke(remoteNotifications);
    }
}
 
Example 4
Source File: AndroidPermissions.java    From CrossMobile with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void requestPermissions(VoidBlock1<Collection<String>> notGrantedPermissions, String... permissions) {
    Collection<String> reqPermissions = new LinkedHashSet<>();
    if (permissions != null && permissions.length > 0) {
        for (String permission : permissions)
            if (permission != null) {
                permission = permission.trim();
                if (!permission.isEmpty()) {
                    if (ContextCompat.checkSelfPermission(MainActivity.current(), permission) != PackageManager.PERMISSION_GRANTED)
                        reqPermissions.add(permission);
                } else
                    Native.system().error("Requesting an empty Android permission", null);
            } else
                Native.system().error("Requesting a null Android permission", null);
    } else
        Native.system().error("Requested Android permissions are empty", null);
    Collection<String> alreadyAsked = BaseUtils.removeCommon(reqPermissions, alreadyAskedForPermission);
    alreadyAskedForPermission.addAll(reqPermissions);
    if (reqPermissions.isEmpty()) {
        if (notGrantedPermissions != null)
            notGrantedPermissions.invoke(alreadyAsked);
    } else {
        MainActivity.current.getStateListener().request((givenPermissions, grantResults) -> {
            if (givenPermissions == null || grantResults == null || notGrantedPermissions == null)
                return;
            for (int i = 0; i < givenPermissions.length && i < grantResults.length; i++)
                if (grantResults[i] == PackageManager.PERMISSION_GRANTED)
                    reqPermissions.remove(givenPermissions[i]);
            notGrantedPermissions.invoke(reqPermissions);
        }, reqPermissions);
    }
}
 
Example 5
Source File: AndroidImageBridge.java    From CrossMobile with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
    public void requestPhotoAlbum(VoidBlock1<CGImage> result) {
        ActivityResultListener activityResult = new ActivityResultListener() {
            @Override
            public void result(int resultCode, Intent data) {
                CGImage cgimage = null;
                if (resultCode == RESULT_OK && data != null && data.getData() != null) {
                    Uri uri = data.getData();
                    String photoPath = Native.file().getRandomLocation();
                    File photoFile = new File(photoPath);
                    try {
                        Native.file().copyStreamAndClose(MainActivity.current.getContentResolver().openInputStream(uri), new FileOutputStream(photoFile), IMAGE_STREAM_BUFFER_SIZE);
                        cgimage = cgimage(photoPath, null);
                    } catch (IOException ex) {
                        if (photoFile.exists())
                            photoFile.delete();
                    }
                }
                result.invoke(cgimage);
            }
        };

        Intent photoChooserIntent = new Intent();
// Show only images, no videos or anything else
        photoChooserIntent.setType("image/*");
        photoChooserIntent.setAction(Intent.ACTION_GET_CONTENT);
// Always show the chooser (if there are multiple options available)
        // MainActivity.current.startActivityForResult(Intent.createChooser(photoChooserIntent, "Select Picture"), PICK_IMAGE_REQUEST);

        //MainActivity.current.startActivityForResult(takePictureIntent, );
        if (photoChooserIntent.resolveActivity(MainActivity.current.getPackageManager()) != null)
            MainActivity.current.getStateListener().launch(activityResult, photoChooserIntent);
    }
 
Example 6
Source File: UIView.java    From CrossMobile with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void meAndChildren(VoidBlock1<UIView> action, boolean depthFirst) {
    if (!depthFirst)
        action.invoke(this);
    for (UIView child : children)
        child.meAndChildren(action, depthFirst);
    if (depthFirst)
        action.invoke(this);
}
 
Example 7
Source File: UIAlertController.java    From CrossMobile with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Used in order to adds a text field to an alert. Repeated use add more
 * text fields.
 *
 * @param configurationHandler A block use for the configuration of the text
 *                             field before being displayed to the alert.
 */
@CMSelector("- (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *textField))configurationHandler;")
public void addTextFieldWithConfigurationHandler(VoidBlock1<UITextField> configurationHandler) {
    if (style != UIAlertControllerStyle.Alert)
        throw new RuntimeException("You can add a text field only if the preferredStyle property is set to UIAlertControllerStyle.Alert.");
    UITextField tf = new UITextField();
    if (configurationHandler != null)
        configurationHandler.invoke(tf);
    textFields.add(tf);
}
 
Example 8
Source File: ResourceResolver.java    From CrossMobile with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void getResources(String path, VoidBlock1<InputStream> streams) {
    Enumeration<URL> resources;
    try {
        resources = ResourceResolver.class.getClassLoader().getResources(path);
    } catch (IOException e) {
        return;
    }
    while (resources.hasMoreElements()) {
        try (InputStream inputStream = resources.nextElement().openStream()) {
            streams.invoke(inputStream);
        } catch (Exception ignored) {
        }
    }
}
 
Example 9
Source File: AndroidNotificationBridge.java    From CrossMobile with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void getPendingNotificationRequestsWithCompletionHandler(VoidBlock1<List<UNNotificationRequest>> completionHandler) {
    completionHandler.invoke(new ArrayList<>(pendingRequests.keySet()));
}
 
Example 10
Source File: AndroidNotificationBridge.java    From CrossMobile with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void getDeliveredNotificationsWithCompletionHandler(VoidBlock1<List<UNNotification>> completionHandler) {
    completionHandler.invoke(new ArrayList<>());
}
 
Example 11
Source File: UNUserNotificationCenter.java    From CrossMobile with GNU Lesser General Public License v3.0 4 votes vote down vote up
@CMSelector("- (void)getNotificationSettingsWithCompletionHandler:(void (^)(UNNotificationSettings *settings))completionHandler;")
public void getNotificationSettingsWithCompletionHandler(VoidBlock1<UNNotificationSettings> completionHandler) {
    completionHandler.invoke(settings);
}
 
Example 12
Source File: UNUserNotificationCenter.java    From CrossMobile with GNU Lesser General Public License v3.0 4 votes vote down vote up
@CMSelector("- (void)getNotificationCategoriesWithCompletionHandler:(void (^)(NSSet<UNNotificationCategory *> *categories))completionHandler;")
public void getNotificationCategoriesWithCompletionHandler(VoidBlock1<Set<UNNotificationCategory>> completionHandler) {
    Set<UNNotificationCategory> categories = null;
    completionHandler.invoke(categories);
}