mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 959742 - Auto close lists if they don't have any buttons on them. r=bnicholson
This commit is contained in:
parent
8275ad7aca
commit
68c9262096
@ -92,6 +92,7 @@ public class IconGridInput extends PromptInput implements OnItemClickListener {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
mSelected = position;
|
||||
notifyListeners(Integer.toString(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -203,23 +203,7 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
ThreadUtils.assertOnUiThread();
|
||||
JSONObject ret = new JSONObject();
|
||||
try {
|
||||
addButtonResult(ret, which);
|
||||
addInputValues(ret);
|
||||
|
||||
if (mAdapter != null) {
|
||||
addListResult(ret, which);
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
Log.i(LOGTAG, "Error building return: " + ex);
|
||||
}
|
||||
|
||||
if (dialog != null) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
|
||||
finishDialog(ret);
|
||||
closeIfNoButtons(which);
|
||||
}
|
||||
|
||||
/* Adds a set of list items to the prompt. This can be used for either context menu type dialogs, checked lists,
|
||||
@ -360,6 +344,19 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
ThreadUtils.assertOnUiThread();
|
||||
mAdapter.toggleSelected(position);
|
||||
|
||||
// If there are no buttons on this dialog, then we take selecting an item as a sign to close
|
||||
// the dialog. Note that means it will be hard to select multiple things in this list, but
|
||||
// given there is no way to confirm+close the dialog, it seems reasonable.
|
||||
closeIfNoButtons(position);
|
||||
}
|
||||
|
||||
private boolean closeIfNoButtons(int selected) {
|
||||
if (mButtons == null || mButtons.length == 0) {
|
||||
closeDialog(selected);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* @DialogInterface.OnCancelListener
|
||||
@ -387,6 +384,20 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis
|
||||
finishDialog(ret);
|
||||
}
|
||||
|
||||
/* Called any time we're closing the dialog to cleanup and notify listeners that the dialog
|
||||
* is closing.
|
||||
*/
|
||||
public void closeDialog(int which) {
|
||||
JSONObject ret = new JSONObject();
|
||||
mDialog.dismiss();
|
||||
|
||||
addButtonResult(ret, which);
|
||||
addListResult(ret, which);
|
||||
addInputValues(ret);
|
||||
|
||||
finishDialog(ret);
|
||||
}
|
||||
|
||||
/* Called any time we're closing the dialog to cleanup and notify listeners that the dialog
|
||||
* is closing.
|
||||
*/
|
||||
@ -421,6 +432,7 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis
|
||||
for (int i = 0; i < mInputs.length; i++) {
|
||||
try {
|
||||
mInputs[i] = PromptInput.getInput(inputs.getJSONObject(i));
|
||||
mInputs[i].setListener(this);
|
||||
} catch(Exception ex) { }
|
||||
}
|
||||
|
||||
@ -437,6 +449,14 @@ public class Prompt implements OnClickListener, OnCancelListener, OnItemClickLis
|
||||
show(title, text, menuitems, choiceMode);
|
||||
}
|
||||
|
||||
// Called when the prompt inputs on the dialog change
|
||||
public void onChange(PromptInput input) {
|
||||
// If there are no buttons on this dialog, assuming that "changing" an input
|
||||
// means something was selected and we can close. This provides a way to tap
|
||||
// on a list item and close the dialog automatically.
|
||||
closeIfNoButtons(-1);
|
||||
}
|
||||
|
||||
private static JSONArray getSafeArray(JSONObject json, String key) {
|
||||
try {
|
||||
return json.getJSONArray(key);
|
||||
|
@ -38,9 +38,18 @@ public class PromptInput {
|
||||
protected final String mType;
|
||||
protected final String mId;
|
||||
protected final String mValue;
|
||||
protected OnChangeListener mListener;
|
||||
protected View mView;
|
||||
public static final String LOGTAG = "GeckoPromptInput";
|
||||
|
||||
public interface OnChangeListener {
|
||||
public void onChange(PromptInput input);
|
||||
}
|
||||
|
||||
public void setListener(OnChangeListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public static class EditInput extends PromptInput {
|
||||
protected final String mHint;
|
||||
protected final boolean mAutofocus;
|
||||
@ -376,4 +385,10 @@ public class PromptInput {
|
||||
public boolean canApplyInputStyle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void notifyListeners(String val) {
|
||||
if (mListener != null) {
|
||||
mListener.onChange(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,6 +104,7 @@ public class TabInput extends PromptInput implements AdapterView.OnItemClickList
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
ThreadUtils.assertOnUiThread();
|
||||
mPosition = position;
|
||||
notifyListeners(Integer.toString(position));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user