org.robovm.objc.block.VoidBlock1 Java Examples
The following examples show how to use
org.robovm.objc.block.VoidBlock1.
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: ViewController.java From CrossMobile with GNU Lesser General Public License v3.0 | 6 votes |
private UIView initControls(double y, String name, VoidBlock1<Integer> callback) { UIStepper stepper = new UIStepper(new CGRect(0, 0, 100, 20)); stepper.setMinimumValue(0); stepper.setMaximumValue(99); stepper.setValue(0); UILabel label = new UILabel(new CGRect(110, 0, 150, 20)); label.setText(name + ": 0"); stepper.addTarget((c, e) -> { int value = (int) Math.round(stepper.value()); label.setText(name + ": " + value); callback.invoke(value); }, UIControlEvents.ValueChanged); UIView bundle = new UIView(new CGRect(20, y, 260, 30)); bundle.addSubview(stepper); bundle.addSubview(label); return bundle; }
Example #2
Source File: PAPWelcomeViewController.java From robovm-samples with Apache License 2.0 | 6 votes |
@Override public void viewDidLoad() { super.viewDidLoad(); FBSDKProfile.Notifications.observeCurrentProfileDidChange(new VoidBlock1<FBSDKProfileChangeNotification>() { @Override public void invoke(FBSDKProfileChangeNotification notification) { if (FBSDKProfile.getCurrentProfile() != null && PAPUser.getCurrentUser() != null) { PAPUser.getCurrentUser().fetchInBackground(new PFGetCallback<PAPUser>() { @Override public void done(PAPUser object, NSError error) { refreshCurrentUser(object, error); } }); } } }); }
Example #3
Source File: DesktopImageBridge.java From CrossMobile with GNU Lesser General Public License v3.0 | 6 votes |
@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 #4
Source File: AndroidImageBridge.java From CrossMobile with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void requestCamera(VoidBlock1<CGImage> filepathResult) { AndroidPermissions.current().requestPermissions(notGranted -> { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (notGranted.isEmpty() && takePictureIntent.resolveActivity(MainActivity.current.getPackageManager()) != null) { // Create output image file String rawPhotoPath = Native.file().getRandomLocation(); File photoFile = new File(rawPhotoPath); Uri photoURI = AndroidFileBridge.getExternalUri(photoFile); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); ActivityResultListener activityResult = new ActivityResultListener() { @Override public void result(int resultCode, Intent data) { CGImage cgimage = resultCode == RESULT_OK ? cgimage(rawPhotoPath, null) : null; if (cgimage == null && photoFile.isFile()) photoFile.delete(); filepathResult.invoke(cgimage); } }; MainActivity.current.getStateListener().launch(activityResult, takePictureIntent); } else filepathResult.invoke(null); }, AndroidPermission.CAMERA); }
Example #5
Source File: GameCenterClient.java From gdx-gamesvcs with Apache License 2.0 | 6 votes |
@Override public boolean deleteGameState(String fileId, final ISaveGameStateResponseListener success) { if (!isSessionActive()) return false; GKLocalPlayer.getLocalPlayer().deleteSavedGames(fileId, new VoidBlock1<NSError>() { @Override public void invoke(NSError error) { if (success == null) return; if (error == null) success.onGameStateSaved(true, null); else success.onGameStateSaved(false, String.valueOf(error.getCode())); } }); return true; }
Example #6
Source File: UIView.java From CrossMobile with GNU Lesser General Public License v3.0 | 6 votes |
/** * Animates changes between views using the specified options. * * @param duration The duration of the animations measured in seconds. * @param delay The delay before the beginning of the animations. * @param UIViewAnimationOptions Options to perform the animations. * @param animations The changes to commit to the views. Not NULL. * @param completion A block object to be executed when the animations ends. * @see crossmobile.ios.uikit.UIViewAnimationOptions */ @CMSelector("+ (void)animateWithDuration:(NSTimeInterval)duration\n" + " delay:(NSTimeInterval)delay\n" + " options:(UIViewAnimationOptions)options\n" + " animations:(void (^)(void))animations\n" + " completion:(void (^)(BOOL finished))completion") public static void animateWithDuration(double duration, double delay, int UIViewAnimationOptions, Runnable animations, VoidBlock1<Boolean> completion) { if (animationsEnabled && animations != null) { synchronized (animationLock) { pendingAnim().setDuration(duration); pendingAnim.setDelay(delay); pendingAnim.setCurve((UIViewAnimationOptions >>> 16) & 0xF); pendingAnim.setTransition((UIViewAnimationOptions >>> 20) & 0x7); pendingAnim.setDelegate(completion); } animations.run(); synchronized (animationLock) { pendingAnim.commit(); pendingAnim = null; } } }
Example #7
Source File: GameCenterClient.java From gdx-gamesvcs with Apache License 2.0 | 6 votes |
@Override public boolean incrementAchievement(String achievementId, int incNum, float completionPercentage) { if (isSessionActive() && achievementId != null) { GKAchievement achievement = new GKAchievement(achievementId); achievement.setPercentComplete(completionPercentage * 100); achievement.setShowsCompletionBanner(true); // Create an array with the achievement NSArray<GKAchievement> achievements = new NSArray<>(achievement); GKAchievement.reportAchievements(achievements, new VoidBlock1<NSError>() { @Override public void invoke (NSError error) { // do nothing } }); return true; } return false; }
Example #8
Source File: UIViewController.java From CrossMobile with GNU Lesser General Public License v3.0 | 6 votes |
@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 #9
Source File: GameCenterClient.java From gdx-gamesvcs with Apache License 2.0 | 6 votes |
@Override public boolean submitToLeaderboard(String leaderboardId, long score, String tag) { if (isSessionActive() && leaderboardId != null) { GKScore scoreReporter = new GKScore(); scoreReporter.setValue(score); scoreReporter.setLeaderboardIdentifier(leaderboardId); NSArray<GKScore> scores = new NSArray<>(scoreReporter); GKScore.reportScores(scores, new VoidBlock1<NSError>() { @Override public void invoke (NSError error) { // ignore errors } }); return true; } return false; }
Example #10
Source File: RootViewController.java From robovm-samples with Apache License 2.0 | 6 votes |
private void startIconDownload(AppRecord appRecord, final NSIndexPath indexPath) { IconDownloader iconDownloader = imageDownloadsInProgress.get(indexPath.getRow()); if (iconDownloader == null) { iconDownloader = new IconDownloader(appRecord, new VoidBlock1<AppRecord>() { @Override public void invoke(AppRecord a) { UITableViewCell cell = getTableView().getCellForRow(indexPath); // Display the newly loaded image cell.getImageView().setImage(a.appIcon); // Remove the IconDownloader from the in progress list. // This will result in it being deallocated. imageDownloadsInProgress.remove(indexPath.getRow()); } }); imageDownloadsInProgress.put(indexPath.getRow(), iconDownloader); iconDownloader.startDownload(); } }
Example #11
Source File: IOSProductsList.java From robovm-samples with Apache License 2.0 | 6 votes |
public IOSProductsList() { // Register for StoreManager's notifications NSNotificationCenter.getDefaultCenter().addObserver(StoreManager.IAPProductRequestNotification, StoreManager.getInstance(), NSOperationQueue.getMainQueue(), new VoidBlock1<NSNotification>() { @Override public void invoke(NSNotification a) { handleProductRequestNotification(a); } }); // The tableview is organized into 2 sections: AVAILABLE PRODUCTS and // INVALID PRODUCT IDS products.add(new MyModel("AVAILABLE PRODUCTS")); products.add(new MyModel("INVALID PRODUCT IDS")); fetchProductInformation(); getTableView().registerReusableCellClass(UITableViewCell.class, "availableProductID"); getTableView().registerReusableCellClass(UITableViewCell.class, "invalidIdentifierID"); }
Example #12
Source File: RootViewController.java From robovm-samples with Apache License 2.0 | 6 votes |
@Override public void viewWillAppear(boolean animated) { super.viewWillAppear(animated); /* * Load our preferences. Preloading the relevant preferences here will * prevent possible diskIO latency from stalling our code in more time * critical areas, such as tableView:cellForRowAtIndexPath:, where the * values associated with these preferences are actually needed. */ onDefaultsChanged(); /* * Begin listening for changes to our preferences when the Settings app * does so, when we are resumed from the backround, this will give us a * chance to update our UI. */ notification = NSUserDefaults.Notifications.observeDidChange(null, new VoidBlock1<NSUserDefaults>() { @Override public void invoke(NSUserDefaults a) { onDefaultsChanged(); } }); }
Example #13
Source File: AAPLAlertControllerViewController.java From robovm-samples with Apache License 2.0 | 6 votes |
/** * Show an alert with an "Okay" button. */ private void showSimpleAlert() { String title = "A Short Title Is Best"; String message = "A message should be a short, complete sentence."; String cancelButtonTitle = "OK"; UIAlertController alertController = new UIAlertController(title, message, UIAlertControllerStyle.Alert); // Create the action. UIAlertAction cancelAction = new UIAlertAction(cancelButtonTitle, UIAlertActionStyle.Cancel, new VoidBlock1<UIAlertAction>() { @Override public void invoke(UIAlertAction a) { System.out.println("The simple alert's cancel action occured."); } }); // Add the action. alertController.addAction(cancelAction); presentViewController(alertController, true, null); }
Example #14
Source File: FacebookHandler.java From robovm-samples with Apache License 2.0 | 5 votes |
private FacebookHandler() { loginManager = new FBSDKLoginManager(); loginManager.setDefaultAudience(FBSDKDefaultAudience.Everyone); FBSDKProfile.enableUpdatesOnAccessTokenChange(true); FBSDKProfile.Notifications.observeCurrentProfileDidChange(new VoidBlock1<FBSDKProfileChangeNotification>() { @Override public void invoke(FBSDKProfileChangeNotification notification) { if (notification != null && notification.getNewProfile() != null) { FBSDKProfile currentProfile = notification.getNewProfile(); // TODO Store the profile and update the profile ui. } } }); }
Example #15
Source File: ActivityStateListener.java From CrossMobile with GNU Lesser General Public License v3.0 | 5 votes |
private <K> boolean onAutoRemovable(Map<K, Integer> registry, Collection<K> autoRemove, int requestCode, VoidBlock1<K> consumer) { Collection<K> activeListeners = new ArrayList<>(); for (K key : registry.keySet()) if (requestCode == registry.get(key)) activeListeners.add(key); for (K listener : activeListeners) { if (autoRemove == ALWAYS_REMOVE || autoRemove.remove(listener)) registry.remove(listener); Native.system().safeRun(() -> consumer.invoke(listener)); } return !activeListeners.isEmpty(); }
Example #16
Source File: AndroidNotificationBridge.java From CrossMobile with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void addNotificationRequest(UNNotificationRequest request, VoidBlock1<NSError> completionHandler) { UNNotificationTrigger trigger = request.trigger(); if (trigger instanceof UNCalendarNotificationTrigger) return; else if (trigger instanceof UNLocationNotificationTrigger) return; else if (trigger instanceof UNTimeIntervalNotificationTrigger) return; }
Example #17
Source File: FirebaseInitializer.java From CrossMobile with GNU Lesser General Public License v3.0 | 5 votes |
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 #18
Source File: AndroidPermissions.java From CrossMobile with GNU Lesser General Public License v3.0 | 5 votes |
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 #19
Source File: AndroidImageBridge.java From CrossMobile with GNU Lesser General Public License v3.0 | 5 votes |
@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 #20
Source File: PAPActivityFeedViewController.java From robovm-samples with Apache License 2.0 | 5 votes |
@Override public void viewDidLoad() { getTableView().setSeparatorStyle(UITableViewCellSeparatorStyle.SingleLine); super.viewDidLoad(); UIView texturedBackgroundView = new UIView(getView().getBounds()); texturedBackgroundView.setBackgroundColor(UIColor.black()); getTableView().setBackgroundView(texturedBackgroundView); getNavigationItem().setTitleView(new UIImageView(UIImage.getImage("LogoNavigationBar"))); // Add Settings button getNavigationItem().setRightBarButtonItem(new PAPSettingsButtonItem(settingsButtonAction)); applicationDidReceiveRemoteNotification = PAPNotificationManager.addObserver( PAPNotification.DID_RECEIVE_REMOTE_NOTIFICATION, new VoidBlock1<NSNotification>() { @Override public void invoke(NSNotification notification) { loadObjects(); } }); blankTimelineView = new UIView(getTableView().getBounds()); UIButton button = new UIButton(UIButtonType.Custom); button.setBackgroundImage(UIImage.getImage("ActivityFeedBlank"), UIControlState.Normal); button.setFrame(new CGRect(24, 113, 271, 140)); button.addOnTouchUpInsideListener(inviteFriendsButtonAction); blankTimelineView.addSubview(button); lastRefresh = PAPCache.getSharedCache().getLastActivityFeedRefresh(); }
Example #21
Source File: NSTimer.java From CrossMobile with GNU Lesser General Public License v3.0 | 5 votes |
@CMConstructor("- (instancetype)initWithFireDate:(NSDate *)date \n" + " interval:(NSTimeInterval)interval \n" + " repeats:(BOOL)repeats \n" + " block:(void (^)(NSTimer *timer))block;") public NSTimer(NSDate date, double interval, boolean repeats, VoidBlock1<NSTimer> block) { this(date, interval, block::invoke, null, repeats); }
Example #22
Source File: UserProfileViewController.java From robovm-samples with Apache License 2.0 | 5 votes |
@Override public void viewDidLoad() { super.viewDidLoad(); FBSDKProfile.Notifications.observeCurrentProfileDidChange(new VoidBlock1<FBSDKProfileChangeNotification>() { @Override public void invoke(FBSDKProfileChangeNotification notification) { if (notification.getNewProfile() != null) { getTableView().reloadData(); } } }); }
Example #23
Source File: ResourceResolver.java From CrossMobile with GNU Lesser General Public License v3.0 | 5 votes |
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 #24
Source File: UIView.java From CrossMobile with GNU Lesser General Public License v3.0 | 5 votes |
/** * Sets the transition to be applied to a parent view during an animation block. * In the animation block, perform all required changes to the child views. * * @param view The view to which the transition will be applied. * @param duration The duration of the animation * @param UIViewAnimationOptions The transition options. Usual values are UIViewAnimationOptions.Transition* values * @param animations The changes to commit to the views. Not NULL. * @param completion A block object to be executed when the animations ends. * @see UIViewAnimationOptions */ @CMSelector("+ (void)transitionWithView:(UIView *)view \n" + " duration:(NSTimeInterval)duration \n" + " options:(UIViewAnimationOptions)options \n" + " animations:(void (^)(void))animations \n" + " completion:(void (^)(BOOL finished))completion;") public static void transitionWithView(UIView view, double duration, int UIViewAnimationOptions, Runnable animations, VoidBlock1<Boolean> completion) { if (animationsEnabled && animations != null) { pendingAnim().setParent(view); animateWithDuration(duration, 0, UIViewAnimationOptions, animations, completion); } }
Example #25
Source File: UIView.java From CrossMobile with GNU Lesser General Public License v3.0 | 5 votes |
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 #26
Source File: UIAlertController.java From CrossMobile with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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 #27
Source File: cmAnimation.java From CrossMobile with GNU Lesser General Public License v3.0 | 4 votes |
void setDelegate(VoidBlock1<Boolean> delegate) { this.delegate = delegate; }
Example #28
Source File: UIApplicationDelegate.java From CrossMobile with GNU Lesser General Public License v3.0 | 4 votes |
@CMSelector("- (void)application:(UIApplication *)application \n" + "didReceiveRemoteNotification:(NSDictionary *)userInfo \n" + "fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler;") default void didReceiveRemoteNotificationFetchCompletionHandler(UIApplication app, Map<String, Object> userinfo, VoidBlock1<Integer> completionHandler) { }
Example #29
Source File: UIAlertAction.java From CrossMobile with GNU Lesser General Public License v3.0 | 4 votes |
private UIAlertAction(String title, int style, VoidBlock1<UIAlertAction> handler) { this.title = title; this.style = style; this.handler = handler; }
Example #30
Source File: Recycler.java From CrossMobile with GNU Lesser General Public License v3.0 | 4 votes |
public Recycler(Block1<C, V> constructor, VoidBlock1<V> cleanup, VoidBlock1<V> resurrect) { this.constructor = constructor; this.cleanup = cleanup; this.resurrect = resurrect; }