diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/settings/DoubleEditSetting.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/settings/DoubleEditSetting.java index f23d7fa30..c111163f4 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/settings/DoubleEditSetting.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/settings/DoubleEditSetting.java @@ -35,12 +35,21 @@ private void initialize(Context aContext) { by.setVisibility(View.VISIBLE); mText2 = findViewById(R.id.textValue2); + mText2.setSoundEffectsEnabled(false); + mText2.setOnClickListener(mText2ClickListener); + mEdit2 = findViewById(R.id.editValue2); mEdit2.setSoundEffectsEnabled(false); + mEdit2.setOnTouchListener((v, event) -> updateTouchTextSelection(v)); + mEdit2.setOnFocusChangeListener((v, hasFocus) -> updateFocusTextSelection(v, hasFocus)); + mEdit2.addTextChangedListener(new TextColorTextWatcher(mEdit2)); + mEdit2.setOnClickListener(v -> mEdit2.selectAll()); mEdit2.setOnEditorActionListener(mInternalEditorActionListener); } + private OnClickListener mText2ClickListener = v -> mButton.performClick(); + protected void onClickListener(View v) { mText2.setVisibility(mEdit1.getVisibility()); mEdit2.setVisibility(mEdit1.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE); diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/settings/SingleEditSetting.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/settings/SingleEditSetting.java index 4b521a4a6..c1e70a8fa 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/settings/SingleEditSetting.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/settings/SingleEditSetting.java @@ -1,8 +1,11 @@ package org.mozilla.vrbrowser.ui.settings; import android.content.Context; +import android.content.res.ColorStateList; import android.content.res.TypedArray; import android.support.annotation.StringRes; +import android.text.Editable; +import android.text.TextWatcher; import android.util.AttributeSet; import android.view.KeyEvent; import android.view.View; @@ -21,8 +24,10 @@ public class SingleEditSetting extends LinearLayout { private TextView mDescriptionView; protected TextView mText1; protected EditText mEdit1; - private TextView mButton; + protected TextView mButton; private OnClickListener mListener; + private int mEditTextSelectedColor; + private int mEditTextUnelectedColor; public SingleEditSetting(Context context, AttributeSet attrs) { this(context, attrs, 0); @@ -47,21 +52,29 @@ private void initialize(Context aContext) { mDescriptionView.setText(mDescription); mText1 = findViewById(R.id.textValue1); + mText1.setSoundEffectsEnabled(false); + mText1.setOnClickListener(mText1ClickListener); + mEdit1 = findViewById(R.id.editValue1); mEdit1.setSoundEffectsEnabled(false); mEdit1.setOnEditorActionListener(mInternalEditorActionListener); + ColorStateList colors = mEdit1.getTextColors(); + mEditTextSelectedColor = colors.getColorForState(View.SELECTED_STATE_SET, R.color.fog); + mEditTextUnelectedColor = colors.getColorForState(View.EMPTY_STATE_SET, R.color.asphalt); + mEdit1.setOnTouchListener((v, event) -> updateTouchTextSelection(v)); + mEdit1.setOnFocusChangeListener((v, hasFocus) -> updateFocusTextSelection(v, hasFocus)); + mEdit1.addTextChangedListener(new TextColorTextWatcher(mEdit1)); + mEdit1.setOnClickListener(v -> mEdit1.selectAll()); mButton = findViewById(R.id.settingButton); + mButton.setSoundEffectsEnabled(false); mButton.setOnClickListener(mInternalClickListener); } - private View.OnClickListener mInternalClickListener = new View.OnClickListener() { - @Override - public void onClick(View v) { - onClickListener(v); - } - }; + private OnClickListener mText1ClickListener = v -> mButton.performClick(); + + private View.OnClickListener mInternalClickListener = v -> onClickListener(v); protected TextView.OnEditorActionListener mInternalEditorActionListener = new TextView.OnEditorActionListener() { @Override @@ -104,4 +117,69 @@ public void setOnClickListener(OnClickListener aListener) { mListener = aListener; } + public void cancel() { + mText1.setVisibility(VISIBLE); + mEdit1.setVisibility(View.GONE); + @StringRes int buttonText = mEdit1.getVisibility() == View.VISIBLE ? + R.string.developer_options_save : R.string.developer_options_edit; + mButton.setText(buttonText); + } + + public boolean isEditing() { + return mEdit1.getVisibility() == View.VISIBLE; + } + + protected boolean updateTouchTextSelection(View v) { + EditText editText = (EditText) v; + if (editText.hasSelection()) { + editText.setTextColor(mEditTextSelectedColor); + + } else { + editText.setTextColor(mEditTextUnelectedColor); + } + + editText.requestFocusFromTouch(); + + return false; + } + + protected void updateFocusTextSelection(View v, boolean hasFocus) { + EditText editText = (EditText) v; + if (editText.hasSelection()) { + if (hasFocus) { + editText.setTextColor(mEditTextSelectedColor); + + } else { + editText.setTextColor(mEditTextUnelectedColor); + } + + } else { + editText.setTextColor(mEditTextUnelectedColor); + } + } + + protected class TextColorTextWatcher implements TextWatcher { + + private EditText mEditText; + + public TextColorTextWatcher(EditText view) { + mEditText = view; + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + mEditText.setTextColor(mEditTextUnelectedColor); + } + + @Override + public void afterTextChanged(Editable s) { + + } + } + } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/DeveloperOptionsEditText.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/DeveloperOptionsEditText.java deleted file mode 100644 index a2db6c971..000000000 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/DeveloperOptionsEditText.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.mozilla.vrbrowser.ui.views; - -import android.content.Context; -import android.text.Editable; -import android.text.TextWatcher; -import android.util.AttributeSet; -import android.view.View; -import org.mozilla.vrbrowser.R; - -public class DeveloperOptionsEditText extends android.support.v7.widget.AppCompatEditText { - - public DeveloperOptionsEditText(Context context, AttributeSet attrs) { - super(context, attrs); - - initialize(); - } - - public DeveloperOptionsEditText(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - - initialize(); - } - - private void initialize() { - addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { - - } - - @Override - public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - - } - - @Override - public void afterTextChanged(Editable editable) { - - } - }); - setOnFocusChangeListener(new OnFocusChangeListener() { - @Override - public void onFocusChange(View view, boolean b) { - if (b) - setTextColor(getContext().getColor(R.color.fog)); - else - setTextColor(getContext().getColor(R.color.asphalt)); - } - }); - setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - selectAll(); - } - }); - } - - @Override - public void addTextChangedListener(final TextWatcher watcher) { - super.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { - watcher.beforeTextChanged(charSequence, i, i1, i2); - } - - @Override - public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - watcher.onTextChanged(charSequence, i, i1, i2); - } - - @Override - public void afterTextChanged(Editable editable) { - setTextColor(getContext().getColor(R.color.asphalt)); - watcher.afterTextChanged(editable); - } - }); - } - - @Override - public void setOnFocusChangeListener(final View.OnFocusChangeListener l) { - super.setOnFocusChangeListener(new OnFocusChangeListener() { - @Override - public void onFocusChange(View view, boolean b) { - l.onFocusChange(view, b); - } - }); - } - - @Override - public void setOnClickListener(final View.OnClickListener l) { - super.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - l.onClick(view); - } - }); - } - -} diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/DeveloperOptionsWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/DeveloperOptionsWidget.java index 1d5ef122e..991fd61d3 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/DeveloperOptionsWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/DeveloperOptionsWidget.java @@ -8,8 +8,6 @@ import android.content.Context; import android.util.AttributeSet; import android.view.View; -import android.widget.CompoundButton; -import android.widget.RadioGroup; import android.widget.ScrollView; import org.mozilla.vrbrowser.R; @@ -27,8 +25,6 @@ public class DeveloperOptionsWidget extends UIWidget { - private static final String LOGTAG = "VRB"; - private AudioEngine mAudio; private UIButton mBackButton; @@ -74,15 +70,12 @@ private void initialize(Context aContext) { mAudio = AudioEngine.fromContext(aContext); mBackButton = findViewById(R.id.backButton); - mBackButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - if (mAudio != null) { - mAudio.playSound(AudioEngine.Sound.CLICK); - } - - onDismiss(); + mBackButton.setOnClickListener(view -> { + if (mAudio != null) { + mAudio.playSound(AudioEngine.Sound.CLICK); } + + onDismiss(); }); mRemoteDebuggingSwitch = findViewById(R.id.remote_debugging_switch); @@ -183,6 +176,25 @@ public void show() { mScrollbar.scrollTo(0, 0); } + @Override + protected void onDismiss() { + if (mDensityEdit.isEditing()) { + mDensityEdit.cancel(); + + } else if (mDpiEdit.isEditing()) { + mDpiEdit.cancel(); + + } else if (mWindowSizeEdit.isEditing()) { + mWindowSizeEdit.cancel(); + + } else if (mMaxWindowSizeEdit.isEditing()) { + mMaxWindowSizeEdit.cancel(); + + } else { + super.onDismiss(); + } + } + private void showRestartDialog() { hide(REMOVE_WIDGET); @@ -205,70 +217,27 @@ private void onRestartDialogDismissed() { show(); } - private SwitchSetting.OnCheckedChangeListener mRemoteDebuggingListener = new SwitchSetting.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean value, boolean doApply) { - setRemoteDebugging(value, doApply); - } - }; + private SwitchSetting.OnCheckedChangeListener mRemoteDebuggingListener = (compoundButton, value, doApply) -> setRemoteDebugging(value, doApply); - private SwitchSetting.OnCheckedChangeListener mConsoleLogsListener = new SwitchSetting.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean value, boolean doApply) { - setConsoleLogs(value, doApply); - } - }; + private SwitchSetting.OnCheckedChangeListener mConsoleLogsListener = (compoundButton, value, doApply) -> setConsoleLogs(value, doApply); - private SwitchSetting.OnCheckedChangeListener mEnvOverrideListener = new SwitchSetting.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean value, boolean doApply) { - setEnvOverride(value); - showRestartDialog(); - } + private SwitchSetting.OnCheckedChangeListener mEnvOverrideListener = (compoundButton, value, doApply) -> { + setEnvOverride(value); + showRestartDialog(); }; - private SwitchSetting.OnCheckedChangeListener mMultiprocessListener = new SwitchSetting.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean value, boolean doApply) { - setMultiprocess(value, doApply); - } - }; + private SwitchSetting.OnCheckedChangeListener mMultiprocessListener = (compoundButton, value, doApply) -> setMultiprocess(value, doApply); - private SwitchSetting.OnCheckedChangeListener mServoListener = new SwitchSetting.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean b, boolean doApply) { - setServo(b, true); - } - }; + private SwitchSetting.OnCheckedChangeListener mServoListener = (compoundButton, b, doApply) -> setServo(b, true); - private RadioGroupSetting.OnCheckedChangeListener mUaModeListener = new RadioGroupSetting.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(RadioGroup radioGroup, int checkedId, boolean doApply) { - setUaMode(checkedId, true); - } - }; + private RadioGroupSetting.OnCheckedChangeListener mUaModeListener = (radioGroup, checkedId, doApply) -> setUaMode(checkedId, true); - private RadioGroupSetting.OnCheckedChangeListener mMSSAChangeListener = new RadioGroupSetting.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(RadioGroup radioGroup, int checkedId, boolean doApply) { - setMSAAMode(checkedId, true); - } - }; + private RadioGroupSetting.OnCheckedChangeListener mMSSAChangeListener = (radioGroup, checkedId, doApply) -> setMSAAMode(checkedId, true); - private RadioGroupSetting.OnCheckedChangeListener mEnvsListener = new RadioGroupSetting.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(RadioGroup radioGroup, int checkedId, boolean doApply) { - setEnv(checkedId, doApply); - } - }; + private RadioGroupSetting.OnCheckedChangeListener mEnvsListener = (radioGroup, checkedId, doApply) -> setEnv(checkedId, doApply); - private RadioGroupSetting.OnCheckedChangeListener mPointerColorListener = new RadioGroupSetting.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(RadioGroup radioGroup, int checkedId, boolean doApply) { - setPointerColor(checkedId, doApply); - } - }; + private RadioGroupSetting.OnCheckedChangeListener mPointerColorListener = (radioGroup, checkedId, doApply) -> setPointerColor(checkedId, doApply); private OnClickListener mDensityListener = new OnClickListener() { @Override @@ -450,7 +419,7 @@ private void setPointerColor(int checkedId, boolean doApply) { } private boolean setDisplayDensity(float newDensity) { - mDensityEdit.setOnClickListener((SingleEditSetting.OnClickListener)null); + mDensityEdit.setOnClickListener(null); boolean restart = false; float prevDensity = SettingsStore.getInstance(getContext()).getDisplayDensity(); if (newDensity <= 0) { @@ -467,7 +436,7 @@ private boolean setDisplayDensity(float newDensity) { } private boolean setDisplayDpi(int newDpi) { - mDpiEdit.setOnClickListener((SingleEditSetting.OnClickListener)null); + mDpiEdit.setOnClickListener(null); boolean restart = false; int prevDensity = SettingsStore.getInstance(getContext()).getDisplayDpi(); if (newDpi <= 0) { diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/SettingsWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/SettingsWidget.java index 895c6ecb7..3c51192a9 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/SettingsWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/SettingsWidget.java @@ -296,7 +296,7 @@ private void onDeveloperOptionsDialogDismissed() { public void onGlobalFocusChanged(View oldFocus, View newFocus) { boolean dismiss = false; UIWidget widget = getChild(mDeveloperOptionsDialogHandle); - if (widget != null && oldFocus == widget && widget.isVisible()) { + if (widget != null && oldFocus == widget && !widget.isChild(newFocus) && widget.isVisible()) { dismiss = true; } else if (oldFocus == this && isVisible()) { diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UIWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UIWidget.java index d598f0e1f..05cd44c8b 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UIWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UIWidget.java @@ -331,6 +331,9 @@ protected T getChild(int aChildId) { return (T) mChildren.get(aChildId); } + protected boolean isChild(View aView) { + return findViewById(aView.getId()) != null; + } protected void onDismiss() { hide(REMOVE_WIDGET); diff --git a/app/src/main/res/drawable/edittext_textcolor.xml b/app/src/main/res/drawable/edittext_textcolor.xml index a4f539b2d..cfd780220 100644 --- a/app/src/main/res/drawable/edittext_textcolor.xml +++ b/app/src/main/res/drawable/edittext_textcolor.xml @@ -1,8 +1,6 @@ - - \ No newline at end of file diff --git a/app/src/main/res/layout/setting_edit.xml b/app/src/main/res/layout/setting_edit.xml index bd1291086..76497d8d1 100644 --- a/app/src/main/res/layout/setting_edit.xml +++ b/app/src/main/res/layout/setting_edit.xml @@ -37,7 +37,7 @@ android:visibility="visible" tools:text="Value" /> - - 20sp @drawable/edittext_background @drawable/edittext_textcolor + @drawable/edittext_textcolor @color/ocean 5dp bold 1 actionDone + true + true + true true 5dp center_vertical