Skip to content

Commit 4b02aea

Browse files
authored
Fixes Igalia#350 Personalized homepage (Igalia#891)
* Fixes Igalia#350 Personalized homepage * Select homepage text field when it's the default value
1 parent 3409459 commit 4b02aea

22 files changed

+528
-156
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ Restart FxR and close and re-open the WebIDE page.
139139
- 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.
140140
- 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`
141141
- 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
142+
- 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
142143
- 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.
143144
- You can set `disableCrashRestart=true` in the gradle `user.properties` to disable app relaunch on crash.
144145

app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java

+6
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,12 @@ void loadFromIntent(final Intent intent) {
322322
uri = Uri.parse(intent.getExtras().getString("url"));
323323
}
324324

325+
Bundle extras = intent.getExtras();
326+
if (extras != null && extras.containsKey("homepage")) {
327+
Uri homepageUri = Uri.parse(extras.getString("homepage"));
328+
SettingsStore.getInstance(this).setHomepage(homepageUri.toString());
329+
}
330+
325331
if (SessionStore.get().getCurrentSession() == null) {
326332
String url = (uri != null ? uri.toString() : null);
327333
int id = SessionStore.get().createSession();

app/src/common/shared/org/mozilla/vrbrowser/browser/SessionStore.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public static SessionStore get() {
7070
return mInstance;
7171
}
7272
// You can test a local file using: "resource://android/assets/webvr/index.html"
73-
private static final String HOME_WITHOUT_REGION_ORIGIN = "https://webxr.today/";
7473
public static final String PRIVATE_BROWSING_URI = "about:privatebrowsing";
7574
public static final int NO_SESSION_ID = -1;
7675

@@ -342,6 +341,7 @@ int createSession(SessionSettings aSettings) {
342341

343342
int result = state.mSession.hashCode();
344343
mSessions.put(result, state);
344+
345345
state.mSession.getSettings().setBoolean(GeckoSessionSettings.USE_MULTIPROCESS, aSettings.multiprocess);
346346
state.mSession.getSettings().setBoolean(GeckoSessionSettings.USE_PRIVATE_MODE, aSettings.privateMode);
347347
state.mSession.getSettings().setBoolean(GeckoSessionSettings.USE_TRACKING_PROTECTION, aSettings.trackingProtection);
@@ -492,15 +492,17 @@ public void setRegion(String aRegion) {
492492
}
493493

494494
public String getHomeUri() {
495-
String result = SessionStore.HOME_WITHOUT_REGION_ORIGIN;
496-
if (mRegion != null) {
497-
result = SessionStore.HOME_WITHOUT_REGION_ORIGIN + "?region=" + mRegion;
495+
String homepage = SettingsStore.getInstance(mContext).getHomepage();
496+
if (homepage.equals(mContext.getString(R.string.homepage_url)) && mRegion != null) {
497+
homepage = homepage + "?region=" + mRegion;
498498
}
499-
return result;
499+
return homepage;
500500
}
501501

502502
public Boolean isHomeUri(String aUri) {
503-
return aUri != null && aUri.toLowerCase().startsWith(SessionStore.HOME_WITHOUT_REGION_ORIGIN);
503+
return aUri != null && aUri.toLowerCase().startsWith(
504+
SettingsStore.getInstance(mContext).getHomepage()
505+
);
504506
}
505507

506508
public String getCurrentUri() {
@@ -906,7 +908,7 @@ public void onLocationChange(GeckoSession aSession, String aUri) {
906908
}
907909

908910
// The homepage finishes loading after the region has been updated
909-
if (mRegion != null && aUri.equalsIgnoreCase(SessionStore.HOME_WITHOUT_REGION_ORIGIN)) {
911+
if (mRegion != null && aUri.equalsIgnoreCase(SettingsStore.getInstance(mContext).getHomepage())) {
910912
aSession.loadUri("javascript:window.location.replace('" + getHomeUri() + "');");
911913
}
912914
}

app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java

+11
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,17 @@ public void setInputMode(int aTouchMode) {
187187
editor.commit();
188188
}
189189

190+
public String getHomepage() {
191+
return mPrefs.getString(
192+
mContext.getString(R.string.settings_key_homepage),
193+
mContext.getString(R.string.homepage_url));
194+
}
195+
196+
public void setHomepage(String aHomepage) {
197+
SharedPreferences.Editor editor = mPrefs.edit();
198+
editor.putString(mContext.getString(R.string.settings_key_homepage), aHomepage);
199+
editor.commit();
200+
}
190201

191202
public float getDisplayDensity() {
192203
return mPrefs.getFloat(

app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/ButtonSetting.java

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ protected void onClickListener(View v) {
5656
if (mListener != null) {
5757
mListener.onClick(v);
5858
}
59+
60+
v.requestFocus();
5961
}
6062

6163
public void setOnClickListener(OnClickListener aListener) {

app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/DoubleEditSetting.java

+54-11
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import android.content.Context;
44
import android.content.res.TypedArray;
5+
import android.text.InputFilter;
6+
import android.text.InputType;
57
import android.util.AttributeSet;
68
import android.view.View;
7-
import android.widget.EditText;
89
import android.widget.TextView;
910

1011
import org.mozilla.vrbrowser.R;
@@ -13,7 +14,8 @@ public class DoubleEditSetting extends SingleEditSetting {
1314

1415
private String mBy;
1516
private TextView mText2;
16-
private EditText mEdit2;
17+
private SettingsEditText mEdit2;
18+
private String mDefaultSecondValue;
1719

1820
public DoubleEditSetting(Context context, AttributeSet attrs) {
1921
this(context, attrs, 0);
@@ -39,31 +41,72 @@ private void initialize(Context aContext) {
3941
mText2.setOnClickListener(mText2ClickListener);
4042

4143
mEdit2 = findViewById(R.id.editValue2);
44+
mEdit2.setHighlightedTextColor(mHighlightedTextColor);
45+
mEdit2.setHighlightedTextColor(mHighlightedTextColor);
46+
mEdit2.setOnClickListener(view -> {
47+
if (mEdit2.getText().toString().equals(mEdit2.getHint())) {
48+
mEdit2.requestFocus();
49+
mEdit2.selectAll();
50+
}
51+
});
4252
mEdit2.setSoundEffectsEnabled(false);
43-
mEdit2.setOnTouchListener((v, event) -> updateTouchTextSelection(v));
44-
mEdit2.setOnFocusChangeListener((v, hasFocus) -> updateFocusTextSelection(v, hasFocus));
45-
mEdit2.addTextChangedListener(new TextColorTextWatcher(mEdit2));
46-
mEdit2.setOnClickListener(v -> mEdit2.selectAll());
53+
if (mMaxLength != 0) {
54+
mEdit2.setFilters(new InputFilter[]{
55+
new InputFilter.LengthFilter(mMaxLength)
56+
});
57+
}
58+
if (mInputType != InputType.TYPE_NULL) {
59+
mEdit2.setInputType(mInputType);
60+
}
61+
if (mWidth > 0) {
62+
mEdit2.setWidth((int)mWidth);
63+
}
4764

4865
mEdit2.setOnEditorActionListener(mInternalEditorActionListener);
4966
}
5067

5168
private OnClickListener mText2ClickListener = v -> mButton.performClick();
5269

5370
protected void onClickListener(View v) {
54-
mText2.setVisibility(mEdit1.getVisibility());
55-
mEdit2.setVisibility(mEdit1.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
71+
mText2.setVisibility(mEdit2.getVisibility());
72+
mEdit2.setVisibility(mEdit2.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
5673

5774
super.onClickListener(v);
5875
}
5976

77+
public void setDefaultSecondValue(String value) {
78+
mDefaultSecondValue = value;
79+
}
80+
6081
public String getSecondText() {
61-
return mEdit2.getText().toString();
82+
return mEdit2.getText().equals(mEdit2.getHint()) ? mDefaultSecondValue : mEdit2.getText().toString();
6283
}
6384

6485
public void setSecondText(String text) {
65-
mText2.setText(text);
66-
mEdit2.setText(text);
86+
if (text.equals(mDefaultSecondValue)) {
87+
mText2.setText(mEdit2.getHint());
88+
mEdit2.setText(mEdit2.getHint());
89+
90+
} else {
91+
mText2.setText(text);
92+
mEdit2.setText(text);
93+
}
94+
}
95+
96+
public void setHint2(String hint) {
97+
mEdit2.setHint(hint);
98+
}
99+
100+
@Override
101+
public void cancel() {
102+
super.cancel();
103+
104+
mText2.setVisibility(VISIBLE);
105+
mEdit2.setVisibility(View.GONE);
106+
107+
if (mEdit2.length() == 0) {
108+
setSecondText(mDefaultSecondValue != null ? mDefaultSecondValue : mText2.getText().toString());
109+
}
67110
}
68111

69112
}

app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/RadioGroupSetting.java

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Context;
44
import android.content.res.TypedArray;
5+
import android.text.InputType;
56
import android.util.AttributeSet;
67
import android.util.TypedValue;
78
import android.view.ContextThemeWrapper;
@@ -75,6 +76,7 @@ protected void initialize(Context aContext, @LayoutRes int layout) {
7576

7677
for (int i=0; i<mOptions.length; i++) {
7778
RadioButton button = new RadioButton(new ContextThemeWrapper(getContext(), R.style.radioButtonTheme), null, 0);
79+
button.setInputType(InputType.TYPE_NULL);
7880
button.setClickable(true);
7981
button.setId(i);
8082
button.setText(mOptions[i]);
@@ -93,6 +95,7 @@ public void onCheckedChanged(RadioGroup compoundButton, @IdRes int checkedId) {
9395
}
9496

9597
setChecked(checkedId, true);
98+
compoundButton.requestFocus();
9699
}
97100
};
98101

app/src/common/shared/org/mozilla/vrbrowser/ui/views/settings/RadioGroupVSetting.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.mozilla.vrbrowser.ui.views.settings;
22

33
import android.content.Context;
4+
import android.text.InputType;
45
import android.util.AttributeSet;
56
import android.widget.RadioButton;
67

@@ -22,6 +23,7 @@ protected void initialize(Context aContext, @LayoutRes int layout) {
2223

2324
for (int i=0; i<mRadioGroup.getChildCount(); i++) {
2425
RadioButton button = (RadioButton)mRadioGroup.getChildAt(i);
26+
button.setInputType(InputType.TYPE_NULL);
2527
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
2628
params.topMargin = 20;
2729
params.bottomMargin = 20;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package org.mozilla.vrbrowser.ui.views.settings;
2+
3+
import android.annotation.SuppressLint;
4+
import android.content.Context;
5+
import android.text.Editable;
6+
import android.text.TextWatcher;
7+
import android.text.style.ForegroundColorSpan;
8+
import android.util.AttributeSet;
9+
import android.view.View;
10+
import android.widget.EditText;
11+
12+
import androidx.annotation.Nullable;
13+
14+
@SuppressLint("AppCompatCustomView")
15+
public class SettingsEditText extends EditText {
16+
17+
private int mNormalTextColor = 0;
18+
private int mHighlightedTextColor = 0;
19+
20+
public SettingsEditText(Context context) {
21+
super(context);
22+
initialize();
23+
}
24+
25+
public SettingsEditText(Context context, @Nullable AttributeSet attrs) {
26+
super(context, attrs);
27+
initialize();
28+
}
29+
30+
public SettingsEditText(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
31+
super(context, attrs, defStyleAttr);
32+
initialize();
33+
}
34+
35+
private void initialize() {
36+
mNormalTextColor = getTextColors().getColorForState(View.EMPTY_STATE_SET, 0);
37+
addTextChangedListener(watcher);
38+
39+
setOnFocusChangeListener((view, b) -> {
40+
if (hasSelection()) {
41+
if (b) {
42+
int start = getSelectionStart();
43+
int end = getSelectionEnd();
44+
if (end < start) {
45+
int tmp = end;
46+
end = start;
47+
start = tmp;
48+
}
49+
50+
ForegroundColorSpan highlightedColor = new ForegroundColorSpan(mHighlightedTextColor);
51+
getText().setSpan(highlightedColor, start, end, 0);
52+
53+
} else {
54+
ForegroundColorSpan normalColor = new ForegroundColorSpan(mNormalTextColor);
55+
getText().setSpan(normalColor, 0, length(), 0);
56+
}
57+
58+
} else {
59+
ForegroundColorSpan normalColor = new ForegroundColorSpan(mNormalTextColor);
60+
getText().setSpan(normalColor, 0, length(), 0);
61+
}
62+
});
63+
}
64+
65+
TextWatcher watcher = new TextWatcher() {
66+
@Override
67+
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
68+
ForegroundColorSpan normalColor = new ForegroundColorSpan(mNormalTextColor);
69+
getText().setSpan(normalColor, 0, length(), 0);
70+
}
71+
72+
@Override
73+
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
74+
75+
}
76+
77+
@Override
78+
public void afterTextChanged(Editable editable) {
79+
80+
}
81+
};
82+
83+
@Override
84+
protected void onSelectionChanged(int selStart, int selEnd) {
85+
super.onSelectionChanged(selStart, selEnd);
86+
87+
if (getTextColors() != null) {
88+
handleTextColor();
89+
}
90+
}
91+
92+
private void handleTextColor() {
93+
if (mHighlightedTextColor == 0) {
94+
mHighlightedTextColor = mNormalTextColor;
95+
}
96+
97+
if (isPressed()) {
98+
ForegroundColorSpan normalColor = new ForegroundColorSpan(mNormalTextColor);
99+
getText().setSpan(normalColor, 0, length(), 0);
100+
}
101+
102+
if (hasSelection()) {
103+
int start = getSelectionStart();
104+
int end = getSelectionEnd();
105+
if (end < start) {
106+
int tmp = end;
107+
end = start;
108+
start = tmp;
109+
}
110+
111+
ForegroundColorSpan normalColor = new ForegroundColorSpan(mNormalTextColor);
112+
getText().setSpan(normalColor, 0, length(), 0);
113+
ForegroundColorSpan highlightedColor = new ForegroundColorSpan(mHighlightedTextColor);
114+
getText().setSpan(highlightedColor, start, end, 0);
115+
}
116+
}
117+
118+
public void setHighlightedTextColor(int color) {
119+
mHighlightedTextColor = color;
120+
}
121+
122+
}

0 commit comments

Comments
 (0)