org.robovm.apple.foundation.NSObject Java Examples

The following examples show how to use org.robovm.apple.foundation.NSObject. 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: MainMenuViewController.java    From robovm-samples with Apache License 2.0 6 votes vote down vote up
private void publishFeedAction() {
    FacebookHandler.getInstance().publishFeed("RoboVM", "RoboPods Facebook iOS",
            "Hello World! This has been sent by RoboVM!!!", "http://www.robovm.com",
            "http://www.robovm.com/wp-content/uploads/2015/03/RoboVM-logo-wide.png",
            new FacebookHandler.RequestListener() {
                @Override
                public void onSuccess(NSObject result) {
                    UIAlertView alert = new UIAlertView("Success!", "Your message has been posted!", null, "OK");
                    alert.show();
                }

                @Override
                public void onError(String message) {
                    FacebookHandler.getInstance().alertError("Error during feed!", message);
                }

                @Override
                public void onCancel() {}
            });
}
 
Example #2
Source File: ShortcutDetailViewController.java    From robovm-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void prepareForSegue(UIStoryboardSegue segue, NSObject sender) {
    if (shortcutItem == null) {
        throw new RuntimeException("shortcutItem was not set");
    }

    if (segue.getIdentifier().equals("ShortcutDetailUpdated")) {
        // In the updated case, create a shortcut item to represent the
        // final state of the view controller.
        UIApplicationShortcutIconType iconType = getIconTypeForSelectedRow((int) pickerView.getSelectedRow(0));

        UIApplicationShortcutIcon icon = new UIApplicationShortcutIcon(iconType);

        NSDictionary<NSString, ?> info = new NSMutableDictionary<>();
        info.put(ApplicationShortcuts.APPLICATION_SHORTCUT_USER_INFO_ICON_KEY, pickerView.getSelectedRow(0));
        shortcutItem = new UIApplicationShortcutItem(shortcutItem.getType(), titleTextField.getText(),
                subtitleTextField.getText(), icon, info);
    }
}
 
Example #3
Source File: ElementsTableViewController.java    From robovm-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void prepareForSegue(UIStoryboardSegue segue, NSObject sender) {
    if (segue.getIdentifier().equals("showDetail")) {
        NSIndexPath selectedIndexPath = getTableView().getIndexPathForSelectedRow();

        // find the right view controller
        AtomicElement element = dataSource.getAtomicElement(selectedIndexPath);
        AtomicElementViewController viewController = (AtomicElementViewController) segue
                .getDestinationViewController();

        // hide the bottom tabbar when we push this view controller
        viewController.setHidesBottomBarWhenPushed(true);

        // pass the element to this detail view controller
        viewController.setElement(element);
    }
}
 
Example #4
Source File: APAHeroCharacter.java    From robovm-samples with Apache License 2.0 6 votes vote down vote up
private void fireProjectile () {
    APAMultiplayerLayeredCharacterScene scene = getCharacterScene();

    SKSpriteNode projectile = (SKSpriteNode)getProjectile().copy();
    projectile.setPosition(getPosition());
    projectile.setZRotation(getZRotation());

    SKEmitterNode emitter = (SKEmitterNode)getProjectileEmitter().copy();
    emitter.setTargetNode(scene.getChild("world"));
    projectile.addChild(emitter);

    scene.addNode(projectile, APAWorldLayer.Character);

    double rot = getZRotation();

    projectile.runAction(SKAction.moveBy(-Math.sin(rot) * HERO_PROJECTILE_SPEED * HERO_PROJECTILE_LIFETIME, Math.cos(rot)
        * HERO_PROJECTILE_SPEED * HERO_PROJECTILE_LIFETIME, HERO_PROJECTILE_LIFETIME));
    projectile.runAction(SKAction.sequence(new NSArray<SKAction>(SKAction.wait(HERO_PROJECTILE_FADEOUT_TIME), SKAction
        .fadeOut(HERO_PROJECTILE_LIFETIME - HERO_PROJECTILE_FADEOUT_TIME), SKAction.removeFromParent())));
    projectile.runAction(sharedProjectileSoundAction);

    NSMutableDictionary<NSString, NSObject> userData = new NSMutableDictionary<>();
    userData.put(PLAYER_KEY, player);
    projectile.setUserData(userData);
}
 
