Skip to content

Commit

Permalink
Implement Zoom UI in Hamburger Menu
Browse files Browse the repository at this point in the history
Unlike the general menu items with ImageView&TextView layout, a
Zoom menu has ImageView&TextView&+/- ImageViews layout and only
+/- ImageViews should handle hover and click events.
This patch configures the zoom layout and add the relevant code.
The +/- ImageViews are connected to the page zoom feature, and this
Zoom UI appears only in chromium-backend.
  • Loading branch information
MyidShin authored and svillar committed Feb 16, 2024
1 parent c169074 commit 290eef6
Show file tree
Hide file tree
Showing 15 changed files with 248 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ android {
buildConfigField "String[]", "SPEECH_SERVICES", "{ com.igalia.wolvic.speech.SpeechServices.MEETKAI }"
buildConfigField "Boolean", "SUPPORTS_SYSTEM_NOTIFICATIONS", "false"
buildConfigField "Float", "DEFAULT_DENSITY", "1.25f"
buildConfigField "Boolean", "ENABLE_PAGE_ZOOM", "false"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resValue 'string', 'app_name', 'Wolvic'
resValue 'string', 'HOMEPAGE_URL', "https://wolvic.com/start"
Expand Down Expand Up @@ -360,6 +362,7 @@ android {
arguments "-DCHROMIUM=ON"
}
}
buildConfigField "Boolean", "ENABLE_PAGE_ZOOM", "true"
}

webkit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.graphics.Matrix;
import android.view.ViewGroup;

import androidx.annotation.AnyThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

Expand Down Expand Up @@ -240,6 +241,24 @@ public WTextInput getTextInput() {
return mTextInput;
}

@AnyThread
@Override
public void pageZoomIn() {
mTab.pageZoomIn();
}

@AnyThread
@Override
public void pageZoomOut() {
mTab.pageZoomOut();
}

@AnyThread
@Override
public int getCurrentZoomLevel() {
return mTab.getCurrentZoomLevel();
}

@NonNull
@Override
public WPanZoomController getPanZoomController() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ public WTextInput getTextInput() {
return mTextInput;
}

@Override
public void pageZoomIn() {}

@Override
public void pageZoomOut() {}

@Override
public int getCurrentZoomLevel() { return 0; }

@NonNull
@Override
public WPanZoomController getPanZoomController() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,11 @@ public boolean isPassthroughSupported() {
(DeviceType.isPicoXR() && Build.ID.compareTo(kPicoVersionPassthroughUpdate) >= 0);
}

@Override
public boolean isPageZoomEnabled() {
return BuildConfig.ENABLE_PAGE_ZOOM;
}

