summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenson Huang <benson.huang@mediatek.com>2015-01-22 12:28:34 +0800
committerNicholas Sauer <nicksauer@google.com>2015-01-28 07:17:10 +0000
commit46104d8a8f87ee400a9b1a917b3d7512d8302dfb (patch)
treed628b48a7f40b40dc8186e4b78e2249ff996d830
parent31fe68d90c5c218aca1969d61052db24d8f2362c (diff)
downloadFMRadio-46104d8a8f87ee400a9b1a917b3d7512d8302dfb.tar.gz
[FM] Only space character should not be allowed while renaming a FM channel or a recorded audio file
Launch FM app and plug in a wired headset -> Star mark a channel to add it favorite -> Go to favorite, tap on the menu (3 dots) and tap on rename to rename the channel -> Enter only spaces and save the channel -> Record an audio and on the dialogue, rename it with only spaces and tap on save, the channel names and audio files are saved without any error message. While playing this channel, FM notification shows no name because of the spaces The fix is to add some condition check for showing/hiding save button. Bug 19087268 from: https://partner-android-review.googlesource.com/#/c/198815/ Change-Id: I2ac0b81d2311eace3d5e28baca31d59d3095c8d1 Signed-off-by: Benson Huang <benson.huang@mediatek.com>
-rw-r--r--src/com/android/fmradio/dialogs/FmFavoriteEditDialog.java71
1 files changed, 63 insertions, 8 deletions
diff --git a/src/com/android/fmradio/dialogs/FmFavoriteEditDialog.java b/src/com/android/fmradio/dialogs/FmFavoriteEditDialog.java
index c2bfc24..ca07c6f 100644
--- a/src/com/android/fmradio/dialogs/FmFavoriteEditDialog.java
+++ b/src/com/android/fmradio/dialogs/FmFavoriteEditDialog.java
@@ -24,7 +24,10 @@ import android.content.DialogInterface;
import android.os.Bundle;
import android.text.Editable;
import android.text.Selection;
+import android.text.TextUtils;
+import android.text.TextWatcher;
import android.view.View;
+import android.widget.Button;
import android.widget.EditText;
import com.android.fmradio.R;
@@ -37,7 +40,7 @@ public class FmFavoriteEditDialog extends DialogFragment {
private static final String STATION_NAME = "station_name";
private static final String STATION_FREQ = "station_freq";
private EditFavoriteListener mListener = null;
- private EditText mEditTextFrequency = null;
+ private EditText mStationNameEditor = null;
/**
* Create edit favorite dialog instance, caller should implement edit
@@ -81,18 +84,18 @@ public class FmFavoriteEditDialog extends DialogFragment {
String stationName = getArguments().getString(STATION_NAME);
final int stationFreq = getArguments().getInt(STATION_FREQ);
View v = View.inflate(getActivity(), R.layout.editstation, null);
- final EditText editTextStationName = (EditText) v.findViewById(
+ mStationNameEditor = (EditText) v.findViewById(
R.id.dlg_edit_station_name_text);
- if (null == stationName || "".equals(stationName)) {
+ if (null == stationName || "".equals(stationName.trim())) {
stationName = "";
}
- editTextStationName.requestFocus();
- editTextStationName.requestFocusFromTouch();
+ mStationNameEditor.requestFocus();
+ mStationNameEditor.requestFocusFromTouch();
// Edit
- editTextStationName.setText(stationName);
- Editable text = editTextStationName.getText();
+ mStationNameEditor.setText(stationName);
+ Editable text = mStationNameEditor.getText();
Selection.setSelection(text, text.length());
return new AlertDialog.Builder(getActivity())
// Must call setTitle here or the title will not be displayed.
@@ -100,11 +103,63 @@ public class FmFavoriteEditDialog extends DialogFragment {
.setPositiveButton(R.string.save,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
- String newName = editTextStationName.getText().toString();
+ String newName = mStationNameEditor.getText().toString().trim();
mListener.editFavorite(stationFreq, newName);
}
})
.setNegativeButton(android.R.string.cancel, null)
.create();
}
+
+ /**
+ * Set the dialog edit text and other attribute.
+ */
+ @Override
+ public void onResume() {
+ super.onResume();
+ setTextChangedCallback();
+ String toName = mStationNameEditor.getText().toString();
+ // empty or blank or white space only name is not allowed
+ toggleSaveButton(toName != null && TextUtils.getTrimmedLength(toName) > 0);
+ }
+
+ /**
+ * This method register callback and set filter to Edit, in order to make
+ * sure that user input is legal. The input can't be empty/blank/all-spaces filename
+ */
+ private void setTextChangedCallback() {
+ mStationNameEditor.addTextChangedListener(new TextWatcher() {
+ // not use, so don't need to implement it
+ @Override
+ public void afterTextChanged(Editable arg0) {
+ }
+
+ // not use, so don't need to implement it
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ }
+
+ /**
+ * check user input whether is null or all white space.
+ */
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ // empty or blank or white space only name is not allowed
+ toggleSaveButton(TextUtils.getTrimmedLength(s) > 0);
+ }
+ });
+ }
+
+ /**
+ * This method enables or disables save button to forbid renaming station name to null.
+ * @param isEnabled true to enable save button, false to disable save button
+ */
+ private void toggleSaveButton(boolean isEnabled) {
+ final AlertDialog dialog = (AlertDialog) getDialog();
+ if (dialog == null) {
+ return;
+ }
+ final Button button = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
+ button.setEnabled(isEnabled);
+ }
}