From d15e231c7ed0723ea0526af2331ba2eaf414214f Mon Sep 17 00:00:00 2001 From: Margaret Leibovic Date: Tue, 6 Mar 2012 11:56:43 -0800 Subject: [PATCH] Bug 704879 - (4.5/6) Refactor message handling code into separate private messages. r=lucasr --- mobile/android/base/FormAssistPopup.java | 42 ++++++++++++++---------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/mobile/android/base/FormAssistPopup.java b/mobile/android/base/FormAssistPopup.java index 688c348a581..01a14ab9cd0 100644 --- a/mobile/android/base/FormAssistPopup.java +++ b/mobile/android/base/FormAssistPopup.java @@ -98,30 +98,38 @@ public class FormAssistPopup extends ListView implements GeckoEventListener { public void handleMessage(String event, JSONObject message) { try { if (event.equals("FormAssist:AutoComplete")) { - final JSONArray suggestions = message.getJSONArray("suggestions"); - final JSONArray rect = message.getJSONArray("rect"); - final double zoom = message.getDouble("zoom"); - GeckoApp.mAppContext.mMainHandler.post(new Runnable() { - public void run() { - // Don't show autocomplete popup when using fullscreen // VKB - InputMethodManager imm = - (InputMethodManager) GeckoApp.mAppContext.getSystemService(Context.INPUT_METHOD_SERVICE); - if (!imm.isFullscreenMode()) - show(suggestions, rect, zoom); - } - }); + handleAutoCompleteMessage(message); } else if (event.equals("FormAssist:Hide")) { - GeckoApp.mAppContext.mMainHandler.post(new Runnable() { - public void run() { - hide(); - } - }); + handleHideMessage(message); } } catch (Exception e) { Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e); } } + private void handleAutoCompleteMessage(JSONObject message) throws JSONException { + final JSONArray suggestions = message.getJSONArray("suggestions"); + final JSONArray rect = message.getJSONArray("rect"); + final double zoom = message.getDouble("zoom"); + GeckoApp.mAppContext.mMainHandler.post(new Runnable() { + public void run() { + // Don't show autocomplete popup when using fullscreen VKB + InputMethodManager imm = + (InputMethodManager) GeckoApp.mAppContext.getSystemService(Context.INPUT_METHOD_SERVICE); + if (!imm.isFullscreenMode()) + show(suggestions, rect, zoom); + } + }); + } + + private void handleHideMessage(JSONObject message) { + GeckoApp.mAppContext.mMainHandler.post(new Runnable() { + public void run() { + hide(); + } + }); + } + public void show(JSONArray suggestions, JSONArray rect, double zoom) { ArrayAdapter adapter = new ArrayAdapter(mContext, R.layout.autocomplete_list_item); for (int i = 0; i < suggestions.length(); i++) {