2020-03-09 18:24:47 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-03-31 03:54:50 -07:00
|
|
|
package com.android.launcher3.views;
|
2020-03-09 18:24:47 -07:00
|
|
|
|
|
|
|
|
import android.content.Context;
|
2021-06-08 14:35:22 +01:00
|
|
|
import android.content.res.Configuration;
|
2020-03-09 18:24:47 -07:00
|
|
|
import android.graphics.CornerPathEffect;
|
|
|
|
|
import android.graphics.Paint;
|
2021-06-08 14:35:22 +01:00
|
|
|
import android.graphics.Rect;
|
2020-03-09 18:24:47 -07:00
|
|
|
import android.graphics.drawable.ShapeDrawable;
|
|
|
|
|
import android.os.Handler;
|
2021-04-09 09:58:53 +01:00
|
|
|
import android.util.Log;
|
2020-03-09 18:24:47 -07:00
|
|
|
import android.view.Gravity;
|
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
2021-04-09 09:58:53 +01:00
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
import androidx.annotation.Px;
|
2020-03-09 18:24:47 -07:00
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
|
|
2020-03-31 03:54:50 -07:00
|
|
|
import com.android.launcher3.AbstractFloatingView;
|
2020-04-13 17:15:05 -07:00
|
|
|
import com.android.launcher3.BaseDraggingActivity;
|
2021-09-19 19:27:07 -07:00
|
|
|
import com.android.launcher3.DeviceProfile;
|
2020-03-31 03:54:50 -07:00
|
|
|
import com.android.launcher3.R;
|
2020-03-09 18:24:47 -07:00
|
|
|
import com.android.launcher3.anim.Interpolators;
|
|
|
|
|
import com.android.launcher3.dragndrop.DragLayer;
|
|
|
|
|
import com.android.launcher3.graphics.TriangleShape;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A base class for arrow tip view in launcher
|
|
|
|
|
*/
|
|
|
|
|
public class ArrowTipView extends AbstractFloatingView {
|
|
|
|
|
|
2021-04-09 09:58:53 +01:00
|
|
|
private static final String TAG = ArrowTipView.class.getSimpleName();
|
2020-03-09 18:24:47 -07:00
|
|
|
private static final long AUTO_CLOSE_TIMEOUT_MILLIS = 10 * 1000;
|
|
|
|
|
private static final long SHOW_DELAY_MS = 200;
|
|
|
|
|
private static final long SHOW_DURATION_MS = 300;
|
|
|
|
|
private static final long HIDE_DURATION_MS = 100;
|
|
|
|
|
|
2020-04-13 17:15:05 -07:00
|
|
|
protected final BaseDraggingActivity mActivity;
|
2020-03-09 18:24:47 -07:00
|
|
|
private final Handler mHandler = new Handler();
|
2021-05-21 12:42:32 -05:00
|
|
|
private final int mArrowWidth;
|
2021-09-19 19:27:07 -07:00
|
|
|
private final int mArrowMinOffset;
|
2021-06-08 14:35:22 +01:00
|
|
|
private boolean mIsPointingUp;
|
2020-03-09 18:24:47 -07:00
|
|
|
private Runnable mOnClosed;
|
2021-06-08 14:35:22 +01:00
|
|
|
private View mArrowView;
|
2020-03-09 18:24:47 -07:00
|
|
|
|
|
|
|
|
public ArrowTipView(Context context) {
|
2021-05-21 12:42:32 -05:00
|
|
|
this(context, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ArrowTipView(Context context, boolean isPointingUp) {
|
2020-03-09 18:24:47 -07:00
|
|
|
super(context, null, 0);
|
2020-04-13 17:15:05 -07:00
|
|
|
mActivity = BaseDraggingActivity.fromContext(context);
|
2021-05-21 12:42:32 -05:00
|
|
|
mIsPointingUp = isPointingUp;
|
|
|
|
|
mArrowWidth = context.getResources().getDimensionPixelSize(R.dimen.arrow_toast_arrow_width);
|
2021-09-19 19:27:07 -07:00
|
|
|
mArrowMinOffset = context.getResources().getDimensionPixelSize(
|
|
|
|
|
R.dimen.dynamic_grid_cell_border_spacing);
|
2020-03-09 18:24:47 -07:00
|
|
|
init(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onControllerInterceptTouchEvent(MotionEvent ev) {
|
|
|
|
|
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
|
close(true);
|
2021-06-07 10:27:23 +01:00
|
|
|
if (mActivity.getDragLayer().isEventOverView(this, ev)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-03-09 18:24:47 -07:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void handleClose(boolean animate) {
|
|
|
|
|
if (mIsOpen) {
|
|
|
|
|
if (animate) {
|
|
|
|
|
animate().alpha(0f)
|
|
|
|
|
.withLayer()
|
|
|
|
|
.setStartDelay(0)
|
|
|
|
|
.setDuration(HIDE_DURATION_MS)
|
|
|
|
|
.setInterpolator(Interpolators.ACCEL)
|
2020-04-13 17:15:05 -07:00
|
|
|
.withEndAction(() -> mActivity.getDragLayer().removeView(this))
|
2020-03-09 18:24:47 -07:00
|
|
|
.start();
|
|
|
|
|
} else {
|
|
|
|
|
animate().cancel();
|
2020-04-13 17:15:05 -07:00
|
|
|
mActivity.getDragLayer().removeView(this);
|
2020-03-09 18:24:47 -07:00
|
|
|
}
|
|
|
|
|
if (mOnClosed != null) mOnClosed.run();
|
|
|
|
|
mIsOpen = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected boolean isOfType(int type) {
|
|
|
|
|
return (type & TYPE_ON_BOARD_POPUP) != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void init(Context context) {
|
|
|
|
|
inflate(context, R.layout.arrow_toast, this);
|
|
|
|
|
setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
|
2021-06-08 14:35:22 +01:00
|
|
|
mArrowView = findViewById(R.id.arrow);
|
|
|
|
|
updateArrowTipInView();
|
2020-03-09 18:24:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show Tip with specified string and Y location
|
|
|
|
|
*/
|
|
|
|
|
public ArrowTipView show(String text, int top) {
|
2020-06-09 20:28:52 -07:00
|
|
|
return show(text, Gravity.CENTER_HORIZONTAL, 0, top);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the ArrowTipView (tooltip) center, start, or end aligned.
|
|
|
|
|
*
|
2021-09-19 19:27:07 -07:00
|
|
|
* @param text The text to be shown in the tooltip.
|
|
|
|
|
* @param gravity The gravity aligns the tooltip center, start, or end.
|
2020-06-09 20:28:52 -07:00
|
|
|
* @param arrowMarginStart The margin from start to place arrow (ignored if center)
|
2021-09-19 19:27:07 -07:00
|
|
|
* @param top The Y coordinate of the bottom of tooltip.
|
2020-06-09 20:28:52 -07:00
|
|
|
* @return The tooltip.
|
|
|
|
|
*/
|
|
|
|
|
public ArrowTipView show(String text, int gravity, int arrowMarginStart, int top) {
|
2021-07-30 03:32:39 +00:00
|
|
|
return show(text, gravity, arrowMarginStart, top, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the ArrowTipView (tooltip) center, start, or end aligned.
|
|
|
|
|
*
|
|
|
|
|
* @param text The text to be shown in the tooltip.
|
|
|
|
|
* @param gravity The gravity aligns the tooltip center, start, or end.
|
|
|
|
|
* @param arrowMarginStart The margin from start to place arrow (ignored if center)
|
|
|
|
|
* @param top The Y coordinate of the bottom of tooltip.
|
|
|
|
|
* @param shouldAutoClose If Tooltip should be auto close.
|
|
|
|
|
* @return The tooltip.
|
|
|
|
|
*/
|
|
|
|
|
public ArrowTipView show(
|
|
|
|
|
String text, int gravity, int arrowMarginStart, int top, boolean shouldAutoClose) {
|
2020-03-09 18:24:47 -07:00
|
|
|
((TextView) findViewById(R.id.text)).setText(text);
|
2020-06-09 20:28:52 -07:00
|
|
|
ViewGroup parent = mActivity.getDragLayer();
|
|
|
|
|
parent.addView(this);
|
2020-03-09 18:24:47 -07:00
|
|
|
|
2021-09-19 19:27:07 -07:00
|
|
|
DeviceProfile grid = mActivity.getDeviceProfile();
|
|
|
|
|
|
2020-03-09 18:24:47 -07:00
|
|
|
DragLayer.LayoutParams params = (DragLayer.LayoutParams) getLayoutParams();
|
2020-06-09 20:28:52 -07:00
|
|
|
params.gravity = gravity;
|
2021-09-19 19:27:07 -07:00
|
|
|
params.leftMargin = mArrowMinOffset + grid.getInsets().left;
|
|
|
|
|
params.rightMargin = mArrowMinOffset + grid.getInsets().right;
|
2021-06-08 14:35:22 +01:00
|
|
|
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mArrowView.getLayoutParams();
|
2021-09-19 19:27:07 -07:00
|
|
|
|
2020-06-09 20:28:52 -07:00
|
|
|
lp.gravity = gravity;
|
2021-04-29 14:20:19 -07:00
|
|
|
|
|
|
|
|
if (parent.getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
|
|
|
|
|
arrowMarginStart = parent.getMeasuredWidth() - arrowMarginStart;
|
|
|
|
|
}
|
2020-06-09 20:28:52 -07:00
|
|
|
if (gravity == Gravity.END) {
|
2021-09-19 19:27:07 -07:00
|
|
|
lp.setMarginEnd(Math.max(mArrowMinOffset,
|
|
|
|
|
parent.getMeasuredWidth() - params.rightMargin - arrowMarginStart
|
|
|
|
|
- mArrowWidth / 2));
|
2020-06-09 20:28:52 -07:00
|
|
|
} else if (gravity == Gravity.START) {
|
2021-09-19 19:27:07 -07:00
|
|
|
lp.setMarginStart(Math.max(mArrowMinOffset,
|
|
|
|
|
arrowMarginStart - params.leftMargin - mArrowWidth / 2));
|
2020-06-09 20:28:52 -07:00
|
|
|
}
|
|
|
|
|
requestLayout();
|
2021-05-21 12:42:32 -05:00
|
|
|
post(() -> setY(top - (mIsPointingUp ? 0 : getHeight())));
|
2021-06-07 10:27:23 +01:00
|
|
|
|
|
|
|
|
mIsOpen = true;
|
2021-07-30 03:32:39 +00:00
|
|
|
if (shouldAutoClose) {
|
|
|
|
|
mHandler.postDelayed(() -> handleClose(true), AUTO_CLOSE_TIMEOUT_MILLIS);
|
|
|
|
|
}
|
2020-03-09 18:24:47 -07:00
|
|
|
setAlpha(0);
|
|
|
|
|
animate()
|
|
|
|
|
.alpha(1f)
|
|
|
|
|
.withLayer()
|
|
|
|
|
.setStartDelay(SHOW_DELAY_MS)
|
|
|
|
|
.setDuration(SHOW_DURATION_MS)
|
|
|
|
|
.setInterpolator(Interpolators.DEACCEL)
|
|
|
|
|
.start();
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-09 09:58:53 +01:00
|
|
|
/**
|
2021-06-08 14:35:22 +01:00
|
|
|
* Show the ArrowTipView (tooltip) custom aligned. The tooltip is vertically flipped if it
|
|
|
|
|
* cannot fit on screen in the requested orientation.
|
2021-04-09 09:58:53 +01:00
|
|
|
*
|
2021-06-07 10:27:23 +01:00
|
|
|
* @param text The text to be shown in the tooltip.
|
|
|
|
|
* @param arrowXCoord The X coordinate for the arrow on the tooltip. The arrow is usually in the
|
|
|
|
|
* center of tooltip unless the tooltip goes beyond screen margin.
|
|
|
|
|
* @param yCoord The Y coordinate of the pointed tip end of the tooltip.
|
|
|
|
|
* @return The tool tip view. {@code null} if the tip can not be shown.
|
2021-04-09 09:58:53 +01:00
|
|
|
*/
|
2021-06-07 10:27:23 +01:00
|
|
|
@Nullable public ArrowTipView showAtLocation(String text, @Px int arrowXCoord, @Px int yCoord) {
|
2021-07-30 03:32:39 +00:00
|
|
|
return showAtLocation(
|
|
|
|
|
text,
|
|
|
|
|
arrowXCoord,
|
|
|
|
|
/* yCoordDownPointingTip= */ yCoord,
|
|
|
|
|
/* yCoordUpPointingTip= */ yCoord,
|
|
|
|
|
/* shouldAutoClose= */ true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the ArrowTipView (tooltip) custom aligned. The tooltip is vertically flipped if it
|
|
|
|
|
* cannot fit on screen in the requested orientation.
|
|
|
|
|
*
|
|
|
|
|
* @param text The text to be shown in the tooltip.
|
|
|
|
|
* @param arrowXCoord The X coordinate for the arrow on the tooltip. The arrow is usually in the
|
|
|
|
|
* center of tooltip unless the tooltip goes beyond screen margin.
|
|
|
|
|
* @param yCoord The Y coordinate of the pointed tip end of the tooltip.
|
|
|
|
|
* @param shouldAutoClose If Tooltip should be auto close.
|
|
|
|
|
* @return The tool tip view. {@code null} if the tip can not be shown.
|
|
|
|
|
*/
|
|
|
|
|
@Nullable public ArrowTipView showAtLocation(
|
|
|
|
|
String text, @Px int arrowXCoord, @Px int yCoord, boolean shouldAutoClose) {
|
2021-06-08 14:35:22 +01:00
|
|
|
return showAtLocation(
|
|
|
|
|
text,
|
|
|
|
|
arrowXCoord,
|
|
|
|
|
/* yCoordDownPointingTip= */ yCoord,
|
2021-07-30 03:32:39 +00:00
|
|
|
/* yCoordUpPointingTip= */ yCoord,
|
|
|
|
|
/* shouldAutoClose= */ shouldAutoClose);
|
2021-06-08 14:35:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the ArrowTipView (tooltip) custom aligned. The tooltip is vertically flipped if it
|
|
|
|
|
* cannot fit on screen in the requested orientation.
|
|
|
|
|
*
|
|
|
|
|
* @param text The text to be shown in the tooltip.
|
|
|
|
|
* @param arrowXCoord The X coordinate for the arrow on the tooltip. The arrow is usually in the
|
|
|
|
|
* center of tooltip unless the tooltip goes beyond screen margin.
|
|
|
|
|
* @param rect The coordinates of the view which requests the tooltip to be shown.
|
|
|
|
|
* @param margin The margin between {@param rect} and the tooltip.
|
|
|
|
|
* @return The tool tip view. {@code null} if the tip can not be shown.
|
|
|
|
|
*/
|
|
|
|
|
@Nullable public ArrowTipView showAroundRect(
|
|
|
|
|
String text, @Px int arrowXCoord, Rect rect, @Px int margin) {
|
|
|
|
|
return showAtLocation(
|
|
|
|
|
text,
|
|
|
|
|
arrowXCoord,
|
|
|
|
|
/* yCoordDownPointingTip= */ rect.top - margin,
|
2021-07-30 03:32:39 +00:00
|
|
|
/* yCoordUpPointingTip= */ rect.bottom + margin,
|
|
|
|
|
/* shouldAutoClose= */ true);
|
2021-06-08 14:35:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the ArrowTipView (tooltip) custom aligned. The tooltip is vertically flipped if it
|
|
|
|
|
* cannot fit on screen in the requested orientation.
|
|
|
|
|
*
|
|
|
|
|
* @param text The text to be shown in the tooltip.
|
|
|
|
|
* @param arrowXCoord The X coordinate for the arrow on the tooltip. The arrow is usually in the
|
|
|
|
|
* center of tooltip unless the tooltip goes beyond screen margin.
|
|
|
|
|
* @param yCoordDownPointingTip The Y coordinate of the pointed tip end of the tooltip when the
|
|
|
|
|
* tooltip is placed pointing downwards.
|
|
|
|
|
* @param yCoordUpPointingTip The Y coordinate of the pointed tip end of the tooltip when the
|
|
|
|
|
* tooltip is placed pointing upwards.
|
2021-07-30 03:32:39 +00:00
|
|
|
* @param shouldAutoClose If Tooltip should be auto close.
|
2021-06-08 14:35:22 +01:00
|
|
|
* @return The tool tip view. {@code null} if the tip can not be shown.
|
|
|
|
|
*/
|
|
|
|
|
@Nullable private ArrowTipView showAtLocation(String text, @Px int arrowXCoord,
|
2021-07-30 03:32:39 +00:00
|
|
|
@Px int yCoordDownPointingTip, @Px int yCoordUpPointingTip, boolean shouldAutoClose) {
|
2021-04-09 09:58:53 +01:00
|
|
|
ViewGroup parent = mActivity.getDragLayer();
|
|
|
|
|
@Px int parentViewWidth = parent.getWidth();
|
2021-06-08 14:35:22 +01:00
|
|
|
@Px int parentViewHeight = parent.getHeight();
|
2021-05-27 14:55:21 +01:00
|
|
|
@Px int maxTextViewWidth = getContext().getResources()
|
|
|
|
|
.getDimensionPixelSize(R.dimen.widget_picker_education_tip_max_width);
|
2021-04-09 09:58:53 +01:00
|
|
|
@Px int minViewMargin = getContext().getResources()
|
|
|
|
|
.getDimensionPixelSize(R.dimen.widget_picker_education_tip_min_margin);
|
2021-05-27 14:55:21 +01:00
|
|
|
if (parentViewWidth < maxTextViewWidth + 2 * minViewMargin) {
|
2021-04-09 09:58:53 +01:00
|
|
|
Log.w(TAG, "Cannot display tip on a small screen of size: " + parentViewWidth);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TextView textView = findViewById(R.id.text);
|
|
|
|
|
textView.setText(text);
|
2021-05-27 14:55:21 +01:00
|
|
|
textView.setMaxWidth(maxTextViewWidth);
|
2021-04-09 09:58:53 +01:00
|
|
|
parent.addView(this);
|
|
|
|
|
requestLayout();
|
|
|
|
|
|
|
|
|
|
post(() -> {
|
2021-06-08 14:35:22 +01:00
|
|
|
// Adjust the tooltip horizontally.
|
2021-04-09 09:58:53 +01:00
|
|
|
float halfWidth = getWidth() / 2f;
|
|
|
|
|
float xCoord;
|
|
|
|
|
if (arrowXCoord - halfWidth < minViewMargin) {
|
2021-06-07 10:27:23 +01:00
|
|
|
// If the tooltip is estimated to go beyond the left margin, place its start just at
|
|
|
|
|
// the left margin.
|
2021-04-09 09:58:53 +01:00
|
|
|
xCoord = minViewMargin;
|
|
|
|
|
} else if (arrowXCoord + halfWidth > parentViewWidth - minViewMargin) {
|
2021-06-07 10:27:23 +01:00
|
|
|
// If the tooltip is estimated to go beyond the right margin, place it such that its
|
|
|
|
|
// end is just at the right margin.
|
2021-04-09 09:58:53 +01:00
|
|
|
xCoord = parentViewWidth - minViewMargin - getWidth();
|
|
|
|
|
} else {
|
2021-06-07 10:27:23 +01:00
|
|
|
// Place the tooltip such that its center is at arrowXCoord.
|
2021-04-09 09:58:53 +01:00
|
|
|
xCoord = arrowXCoord - halfWidth;
|
|
|
|
|
}
|
|
|
|
|
setX(xCoord);
|
2021-06-08 14:35:22 +01:00
|
|
|
|
|
|
|
|
// Adjust the tooltip vertically.
|
|
|
|
|
@Px int viewHeight = getHeight();
|
|
|
|
|
if (mIsPointingUp
|
|
|
|
|
? (yCoordUpPointingTip + viewHeight > parentViewHeight)
|
|
|
|
|
: (yCoordDownPointingTip - viewHeight < 0)) {
|
|
|
|
|
// Flip the view if it exceeds the vertical bounds of screen.
|
|
|
|
|
mIsPointingUp = !mIsPointingUp;
|
|
|
|
|
updateArrowTipInView();
|
|
|
|
|
}
|
|
|
|
|
// Place the tooltip such that its top is at yCoordUpPointingTip if arrow is displayed
|
|
|
|
|
// pointing upwards, otherwise place it such that its bottom is at
|
|
|
|
|
// yCoordDownPointingTip.
|
|
|
|
|
setY(mIsPointingUp ? yCoordUpPointingTip : yCoordDownPointingTip - viewHeight);
|
|
|
|
|
|
2021-06-07 10:27:23 +01:00
|
|
|
// Adjust the arrow's relative position on tooltip to make sure the actual position of
|
|
|
|
|
// arrow's pointed tip is always at arrowXCoord.
|
2021-06-08 14:35:22 +01:00
|
|
|
mArrowView.setX(arrowXCoord - xCoord - mArrowView.getWidth() / 2f);
|
2021-04-09 09:58:53 +01:00
|
|
|
requestLayout();
|
|
|
|
|
});
|
|
|
|
|
|
2021-06-07 10:27:23 +01:00
|
|
|
mIsOpen = true;
|
2021-07-30 03:32:39 +00:00
|
|
|
if (shouldAutoClose) {
|
|
|
|
|
mHandler.postDelayed(() -> handleClose(true), AUTO_CLOSE_TIMEOUT_MILLIS);
|
|
|
|
|
}
|
2021-04-09 09:58:53 +01:00
|
|
|
setAlpha(0);
|
|
|
|
|
animate()
|
|
|
|
|
.alpha(1f)
|
|
|
|
|
.withLayer()
|
|
|
|
|
.setStartDelay(SHOW_DELAY_MS)
|
|
|
|
|
.setDuration(SHOW_DURATION_MS)
|
|
|
|
|
.setInterpolator(Interpolators.DEACCEL)
|
|
|
|
|
.start();
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-08 14:35:22 +01:00
|
|
|
private void updateArrowTipInView() {
|
|
|
|
|
ViewGroup.LayoutParams arrowLp = mArrowView.getLayoutParams();
|
|
|
|
|
ShapeDrawable arrowDrawable = new ShapeDrawable(TriangleShape.create(
|
|
|
|
|
arrowLp.width, arrowLp.height, mIsPointingUp));
|
|
|
|
|
Paint arrowPaint = arrowDrawable.getPaint();
|
|
|
|
|
@Px int arrowTipRadius = getContext().getResources()
|
|
|
|
|
.getDimensionPixelSize(R.dimen.arrow_toast_corner_radius);
|
|
|
|
|
arrowPaint.setColor(ContextCompat.getColor(getContext(), R.color.arrow_tip_view_bg));
|
|
|
|
|
arrowPaint.setPathEffect(new CornerPathEffect(arrowTipRadius));
|
|
|
|
|
mArrowView.setBackground(arrowDrawable);
|
|
|
|
|
// Add negative margin so that the rounded corners on base of arrow are not visible.
|
|
|
|
|
removeView(mArrowView);
|
|
|
|
|
if (mIsPointingUp) {
|
|
|
|
|
addView(mArrowView, 0);
|
|
|
|
|
((ViewGroup.MarginLayoutParams) arrowLp).setMargins(0, 0, 0, -1 * arrowTipRadius);
|
|
|
|
|
} else {
|
|
|
|
|
addView(mArrowView, 1);
|
|
|
|
|
((ViewGroup.MarginLayoutParams) arrowLp).setMargins(0, -1 * arrowTipRadius, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-09 18:24:47 -07:00
|
|
|
/**
|
|
|
|
|
* Register a callback fired when toast is hidden
|
|
|
|
|
*/
|
|
|
|
|
public ArrowTipView setOnClosedCallback(Runnable runnable) {
|
|
|
|
|
mOnClosed = runnable;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2021-06-08 14:35:22 +01:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
|
close(/* animate= */ false);
|
|
|
|
|
}
|
2020-03-09 18:24:47 -07:00
|
|
|
}
|