From 33da0d74c0298bd488cd89c3cceb03da562519c5 Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Tue, 10 Jan 2012 10:05:42 -0500 Subject: [PATCH] Bug 716673 - Refactor some code that sends messages to Gecko. r=pcwalton --- mobile/android/base/ui/PanZoomController.java | 54 +++++-------------- 1 file changed, 13 insertions(+), 41 deletions(-) diff --git a/mobile/android/base/ui/PanZoomController.java b/mobile/android/base/ui/PanZoomController.java index 9901d7b0cd61..bb75b658bc4e 100644 --- a/mobile/android/base/ui/PanZoomController.java +++ b/mobile/android/base/ui/PanZoomController.java @@ -1025,8 +1025,7 @@ public class PanZoomController mLastEventTime = detector.getEventTime(); } - @Override - public void onLongPress(MotionEvent motionEvent) { + private void sendPointToGecko(String event, MotionEvent motionEvent) { String json; try { PointF point = new PointF(motionEvent.getX(), motionEvent.getY()); @@ -1035,13 +1034,17 @@ public class PanZoomController return; } json = PointUtils.toJSON(point).toString(); - } catch(Exception ex) { - Log.w(LOGTAG, "Error building return: " + ex); - return; // json would be null + } catch (Exception e) { + Log.e(LOGTAG, "Unable to convert point to JSON for " + event, e); + return; } - GeckoEvent e = new GeckoEvent("Gesture:LongPress", json); - GeckoAppShell.sendEventToGecko(e); + GeckoAppShell.sendEventToGecko(new GeckoEvent(event, json)); + } + + @Override + public void onLongPress(MotionEvent motionEvent) { + sendPointToGecko("Gesture:LongPress", motionEvent); } public boolean getRedrawHint() { @@ -1050,35 +1053,14 @@ public class PanZoomController @Override public boolean onDown(MotionEvent motionEvent) { - String json; - try { - PointF point = new PointF(motionEvent.getX(), motionEvent.getY()); - point = mController.convertViewPointToLayerPoint(point); - json = PointUtils.toJSON(point).toString(); - } catch(Exception ex) { - throw new RuntimeException(ex); - } - - GeckoEvent e = new GeckoEvent("Gesture:ShowPress", json); - GeckoAppShell.sendEventToGecko(e); + sendPointToGecko("Gesture:ShowPress", motionEvent); return false; } @Override public boolean onSingleTapConfirmed(MotionEvent motionEvent) { - String json; - try { - PointF point = new PointF(motionEvent.getX(), motionEvent.getY()); - point = mController.convertViewPointToLayerPoint(point); - json = PointUtils.toJSON(point).toString(); - } catch(Exception ex) { - throw new RuntimeException(ex); - } - GeckoApp.mAppContext.mAutoCompletePopup.hide(); - - GeckoEvent e = new GeckoEvent("Gesture:SingleTap", json); - GeckoAppShell.sendEventToGecko(e); + sendPointToGecko("Gesture:SingleTap", motionEvent); return true; } @@ -1089,17 +1071,7 @@ public class PanZoomController @Override public boolean onDoubleTap(MotionEvent motionEvent) { - String json; - try { - PointF point = new PointF(motionEvent.getX(), motionEvent.getY()); - point = mController.convertViewPointToLayerPoint(point); - json = PointUtils.toJSON(point).toString(); - } catch(Exception ex) { - throw new RuntimeException(ex); - } - - GeckoEvent e = new GeckoEvent("Gesture:DoubleTap", json); - GeckoAppShell.sendEventToGecko(e); + sendPointToGecko("Gesture:DoubleTap", motionEvent); return true; }