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

Commit 795ba86

Browse files
keianhzoMortimerGoro
authored andcommitted
Implements latest Settings spec (#1423)
* New Settings spec implementation * Rebase updates, added tooltip support for missing icons. * Hide UA button on home * Fixes autoplay reset
1 parent 469033c commit 795ba86

36 files changed

Lines changed: 750 additions & 385 deletions

app/src/common/shared/org/mozilla/vrbrowser/browser/SessionStore.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,10 @@ public void switchPrivateMode() {
837837
}
838838
}
839839

840+
public int getUaMode() {
841+
return mCurrentSession.getSettings().getUserAgentMode();
842+
}
843+
840844
public void setUaMode(int mode) {
841845
if (mCurrentSession != null) {
842846
mCurrentSession.getSettings().setUserAgentMode(mode);

app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ SettingsStore getInstance(final @NonNull Context aContext) {
4545
public final static boolean ENV_OVERRIDE_DEFAULT = false;
4646
public final static boolean MULTIPROCESS_DEFAULT = false;
4747
public final static boolean PERFORMANCE_MONITOR_DEFAULT = true;
48+
public final static boolean DRM_PLAYBACK_DEFAULT = false;
4849
public final static boolean TRACKING_DEFAULT = true;
50+
public final static boolean NOTIFICATIONS_DEFAULT = true;
51+
public final static boolean SPEECH_DATA_COLLECTION_DEFAULT = false;
4952
public final static boolean SERVO_DEFAULT = false;
5053
public final static int UA_MODE_DEFAULT = GeckoSessionSettings.USER_AGENT_MODE_VR;
5154
public final static int INPUT_MODE_DEFAULT = 1;
@@ -66,6 +69,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
6669
public final static int FOVEATED_APP_DEFAULT_LEVEL = 0;
6770
public final static int FOVEATED_WEBVR_DEFAULT_LEVEL = 0;
6871
private final static long CRASH_RESTART_DELTA = 2000;
72+
public final static boolean AUTOPLAY_ENABLED = false;
6973

7074
// Enable telemetry by default (opt-out).
7175
private final static boolean enableCrashReportingByDefault = false;
@@ -146,6 +150,17 @@ public void setConsoleLogsEnabled(boolean isEnabled) {
146150
editor.commit();
147151
}
148152

153+
public boolean isDrmContentPlaybackEnabled() {
154+
return mPrefs.getBoolean(
155+
mContext.getString(R.string.settings_key_drm_playback), DRM_PLAYBACK_DEFAULT);
156+
}
157+
158+
public void setDrmContentPlaybackEnabled(boolean isEnabled) {
159+
SharedPreferences.Editor editor = mPrefs.edit();
160+
editor.putBoolean(mContext.getString(R.string.settings_key_drm_playback), isEnabled);
161+
editor.commit();
162+
}
163+
149164
public boolean isTrackingProtectionEnabled() {
150165
return mPrefs.getBoolean(
151166
mContext.getString(R.string.settings_key_tracking_protection), TRACKING_DEFAULT);
@@ -484,5 +499,27 @@ public synchronized void resetCrashRestartCount() {
484499
editor.putLong(mContext.getString(R.string.settings_key_crash_restart_count), 0);
485500
editor.commit();
486501
}
502+
503+
public boolean isSpeechDataCollectionEnabled() {
504+
return mPrefs.getBoolean(
505+
mContext.getString(R.string.settings_key_speech_data_collection), SPEECH_DATA_COLLECTION_DEFAULT);
506+
}
507+
508+
public void setSpeechDataCollectionEnabled(boolean isEnabled) {
509+
SharedPreferences.Editor editor = mPrefs.edit();
510+
editor.putBoolean(mContext.getString(R.string.settings_key_speech_data_collection), isEnabled);
511+
editor.commit();
512+
}
513+
514+
public boolean isNotificationsEnabled() {
515+
return mPrefs.getBoolean(
516+
mContext.getString(R.string.settings_key_notifications), NOTIFICATIONS_DEFAULT);
517+
}
518+
519+
public void setNotificationsEnabled(boolean isEnabled) {
520+
SharedPreferences.Editor editor = mPrefs.edit();
521+
editor.putBoolean(mContext.getString(R.string.settings_key_notifications), isEnabled);
522+
editor.commit();
523+
}
487524
}
488525

app/src/common/shared/org/mozilla/vrbrowser/ui/views/NavigationURLBar.java

Lines changed: 83 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,27 @@
1414
import android.util.AttributeSet;
1515
import android.util.TypedValue;
1616
import android.view.GestureDetector;
17-
import android.view.LayoutInflater;
1817
import android.view.MotionEvent;
1918
import android.view.View;
20-
import android.view.ViewGroup;
2119
import android.view.animation.Animation;
2220
import android.view.animation.AnimationUtils;
2321
import android.view.inputmethod.EditorInfo;
2422
import android.widget.FrameLayout;
25-
import android.widget.ImageButton;
2623
import android.widget.ImageView;
2724
import android.widget.RelativeLayout;
2825

26+
import androidx.annotation.NonNull;
27+
import androidx.annotation.StringRes;
28+
29+
import org.mozilla.geckoview.GeckoSessionSettings;
2930
import org.mozilla.vrbrowser.R;
3031
import org.mozilla.vrbrowser.audio.AudioEngine;
3132
import org.mozilla.vrbrowser.browser.BookmarksStore;
3233
import org.mozilla.vrbrowser.browser.SessionStore;
34+
import org.mozilla.vrbrowser.browser.SettingsStore;
3335
import org.mozilla.vrbrowser.search.SearchEngineWrapper;
3436
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
37+
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
3538
import org.mozilla.vrbrowser.utils.StringUtils;
3639
import org.mozilla.vrbrowser.utils.UIThreadExecutor;
3740
import org.mozilla.vrbrowser.utils.UrlUtils;
@@ -41,7 +44,6 @@
4144
import java.net.URL;
4245
import java.net.URLDecoder;
4346

44-
import androidx.annotation.StringRes;
4547
import kotlin.Unit;
4648
import mozilla.components.browser.domains.autocomplete.DomainAutocompleteResult;
4749
import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider;
@@ -50,7 +52,8 @@
5052

5153
public class NavigationURLBar extends FrameLayout {
5254
private InlineAutocompleteEditText mURL;
53-
private ImageButton mMicrophoneButton;
55+
private UIButton mMicrophoneButton;
56+
private UIButton mUAModeButton;
5457
private ImageView mInsecureIcon;
5558
private ImageView mLoadingView;
5659
private Animation mLoadingAnimation;
@@ -62,10 +65,11 @@ public class NavigationURLBar extends FrameLayout {
6265
private int mURLWebsiteColor;
6366
private NavigationURLBarDelegate mDelegate;
6467
private ShippedDomainsProvider mAutocompleteProvider;
65-
private ImageButton mBookmarkButton;
68+
private UIButton mBookmarkButton;
6669
private AudioEngine mAudio;
6770
private boolean mIsBookmarkMode;
6871
private boolean mBookmarkEnabled = true;
72+
private boolean mIsContextButtonsEnabled = true;
6973
private UIThreadExecutor mUIThreadExecutor = new UIThreadExecutor();
7074

7175
private Unit domainAutocompleteFilter(String text) {
@@ -99,7 +103,6 @@ private void initialize(Context aContext) {
99103
mAudio = AudioEngine.fromContext(aContext);
100104

101105
// Inflate this data binding layout
102-
LayoutInflater inflater = LayoutInflater.from(aContext);
103106
inflate(aContext, R.layout.navigation_url, this);
104107

105108
// Use Domain autocomplete provider from components
@@ -119,6 +122,7 @@ private void initialize(Context aContext) {
119122

120123
mURL.setOnFocusChangeListener((view, focused) -> {
121124
showVoiceSearch(!focused || (mURL.getText().length() == 0));
125+
showContextButtons(!focused && mIsContextButtonsEnabled);
122126

123127
mURL.setSelection(mURL.getText().length(), 0);
124128
});
@@ -142,6 +146,12 @@ private void initialize(Context aContext) {
142146
mMicrophoneButton = findViewById(R.id.microphoneButton);
143147
mMicrophoneButton.setTag(R.string.view_id_tag, R.id.microphoneButton);
144148
mMicrophoneButton.setOnClickListener(mMicrophoneListener);
149+
150+
mUAModeButton = findViewById(R.id.uaModeButton);
151+
mUAModeButton.setTag(R.string.view_id_tag, R.id.uaModeButton);
152+
mUAModeButton.setOnClickListener(mUAModeListener);
153+
setUAMode(SettingsStore.getInstance(aContext).getUaMode());
154+
145155
mURLLeftContainer = findViewById(R.id.urlLeftContainer);
146156
mInsecureIcon = findViewById(R.id.insecureIcon);
147157
mLoadingView = findViewById(R.id.loadingView);
@@ -178,7 +188,6 @@ public void onResume() {
178188
if (mIsLoading) {
179189
mLoadingView.startAnimation(mLoadingAnimation);
180190
}
181-
182191
}
183192

184193
public void setDelegate(NavigationURLBarDelegate delegate) {
@@ -192,27 +201,19 @@ public void setIsBookmarkMode(boolean isBookmarkMode) {
192201
mIsBookmarkMode = isBookmarkMode;
193202
if (isBookmarkMode) {
194203
mMicrophoneButton.setVisibility(GONE);
204+
mUAModeButton.setVisibility(GONE);
195205
mBookmarkButton.setVisibility(GONE);
206+
196207
} else {
197208
mMicrophoneButton.setVisibility(VISIBLE);
209+
mUAModeButton.setVisibility(VISIBLE);
198210
if (mBookmarkEnabled) {
199211
mBookmarkButton.setVisibility(VISIBLE);
200212
}
201213
}
202214
syncViews();
203215
}
204216

205-
private void setBookmarkEnabled(boolean aEnabled) {
206-
if (mBookmarkEnabled != aEnabled) {
207-
mBookmarkEnabled = aEnabled;
208-
mBookmarkButton.setVisibility(aEnabled ? View.VISIBLE : View.GONE);
209-
ViewGroup.LayoutParams params = mMicrophoneButton.getLayoutParams();
210-
params.width = (int) getResources().getDimension(aEnabled ? R.dimen.url_bar_item_width : R.dimen.url_bar_last_item_width);
211-
mMicrophoneButton.setLayoutParams(params);
212-
mMicrophoneButton.setBackgroundResource(aEnabled ? R.drawable.url_button : R.drawable.url_button_end);
213-
}
214-
}
215-
216217
private void handleBookmarkClick() {
217218
if (mAudio != null) {
218219
mAudio.playSound(AudioEngine.Sound.CLICK);
@@ -293,12 +294,17 @@ else if (aURL.startsWith("data:") && SessionStore.get().isCurrentSessionPrivate(
293294
mURL.setText(aURL);
294295
}
295296
}
296-
setBookmarkEnabled(aURL.length() > 0 && !aURL.startsWith("about://"));
297+
mIsContextButtonsEnabled = aURL.length() > 0 && !aURL.startsWith("about://");
298+
showContextButtons(mIsContextButtonsEnabled);
297299
}
298300

299301
mURL.addTextChangedListener(mURLTextWatcher);
300302
}
301303

304+
private boolean isEmptyUrl(@NonNull String aURL) {
305+
return aURL.length() == 0 || aURL.startsWith("about://");
306+
}
307+
302308
public String getText() {
303309
return mURL.getText().toString();
304310
}
@@ -331,32 +337,48 @@ public void setIsLoading(boolean aIsLoading) {
331337
}
332338
}
333339

340+
public void setUAMode(int uaMode) {
341+
if (uaMode == GeckoSessionSettings.USER_AGENT_MODE_DESKTOP) {
342+
mUAModeButton.setImageResource(R.drawable.ic_icon_ua_desktop);
343+
344+
} else {
345+
mUAModeButton.setImageResource(R.drawable.ic_icon_ua_default);
346+
}
347+
}
348+
349+
private void showContextButtons(boolean aEnabled) {
350+
if (mBookmarkEnabled != aEnabled) {
351+
mBookmarkEnabled = aEnabled;
352+
}
353+
354+
if (aEnabled) {
355+
mMicrophoneButton.setBackgroundResource(R.drawable.url_button);
356+
mMicrophoneButton.getLayoutParams().width = (int)getContext().getResources().getDimension(R.dimen.url_bar_item_width);
357+
mBookmarkButton.setVisibility(VISIBLE);
358+
mUAModeButton.setVisibility(VISIBLE);
359+
360+
} else {
361+
mMicrophoneButton.setBackgroundResource(R.drawable.url_button_end);
362+
mMicrophoneButton.getLayoutParams().width = (int)getContext().getResources().getDimension(R.dimen.url_bar_last_item_width);
363+
mBookmarkButton.setVisibility(GONE);
364+
mUAModeButton.setVisibility(GONE);
365+
}
366+
}
367+
334368
public void showVoiceSearch(boolean enabled) {
335369
if (enabled) {
336-
if (mBookmarkEnabled) {
337-
mMicrophoneButton.setBackgroundResource(R.drawable.url_button);
338-
mMicrophoneButton.getLayoutParams().width = (int)getContext().getResources().getDimension(R.dimen.url_bar_item_width);
339-
}
370+
mURL.setPadding(mURL.getPaddingStart(), mURL.getPaddingTop(), WidgetPlacement.convertDpToPixel(getContext(), 100), mURL.getPaddingBottom());
371+
340372
mMicrophoneButton.setImageResource(R.drawable.ic_icon_microphone);
373+
mMicrophoneButton.setTooltip(getResources().getString(R.string.voice_search_tooltip));
341374
mMicrophoneButton.setOnClickListener(mMicrophoneListener);
342375

343-
if (mIsBookmarkMode) {
344-
mMicrophoneButton.setVisibility(GONE);
345-
} else if (mBookmarkEnabled) {
346-
mBookmarkButton.setVisibility(VISIBLE);
347-
}
348-
349376
} else if (mURL.hasFocus()){
377+
mURL.setPadding(mURL.getPaddingStart(), mURL.getPaddingTop(), WidgetPlacement.convertDpToPixel(getContext(), 40), mURL.getPaddingBottom());
378+
350379
mMicrophoneButton.setImageResource(R.drawable.ic_icon_clear);
351-
mMicrophoneButton.setBackgroundResource(R.drawable.url_button_end);
352-
mMicrophoneButton.getLayoutParams().width = (int)getContext().getResources().getDimension(R.dimen.url_bar_last_item_width);
380+
mMicrophoneButton.setTooltip(getResources().getString(R.string.clear_tooltip));
353381
mMicrophoneButton.setOnClickListener(mClearListener);
354-
355-
if (mIsBookmarkMode) {
356-
mMicrophoneButton.setVisibility(VISIBLE);
357-
}
358-
359-
mBookmarkButton.setVisibility(GONE);
360382
}
361383
}
362384

@@ -449,6 +471,26 @@ public void setClickable(boolean clickable) {
449471
TelemetryWrapper.voiceInputEvent();
450472
};
451473

474+
private OnClickListener mUAModeListener = view -> {
475+
if (mAudio != null) {
476+
mAudio.playSound(AudioEngine.Sound.CLICK);
477+
}
478+
479+
view.requestFocusFromTouch();
480+
481+
int uaMode = SessionStore.get().getUaMode();
482+
if (uaMode == GeckoSessionSettings.USER_AGENT_MODE_VR) {
483+
setUAMode(GeckoSessionSettings.USER_AGENT_MODE_DESKTOP);
484+
SessionStore.get().setUaMode(GeckoSessionSettings.USER_AGENT_MODE_DESKTOP);
485+
486+
}else {
487+
setUAMode(GeckoSessionSettings.USER_AGENT_MODE_VR);
488+
SessionStore.get().setUaMode(GeckoSessionSettings.USER_AGENT_MODE_VR);
489+
}
490+
491+
TelemetryWrapper.voiceInputEvent();
492+
};
493+
452494
private OnClickListener mClearListener = view -> {
453495
if (mAudio != null) {
454496
mAudio.playSound(AudioEngine.Sound.CLICK);
@@ -465,12 +507,9 @@ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)
465507

466508
@Override
467509
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
468-
if (mURL.getText().length() > 0) {
469-
showVoiceSearch(false);
470-
471-
} else {
472-
showVoiceSearch(true);
473-
}
510+
String aURL = mURL.getText().toString();
511+
showVoiceSearch(isEmptyUrl(aURL));
512+
showContextButtons(isEmptyUrl(aURL) && mIsContextButtonsEnabled);
474513
}
475514

476515
@Override

0 commit comments

Comments
 (0)