2011-11-18 10:28:17 -08:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 04:12:37 -07: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-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2012-08-02 17:13:40 -07:00
|
|
|
import org.mozilla.gecko.util.GeckoEventResponder;
|
2013-03-15 03:52:52 -07:00
|
|
|
import org.mozilla.gecko.util.ThreadUtils;
|
2012-08-08 00:42:00 -07:00
|
|
|
import org.mozilla.gecko.widget.DateTimePicker;
|
2012-07-27 17:53:54 -07:00
|
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
2012-01-24 16:31:33 -08:00
|
|
|
import android.content.DialogInterface.OnCancelListener;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.content.DialogInterface.OnClickListener;
|
2012-01-24 16:31:33 -08:00
|
|
|
import android.content.res.Resources;
|
2012-03-18 09:15:56 -07:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2013-01-24 12:41:35 -08:00
|
|
|
import android.text.Html;
|
2012-01-24 16:31:33 -08:00
|
|
|
import android.text.InputType;
|
2013-01-15 12:31:24 -08:00
|
|
|
import android.text.TextUtils;
|
2012-11-05 11:33:43 -08:00
|
|
|
import android.text.format.DateFormat;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.util.Log;
|
|
|
|
import android.view.LayoutInflater;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewGroup.LayoutParams;
|
2013-04-08 00:51:56 -07:00
|
|
|
import android.view.inputmethod.InputMethodManager;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.AdapterView.OnItemClickListener;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.widget.ArrayAdapter;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.CheckedTextView;
|
2012-08-08 00:42:00 -07:00
|
|
|
import android.widget.DatePicker;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.ListView;
|
2013-01-24 12:41:35 -08:00
|
|
|
import android.widget.ScrollView;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.widget.Spinner;
|
|
|
|
import android.widget.TextView;
|
2012-08-08 00:42:00 -07:00
|
|
|
import android.widget.TimePicker;
|
2012-07-27 17:53:54 -07:00
|
|
|
|
2012-08-08 00:42:00 -07:00
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.GregorianCalendar;
|
2013-05-09 18:48:00 -07:00
|
|
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
2013-04-08 00:51:56 -07:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
public class PromptService implements OnClickListener, OnCancelListener, OnItemClickListener, GeckoEventResponder {
|
2011-11-18 10:28:17 -08:00
|
|
|
private static final String LOGTAG = "GeckoPromptService";
|
|
|
|
|
2012-08-08 00:42:00 -07:00
|
|
|
private String[] mButtons;
|
2011-11-18 10:28:17 -08:00
|
|
|
private PromptInput[] mInputs;
|
2013-01-15 12:31:24 -08:00
|
|
|
private boolean[] mSelected;
|
2012-09-04 14:43:38 -07:00
|
|
|
private AlertDialog mDialog;
|
2012-03-18 09:15:56 -07:00
|
|
|
|
2013-05-09 18:48:00 -07:00
|
|
|
private final LayoutInflater mInflater;
|
2013-05-09 18:48:00 -07:00
|
|
|
private final ConcurrentLinkedQueue<String> mPromptQueue;
|
2013-01-15 12:31:24 -08:00
|
|
|
private final int mGroupPaddingSize;
|
|
|
|
private final int mLeftRightTextWithIconPadding;
|
|
|
|
private final int mTopBottomTextWithIconPadding;
|
|
|
|
private final int mIconTextPadding;
|
|
|
|
private final int mIconSize;
|
2013-01-24 12:41:35 -08:00
|
|
|
private final int mInputPaddingSize;
|
2013-03-01 16:09:33 -08:00
|
|
|
private final int mMinRowSize;
|
2011-12-07 15:12:51 -08:00
|
|
|
|
|
|
|
PromptService() {
|
2013-05-09 18:48:00 -07:00
|
|
|
mInflater = LayoutInflater.from(GeckoApp.mAppContext);
|
2013-05-09 18:48:00 -07:00
|
|
|
mPromptQueue = new ConcurrentLinkedQueue<String>();
|
2012-07-27 23:13:34 -07:00
|
|
|
|
2012-01-24 16:31:33 -08:00
|
|
|
Resources res = GeckoApp.mAppContext.getResources();
|
2012-07-27 23:13:34 -07:00
|
|
|
mGroupPaddingSize = (int) (res.getDimension(R.dimen.prompt_service_group_padding_size));
|
|
|
|
mLeftRightTextWithIconPadding = (int) (res.getDimension(R.dimen.prompt_service_left_right_text_with_icon_padding));
|
|
|
|
mTopBottomTextWithIconPadding = (int) (res.getDimension(R.dimen.prompt_service_top_bottom_text_with_icon_padding));
|
|
|
|
mIconTextPadding = (int) (res.getDimension(R.dimen.prompt_service_icon_text_padding));
|
|
|
|
mIconSize = (int) (res.getDimension(R.dimen.prompt_service_icon_size));
|
2013-01-24 12:41:35 -08:00
|
|
|
mInputPaddingSize = (int) (res.getDimension(R.dimen.prompt_service_inputs_padding));
|
2013-03-01 16:09:33 -08:00
|
|
|
mMinRowSize = (int) (res.getDimension(R.dimen.prompt_service_min_list_item_height));
|
2012-06-13 14:12:15 -07:00
|
|
|
|
2012-08-02 18:38:45 -07:00
|
|
|
GeckoAppShell.getEventDispatcher().registerEventListener("Prompt:Show", this);
|
2011-12-07 15:12:51 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-07-13 07:17:03 -07:00
|
|
|
void destroy() {
|
2012-08-02 18:38:45 -07:00
|
|
|
GeckoAppShell.getEventDispatcher().unregisterEventListener("Prompt:Show", this);
|
2012-07-13 07:17:03 -07:00
|
|
|
}
|
|
|
|
|
2012-08-08 00:42:00 -07:00
|
|
|
private static String formatDateString(String dateFormat, Calendar calendar) {
|
|
|
|
return new SimpleDateFormat(dateFormat).format(calendar.getTime());
|
|
|
|
}
|
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
private class PromptInput {
|
2013-01-15 12:31:24 -08:00
|
|
|
private final JSONObject mJSONInput;
|
|
|
|
|
|
|
|
private final String mLabel;
|
|
|
|
private final String mType;
|
2013-01-15 12:31:25 -08:00
|
|
|
private final String mId;
|
2013-01-15 12:31:24 -08:00
|
|
|
private final String mHint;
|
|
|
|
private final boolean mAutofocus;
|
|
|
|
private final String mValue;
|
|
|
|
|
|
|
|
private View mView;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
public PromptInput(JSONObject aJSONInput) {
|
|
|
|
mJSONInput = aJSONInput;
|
2013-01-15 12:31:24 -08:00
|
|
|
mLabel = getSafeString(aJSONInput, "label");
|
|
|
|
mType = getSafeString(aJSONInput, "type");
|
2013-01-15 12:31:25 -08:00
|
|
|
String id = getSafeString(aJSONInput, "id");
|
|
|
|
mId = TextUtils.isEmpty(id) ? mType : id;
|
2013-01-15 12:31:24 -08:00
|
|
|
mHint = getSafeString(aJSONInput, "hint");
|
|
|
|
mValue = getSafeString(aJSONInput, "value");
|
|
|
|
mAutofocus = getSafeBool(aJSONInput, "autofocus");
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-08-08 00:42:00 -07:00
|
|
|
public View getView() throws UnsupportedOperationException {
|
2013-01-15 12:31:24 -08:00
|
|
|
if (mType.equals("checkbox")) {
|
2011-11-18 10:28:17 -08:00
|
|
|
CheckBox checkbox = new CheckBox(GeckoApp.mAppContext);
|
|
|
|
checkbox.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
|
2013-01-15 12:31:24 -08:00
|
|
|
checkbox.setText(mLabel);
|
2013-01-15 12:31:24 -08:00
|
|
|
checkbox.setChecked(getSafeBool(mJSONInput, "checked"));
|
2013-01-15 12:31:24 -08:00
|
|
|
mView = (View)checkbox;
|
|
|
|
} else if (mType.equals("date")) {
|
2012-08-08 00:42:00 -07:00
|
|
|
try {
|
2013-01-15 12:31:24 -08:00
|
|
|
DateTimePicker input = new DateTimePicker(GeckoApp.mAppContext, "yyyy-MM-dd", mValue,
|
2013-01-24 12:42:06 -08:00
|
|
|
DateTimePicker.PickersState.DATE);
|
2012-08-08 00:42:00 -07:00
|
|
|
input.toggleCalendar(true);
|
2013-01-15 12:31:24 -08:00
|
|
|
mView = (View)input;
|
2012-08-08 00:42:00 -07:00
|
|
|
} catch (UnsupportedOperationException ex) {
|
|
|
|
// We can't use our custom version of the DatePicker widget because the sdk is too old.
|
|
|
|
// But we can fallback on the native one.
|
|
|
|
DatePicker input = new DatePicker(GeckoApp.mAppContext);
|
|
|
|
try {
|
2013-01-15 12:31:24 -08:00
|
|
|
if (!TextUtils.isEmpty(mValue)) {
|
2012-08-08 00:42:00 -07:00
|
|
|
GregorianCalendar calendar = new GregorianCalendar();
|
2013-01-15 12:31:24 -08:00
|
|
|
calendar.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(mValue));
|
2012-08-08 00:42:00 -07:00
|
|
|
input.updateDate(calendar.get(Calendar.YEAR),
|
|
|
|
calendar.get(Calendar.MONTH),
|
|
|
|
calendar.get(Calendar.DAY_OF_MONTH));
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(LOGTAG, "error parsing format string: " + e);
|
|
|
|
}
|
2013-01-15 12:31:24 -08:00
|
|
|
mView = (View)input;
|
2012-08-08 00:42:00 -07:00
|
|
|
}
|
2013-01-15 12:31:24 -08:00
|
|
|
} else if (mType.equals("week")) {
|
|
|
|
DateTimePicker input = new DateTimePicker(GeckoApp.mAppContext, "yyyy-'W'ww", mValue,
|
2013-01-24 12:42:06 -08:00
|
|
|
DateTimePicker.PickersState.WEEK);
|
2013-01-15 12:31:24 -08:00
|
|
|
mView = (View)input;
|
|
|
|
} else if (mType.equals("time")) {
|
2012-08-08 00:42:00 -07:00
|
|
|
TimePicker input = new TimePicker(GeckoApp.mAppContext);
|
2012-11-05 11:33:43 -08:00
|
|
|
input.setIs24HourView(DateFormat.is24HourFormat(GeckoApp.mAppContext));
|
2013-01-09 14:50:22 -08:00
|
|
|
|
|
|
|
GregorianCalendar calendar = new GregorianCalendar();
|
2013-01-15 12:31:24 -08:00
|
|
|
if (!TextUtils.isEmpty(mValue)) {
|
2012-08-08 00:42:00 -07:00
|
|
|
try {
|
2013-01-15 12:31:24 -08:00
|
|
|
calendar.setTime(new SimpleDateFormat("kk:mm").parse(mValue));
|
2012-08-08 00:42:00 -07:00
|
|
|
} catch (Exception e) { }
|
|
|
|
}
|
2013-01-09 14:50:22 -08:00
|
|
|
input.setCurrentHour(calendar.get(GregorianCalendar.HOUR_OF_DAY));
|
|
|
|
input.setCurrentMinute(calendar.get(GregorianCalendar.MINUTE));
|
2013-01-15 12:31:24 -08:00
|
|
|
mView = (View)input;
|
|
|
|
} else if (mType.equals("datetime-local") || mType.equals("datetime")) {
|
|
|
|
DateTimePicker input = new DateTimePicker(GeckoApp.mAppContext, "yyyy-MM-dd kk:mm", mValue,
|
2013-01-24 12:42:06 -08:00
|
|
|
DateTimePicker.PickersState.DATETIME);
|
2012-08-08 00:42:00 -07:00
|
|
|
input.toggleCalendar(true);
|
2013-01-15 12:31:24 -08:00
|
|
|
mView = (View)input;
|
|
|
|
} else if (mType.equals("month")) {
|
|
|
|
DateTimePicker input = new DateTimePicker(GeckoApp.mAppContext, "yyyy-MM", mValue,
|
2013-01-24 12:42:06 -08:00
|
|
|
DateTimePicker.PickersState.MONTH);
|
2013-01-15 12:31:24 -08:00
|
|
|
mView = (View)input;
|
|
|
|
} else if (mType.equals("textbox") || mType.equals("password")) {
|
2011-11-18 10:28:17 -08:00
|
|
|
EditText input = new EditText(GeckoApp.mAppContext);
|
|
|
|
int inputtype = InputType.TYPE_CLASS_TEXT;
|
2013-01-15 12:31:24 -08:00
|
|
|
if (mType.equals("password")) {
|
2011-11-18 10:28:17 -08:00
|
|
|
inputtype |= InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
|
|
|
|
}
|
|
|
|
input.setInputType(inputtype);
|
2013-01-15 12:31:24 -08:00
|
|
|
input.setText(mValue);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2013-01-15 12:31:24 -08:00
|
|
|
if (!TextUtils.isEmpty(mHint)) {
|
2013-01-15 12:31:24 -08:00
|
|
|
input.setHint(mHint);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-08-15 13:51:36 -07:00
|
|
|
|
2013-01-15 12:31:24 -08:00
|
|
|
if (mAutofocus) {
|
2012-08-15 13:51:36 -07:00
|
|
|
input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-08-15 13:51:36 -07:00
|
|
|
public void onFocusChange(View v, boolean hasFocus) {
|
|
|
|
if (hasFocus) {
|
|
|
|
((InputMethodManager) GeckoApp.mAppContext.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(v, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
input.requestFocus();
|
|
|
|
}
|
|
|
|
|
2013-01-15 12:31:24 -08:00
|
|
|
mView = (View)input;
|
|
|
|
} else if (mType.equals("menulist")) {
|
2011-11-18 10:28:17 -08:00
|
|
|
Spinner spinner = new Spinner(GeckoApp.mAppContext);
|
|
|
|
try {
|
|
|
|
String[] listitems = getStringArray(mJSONInput, "values");
|
|
|
|
if (listitems.length > 0) {
|
2013-04-15 15:06:42 -07:00
|
|
|
ArrayAdapter<String> adapter = new ArrayAdapter<String>(GeckoApp.mAppContext, R.layout.simple_dropdown_item_1line, listitems);
|
2011-11-18 10:28:17 -08:00
|
|
|
spinner.setAdapter(adapter);
|
2013-03-07 10:08:03 -08:00
|
|
|
int selectedIndex = getSafeInt(mJSONInput, "selected");
|
|
|
|
spinner.setSelection(selectedIndex);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
} catch(Exception ex) { }
|
2013-01-15 12:31:24 -08:00
|
|
|
mView = (View)spinner;
|
2013-01-24 12:41:35 -08:00
|
|
|
} else if (mType.equals("label")) {
|
|
|
|
// not really an input, but a way to add labels and such to the dialog
|
|
|
|
TextView view = new TextView(GeckoApp.mAppContext);
|
|
|
|
view.setText(Html.fromHtml(mLabel));
|
|
|
|
mView = view;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2013-01-15 12:31:24 -08:00
|
|
|
return mView;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2013-01-15 12:31:25 -08:00
|
|
|
public String getId() {
|
|
|
|
return mId;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-08-08 00:42:00 -07:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public String getValue() {
|
2013-01-15 12:31:24 -08:00
|
|
|
if (mType.equals("checkbox")) {
|
|
|
|
CheckBox checkbox = (CheckBox)mView;
|
2011-11-18 10:28:17 -08:00
|
|
|
return checkbox.isChecked() ? "true" : "false";
|
2013-01-15 12:31:24 -08:00
|
|
|
} else if (mType.equals("textbox") || mType.equals("password")) {
|
|
|
|
EditText edit = (EditText)mView;
|
2011-11-18 10:28:17 -08:00
|
|
|
return edit.getText().toString();
|
2013-01-15 12:31:24 -08:00
|
|
|
} else if (mType.equals("menulist")) {
|
|
|
|
Spinner spinner = (Spinner)mView;
|
2011-11-18 10:28:17 -08:00
|
|
|
return Integer.toString(spinner.getSelectedItemPosition());
|
2013-01-15 12:31:24 -08:00
|
|
|
} else if (mType.equals("time")) {
|
|
|
|
TimePicker tp = (TimePicker)mView;
|
2012-08-08 00:42:00 -07:00
|
|
|
GregorianCalendar calendar =
|
|
|
|
new GregorianCalendar(0,0,0,tp.getCurrentHour(),tp.getCurrentMinute());
|
|
|
|
return formatDateString("kk:mm",calendar);
|
2013-01-24 12:41:35 -08:00
|
|
|
} else if (mType.equals("label")) {
|
|
|
|
return "";
|
2013-01-15 12:31:24 -08:00
|
|
|
} else if (android.os.Build.VERSION.SDK_INT < 11 && mType.equals("date")) {
|
2012-08-08 00:42:00 -07:00
|
|
|
// We can't use the custom DateTimePicker with a sdk older than 11.
|
|
|
|
// Fallback on the native DatePicker.
|
2013-01-15 12:31:24 -08:00
|
|
|
DatePicker dp = (DatePicker)mView;
|
2012-08-08 00:42:00 -07:00
|
|
|
GregorianCalendar calendar =
|
|
|
|
new GregorianCalendar(dp.getYear(),dp.getMonth(),dp.getDayOfMonth());
|
|
|
|
return formatDateString("yyyy-MM-dd",calendar);
|
|
|
|
} else {
|
2013-01-15 12:31:24 -08:00
|
|
|
DateTimePicker dp = (DateTimePicker)mView;
|
2012-08-08 00:42:00 -07:00
|
|
|
GregorianCalendar calendar = new GregorianCalendar();
|
|
|
|
calendar.setTimeInMillis(dp.getTimeInMillis());
|
2013-01-15 12:31:24 -08:00
|
|
|
if (mType.equals("date")) {
|
2012-08-08 00:42:00 -07:00
|
|
|
return formatDateString("yyyy-MM-dd",calendar);
|
2013-01-15 12:31:24 -08:00
|
|
|
} else if (mType.equals("week")) {
|
2012-08-08 00:42:00 -07:00
|
|
|
return formatDateString("yyyy-'W'ww",calendar);
|
2013-01-15 12:31:24 -08:00
|
|
|
} else if (mType.equals("datetime-local")) {
|
2012-08-08 00:42:00 -07:00
|
|
|
return formatDateString("yyyy-MM-dd kk:mm",calendar);
|
2013-01-15 12:31:24 -08:00
|
|
|
} else if (mType.equals("datetime")) {
|
2012-08-08 00:42:00 -07:00
|
|
|
calendar.set(GregorianCalendar.ZONE_OFFSET,0);
|
|
|
|
calendar.setTimeInMillis(dp.getTimeInMillis());
|
|
|
|
return formatDateString("yyyy-MM-dd kk:mm",calendar);
|
2013-01-15 12:31:24 -08:00
|
|
|
} else if (mType.equals("month")) {
|
2012-08-08 00:42:00 -07:00
|
|
|
return formatDateString("yyyy-MM",calendar);
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-13 14:12:15 -07:00
|
|
|
// GeckoEventListener implementation
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-06-13 14:12:15 -07:00
|
|
|
public void handleMessage(String event, final JSONObject message) {
|
2012-09-13 11:06:36 -07:00
|
|
|
// The dialog must be created on the UI thread.
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-06-13 14:12:15 -07:00
|
|
|
public void run() {
|
|
|
|
processMessage(message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// GeckoEventResponder implementation
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-06-13 14:12:15 -07:00
|
|
|
public String getResponse() {
|
|
|
|
// we only handle one kind of message in handleMessage, and this is the
|
|
|
|
// response we provide for that message
|
2013-05-09 18:48:00 -07:00
|
|
|
String result;
|
|
|
|
while (null == (result = mPromptQueue.poll())) {
|
|
|
|
GeckoAppShell.processNextNativeEvent(true);
|
2013-05-09 18:48:00 -07:00
|
|
|
}
|
2013-05-09 18:48:00 -07:00
|
|
|
return result;
|
2012-06-13 14:12:15 -07:00
|
|
|
}
|
|
|
|
|
2013-01-24 12:41:35 -08:00
|
|
|
private View applyInputStyle(View view) {
|
|
|
|
view.setPadding(mInputPaddingSize, 0, mInputPaddingSize, 0);
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2012-08-08 00:42:00 -07:00
|
|
|
public void show(String aTitle, String aText, PromptListItem[] aMenuList, boolean aMultipleSelection) {
|
2013-03-15 03:52:52 -07:00
|
|
|
ThreadUtils.assertOnUiThread();
|
2012-09-13 11:06:36 -07:00
|
|
|
|
|
|
|
// treat actions that show a dialog as if preventDefault by content to prevent panning
|
2013-01-15 12:31:24 -08:00
|
|
|
GeckoApp.mAppContext.getLayerView().abortPanning();
|
2012-07-18 17:58:56 -07:00
|
|
|
|
2013-01-15 12:31:24 -08:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(GeckoApp.mAppContext);
|
|
|
|
if (!TextUtils.isEmpty(aTitle)) {
|
2011-11-18 10:28:17 -08:00
|
|
|
builder.setTitle(aTitle);
|
|
|
|
}
|
|
|
|
|
2013-01-15 12:31:24 -08:00
|
|
|
if (!TextUtils.isEmpty(aText)) {
|
2011-11-18 10:28:17 -08:00
|
|
|
builder.setMessage(aText);
|
|
|
|
}
|
|
|
|
|
2012-03-18 09:15:56 -07:00
|
|
|
int length = mInputs == null ? 0 : mInputs.length;
|
|
|
|
if (aMenuList != null && aMenuList.length > 0) {
|
2013-01-10 12:26:58 -08:00
|
|
|
int resourceId = android.R.layout.simple_list_item_1;
|
2011-11-18 10:28:17 -08:00
|
|
|
if (mSelected != null && mSelected.length > 0) {
|
|
|
|
if (aMultipleSelection) {
|
2012-10-02 18:58:01 -07:00
|
|
|
resourceId = R.layout.select_dialog_multichoice;
|
2011-11-18 10:28:17 -08:00
|
|
|
} else {
|
2013-04-15 15:06:42 -07:00
|
|
|
resourceId = R.layout.select_dialog_singlechoice;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
PromptListAdapter adapter = new PromptListAdapter(GeckoApp.mAppContext, resourceId, aMenuList);
|
|
|
|
if (mSelected != null && mSelected.length > 0) {
|
|
|
|
if (aMultipleSelection) {
|
2013-05-09 18:48:00 -07:00
|
|
|
adapter.listView = (ListView) mInflater.inflate(R.layout.select_dialog_list, null);
|
2011-11-18 10:28:17 -08:00
|
|
|
adapter.listView.setOnItemClickListener(this);
|
|
|
|
builder.setInverseBackgroundForced(true);
|
|
|
|
adapter.listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
|
|
|
adapter.listView.setAdapter(adapter);
|
|
|
|
builder.setView(adapter.listView);
|
|
|
|
} else {
|
|
|
|
int selectedIndex = -1;
|
|
|
|
for (int i = 0; i < mSelected.length; i++) {
|
|
|
|
if (mSelected[i]) {
|
|
|
|
selectedIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mSelected = null;
|
|
|
|
builder.setSingleChoiceItems(adapter, selectedIndex, this);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
builder.setAdapter(adapter, this);
|
|
|
|
mSelected = null;
|
|
|
|
}
|
|
|
|
} else if (length == 1) {
|
2012-08-08 00:42:00 -07:00
|
|
|
try {
|
2013-01-31 11:05:49 -08:00
|
|
|
ScrollView view = new ScrollView(GeckoApp.mAppContext);
|
|
|
|
view.addView(mInputs[0].getView());
|
|
|
|
builder.setView(applyInputStyle(view));
|
2012-08-08 00:42:00 -07:00
|
|
|
} catch(UnsupportedOperationException ex) {
|
2012-08-07 08:09:15 -07:00
|
|
|
// We cannot display these input widgets with this sdk version,
|
|
|
|
// do not display any dialog and finish the prompt now.
|
|
|
|
finishDialog("{\"button\": -1}");
|
|
|
|
return;
|
2012-08-08 00:42:00 -07:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
} else if (length > 1) {
|
2012-08-08 00:42:00 -07:00
|
|
|
try {
|
2013-01-31 11:05:49 -08:00
|
|
|
LinearLayout linearLayout = new LinearLayout(GeckoApp.mAppContext);
|
|
|
|
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
2012-08-08 00:42:00 -07:00
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
View content = mInputs[i].getView();
|
|
|
|
linearLayout.addView(content);
|
|
|
|
}
|
2013-01-31 11:05:49 -08:00
|
|
|
ScrollView view = new ScrollView(GeckoApp.mAppContext);
|
|
|
|
view.addView(linearLayout);
|
|
|
|
builder.setView(applyInputStyle(view));
|
2012-08-08 00:42:00 -07:00
|
|
|
} catch(UnsupportedOperationException ex) {
|
2012-08-07 08:09:15 -07:00
|
|
|
// We cannot display these input widgets with this sdk version,
|
|
|
|
// do not display any dialog and finish the prompt now.
|
|
|
|
finishDialog("{\"button\": -1}");
|
|
|
|
return;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-08 00:42:00 -07:00
|
|
|
length = mButtons == null ? 0 : mButtons.length;
|
2011-11-18 10:28:17 -08:00
|
|
|
if (length > 0) {
|
2012-08-07 08:09:15 -07:00
|
|
|
builder.setPositiveButton(mButtons[0], this);
|
2012-09-04 15:10:43 -07:00
|
|
|
if (length > 1) {
|
2012-08-07 08:09:15 -07:00
|
|
|
builder.setNeutralButton(mButtons[1], this);
|
2012-09-04 15:10:43 -07:00
|
|
|
if (length > 2) {
|
2012-08-07 08:09:15 -07:00
|
|
|
builder.setNegativeButton(mButtons[2], this);
|
2012-09-04 15:10:43 -07:00
|
|
|
}
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-09-13 11:06:36 -07:00
|
|
|
mDialog = builder.create();
|
|
|
|
mDialog.setOnCancelListener(PromptService.this);
|
|
|
|
mDialog.show();
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-11-18 10:28:17 -08:00
|
|
|
public void onClick(DialogInterface aDialog, int aWhich) {
|
2013-03-15 03:52:52 -07:00
|
|
|
ThreadUtils.assertOnUiThread();
|
2011-11-18 10:28:17 -08:00
|
|
|
JSONObject ret = new JSONObject();
|
|
|
|
try {
|
|
|
|
int button = -1;
|
|
|
|
ListView list = mDialog.getListView();
|
|
|
|
if (list != null || mSelected != null) {
|
|
|
|
button = aWhich;
|
|
|
|
if (mSelected != null) {
|
|
|
|
JSONArray selected = new JSONArray();
|
|
|
|
for (int i = 0; i < mSelected.length; i++) {
|
|
|
|
selected.put(mSelected[i]);
|
|
|
|
}
|
|
|
|
ret.put("button", selected);
|
|
|
|
} else {
|
|
|
|
ret.put("button", button);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch(aWhich) {
|
|
|
|
case DialogInterface.BUTTON_POSITIVE : button = 0; break;
|
|
|
|
case DialogInterface.BUTTON_NEUTRAL : button = 1; break;
|
|
|
|
case DialogInterface.BUTTON_NEGATIVE : button = 2; break;
|
|
|
|
}
|
|
|
|
ret.put("button", button);
|
|
|
|
}
|
|
|
|
if (mInputs != null) {
|
|
|
|
for (int i = 0; i < mInputs.length; i++) {
|
2013-01-15 12:31:25 -08:00
|
|
|
ret.put(mInputs[i].getId(), mInputs[i].getValue());
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(Exception ex) {
|
|
|
|
Log.i(LOGTAG, "Error building return: " + ex);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDialog != null) {
|
|
|
|
mDialog.dismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
finishDialog(ret.toString());
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-11-18 10:28:17 -08:00
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
2013-03-15 03:52:52 -07:00
|
|
|
ThreadUtils.assertOnUiThread();
|
2011-11-18 10:28:17 -08:00
|
|
|
mSelected[position] = !mSelected[position];
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-11-18 10:28:17 -08:00
|
|
|
public void onCancel(DialogInterface aDialog) {
|
2013-03-15 03:52:52 -07:00
|
|
|
ThreadUtils.assertOnUiThread();
|
2011-11-18 10:28:17 -08:00
|
|
|
JSONObject ret = new JSONObject();
|
|
|
|
try {
|
|
|
|
ret.put("button", -1);
|
|
|
|
} catch(Exception ex) { }
|
|
|
|
finishDialog(ret.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void finishDialog(String aReturn) {
|
|
|
|
mInputs = null;
|
2012-08-08 00:42:00 -07:00
|
|
|
mButtons = null;
|
2011-11-18 10:28:17 -08:00
|
|
|
mDialog = null;
|
|
|
|
mSelected = null;
|
2013-05-09 18:48:00 -07:00
|
|
|
mPromptQueue.offer(aReturn);
|
|
|
|
// poke the Gecko thread in case it's waiting for new events
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createNoOpEvent());
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-06-13 14:12:15 -07:00
|
|
|
private void processMessage(JSONObject geckoObject) {
|
2013-01-15 12:31:24 -08:00
|
|
|
String title = getSafeString(geckoObject, "title");
|
|
|
|
String text = getSafeString(geckoObject, "text");
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2013-01-15 12:31:24 -08:00
|
|
|
mButtons = getStringArray(geckoObject, "buttons");
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2013-01-15 12:31:24 -08:00
|
|
|
JSONArray inputs = getSafeArray(geckoObject, "inputs");
|
|
|
|
mInputs = new PromptInput[inputs.length()];
|
|
|
|
for (int i = 0; i < mInputs.length; i++) {
|
2011-11-18 10:28:17 -08:00
|
|
|
try {
|
|
|
|
mInputs[i] = new PromptInput(inputs.getJSONObject(i));
|
|
|
|
} catch(Exception ex) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
PromptListItem[] menuitems = getListItemArray(geckoObject, "listitems");
|
|
|
|
mSelected = getBooleanArray(geckoObject, "selected");
|
2013-01-15 12:31:24 -08:00
|
|
|
boolean multiple = getSafeBool(geckoObject, "multiple");
|
2012-08-08 00:42:00 -07:00
|
|
|
show(title, text, menuitems, multiple);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2013-01-15 12:31:24 -08:00
|
|
|
private static String getSafeString(JSONObject json, String key) {
|
2011-11-18 10:28:17 -08:00
|
|
|
try {
|
2013-01-15 12:31:24 -08:00
|
|
|
return json.getString(key);
|
|
|
|
} catch (Exception e) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static JSONArray getSafeArray(JSONObject json, String key) {
|
|
|
|
try {
|
|
|
|
return json.getJSONArray(key);
|
|
|
|
} catch (Exception e) {
|
|
|
|
return new JSONArray();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean getSafeBool(JSONObject json, String key) {
|
|
|
|
try {
|
|
|
|
return json.getBoolean(key);
|
|
|
|
} catch (Exception e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int getSafeInt(JSONObject json, String key ) {
|
|
|
|
try {
|
|
|
|
return json.getInt(key);
|
|
|
|
} catch (Exception e) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private String[] getStringArray(JSONObject aObject, String aName) {
|
|
|
|
JSONArray items = getSafeArray(aObject, aName);
|
2011-11-18 10:28:17 -08:00
|
|
|
int length = items.length();
|
|
|
|
String[] list = new String[length];
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
try {
|
|
|
|
list[i] = items.getString(i);
|
|
|
|
} catch(Exception ex) { }
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean[] getBooleanArray(JSONObject aObject, String aName) {
|
|
|
|
JSONArray items = new JSONArray();
|
|
|
|
try {
|
|
|
|
items = aObject.getJSONArray(aName);
|
|
|
|
} catch(Exception ex) { return null; }
|
|
|
|
int length = items.length();
|
|
|
|
boolean[] list = new boolean[length];
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
try {
|
|
|
|
list[i] = items.getBoolean(i);
|
|
|
|
} catch(Exception ex) { }
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
private PromptListItem[] getListItemArray(JSONObject aObject, String aName) {
|
2013-01-15 12:31:24 -08:00
|
|
|
JSONArray items = getSafeArray(aObject, aName);
|
2011-11-18 10:28:17 -08:00
|
|
|
int length = items.length();
|
|
|
|
PromptListItem[] list = new PromptListItem[length];
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
try {
|
|
|
|
list[i] = new PromptListItem(items.getJSONObject(i));
|
|
|
|
} catch(Exception ex) { }
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2013-01-15 12:31:24 -08:00
|
|
|
public static class PromptListItem {
|
|
|
|
public final String label;
|
|
|
|
public final boolean isGroup;
|
|
|
|
public final boolean inGroup;
|
|
|
|
public final boolean disabled;
|
|
|
|
public final int id;
|
|
|
|
public final boolean isParent;
|
2012-03-18 09:15:56 -07:00
|
|
|
|
|
|
|
// This member can't be accessible from JS, see bug 733749.
|
2013-01-15 12:31:24 -08:00
|
|
|
public Drawable icon;
|
2012-03-18 09:15:56 -07:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
PromptListItem(JSONObject aObject) {
|
2013-01-15 12:31:24 -08:00
|
|
|
label = getSafeString(aObject, "label");
|
|
|
|
isGroup = getSafeBool(aObject, "isGroup");
|
|
|
|
inGroup = getSafeBool(aObject, "inGroup");
|
|
|
|
disabled = getSafeBool(aObject, "disabled");
|
|
|
|
id = getSafeInt(aObject, "id");
|
|
|
|
isParent = getSafeBool(aObject, "isParent");
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-03-18 09:15:56 -07:00
|
|
|
|
|
|
|
public PromptListItem(String aLabel) {
|
|
|
|
label = aLabel;
|
2013-01-15 12:31:24 -08:00
|
|
|
isGroup = false;
|
|
|
|
inGroup = false;
|
|
|
|
disabled = false;
|
|
|
|
id = 0;
|
|
|
|
isParent = false;
|
2012-03-18 09:15:56 -07:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
public class PromptListAdapter extends ArrayAdapter<PromptListItem> {
|
2012-03-30 09:31:31 -07:00
|
|
|
private static final int VIEW_TYPE_ITEM = 0;
|
|
|
|
private static final int VIEW_TYPE_GROUP = 1;
|
|
|
|
private static final int VIEW_TYPE_COUNT = 2;
|
|
|
|
|
2013-01-15 12:31:24 -08:00
|
|
|
public ListView listView;
|
2012-08-07 08:09:15 -07:00
|
|
|
private int mResourceId = -1;
|
2013-02-21 08:41:41 -08:00
|
|
|
private Drawable mBlankDrawable = null;
|
|
|
|
private Drawable mMoreDrawable = null;
|
2013-01-15 12:31:24 -08:00
|
|
|
|
2012-08-07 08:09:15 -07:00
|
|
|
PromptListAdapter(Context context, int textViewResourceId, PromptListItem[] objects) {
|
2011-11-18 10:28:17 -08:00
|
|
|
super(context, textViewResourceId, objects);
|
|
|
|
mResourceId = textViewResourceId;
|
2012-08-07 08:09:15 -07:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-03-30 09:31:31 -07:00
|
|
|
@Override
|
|
|
|
public int getItemViewType(int position) {
|
|
|
|
PromptListItem item = getItem(position);
|
|
|
|
return (item.isGroup ? VIEW_TYPE_GROUP : VIEW_TYPE_ITEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getViewTypeCount() {
|
|
|
|
return VIEW_TYPE_COUNT;
|
|
|
|
}
|
|
|
|
|
2013-02-21 08:41:41 -08:00
|
|
|
private Drawable getMoreDrawable(Resources res) {
|
|
|
|
if (mMoreDrawable == null) {
|
|
|
|
mMoreDrawable = res.getDrawable(android.R.drawable.ic_menu_more);
|
|
|
|
}
|
|
|
|
return mMoreDrawable;
|
|
|
|
}
|
|
|
|
|
|
|
|
private Drawable getBlankDrawable(Resources res) {
|
|
|
|
if (mBlankDrawable == null) {
|
|
|
|
mBlankDrawable = res.getDrawable(R.drawable.blank);
|
|
|
|
}
|
|
|
|
return mBlankDrawable;
|
|
|
|
}
|
|
|
|
|
2012-03-30 09:31:31 -07:00
|
|
|
private void maybeUpdateIcon(PromptListItem item, TextView t) {
|
2013-02-21 08:41:41 -08:00
|
|
|
if (item.icon == null && !item.inGroup && !item.isParent) {
|
2013-01-04 11:18:42 -08:00
|
|
|
t.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
|
2012-03-30 09:31:31 -07:00
|
|
|
return;
|
2013-01-04 11:18:42 -08:00
|
|
|
}
|
2012-03-30 09:31:31 -07:00
|
|
|
|
2013-01-04 11:18:42 -08:00
|
|
|
Drawable d = null;
|
2012-03-30 09:31:31 -07:00
|
|
|
Resources res = GeckoApp.mAppContext.getResources();
|
|
|
|
// Set the padding between the icon and the text.
|
|
|
|
t.setCompoundDrawablePadding(mIconTextPadding);
|
2013-01-04 11:18:42 -08:00
|
|
|
if (item.icon != null) {
|
|
|
|
// We want the icon to be of a specific size. Some do not
|
|
|
|
// follow this rule so we have to resize them.
|
|
|
|
Bitmap bitmap = ((BitmapDrawable) item.icon).getBitmap();
|
|
|
|
d = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, mIconSize, mIconSize, true));
|
2013-02-21 08:41:41 -08:00
|
|
|
} else if (item.inGroup) {
|
|
|
|
// We don't currently support "indenting" items with icons
|
|
|
|
d = getBlankDrawable(res);
|
2013-01-04 11:18:42 -08:00
|
|
|
}
|
2012-03-30 09:31:31 -07:00
|
|
|
|
2013-01-04 11:18:42 -08:00
|
|
|
Drawable moreDrawable = null;
|
|
|
|
if (item.isParent) {
|
2013-02-21 08:41:41 -08:00
|
|
|
moreDrawable = getMoreDrawable(res);
|
2013-01-04 11:18:42 -08:00
|
|
|
}
|
2012-03-30 09:31:31 -07:00
|
|
|
|
2013-01-04 11:18:42 -08:00
|
|
|
if (d != null || moreDrawable != null) {
|
|
|
|
t.setCompoundDrawablesWithIntrinsicBounds(d, null, moreDrawable, null);
|
|
|
|
}
|
2012-03-30 09:31:31 -07:00
|
|
|
}
|
|
|
|
|
2012-03-30 09:31:31 -07:00
|
|
|
private void maybeUpdateCheckedState(int position, PromptListItem item, ViewHolder viewHolder) {
|
2013-01-04 11:18:42 -08:00
|
|
|
viewHolder.textView.setEnabled(!item.disabled && !item.isGroup);
|
|
|
|
viewHolder.textView.setClickable(item.isGroup || item.disabled);
|
|
|
|
|
|
|
|
if (mSelected == null)
|
2012-03-30 09:31:31 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
CheckedTextView ct;
|
|
|
|
try {
|
|
|
|
ct = (CheckedTextView) viewHolder.textView;
|
2013-01-04 11:18:42 -08:00
|
|
|
// Apparently just using ct.setChecked(true) doesn't work, so this
|
|
|
|
// is stolen from the android source code as a way to set the checked
|
|
|
|
// state of these items
|
|
|
|
if (listView != null)
|
|
|
|
listView.setItemChecked(position, mSelected[position]);
|
2012-03-30 09:31:31 -07:00
|
|
|
} catch (Exception e) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-07-26 18:17:23 -07:00
|
|
|
@Override
|
2011-11-18 10:28:17 -08:00
|
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
|
PromptListItem item = getItem(position);
|
2012-03-30 09:31:31 -07:00
|
|
|
ViewHolder viewHolder = null;
|
|
|
|
|
|
|
|
if (convertView == null) {
|
|
|
|
int resourceId = mResourceId;
|
|
|
|
if (item.isGroup) {
|
|
|
|
resourceId = R.layout.list_item_header;
|
|
|
|
}
|
|
|
|
|
2013-05-09 18:48:00 -07:00
|
|
|
convertView = mInflater.inflate(resourceId, null);
|
2013-03-01 16:09:33 -08:00
|
|
|
convertView.setMinimumHeight(mMinRowSize);
|
2012-03-30 09:31:31 -07:00
|
|
|
|
2013-01-15 12:31:24 -08:00
|
|
|
TextView tv = (TextView) convertView.findViewById(android.R.id.text1);
|
|
|
|
viewHolder = new ViewHolder(tv, tv.getPaddingLeft(), tv.getPaddingRight(),
|
|
|
|
tv.getPaddingTop(), tv.getPaddingBottom());
|
2012-03-30 09:31:31 -07:00
|
|
|
|
|
|
|
convertView.setTag(viewHolder);
|
|
|
|
} else {
|
|
|
|
viewHolder = (ViewHolder) convertView.getTag();
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-03-30 09:31:31 -07:00
|
|
|
|
2012-03-30 09:31:31 -07:00
|
|
|
viewHolder.textView.setText(item.label);
|
2012-03-30 09:31:31 -07:00
|
|
|
maybeUpdateCheckedState(position, item, viewHolder);
|
2012-03-30 09:31:31 -07:00
|
|
|
maybeUpdateIcon(item, viewHolder.textView);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-03-30 09:31:31 -07:00
|
|
|
return convertView;
|
|
|
|
}
|
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
private class ViewHolder {
|
2013-01-15 12:31:24 -08:00
|
|
|
public final TextView textView;
|
|
|
|
public final int paddingLeft;
|
|
|
|
public final int paddingRight;
|
|
|
|
public final int paddingTop;
|
|
|
|
public final int paddingBottom;
|
|
|
|
|
|
|
|
ViewHolder(TextView aTextView, int aLeft, int aRight, int aTop, int aBottom) {
|
|
|
|
textView = aTextView;
|
|
|
|
paddingLeft = aLeft;
|
|
|
|
paddingRight = aRight;
|
|
|
|
paddingTop = aTop;
|
|
|
|
paddingBottom = aBottom;
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|