Merge "Add limitation for the password"

This commit is contained in:
SongFerng Wang
2023-02-09 09:02:34 +00:00
committed by Gerrit Code Review
2 changed files with 49 additions and 1 deletions

View File

@@ -2348,7 +2348,10 @@
<string name="media_output_broadcast_update_error">Can\u2019t save. Try again.</string>
<!-- The error message when Broadcast name/code update failed and can't change again[CHAR LIMIT=60] -->
<string name="media_output_broadcast_last_update_error">Can\u2019t save.</string>
<!-- The hint message when Broadcast code is less than 4 characters [CHAR LIMIT=60] -->
<string name="media_output_broadcast_code_hint_no_less_than_min">Use at least 4 characters</string>
<!-- The hint message when Broadcast code is more than 16 characters [CHAR LIMIT=60] -->
<string name="media_output_broadcast_code_hint_no_more_than_max">Use fewer than 16 characters</string>
<!-- Label for clip data when copying the build number off QS [CHAR LIMIT=NONE]-->
<string name="build_number_clip_data_label">Build number</string>

View File

@@ -20,6 +20,8 @@ import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.util.Log;
@@ -64,11 +66,51 @@ public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog {
private String mCurrentBroadcastName;
private String mCurrentBroadcastCode;
private boolean mIsStopbyUpdateBroadcastCode = false;
private TextWatcher mTextWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Do nothing
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Do nothing
}
@Override
public void afterTextChanged(Editable s) {
if (mAlertDialog == null || mBroadcastErrorMessage == null) {
return;
}
boolean breakBroadcastCodeRuleTextLengthLessThanMin =
s.length() > 0 && s.length() < BROADCAST_CODE_MIN_LENGTH;
boolean breakBroadcastCodeRuleTextLengthMoreThanMax =
s.length() > BROADCAST_CODE_MAX_LENGTH;
boolean breakRule = breakBroadcastCodeRuleTextLengthLessThanMin
|| breakBroadcastCodeRuleTextLengthMoreThanMax;
if (breakBroadcastCodeRuleTextLengthLessThanMin) {
mBroadcastErrorMessage.setText(
R.string.media_output_broadcast_code_hint_no_less_than_min);
} else if (breakBroadcastCodeRuleTextLengthMoreThanMax) {
mBroadcastErrorMessage.setText(
R.string.media_output_broadcast_code_hint_no_more_than_max);
}
mBroadcastErrorMessage.setVisibility(breakRule ? View.VISIBLE : View.INVISIBLE);
Button positiveBtn = mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
if (positiveBtn != null) {
positiveBtn.setEnabled(breakRule ? false : true);
}
}
};
static final int METADATA_BROADCAST_NAME = 0;
static final int METADATA_BROADCAST_CODE = 1;
private static final int MAX_BROADCAST_INFO_UPDATE = 3;
private static final int BROADCAST_CODE_MAX_LENGTH = 16;
private static final int BROADCAST_CODE_MIN_LENGTH = 4;
MediaOutputBroadcastDialog(Context context, boolean aboveStatusbar,
BroadcastSender broadcastSender, MediaOutputController mediaOutputController) {
@@ -219,6 +261,9 @@ public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog {
R.layout.media_output_broadcast_update_dialog, null);
final EditText editText = layout.requireViewById(R.id.broadcast_edit_text);
editText.setText(editString);
if (isBroadcastCode) {
editText.addTextChangedListener(mTextWatcher);
}
mBroadcastErrorMessage = layout.requireViewById(R.id.broadcast_error_message);
mAlertDialog = new Builder(mContext)
.setTitle(isBroadcastCode ? R.string.media_output_broadcast_code