Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Servo toggles
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrouget committed Oct 3, 2018
1 parent e74a8ea commit 4433afe
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 3 deletions.
12 changes: 12 additions & 0 deletions app/src/common/shared/org/mozilla/vrbrowser/SettingsStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
public final static boolean CONSOLE_LOGS_DEFAULT = false;
public final static boolean ENV_OVERRIDE_DEFAULT = false;
public final static boolean MULTIPROCESS_DEFAULT = false;
public final static boolean SERVO_DEFAULT = false;
public final static DeveloperOptionsWidget.UaMode UA_MODE_DEFAULT = DeveloperOptionsWidget.UaMode.MOBILE;
public final static DeveloperOptionsWidget.InputMode INPUT_MODE_DEFAULT = DeveloperOptionsWidget.InputMode.TOUCH;
public final static float DISPLAY_DENSITY_DEFAULT = 1.0f;
Expand Down Expand Up @@ -148,6 +149,17 @@ public void setMultiprocessEnabled(boolean isEnabled) {
editor.commit();
}

public boolean isServoEnabled() {
return mPrefs.getBoolean(
mContext.getString(R.string.settings_key_servo), SERVO_DEFAULT);
}

public void setServoEnabled(boolean isEnabled) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(mContext.getString(R.string.settings_key_servo), isEnabled);
editor.commit();
}

public int getUaMode() {
return mPrefs.getInt(
mContext.getString(R.string.settings_key_desktop_version), UA_MODE_DEFAULT.ordinal());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public enum UaMode {
private Switch mConsoleLogsSwitch;
private Switch mEnvOverrideSwitch;
private Switch mMultiprocessSwitch;
private Switch mServoSwitch;
private RadioGroup mUaModeRadio;
private RadioButton mDesktopRadio;
private RadioButton mRadioMobile;
Expand Down Expand Up @@ -80,6 +81,7 @@ public enum UaMode {
private TextView mConsoleLogsSwitchText;
private TextView mEnvOverrideSwitchText;
private TextView mMultiprocessSwitchText;
private TextView mServoSwitchText;
private int mRestartDialogHandle = -1;

public DeveloperOptionsWidget(Context aContext) {
Expand Down Expand Up @@ -161,6 +163,12 @@ public void onClick(View view) {
mMultiprocessSwitch.setSoundEffectsEnabled(false);
setMultiprocess(SettingsStore.getInstance(getContext()).isMultiprocessEnabled(), false);

mServoSwitchText = findViewById(R.id.developer_options_servo_switch_text);
mServoSwitch = findViewById(R.id.developer_options_servo_switch);
mServoSwitch.setOnCheckedChangeListener(mServoListener);
mServoSwitch.setSoundEffectsEnabled(false);
setServo(SettingsStore.getInstance(getContext()).isServoEnabled(), false);

UaMode uaMode = UaMode.values()[SettingsStore.getInstance(getContext()).getUaMode()];
mUaModeRadio = findViewById(R.id.radioUaMode);
mUaModeRadio.setSoundEffectsEnabled(false);
Expand Down Expand Up @@ -389,6 +397,17 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
}
};

private CompoundButton.OnCheckedChangeListener mServoListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}

setServo(b, true);
}
};

private RadioGroup.OnCheckedChangeListener mUaModeListener = new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
Expand Down Expand Up @@ -575,6 +594,7 @@ public void onClick(View view) {
}

setMultiprocess(SettingsStore.MULTIPROCESS_DEFAULT, true);
setServo(SettingsStore.SERVO_DEFAULT, true);
setUaMode(SettingsStore.UA_MODE_DEFAULT, true);
setInputMode(SettingsStore.INPUT_MODE_DEFAULT);
restart = restart | setDisplayDensity(SettingsStore.DISPLAY_DENSITY_DEFAULT);
Expand Down Expand Up @@ -634,6 +654,19 @@ private void setMultiprocess(boolean value, boolean doApply) {
}
}

