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 17, 2018
1 parent 91d4710 commit 51a323e
Show file tree
Hide file tree
Showing 17 changed files with 304 additions and 76 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,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 @@ -328,6 +328,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,7 +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.GestureDetector;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
Expand Down Expand Up @@ -40,10 +43,32 @@ private void initialize(Context aContext) {

mEdit2 = findViewById(R.id.editValue2);
mEdit2.setSoundEffectsEnabled(false);
mEdit2.setOnTouchListener((v, event) -> updateTouchTextSelection(v));
mEdit2.setOnFocusChangeListener((v, hasFocus) -> updateFocusTextSelection(v, hasFocus));
final GestureDetector gestureDetector = new GestureDetector(getContext(), new GestureListener());
gestureDetector.setOnDoubleTapListener(new DoubleTapListener(mEdit2));
mEdit2.setOnTouchListener((view, motionEvent) -> {
if (gestureDetector.onTouchEvent(motionEvent)) {
return true;
}
return view.onTouchEvent(motionEvent);
});
mEdit2.setOnFocusChangeListener((v, hasFocus) -> {
if (mEdit2.getSelectionStart() == mEdit2.getSelectionEnd()) {
mEdit2.setTextColor(mEditTextColor);
}
});
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);
}
Expand All @@ -66,4 +91,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
Expand Up @@ -4,9 +4,15 @@
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType;
import android.text.SpannableString;
import android.text.TextWatcher;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
Expand All @@ -22,13 +28,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;
protected TextView mButton;
private OnClickListener mListener;
private int mEditTextSelectedColor;
private int mEditTextUnelectedColor;
protected int mEditTextSelectedColor;
protected int mEditTextColor;

public SingleEditSetting(Context context, AttributeSet attrs) {
this(context, attrs, 0);
Expand All @@ -39,8 +48,9 @@ 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);
initialize(context);
}

Expand All @@ -62,11 +72,27 @@ private void initialize(Context aContext) {
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));
mEditTextColor = colors.getColorForState(View.EMPTY_STATE_SET, R.color.asphalt);
final GestureDetector gestureDetector = new GestureDetector(getContext(), new GestureListener());
gestureDetector.setOnDoubleTapListener(new DoubleTapListener(mEdit1));
mEdit1.setOnTouchListener((view, motionEvent) -> gestureDetector.onTouchEvent(motionEvent));
mEdit1.setOnFocusChangeListener((v, hasFocus) -> {
if (mEdit1.getSelectionStart() == mEdit1.getSelectionEnd()) {
mEdit1.setTextColor(mEditTextColor);
}
});
mEdit1.addTextChangedListener(new TextColorTextWatcher(mEdit1));
mEdit1.setOnClickListener(v -> mEdit1.selectAll());
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);
Expand Down Expand Up @@ -114,6 +140,10 @@ public void setFirstText(String text) {
mEdit1.setText(text);
}

public void setHint1(String hint) {
mEdit1.setHint(hint);
}

public void setOnClickListener(OnClickListener aListener) {
mListener = aListener;
}
Expand All @@ -130,57 +160,65 @@ public boolean isEditing() {
return mEdit1.getVisibility() == View.VISIBLE;
}

protected boolean updateTouchTextSelection(View v) {
EditText editText = (EditText) v;
if (editText.hasSelection()) {
editText.setTextColor(mEditTextSelectedColor);
protected class TextColorTextWatcher implements TextWatcher {

private EditText mEditText;

} else {
editText.setTextColor(mEditTextUnelectedColor);
public TextColorTextWatcher(EditText view) {
mEditText = view;
}

editText.requestFocusFromTouch();

return false;
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

protected void updateFocusTextSelection(View v, boolean hasFocus) {
EditText editText = (EditText) v;
if (editText.hasSelection()) {
if (hasFocus) {
editText.setTextColor(mEditTextSelectedColor);
}

} else {
editText.setTextColor(mEditTextUnelectedColor);
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
mEditText.setTextColor(mEditTextColor);
}

@Override
public void afterTextChanged(Editable s) {

} else {
editText.setTextColor(mEditTextUnelectedColor);
}
}

protected class TextColorTextWatcher implements TextWatcher {
protected class GestureListener extends GestureDetector.SimpleOnGestureListener {

@Override
public boolean onDoubleTap(MotionEvent event) {
return false;
}
}

protected class DoubleTapListener implements GestureDetector.OnDoubleTapListener {

private EditText mEditText;

public TextColorTextWatcher(EditText view) {
public DoubleTapListener(EditText view) {
mEditText = view;
}

@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
mEditText.setTextColor(mEditTextColor);
return false;
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
mEditText.setTextColor(mEditTextUnelectedColor);
public boolean onDoubleTap(MotionEvent motionEvent) {
mEditText.selectAll();
mEditText.setTextColor(mEditTextSelectedColor);
return false;
}

@Override
public void afterTextChanged(Editable s) {

public boolean onDoubleTapEvent(MotionEvent motionEvent) {
mEditText.selectAll();
return false;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -321,8 +320,6 @@ private void showDeveloperOptionsDialog() {
}

widget.show();

mCurrentlyOpenedDialogHandle = mDeveloperOptionsDialogHandle;
}

private void showLanguageOptionsDialog() {
Expand All @@ -336,8 +333,6 @@ private void showLanguageOptionsDialog() {
}

widget.show();

mCurrentlyOpenedDialogHandle = mLanguageOptionsDialogHandle;
}

private void showDisplayOptionsDialog() {
Expand All @@ -351,8 +346,6 @@ private void showDisplayOptionsDialog() {
}

widget.show();

mCurrentlyOpenedDialogHandle = mDisplayOptionsDialogHandle;
}

private void onOptionsDialogDismissed() {
Expand Down

0 comments on commit 51a323e

Please sign in to comment.