Permalink
Browse files

Implement getter for View.center property on Android

  • Loading branch information...
brion committed Sep 9, 2010
1 parent ca24e62 commit f0c7f7d64f0d58ded647db21a9198a1eb105d830
Showing with 28 additions and 0 deletions.
  1. +28 −0 android/titanium/src/org/appcelerator/titanium/proxy/TiViewProxy.java
@@ -47,6 +47,7 @@
private static final int MSG_ANIMATE = MSG_FIRST_ID + 109;
private static final int MSG_TOIMAGE = MSG_FIRST_ID + 110;
private static final int MSG_GETSIZE = MSG_FIRST_ID + 111;
+ private static final int MSG_GETCENTER = MSG_FIRST_ID + 112;
protected static final int MSG_LAST_ID = MSG_FIRST_ID + 999;
@@ -156,6 +157,26 @@ public boolean handleMessage(Message msg)
d.put("height", 0);
}
+ result.setResult(d);
+ return true;
+ }
+ case MSG_GETCENTER : {
+ AsyncResult result = (AsyncResult) msg.obj;
+ TiDict d = null;
+ if (view != null) {
+ View v = view.getNativeView();
+ if (v != null) {
+ d = new TiDict();
+ d.put("x", (double)v.getLeft() + (double)v.getWidth() / 2);
+ d.put("y", (double)v.getTop() + (double)v.getHeight() / 2);
+ }
+ }
+ if (d == null) {
+ d = new TiDict();
+ d.put("x", 0);
+ d.put("y", 0);
+ }
+
result.setResult(d);
return true;
}
@@ -185,6 +206,13 @@ public TiDict getSize() {
return (TiDict) result.getResult();
}
+ public TiDict getCenter() {
+ AsyncResult result = new AsyncResult(getTiContext().getActivity());
+ Message msg = getUIHandler().obtainMessage(MSG_GETCENTER, result);
+ msg.sendToTarget();
+ return (TiDict) result.getResult();
+ }
+
public void clearView() {
if (view != null) {
view.release();

0 comments on commit f0c7f7d

Please sign in to comment.