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

Implements latest Settings spec #1423

Merged
merged 4 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,10 @@ public void switchPrivateMode() {
}
}

public int getUaMode() {
return mCurrentSession.getSettings().getUserAgentMode();
}

public void setUaMode(int mode) {
if (mCurrentSession != null) {
mCurrentSession.getSettings().setUserAgentMode(mode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ SettingsStore getInstance(final @NonNull Context aContext) {
public final static boolean ENV_OVERRIDE_DEFAULT = false;
public final static boolean MULTIPROCESS_DEFAULT = false;
public final static boolean PERFORMANCE_MONITOR_DEFAULT = true;
public final static boolean DRM_PLAYBACK_DEFAULT = false;
public final static boolean TRACKING_DEFAULT = true;
public final static boolean NOTIFICATIONS_DEFAULT = true;
public final static boolean SPEECH_DATA_COLLECTION_DEFAULT = false;
public final static boolean SERVO_DEFAULT = false;
public final static int UA_MODE_DEFAULT = GeckoSessionSettings.USER_AGENT_MODE_VR;
public final static int INPUT_MODE_DEFAULT = 1;
Expand Down Expand Up @@ -146,6 +149,17 @@ public void setConsoleLogsEnabled(boolean isEnabled) {
editor.commit();
}

public boolean isDrmContentPlaybackEnabled() {
return mPrefs.getBoolean(
mContext.getString(R.string.settings_key_drm_playback), DRM_PLAYBACK_DEFAULT);
}

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

public boolean isTrackingProtectionEnabled() {
return mPrefs.getBoolean(
mContext.getString(R.string.settings_key_tracking_protection), TRACKING_DEFAULT);
Expand Down Expand Up @@ -484,5 +498,27 @@ public synchronized void resetCrashRestartCount() {
editor.putLong(mContext.getString(R.string.settings_key_crash_restart_count), 0);
editor.commit();
}

public boolean isSpeechDataCollectionEnabled() {
return mPrefs.getBoolean(
mContext.getString(R.string.settings_key_speech_data_collection), SPEECH_DATA_COLLECTION_DEFAULT);
}

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

public boolean isNotificationsEnabled() {
return mPrefs.getBoolean(
mContext.getString(R.string.settings_key_notifications), NOTIFICATIONS_DEFAULT);
}

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

Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@
import android.widget.ImageView;
import android.widget.RelativeLayout;

import org.mozilla.geckoview.GeckoSessionSettings;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.audio.AudioEngine;
import org.mozilla.vrbrowser.browser.BookmarksStore;
import org.mozilla.vrbrowser.browser.SessionStore;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.search.SearchEngineWrapper;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
import org.mozilla.vrbrowser.utils.StringUtils;
import org.mozilla.vrbrowser.utils.UIThreadExecutor;
import org.mozilla.vrbrowser.utils.UrlUtils;
Expand All @@ -49,7 +52,8 @@

public class NavigationURLBar extends FrameLayout {
private InlineAutocompleteEditText mURL;
private ImageButton mMicrophoneButton;
private UIButton mMicrophoneButton;
private UIButton mUAModeButton;
private ImageView mInsecureIcon;
private ImageView mLoadingView;
private Animation mLoadingAnimation;
Expand All @@ -61,7 +65,7 @@ public class NavigationURLBar extends FrameLayout {
private int mURLWebsiteColor;
private NavigationURLBarDelegate mDelegate;
private ShippedDomainsProvider mAutocompleteProvider;
private ImageButton mBookmarkButton;
private UIButton mBookmarkButton;
private AudioEngine mAudio;
private boolean mIsBookmarkMode;
private boolean mBookmarkEnabled = true;
Expand Down Expand Up @@ -141,6 +145,12 @@ private void initialize(Context aContext) {
mMicrophoneButton = findViewById(R.id.microphoneButton);
mMicrophoneButton.setTag(R.string.view_id_tag, R.id.microphoneButton);
mMicrophoneButton.setOnClickListener(mMicrophoneListener);

mUAModeButton = findViewById(R.id.uaModeButton);
mUAModeButton.setTag(R.string.view_id_tag, R.id.uaModeButton);
mUAModeButton.setOnClickListener(mUAModeListener);
setUAModeButton(SettingsStore.getInstance(aContext).getUaMode());

mURLLeftContainer = findViewById(R.id.urlLeftContainer);
mInsecureIcon = findViewById(R.id.insecureIcon);
mLoadingView = findViewById(R.id.loadingView);
Expand Down Expand Up @@ -177,7 +187,6 @@ public void onResume() {
if (mIsLoading) {
mLoadingView.startAnimation(mLoadingAnimation);
}

}

public void setDelegate(NavigationURLBarDelegate delegate) {
Expand Down Expand Up @@ -205,10 +214,10 @@ private void setBookmarkEnabled(boolean aEnabled) {
if (mBookmarkEnabled != aEnabled) {
mBookmarkEnabled = aEnabled;
mBookmarkButton.setVisibility(aEnabled ? View.VISIBLE : View.GONE);
ViewGroup.LayoutParams params = mMicrophoneButton.getLayoutParams();
ViewGroup.LayoutParams params = mUAModeButton.getLayoutParams();
params.width = (int) getResources().getDimension(aEnabled ? R.dimen.url_bar_item_width : R.dimen.url_bar_last_item_width);
mMicrophoneButton.setLayoutParams(params);
mMicrophoneButton.setBackgroundResource(aEnabled ? R.drawable.url_button : R.drawable.url_button_end);
mUAModeButton.setLayoutParams(params);
mUAModeButton.setBackgroundResource(aEnabled ? R.drawable.url_button : R.drawable.url_button_end);
}
}

Expand Down Expand Up @@ -330,32 +339,48 @@ public void setIsLoading(boolean aIsLoading) {
}
}

public void setUAModeButton(int uaMode) {
if (uaMode == GeckoSessionSettings.USER_AGENT_MODE_DESKTOP) {
mUAModeButton.setImageResource(R.drawable.ic_icon_ua_desktop);

} else {
mUAModeButton.setImageResource(R.drawable.ic_icon_ua_default);
}
}

public void showVoiceSearch(boolean enabled) {
if (enabled) {
mURL.setPadding(mURL.getPaddingStart(), mURL.getPaddingTop(), WidgetPlacement.convertDpToPixel(getContext(), 100), mURL.getPaddingBottom());
if (mBookmarkEnabled) {
mMicrophoneButton.setBackgroundResource(R.drawable.url_button);
mMicrophoneButton.getLayoutParams().width = (int)getContext().getResources().getDimension(R.dimen.url_bar_item_width);
mUAModeButton.setBackgroundResource(R.drawable.url_button);
mUAModeButton.getLayoutParams().width = (int)getContext().getResources().getDimension(R.dimen.url_bar_item_width);
}
mMicrophoneButton.setImageResource(R.drawable.ic_icon_microphone);
mMicrophoneButton.setOnClickListener(mMicrophoneListener);

mUAModeButton.setTooltip(getResources().getString(R.string.user_agent_tooltip));
setUAModeButton(SettingsStore.getInstance(getContext()).getUaMode());
mUAModeButton.setOnClickListener(mUAModeListener);

if (mIsBookmarkMode) {
mMicrophoneButton.setVisibility(GONE);
mUAModeButton.setVisibility(GONE);
} else if (mBookmarkEnabled) {
mBookmarkButton.setVisibility(VISIBLE);
}
mMicrophoneButton.setVisibility(VISIBLE);

} else if (mURL.hasFocus()){
mMicrophoneButton.setImageResource(R.drawable.ic_icon_clear);
mMicrophoneButton.setBackgroundResource(R.drawable.url_button_end);
mMicrophoneButton.getLayoutParams().width = (int)getContext().getResources().getDimension(R.dimen.url_bar_last_item_width);
mMicrophoneButton.setOnClickListener(mClearListener);
mURL.setPadding(mURL.getPaddingStart(), mURL.getPaddingTop(), WidgetPlacement.convertDpToPixel(getContext(), 40), mURL.getPaddingBottom());
mUAModeButton.setImageResource(R.drawable.ic_icon_clear);
mUAModeButton.setTooltip(getResources().getString(R.string.clear_tooltip));
mUAModeButton.setBackgroundResource(R.drawable.url_button_end);
mUAModeButton.getLayoutParams().width = (int)getContext().getResources().getDimension(R.dimen.url_bar_last_item_width);
mUAModeButton.setOnClickListener(mClearListener);

if (mIsBookmarkMode) {
mMicrophoneButton.setVisibility(VISIBLE);
mUAModeButton.setVisibility(VISIBLE);
}

mBookmarkButton.setVisibility(GONE);
mMicrophoneButton.setVisibility(GONE);
}
}

Expand Down Expand Up @@ -447,6 +472,26 @@ public void setClickable(boolean clickable) {
TelemetryWrapper.voiceInputEvent();
};

private OnClickListener mUAModeListener = view -> {
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}

view.requestFocusFromTouch();

int uaMode = SessionStore.get().getUaMode();
if (uaMode == GeckoSessionSettings.USER_AGENT_MODE_VR) {
setUAModeButton(GeckoSessionSettings.USER_AGENT_MODE_DESKTOP);
SessionStore.get().setUaMode(GeckoSessionSettings.USER_AGENT_MODE_DESKTOP);

}else {
setUAModeButton(GeckoSessionSettings.USER_AGENT_MODE_VR);
SessionStore.get().setUaMode(GeckoSessionSettings.USER_AGENT_MODE_VR);
}

TelemetryWrapper.voiceInputEvent();
};

private OnClickListener mClearListener = view -> {
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
import android.widget.Switch;
import android.widget.TextView;

import androidx.annotation.NonNull;

import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.audio.AudioEngine;
import org.mozilla.vrbrowser.ui.views.UIButton;
import org.mozilla.vrbrowser.utils.ViewUtils;

public class SwitchSetting extends LinearLayout {

Expand All @@ -38,6 +41,10 @@ public SwitchSetting(Context context, AttributeSet attrs, int defStyleAttr) {

TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.SwitchSetting, defStyleAttr, 0);
mText = attributes.getString(R.styleable.SwitchSetting_description);
int onResId = attributes.getResourceId(R.styleable.SwitchSetting_on_text, R.string.on);
mOnText = getResources().getString(onResId);
int offResId = attributes.getResourceId(R.styleable.SwitchSetting_off_text, R.string.off);
mOffText = getResources().getString(offResId);
attributes.recycle();

initialize(context);
Expand All @@ -47,8 +54,6 @@ private void initialize(Context aContext) {
inflate(aContext, R.layout.setting_switch, this);

mAudio = AudioEngine.fromContext(aContext);
mOnText = aContext.getString(R.string.on);
mOffText = aContext.getString(R.string.off);

mSwitchDescription = findViewById(R.id.setting_description);
mSwitchDescription.setText(mText);
Expand All @@ -72,8 +77,11 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
}
};

public void setValue(boolean value, boolean doApply) {
public void setLinkClickListner(@NonNull ViewUtils.LinkClickableSpan listener) {
ViewUtils.setTextViewHTML(mSwitchDescription, mText, (widget, url) -> listener.onClick(widget, url));
}

public void setValue(boolean value, boolean doApply) {
mSwitch.setOnCheckedChangeListener(null);
mSwitch.setChecked(value);
mSwitch.setOnCheckedChangeListener(mInternalSwitchListener);
Expand All @@ -97,7 +105,6 @@ public void setChecked(boolean value) {
updateSwitchText();
}


public String getDescription() {
return mSwitchDescription.getText().toString();
}
Expand All @@ -106,16 +113,6 @@ private void updateSwitchText() {
mSwitchText.setText(mSwitch.isChecked() ? mOnText : mOffText);
}

public void setOnText(String aText) {
mOnText = aText;
updateSwitchText();
}

public void setOffText(String aText) {
mOffText = aText;
updateSwitchText();
}

public void setHelpDelegate(Runnable aDelegate) {
if (aDelegate != null) {
mHelpButton.setVisibility(View.VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,9 @@ public void OnVoiceSearchError() {
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key == mAppContext.getString(R.string.settings_key_servo)) {
updateServoButton();

} else if (key == mAppContext.getString(R.string.settings_key_user_agent_version)) {
mURLBar.setUAModeButton(SettingsStore.getInstance(getContext()).getUaMode());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class TrayWidget extends UIWidget implements SessionStore.SessionChangeLi
static final String LOGTAG = "VRB";
private static final int ICON_ANIMATION_DURATION = 200;

private UIButton mHelpButton;
private UIButton mSettingsButton;
private UIButton mPrivateButton;
private UIButton mBookmarksButton;
Expand Down Expand Up @@ -65,17 +64,6 @@ private void initialize(Context aContext) {
mMinPadding = WidgetPlacement.pixelDimension(getContext(), R.dimen.tray_icon_padding_min);
mMaxPadding = WidgetPlacement.pixelDimension(getContext(), R.dimen.tray_icon_padding_max);

mHelpButton = findViewById(R.id.helpButton);
mHelpButton.setOnHoverListener(mButtonScaleHoverListener);
mHelpButton.setOnClickListener(view -> {
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
}

onHelpButtonClicked();
view.requestFocusFromTouch();
});

mPrivateButton = findViewById(R.id.privateButton);
mPrivateButton.setOnHoverListener(mButtonScaleHoverListener);
mPrivateButton.setOnClickListener(view -> {
Expand Down Expand Up @@ -317,16 +305,6 @@ public boolean isDialogOpened(int aHandle) {
return false;
}

private void onHelpButtonClicked() {
GeckoSession session = SessionStore.get().getCurrentSession();
if (session == null) {
int sessionId = SessionStore.get().createSession();
SessionStore.get().setCurrentSession(sessionId);
}

SessionStore.get().loadUri(getContext().getString(R.string.help_url));
}

// BookmarkListener

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ private void initialize(Context aContext) {

mMozillaSpeechService = MozillaSpeechService.getInstance();
mMozillaSpeechService.setProductTag(getContext().getString(R.string.voice_app_id));
mMozillaSpeechService.storeSamples(false);
mMozillaSpeechService.storeTranscriptions(false);
boolean storeData = SettingsStore.getInstance(aContext).isSpeechDataCollectionEnabled();
mMozillaSpeechService.storeSamples(storeData);
mMozillaSpeechService.storeTranscriptions(storeData);

mVoiceSearchText1 = findViewById(R.id.voiceSearchText1);
mVoiceSearchText2 = findViewById(R.id.voiceSearchText2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class ControllerOptionsView extends SettingsView {
private RadioGroupSetting mPointerColorRadio;
private RadioGroupSetting mScrollDirectionRadio;
private ButtonSetting mResetButton;
private ScrollView mScrollbar;

public ControllerOptionsView(Context aContext, WidgetManagerDelegate aWidgetManager) {
super(aContext, aWidgetManager);
Expand Down Expand Up @@ -57,12 +56,6 @@ private void initialize(Context aContext) {
mResetButton.setOnClickListener(v -> resetOptions());
}

@Override
public void onShown() {
super.onShown();
mScrollbar.scrollTo(0, 0);
}

private void resetOptions() {
if (!mPointerColorRadio.getValueForId(mPointerColorRadio.getCheckedRadioButtonId()).equals(SettingsStore.POINTER_COLOR_DEFAULT_DEFAULT)) {
setPointerColor(mPointerColorRadio.getIdForValue(SettingsStore.POINTER_COLOR_DEFAULT_DEFAULT), true);
Expand Down