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

Commit

Permalink
UI Polishing (#1915)
Browse files Browse the repository at this point in the history
* URL text hint truncates

Quick and dirt fix for this, better URL UI handling in 1.5

* Language settings panels fixes

* Tooltip fixes

* Languages and display settings style updates

* Vertical separators for the tray

* Responsive library layout

* Reverte of URL hint fix
  • Loading branch information
keianhzo authored and bluemarvin committed Oct 7, 2019
1 parent 9d3531a commit 12295cb
Show file tree
Hide file tree
Showing 23 changed files with 254 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import android.text.SpannableString;
import android.text.style.ImageSpan;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.Dimension;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.databinding.BindingAdapter;
Expand Down Expand Up @@ -65,4 +67,11 @@ public static void setSpannableString(@NonNull TextView textView, Drawable drawa
spannableString.setSpan(span, spannableString.toString().indexOf("@"), spannableString.toString().indexOf("@")+1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
textView.setText(spannableString);
}

@BindingAdapter("layout_height")
public static void setLayoutHeight(@NonNull View view, @NonNull @Dimension float dimen) {
ViewGroup.LayoutParams params = view.getLayoutParams();
params.height = (int)dimen;
view.setLayoutParams(params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class BookmarkAdapter extends RecyclerView.Adapter<BookmarkAdapter.Bookma
private int mMaxPadding;
private int mIconColorHover;
private int mIconNormalColor;
private boolean mIsNarrowLayout;

@Nullable
private final BookmarkItemCallback mBookmarkItemCallback;
Expand All @@ -51,9 +52,18 @@ public BookmarkAdapter(@Nullable BookmarkItemCallback clickCallback, Context aCo
mIconColorHover = aContext.getResources().getColor(R.color.white, aContext.getTheme());
mIconNormalColor = aContext.getResources().getColor(R.color.rhino, aContext.getTheme());

mIsNarrowLayout = false;

setHasStableIds(true);
}

public void setNarrow(boolean isNarrow) {
if (mIsNarrowLayout != isNarrow) {
mIsNarrowLayout = isNarrow;
notifyDataSetChanged();
}
}

public void setBookmarkList(final List<? extends BookmarkNode> bookmarkList) {
if (mBookmarkList == null) {
mBookmarkList = bookmarkList;
Expand Down Expand Up @@ -116,8 +126,10 @@ public BookmarkViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int view
BookmarkItemBinding binding = DataBindingUtil
.inflate(LayoutInflater.from(parent.getContext()), R.layout.bookmark_item,
parent, false);

binding.setCallback(mBookmarkItemCallback);
binding.setIsHovered(false);
binding.setIsNarrow(mIsNarrowLayout);
binding.layout.setOnHoverListener((view, motionEvent) -> {
int ev = motionEvent.getActionMasked();
switch (ev) {
Expand Down Expand Up @@ -184,6 +196,7 @@ public BookmarkViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int view
@Override
public void onBindViewHolder(@NonNull BookmarkViewHolder holder, int position) {
holder.binding.setItem(mBookmarkList.get(position));
holder.binding.setIsNarrow(mIsNarrowLayout);
holder.binding.executePendingBindings();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class HistoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
private int mMaxPadding;
private int mIconColorHover;
private int mIconNormalColor;
private boolean mIsNarrowLayout;

@Nullable
private final HistoryItemCallback mHistoryItemCallback;
Expand All @@ -56,9 +57,18 @@ public HistoryAdapter(@Nullable HistoryItemCallback clickCallback, Context aCont
mIconColorHover = aContext.getResources().getColor(R.color.white, aContext.getTheme());
mIconNormalColor = aContext.getResources().getColor(R.color.rhino, aContext.getTheme());

mIsNarrowLayout = false;

setHasStableIds(true);
}

public void setNarrow(boolean isNarrow) {
if (mIsNarrowLayout != isNarrow) {
mIsNarrowLayout = isNarrow;
notifyDataSetChanged();
}
}

public void setHistoryList(final List<? extends VisitInfo> historyList) {
if (mHistoryList == null) {
mHistoryList = historyList;
Expand Down Expand Up @@ -131,6 +141,7 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
parent, false);
binding.setCallback(mHistoryItemCallback);
binding.setIsHovered(false);
binding.setIsNarrow(mIsNarrowLayout);
binding.layout.setOnHoverListener((view, motionEvent) -> {
int ev = motionEvent.getActionMasked();
switch (ev) {
Expand Down Expand Up @@ -210,6 +221,7 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
if (holder instanceof HistoryItemViewHolder) {
HistoryItemViewHolder item = (HistoryItemViewHolder) holder;
item.binding.setItem(mHistoryList.get(position));
item.binding.setIsNarrow(mIsNarrowLayout);
item.binding.executePendingBindings();

} else if (holder instanceof HistoryItemViewHeaderHolder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.audio.AudioEngine;
import org.mozilla.vrbrowser.browser.BookmarksStore;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.browser.engine.SessionStack;
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.databinding.BookmarksBinding;
Expand Down Expand Up @@ -153,6 +154,14 @@ private void showBookmarks(List<BookmarkNode> aBookmarks) {
mBinding.executePendingBindings();
}

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);

double width = Math.ceil(getWidth()/getContext().getResources().getDisplayMetrics().density);
mBookmarkAdapter.setNarrow(width < SettingsStore.WINDOW_WIDTH_DEFAULT);
}

// BookmarksStore.BookmarksViewListener
@Override
public void onBookmarksUpdated() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.browser.HistoryStore;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.browser.engine.SessionStack;
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.databinding.HistoryBinding;
Expand Down Expand Up @@ -199,6 +200,14 @@ private void showHistory(List<VisitInfo> historyItems) {
mBinding.executePendingBindings();
}

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);

double width = Math.ceil(getWidth()/getContext().getResources().getDisplayMetrics().density);
mHistoryAdapter.setNarrow(width < SettingsStore.WINDOW_WIDTH_DEFAULT);
}

// HistoryStore.HistoryListener
@Override
public void onHistoryUpdated() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.MotionEvent;

import androidx.annotation.IdRes;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatImageButton;

Expand All @@ -41,6 +42,7 @@ public class UIButton extends AppCompatImageButton implements CustomUIButton {
private String mTooltipText;
private int mTooltipDelay;
private float mTooltipDensity;
private @LayoutRes int mTooltipLayout;
private boolean mCurvedTooltip = true;
private ViewUtils.TooltipPosition mTooltipPosition;
private boolean mIsPrivate;
Expand All @@ -66,11 +68,14 @@ public UIButton(Context context, AttributeSet attrs, int defStyleAttr) {
mNotificationModeTintColorListRes = attributes.getResourceId(R.styleable.UIButton_notificationModeTintColorList, 0);
mTooltipDelay = attributes.getInt(R.styleable.UIButton_tooltipDelay, getResources().getInteger(R.integer.tooltip_delay));
mTooltipPosition = ViewUtils.TooltipPosition.fromId(attributes.getInt(R.styleable.UIButton_tooltipPosition, ViewUtils.TooltipPosition.BOTTOM.ordinal()));
mTooltipDensity = attributes.getFloat(R.styleable.UIButton_tooltipDensity, getContext().getResources().getDisplayMetrics().density);
TypedValue densityValue = new TypedValue();
getResources().getValue(R.dimen.tooltip_default_density, densityValue, true);
mTooltipDensity = attributes.getFloat(R.styleable.UIButton_tooltipDensity, densityValue.getFloat());
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
TypedArray arr = context.obtainStyledAttributes(attrs, new int [] {android.R.attr.tooltipText});
mTooltipText = arr.getString(0);
}
mTooltipLayout = attributes.getResourceId(R.styleable.UIButton_tooltipLayout, R.layout.tooltip);
attributes.recycle();

mBackground = getBackground();
Expand Down Expand Up @@ -223,7 +228,7 @@ public void run() {
}

if (mTooltipView == null) {
mTooltipView = new TooltipWidget(getContext());
mTooltipView = new TooltipWidget(getContext(), mTooltipLayout);
}
mTooltipView.setCurvedMode(mCurvedTooltip);
mTooltipView.setText(getTooltip());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.ui.views.UIButton;
import org.mozilla.vrbrowser.ui.widgets.settings.SettingsWidget;
import org.mozilla.vrbrowser.utils.SystemUtils;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -485,7 +484,7 @@ public void run() {
mLibraryNotification.getPlacement().translationX = (offsetViewBounds.left + mBookmarksButton.getWidth() / 2.0f) * ratio;
mLibraryNotification.getPlacement().translationY = ((offsetViewBounds.top - 60) * ratio);
mLibraryNotification.getPlacement().translationZ = 25.0f;
mLibraryNotification.getPlacement().density = 3.0f;
mLibraryNotification.getPlacement().density = WidgetPlacement.floatDimension(getContext(), R.dimen.tray_tooltip_density);
mLibraryNotification.setText(R.string.bookmarks_saved_notification);
mLibraryNotification.setCurvedMode(false);
mLibraryNotification.show(UIWidget.CLEAR_FOCUS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Point;
import android.graphics.Typeface;
import android.preference.PreferenceManager;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.StyleSpan;
import android.view.LayoutInflater;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;

import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.databinding.OptionsLanguageBinding;
import org.mozilla.vrbrowser.ui.adapters.Language;
import org.mozilla.vrbrowser.ui.widgets.WidgetManagerDelegate;
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
import org.mozilla.vrbrowser.utils.LocaleUtils;
import org.mozilla.vrbrowser.utils.ViewUtils;

import java.util.List;

Expand Down Expand Up @@ -85,9 +92,7 @@ protected void onDismiss() {
};

private void setVoiceLanguage() {
String voiceLanguageString = LocaleUtils.getVoiceSearchLanguageString(getContext());
String text = getContext().getResources().getString(R.string.language_options_voice_search_language, voiceLanguageString);
mBinding.voiceSearchLanguageButton.setDescription(ViewUtils.getSpannedText(text));
mBinding.voiceSearchLanguageDescription.setText(getSpannedLanguageText(LocaleUtils.getVoiceSearchLanguageString(getContext())), TextView.BufferType.SPANNABLE);
}

private void setContentLanguage() {
Expand All @@ -96,13 +101,30 @@ private void setContentLanguage() {
if (preferredLanguages.size() > 0) {
text = preferredLanguages.get(0).getName();
}
mBinding.contentLanguageButton.setDescription(ViewUtils.getSpannedText(getContext().getResources().getString(R.string.language_options_content_language, text)));
mBinding.contentLanguageDescription.setText(getSpannedLanguageText(text));
}

private void setDisplayLanguage() {
String displayLanguageString = LocaleUtils.getDisplayCurrentLanguageString();
String text = getContext().getResources().getString(R.string.language_options_display_language, displayLanguageString);
mBinding.displayLanguageButton.setDescription(ViewUtils.getSpannedText(text));
mBinding.displayLanguageDescription.setText(getSpannedLanguageText(LocaleUtils.getDisplayCurrentLanguageString()));
}

private int getLanguageIndex(@NonNull String text) {
if (text.contains("(")) {
return text.indexOf("(");
}

if (text.contains("[")) {
return text.indexOf("[");
}

return text.length() - 1;
}

private SpannableStringBuilder getSpannedLanguageText(@NonNull String language) {
int end = getLanguageIndex(language);
SpannableStringBuilder spanned = new SpannableStringBuilder(language);
spanned.setSpan(new StyleSpan(Typeface.BOLD), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return spanned;
}

private OnClickListener mContentListener = v -> mDelegate.showView(mContentLanguage);
Expand All @@ -123,4 +145,10 @@ private void setDisplayLanguage() {
}
};

@Override
public Point getDimensions() {
return new Point( WidgetPlacement.dpDimension(getContext(), R.dimen.language_options_width),
WidgetPlacement.dpDimension(getContext(), R.dimen.language_options_height));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public boolean isEditing() {
protected void onGlobalFocusChanged(View oldFocus, View newFocus) {}

public Point getDimensions() {
return new Point( WidgetPlacement.dpDimension(getContext(), R.dimen.developer_options_width),
WidgetPlacement.dpDimension(getContext(), R.dimen.developer_options_height));
return new Point( WidgetPlacement.dpDimension(getContext(), R.dimen.options_width),
WidgetPlacement.dpDimension(getContext(), R.dimen.options_height));
}

protected boolean reset() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.mozilla.vrbrowser.ui.widgets.dialogs.RestartDialogWidget;
import org.mozilla.vrbrowser.ui.widgets.dialogs.UIDialog;
import org.mozilla.vrbrowser.ui.widgets.prompts.AlertPromptWidget;
import org.mozilla.vrbrowser.utils.SystemUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
Expand Down Expand Up @@ -186,9 +185,9 @@ private void initialize(Context aContext) {

mAudio = AudioEngine.fromContext(aContext);

mViewMarginH = mWidgetPlacement.width - WidgetPlacement.dpDimension(getContext(), R.dimen.developer_options_width);
mViewMarginH = mWidgetPlacement.width - WidgetPlacement.dpDimension(getContext(), R.dimen.options_width);
mViewMarginH = WidgetPlacement.convertDpToPixel(getContext(), mViewMarginH);
mViewMarginV = mWidgetPlacement.height - WidgetPlacement.dpDimension(getContext(), R.dimen.developer_options_height);
mViewMarginV = mWidgetPlacement.height - WidgetPlacement.dpDimension(getContext(), R.dimen.options_height);
mViewMarginV = WidgetPlacement.convertDpToPixel(getContext(), mViewMarginV);
}

Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/layout/bookmark_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools">

<data>
<import type="android.widget.LinearLayout"/>

<variable
name="item"
Expand All @@ -16,11 +17,16 @@
<variable
name="isHovered"
type="boolean" />

<variable
name="isNarrow"
type="boolean" />
</data>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="@dimen/library_item_row_height"
app:layout_height="@{isNarrow ? @dimen/library_item_row_height_narrow : @dimen/library_item_row_height}"
android:background="@color/void_color">

<RelativeLayout
Expand All @@ -45,7 +51,7 @@
android:layout_centerVertical="true"
android:layout_toStartOf="@id/time_buttons"
android:gravity="center_vertical"
android:orientation="horizontal">
android:orientation="@{isNarrow ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL}">

<TextView
android:id="@+id/title"
Expand Down
Loading

0 comments on commit 12295cb

Please sign in to comment.