Introduced a new hook so that subclasses of popup control set can decide for themselves if the ok button should always dismiss the dialog (for data validation purposes)

pull/14/head
Sam Bosley 13 years ago
parent 85efa99f2b
commit b0a1efcdcd

@ -389,17 +389,17 @@ public class RepeatControlSet extends PopupControlSet {
} }
@Override @Override
protected Dialog buildDialog(String title, final DialogInterface.OnClickListener okListener, final DialogInterface.OnCancelListener cancelListener) { protected Dialog buildDialog(String title, final PopupDialogClickListener okListener, final DialogInterface.OnCancelListener cancelListener) {
DialogInterface.OnClickListener doRepeatButton = new DialogInterface.OnClickListener() { PopupDialogClickListener doRepeatButton = new PopupDialogClickListener() {
@Override @Override
public void onClick(DialogInterface d, int which) { public boolean onClick(DialogInterface d, int which) {
doRepeat = true; doRepeat = true;
okListener.onClick(d, which);
for (RepeatChangedListener l : listeners) { for (RepeatChangedListener l : listeners) {
l.repeatChanged(doRepeat); l.repeatChanged(doRepeat);
} }
return okListener.onClick(d, which);
} }
}; };
final Dialog d = super.buildDialog(title, doRepeatButton, cancelListener); final Dialog d = super.buildDialog(title, doRepeatButton, cancelListener);

@ -176,10 +176,10 @@ public class TaskRabbitNameControlSet extends PopupControlSet implements TaskRab
} }
@Override @Override
protected void onOkClick() { protected boolean onOkClick() {
super.onOkClick();
InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
return super.onOkClick();
} }
@Override @Override

@ -81,10 +81,10 @@ public class EditNotesControlSet extends PopupControlSet {
} }
@Override @Override
protected void onOkClick() { protected boolean onOkClick() {
super.onOkClick();
InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
return super.onOkClick();
} }
@Override @Override

@ -27,10 +27,14 @@ public abstract class PopupControlSet extends TaskEditControlSet {
protected final TextView displayText; protected final TextView displayText;
private final String titleString; private final String titleString;
final DialogInterface.OnClickListener okListener = new DialogInterface.OnClickListener() { public interface PopupDialogClickListener {
public boolean onClick(DialogInterface d, int which);
}
final PopupDialogClickListener okListener = new PopupDialogClickListener() {
@Override @Override
public void onClick(DialogInterface d, int which) { public boolean onClick(DialogInterface d, int which) {
onOkClick(); return onOkClick();
} }
}; };
@ -66,7 +70,7 @@ public abstract class PopupControlSet extends TaskEditControlSet {
return displayView; return displayView;
} }
protected Dialog buildDialog(String title, final DialogInterface.OnClickListener okClickListener, DialogInterface.OnCancelListener cancelClickListener) { protected Dialog buildDialog(String title, final PopupDialogClickListener okClickListener, DialogInterface.OnCancelListener cancelClickListener) {
int theme = ThemeService.getEditDialogTheme(); int theme = ThemeService.getEditDialogTheme();
dialog = new Dialog(activity, theme); dialog = new Dialog(activity, theme);
if (title.length() == 0) if (title.length() == 0)
@ -82,7 +86,7 @@ public abstract class PopupControlSet extends TaskEditControlSet {
dismiss.setOnClickListener(new OnClickListener() { dismiss.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
okClickListener.onClick(dialog, 0); if (okClickListener.onClick(dialog, 0))
DialogUtilities.dismissDialog(activity, dialog); DialogUtilities.dismissDialog(activity, dialog);
} }
}); });
@ -122,8 +126,13 @@ public abstract class PopupControlSet extends TaskEditControlSet {
// Subclasses can override // Subclasses can override
} }
protected void onOkClick() { /**
* @return true if the dialog should be dismissed as the result of
* the click. Default is true.
*/
protected boolean onOkClick() {
refreshDisplayView(); refreshDisplayView();
return true;
} }
protected void onCancelClick() { protected void onCancelClick() {

Loading…
Cancel
Save