From 4b02aeaf48e000fe33a46f31649b79d092cfe455 Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Thu, 20 Dec 2018 17:03:16 +0900 Subject: [PATCH] Fixes #350 Personalized homepage (#891) * Fixes #350 Personalized homepage * Select homepage text field when it's the default value --- README.md | 1 + .../mozilla/vrbrowser/VRBrowserActivity.java | 6 + .../vrbrowser/browser/SessionStore.java | 16 +- .../vrbrowser/browser/SettingsStore.java | 11 ++ .../ui/views/settings/ButtonSetting.java | 2 + .../ui/views/settings/DoubleEditSetting.java | 65 ++++++-- .../ui/views/settings/RadioGroupSetting.java | 3 + .../ui/views/settings/RadioGroupVSetting.java | 2 + .../ui/views/settings/SettingsEditText.java | 122 ++++++++++++++ .../ui/views/settings/SingleEditSetting.java | 132 +++++++-------- .../ui/views/settings/SwitchSetting.java | 1 + .../ui/widgets/dialogs/SettingsWidget.java | 7 - .../options/DeveloperOptionsWidget.java | 88 ++++++++-- .../widgets/options/DisplayOptionsWidget.java | 156 +++++++++++++++--- .../res/drawable/settings_edit_cursor.xml | 6 + app/src/main/res/layout/options_developer.xml | 9 + app/src/main/res/layout/options_display.xml | 24 ++- app/src/main/res/layout/setting_edit.xml | 12 +- app/src/main/res/values/attrs.xml | 4 + app/src/main/res/values/non_L10n.xml | 2 + app/src/main/res/values/strings.xml | 7 + app/src/main/res/values/styles.xml | 8 +- 22 files changed, 528 insertions(+), 156 deletions(-) create mode 100644 app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/SettingsEditText.java create mode 100644 app/src/main/res/drawable/settings_edit_cursor.xml diff --git a/README.md b/README.md index d158ae603..12c8f90a1 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,7 @@ Restart FxR and close and re-open the WebIDE page. - When using the native debugger you can ignore the first SIGSEGV: address access protected stop in GV thread. It's not a crash; you can click *Resume* to continue debugging. - On some platforms such as Oculus Go the native debugger stops on each input event. You can set this LLDB post-attach command in Android Studio to fix the problem: `pro hand -p true -s false SIGILL` - You can use `adb shell am start -a android.intent.action.VIEW -d "https://aframe.io" org.mozilla.vrbrowser/org.mozilla.vrbrowser.VRBrowserActivity` to load a URL from the command line +- You can use `adb shell am start -a android.intent.action.VIEW -n org.mozilla.vrbrowser/org.mozilla.vrbrowser.VRBrowserActivity -e homepage "https://example.com"` to override the homepage - You can use `adb shell setprop debug.oculus.enableVideoCapture 1` to record videos on the Oculus Go. Remember to disable it when your video is ready. - You can set `disableCrashRestart=true` in the gradle `user.properties` to disable app relaunch on crash. diff --git a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java index b1483a852..1b720703f 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java @@ -322,6 +322,12 @@ void loadFromIntent(final Intent intent) { uri = Uri.parse(intent.getExtras().getString("url")); } + Bundle extras = intent.getExtras(); + if (extras != null && extras.containsKey("homepage")) { + Uri homepageUri = Uri.parse(extras.getString("homepage")); + SettingsStore.getInstance(this).setHomepage(homepageUri.toString()); + } + if (SessionStore.get().getCurrentSession() == null) { String url = (uri != null ? uri.toString() : null); int id = SessionStore.get().createSession(); diff --git a/app/src/common/shared/org/mozilla/vrbrowser/browser/SessionStore.java b/app/src/common/shared/org/mozilla/vrbrowser/browser/SessionStore.java index 39c9c7f94..903b1be4b 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/browser/SessionStore.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/browser/SessionStore.java @@ -70,7 +70,6 @@ public static SessionStore get() { return mInstance; } // You can test a local file using: "resource://android/assets/webvr/index.html" - private static final String HOME_WITHOUT_REGION_ORIGIN = "https://webxr.today/"; public static final String PRIVATE_BROWSING_URI = "about:privatebrowsing"; public static final int NO_SESSION_ID = -1; @@ -342,6 +341,7 @@ int createSession(SessionSettings aSettings) { int result = state.mSession.hashCode(); mSessions.put(result, state); + state.mSession.getSettings().setBoolean(GeckoSessionSettings.USE_MULTIPROCESS, aSettings.multiprocess); state.mSession.getSettings().setBoolean(GeckoSessionSettings.USE_PRIVATE_MODE, aSettings.privateMode); state.mSession.getSettings().setBoolean(GeckoSessionSettings.USE_TRACKING_PROTECTION, aSettings.trackingProtection); @@ -492,15 +492,17 @@ public void setRegion(String aRegion) { } public String getHomeUri() { - String result = SessionStore.HOME_WITHOUT_REGION_ORIGIN; - if (mRegion != null) { - result = SessionStore.HOME_WITHOUT_REGION_ORIGIN + "?region=" + mRegion; + String homepage = SettingsStore.getInstance(mContext).getHomepage(); + if (homepage.equals(mContext.getString(R.string.homepage_url)) && mRegion != null) { + homepage = homepage + "?region=" + mRegion; } - return result; + return homepage; } public Boolean isHomeUri(String aUri) { - return aUri != null && aUri.toLowerCase().startsWith(SessionStore.HOME_WITHOUT_REGION_ORIGIN); + return aUri != null && aUri.toLowerCase().startsWith( + SettingsStore.getInstance(mContext).getHomepage() + ); } public String getCurrentUri() { @@ -906,7 +908,7 @@ public void onLocationChange(GeckoSession aSession, String aUri) { } // The homepage finishes loading after the region has been updated - if (mRegion != null && aUri.equalsIgnoreCase(SessionStore.HOME_WITHOUT_REGION_ORIGIN)) { + if (mRegion != null && aUri.equalsIgnoreCase(SettingsStore.getInstance(mContext).getHomepage())) { aSession.loadUri("javascript:window.location.replace('" + getHomeUri() + "');"); } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java b/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java index 3f1255ec9..0f4f75a1b 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java @@ -187,6 +187,17 @@ public void setInputMode(int aTouchMode) { editor.commit(); } + public String getHomepage() { + return mPrefs.getString( + mContext.getString(R.string.settings_key_homepage), + mContext.getString(R.string.homepage_url)); + } + + public void setHomepage(String aHomepage) { + SharedPreferences.Editor editor = mPrefs.edit(); + editor.putString(mContext.getString(R.string.settings_key_homepage), aHomepage); + editor.commit(); + } public float getDisplayDensity() { return mPrefs.getFloat( diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/ButtonSetting.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/ButtonSetting.java index 4d9c61cb1..127e1fc48 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/ButtonSetting.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/ButtonSetting.java @@ -56,6 +56,8 @@ protected void onClickListener(View v) { if (mListener != null) { mListener.onClick(v); } + + v.requestFocus(); } public void setOnClickListener(OnClickListener aListener) { diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/DoubleEditSetting.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/DoubleEditSetting.java index b3fbdfa79..f61347b68 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/DoubleEditSetting.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/DoubleEditSetting.java @@ -2,9 +2,10 @@ import android.content.Context; import android.content.res.TypedArray; +import android.text.InputFilter; +import android.text.InputType; import android.util.AttributeSet; import android.view.View; -import android.widget.EditText; import android.widget.TextView; import org.mozilla.vrbrowser.R; @@ -13,7 +14,8 @@ public class DoubleEditSetting extends SingleEditSetting { private String mBy; private TextView mText2; - private EditText mEdit2; + private SettingsEditText mEdit2; + private String mDefaultSecondValue; public DoubleEditSetting(Context context, AttributeSet attrs) { this(context, attrs, 0); @@ -39,11 +41,26 @@ private void initialize(Context aContext) { mText2.setOnClickListener(mText2ClickListener); mEdit2 = findViewById(R.id.editValue2); + mEdit2.setHighlightedTextColor(mHighlightedTextColor); + mEdit2.setHighlightedTextColor(mHighlightedTextColor); + mEdit2.setOnClickListener(view -> { + if (mEdit2.getText().toString().equals(mEdit2.getHint())) { + mEdit2.requestFocus(); + mEdit2.selectAll(); + } + }); 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()); + if (mMaxLength != 0) { + mEdit2.setFilters(new InputFilter[]{ + new InputFilter.LengthFilter(mMaxLength) + }); + } + if (mInputType != InputType.TYPE_NULL) { + mEdit2.setInputType(mInputType); + } + if (mWidth > 0) { + mEdit2.setWidth((int)mWidth); + } mEdit2.setOnEditorActionListener(mInternalEditorActionListener); } @@ -51,19 +68,45 @@ private void initialize(Context aContext) { 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); + mText2.setVisibility(mEdit2.getVisibility()); + mEdit2.setVisibility(mEdit2.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE); super.onClickListener(v); } + public void setDefaultSecondValue(String value) { + mDefaultSecondValue = value; + } + public String getSecondText() { - return mEdit2.getText().toString(); + return mEdit2.getText().equals(mEdit2.getHint()) ? mDefaultSecondValue : mEdit2.getText().toString(); } public void setSecondText(String text) { - mText2.setText(text); - mEdit2.setText(text); + if (text.equals(mDefaultSecondValue)) { + mText2.setText(mEdit2.getHint()); + mEdit2.setText(mEdit2.getHint()); + + } else { + mText2.setText(text); + mEdit2.setText(text); + } + } + + public void setHint2(String hint) { + mEdit2.setHint(hint); + } + + @Override + public void cancel() { + super.cancel(); + + mText2.setVisibility(VISIBLE); + mEdit2.setVisibility(View.GONE); + + if (mEdit2.length() == 0) { + setSecondText(mDefaultSecondValue != null ? mDefaultSecondValue : mText2.getText().toString()); + } } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/RadioGroupSetting.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/RadioGroupSetting.java index 9e81b953c..e87b25e18 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/RadioGroupSetting.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/RadioGroupSetting.java @@ -2,6 +2,7 @@ import android.content.Context; import android.content.res.TypedArray; +import android.text.InputType; import android.util.AttributeSet; import android.util.TypedValue; import android.view.ContextThemeWrapper; @@ -75,6 +76,7 @@ protected void initialize(Context aContext, @LayoutRes int layout) { for (int i=0; i { + if (hasSelection()) { + if (b) { + int start = getSelectionStart(); + int end = getSelectionEnd(); + if (end < start) { + int tmp = end; + end = start; + start = tmp; + } + + ForegroundColorSpan highlightedColor = new ForegroundColorSpan(mHighlightedTextColor); + getText().setSpan(highlightedColor, start, end, 0); + + } else { + ForegroundColorSpan normalColor = new ForegroundColorSpan(mNormalTextColor); + getText().setSpan(normalColor, 0, length(), 0); + } + + } else { + ForegroundColorSpan normalColor = new ForegroundColorSpan(mNormalTextColor); + getText().setSpan(normalColor, 0, length(), 0); + } + }); + } + + TextWatcher watcher = new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + ForegroundColorSpan normalColor = new ForegroundColorSpan(mNormalTextColor); + getText().setSpan(normalColor, 0, length(), 0); + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + + } + + @Override + public void afterTextChanged(Editable editable) { + + } + }; + + @Override + protected void onSelectionChanged(int selStart, int selEnd) { + super.onSelectionChanged(selStart, selEnd); + + if (getTextColors() != null) { + handleTextColor(); + } + } + + private void handleTextColor() { + if (mHighlightedTextColor == 0) { + mHighlightedTextColor = mNormalTextColor; + } + + if (isPressed()) { + ForegroundColorSpan normalColor = new ForegroundColorSpan(mNormalTextColor); + getText().setSpan(normalColor, 0, length(), 0); + } + + if (hasSelection()) { + int start = getSelectionStart(); + int end = getSelectionEnd(); + if (end < start) { + int tmp = end; + end = start; + start = tmp; + } + + ForegroundColorSpan normalColor = new ForegroundColorSpan(mNormalTextColor); + getText().setSpan(normalColor, 0, length(), 0); + ForegroundColorSpan highlightedColor = new ForegroundColorSpan(mHighlightedTextColor); + getText().setSpan(highlightedColor, start, end, 0); + } + } + + public void setHighlightedTextColor(int color) { + mHighlightedTextColor = color; + } + +} diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/SingleEditSetting.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/SingleEditSetting.java index abe78befb..658b9c1b3 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/SingleEditSetting.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/SingleEditSetting.java @@ -1,18 +1,17 @@ package org.mozilla.vrbrowser.ui.views.settings; import android.content.Context; -import android.content.res.ColorStateList; import android.content.res.TypedArray; -import android.text.Editable; -import android.text.TextWatcher; +import android.text.InputFilter; +import android.text.InputType; import android.util.AttributeSet; import android.view.KeyEvent; import android.view.View; import android.view.inputmethod.EditorInfo; -import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; +import org.jetbrains.annotations.NotNull; import org.mozilla.vrbrowser.R; import org.mozilla.vrbrowser.audio.AudioEngine; @@ -22,13 +21,16 @@ public class SingleEditSetting extends LinearLayout { private AudioEngine mAudio; private String mDescription; + protected int mMaxLength; + protected float mWidth; + protected int mInputType; private TextView mDescriptionView; - protected TextView mText1; - protected EditText mEdit1; + private TextView mText1; + private SettingsEditText mEdit1; protected TextView mButton; private OnClickListener mListener; - private int mEditTextSelectedColor; - private int mEditTextUnelectedColor; + protected int mHighlightedTextColor; + private String mDefaultFirstValue; public SingleEditSetting(Context context, AttributeSet attrs) { this(context, attrs, 0); @@ -39,8 +41,10 @@ public SingleEditSetting(Context context, AttributeSet attrs, int defStyleAttr) TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.EditSetting, defStyleAttr, 0); mDescription = attributes.getString(R.styleable.EditSetting_description); - attributes.recycle(); - + mMaxLength = attributes.getInt(R.styleable.EditSetting_android_maxLength, 0); + mWidth = attributes.getDimension(R.styleable.EditSetting_android_width, 0.0f); + mInputType = attributes.getInt(R.styleable.EditSetting_android_inputType, InputType.TYPE_NULL); + mHighlightedTextColor = attributes.getColor(R.styleable.EditSetting_highlightedTextColor, 0); initialize(context); } @@ -57,16 +61,26 @@ private void initialize(Context aContext) { mText1.setOnClickListener(mText1ClickListener); mEdit1 = findViewById(R.id.editValue1); - mEdit1.setSoundEffectsEnabled(false); - + mEdit1.setHighlightedTextColor(mHighlightedTextColor); 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()); + mEdit1.setOnClickListener(view -> { + if (mEdit1.getText().toString().equals(mEdit1.getHint())) { + mEdit1.requestFocus(); + mEdit1.selectAll(); + } + }); + mEdit1.setSoundEffectsEnabled(false); + if (mMaxLength != 0) { + mEdit1.setFilters(new InputFilter[]{ + new InputFilter.LengthFilter(mMaxLength) + }); + } + if (mInputType != InputType.TYPE_NULL) { + mEdit1.setInputType(mInputType); + } + if (mWidth > 0) { + mEdit1.setWidth((int)mWidth); + } mButton = findViewById(R.id.settingButton); mButton.setSoundEffectsEnabled(false); @@ -103,15 +117,33 @@ protected void onClickListener(View v) { if (mListener != null) { mListener.onClick(v); } + + mEdit1.requestFocus(); + } + + public void setDefaultFirstValue(String value) { + mDefaultFirstValue = value; } public String getFirstText() { - return mEdit1.getText().toString(); + return mEdit1.getText().equals(mEdit1.getHint()) ? mDefaultFirstValue : mEdit1.getText().toString(); } public void setFirstText(String text) { - mText1.setText(text); - mEdit1.setText(text); + if (text.equals(mDefaultFirstValue)) { + mText1.setText(mEdit1.getHint()); + mEdit1.setText(mEdit1.getHint()); + mEdit1.requestFocus(); + mEdit1.selectAll(); + + } else { + mText1.setText(text); + mEdit1.setText(text); + } + } + + public void setHint1(String hint) { + mEdit1.setHint(hint); } public void setOnClickListener(OnClickListener aListener) { @@ -123,6 +155,9 @@ public void cancel() { mEdit1.setVisibility(View.GONE); @StringRes int buttonText = mEdit1.getVisibility() == View.VISIBLE ? R.string.developer_options_save : R.string.developer_options_edit; + if (mEdit1.length() == 0) { + setFirstText(mDefaultFirstValue != null ? mDefaultFirstValue : mText1.getText().toString()); + } mButton.setText(buttonText); } @@ -130,57 +165,8 @@ 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) { - - } + public boolean contains(@NotNull View view) { + return findViewById(view.getId()) == view; } } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/SwitchSetting.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/SwitchSetting.java index 516d490b4..658e9389c 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/SwitchSetting.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/SwitchSetting.java @@ -61,6 +61,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) { } setValue(b, true); + mSwitch.requestFocus(); } }; diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/SettingsWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/SettingsWidget.java index f814ec147..44d16b797 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/SettingsWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/SettingsWidget.java @@ -46,7 +46,6 @@ public class SettingsWidget extends UIWidget implements WidgetManagerDelegate.Fo private int mDeveloperOptionsDialogHandle = -1; private int mLanguageOptionsDialogHandle = -1; private int mDisplayOptionsDialogHandle = -1; - private int mCurrentlyOpenedDialogHandle = -1; private TextView mBuildText; class VersionGestureListener extends GestureDetector.SimpleOnGestureListener { @@ -321,8 +320,6 @@ private void showDeveloperOptionsDialog() { } widget.show(); - - mCurrentlyOpenedDialogHandle = mDeveloperOptionsDialogHandle; } private void showLanguageOptionsDialog() { @@ -336,8 +333,6 @@ private void showLanguageOptionsDialog() { } widget.show(); - - mCurrentlyOpenedDialogHandle = mLanguageOptionsDialogHandle; } private void showDisplayOptionsDialog() { @@ -351,8 +346,6 @@ private void showDisplayOptionsDialog() { } widget.show(); - - mCurrentlyOpenedDialogHandle = mDisplayOptionsDialogHandle; } private void onOptionsDialogDismissed() { diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/options/DeveloperOptionsWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/options/DeveloperOptionsWidget.java index a2079b2e1..e6f7f32e0 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/options/DeveloperOptionsWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/options/DeveloperOptionsWidget.java @@ -17,11 +17,12 @@ import org.mozilla.vrbrowser.ui.views.UIButton; import org.mozilla.vrbrowser.ui.views.settings.ButtonSetting; import org.mozilla.vrbrowser.ui.views.settings.RadioGroupSetting; +import org.mozilla.vrbrowser.ui.views.settings.SingleEditSetting; import org.mozilla.vrbrowser.ui.views.settings.SwitchSetting; -import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate; -import org.mozilla.vrbrowser.ui.widgets.dialogs.RestartDialogWidget; import org.mozilla.vrbrowser.ui.widgets.UIWidget; +import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate; import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement; +import org.mozilla.vrbrowser.ui.widgets.dialogs.RestartDialogWidget; import static org.mozilla.vrbrowser.utils.ServoUtils.isServoAvailable; @@ -41,6 +42,9 @@ public class DeveloperOptionsWidget extends UIWidget implements private RadioGroupSetting mEnvironmentsRadio; private RadioGroupSetting mPointerColorRadio; + private SingleEditSetting mHomepageEdit; + private String mDefaultHomepageUrl; + private ButtonSetting mResetButton; private int mRestartDialogHandle = -1; @@ -66,18 +70,27 @@ private void initialize(Context aContext) { mAudio = AudioEngine.fromContext(aContext); - mWidgetManager.addFocusChangeListener(this); - mWidgetManager.addWorldClickListener(this); - mBackButton = findViewById(R.id.backButton); mBackButton.setOnClickListener(view -> { if (mAudio != null) { mAudio.playSound(AudioEngine.Sound.CLICK); } - onDismiss(); + hide(REMOVE_WIDGET); + if (mDelegate != null) { + mDelegate.onDismiss(); + } }); + mDefaultHomepageUrl = getContext().getString(R.string.homepage_url); + + mHomepageEdit = findViewById(R.id.homepage_edit); + mHomepageEdit.setHint1(getContext().getString(R.string.homepage_hint)); + mHomepageEdit.setDefaultFirstValue(mDefaultHomepageUrl); + mHomepageEdit.setFirstText(SettingsStore.getInstance(getContext()).getHomepage()); + mHomepageEdit.setOnClickListener(mHomepageListener); + setHomepage(SettingsStore.getInstance(getContext()).getHomepage()); + mRemoteDebuggingSwitch = findViewById(R.id.remote_debugging_switch); mRemoteDebuggingSwitch.setOnCheckedChangeListener(mRemoteDebuggingListener); setRemoteDebugging(SettingsStore.getInstance(getContext()).isRemoteDebuggingEnabled(), false); @@ -132,18 +145,32 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) { } @Override - public void releaseWidget() { - mWidgetManager.removeFocusChangeListener(this); - mWidgetManager.removeWorldClickListener(this); + public void show() { + super.show(); - super.releaseWidget(); + mWidgetManager.addWorldClickListener(this); + mWidgetManager.addFocusChangeListener(this); + mScrollbar.scrollTo(0, 0); } @Override - public void show() { - super.show(); + public void hide(@HideFlags int aHideFlags) { + super.hide(aHideFlags); - mScrollbar.scrollTo(0, 0); + mHomepageEdit.cancel(); + + mWidgetManager.removeWorldClickListener(this); + mWidgetManager.removeFocusChangeListener(this); + } + + @Override + protected void onDismiss() { + if (mHomepageEdit.isEditing()) { + mHomepageEdit.cancel(); + + } else { + super.onDismiss(); + } } private void showRestartDialog() { @@ -163,6 +190,15 @@ private void onRestartDialogDismissed() { show(); } + private OnClickListener mHomepageListener = (view) -> { + if (!mHomepageEdit.getFirstText().isEmpty()) { + setHomepage(mHomepageEdit.getFirstText()); + + } else { + setHomepage(mDefaultHomepageUrl); + } + }; + private SwitchSetting.OnCheckedChangeListener mRemoteDebuggingListener = (compoundButton, value, doApply) -> { setRemoteDebugging(value, doApply); }; @@ -199,9 +235,16 @@ private void onRestartDialogDismissed() { restart = true; } - setConsoleLogs(SettingsStore.CONSOLE_LOGS_DEFAULT, true); - setMultiprocess(SettingsStore.MULTIPROCESS_DEFAULT, true); - setServo(SettingsStore.SERVO_DEFAULT, true); + if (mConsoleLogsSwitch.isChecked() != SettingsStore.CONSOLE_LOGS_DEFAULT) { + setConsoleLogs(SettingsStore.CONSOLE_LOGS_DEFAULT, true); + } + if (mMultiprocessSwitch.isChecked() != SettingsStore.MULTIPROCESS_DEFAULT) { + setMultiprocess(SettingsStore.MULTIPROCESS_DEFAULT, true); + } + if (mServoSwitch.isChecked() != SettingsStore.SERVO_DEFAULT) { + setServo(SettingsStore.SERVO_DEFAULT, true); + } + setHomepage(mDefaultHomepageUrl); if (mEnvOverrideSwitch.isChecked() != SettingsStore.ENV_OVERRIDE_DEFAULT) { setEnvOverride(SettingsStore.ENV_OVERRIDE_DEFAULT); @@ -216,6 +259,13 @@ private void onRestartDialogDismissed() { showRestartDialog(); }; + private void setHomepage(String newHomepage) { + mHomepageEdit.setOnClickListener(null); + mHomepageEdit.setFirstText(newHomepage); + SettingsStore.getInstance(getContext()).setHomepage(newHomepage); + mHomepageEdit.setOnClickListener(mHomepageListener); + } + private void setRemoteDebugging(boolean value, boolean doApply) { mRemoteDebuggingSwitch.setOnCheckedChangeListener(null); mRemoteDebuggingSwitch.setValue(value, doApply); @@ -300,6 +350,12 @@ private void setPointerColor(int checkedId, boolean doApply) { @Override public void onGlobalFocusChanged(View oldFocus, View newFocus) { + if (oldFocus != null) { + if (mHomepageEdit.contains(oldFocus) && mHomepageEdit.isEditing()) { + mHomepageEdit.cancel(); + } + } + if (oldFocus == this && isVisible() && findViewById(newFocus.getId()) == null) { onDismiss(); } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/options/DisplayOptionsWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/options/DisplayOptionsWidget.java index 0766cafec..1edb88c68 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/options/DisplayOptionsWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/options/DisplayOptionsWidget.java @@ -64,16 +64,16 @@ private void initialize(Context aContext) { mAudio = AudioEngine.fromContext(aContext); - mWidgetManager.addFocusChangeListener(this); - mWidgetManager.addWorldClickListener(this); - mBackButton = findViewById(R.id.backButton); mBackButton.setOnClickListener(view -> { if (mAudio != null) { mAudio.playSound(AudioEngine.Sound.CLICK); } - onDismiss(); + hide(REMOVE_WIDGET); + if (mDelegate != null) { + mDelegate.onDismiss(); + } }); int uaMode = SettingsStore.getInstance(getContext()).getUaMode(); @@ -87,16 +87,24 @@ private void initialize(Context aContext) { setMSAAMode(mMSAARadio.getIdForValue(msaaLevel), false); mDensityEdit = findViewById(R.id.density_edit); + mDensityEdit.setHint1(String.valueOf(SettingsStore.DISPLAY_DENSITY_DEFAULT)); + mDensityEdit.setDefaultFirstValue(String.valueOf(SettingsStore.DISPLAY_DENSITY_DEFAULT)); mDensityEdit.setFirstText(Float.toString(SettingsStore.getInstance(getContext()).getDisplayDensity())); mDensityEdit.setOnClickListener(mDensityListener); setDisplayDensity(SettingsStore.getInstance(getContext()).getDisplayDensity()); mDpiEdit = findViewById(R.id.dpi_edit); + mDpiEdit.setHint1(String.valueOf(SettingsStore.DISPLAY_DPI_DEFAULT)); + mDpiEdit.setDefaultFirstValue(String.valueOf(SettingsStore.DISPLAY_DPI_DEFAULT)); mDpiEdit.setFirstText(Integer.toString(SettingsStore.getInstance(getContext()).getDisplayDpi())); mDpiEdit.setOnClickListener(mDpiListener); setDisplayDpi(SettingsStore.getInstance(getContext()).getDisplayDpi()); mWindowSizeEdit = findViewById(R.id.windowSize_edit); + mWindowSizeEdit.setHint1(String.valueOf(SettingsStore.WINDOW_WIDTH_DEFAULT)); + mWindowSizeEdit.setHint2(String.valueOf(SettingsStore.WINDOW_HEIGHT_DEFAULT)); + mWindowSizeEdit.setDefaultFirstValue(String.valueOf(SettingsStore.WINDOW_WIDTH_DEFAULT)); + mWindowSizeEdit.setDefaultFirstValue(String.valueOf(SettingsStore.WINDOW_HEIGHT_DEFAULT)); mWindowSizeEdit.setFirstText(Integer.toString(SettingsStore.getInstance(getContext()).getWindowWidth())); mWindowSizeEdit.setSecondText(Integer.toString(SettingsStore.getInstance(getContext()).getWindowHeight())); mWindowSizeEdit.setOnClickListener(mWindowSizeListener); @@ -106,6 +114,10 @@ private void initialize(Context aContext) { false); mMaxWindowSizeEdit = findViewById(R.id.maxWindowSize_edit); + mMaxWindowSizeEdit.setHint1(String.valueOf(SettingsStore.MAX_WINDOW_WIDTH_DEFAULT)); + mMaxWindowSizeEdit.setHint2(String.valueOf(SettingsStore.MAX_WINDOW_HEIGHT_DEFAULT)); + mMaxWindowSizeEdit.setDefaultFirstValue(String.valueOf(SettingsStore.MAX_WINDOW_WIDTH_DEFAULT)); + mMaxWindowSizeEdit.setDefaultFirstValue(String.valueOf(SettingsStore.MAX_WINDOW_HEIGHT_DEFAULT)); mMaxWindowSizeEdit.setFirstText(Integer.toString(SettingsStore.getInstance(getContext()).getMaxWindowWidth())); mMaxWindowSizeEdit.setSecondText(Integer.toString(SettingsStore.getInstance(getContext()).getMaxWindowHeight())); mMaxWindowSizeEdit.setOnClickListener(mMaxWindowSizeListener); @@ -134,18 +146,54 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) { } @Override - public void releaseWidget() { - mWidgetManager.removeFocusChangeListener(this); - mWidgetManager.removeWorldClickListener(this); + public void show() { + super.show(); - super.releaseWidget(); + mWidgetManager.addWorldClickListener(this); + mWidgetManager.addFocusChangeListener(this); + mScrollbar.scrollTo(0, 0); } @Override - public void show() { - super.show(); + public void hide(@HideFlags int aHideFlags) { + super.hide(aHideFlags); - mScrollbar.scrollTo(0, 0); + mDensityEdit.cancel(); + mDpiEdit.cancel(); + mWindowSizeEdit.cancel(); + mMaxWindowSizeEdit.cancel(); + + mWidgetManager.removeWorldClickListener(this); + mWidgetManager.removeFocusChangeListener(this); + } + + @Override + protected void onDismiss() { + boolean dismiss = true; + + if (mDensityEdit.isEditing()) { + dismiss = false; + mDensityEdit.cancel(); + } + + if (mDpiEdit.isEditing()) { + dismiss = false; + mDpiEdit.cancel(); + } + + if (mWindowSizeEdit.isEditing()) { + dismiss = false; + mWindowSizeEdit.cancel(); + } + + if (mMaxWindowSizeEdit.isEditing()) { + dismiss = false; + mMaxWindowSizeEdit.cancel(); + } + + if (dismiss) { + super.onDismiss(); + } } private void showRestartDialog() { @@ -175,41 +223,76 @@ private void onRestartDialogDismissed() { }; private OnClickListener mDensityListener = (view) -> { - float newDensity = Float.parseFloat(mDensityEdit.getFirstText()); - if (setDisplayDensity(newDensity)) { - showRestartDialog(); + try { + float newDensity = Float.parseFloat(mDensityEdit.getFirstText()); + if (setDisplayDensity(newDensity)) { + showRestartDialog(); + } + + } catch (NumberFormatException e) { + if (setDisplayDensity(SettingsStore.DISPLAY_DENSITY_DEFAULT)) { + showRestartDialog(); + } } }; private OnClickListener mDpiListener = (view) -> { - int newDpi = Integer.parseInt(mDpiEdit.getFirstText()); - if (setDisplayDpi(newDpi)) { - showRestartDialog(); + try { + int newDpi = Integer.parseInt(mDpiEdit.getFirstText()); + if (setDisplayDpi(newDpi)) { + showRestartDialog(); + } + + } catch (NumberFormatException e) { + if (setDisplayDpi(SettingsStore.DISPLAY_DPI_DEFAULT)) { + showRestartDialog(); + } } }; private OnClickListener mWindowSizeListener = (view) -> { - int newWindowWidth = Integer.parseInt(mWindowSizeEdit.getFirstText()); - int newWindowHeight = Integer.parseInt(mWindowSizeEdit.getSecondText()); - setWindowSize(newWindowWidth, newWindowHeight, true); + try { + int newWindowWidth = Integer.parseInt(mWindowSizeEdit.getFirstText()); + int newWindowHeight = Integer.parseInt(mWindowSizeEdit.getSecondText()); + setWindowSize(newWindowWidth, newWindowHeight, true); + + } catch (NumberFormatException e) { + setWindowSize(SettingsStore.WINDOW_WIDTH_DEFAULT, SettingsStore.WINDOW_HEIGHT_DEFAULT, true); + } }; private OnClickListener mMaxWindowSizeListener = (view) -> { - int newMaxWindowWidth = Integer.parseInt(mMaxWindowSizeEdit.getFirstText()); - int newMaxWindowHeight = Integer.parseInt(mMaxWindowSizeEdit.getSecondText()); - setMaxWindowSize(newMaxWindowWidth, newMaxWindowHeight, true); + try { + int newMaxWindowWidth = Integer.parseInt(mMaxWindowSizeEdit.getFirstText()); + int newMaxWindowHeight = Integer.parseInt(mMaxWindowSizeEdit.getSecondText()); + setMaxWindowSize(newMaxWindowWidth, newMaxWindowHeight, true); + + } catch (NumberFormatException e) { + setMaxWindowSize(SettingsStore.MAX_WINDOW_WIDTH_DEFAULT, SettingsStore.MAX_WINDOW_HEIGHT_DEFAULT, true); + } }; private OnClickListener mResetListener = (view) -> { boolean restart = false; - setUaMode(mUaModeRadio.getIdForValue(SettingsStore.UA_MODE_DEFAULT), true); - setMSAAMode(mMSAARadio.getIdForValue(SettingsStore.MSAA_DEFAULT_LEVEL), true); + if (!mUaModeRadio.getValueForId(mUaModeRadio.getCheckedRadioButtonId()).equals(SettingsStore.UA_MODE_DEFAULT)) { + setUaMode(mUaModeRadio.getIdForValue(SettingsStore.UA_MODE_DEFAULT), true); + } + if (!mMSAARadio.getValueForId(mMSAARadio.getCheckedRadioButtonId()).equals(SettingsStore.MSAA_DEFAULT_LEVEL)) { + setMSAAMode(mMSAARadio.getIdForValue(SettingsStore.MSAA_DEFAULT_LEVEL), true); + } restart = restart | setDisplayDensity(SettingsStore.DISPLAY_DENSITY_DEFAULT); restart = restart | setDisplayDpi(SettingsStore.DISPLAY_DPI_DEFAULT); - setWindowSize(SettingsStore.WINDOW_WIDTH_DEFAULT, SettingsStore.WINDOW_HEIGHT_DEFAULT, true); - setMaxWindowSize(SettingsStore.MAX_WINDOW_WIDTH_DEFAULT, SettingsStore.MAX_WINDOW_HEIGHT_DEFAULT, true); + + if (Integer.parseInt(mWindowSizeEdit.getFirstText()) != SettingsStore.WINDOW_WIDTH_DEFAULT || + Integer.parseInt(mWindowSizeEdit.getSecondText()) != SettingsStore.WINDOW_HEIGHT_DEFAULT) { + setWindowSize(SettingsStore.WINDOW_WIDTH_DEFAULT, SettingsStore.WINDOW_HEIGHT_DEFAULT, true); + } + if (Integer.parseInt(mMaxWindowSizeEdit.getFirstText()) != SettingsStore.MAX_WINDOW_WIDTH_DEFAULT || + Integer.parseInt(mMaxWindowSizeEdit.getSecondText()) != SettingsStore.MAX_WINDOW_HEIGHT_DEFAULT) { + setMaxWindowSize(SettingsStore.MAX_WINDOW_WIDTH_DEFAULT, SettingsStore.MAX_WINDOW_HEIGHT_DEFAULT, true); + } if (restart) showRestartDialog(); @@ -349,6 +432,25 @@ private void setMaxWindowSize(int newMaxWindowWidth, int newMaxWindowHeight, boo @Override public void onGlobalFocusChanged(View oldFocus, View newFocus) { + if (oldFocus != null) { + if (mDensityEdit.contains(oldFocus) && mDensityEdit.isEditing()) { + mDensityEdit.cancel(); + } + if (mDpiEdit.contains(oldFocus) && mDpiEdit.isEditing()) { + mDpiEdit.cancel(); + } + if (mWindowSizeEdit.contains(oldFocus) && + (newFocus != null && !mWindowSizeEdit.contains(newFocus)) && + mWindowSizeEdit.isEditing()) { + mWindowSizeEdit.cancel(); + } + if (mMaxWindowSizeEdit.contains(oldFocus) && + (newFocus != null && !mMaxWindowSizeEdit.contains(newFocus)) && + mMaxWindowSizeEdit.isEditing()) { + mMaxWindowSizeEdit.cancel(); + } + } + if (oldFocus == this && isVisible() && findViewById(newFocus.getId()) == null) { onDismiss(); } diff --git a/app/src/main/res/drawable/settings_edit_cursor.xml b/app/src/main/res/drawable/settings_edit_cursor.xml new file mode 100644 index 000000000..9ae6ff724 --- /dev/null +++ b/app/src/main/res/drawable/settings_edit_cursor.xml @@ -0,0 +1,6 @@ + + + + !--Could be any color you want + \ No newline at end of file diff --git a/app/src/main/res/layout/options_developer.xml b/app/src/main/res/layout/options_developer.xml index 286deae54..6a901a315 100644 --- a/app/src/main/res/layout/options_developer.xml +++ b/app/src/main/res/layout/options_developer.xml @@ -45,6 +45,15 @@ android:layout_height="wrap_content" android:orientation="vertical"> + + + app:description="@string/developer_options_display_density" + app:highlightedTextColor="@color/fog" + android:maxLength="4" + android:inputType="numberDecimal" + android:width="75dp" /> + app:description="@string/developer_options_display_dpi" + app:highlightedTextColor="@color/fog" + android:maxLength="4" + android:inputType="number" + android:width="75dp" /> + app:description="@string/developer_options_window_size" + app:highlightedTextColor="@color/fog" + android:maxLength="4" + android:inputType="number" + android:width="75dp" /> + app:description="@string/developer_options_max_window_size" + app:highlightedTextColor="@color/fog" + android:maxLength="4" + android:inputType="number" + android:width="75dp" /> diff --git a/app/src/main/res/layout/setting_edit.xml b/app/src/main/res/layout/setting_edit.xml index 85a0b4619..d96e9b819 100644 --- a/app/src/main/res/layout/setting_edit.xml +++ b/app/src/main/res/layout/setting_edit.xml @@ -16,14 +16,16 @@ android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_centerVertical="true" + android:layout_marginEnd="10dp" + android:layout_toLeftOf="@+id/settingButton" android:gravity="center_vertical" android:orientation="horizontal"> - @@ -50,15 +50,13 @@ - diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 5d8ff8942..faa420370 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -36,6 +36,10 @@ + + + + diff --git a/app/src/main/res/values/non_L10n.xml b/app/src/main/res/values/non_L10n.xml index 4da57a909..3f87e27e0 100644 --- a/app/src/main/res/values/non_L10n.xml +++ b/app/src/main/res/values/non_L10n.xml @@ -1,6 +1,8 @@ Firefox Reality mzl.la/fxr + https://webxr.today/ + settings_homepage settings_crash settings_locale settings_telemetry diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9ea266ab4..b4eee2ad0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -265,6 +265,10 @@ White + + Homepage + On @@ -507,4 +511,7 @@

Private Browsing doesn’t make you anonymous on the Internet. Your employer or Internet service provider can still know what page you visit.

Learn more about Private Browsing.

]]> + + + Firefox Home (Default)
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index af6fef2a9..72924fe95 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -156,12 +156,11 @@