Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #350 Personalized homepage #891

Merged
merged 2 commits into from
Dec 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() + "');");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ protected void onClickListener(View v) {
if (mListener != null) {
mListener.onClick(v);
}

v.requestFocus();
}

public void setOnClickListener(OnClickListener aListener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -39,31 +41,72 @@ 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);
}

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());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,6 +76,7 @@ protected void initialize(Context aContext, @LayoutRes int layout) {

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

setChecked(checkedId, true);
compoundButton.requestFocus();
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.mozilla.vrbrowser.ui.views.settings;

import android.content.Context;
import android.text.InputType;
import android.util.AttributeSet;
import android.widget.RadioButton;

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

for (int i=0; i<mRadioGroup.getChildCount(); i++) {
RadioButton button = (RadioButton)mRadioGroup.getChildAt(i);
button.setInputType(InputType.TYPE_NULL);
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
params.topMargin = 20;
params.bottomMargin = 20;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package org.mozilla.vrbrowser.ui.views.settings;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;

import androidx.annotation.Nullable;

@SuppressLint("AppCompatCustomView")
public class SettingsEditText extends EditText {

private int mNormalTextColor = 0;
private int mHighlightedTextColor = 0;

public SettingsEditText(Context context) {
super(context);
initialize();
}

public SettingsEditText(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initialize();
}

public SettingsEditText(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize();
}

private void initialize() {
mNormalTextColor = getTextColors().getColorForState(View.EMPTY_STATE_SET, 0);
addTextChangedListener(watcher);

setOnFocusChangeListener((view, b) -> {
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;
}

}