2011-12-07 00:44:08 +00:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-12-07 00:44:08 +00:00
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
|
|
|
import org.mozilla.gecko.gfx.FloatSize;
|
2013-03-02 01:05:58 +00:00
|
|
|
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
|
2012-08-03 00:13:40 +00:00
|
|
|
import org.mozilla.gecko.util.GeckoEventListener;
|
2013-03-15 10:52:53 +00:00
|
|
|
import org.mozilla.gecko.util.ThreadUtils;
|
2011-12-07 00:44:08 +00:00
|
|
|
|
2012-07-28 00:53:54 +00:00
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
2011-12-07 00:44:08 +00:00
|
|
|
import android.content.Context;
|
2012-07-28 06:13:34 +00:00
|
|
|
import android.content.res.Resources;
|
2013-05-30 11:53:22 +00:00
|
|
|
import android.graphics.PointF;
|
2011-12-07 00:44:08 +00:00
|
|
|
import android.util.AttributeSet;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.util.Log;
|
2012-03-06 21:56:16 +00:00
|
|
|
import android.util.Pair;
|
|
|
|
import android.view.LayoutInflater;
|
2011-12-07 00:44:08 +00:00
|
|
|
import android.view.View;
|
2012-03-06 21:56:16 +00:00
|
|
|
import android.view.ViewGroup;
|
2011-12-07 00:44:08 +00:00
|
|
|
import android.view.animation.Animation;
|
|
|
|
import android.view.animation.AnimationUtils;
|
2012-03-06 19:56:42 +00:00
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2012-07-28 00:53:54 +00:00
|
|
|
import android.widget.AdapterView;
|
2012-03-21 21:08:04 +00:00
|
|
|
import android.widget.AdapterView.OnItemClickListener;
|
2011-12-07 00:44:08 +00:00
|
|
|
import android.widget.ArrayAdapter;
|
2012-04-18 22:35:36 +00:00
|
|
|
import android.widget.ImageView;
|
2011-12-07 00:44:08 +00:00
|
|
|
import android.widget.ListView;
|
2012-04-18 22:35:36 +00:00
|
|
|
import android.widget.RelativeLayout;
|
2011-12-07 00:44:08 +00:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2012-07-22 07:18:14 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collection;
|
|
|
|
|
2012-03-21 21:08:04 +00:00
|
|
|
public class FormAssistPopup extends RelativeLayout implements GeckoEventListener {
|
2011-12-07 00:44:08 +00:00
|
|
|
private Context mContext;
|
2012-07-22 07:18:14 +00:00
|
|
|
private Animation mAnimation;
|
2011-12-07 00:44:08 +00:00
|
|
|
|
2012-03-21 21:08:04 +00:00
|
|
|
private ListView mAutoCompleteList;
|
|
|
|
private RelativeLayout mValidationMessage;
|
|
|
|
private TextView mValidationMessageText;
|
2012-04-18 22:35:36 +00:00
|
|
|
private ImageView mValidationMessageArrow;
|
|
|
|
private ImageView mValidationMessageArrowInverted;
|
2012-03-21 21:08:04 +00:00
|
|
|
|
2013-06-19 15:35:44 +00:00
|
|
|
private double mX;
|
|
|
|
private double mY;
|
|
|
|
private double mW;
|
|
|
|
private double mH;
|
|
|
|
private boolean mIsAutoComplete = true;
|
|
|
|
|
2012-03-21 21:08:04 +00:00
|
|
|
private static int sAutoCompleteMinWidth = 0;
|
|
|
|
private static int sAutoCompleteRowHeight = 0;
|
|
|
|
private static int sValidationMessageHeight = 0;
|
2012-04-18 22:35:36 +00:00
|
|
|
private static int sValidationTextMarginTop = 0;
|
|
|
|
private static RelativeLayout.LayoutParams sValidationTextLayoutNormal;
|
|
|
|
private static RelativeLayout.LayoutParams sValidationTextLayoutInverted;
|
2011-12-07 00:44:08 +00:00
|
|
|
|
2013-03-02 01:06:00 +00:00
|
|
|
private static final String LOGTAG = "GeckoFormAssistPopup";
|
2012-03-06 19:56:44 +00:00
|
|
|
|
2012-07-22 07:18:14 +00:00
|
|
|
// The blocklist is so short that ArrayList is probably cheaper than HashSet.
|
|
|
|
private static final Collection<String> sInputMethodBlocklist = Arrays.asList(new String[] {
|
|
|
|
InputMethods.METHOD_GOOGLE_JAPANESE_INPUT, // bug 775850
|
|
|
|
InputMethods.METHOD_OPENWNN_PLUS, // bug 768108
|
|
|
|
InputMethods.METHOD_SIMEJI, // bug 768108
|
|
|
|
InputMethods.METHOD_SWYPE, // bug 755909
|
|
|
|
InputMethods.METHOD_SWYPE_BETA, // bug 755909
|
|
|
|
});
|
|
|
|
|
2012-03-06 19:56:41 +00:00
|
|
|
public FormAssistPopup(Context context, AttributeSet attrs) {
|
2011-12-07 00:44:08 +00:00
|
|
|
super(context, attrs);
|
|
|
|
mContext = context;
|
|
|
|
|
|
|
|
mAnimation = AnimationUtils.loadAnimation(context, R.anim.grow_fade_in);
|
|
|
|
mAnimation.setDuration(75);
|
|
|
|
|
|
|
|
setFocusable(false);
|
|
|
|
|
2012-08-03 01:38:45 +00:00
|
|
|
registerEventListener("FormAssist:AutoComplete");
|
|
|
|
registerEventListener("FormAssist:ValidationMessage");
|
|
|
|
registerEventListener("FormAssist:Hide");
|
2012-03-06 19:56:42 +00:00
|
|
|
}
|
|
|
|
|
2012-07-13 14:17:03 +00:00
|
|
|
void destroy() {
|
2012-08-03 01:38:45 +00:00
|
|
|
unregisterEventListener("FormAssist:AutoComplete");
|
|
|
|
unregisterEventListener("FormAssist:ValidationMessage");
|
|
|
|
unregisterEventListener("FormAssist:Hide");
|
2012-07-13 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-03-06 19:56:42 +00:00
|
|
|
public void handleMessage(String event, JSONObject message) {
|
|
|
|
try {
|
|
|
|
if (event.equals("FormAssist:AutoComplete")) {
|
2012-03-06 19:56:43 +00:00
|
|
|
handleAutoCompleteMessage(message);
|
2012-03-06 19:56:44 +00:00
|
|
|
} else if (event.equals("FormAssist:ValidationMessage")) {
|
|
|
|
handleValidationMessage(message);
|
2012-03-06 19:56:43 +00:00
|
|
|
} else if (event.equals("FormAssist:Hide")) {
|
2012-03-06 19:56:43 +00:00
|
|
|
handleHideMessage(message);
|
2012-03-06 19:56:42 +00:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
|
|
|
|
}
|
2011-12-07 00:44:08 +00:00
|
|
|
}
|
|
|
|
|
2012-03-06 19:56:43 +00:00
|
|
|
private void handleAutoCompleteMessage(JSONObject message) throws JSONException {
|
|
|
|
final JSONArray suggestions = message.getJSONArray("suggestions");
|
2013-03-02 01:05:58 +00:00
|
|
|
final JSONObject rect = message.getJSONObject("rect");
|
2013-03-15 10:52:53 +00:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-03-06 19:56:43 +00:00
|
|
|
public void run() {
|
2013-03-02 01:05:58 +00:00
|
|
|
showAutoCompleteSuggestions(suggestions, rect);
|
2012-03-06 19:56:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-03-06 19:56:44 +00:00
|
|
|
private void handleValidationMessage(JSONObject message) throws JSONException {
|
|
|
|
final String validationMessage = message.getString("validationMessage");
|
2013-03-02 01:05:58 +00:00
|
|
|
final JSONObject rect = message.getJSONObject("rect");
|
2013-03-15 10:52:53 +00:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-03-06 19:56:44 +00:00
|
|
|
public void run() {
|
2013-03-02 01:05:58 +00:00
|
|
|
showValidationMessage(validationMessage, rect);
|
2012-03-06 19:56:44 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-03-15 10:52:53 +00:00
|
|
|
|
2012-03-06 19:56:43 +00:00
|
|
|
private void handleHideMessage(JSONObject message) {
|
2013-03-15 10:52:53 +00:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-03-06 19:56:43 +00:00
|
|
|
public void run() {
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-03-02 01:05:58 +00:00
|
|
|
private void showAutoCompleteSuggestions(JSONArray suggestions, JSONObject rect) {
|
2012-03-21 21:08:04 +00:00
|
|
|
if (mAutoCompleteList == null) {
|
|
|
|
LayoutInflater inflater = LayoutInflater.from(mContext);
|
|
|
|
mAutoCompleteList = (ListView) inflater.inflate(R.layout.autocomplete_list, null);
|
|
|
|
|
|
|
|
mAutoCompleteList.setOnItemClickListener(new OnItemClickListener() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-03-21 21:08:04 +00:00
|
|
|
public void onItemClick(AdapterView<?> parentView, View view, int position, long id) {
|
|
|
|
// Use the value stored with the autocomplete view, not the label text,
|
|
|
|
// since they can be different.
|
|
|
|
TextView textView = (TextView) view;
|
|
|
|
String value = (String) textView.getTag();
|
2012-07-19 18:00:07 +00:00
|
|
|
broadcastGeckoEvent("FormAssist:AutoComplete", value);
|
2012-03-21 21:08:04 +00:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
addView(mAutoCompleteList);
|
|
|
|
}
|
|
|
|
|
2012-03-06 21:56:16 +00:00
|
|
|
AutoCompleteListAdapter adapter = new AutoCompleteListAdapter(mContext, R.layout.autocomplete_list_item);
|
|
|
|
adapter.populateSuggestionsList(suggestions);
|
2012-03-21 21:08:04 +00:00
|
|
|
mAutoCompleteList.setAdapter(adapter);
|
2012-03-06 19:56:44 +00:00
|
|
|
|
2013-06-19 15:35:44 +00:00
|
|
|
if (setGeckoPositionData(rect, true)) {
|
|
|
|
positionAndShowPopup();
|
|
|
|
}
|
2012-03-06 19:56:44 +00:00
|
|
|
}
|
2011-12-07 00:44:08 +00:00
|
|
|
|
2013-03-02 01:05:58 +00:00
|
|
|
private void showValidationMessage(String validationMessage, JSONObject rect) {
|
2012-03-21 21:08:04 +00:00
|
|
|
if (mValidationMessage == null) {
|
|
|
|
LayoutInflater inflater = LayoutInflater.from(mContext);
|
|
|
|
mValidationMessage = (RelativeLayout) inflater.inflate(R.layout.validation_message, null);
|
|
|
|
|
|
|
|
addView(mValidationMessage);
|
|
|
|
mValidationMessageText = (TextView) mValidationMessage.findViewById(R.id.validation_message_text);
|
2012-04-18 22:35:36 +00:00
|
|
|
|
2012-07-28 06:13:34 +00:00
|
|
|
sValidationTextMarginTop = (int) (mContext.getResources().getDimension(R.dimen.validation_message_margin_top));
|
2012-04-18 22:35:36 +00:00
|
|
|
|
|
|
|
sValidationTextLayoutNormal = new RelativeLayout.LayoutParams(mValidationMessageText.getLayoutParams());
|
|
|
|
sValidationTextLayoutNormal.setMargins(0, sValidationTextMarginTop, 0, 0);
|
|
|
|
|
|
|
|
sValidationTextLayoutInverted = new RelativeLayout.LayoutParams(sValidationTextLayoutNormal);
|
|
|
|
sValidationTextLayoutInverted.setMargins(0, 0, 0, 0);
|
|
|
|
|
|
|
|
mValidationMessageArrow = (ImageView) mValidationMessage.findViewById(R.id.validation_message_arrow);
|
|
|
|
mValidationMessageArrowInverted = (ImageView) mValidationMessage.findViewById(R.id.validation_message_arrow_inverted);
|
2012-03-21 21:08:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mValidationMessageText.setText(validationMessage);
|
|
|
|
|
|
|
|
// We need to set the text as selected for the marquee text to work.
|
|
|
|
mValidationMessageText.setSelected(true);
|
2011-12-07 00:44:08 +00:00
|
|
|
|
2013-06-19 15:35:44 +00:00
|
|
|
if (setGeckoPositionData(rect, false)) {
|
|
|
|
positionAndShowPopup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean setGeckoPositionData(JSONObject rect, boolean isAutoComplete) {
|
|
|
|
try {
|
|
|
|
mX = rect.getDouble("x");
|
|
|
|
mY = rect.getDouble("y");
|
|
|
|
mW = rect.getDouble("w");
|
|
|
|
mH = rect.getDouble("h");
|
|
|
|
} catch (JSONException e) {
|
|
|
|
// Bail if we can't get the correct dimensions for the popup.
|
|
|
|
Log.e(LOGTAG, "Error getting FormAssistPopup dimensions", e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mIsAutoComplete = isAutoComplete;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void positionAndShowPopup() {
|
|
|
|
positionAndShowPopup(GeckoAppShell.getLayerView().getViewportMetrics());
|
2012-03-06 19:56:44 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 15:35:44 +00:00
|
|
|
private void positionAndShowPopup(ImmutableViewportMetrics aMetrics) {
|
|
|
|
ThreadUtils.assertOnUiThread();
|
|
|
|
|
2012-03-06 19:56:44 +00:00
|
|
|
// Don't show the form assist popup when using fullscreen VKB
|
|
|
|
InputMethodManager imm =
|
2013-05-24 16:21:01 +00:00
|
|
|
(InputMethodManager) GeckoAppShell.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
2012-03-06 19:56:44 +00:00
|
|
|
if (imm.isFullscreenMode())
|
2013-03-02 01:06:00 +00:00
|
|
|
return;
|
2011-12-07 00:44:08 +00:00
|
|
|
|
2012-03-21 21:08:04 +00:00
|
|
|
// Hide/show the appropriate popup contents
|
|
|
|
if (mAutoCompleteList != null)
|
2013-06-19 15:35:44 +00:00
|
|
|
mAutoCompleteList.setVisibility(mIsAutoComplete ? VISIBLE : GONE);
|
2012-03-21 21:08:04 +00:00
|
|
|
if (mValidationMessage != null)
|
2013-06-19 15:35:44 +00:00
|
|
|
mValidationMessage.setVisibility(mIsAutoComplete ? GONE : VISIBLE);
|
2012-03-21 21:08:04 +00:00
|
|
|
|
|
|
|
if (sAutoCompleteMinWidth == 0) {
|
2012-07-28 06:13:34 +00:00
|
|
|
Resources res = mContext.getResources();
|
|
|
|
sAutoCompleteMinWidth = (int) (res.getDimension(R.dimen.autocomplete_min_width));
|
|
|
|
sAutoCompleteRowHeight = (int) (res.getDimension(R.dimen.autocomplete_row_height));
|
|
|
|
sValidationMessageHeight = (int) (res.getDimension(R.dimen.validation_message_height));
|
2012-03-21 21:08:04 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 15:35:44 +00:00
|
|
|
float zoom = aMetrics.zoomFactor;
|
|
|
|
PointF offset = aMetrics.getMarginOffset();
|
2013-03-02 01:05:58 +00:00
|
|
|
|
2012-03-21 21:08:04 +00:00
|
|
|
// These values correspond to the input box for which we want to
|
|
|
|
// display the FormAssistPopup.
|
2013-06-19 15:35:44 +00:00
|
|
|
int left = (int) (mX * zoom - aMetrics.viewportRectLeft + offset.x);
|
|
|
|
int top = (int) (mY * zoom - aMetrics.viewportRectTop + offset.y);
|
|
|
|
int width = (int) (mW * zoom);
|
|
|
|
int height = (int) (mH * zoom);
|
2011-12-07 00:44:08 +00:00
|
|
|
|
2012-03-21 21:08:00 +00:00
|
|
|
int popupWidth = RelativeLayout.LayoutParams.FILL_PARENT;
|
2012-03-21 21:07:57 +00:00
|
|
|
int popupLeft = left < 0 ? 0 : left;
|
2011-12-07 00:44:08 +00:00
|
|
|
|
2013-06-19 15:35:44 +00:00
|
|
|
FloatSize viewport = aMetrics.getSize();
|
2011-12-07 00:44:08 +00:00
|
|
|
|
2012-03-21 21:08:04 +00:00
|
|
|
// For autocomplete suggestions, if the input is smaller than the screen-width,
|
|
|
|
// shrink the popup's width. Otherwise, keep it as FILL_PARENT.
|
2013-06-19 15:35:44 +00:00
|
|
|
if (mIsAutoComplete && (left + width) < viewport.width) {
|
2012-03-21 21:07:57 +00:00
|
|
|
popupWidth = left < 0 ? left + width : width;
|
2012-01-27 20:10:45 +00:00
|
|
|
|
2012-03-21 21:08:04 +00:00
|
|
|
// Ensure the popup has a minimum width.
|
|
|
|
if (popupWidth < sAutoCompleteMinWidth) {
|
|
|
|
popupWidth = sAutoCompleteMinWidth;
|
2012-01-27 20:10:45 +00:00
|
|
|
|
2012-03-21 21:08:04 +00:00
|
|
|
// Move the popup to the left if there isn't enough room for it.
|
|
|
|
if ((popupLeft + popupWidth) > viewport.width)
|
|
|
|
popupLeft = (int) (viewport.width - popupWidth);
|
|
|
|
}
|
2012-01-27 20:10:45 +00:00
|
|
|
}
|
2011-12-07 00:44:08 +00:00
|
|
|
|
2012-03-21 21:08:04 +00:00
|
|
|
int popupHeight;
|
2013-06-19 15:35:44 +00:00
|
|
|
if (mIsAutoComplete)
|
2012-03-21 21:08:04 +00:00
|
|
|
popupHeight = sAutoCompleteRowHeight * mAutoCompleteList.getAdapter().getCount();
|
|
|
|
else
|
|
|
|
popupHeight = sValidationMessageHeight;
|
|
|
|
|
2012-03-21 21:08:00 +00:00
|
|
|
int popupTop = top + height;
|
2012-02-03 22:10:49 +00:00
|
|
|
|
2013-06-19 15:35:44 +00:00
|
|
|
if (!mIsAutoComplete) {
|
2012-04-18 22:35:36 +00:00
|
|
|
mValidationMessageText.setLayoutParams(sValidationTextLayoutNormal);
|
|
|
|
mValidationMessageArrow.setVisibility(VISIBLE);
|
|
|
|
mValidationMessageArrowInverted.setVisibility(GONE);
|
|
|
|
}
|
|
|
|
|
2012-03-21 21:08:04 +00:00
|
|
|
// If the popup doesn't fit below the input box, shrink its height, or
|
|
|
|
// see if we can place it above the input instead.
|
2012-03-21 21:07:57 +00:00
|
|
|
if ((popupTop + popupHeight) > viewport.height) {
|
2012-03-21 21:08:04 +00:00
|
|
|
// Find where the maximum space is, and put the popup there.
|
2012-03-21 21:07:57 +00:00
|
|
|
if ((viewport.height - popupTop) > top) {
|
2012-03-21 21:08:04 +00:00
|
|
|
// Shrink the height to fit it below the input box.
|
2012-03-21 21:07:57 +00:00
|
|
|
popupHeight = (int) (viewport.height - popupTop);
|
2012-02-03 22:10:49 +00:00
|
|
|
} else {
|
2012-03-21 21:07:57 +00:00
|
|
|
if (popupHeight < top) {
|
2012-03-21 21:08:04 +00:00
|
|
|
// No shrinking needed to fit on top.
|
2012-03-21 21:07:57 +00:00
|
|
|
popupTop = (top - popupHeight);
|
2012-02-03 22:10:49 +00:00
|
|
|
} else {
|
2012-03-21 21:08:04 +00:00
|
|
|
// Shrink to available space on top.
|
2012-03-21 21:07:57 +00:00
|
|
|
popupTop = 0;
|
|
|
|
popupHeight = top;
|
2012-02-03 22:10:49 +00:00
|
|
|
}
|
2012-04-18 22:35:36 +00:00
|
|
|
|
2013-06-19 15:35:44 +00:00
|
|
|
if (!mIsAutoComplete) {
|
2012-04-18 22:35:36 +00:00
|
|
|
mValidationMessageText.setLayoutParams(sValidationTextLayoutInverted);
|
|
|
|
mValidationMessageArrow.setVisibility(GONE);
|
|
|
|
mValidationMessageArrowInverted.setVisibility(VISIBLE);
|
|
|
|
}
|
2012-02-03 22:10:49 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-07 00:44:08 +00:00
|
|
|
|
2012-03-21 21:08:00 +00:00
|
|
|
RelativeLayout.LayoutParams layoutParams =
|
|
|
|
new RelativeLayout.LayoutParams(popupWidth, popupHeight);
|
|
|
|
layoutParams.setMargins(popupLeft, popupTop, 0, 0);
|
|
|
|
setLayoutParams(layoutParams);
|
2011-12-07 00:44:08 +00:00
|
|
|
requestLayout();
|
2012-03-06 19:56:44 +00:00
|
|
|
|
2013-03-02 01:06:00 +00:00
|
|
|
if (!isShown()) {
|
|
|
|
setVisibility(VISIBLE);
|
|
|
|
startAnimation(mAnimation);
|
|
|
|
}
|
2011-12-07 00:44:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void hide() {
|
|
|
|
if (isShown()) {
|
2012-03-21 21:08:04 +00:00
|
|
|
setVisibility(GONE);
|
2012-07-19 18:00:07 +00:00
|
|
|
broadcastGeckoEvent("FormAssist:Hidden", null);
|
2011-12-07 00:44:08 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-06 21:56:16 +00:00
|
|
|
|
2012-07-22 07:18:14 +00:00
|
|
|
void onInputMethodChanged(String newInputMethod) {
|
|
|
|
boolean blocklisted = sInputMethodBlocklist.contains(newInputMethod);
|
|
|
|
broadcastGeckoEvent("FormAssist:Blocklisted", String.valueOf(blocklisted));
|
2012-07-19 18:00:07 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 15:35:44 +00:00
|
|
|
void onMetricsChanged(final ImmutableViewportMetrics aMetrics) {
|
|
|
|
if (!isShown()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
positionAndShowPopup(aMetrics);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-07-19 18:00:07 +00:00
|
|
|
private static void broadcastGeckoEvent(String eventName, String eventData) {
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent(eventName, eventData));
|
|
|
|
}
|
|
|
|
|
2012-03-06 21:56:16 +00:00
|
|
|
private class AutoCompleteListAdapter extends ArrayAdapter<Pair<String, String>> {
|
|
|
|
private LayoutInflater mInflater;
|
|
|
|
private int mTextViewResourceId;
|
|
|
|
|
|
|
|
public AutoCompleteListAdapter(Context context, int textViewResourceId) {
|
|
|
|
super(context, textViewResourceId);
|
|
|
|
|
|
|
|
mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
mTextViewResourceId = textViewResourceId;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This method takes an array of autocomplete suggestions with label/value properties
|
|
|
|
// and adds label/value Pair objects to the array that backs the adapter.
|
|
|
|
public void populateSuggestionsList(JSONArray suggestions) {
|
|
|
|
try {
|
|
|
|
for (int i = 0; i < suggestions.length(); i++) {
|
2012-03-20 17:52:19 +00:00
|
|
|
JSONObject suggestion = suggestions.getJSONObject(i);
|
2012-03-06 21:56:16 +00:00
|
|
|
String label = suggestion.getString("label");
|
|
|
|
String value = suggestion.getString("value");
|
|
|
|
add(new Pair<String, String>(label, value));
|
|
|
|
}
|
|
|
|
} catch (JSONException e) {
|
2012-07-23 19:04:28 +00:00
|
|
|
Log.e(LOGTAG, "JSONException", e);
|
2012-03-06 21:56:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
|
if (convertView == null)
|
|
|
|
convertView = mInflater.inflate(mTextViewResourceId, null);
|
|
|
|
|
|
|
|
Pair<String, String> item = getItem(position);
|
|
|
|
TextView itemView = (TextView) convertView;
|
|
|
|
|
|
|
|
// Set the text with the suggestion label
|
|
|
|
itemView.setText(item.first);
|
|
|
|
|
|
|
|
// Set a tag with the suggestion value
|
|
|
|
itemView.setTag(item.second);
|
|
|
|
|
|
|
|
return convertView;
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 01:38:45 +00:00
|
|
|
|
|
|
|
private void registerEventListener(String event) {
|
|
|
|
GeckoAppShell.getEventDispatcher().registerEventListener(event, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void unregisterEventListener(String event) {
|
|
|
|
GeckoAppShell.getEventDispatcher().unregisterEventListener(event, this);
|
|
|
|
}
|
2011-12-07 00:44:08 +00:00
|
|
|
}
|