Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 46e5b654 authored by SongFerng Wang's avatar SongFerng Wang Committed by Automerger Merge Worker
Browse files

Merge "Add limitation for the password" am: 4c0ca9b8

parents caf7a70b 4c0ca9b8
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -2436,7 +2436,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>
+45 −0
Original line number Diff line number Diff line
@@ -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