Skip to content

Commit

Permalink
Fixes #350 Personalized homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Dec 18, 2018
1 parent f4868c7 commit 177891b
Show file tree
Hide file tree
Showing 18 changed files with 408 additions and 126 deletions.
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 @@ -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,7 @@ public class DoubleEditSetting extends SingleEditSetting {

private String mBy;
private TextView mText2;
private EditText mEdit2;
private SettingsEditText mEdit2;

public DoubleEditSetting(Context context, AttributeSet attrs) {
this(context, attrs, 0);
Expand All @@ -39,20 +40,28 @@ private void initialize(Context aContext) {
mText2.setOnClickListener(mText2ClickListener);

mEdit2 = findViewById(R.id.editValue2);
mEdit2.setHighlightedTextColor(mHighlightedTextColor);
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);
}
Expand All @@ -66,4 +75,16 @@ public void setSecondText(String 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);
}

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

}

0 comments on commit 177891b

Please sign in to comment.