diff options
author | David Braun <dabraun@google.com> | 2013-10-07 11:35:48 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-10-07 11:35:48 -0700 |
commit | d16b66d7e1e99481e917c6b6157e93a6c2f068a0 (patch) | |
tree | 4efc9fdd9523c3f80f3c5c48a80004924f29f3d4 | |
parent | d0abea53bdb724ca81d0ae45e5698baf0622ba58 (diff) | |
parent | d5a3e0a25c19bf50ed05ed9ec3307a760cba2123 (diff) |
am db425650: am 49d9975a: am ef1b5e0a: Add custom message dialog for Respond via Message.
* commit 'db425650ecd45ba46d13bd92f0af39f6f2425d63':
Add custom message dialog for Respond via Message.
-rwxr-xr-x | InCallUI/res/values/strings.xml | 4 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/AnswerFragment.java | 73 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/AnswerPresenter.java | 13 |
3 files changed, 70 insertions, 20 deletions
diff --git a/InCallUI/res/values/strings.xml b/InCallUI/res/values/strings.xml index e7049e5b2..7c588b34a 100755 --- a/InCallUI/res/values/strings.xml +++ b/InCallUI/res/values/strings.xml @@ -1280,6 +1280,10 @@ <string name="respond_via_sms_canned_response_4">Can\'t talk now. Call me later?</string> <!-- "Respond via SMS" option that lets you compose a custom response. [CHAR LIMIT=30] --> <string name="respond_via_sms_custom_message">Write your own...</string> + <!-- "Custom Message" Cancel alert dialog button --> + <string name="custom_message_cancel">Cancel</string> + <!-- "Custom Message" Send alert dialog button --> + <string name="custom_message_send">Send</string> <!-- Title of settings screen for managing the "Respond via SMS" feature. [CHAR LIMIT=30] --> <string name="respond_via_sms_setting_title">Quick responses</string> diff --git a/InCallUI/src/com/android/incallui/AnswerFragment.java b/InCallUI/src/com/android/incallui/AnswerFragment.java index 324d5228f..29a458656 100644 --- a/InCallUI/src/com/android/incallui/AnswerFragment.java +++ b/InCallUI/src/com/android/incallui/AnswerFragment.java @@ -18,12 +18,18 @@ package com.android.incallui; import android.app.AlertDialog; import android.app.Dialog; +import android.content.DialogInterface; import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.WindowManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; import android.widget.ListView; import com.google.common.base.Preconditions; @@ -106,12 +112,7 @@ public class AnswerFragment extends BaseFragment<AnswerPresenter, AnswerPresente } @Override - public boolean isMessageDialogueShowing() { - return mCannedResponsePopup != null && mCannedResponsePopup.isShowing(); - } - - @Override - public void showMessageDialogue() { + public void showMessageDialog() { final ListView lv = new ListView(getActivity()); Preconditions.checkNotNull(mTextResponsesAdapter); @@ -130,16 +131,65 @@ public class AnswerFragment extends BaseFragment<AnswerPresenter, AnswerPresente * This is safe to call even if the popup is already dismissed, and even if you never called * showRespondViaSmsPopup() in the first place. */ - @Override - public void dismissPopup() { + private void dismissPopup() { if (mCannedResponsePopup != null) { mCannedResponsePopup.dismiss(); // safe even if already dismissed mCannedResponsePopup = null; } } + /** + * Shows the custom message entry dialog. + */ + public void showCustomMessageDialog() { + // Create an alert dialog containing an EditText + final EditText et = new EditText(getActivity()); + final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setCancelable( + true).setView(et) + .setPositiveButton(R.string.custom_message_send, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + getPresenter().rejectCallWithMessage(et.getText().toString().trim()); + } + }) + .setNegativeButton(R.string.custom_message_cancel, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + } + }) + .setTitle(R.string.respond_via_sms_custom_message); + final AlertDialog customResponseDialog = builder.create(); + + // Enable/disable the send button based on whether there is a message in the EditText + et.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) { + final Button sendButton = customResponseDialog.getButton( + DialogInterface.BUTTON_POSITIVE); + sendButton.setEnabled(s != null && s.toString().trim().length() != 0); + } + }); + + // Keyboard up, show the dialog + customResponseDialog.getWindow().setSoftInputMode( + WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); + customResponseDialog.show(); + + // Send button starts out disabled + final Button sendButton = customResponseDialog.getButton(DialogInterface.BUTTON_POSITIVE); + sendButton.setEnabled(false); + } + @Override - public void configureMessageDialogue(ArrayList<String> textResponses) { + public void configureMessageDialog(ArrayList<String> textResponses) { final ArrayList<String> textResponsesForDisplay = new ArrayList<String>(textResponses); textResponsesForDisplay.add(getResources().getString( @@ -178,12 +228,13 @@ public class AnswerFragment extends BaseFragment<AnswerPresenter, AnswerPresente Log.d(this, "RespondViaSmsItemClickListener.onItemClick(" + position + ")..."); final String message = (String) parent.getItemAtPosition(position); Log.v(this, "- message: '" + message + "'"); + dismissPopup(); // The "Custom" choice is a special case. // (For now, it's guaranteed to be the last item.) if (position == (parent.getCount() - 1)) { - // Take the user to the standard SMS compose UI. - getPresenter().rejectCallWithMessage(null); + // Show the custom message dialog + showCustomMessageDialog(); } else { getPresenter().rejectCallWithMessage(message); } diff --git a/InCallUI/src/com/android/incallui/AnswerPresenter.java b/InCallUI/src/com/android/incallui/AnswerPresenter.java index b3deb641e..6d70f8185 100644 --- a/InCallUI/src/com/android/incallui/AnswerPresenter.java +++ b/InCallUI/src/com/android/incallui/AnswerPresenter.java @@ -93,7 +93,7 @@ public class AnswerPresenter extends Presenter<AnswerPresenter.AnswerUi> if (call.can(Call.Capabilities.RESPOND_VIA_TEXT) && textMsgs != null) { getUi().showTextButton(true); - getUi().configureMessageDialogue(textMsgs); + getUi().configureMessageDialog(textMsgs); } else { getUi().showTextButton(false); } @@ -134,24 +134,19 @@ public class AnswerPresenter extends Presenter<AnswerPresenter.AnswerUi> public void onText() { if (getUi() != null) { - getUi().showMessageDialogue(); + getUi().showMessageDialog(); } } public void rejectCallWithMessage(String message) { Log.d(this, "sendTextToDefaultActivity()..."); - if (getUi() != null) { - getUi().dismissPopup(); - } CallCommandClient.getInstance().rejectCall(mCallId, true, message); } interface AnswerUi extends Ui { public void showAnswerUi(boolean show); public void showTextButton(boolean show); - public boolean isMessageDialogueShowing(); - public void showMessageDialogue(); - public void dismissPopup(); - public void configureMessageDialogue(ArrayList<String> textResponses); + public void showMessageDialog(); + public void configureMessageDialog(ArrayList<String> textResponses); } } |