Skip to content

Instantly share code, notes, and snippets.

@badlogic
Created January 7, 2015 12:57
Show Gist options
  • Select an option

  • Save badlogic/fad04333d5986b9cf558 to your computer and use it in GitHub Desktop.

Select an option

Save badlogic/fad04333d5986b9cf558 to your computer and use it in GitHub Desktop.
import org.robovm.apple.coregraphics.CGRect;
import org.robovm.apple.coremotion.CMAccelerometerData;
import org.robovm.apple.coremotion.CMMotionManager;
import org.robovm.apple.foundation.NSAutoreleasePool;
import org.robovm.apple.foundation.NSError;
import org.robovm.apple.foundation.NSOperationQueue;
import org.robovm.apple.uikit.UIApplication;
import org.robovm.apple.uikit.UIApplicationDelegateAdapter;
import org.robovm.apple.uikit.UIApplicationLaunchOptions;
import org.robovm.apple.uikit.UIButton;
import org.robovm.apple.uikit.UIButtonType;
import org.robovm.apple.uikit.UIColor;
import org.robovm.apple.uikit.UIControl;
import org.robovm.apple.uikit.UIControlState;
import org.robovm.apple.uikit.UIEvent;
import org.robovm.apple.uikit.UIScreen;
import org.robovm.apple.uikit.UIWindow;
import org.robovm.objc.block.VoidBlock2;
public class IOSDemo extends UIApplicationDelegateAdapter {
private CMMotionManager motionManager;
private VoidBlock2<CMAccelerometerData, NSError> accelVoid;
private UIWindow window = null;
private int clickCount = 0;
@Override
public boolean didFinishLaunching(UIApplication application,
UIApplicationLaunchOptions launchOptions) {
final UIButton button = UIButton.create(UIButtonType.RoundedRect);
button.setFrame(new CGRect(115.0f, 121.0f, 91.0f, 37.0f));
button.setTitle("Click me!", UIControlState.Normal);
button.addOnTouchUpInsideListener(new UIControl.OnTouchUpInsideListener() {
@Override
public void onTouchUpInside(UIControl control, UIEvent event) {
System.out.println("Hello world");
System.err.println("Error");
button.setTitle("Click #" + (++clickCount),
UIControlState.Normal);
}
});
window = new UIWindow(UIScreen.getMainScreen().getBounds());
window.setBackgroundColor(UIColor.lightGray());
window.addSubview(button);
window.makeKeyAndVisible();
motionManager = new CMMotionManager();
motionManager.setAccelerometerUpdateInterval(0.05f);
accelVoid = new VoidBlock2<CMAccelerometerData, NSError>() {
@Override
public void invoke(CMAccelerometerData accelData, NSError error) {
System.out.println(String.format("Got data: %f, %f, %f", accelData.getAcceleration().getX(),
accelData.getAcceleration().getY(),
accelData.getAcceleration().getZ()));
}
};
motionManager.startAccelerometerUpdates(new NSOperationQueue(), accelVoid);
return true;
}
public static void main(String[] args) {
try (NSAutoreleasePool pool = new NSAutoreleasePool()) {
UIApplication.main(args, null, IOSDemo.class);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment