Commit a1fe2ba9 authored by Lijin Shen's avatar Lijin Shen Committed by Commit Bot

[Messages] Add swipe detection of message banner view.

Add a detector for message banner view. To detect swipe gestures, set
a swipe handler by MessageBannerView#setSwipeHandler.

Bug: 1123947
Change-Id: Ie8e1405e4bf4c31b37707a2d5e7f33b582283ea7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2473801Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Lijin Shen <lazzzis@google.com>
Cr-Commit-Position: refs/heads/master@{#822718}
parent ccf3906e
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
package org.chromium.components.messages; package org.chromium.components.messages;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
...@@ -14,6 +16,9 @@ import android.widget.TextView; ...@@ -14,6 +16,9 @@ import android.widget.TextView;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import org.chromium.components.browser_ui.widget.gesture.SwipeGestureListener;
import org.chromium.components.browser_ui.widget.gesture.SwipeGestureListener.SwipeHandler;
/** /**
* View representing the message banner. * View representing the message banner.
*/ */
...@@ -24,6 +29,7 @@ public class MessageBannerView extends LinearLayout { ...@@ -24,6 +29,7 @@ public class MessageBannerView extends LinearLayout {
private TextView mPrimaryButton; private TextView mPrimaryButton;
private ImageView mSecondaryButton; private ImageView mSecondaryButton;
private View mDivider; private View mDivider;
private SwipeGestureListener mSwipeGestureDetector;
public MessageBannerView(Context context, @Nullable AttributeSet attrs) { public MessageBannerView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs); super(context, attrs);
...@@ -70,4 +76,17 @@ public class MessageBannerView extends LinearLayout { ...@@ -70,4 +76,17 @@ public class MessageBannerView extends LinearLayout {
void setSecondaryIconContentDescription(String description) { void setSecondaryIconContentDescription(String description) {
mSecondaryButton.setContentDescription(description); mSecondaryButton.setContentDescription(description);
} }
void setSwipeHandler(SwipeHandler handler) {
mSwipeGestureDetector = new SwipeGestureListener(getContext(), handler);
}
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
if (mSwipeGestureDetector != null) {
return mSwipeGestureDetector.onTouchEvent(event) || super.onTouchEvent(event);
}
return super.onTouchEvent(event);
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment