Bug 770101 - about:config should label integer fields correctly so keyboard uses numerical mode, r=wesj

This commit is contained in:
Mark Capella 2013-09-17 23:54:48 -04:00
Родитель b7e72c7117
Коммит 618621d1b2
3 изменённых файлов: 67 добавлений и 31 удалений

Просмотреть файл

@ -13,9 +13,18 @@ import org.json.JSONArray;
import org.json.JSONObject;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Build;
import android.text.format.DateFormat;
import android.text.Html;
import android.text.InputType;
import android.text.TextUtils;
import android.util.Log;
import android.view.inputmethod.InputMethodManager;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CheckedTextView;
import android.widget.DatePicker;
@ -24,14 +33,6 @@ import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.TimePicker;
import android.text.InputType;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.Log;
import android.text.Html;
import android.widget.ArrayAdapter;
import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.InputMethodManager;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@ -91,6 +92,21 @@ class PromptInput {
}
}
public static class NumberInput extends EditInput {
public static final String INPUT_TYPE = "number";
public NumberInput(JSONObject obj) {
super(obj);
}
public View getView(final Context context) throws UnsupportedOperationException {
EditText input = (EditText) super.getView(context);
input.setRawInputType(Configuration.KEYBOARD_12KEY);
input.setInputType(InputType.TYPE_CLASS_NUMBER |
InputType.TYPE_NUMBER_FLAG_SIGNED);
return input;
}
}
public static class PasswordInput extends EditInput {
public static final String INPUT_TYPE = "password";
public PasswordInput(JSONObject obj) {
@ -324,6 +340,8 @@ class PromptInput {
String type = obj.optString("type");
if (EditInput.INPUT_TYPE.equals(type)) {
return new EditInput(obj);
} else if (NumberInput.INPUT_TYPE.equals(type)) {
return new NumberInput(obj);
} else if (PasswordInput.INPUT_TYPE.equals(type)) {
return new PasswordInput(obj);
} else if (CheckboxInput.INPUT_TYPE.equals(type)) {

Просмотреть файл

@ -37,8 +37,10 @@
<script type="application/javascript;version=1.8"><![CDATA[
const {classes: Cc, interfaces: Ci, manager: Cm, utils: Cu} = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Prompt.jsm");
let gStringBundle = Services.strings.createBundle("chrome://browser/locale/config.properties");
let gCommonBundle = Services.strings.createBundle("chrome://global/locale/commonDialogs.properties");
function dump(a) {
Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage(a);
@ -144,31 +146,37 @@
}
Services.prefs.setBoolPref(aPref.name, result.value);
} else {
let result = { value: aPref.value };
let text = gStringBundle.formatStringFromName("modifyPref.promptText", [aPref.name], 1);
if (!Services.prompt.prompt(window, title, text, result, null, {}))
return;
if (aPref.type == Ci.nsIPrefBranch.PREF_INT) {
// | 0 converts to integer or 0; - 0 to float or NaN.
// Thus, this check should catch all cases.
let val = result.value | 0;
if (val != result.value - 0) {
let errorTitle = gStringBundle.GetStringFromName("modifyPref.numberErrorTitle");
let errorText = gStringBundle.GetStringFromName("modifyPref.numberErrorText");
Services.prompt.alert(window, errorTitle, errorText);
return;
}
Services.prefs.setIntPref(aPref.name, val);
} else {
let supportsString = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
supportsString.data = result.value;
Services.prefs.setComplexValue(aPref.name, Ci.nsISupportsString, supportsString);
}
Services.prefs.savePrefFile(null);
return;
}
Services.prefs.savePrefFile(null);
// If not a boolean, we're a number or string
let p = new Prompt({
window: window,
title: title,
message: gStringBundle.formatStringFromName("modifyPref.promptText", [aPref.name], 1),
buttons: [
gCommonBundle.GetStringFromName("OK"),
gCommonBundle.GetStringFromName("Cancel")
]
});
(aPref.type == Ci.nsIPrefBranch.PREF_INT) ?
p.addNumber({ value: aPref.value, autofocus: true }) :
p.addTextbox({ value: aPref.value, autofocus: true });
p.show(function(result) {
if (result.button == 0) {
if (aPref.type == Ci.nsIPrefBranch.PREF_INT) {
Services.prefs.setIntPref(aPref.name, result.number0);
} else {
let supportsString = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
supportsString.data = result.textbox0;
Services.prefs.setComplexValue(aPref.name, Ci.nsISupportsString, supportsString);
}
Services.prefs.savePrefFile(null);
}
});
},
resetPref: function AC_resetPref(aPref) {

Просмотреть файл

@ -78,6 +78,16 @@ Prompt.prototype = {
});
},
addNumber: function(aOptions) {
return this._addInput({
type: "number",
value: aOptions.value,
hint: aOptions.hint,
autofocus: aOptions.autofocus,
id: aOptions.id
});
},
addPassword: function(aOptions) {
return this._addInput({
type: "password",