use of cli.MonoTouch.Foundation.NSObject in project playn by threerings.
the class IOSTouch method toTouchEvents.
private Event.Impl[] toTouchEvents(NSSet touches, UIEvent event) {
final Event.Impl[] events = new Event.Impl[Convert.ToInt32(touches.get_Count())];
touches.Enumerate(new NSSetEnumerator(new NSSetEnumerator.Method() {
public void Invoke(NSObject obj, boolean[] stop) {
UITouch touch = (UITouch) obj;
PointF loc = touch.LocationInView(touch.get_View());
// transform the point based on our current scale
IPoint xloc = graphics.transformTouch(loc.get_X(), loc.get_Y());
// on iOS the memory address of the UITouch object is the unique id
int id = touch.get_Handle().ToInt32();
events[_idx++] = new Event.Impl(new Events.Flags.Impl(), touch.get_Timestamp() * 1000, xloc.x(), xloc.y(), id);
stop[0] = false;
}
private int _idx = 0;
}));
return events;
}
use of cli.MonoTouch.Foundation.NSObject in project playn by threerings.
the class IOSNet method sendRequest.
protected void sendRequest(NSUrlRequest req, final Callback<Response> callback) {
new NSUrlConnection(req, new NSUrlConnectionDelegate() {
private NSMutableData data;
private int rspCode = -1;
private NSDictionary headers;
@Override
public void ReceivedResponse(NSUrlConnection conn, NSUrlResponse rsp) {
// if we are redirected, we may accumulate data as we bounce through requests, so we reset
// our data accumulator each time we receive the response headers
data = new NSMutableData();
// note our most recent response code
if (rsp instanceof NSHttpUrlResponse) {
NSHttpUrlResponse hrsp = (NSHttpUrlResponse) rsp;
rspCode = hrsp.get_StatusCode();
headers = hrsp.get_AllHeaderFields();
}
}
@Override
public void ReceivedData(NSUrlConnection conn, NSData data) {
this.data.AppendData(data);
}
@Override
public void FailedWithError(NSUrlConnection conn, NSError error) {
String errmsg = error.get_LocalizedDescription();
Exception exn = rspCode > 0 ? new HttpException(rspCode, errmsg) : new Exception(errmsg);
platform.notifyFailure(callback, exn);
}
@Override
public void FinishedLoading(NSUrlConnection conn) {
platform.notifySuccess(callback, new ResponseImpl(rspCode) {
@Override
protected Map<String, List<String>> extractHeaders() {
Map<String, List<String>> headerMap = new HashMap<String, List<String>>();
for (NSObject key : headers.get_Keys()) {
// iOS concatenates all repeated headers into a single header separated by commas,
// which is known to be a fucking stupid thing to do, but hey, they're doing it!
headerMap.put(key.ToString(), Collections.singletonList(headers.get_Item(key).ToString()));
}
return headerMap;
}
@Override
public String payloadString() {
return NSString.op_Implicit(NSString.FromData(data, NSStringEncoding.wrap(NSStringEncoding.UTF8)));
}
@Override
public byte[] payload() {
int length = Convert.ToInt32(data.get_Length());
byte[] bytes = new byte[length];
Marshal.Copy(data.get_Bytes(), bytes, 0, length);
return bytes;
}
});
}
}, true);
}
use of cli.MonoTouch.Foundation.NSObject in project playn by threerings.
the class IOSPlatform method willTerminate.
private void willTerminate() {
// let the app know that we're terminating
onExit();
// terminate our lifecycle observers
for (NSObject obs : lifecycleObservers) {
NSNotificationCenter.get_DefaultCenter().RemoveObserver(obs);
}
lifecycleObservers.clear();
// wait for the desired interval and then terminate the GL and AL systems
NSTimer.CreateScheduledTimer(config.timeForTermination, new NSAction(new NSAction.Method() {
@Override
public void Invoke() {
// stop the GL view
gameView.Stop();
// stop and release the AL resources (if audio was ever initialized)
if (audio != null)
audio.terminate();
// clear out the platform in order to make sure the game creation flow can be repeated when
// it is used as a part of a larger application
PlayN.setPlatform(null);
}
}));
}
use of cli.MonoTouch.Foundation.NSObject in project playn by threerings.
the class IOSPointer method toPointerEvent.
private Event.Impl toPointerEvent(NSSet touches, UIEvent event) {
final Event.Impl[] eventw = new Event.Impl[1];
touches.Enumerate(new NSSetEnumerator(new NSSetEnumerator.Method() {
public void Invoke(NSObject obj, boolean[] stop) {
UITouch touch = (UITouch) obj;
int handle = touch.get_Handle().ToInt32();
// if we have an active touch, we only care about that touch
if (_active != 0 && handle != _active) {
stop[0] = false;
} else {
_active = handle;
PointF loc = touch.LocationInView(touch.get_View());
// transform the point based on our current scale
IPoint xloc = graphics.transformTouch(loc.get_X(), loc.get_Y());
eventw[0] = new Event.Impl(new Events.Flags.Impl(), touch.get_Timestamp() * 1000, xloc.x(), xloc.y(), true);
stop[0] = true;
}
}
}));
return eventw[0];
}
Aggregations