diff --git a/res/layout/quick_response_item.xml b/res/layout/quick_response_item.xml
index 577abb3e6..af0966242 100644
--- a/res/layout/quick_response_item.xml
+++ b/res/layout/quick_response_item.xml
@@ -14,7 +14,7 @@
limitations under the License.
-->
-
-
-
\ No newline at end of file
+
diff --git a/src/com/android/email/activity/setup/AccountSettingsEditQuickResponsesFragment.java b/src/com/android/email/activity/setup/AccountSettingsEditQuickResponsesFragment.java
index 136aac981..d440a39d1 100644
--- a/src/com/android/email/activity/setup/AccountSettingsEditQuickResponsesFragment.java
+++ b/src/com/android/email/activity/setup/AccountSettingsEditQuickResponsesFragment.java
@@ -54,8 +54,7 @@ import android.widget.TextView;
*
*
This fragment is run as a preference panel from AccountSettings.
*/
-public class AccountSettingsEditQuickResponsesFragment extends Fragment
- implements OnClickListener {
+public class AccountSettingsEditQuickResponsesFragment extends Fragment {
private ListView mQuickResponsesView;
private Account mAccount;
private Context mContext;
@@ -69,10 +68,9 @@ public class AccountSettingsEditQuickResponsesFragment extends Fragment
private static class ArrayAdapterWithButtons extends ArrayAdapter {
private QuickResponse[] mQuickResponses;
private final long mAccountId;
- private final Context mContext;
private final FragmentManager mFragmentManager;
- private OnClickListener mOnEditListener = new OnClickListener() {
+ private final OnClickListener mOnEditListener = new OnClickListener() {
@Override
public void onClick(View view) {
QuickResponse quickResponse = (QuickResponse) (view.getTag());
@@ -82,23 +80,6 @@ public class AccountSettingsEditQuickResponsesFragment extends Fragment
}
};
- private OnClickListener mOnDeleteListener = new OnClickListener() {
- @Override
- public void onClick(View view) {
- final QuickResponse quickResponse = (QuickResponse) view.getTag();
-
- // Delete the QuickResponse from the database. Content watchers used to
- // update the ListView of QuickResponses upon deletion.
- EmailAsyncTask.runAsyncParallel(new Runnable() {
- @Override
- public void run() {
- EmailContent.delete(mContext, quickResponse.getBaseUri(),
- quickResponse.getId());
- }
- });
- }
- };
-
private static final int resourceId = R.layout.quick_response_item;
private static final int textViewId = R.id.quick_response_text;
@@ -116,7 +97,6 @@ public class AccountSettingsEditQuickResponsesFragment extends Fragment
super(context, resourceId, textViewId, quickResponses);
mQuickResponses = quickResponses;
mAccountId = accountId;
- mContext = context;
mFragmentManager = fragmentManager;
}
@@ -126,10 +106,6 @@ public class AccountSettingsEditQuickResponsesFragment extends Fragment
convertView.setTag(mQuickResponses[position]);
convertView.setOnClickListener(mOnEditListener);
- ImageView deleteIcon = (ImageView) convertView.findViewById(R.id.delete_icon);
- deleteIcon.setTag(mQuickResponses[position]);
- deleteIcon.setOnClickListener(mOnDeleteListener);
-
return convertView;
}
}
@@ -241,13 +217,13 @@ public class AccountSettingsEditQuickResponsesFragment extends Fragment
if (Logging.DEBUG_LIFECYCLE && MailActivityEmail.DEBUG) {
LogUtils.d(Logging.LOG_TAG, "AccountSettingsEditQuickResponsesFragment onCreateView");
}
- int layoutId = R.layout.account_settings_edit_quick_responses_fragment;
- View view = inflater.inflate(layoutId, container, false);
+ View view = inflater.inflate(R.layout.account_settings_edit_quick_responses_fragment,
+ container, false);
mContext = getActivity();
mQuickResponsesView = UiUtilities.getView(view,
R.id.account_settings_quick_responses_list);
- TextView emptyView = (TextView)
+ TextView emptyView =
UiUtilities.getView(((ViewGroup) mQuickResponsesView.getParent()), R.id.empty_view);
mQuickResponsesView.setEmptyView(emptyView);
@@ -265,7 +241,14 @@ public class AccountSettingsEditQuickResponsesFragment extends Fragment
}
});
- UiUtilities.getView(view, R.id.create_new).setOnClickListener(this);
+ UiUtilities.getView(view, R.id.create_new).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ EditQuickResponseDialog
+ .newInstance(null, mAccount.mId)
+ .show(getFragmentManager(), null);
+ }
+ });
return view;
}
@@ -275,16 +258,4 @@ public class AccountSettingsEditQuickResponsesFragment extends Fragment
mTaskTracker.cancellAllInterrupt();
super.onDestroy();
}
-
- /**
- * Implements OnClickListener
- */
- @Override
- public void onClick(View v) {
- if (v.getId() == R.id.create_new) {
- EditQuickResponseDialog
- .newInstance(null, mAccount.mId)
- .show(getFragmentManager(), null);
- }
- }
}
\ No newline at end of file
diff --git a/src/com/android/email/activity/setup/EditQuickResponseDialog.java b/src/com/android/email/activity/setup/EditQuickResponseDialog.java
index e3ef21cfb..47cb2b18f 100644
--- a/src/com/android/email/activity/setup/EditQuickResponseDialog.java
+++ b/src/com/android/email/activity/setup/EditQuickResponseDialog.java
@@ -38,8 +38,7 @@ import android.widget.EditText;
/**
* Dialog to edit the text of a given or new quick response
*/
-public class EditQuickResponseDialog extends DialogFragment
- implements DialogInterface.OnClickListener, TextWatcher {
+public class EditQuickResponseDialog extends DialogFragment {
private EditText mQuickResponseEditText;
private QuickResponse mQuickResponse;
private AlertDialog mDialog;
@@ -73,7 +72,7 @@ public class EditQuickResponseDialog extends DialogFragment
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Context context = getActivity();
mQuickResponse = (QuickResponse) getArguments().getParcelable(QUICK_RESPONSE);
- View wrapper = LayoutInflater.from(context)
+ final View wrapper = LayoutInflater.from(context)
.inflate(R.layout.quick_response_edit_dialog, null);
mQuickResponseEditText = (EditText) wrapper.findViewById(R.id.quick_response_text);
if (savedInstanceState != null) {
@@ -86,13 +85,66 @@ public class EditQuickResponseDialog extends DialogFragment
mQuickResponseEditText.setText(mQuickResponse.toString());
}
mQuickResponseEditText.setSelection(mQuickResponseEditText.length());
- mQuickResponseEditText.addTextChangedListener(this);
+ mQuickResponseEditText.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(s.length() > 0);
+ }
+ });
+
+ DialogInterface.OnClickListener saveClickListener =
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ final long accountId = getArguments().getLong("accountId");
+ final String text = mQuickResponseEditText.getText().toString();
+ final Context context = getActivity();
+ if (mQuickResponse == null) {
+ mQuickResponse = new QuickResponse(accountId, text);
+ }
+
+ // Insert the new QuickResponse into the database. Content watchers used to
+ // update the ListView of QuickResponses upon insertion.
+ EmailAsyncTask.runAsyncParallel(new Runnable() {
+ @Override
+ public void run() {
+ if (!mQuickResponse.isSaved()) {
+ mQuickResponse.save(context);
+ } else {
+ ContentValues values = new ContentValues();
+ values.put(QuickResponseColumns.TEXT, text);
+ mQuickResponse.update(context, values);
+ }
+ }
+
+ });
+ }
+ };
+ DialogInterface.OnClickListener deleteClickListener =
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (mQuickResponse == null) {
+ return;
+ }
+ // TODO: confirm delete
+ mQuickResponse.delete(context, mQuickResponse.getBaseUri(),
+ mQuickResponse.getId());
+ }
+ };
final AlertDialog.Builder b = new AlertDialog.Builder(context);
b.setTitle(getResources().getString(R.string.edit_quick_response_dialog))
.setView(wrapper)
- .setNegativeButton(R.string.cancel_action, this)
- .setPositiveButton(R.string.save_action, this);
+ .setNegativeButton(R.string.cancel_action, null)
+ .setPositiveButton(R.string.save_action, saveClickListener)
+ .setNeutralButton(R.string.delete, deleteClickListener);
mDialog = b.create();
return mDialog;
}
@@ -107,20 +159,6 @@ public class EditQuickResponseDialog extends DialogFragment
}
}
- // implements TextWatcher
- @Override
- public void afterTextChanged(Editable s) {
- mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(s.length() > 0);
- }
-
- // implements TextWatcher
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
-
- // implements TextWatcher
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {}
-
// Saves contents during orientation change
@Override
public void onSaveInstanceState(Bundle outState) {
@@ -128,40 +166,4 @@ public class EditQuickResponseDialog extends DialogFragment
outState.putString(
QUICK_RESPONSE_EDITED_STRING, mQuickResponseEditText.getText().toString());
}
-
- /**
- * Implements DialogInterface.OnClickListener
- */
- @Override
- public void onClick(DialogInterface dialog, int which) {
- switch (which) {
- case DialogInterface.BUTTON_NEGATIVE:
- dialog.cancel();
- break;
- case DialogInterface.BUTTON_POSITIVE:
- final long accountId = getArguments().getLong("accountId");
- final String text = mQuickResponseEditText.getText().toString();
- final Context context = getActivity();
- if (mQuickResponse == null) {
- mQuickResponse = new QuickResponse(accountId, text);
- }
-
- // Insert the new QuickResponse into the database. Content watchers used to
- // update the ListView of QuickResponses upon insertion.
- EmailAsyncTask.runAsyncParallel(new Runnable() {
- @Override
- public void run() {
- if (!mQuickResponse.isSaved()) {
- mQuickResponse.save(context);
- } else {
- ContentValues values = new ContentValues();
- values.put(QuickResponseColumns.TEXT, text);
- mQuickResponse.update(context, values);
- }
- }
-
- });
- break;
- }
- }
}