private void setServo(boolean value, boolean doApply) {
mServoSwitch.setOnCheckedChangeListener(null);
mServoSwitch.setChecked(value);
mServoSwitch.setOnCheckedChangeListener(mServoListener);
mServoSwitchText.setText(value ? getContext().getString(R.string.on) : getContext().getString(R.string.off));

SettingsStore.getInstance(getContext()).setServoEnabled(value);

if (doApply) {
SessionStore.get().setServo(value);
}
}

private UaMode getUaModeFromRadio(int checkedId) {
UaMode uaMode;
switch (checkedId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package org.mozilla.vrbrowser.ui;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.util.Log;
Expand All @@ -25,7 +27,8 @@
public class NavigationBarWidget extends UIWidget implements GeckoSession.NavigationDelegate,
GeckoSession.ProgressDelegate, GeckoSession.ContentDelegate,
WidgetManagerDelegate.Listener, SessionStore.SessionChangeListener,
NavigationURLBar.NavigationURLBarDelegate, VoiceSearchWidget.VoiceSearchDelegate {
NavigationURLBar.NavigationURLBarDelegate, VoiceSearchWidget.VoiceSearchDelegate,
SharedPreferences.OnSharedPreferenceChangeListener {

private static final String LOGTAG = "VRB";

Expand All @@ -34,6 +37,7 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga
private UIButton mForwardButton;
private UIButton mReloadButton;
private UIButton mHomeButton;
private UIButton mServoButton;
private NavigationURLBar mURLBar;
private ViewGroup mNavigationContainer;
private ViewGroup mFocusModeContainer;
Expand All @@ -52,6 +56,8 @@ public class NavigationBarWidget extends UIWidget implements GeckoSession.Naviga
private ArrayList<CustomUIButton> mButtons;
private int mURLBarLayoutIndex;
private VoiceSearchWidget mVoiceSearchWidget;
private Context mAppContext;
private SharedPreferences mPrefs;

public NavigationBarWidget(Context aContext) {
super(aContext);
Expand All @@ -69,12 +75,14 @@ public NavigationBarWidget(Context aContext, AttributeSet aAttrs, int aDefStyle)
}

private void initialize(Context aContext) {
mAppContext = aContext.getApplicationContext();
inflate(aContext, R.layout.navigation_bar, this);
mAudio = AudioEngine.fromContext(aContext);
mBackButton = findViewById(R.id.backButton);
mForwardButton = findViewById(R.id.forwardButton);
mReloadButton = findViewById(R.id.reloadButton);
mHomeButton = findViewById(R.id.homeButton);
mServoButton = findViewById(R.id.servoButton);
mURLBar = findViewById(R.id.urlBar);
mNavigationContainer = findViewById(R.id.navigationBarContainer);
mFocusModeContainer = findViewById(R.id.focusModeContainer);
Expand Down Expand Up @@ -135,6 +143,16 @@ public void onClick(View v) {
}
});

mServoButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
SessionStore.get().toggleServo();
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}
}
});

mResizeEnterButton = findViewById(R.id.resizeEnterButton);
mResizeExitButton = findViewById(R.id.resizeExitButton);
mPreset0 = findViewById(R.id.resizePreset0);
Expand Down Expand Up @@ -205,7 +223,7 @@ public void onClick(View view) {
mButtons = new ArrayList<>();
mButtons.addAll(Arrays.<CustomUIButton>asList(
mBackButton, mForwardButton, mReloadButton, mHomeButton, mResizeEnterButton, mResizeExitButton,
mPreset0, mPreset1, mPreset2, mPreset3));
mServoButton, mPreset0, mPreset1, mPreset2, mPreset3));

mURLBar.setDelegate(this);

Expand All @@ -218,11 +236,16 @@ public void onClick(View view) {
mVoiceSearchWidget.setDelegate(this);

SessionStore.get().addSessionChangeListener(this);

mPrefs = PreferenceManager.getDefaultSharedPreferences(mAppContext);
mPrefs.registerOnSharedPreferenceChangeListener(this);
updateServoButton();
}