Example #5
Source File: FriendsViewController.java    From robovm-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void viewWillAppear(boolean animated) {
    super.viewWillAppear(animated);

    FacebookHandler.getInstance().requestFriends(new FacebookHandler.RequestListener() {
        @SuppressWarnings("unchecked")
        @Override
        public void onSuccess(NSObject result) {
            FacebookHandler.log("Friends result: %s", result);

            NSDictionary<NSString, ?> root = (NSDictionary<NSString, ?>) result;
            friends = (NSArray<NSDictionary<NSString, ?>>) root
                    .get(new NSString("data"));
            getTableView().reloadData();
        }

        @Override
        public void onError(String message) {
            FacebookHandler.getInstance().alertError("Error while getting a list of your friends!", message);
        }

        @Override
        public void onCancel() {}
    });
}
 
Example #6
Source File: AtomicElement.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
public AtomicElement(NSDictionary<NSString, NSObject> data) {
    atomicNumber = data.getInt("atomicNumber");
    atomicWeight = data.getString("atomicWeight");
    discoveryYear = data.getString("discoveryYear");
    radioactive = Boolean.valueOf(data.getString("radioactive"));
    name = data.getString("name");
    symbol = data.getString("symbol");
    state = data.getString("state");
    group = data.getInt("group");
    period = data.getInt("period");
    vertPos = data.getInt("vertPos");
    horizPos = data.getInt("horizPos");
}
 
Example #7
Source File: PhotoViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@IBAction
private void startTakingPicturesAtIntervals(NSObject sender) {
    /*
     * Start the timer to take a photo every 1.5 seconds.
     * 
     * CAUTION: for the purpose of this sample, we will continue to take
     * pictures indefinitely. Be aware we will run out of memory quickly.
     * You must decide the proper threshold number of photos allowed to take
     * from the camera. One solution to avoid memory constraints is to save
     * each taken photo to disk rather than keeping all of them in memory.
     * In low memory situations sometimes our "didReceiveMemoryWarning"
     * method will be called in which case we can recover some memory and
     * keep the app running.
     */
    startStopButton.setTitle("Stop");
    startStopButton.setOnClickListener(new UIBarButtonItem.OnClickListener() {
        @Override
        public void onClick(UIBarButtonItem barButtonItem) {
            stopTakingPicturesAtIntervals(startStopButton);
        }
    });

    doneButton.setEnabled(false);
    delayedPhotoButton.setEnabled(false);
    takePictureButton.setEnabled(false);

    cameraTimer = new NSTimer(1.5, this, null, true, true);
    cameraTimer.fire(); // Start taking pictures right away.
}
 
Example #8
Source File: PhotoViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@IBAction
private void stopTakingPicturesAtIntervals(NSObject sender) {
    // Stop and reset the timer.
    cameraTimer.invalidate();
    cameraTimer = null;

    finishAndUpdate();
}
 
Example #9
Source File: QuestionViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
/**
 * We must disambiguate which QuestionViewController should handle the
 * exitToQuizStart: action as there will be several QuestionViewController
 * instances on the navigation stack when the unwind segue is triggered. By
 * default, a UINavigationController (or QuizContainerViewController)
 * searches its viewControllers array in reverse. Without overriding this
 * method, the QuestionViewController directly preceding the results screen
 * would be selected as the destination of the unwind segue.
 */
@Override
public boolean canPerformUnwind(Selector action, UIViewController fromViewController, NSObject sender) {
    // Always check if the view controller implements the unwind action by
    // calling the super's implementation.
    if (super.canPerformUnwind(action, fromViewController, sender)) {
        // The first QuestionViewController in the navigation stack should
        // handle the unwind action.
        return this == ((UINavigationController) getParentViewController()).getViewControllers().get(0);
    }

    return false;
}
 
Example #10
Source File: QuestionViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Overriding this method allows a view controller to block the execution of
 * a triggered segue.
 */
@Override
public boolean shouldPerformSegue(String identifier, NSObject sender) {
    if (identifier.equals("NextQuestion")) {
        return !isLastQuestion;
    }

    return super.shouldPerformSegue(identifier, sender);
}
 
