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 14, 2018
1 parent 91d4710 commit 0cc68c4
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 24 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 "http://keianhzo.artstation.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;
String result = SettingsStore.getInstance(mContext).getHomepage();
if (mRegion != null) {
result = SessionStore.HOME_WITHOUT_REGION_ORIGIN + "?region=" + mRegion;
result = result + "?region=" + mRegion;
}
return result;
}

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 @@ -36,6 +36,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
private SharedPreferences mPrefs;

// Developer options default values
public final static String HOMEPAGE_DEFAULT = "https://webxr.today/";
public final static boolean REMOTE_DEBUGGING_DEFAULT = false;
public final static boolean CONSOLE_LOGS_DEFAULT = false;
public final static boolean ENV_OVERRIDE_DEFAULT = false;
Expand Down Expand Up @@ -187,6 +188,15 @@ public void setInputMode(int aTouchMode) {
editor.commit();
}

public String getHomepage() {
return mPrefs.getString(mContext.getString(R.string.settings_key_homepage), HOMEPAGE_DEFAULT);
}

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,6 +2,8 @@

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;
Expand Down Expand Up @@ -44,6 +46,17 @@ private void initialize(Context aContext) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
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.TextWatcher;
import android.util.AttributeSet;
import android.view.KeyEvent;
Expand All @@ -22,6 +24,9 @@ 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;
Expand All @@ -39,8 +44,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 @@ -67,6 +73,17 @@ private void initialize(Context aContext) {
mEdit1.setOnFocusChangeListener((v, hasFocus) -> updateFocusTextSelection(v, hasFocus));
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.mozilla.vrbrowser.ui.widgets.options;

import android.content.Context;
import android.provider.Settings;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ScrollView;
Expand All @@ -17,6 +18,7 @@
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;
Expand All @@ -41,6 +43,8 @@ public class DeveloperOptionsWidget extends UIWidget implements
private RadioGroupSetting mEnvironmentsRadio;
private RadioGroupSetting mPointerColorRadio;

private SingleEditSetting mHomepageEdit;

private ButtonSetting mResetButton;

private int mRestartDialogHandle = -1;
Expand Down Expand Up @@ -78,6 +82,11 @@ private void initialize(Context aContext) {
onDismiss();
});

mHomepageEdit = findViewById(R.id.homepage_edit);
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);
Expand Down Expand Up @@ -146,6 +155,18 @@ public void show() {
mScrollbar.scrollTo(0, 0);
}

@Override
protected void onDismiss() {
SettingsStore settings = SettingsStore.getInstance(getContext());
if (mHomepageEdit.isEditing()) {
mHomepageEdit.setFirstText(settings.getHomepage());
mHomepageEdit.cancel();

} else {
super.onDismiss();
}
}

private void showRestartDialog() {
hide(UIWidget.REMOVE_WIDGET);

Expand All @@ -163,6 +184,10 @@ private void onRestartDialogDismissed() {
show();
}

private OnClickListener mHomepageListener = (view) -> {
setHomepage(mHomepageEdit.getFirstText());
};

private SwitchSetting.OnCheckedChangeListener mRemoteDebuggingListener = (compoundButton, value, doApply) -> {
setRemoteDebugging(value, doApply);
};
Expand Down Expand Up @@ -216,6 +241,19 @@ private void onRestartDialogDismissed() {
showRestartDialog();
};

private void setHomepage(String newHomepage) {
mHomepageEdit.setOnClickListener(null);
String prevHomepage = SettingsStore.getInstance(getContext()).getHomepage();
if (!newHomepage.isEmpty()) {
mHomepageEdit.setFirstText(newHomepage);
SettingsStore.getInstance(getContext()).setHomepage(newHomepage);

} else {
mHomepageEdit.setFirstText(prevHomepage);
}
mHomepageEdit.setOnClickListener(mHomepageListener);
}

private void setRemoteDebugging(boolean value, boolean doApply) {
mRemoteDebuggingSwitch.setOnCheckedChangeListener(null);
mRemoteDebuggingSwitch.setValue(value, doApply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,32 @@ public void show() {
mScrollbar.scrollTo(0, 0);
}

@Override
protected void onDismiss() {
SettingsStore settings = SettingsStore.getInstance(getContext());
if (mDensityEdit.isEditing()) {
mDensityEdit.setFirstText(String.valueOf(settings.getDisplayDensity()));
mDensityEdit.cancel();

} else if (mDpiEdit.isEditing()) {
mDpiEdit.setFirstText(String.valueOf(settings.getDisplayDpi()));
mDpiEdit.cancel();

} else if (mWindowSizeEdit.isEditing()) {
mWindowSizeEdit.setFirstText(String.valueOf(settings.getWindowWidth()));
mWindowSizeEdit.setSecondText(String.valueOf(settings.getWindowHeight()));
mWindowSizeEdit.cancel();

} else if (mMaxWindowSizeEdit.isEditing()) {
mMaxWindowSizeEdit.setFirstText(String.valueOf(settings.getMaxWindowWidth()));
mMaxWindowSizeEdit.setSecondText(String.valueOf(settings.getMaxWindowHeight()));
mMaxWindowSizeEdit.cancel();

} else {
super.onDismiss();
}
}

private void showRestartDialog() {
hide(UIWidget.REMOVE_WIDGET);

Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout/options_developer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@
android:layout_height="wrap_content"
android:orientation="vertical">

<org.mozilla.vrbrowser.ui.views.settings.SingleEditSetting
android:id="@+id/homepage_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:description="@string/developer_options_homepage"
android:inputType="textWebEmailAddress"
android:width="300dp" />

<org.mozilla.vrbrowser.ui.views.settings.SwitchSetting
android:id="@+id/remote_debugging_switch"
android:layout_width="match_parent"
Expand Down
20 changes: 16 additions & 4 deletions app/src/main/res/layout/options_display.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,39 @@
android:id="@+id/density_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:description="@string/developer_options_display_density" />
app:description="@string/developer_options_display_density"
android:maxLength="4"
android:inputType="number"
android:width="75dp" />

<org.mozilla.vrbrowser.ui.views.settings.SingleEditSetting
android:id="@+id/dpi_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:description="@string/developer_options_display_dpi" />
app:description="@string/developer_options_display_dpi"
android:maxLength="4"
android:inputType="number"
android:width="75dp" />

<org.mozilla.vrbrowser.ui.views.settings.DoubleEditSetting
android:id="@+id/windowSize_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:by="@string/developer_options_by"
app:description="@string/developer_options_window_size" />
app:description="@string/developer_options_window_size"
android:maxLength="4"
android:inputType="number"
android:width="75dp" />

<org.mozilla.vrbrowser.ui.views.settings.DoubleEditSetting
android:id="@+id/maxWindowSize_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:by="@string/developer_options_by"
app:description="@string/developer_options_max_window_size" />
app:description="@string/developer_options_max_window_size"
android:maxLength="4"
android:inputType="number"
android:width="75dp" />
</LinearLayout>
</ScrollView>

Expand Down

0 comments on commit 0cc68c4

Please sign in to comment.