Skip to content

Commit

Permalink
onSwipeUp gesture added
Browse files Browse the repository at this point in the history
  • Loading branch information
1311-hack1 committed Oct 14, 2024
1 parent 3831f15 commit 2d0ae40
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ found in the LICENSE file.
android:orientation="vertical">

<FrameLayout
android:id="@+id/toolbar_frame_view"
android:id="@+id/toolbar_frame_view_top"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="8dp"
android:padding="0dp"
android:visibility="visible">
android:visibility="gone">

<LinearLayout
android:id="@+id/pinned_apps_container"
Expand Down Expand Up @@ -100,6 +100,7 @@ found in the LICENSE file.
android:layout_gravity="top"
android:visibility="gone"
android:layout_width="52dp"
android:layout_height="56dp"
style="@style/ToolbarHoverableButton" />
</LinearLayout>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.view.GestureDetector;
import android.view.animation.DecelerateInterpolator;

import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
Expand Down Expand Up @@ -113,6 +115,8 @@ public class ToolbarPhone extends ToolbarLayout
protected static final int TAB_SWITCHER = 1;
protected static final int ENTERING_TAB_SWITCHER = 2;
protected static final int EXITING_TAB_SWITCHER = 3;
private static final int SWIPE_THRESHOLD = 100;
private static final int SWIPE_VELOCITY_THRESHOLD = 100;

@ViewDebug.ExportedProperty(
category = "chrome",
Expand All @@ -132,6 +136,7 @@ public class ToolbarPhone extends ToolbarLayout
private ObservableSupplier<Tracker> mTrackerSupplier;

private ViewGroup mTabSwitcherButtonContainer;
private ViewGroup mToolbarFrameViewTop;
private ViewGroup mOptionalButtonContainer;
private ViewGroup mToolbarButtonsContainer;
protected @Nullable ToggleTabStackButton mToggleTabStackButton;
Expand All @@ -142,6 +147,10 @@ public class ToolbarPhone extends ToolbarLayout
protected ImageView mToolbarShadow;
private OptionalButtonCoordinator mOptionalButtonCoordinator;

private GestureDetector gestureDetector;

private Context context;

@ViewDebug.ExportedProperty(category = "chrome")
protected int mTabSwitcherState;

Expand Down Expand Up @@ -334,6 +343,20 @@ public ToolbarPhone(Context context, AttributeSet attrs) {
mHomeSurfaceToolbarBackgroundColor =
ChromeColors.getSurfaceColor(
getContext(), R.dimen.home_surface_background_color_elevation);

gestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
final int SWIPE_THRESHOLD = 100;
final int SWIPE_VELOCITY_THRESHOLD = 100;

if (e1.getY() - e2.getY() > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
onSwipeUp();
return true;
}
return false;
}
});
if (mIsSurfacePolishEnabled) {
float homeSurfaceLocationBarBackgroundColorAlpha =
ResourcesCompat.getFloat(
Expand All @@ -353,6 +376,7 @@ public void onFinishInflate() {

mToolbarButtonsContainer = findViewById(R.id.toolbar_buttons);
mOptionalButtonContainer = findViewById(R.id.optional_button_container);
mToolbarFrameViewTop = findViewById(R.id.toolbar_frame_view_top);
mTabSwitcherButtonContainer = findViewById(R.id.tab_switcher_button_container);
mHomeButton = findViewById(R.id.home_button);
mUrlBar = findViewById(R.id.url_bar);
Expand Down Expand Up @@ -599,6 +623,10 @@ public boolean onTouchEvent(MotionEvent ev) {
return getToolbarDataProvider().getNewTabPageDelegate().dispatchTouchEvent(ev);
}

if (gestureDetector != null) {
gestureDetector.onTouchEvent(ev);
}

return super.onTouchEvent(ev);
}

Expand Down Expand Up @@ -3201,7 +3229,16 @@ void setNtpSearchBoxScrollFractionForTesting(float ntpSearchBoxScrollFraction) {
mNtpSearchBoxScrollFraction = ntpSearchBoxScrollFraction;
}

public void ShowTabSwitcherToolbarContiainer() {
return;
private void onSwipeUp() {
if (mToolbarFrameViewTop.getVisibility() == View.GONE) {
mToolbarFrameViewTop.setVisibility(View.VISIBLE);

mToolbarFrameViewTop.setTranslationY(200);
mToolbarFrameViewTop.animate()
.translationY(0)
.setDuration(300)
.setInterpolator(new DecelerateInterpolator())
.start();
}
}
}

0 comments on commit 2d0ae40

Please sign in to comment.