Example #11
Source File: QuestionViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void prepareForSegue(UIStoryboardSegue segue, NSObject sender) {
    if (segue.getIdentifier().equals("NextQuestion")) {
        currentQuiz.answerQuestion(questionIndex, (int)
                getTableView().getIndexPathForSelectedRow().getRow() + 1);
        QuestionViewController nextQuestionVC = (QuestionViewController) segue.getDestinationViewController();
        nextQuestionVC.setQuiz(currentQuiz);
        nextQuestionVC.setQuestionIndex(questionIndex + 1);
    } else if (segue.getIdentifier().equals("ResultScreen")) {
        ResultsViewController resultVC = (ResultsViewController) segue.getDestinationViewController();
        resultVC.setQuiz(currentQuiz);
    }
}
 
Example #12
Source File: MainMenuViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
/**
 * This method will be called when the 'Begin' button is tapped.
 */
@Override
public void prepareForSegue(UIStoryboardSegue segue, NSObject sender) {
    // Create a new Quiz from the questions.xml file in the bundle
    // resources.
    String questionsPath = NSBundle.getMainBundle().findResourcePath("questions", "xml");
    Quiz newQuiz = new Quiz(questionsPath);

    // Set the newQuiz as the currentQuiz of the destination view
    // controller.
    QuestionViewController firstQuestionVC = (QuestionViewController) ((UINavigationController) segue
            .getDestinationViewController())
            .getViewControllers().get(0);
    firstQuestionVC.setQuiz(newQuiz);
}
 
Example #13
Source File: AMAnswerMeSDKImpl.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Registers all custom class (Objective-C classes defined in Java) in the
 * SDK packages with the Objective-C runtime.
 */
@SuppressWarnings("unchecked")
static void registerCustomClasses() {
    String packageName = AMAnswerMeSDKImpl.class.getName().substring(0, AMAnswerMeSDKImpl.class.getName().lastIndexOf('.'));
    for (Class<?> cls : VM.listClasses(NSObject.class, ClassLoader.getSystemClassLoader())) {
        if (cls.getName().startsWith(packageName)) {
            Foundation.log("Registering " + cls.getName() + " with the Objective-C runtime");
            ObjCClass.registerCustomClass((Class<? extends ObjCObject>) cls);
        }
    }
}
 
Example #14
Source File: ShortcutsTableViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void prepareForSegue(UIStoryboardSegue segue, NSObject sender) {
    // Supply the shortcutItem matching the selected row from the data
    // source.
    if (segue.getIdentifier().equals("ShowShortcutDetail")) {
        NSIndexPath indexPath = getTableView().getIndexPathForSelectedRow();
        ShortcutDetailViewController controller = (ShortcutDetailViewController) segue
                .getDestinationViewController();
        if (controller != null) {
            controller.setShortcutItem(dynamicShortcuts.get(indexPath.getRow()));
        }
    }
}
 
Example #15
Source File: ShortcutsTableViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@Override
public boolean shouldPerformSegue(String identifier, NSObject sender) {
    // Block navigating to detail view controller for static shortcuts
    // (which are not editable).
    NSIndexPath selectedIndexPath = getTableView().getIndexPathForSelectedRow();
    if (selectedIndexPath == null) {
        return false;
    }
    return selectedIndexPath.getSection() > 0;
}
 
Example #16
Source File: OneViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void prepareForSegue(UIStoryboardSegue segue, NSObject sender) {
    if (segue.getIdentifier().equals("SubLevelSegue")) {
        SubLevelViewController subLevelViewController = (SubLevelViewController) segue
                .getDestinationViewController();
        UITableViewCell cell = (UITableViewCell) sender;
        subLevelViewController.setTitle(cell.getTextLabel().getText());
    }
}
 
Example #17
Source File: SubLevelViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void prepareForSegue(UIStoryboardSegue segue, NSObject sender) {
    if (segue.getIdentifier().equals("modalSegue")) {
        ModalViewController modalViewController = (ModalViewController) segue.getDestinationViewController();
        modalViewController.setOwningViewController(this);
        UITableViewCell cell = (UITableViewCell) sender;
        currentSelectionTitle = cell.getTextLabel().getText();
    }
}
 
