Skip to content

Commit

Permalink
Implements latest Settings spec (#1423)
Browse files Browse the repository at this point in the history
* New Settings spec implementation

* Rebase updates, added tooltip support for missing icons.

* Hide UA button on home

* Fixes autoplay reset
  • Loading branch information
keianhzo authored and MortimerGoro committed Jul 24, 2019
1 parent 469033c commit 795ba86
Show file tree
Hide file tree
Showing 36 changed files with 750 additions and 385 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,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 All @@ -66,6 +69,7 @@ SettingsStore getInstance(final @NonNull Context aContext) {
public final static int FOVEATED_APP_DEFAULT_LEVEL = 0;
public final static int FOVEATED_WEBVR_DEFAULT_LEVEL = 0;
private final static long CRASH_RESTART_DELTA = 2000;
public final static boolean AUTOPLAY_ENABLED = false;

// Enable telemetry by default (opt-out).
private final static boolean enableCrashReportingByDefault = false;
Expand Down Expand Up @@ -146,6 +150,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 +499,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 @@ -14,24 +14,27 @@
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.EditorInfo;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.annotation.StringRes;

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 @@ -41,7 +44,6 @@
import java.net.URL;
import java.net.URLDecoder;

import androidx.annotation.StringRes;
import kotlin.Unit;
import mozilla.components.browser.domains.autocomplete.DomainAutocompleteResult;
import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider;
Expand All @@ -50,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 @@ -62,10 +65,11 @@ 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;
private boolean mIsContextButtonsEnabled = true;
private UIThreadExecutor mUIThreadExecutor = new UIThreadExecutor();

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

// Inflate this data binding layout
LayoutInflater inflater = LayoutInflater.from(aContext);
inflate(aContext, R.layout.navigation_url, this);

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

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

mURL.setSelection(mURL.getText().length(), 0);
});
Expand All @@ -142,6 +146,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);
setUAMode(SettingsStore.getInstance(aContext).getUaMode());

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

}

public void setDelegate(NavigationURLBarDelegate delegate) {
Expand All @@ -192,27 +201,19 @@ public void setIsBookmarkMode(boolean isBookmarkMode) {
mIsBookmarkMode = isBookmarkMode;
if (isBookmarkMode) {
mMicrophoneButton.setVisibility(GONE);
mUAModeButton.setVisibility(GONE);
mBookmarkButton.setVisibility(GONE);

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

private void setBookmarkEnabled(boolean aEnabled) {
if (mBookmarkEnabled != aEnabled) {
mBookmarkEnabled = aEnabled;
mBookmarkButton.setVisibility(aEnabled ? View.VISIBLE : View.GONE);
ViewGroup.LayoutParams params = mMicrophoneButton.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);
}
}

private void handleBookmarkClick() {
if (mAudio != null) {
mAudio.playSound(AudioEngine.Sound.CLICK);
Expand Down Expand Up @@ -293,12 +294,17 @@ else if (aURL.startsWith("data:") && SessionStore.get().isCurrentSessionPrivate(
mURL.setText(aURL);
}
}
setBookmarkEnabled(aURL.length() > 0 && !aURL.startsWith("about://"));
mIsContextButtonsEnabled = aURL.length() > 0 && !aURL.startsWith("about://");
showContextButtons(mIsContextButtonsEnabled);
}

mURL.addTextChangedListener(mURLTextWatcher);
}

private boolean isEmptyUrl(@NonNull String aURL) {
return aURL.length() == 0 || aURL.startsWith("about://");
}

public String getText() {
return mURL.getText().toString();
}
Expand Down Expand Up @@ -331,32 +337,48 @@ public void setIsLoading(boolean aIsLoading) {
}
}

public void setUAMode(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);
}
}

private void showContextButtons(boolean aEnabled) {
if (mBookmarkEnabled != aEnabled) {
mBookmarkEnabled = aEnabled;
}

if (aEnabled) {
mMicrophoneButton.setBackgroundResource(R.drawable.url_button);
mMicrophoneButton.getLayoutParams().width = (int)getContext().getResources().getDimension(R.dimen.url_bar_item_width);
mBookmarkButton.setVisibility(VISIBLE);
mUAModeButton.setVisibility(VISIBLE);

} else {
mMicrophoneButton.setBackgroundResource(R.drawable.url_button_end);
mMicrophoneButton.getLayoutParams().width = (int)getContext().getResources().getDimension(R.dimen.url_bar_last_item_width);
mBookmarkButton.setVisibility(GONE);
mUAModeButton.setVisibility(GONE);
}
}

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

mMicrophoneButton.setImageResource(R.drawable.ic_icon_microphone);
mMicrophoneButton.setTooltip(getResources().getString(R.string.voice_search_tooltip));
mMicrophoneButton.setOnClickListener(mMicrophoneListener);

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

} else if (mURL.hasFocus()){
mURL.setPadding(mURL.getPaddingStart(), mURL.getPaddingTop(), WidgetPlacement.convertDpToPixel(getContext(), 40), mURL.getPaddingBottom());

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.setTooltip(getResources().getString(R.string.clear_tooltip));
mMicrophoneButton.setOnClickListener(mClearListener);

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

mBookmarkButton.setVisibility(GONE);
}
}

Expand Down Expand Up @@ -449,6 +471,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) {
setUAMode(GeckoSessionSettings.USER_AGENT_MODE_DESKTOP);
SessionStore.get().setUaMode(GeckoSessionSettings.USER_AGENT_MODE_DESKTOP);

}else {
setUAMode(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 All @@ -465,12 +507,9 @@ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (mURL.getText().length() > 0) {
showVoiceSearch(false);

} else {
showVoiceSearch(true);
}
String aURL = mURL.getText().toString();
showVoiceSearch(isEmptyUrl(aURL));
showContextButtons(isEmptyUrl(aURL) && mIsContextButtonsEnabled);
}

@Override
Expand Down

0 comments on commit 795ba86

Please sign in to comment.