@Override
public void setHeadLockEnabled(boolean isHeadLockEnabled) {
queueRunnable(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2769,6 +2769,15 @@ void dispatchLocation(double latitude, double longitude, double altitude, float
WTextInput getTextInput();


@AnyThread
void pageZoomIn();

@AnyThread
void pageZoomOut();

@AnyThread
int getCurrentZoomLevel();

/**
* Get the PanZoomController instance for this session.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,25 @@ public void setParentSession(@NonNull Session parentSession) {
mState.mParentId = parentSession.getId();
}

public void pageZoomIn() {
if (mState.mSession != null) {
mState.mSession.pageZoomIn();
}
}

public void pageZoomOut() {
if (mState.mSession != null) {
mState.mSession.pageZoomOut();
}
}

public int getCurrentZoomLevel() {
if (mState.mSession != null) {
return mState.mSession.getCurrentZoomLevel();
}
return 0;
}

// NavigationDelegate

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.igalia.wolvic.databinding.HamburgerMenuAddonItemBinding;
import com.igalia.wolvic.databinding.HamburgerMenuAddonsSettingsItemBinding;
import com.igalia.wolvic.databinding.HamburgerMenuItemBinding;
import com.igalia.wolvic.databinding.HamburgerMenuZoomItemBinding;
import com.igalia.wolvic.utils.SystemUtils;
import com.igalia.wolvic.utils.ViewUtils;

Expand All @@ -41,11 +42,12 @@ public class HamburgerMenuAdapter extends RecyclerView.Adapter<RecyclerView.View

public static class MenuItem {

@IntDef(value = { TYPE_DEFAULT, TYPE_ADDON, TYPE_ADDONS_SETTINGS })
@IntDef(value = { TYPE_DEFAULT, TYPE_ADDON, TYPE_ADDONS_SETTINGS, TYPE_ZOOM })
public @interface MenuItemType {}
public static final int TYPE_DEFAULT = 0;
public static final int TYPE_ADDON = 1;
public static final int TYPE_ADDONS_SETTINGS = 2;
public static final int TYPE_ZOOM = 3;

@MenuItem.MenuItemType
int mItemType;
Expand All @@ -56,6 +58,8 @@ public static class MenuItem {
int mIcon;
Function<MenuItem, Void> mCallback;
Action mAction;
String mZoomLevel;
Function<Boolean, Void> mZoomCallback;

public MenuItem(@NonNull Builder builder) {
mItemType = builder.mItemType;
Expand All @@ -65,6 +69,8 @@ public MenuItem(@NonNull Builder builder) {
mIcon = builder.mIcon;
mCallback = builder.mCallback;
mAction = builder.mAction;
mZoomLevel = builder.mZoomLevel;
mZoomCallback = builder.mZoomCallback;;
}

public int getItemType() {
Expand Down Expand Up @@ -107,6 +113,13 @@ public void setIcon(@DrawableRes int icon) {
mIcon = icon;
}

public void setZoomLevel(String zoomLevel) {
mZoomLevel = zoomLevel;
}

public String getZoomLevel() { return mZoomLevel; }


public static class Builder {

@MenuItem.MenuItemType
Expand All @@ -118,6 +131,8 @@ public static class Builder {
int mIcon;
Function<MenuItem, Void> mCallback;
Action mAction;
String mZoomLevel;
Function<Boolean, Void> mZoomCallback;

public Builder(@MenuItem.MenuItemType int type, @Nullable Function<MenuItem, Void> callback) {
this.mItemType = type;
Expand Down Expand Up @@ -149,6 +164,12 @@ public MenuItem.Builder withAction(@Nullable Action action) {
return this;
}

public MenuItem.Builder withZoom(@NonNull String zoomLevel, Function<Boolean, Void> callback) {
this.mZoomLevel = zoomLevel;
this.mZoomCallback = callback;
return this;
}

public MenuItem build(){
return new MenuItem(this);
}
Expand Down Expand Up @@ -226,6 +247,11 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
parent, false);

return new HamburgerMenuItemAddonsSettingsHolder(binding);
} else if (viewType == MenuItem.TYPE_ZOOM) {
HamburgerMenuZoomItemBinding binding = DataBindingUtil
.inflate(LayoutInflater.from(parent.getContext()), R.layout.hamburger_menu_zoom_item,
parent, false);
return new HamburgerMenuZoomItemHolder(binding);
}

throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly");
Expand Down Expand Up @@ -286,6 +312,17 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int positi
viewHolder.binding.container.setOnHoverListener(mHoverListener);
ViewUtils.setStickyClickListener(viewHolder.binding.container, callback);
setBackground(viewHolder.binding.container, item, position);
} else if (holder instanceof HamburgerMenuZoomItemHolder) {
HamburgerMenuZoomItemHolder viewHolder = (HamburgerMenuZoomItemHolder) holder;
viewHolder.binding.setItem(item);
viewHolder.binding.container.setTag(R.string.position_tag, position);
viewHolder.binding.container.findViewById(R.id.zoomOutImage).setOnClickListener(v -> {
item.mZoomCallback.apply(true);
});
viewHolder.binding.container.findViewById(R.id.zoomInImage).setOnClickListener(v -> {
item.mZoomCallback.apply(false);
});
setBackground(viewHolder.binding.container, item, position);
}
}

Expand Down Expand Up @@ -401,4 +438,13 @@ static class HamburgerMenuItemAddonsSettingsHolder extends RecyclerView.ViewHold
}
}

static class HamburgerMenuZoomItemHolder extends RecyclerView.ViewHolder {

final HamburgerMenuZoomItemBinding binding;

HamburgerMenuZoomItemHolder(@NonNull HamburgerMenuZoomItemBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,21 @@ public void onSaveWebApp() {

showSaveWebAppDialog();
}

@Override
public void onPageZoomIn() {
mAttachedWindow.getSession().pageZoomIn();
}

@Override
public void onPageZoomOut() {
mAttachedWindow.getSession().pageZoomOut();
}

@Override
public int getCurrentZoomLevel() {
return mAttachedWindow.getSession().getCurrentZoomLevel();
}
});
boolean isSendTabEnabled = false;
if (URLUtil.isHttpUrl(mAttachedWindow.getSession().getCurrentUri()) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ interface WebXRListener {
void togglePassthrough();
boolean isPassthroughEnabled();
boolean isPassthroughSupported();
boolean isPageZoomEnabled();
void setHeadLockEnabled(boolean isHeadLockEnabled);
void recenterUIYaw(@YawTarget int target);
void setCylinderDensity(float aDensity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public interface MenuDelegate {
void onSaveWebApp();
void onPassthrough();
boolean isPassthroughEnabled();
void onPageZoomIn();
void onPageZoomOut();
int getCurrentZoomLevel();
}

public static final int SWITCH_ITEM_ID = 0;
Expand Down Expand Up @@ -313,6 +316,19 @@ private void updateItems() {
.build());
}

if (mWidgetManager != null && mWidgetManager.isPageZoomEnabled() && mDelegate != null) {
mItems.add(new HamburgerMenuAdapter.MenuItem.Builder(
HamburgerMenuAdapter.MenuItem.TYPE_ZOOM, null)
.withZoom(Integer.toString(mDelegate.getCurrentZoomLevel()) + "%",
(isZoomOut) -> {
if (isZoomOut) mDelegate.onPageZoomOut();
else mDelegate.onPageZoomIn();
updateItems();
return null;
})
.build());
}

mAdapter.setItems(mItems);
mAdapter.notifyDataSetChanged();

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_icon_minus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M8,12C8,11.448 8.448,11 9,11H15C15.552,11 16,11.448 16,12C16,12.552 15.552,13 15,13H9C8.448,13 8,12.552 8,12ZM7.25,2.388C8.549,2.099 10.124,2 12,2C13.876,2 15.451,2.099 16.75,2.388C18.06,2.679 19.149,3.176 19.986,4.014C20.824,4.851 21.321,5.94 21.612,7.25C21.901,8.549 22,10.124 22,12C22,13.876 21.901,15.451 21.612,16.75C21.321,18.06 20.824,19.149 19.986,19.986C19.149,20.824 18.06,21.321 16.75,21.612C15.451,21.901 13.876,22 12,22C10.124,22 8.549,21.901 7.25,21.612C5.94,21.321 4.851,20.824 4.014,19.986C3.176,19.149 2.679,18.06 2.388,16.75C2.099,15.451 2,13.876 2,12C2,10.124 2.099,8.549 2.388,7.25C2.679,5.94 3.176,4.851 4.014,4.014C4.851,3.176 5.94,2.679 7.25,2.388Z"
android:fillColor="#ffffff"
android:fillType="evenOdd"/>
</vector>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_icon_plus.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M13,9C13,8.448 12.552,8 12,8C11.448,8 11,8.448 11,9V11H9C8.448,11 8,11.448 8,12C8,12.552 8.448,13 9,13H11V15C11,15.552 11.448,16 12,16C12.552,16 13,15.552 13,15V13H15C15.552,13 16,12.552 16,12C16,11.448 15.552,11 15,11H13V9ZM7.25,2.388C8.549,2.099 10.124,2 12,2C13.876,2 15.451,2.099 16.75,2.388C18.06,2.679 19.149,3.176 19.986,4.014C20.824,4.851 21.321,5.94 21.612,7.25C21.901,8.549 22,10.124 22,12C22,13.876 21.901,15.451 21.612,16.75C21.321,18.06 20.824,19.149 19.986,19.986C19.149,20.824 18.06,21.321 16.75,21.612C15.451,21.901 13.876,22 12,22C10.124,22 8.549,21.901 7.25,21.612C5.94,21.321 4.851,20.824 4.014,19.986C3.176,19.149 2.679,18.06 2.388,16.75C2.099,15.451 2,13.876 2,12C2,10.124 2.099,8.549 2.388,7.25C2.679,5.94 3.176,4.851 4.014,4.014C4.851,3.176 5.94,2.679 7.25,2.388Z"
android:fillColor="#ffffff"
android:fillType="evenOdd"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_icon_zoom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:viewportHeight="1920"
android:viewportWidth="1920" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">

<path android:fillColor="#FFFFFF" android:fillType="evenOdd" android:pathData="m1920,1766.7 l-368.1,-368.2c114.3,-146.8 183,-330.8 183,-531C1734.9,389.2 1345.7,0 867.5,0 389.2,0 0,389.2 0,867.5c0,478.3 389.2,867.5 867.5,867.5 200.2,0 384.1,-68.9 531,-183L1766.7,1920 1920,1766.7ZM867.5,1518c-358.8,0 -650.6,-291.8 -650.6,-650.6s291.8,-650.6 650.6,-650.6 650.6,291.8 650.6,650.6 -291.8,650.6 -650.6,650.6ZM975.9,487.9H759v271.1h-271.1v216.9h271.1v271.1h216.9v-271.1h271.1V759h-271.1v-271.1Z"/>
</vector>
Loading

0 comments on commit 290eef6

Please sign in to comment.