Example #18
Source File: MetalBasic3DView.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
public void display() {
    // Create autorelease pool per frame to avoid possible deadlock
    // situations
    // because there are 3 CAMetalDrawables sitting in an autorelease pool.

    try (NSAutoreleasePool pool = new NSAutoreleasePool()) {
        // handle display changes here
        if (layerSizeDidUpdate) {
            // set the metal layer to the drawable size in case orientation
            // or size changes
            CGSize drawableSize = getBounds().getSize();
            drawableSize.setWidth(drawableSize.getWidth() * this.getContentScaleFactor());
            drawableSize.setHeight(drawableSize.getHeight() * this.getContentScaleFactor());

            metalLayer.setDrawableSize(drawableSize);

            // renderer delegate method so renderer can resize anything if
            // needed
            delegate.reshape(this);

            layerSizeDidUpdate = false;
        }

        // rendering delegate method to ask renderer to draw this frame's
        // content
        delegate.render(this);

        // do not retain current drawable beyond the frame.
        // There should be no strong references to this object outside of
        // this view class
        ((NSObject) currentDrawable).dispose();
        currentDrawable = null;
    }
}
 
Example #19
Source File: IAPStoreProductViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public IAPStoreProductViewController() {
    getNavigationItem().setTitle("Store");

    // Create a store product view controller
    storeProductViewController = new SKStoreProductViewController();
    storeProductViewController.setDelegate(this);

    // Fetch all the products
    String plistPath = NSBundle.getMainBundle().findResourcePath("Products", "plist");
    NSArray<NSDictionary<NSString, NSObject>> temp = (NSArray<NSDictionary<NSString, NSObject>>) NSArray
            .read(new File(
                    plistPath));

    for (NSDictionary<NSString, NSObject> item : temp) {
        // Create an Product object to store its category, title, and
        // identifier properties
        Product product = new Product(item);

        // Keep track of all the products
        myProducts.add(product);
    }

    UITableView tableView = new UITableView(UIScreen.getMainScreen().getBounds(), UITableViewStyle.Grouped);
    tableView.registerReusableCellClass(UITableViewCell.class, "productID");
    setTableView(tableView);
}
 
Example #20
Source File: RootViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Launches the Settings app. The Settings app will automatically navigate
 * to to the settings page for this app.
 * 
 * @param sender
 */
@IBAction
private void openApplicationSettings(NSObject sender) {
    /*
     * UIApplication.getOpenSettingsURLString() is only availiable in iOS 8
     * and above. The following code will crash if run on a prior version of
     * iOS. See the check in viewDidLoad()
     */
    UIApplication.getSharedApplication().openURL(new NSURL(UIApplication.getOpenSettingsURLString()));
}
 
Example #21
Source File: TrackLocationViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void prepareForSegue(UIStoryboardSegue segue, NSObject sender) {
    UINavigationController nv = (UINavigationController) segue.getDestinationViewController();
    setupViewController = (SetupViewController) nv.getViewControllers().first();
    setupViewController.configure(true);
    setupViewController.setDelegate(this);
}
 
Example #22
Source File: GetLocationViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void prepareForSegue(UIStoryboardSegue segue, NSObject sender) {
    UINavigationController nv = (UINavigationController) segue.getDestinationViewController();
    setupViewController = (SetupViewController) nv.getViewControllers().first();
    setupViewController.configure(false);
    setupViewController.setDelegate(this);
}
 
Example #23
Source File: TwoViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void prepareForSegue(UIStoryboardSegue segue, NSObject sender) {
    if (segue.getIdentifier().equals("LandscapeViewSegue")) {
        LandscapeViewController landscapeViewController = (LandscapeViewController) segue
                .getDestinationViewController();
        UITableViewCell cell = (UITableViewCell) sender;
        UIImage image = null;
        if (cell.getTextLabel().getText().equals("Cherry Lake")) {
            image = UIImage.getImage("cherrylake");
        } else if (cell.getTextLabel().getText().equals("Lake Don Pedro")) {
            image = UIImage.getImage("lakedonpedro");
        }
        landscapeViewController.setImage(image);
    }
}
 
Example #24
Source File: PhotoViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@IBAction
private void done(NSObject sender) {
    // Dismiss the camera.
    if (cameraTimer != null && cameraTimer.isValid()) {
        cameraTimer.invalidate();
    }
    finishAndUpdate();
}
 
