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

Title bar support #1613

Merged
merged 1 commit into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.utils.InternalPages;

import java.util.ArrayList;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -546,6 +544,18 @@ public String getCurrentTitle() {
return result;
}

public boolean isSecure() {
boolean isSecure = false;
if (mCurrentSession != null) {
SessionState state = mSessions.get(mCurrentSession.hashCode());
if (state == null) {
return false;
}
isSecure = state.mSecurityInformation != null && state.mSecurityInformation.isSecure;
}
return isSecure;
}

public Media getFullScreenVideo() {
if (mCurrentSession != null) {
SessionState state = mSessions.get(mCurrentSession.hashCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,21 +225,6 @@ public void setIsBookmarkMode(boolean isBookmarkMode) {
syncViews();
}

public boolean isInBookmarkMode() {
return mIsBookmarkMode;
}

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 @@ -278,11 +263,11 @@ public void setHint(@StringRes int aHint) {
mURL.setHint(aHint);
}

public void setURL(String aURL) {
if (mIsBookmarkMode) {
return;
}
public void setInsecureVisibility(int visibility) {
mInsecureIcon.setVisibility(visibility);
}

public void setURL(String aURL) {
mURL.removeTextChangedListener(mURLTextWatcher);
if (StringUtils.isEmpty(aURL)) {
setBookmarked(false);
Expand Down Expand Up @@ -419,8 +404,11 @@ private void syncViews() {
mURLLeftContainer.setVisibility(View.VISIBLE);
mURLLeftContainer.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
mLoadingView.setVisibility(mIsLoading ? View.VISIBLE : View.GONE);
mInsecureIcon.setVisibility(!mIsLoading && mIsInsecure ? View.VISIBLE : View.GONE);
if (!mIsBookmarkMode) {
mInsecureIcon.setVisibility(!mIsLoading && mIsInsecure ? View.VISIBLE : View.GONE);
}
leftPadding = mURLLeftContainer.getMeasuredWidth();

} else {
mURLLeftContainer.setVisibility(View.GONE);
mLoadingView.setVisibility(View.GONE);
Expand Down Expand Up @@ -478,6 +466,7 @@ public void handleURLEdit(String text) {
public void setPrivateMode(boolean isEnabled) {
if (isEnabled) {
mURL.setBackground(getContext().getDrawable(R.drawable.url_background_private));

} else {
mURL.setBackground(getContext().getDrawable(R.drawable.url_background));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,7 @@ public void detachFromWindow() {
if (mIsInFullScreenMode) {
exitFullScreenMode();
}
if (mURLBar.isInBookmarkMode() && mAttachedWindow != null) {
onBookmarksHidden(mAttachedWindow);
}

if (mSessionStack != null) {
mSessionStack.removeSessionChangeListener(this);
mSessionStack.removeNavigationListener(this);
Expand All @@ -402,6 +400,19 @@ public void attachToWindow(@NonNull WindowWidget aWindow) {
mAttachedWindow = aWindow;
mAttachedWindow.addBookmarksListener(this);

if (mAttachedWindow != null) {
mURLBar.setIsBookmarkMode(mAttachedWindow.isBookmarksVisible());
if (mAttachedWindow.isBookmarksVisible()) {
mURLBar.setURL(getResources().getString(R.string.url_bookmarks_title));
mURLBar.setInsecureVisibility(View.GONE);

} else {
mURLBar.setURL(mAttachedWindow.getSessionStack().getCurrentUri());
mURLBar.setHint(R.string.search_placeholder);
mURLBar.setInsecureVisibility(View.VISIBLE);
}
}

mSessionStack = aWindow.getSessionStack();
if (mSessionStack != null) {
mURLBar.setSessionStack(mSessionStack);
Expand Down Expand Up @@ -712,6 +723,7 @@ public void onLocationChange(GeckoSession session, String url) {
if (mURLBar != null && !mAttachedWindow.isBookmarksVisible()) {
Log.d(LOGTAG, "Got location change");
mURLBar.setURL(url);
mURLBar.setHint(R.string.search_placeholder);
mReloadButton.setEnabled(true);
}
updateServoButton();
Expand Down Expand Up @@ -773,6 +785,7 @@ public void onPageStart(GeckoSession aSession, String aUri) {
if (mURLBar != null) {
Log.d(LOGTAG, "Got onPageStart");
mURLBar.setURL(aUri);
mURLBar.setHint(R.string.search_placeholder);
}
mIsLoading = true;
mURLBar.setIsLoading(true);
Expand Down Expand Up @@ -966,7 +979,7 @@ public void OnItemClicked(SuggestionsWidget.SuggestionItem item) {
public void onBookmarksShown(WindowWidget aWindow) {
if (mAttachedWindow == aWindow) {
mURLBar.setURL("");
mURLBar.setHint(R.string.about_bookmarks);
mURLBar.setHint(R.string.url_bookmarks_title);
mURLBar.setIsBookmarkMode(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.vrbrowser.ui.widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.URLUtil;

import androidx.annotation.IntegerRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.databinding.DataBindingUtil;

import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.databinding.TitleBarBinding;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;

public class TitleBarWidget extends UIWidget {

private static final String LOGTAG = TitleBarWidget.class.getSimpleName();

public interface Delegate {
void onTitleClicked(TitleBarWidget aWidget);
}

private TitleBarBinding mBinding;
private WindowWidget mAttachedWindow;
private boolean mVisible;

public TitleBarWidget(Context aContext) {
super(aContext);
initialize(aContext);
}

public TitleBarWidget(Context aContext, AttributeSet aAttrs) {
super(aContext, aAttrs);
initialize(aContext);
}

public TitleBarWidget(Context aContext, AttributeSet aAttrs, int aDefStyle) {
super(aContext, aAttrs, aDefStyle);
initialize(aContext);
}

private void initialize(@NonNull Context aContext) {
LayoutInflater inflater = LayoutInflater.from(aContext);

mBinding = DataBindingUtil.inflate(inflater, R.layout.title_bar, this, true);
mBinding.setWidget(this);
mBinding.executePendingBindings();
}

public void setDelegate(Delegate delegate) {
mBinding.setDelegate(delegate);
}

public @Nullable
WindowWidget getAttachedWindow() {
return mAttachedWindow;
}

@Override
public void releaseWidget() {
detachFromWindow();

mAttachedWindow = null;
super.releaseWidget();
}

@Override
protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.width = WidgetPlacement.dpDimension(getContext(), R.dimen.navigation_bar_width);
aPlacement.worldWidth = WidgetPlacement.floatDimension(getContext(), R.dimen.window_world_width);
aPlacement.height = WidgetPlacement.dpDimension(getContext(), R.dimen.navigation_bar_height);
aPlacement.anchorX = 0.5f;
aPlacement.anchorY = 1.0f;
aPlacement.parentAnchorX = 0.5f;
aPlacement.parentAnchorY = 0.0f;
aPlacement.translationY = -35;
aPlacement.opaque = false;
aPlacement.cylinder = true;
aPlacement.visible = true;
}

@Override
public void detachFromWindow() {
mAttachedWindow = null;
}

@Override
public void attachToWindow(@NonNull WindowWidget aWindow) {
if (aWindow == mAttachedWindow) {
return;
}
detachFromWindow();

mWidgetPlacement.parentHandle = aWindow.getHandle();
mAttachedWindow = aWindow;

setPrivateMode(aWindow.getSessionStack().isPrivateMode());
}

@Override
public void setVisible(boolean aIsVisible) {
if (mVisible == aIsVisible) {
return;
}
mVisible = aIsVisible;
getPlacement().visible = aIsVisible;

if (aIsVisible) {
mWidgetManager.addWidget(this);
} else {
mWidgetManager.removeWidget(this);
}
}

private void setPrivateMode(boolean aPrivateMode) {
mBinding.titleBar.setBackground(getContext().getDrawable(aPrivateMode ? R.drawable.title_bar_background_private : R.drawable.title_bar_background));
}

public void setURL(@StringRes int id) {
setURL(getResources().getString(id));
}

public void setURL(String urlString) {
if (urlString == null) {
return;
}

if (URLUtil.isValidUrl(urlString)) {
try {
URI uri = URI.create(urlString);
URL url = new URL(
uri.getScheme() != null ? uri.getScheme() : "",
uri.getAuthority() != null ? uri.getAuthority() : "",
"");
mBinding.url.setText(url.toString());

} catch (MalformedURLException e) {
mBinding.url.setText("");
}

} else {
mBinding.url.setText(urlString);
}
}

public void setIsInsecure(boolean aIsInsecure) {
if (!(mAttachedWindow.getSessionStack().getCurrentUri().startsWith("data") &&
mAttachedWindow.getSessionStack().isPrivateMode())) {
mBinding.insecureIcon.setVisibility(aIsInsecure ? View.VISIBLE : View.GONE);
}
}

public void setInsecureVisibility(int visibility) {
mBinding.insecureIcon.setVisibility(visibility);
}

}
Loading