@Override
public void releaseWidget() {
mWidgetManager.removeListener(this);
mPrefs.unregisterOnSharedPreferenceChangeListener(this);
SessionStore.get().removeNavigationListener(this);
SessionStore.get().removeProgressListener(this);
SessionStore.get().removeContentListener(this);
Expand Down Expand Up @@ -347,6 +370,14 @@ public void showVoiceSearch() {
mURLBar.showVoiceSearch(true);
}

public void updateServoButton() {
if (SettingsStore.getInstance(mAppContext).isServoEnabled()) {
mServoButton.setVisibility(View.VISIBLE);
} else {
mServoButton.setVisibility(View.GONE);
}
}

@Override
public GeckoResult<GeckoSession> onNewSession(@NonNull GeckoSession aSession, @NonNull String aUri) {
return null;
Expand Down Expand Up @@ -552,4 +583,11 @@ public void OnVoiceSearchCanceled() {
public void OnVoiceSearchError() {
// Nothing to do yet
}

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key == mAppContext.getString(R.string.settings_key_servo)) {
updateServoButton();
}
}
}
Binary file added app/src/main/res/drawable/ic_icon_servo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 46 additions & 1 deletion app/src/main/res/layout/developer_options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,51 @@
android:textStyle="bold"/>
</LinearLayout>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/fog"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/developer_options_servo"
android:textSize="14sp"
android:textColor="@color/fog"
android:layout_alignParentStart="true"
android:layout_toStartOf="@id/developer_options_servo_switch_layout"/>
<LinearLayout android:id="@+id/developer_options_servo_switch_layout"
android:orientation="vertical"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true">
<Switch
android:id="@+id/developer_options_servo_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:switchMinWidth="0dp"
android:textOff=""
android:textOn=""
android:track="@drawable/switch_track"
android:thumb="@drawable/switch_thumb"/>
<TextView
android:id="@+id/developer_options_servo_switch_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:paddingTop="5dp"
android:text="OFF"
android:textColor="@color/white"
android:textSize="@dimen/settings_font_size"
android:textStyle="bold"/>
</LinearLayout>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
Expand Down Expand Up @@ -686,4 +731,4 @@
</LinearLayout>
</ScrollView>
</LinearLayout>
</merge>
</merge>
7 changes: 7 additions & 0 deletions app/src/main/res/layout/navigation_bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
android:layout_marginStart="10dp"
android:src="@drawable/ic_icon_home" />

<org.mozilla.vrbrowser.ui.UIButton
android:id="@+id/servoButton"
style="?attr/navigationBarButtonStyle"
android:layout_weight="1"
android:layout_marginStart="10dp"
android:src="@drawable/ic_icon_servo" />

<org.mozilla.vrbrowser.ui.NavigationURLBar
android:id="@+id/urlBar"
android:layout_width="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/non_L10n.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<string name="settings_key_console_logs" translatable="false">settings_console_logs</string>
<string name="settings_key_environment_override" translatable="false">settings_environment_override</string>
<string name="settings_key_multiprocess" translatable="false">settings_environment_multiprocess</string>
<string name="settings_key_servo">settings_environment_servo</string>
<string name="settings_key_desktop_version" translatable="false">settings_desktop_version</string>
<string name="settings_key_input_mode" translatable="false">settings_touch_mode</string>
<string name="settings_key_display_density" translatable="false">settings_display_density</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<string name="developer_options_show_console">Redirect Console to Logcat</string>
<string name="developer_options_env_override">Enable Environment Override</string>
<string name="developer_options_multiprocess">Enable Multiprocess</string>
<string name="developer_options_servo">Enable Servo</string>
<string name="developer_options_ua_mode">User Agent Mode</string>
<string name="developer_options_events">Input Events</string>
<string name="developer_options_display_density">Display Density:</string>
Expand Down

0 comments on commit 4433afe

Please sign in to comment.