Example #25
Source File: AAPLAssetGridViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@IBAction
private void handleAddButtonItem(NSObject sender) {
    // Create a random dummy image.
    CGRect rect = Math.random() % 2 == 0 ? new CGRect(0, 0, 400, 300) : new CGRect(0, 0, 300, 400);
    UIGraphics.beginImageContext(rect.getSize(), false, 1.0);
    UIColor.fromHSBA(Math.random() % 100 / 100, 1, 1, 1).setFill();
    UIGraphics.rectFill(rect, CGBlendMode.Normal);
    final UIImage image = UIGraphics.getImageFromCurrentImageContext();
    UIGraphics.endImageContext();

    // Add it to the photo library
    PHPhotoLibrary.getSharedPhotoLibrary().performChanges(new Runnable() {
        @Override
        public void run() {
            PHAssetChangeRequest assetChangeRequest = PHAssetChangeRequest.createImageAssetCreationRequest(image);

            if (assetCollection != null) {
                PHAssetCollectionChangeRequest assetCollectionChangeRequest = new PHAssetCollectionChangeRequest(
                        assetCollection);
                assetCollectionChangeRequest.addAssets(new NSArray<>(assetChangeRequest
                        .getPlaceholderForCreatedAsset()));
            }
        }
    }, new VoidBlock2<Boolean, NSError>() {
        @Override
        public void invoke(Boolean success, NSError error) {
            if (!success) {
                System.err.println("Error creating asset: " + error);
            }
        }
    });
}
 
Example #26
Source File: InitViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void prepareForSegue(UIStoryboardSegue segue, NSObject sender) {
    if ("playGame".equals(segue.getIdentifier())) {
        ((GameViewController) segue.getDestinationViewController()).setDifficulty(desiredDifficulty);
        if (incomingChallenge != null) {
            ((GameViewController) segue.getDestinationViewController()).setIncomingChallenge(incomingChallenge);
            incomingChallenge = null;
        }
    }
}
 
Example #27
Source File: AAPLAssetGridViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void prepareForSegue(UIStoryboardSegue segue, NSObject sender) {
    NSIndexPath indexPath = getCollectionView().getIndexPathForCell((UICollectionViewCell) sender);
    AAPLAssetViewController assetViewController = (AAPLAssetViewController) segue.getDestinationViewController();
    assetViewController.setAsset(assetsFetchResults.get(indexPath.getItem()));
    assetViewController.setAssetCollection(assetCollection);
}
 
Example #28
Source File: AAPLAssetViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@IBAction
private void handleTrashButtonItem(NSObject sender) {
    VoidBlock2<Boolean, NSError> completionHandler = new VoidBlock2<Boolean, NSError>() {
        @Override
        public void invoke(Boolean success, NSError error) {
            if (success) {
                DispatchQueue.getMainQueue().async(new Runnable() {
                    @Override
                    public void run() {
                        getNavigationController().popViewController(true);
                    }
                });
            } else {
                System.err.println("Error: " + error);
            }
        }
    };
    if (assetCollection != null) {
        // Remove asset from album
        PHPhotoLibrary.getSharedPhotoLibrary().performChanges(new Runnable() {
            @Override
            public void run() {
                PHAssetCollectionChangeRequest changeRequest = new PHAssetCollectionChangeRequest(assetCollection);
                changeRequest.removeAssets(new NSArray<PHAsset>(asset));
            }
        }, completionHandler);
    } else {
        // Delete asset from library
        PHPhotoLibrary.getSharedPhotoLibrary().performChanges(new Runnable() {
            @Override
            public void run() {
                PHAssetChangeRequest.deleteAssets(new NSArray<PHAsset>(asset));
            }
        }, completionHandler);
    }
}
 
Example #29
Source File: MapViewController.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void prepareForSegue(UIStoryboardSegue segue, NSObject sender) {
    if (segue.getIdentifier().equals("pushToDetail")) {
        // Get the destination view controller and set the placemark data
        // that it should display.
        PlacemarkViewController viewController = (PlacemarkViewController) segue.getDestinationViewController();
        viewController.setPlacemark(placemark);
    }
}
 
Example #30
Source File: ImageScrollView.java    From robovm-samples with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static CGSize getImageSize(int index) {
    NSDictionary<NSString, NSObject> info = (NSDictionary<NSString, NSObject>) getImageData().get(index);
    float width = Float.valueOf(info.get(new NSString("width")).toString());
    float height = Float.valueOf(info.get(new NSString("height")).toString());
    return new CGSize(width, height);
}