Bug 736278 - (1/2) Add support for checkbox in doorhanger message. r=mfinkle

This commit is contained in:
Margaret Leibovic 2012-03-27 14:36:20 -07:00
Родитель f29726e93f
Коммит 834afc0600
3 изменённых файлов: 39 добавлений и 3 удалений

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

@ -43,9 +43,11 @@ import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan;
import android.text.style.URLSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -53,6 +55,8 @@ import org.json.JSONObject;
import org.json.JSONException;
public class DoorHanger extends LinearLayout implements Button.OnClickListener {
private static final String LOGTAG = "DoorHanger";
private Context mContext;
private LinearLayout mChoicesLayout;
private TextView mTextView;
@ -61,6 +65,9 @@ public class DoorHanger extends LinearLayout implements Button.OnClickListener {
// value used to identify the notification
private String mValue;
// Optional checkbox added underneath message text
private CheckBox mCheckBox;
static private LayoutInflater mInflater;
private int mPersistence = 0;
@ -99,7 +106,18 @@ public class DoorHanger extends LinearLayout implements Button.OnClickListener {
}
public void onClick(View v) {
GeckoEvent e = GeckoEvent.createBroadcastEvent("Doorhanger:Reply", v.getTag().toString());
JSONObject response = new JSONObject();
try {
response.put("callback", v.getTag().toString());
// If the checkbox is being used, pass its value
if (mCheckBox != null)
response.put("checked", mCheckBox.isChecked());
} catch (JSONException ex) {
Log.e(LOGTAG, "Error creating onClick response: " + ex);
}
GeckoEvent e = GeckoEvent.createBroadcastEvent("Doorhanger:Reply", response.toString());
GeckoAppShell.sendEventToGecko(e);
mTab.removeDoorHanger(mValue);
@ -166,6 +184,13 @@ public class DoorHanger extends LinearLayout implements Button.OnClickListener {
mTextView.setText(titleWithLink);
mTextView.setMovementMethod(LinkMovementMethod.getInstance());
} catch (JSONException e) { }
try {
String checkBoxText = options.getString("checkbox");
mCheckBox = (CheckBox) findViewById(R.id.doorhanger_checkbox);
mCheckBox.setText(checkBoxText);
mCheckBox.setVisibility(VISIBLE);
} catch (JSONException e) { }
}
// This method checks with persistence and timeout options to see if

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

@ -9,6 +9,12 @@
android:textColorLink="@color/doorhanger_link"
android:padding="10dp"/>
<CheckBox android:id="@+id/doorhanger_checkbox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:checked="true"
android:visibility="gone"/>
<LinearLayout android:id="@+id/doorhanger_choices"
style="@android:style/ButtonBar"
android:layout_width="fill_parent"

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

@ -1074,10 +1074,15 @@ var NativeWindow = {
if (this.menu._callbacks[aData])
this.menu._callbacks[aData]();
} else if (aTopic == "Doorhanger:Reply") {
let reply_id = aData;
let data = JSON.parse(aData);
let reply_id = data["callback"];
if (this.doorhanger._callbacks[reply_id]) {
// Pass the value of the optional checkbox to the callback
let checked = data["checked"];
this.doorhanger._callbacks[reply_id].cb(checked);
let prompt = this.doorhanger._callbacks[reply_id].prompt;
this.doorhanger._callbacks[reply_id].cb();
for (let id in this.doorhanger._callbacks) {
if (this.doorhanger._callbacks[id].prompt == prompt) {
delete this.doorhanger._callbacks[id];