NekoX/TMessagesProj/src/main/java/org/telegram/ui/ActionBar/BottomSheet.java

1574 lines
62 KiB
Java
Raw Normal View History

2015-05-21 23:27:27 +02:00
/*
2019-01-23 18:03:33 +01:00
* This is the source code of Telegram for Android v. 5.x.x.
2015-05-21 23:27:27 +02:00
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
2019-01-23 18:03:33 +01:00
* Copyright Nikolai Kudashov, 2013-2018.
2015-05-21 23:27:27 +02:00
*/
package org.telegram.ui.ActionBar;
import android.animation.Animator;
2017-03-31 01:58:05 +02:00
import android.animation.AnimatorListenerAdapter;
2015-07-22 20:56:37 +02:00
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
2021-03-19 11:25:58 +01:00
import android.animation.ValueAnimator;
2015-05-21 23:27:27 +02:00
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
2017-03-31 01:58:05 +02:00
import android.graphics.Canvas;
2021-06-25 02:43:10 +02:00
import android.graphics.Color;
import android.graphics.Insets;
2020-04-24 11:21:58 +02:00
import android.graphics.Paint;
2017-03-31 01:58:05 +02:00
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
2015-07-22 20:56:37 +02:00
import android.graphics.Rect;
2015-06-29 19:12:11 +02:00
import android.graphics.drawable.ColorDrawable;
2015-07-22 20:56:37 +02:00
import android.graphics.drawable.Drawable;
2015-05-21 23:27:27 +02:00
import android.os.Build;
import android.os.Bundle;
2020-09-30 15:48:47 +02:00
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
2019-05-14 14:08:05 +02:00
import androidx.core.view.NestedScrollingParent;
import androidx.core.view.NestedScrollingParentHelper;
import androidx.core.view.ViewCompat;
2021-12-30 11:52:40 +01:00
import androidx.core.widget.NestedScrollView;
2015-06-29 19:12:11 +02:00
import android.text.TextUtils;
2015-05-21 23:27:27 +02:00
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
2016-05-25 23:49:47 +02:00
import android.view.VelocityTracker;
2015-05-21 23:27:27 +02:00
import android.view.View;
2016-05-25 23:49:47 +02:00
import android.view.ViewConfiguration;
2015-05-21 23:27:27 +02:00
import android.view.ViewGroup;
import android.view.Window;
2015-11-26 22:04:02 +01:00
import android.view.WindowInsets;
2015-05-21 23:27:27 +02:00
import android.view.WindowManager;
2019-08-22 01:53:26 +02:00
import android.view.animation.Interpolator;
2015-05-21 23:27:27 +02:00
import android.widget.FrameLayout;
2015-06-29 19:12:11 +02:00
import android.widget.ImageView;
2020-06-25 17:28:24 +02:00
import android.widget.LinearLayout;
import android.widget.ScrollView;
2015-05-21 23:27:27 +02:00
import android.widget.TextView;
import androidx.annotation.NonNull;
2020-06-25 17:28:24 +02:00
import androidx.annotation.RequiresApi;
import androidx.core.view.NestedScrollingParent;
import androidx.core.view.NestedScrollingParentHelper;
import androidx.core.view.ViewCompat;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.AndroidUtilities;
2015-05-21 23:27:27 +02:00
import org.telegram.messenger.FileLog;
2020-06-25 17:28:24 +02:00
import org.telegram.messenger.LocaleController;
2019-07-18 15:01:39 +02:00
import org.telegram.messenger.NotificationCenter;
2015-05-21 23:27:27 +02:00
import org.telegram.messenger.R;
2018-07-30 04:07:02 +02:00
import org.telegram.messenger.UserConfig;
2019-08-22 01:53:26 +02:00
import org.telegram.ui.Components.AnimationProperties;
2021-02-23 12:53:38 +01:00
import org.telegram.ui.Components.Bulletin;
2019-05-14 14:08:05 +02:00
import org.telegram.ui.Components.CubicBezierInterpolator;
2015-05-21 23:27:27 +02:00
import org.telegram.ui.Components.LayoutHelper;
2015-06-29 19:12:11 +02:00
import java.util.ArrayList;
2015-05-21 23:27:27 +02:00
public class BottomSheet extends Dialog {
2018-07-30 04:07:02 +02:00
protected int currentAccount = UserConfig.selectedAccount;
2016-05-25 23:49:47 +02:00
protected ViewGroup containerView;
2016-10-11 13:57:01 +02:00
protected ContainerView container;
2020-04-24 11:21:58 +02:00
protected boolean keyboardVisible;
2016-04-22 15:49:00 +02:00
private WindowInsets lastInsets;
2020-04-24 11:21:58 +02:00
protected boolean drawNavigationBar;
2020-12-23 08:48:30 +01:00
protected boolean scrollNavBar;
2015-06-29 19:12:11 +02:00
2020-02-13 19:26:53 +01:00
protected boolean useSmoothKeyboard;
2020-01-23 07:15:40 +01:00
protected Runnable startAnimationRunnable;
2016-05-25 23:49:47 +02:00
private int layoutCount;
2015-05-21 23:27:27 +02:00
private boolean dismissed;
2015-06-29 19:12:11 +02:00
private int tag;
2015-05-21 23:27:27 +02:00
2017-03-31 01:58:05 +02:00
private boolean allowDrawContent = true;
private boolean useHardwareLayer = true;
2015-05-21 23:27:27 +02:00
private DialogInterface.OnClickListener onClickListener;
private CharSequence[] items;
2015-06-29 19:12:11 +02:00
private int[] itemIcons;
2015-05-21 23:27:27 +02:00
private View customView;
2015-06-29 19:12:11 +02:00
private CharSequence title;
2019-12-31 14:08:08 +01:00
private boolean bigTitle;
2020-04-24 11:21:58 +02:00
private int bottomInset;
2021-06-25 02:43:10 +02:00
private int leftInset;
private int rightInset;
2016-10-11 13:57:01 +02:00
protected boolean fullWidth;
2019-05-14 14:08:05 +02:00
protected boolean isFullscreen;
2020-09-30 15:48:47 +02:00
private boolean fullHeight;
2021-06-25 02:43:10 +02:00
protected ColorDrawable backDrawable = new ColorDrawable(0xff000000) {
@Override
public void setAlpha(int alpha) {
super.setAlpha(alpha);
container.invalidate();
}
};
2016-05-25 23:49:47 +02:00
protected boolean useLightStatusBar = true;
2020-12-23 08:48:30 +01:00
protected boolean useLightNavBar;
protected String behindKeyboardColorKey = Theme.key_dialogBackground;
protected int behindKeyboardColor;
2020-07-08 05:28:13 +02:00
private boolean canDismissWithSwipe = false;
2019-12-31 14:08:08 +01:00
2016-05-25 23:49:47 +02:00
private boolean allowCustomAnimation = true;
2017-03-31 01:58:05 +02:00
private boolean showWithoutAnimation;
2016-05-25 23:49:47 +02:00
2021-04-14 03:44:46 +02:00
protected int statusBarHeight = AndroidUtilities.statusBarHeight;
protected boolean calcMandatoryInsets;
2016-05-25 23:49:47 +02:00
private int touchSlop;
private boolean useFastDismiss;
2019-08-22 01:53:26 +02:00
protected Interpolator openInterpolator = CubicBezierInterpolator.EASE_OUT_QUINT;
2015-06-29 19:12:11 +02:00
2019-01-23 18:03:33 +01:00
private TextView titleView;
2015-11-26 22:04:02 +01:00
private boolean focusable;
2019-05-14 14:08:05 +02:00
private boolean dimBehind = true;
2020-12-23 08:48:30 +01:00
private int dimBehindAlpha = 51;
2019-05-14 14:08:05 +02:00
2020-09-30 15:48:47 +02:00
protected boolean allowNestedScroll = true;
2017-12-08 18:35:59 +01:00
2019-08-22 01:53:26 +02:00
protected Drawable shadowDrawable;
2019-05-14 14:08:05 +02:00
protected int backgroundPaddingTop;
protected int backgroundPaddingLeft;
2015-07-22 20:56:37 +02:00
2020-06-25 17:28:24 +02:00
private boolean applyTopPadding = false;
private boolean applyBottomPadding = false;
2015-06-29 19:12:11 +02:00
private ArrayList<BottomSheetCell> itemViews = new ArrayList<>();
2015-05-21 23:27:27 +02:00
2018-08-27 10:33:11 +02:00
private Runnable dismissRunnable = this::dismiss;
2018-07-30 04:07:02 +02:00
2015-07-22 20:56:37 +02:00
private BottomSheetDelegateInterface delegate;
2015-05-21 23:27:27 +02:00
protected AnimatorSet currentSheetAnimation;
2019-08-22 01:53:26 +02:00
protected int currentSheetAnimationType;
2015-07-22 20:56:37 +02:00
2018-07-30 04:07:02 +02:00
protected View nestedScrollChild;
2020-01-23 07:15:40 +01:00
private boolean disableScroll;
2020-09-30 15:48:47 +02:00
private float currentPanTranslationY;
2020-01-23 07:15:40 +01:00
2020-12-23 08:48:30 +01:00
protected String navBarColorKey = Theme.key_windowBackgroundGray;
protected int navBarColor;
2021-01-28 15:15:51 +01:00
private OnDismissListener onHideListener;
2021-09-20 00:10:42 +02:00
protected Theme.ResourcesProvider resourcesProvider;
2021-01-28 15:15:51 +01:00
2020-01-23 07:15:40 +01:00
public void setDisableScroll(boolean b) {
disableScroll = b;
}
2018-07-30 04:07:02 +02:00
2021-03-19 11:25:58 +01:00
private ValueAnimator keyboardContentAnimator;
protected boolean smoothKeyboardAnimationEnabled;
2021-12-07 14:02:02 +01:00
private boolean openNoDelay;
2021-03-19 11:25:58 +01:00
2020-06-25 17:28:24 +02:00
protected class ContainerView extends LinearLayout implements NestedScrollingParent {
2015-07-22 20:56:37 +02:00
2016-05-25 23:49:47 +02:00
private VelocityTracker velocityTracker = null;
private int startedTrackingX;
private int startedTrackingY;
2016-10-11 13:57:01 +02:00
private int startedTrackingPointerId = -1;
2016-05-25 23:49:47 +02:00
private boolean maybeStartTracking = false;
private boolean startedTracking = false;
private AnimatorSet currentAnimation = null;
2016-05-25 23:49:47 +02:00
private NestedScrollingParentHelper nestedScrollingParentHelper;
2020-04-24 11:21:58 +02:00
private Rect rect = new Rect();
private int keyboardHeight;
private Paint backgroundPaint = new Paint();
2021-03-19 11:25:58 +01:00
private boolean keyboardChanged;
2015-07-22 20:56:37 +02:00
2016-05-25 23:49:47 +02:00
public ContainerView(Context context) {
super(context);
nestedScrollingParentHelper = new NestedScrollingParentHelper(this);
2020-04-24 11:21:58 +02:00
setWillNotDraw(false);
2016-05-25 23:49:47 +02:00
}
2015-07-22 20:56:37 +02:00
2016-05-25 23:49:47 +02:00
@Override
public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) {
2018-07-30 04:07:02 +02:00
return !(nestedScrollChild != null && child != nestedScrollChild) &&
!dismissed && allowNestedScroll && nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL && !canDismissWithSwipe();
2016-05-25 23:49:47 +02:00
}
2015-07-22 20:56:37 +02:00
2016-05-25 23:49:47 +02:00
@Override
public void onNestedScrollAccepted(View child, View target, int nestedScrollAxes) {
nestedScrollingParentHelper.onNestedScrollAccepted(child, target, nestedScrollAxes);
2017-12-08 18:35:59 +01:00
if (dismissed || !allowNestedScroll) {
2016-05-25 23:49:47 +02:00
return;
}
cancelCurrentAnimation();
}
2015-07-22 20:56:37 +02:00
@Override
2016-05-25 23:49:47 +02:00
public void onStopNestedScroll(View target) {
nestedScrollingParentHelper.onStopNestedScroll(target);
2017-12-08 18:35:59 +01:00
if (dismissed || !allowNestedScroll) {
2016-05-25 23:49:47 +02:00
return;
}
float currentTranslation = containerView.getTranslationY();
2016-05-25 23:49:47 +02:00
checkDismiss(0, 0);
}
@Override
public void onNestedScroll(View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
2017-12-08 18:35:59 +01:00
if (dismissed || !allowNestedScroll) {
2016-05-25 23:49:47 +02:00
return;
}
cancelCurrentAnimation();
if (dyUnconsumed != 0) {
float currentTranslation = containerView.getTranslationY();
2016-05-25 23:49:47 +02:00
currentTranslation -= dyUnconsumed;
if (currentTranslation < 0) {
currentTranslation = 0;
}
containerView.setTranslationY(currentTranslation);
2021-06-25 02:43:10 +02:00
container.invalidate();
2016-05-25 23:49:47 +02:00
}
}
2015-07-22 20:56:37 +02:00
2016-05-25 23:49:47 +02:00
@Override
public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) {
2017-12-08 18:35:59 +01:00
if (dismissed || !allowNestedScroll) {
2016-05-25 23:49:47 +02:00
return;
}
cancelCurrentAnimation();
float currentTranslation = containerView.getTranslationY();
2016-05-25 23:49:47 +02:00
if (currentTranslation > 0 && dy > 0) {
currentTranslation -= dy;
consumed[1] = dy;
if (currentTranslation < 0) {
currentTranslation = 0;
}
containerView.setTranslationY(currentTranslation);
2021-06-25 02:43:10 +02:00
container.invalidate();
2016-05-25 23:49:47 +02:00
}
2015-07-22 20:56:37 +02:00
}
@Override
2016-05-25 23:49:47 +02:00
public boolean onNestedFling(View target, float velocityX, float velocityY, boolean consumed) {
return false;
}
@Override
public boolean onNestedPreFling(View target, float velocityX, float velocityY) {
return false;
}
@Override
public int getNestedScrollAxes() {
return nestedScrollingParentHelper.getNestedScrollAxes();
}
2015-07-22 20:56:37 +02:00
2016-05-25 23:49:47 +02:00
private void checkDismiss(float velX, float velY) {
float translationY = containerView.getTranslationY();
2016-05-25 23:49:47 +02:00
boolean backAnimation = translationY < AndroidUtilities.getPixelsInCM(0.8f, false) && (velY < 3500 || Math.abs(velY) < Math.abs(velX)) || velY < 0 && Math.abs(velY) >= 3500;
if (!backAnimation) {
boolean allowOld = allowCustomAnimation;
allowCustomAnimation = false;
useFastDismiss = true;
dismiss();
allowCustomAnimation = allowOld;
} else {
currentAnimation = new AnimatorSet();
currentAnimation.playTogether(ObjectAnimator.ofFloat(containerView, "translationY", 0));
2020-09-30 15:48:47 +02:00
currentAnimation.setDuration((int) (150 * (Math.max(0, translationY) / AndroidUtilities.getPixelsInCM(0.8f, false))));
2019-05-14 14:08:05 +02:00
currentAnimation.setInterpolator(CubicBezierInterpolator.EASE_OUT);
2017-03-31 01:58:05 +02:00
currentAnimation.addListener(new AnimatorListenerAdapter() {
2016-05-25 23:49:47 +02:00
@Override
public void onAnimationEnd(Animator animation) {
2016-05-25 23:49:47 +02:00
if (currentAnimation != null && currentAnimation.equals(animation)) {
currentAnimation = null;
}
2019-07-18 15:01:39 +02:00
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.startAllHeavyOperations, 512);
2016-05-25 23:49:47 +02:00
}
});
2019-07-18 15:01:39 +02:00
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.stopAllHeavyOperations, 512);
2016-05-25 23:49:47 +02:00
currentAnimation.start();
}
}
private void cancelCurrentAnimation() {
if (currentAnimation != null) {
currentAnimation.cancel();
currentAnimation = null;
}
}
2021-12-30 11:52:40 +01:00
private float y = 0f;
public boolean processTouchEvent(MotionEvent ev, boolean intercept) {
2016-05-25 23:49:47 +02:00
if (dismissed) {
return false;
}
2016-10-11 13:57:01 +02:00
if (onContainerTouchEvent(ev)) {
return true;
}
2021-12-30 11:52:40 +01:00
2018-07-30 04:07:02 +02:00
if (canDismissWithTouchOutside() && ev != null && (ev.getAction() == MotionEvent.ACTION_DOWN || ev.getAction() == MotionEvent.ACTION_MOVE) && (!startedTracking && !maybeStartTracking && ev.getPointerCount() == 1)) {
2016-05-25 23:49:47 +02:00
startedTrackingX = (int) ev.getX();
startedTrackingY = (int) ev.getY();
if (startedTrackingY < containerView.getTop() || startedTrackingX < containerView.getLeft() || startedTrackingX > containerView.getRight()) {
dismiss();
return true;
}
2021-12-30 11:52:40 +01:00
onScrollUpBegin(y);
2016-05-25 23:49:47 +02:00
startedTrackingPointerId = ev.getPointerId(0);
maybeStartTracking = true;
cancelCurrentAnimation();
if (velocityTracker != null) {
velocityTracker.clear();
}
} else if (ev != null && ev.getAction() == MotionEvent.ACTION_MOVE && ev.getPointerId(0) == startedTrackingPointerId) {
if (velocityTracker == null) {
velocityTracker = VelocityTracker.obtain();
}
float dx = Math.abs((int) (ev.getX() - startedTrackingX));
float dy = (int) ev.getY() - startedTrackingY;
2021-12-30 11:52:40 +01:00
boolean canScrollUp = onScrollUp(y + dy);
2016-05-25 23:49:47 +02:00
velocityTracker.addMovement(ev);
2020-01-23 07:15:40 +01:00
if (!disableScroll && maybeStartTracking && !startedTracking && (dy > 0 && dy / 3.0f > Math.abs(dx) && Math.abs(dy) >= touchSlop)) {
2016-05-25 23:49:47 +02:00
startedTrackingY = (int) ev.getY();
maybeStartTracking = false;
startedTracking = true;
requestDisallowInterceptTouchEvent(true);
} else if (startedTracking) {
2021-12-30 11:52:40 +01:00
y += dy;
if (!canScrollUp)
y = Math.max(y, 0);
containerView.setTranslationY(Math.max(y, 0));
2016-05-25 23:49:47 +02:00
startedTrackingY = (int) ev.getY();
2021-06-25 02:43:10 +02:00
container.invalidate();
2016-05-25 23:49:47 +02:00
}
2021-03-19 11:25:58 +01:00
} else if (ev == null || ev.getPointerId(0) == startedTrackingPointerId && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_POINTER_UP)) {
2016-05-25 23:49:47 +02:00
if (velocityTracker == null) {
velocityTracker = VelocityTracker.obtain();
}
velocityTracker.computeCurrentVelocity(1000);
2021-12-30 11:52:40 +01:00
onScrollUpEnd(y);
if (startedTracking || y > 0) {
2016-05-25 23:49:47 +02:00
checkDismiss(velocityTracker.getXVelocity(), velocityTracker.getYVelocity());
} else {
maybeStartTracking = false;
}
2021-12-30 11:52:40 +01:00
startedTracking = false;
2016-05-25 23:49:47 +02:00
if (velocityTracker != null) {
velocityTracker.recycle();
velocityTracker = null;
}
2016-10-11 13:57:01 +02:00
startedTrackingPointerId = -1;
2016-05-25 23:49:47 +02:00
}
2018-07-30 04:07:02 +02:00
return !intercept && maybeStartTracking || startedTracking || !canDismissWithSwipe();
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
return processTouchEvent(ev, false);
2016-05-25 23:49:47 +02:00
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
2020-04-24 11:21:58 +02:00
int containerHeight = height;
View rootView = getRootView();
getWindowVisibleDisplayFrame(rect);
2021-03-19 11:25:58 +01:00
int oldKeyboardHeight = keyboardHeight;
2020-04-24 11:21:58 +02:00
if (rect.bottom != 0 && rect.top != 0) {
int usableViewHeight = rootView.getHeight() - (rect.top != 0 ? AndroidUtilities.statusBarHeight : 0) - AndroidUtilities.getViewInset(rootView);
keyboardHeight = Math.max(0, usableViewHeight - (rect.bottom - rect.top));
if (keyboardHeight < AndroidUtilities.dp(20)) {
keyboardHeight = 0;
}
bottomInset -= keyboardHeight;
} else {
keyboardHeight = 0;
}
2021-03-19 11:25:58 +01:00
if (oldKeyboardHeight != keyboardHeight) {
keyboardChanged = true;
}
2020-04-24 11:21:58 +02:00
keyboardVisible = keyboardHeight > AndroidUtilities.dp(20);
if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
bottomInset = lastInsets.getSystemWindowInsetBottom();
2021-06-25 02:43:10 +02:00
leftInset = lastInsets.getSystemWindowInsetLeft();
rightInset = lastInsets.getSystemWindowInsetRight();
if (Build.VERSION.SDK_INT >= 29) {
bottomInset += getAdditionalMandatoryOffsets();
}
2020-04-24 11:21:58 +02:00
if (keyboardVisible && rect.bottom != 0 && rect.top != 0) {
bottomInset -= keyboardHeight;
}
if (!drawNavigationBar) {
containerHeight -= bottomInset;
}
}
setMeasuredDimension(width, containerHeight);
2016-05-25 23:49:47 +02:00
if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
int inset = lastInsets.getSystemWindowInsetBottom();
if (Build.VERSION.SDK_INT >= 29) {
inset += getAdditionalMandatoryOffsets();
}
height -= inset;
2016-05-25 23:49:47 +02:00
}
2017-03-31 01:58:05 +02:00
if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
width -= lastInsets.getSystemWindowInsetRight() + lastInsets.getSystemWindowInsetLeft();
}
2016-05-25 23:49:47 +02:00
boolean isPortrait = width < height;
if (containerView != null) {
if (!fullWidth) {
int widthSpec;
if (AndroidUtilities.isTablet()) {
widthSpec = MeasureSpec.makeMeasureSpec((int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.8f) + backgroundPaddingLeft * 2, MeasureSpec.EXACTLY);
} else {
widthSpec = MeasureSpec.makeMeasureSpec(isPortrait ? width + backgroundPaddingLeft * 2 : (int) Math.max(width * 0.8f, Math.min(AndroidUtilities.dp(480), width)) + backgroundPaddingLeft * 2, MeasureSpec.EXACTLY);
}
containerView.measure(widthSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
2016-05-25 23:49:47 +02:00
} else {
containerView.measure(MeasureSpec.makeMeasureSpec(width + backgroundPaddingLeft * 2, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
}
}
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (child.getVisibility() == GONE || child == containerView) {
continue;
}
2016-10-11 13:57:01 +02:00
if (!onCustomMeasure(child, width, height)) {
measureChildWithMargins(child, MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), 0, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY), 0);
}
2016-05-25 23:49:47 +02:00
}
2015-07-22 20:56:37 +02:00
}
2021-06-25 02:43:10 +02:00
@Override
public void requestLayout() {
super.requestLayout();
}
2015-07-22 20:56:37 +02:00
@Override
2016-05-25 23:49:47 +02:00
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
layoutCount--;
if (containerView != null) {
2020-04-24 11:21:58 +02:00
int t = (bottom - top) - containerView.getMeasuredHeight();
2016-05-25 23:49:47 +02:00
if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
left += lastInsets.getSystemWindowInsetLeft();
2017-03-31 01:58:05 +02:00
right -= lastInsets.getSystemWindowInsetRight();
2020-09-30 15:48:47 +02:00
if (useSmoothKeyboard) {
t = 0;
} else {
t -= lastInsets.getSystemWindowInsetBottom() - (drawNavigationBar ? 0 : bottomInset);
if (Build.VERSION.SDK_INT >= 29) {
t -= getAdditionalMandatoryOffsets();
}
}
2016-05-25 23:49:47 +02:00
}
int l = ((right - left) - containerView.getMeasuredWidth()) / 2;
2017-03-31 01:58:05 +02:00
if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
l += lastInsets.getSystemWindowInsetLeft();
}
2021-03-19 11:25:58 +01:00
if (smoothKeyboardAnimationEnabled && startAnimationRunnable == null && keyboardChanged && !dismissed && containerView.getTop() != t) {
containerView.setTranslationY(containerView.getTop() - t);
if (keyboardContentAnimator != null) {
keyboardContentAnimator.cancel();
}
keyboardContentAnimator = ValueAnimator.ofFloat(containerView.getTranslationY(), 0);
2021-06-25 02:43:10 +02:00
keyboardContentAnimator.addUpdateListener(valueAnimator -> {
containerView.setTranslationY((Float) valueAnimator.getAnimatedValue());
invalidate();
2021-03-19 11:25:58 +01:00
});
keyboardContentAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
containerView.setTranslationY(0);
invalidate();
}
});
keyboardContentAnimator.setDuration(AdjustPanLayoutHelper.keyboardDuration).setInterpolator(AdjustPanLayoutHelper.keyboardInterpolator);
keyboardContentAnimator.start();
}
2016-05-25 23:49:47 +02:00
containerView.layout(l, t, l + containerView.getMeasuredWidth(), t + containerView.getMeasuredHeight());
}
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() == GONE || child == containerView) {
continue;
}
2020-04-24 11:21:58 +02:00
if (!onCustomLayout(child, left, top, right, bottom - (drawNavigationBar ? bottomInset : 0))) {
2020-06-25 17:28:24 +02:00
final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams();
2016-05-25 23:49:47 +02:00
2016-10-11 13:57:01 +02:00
final int width = child.getMeasuredWidth();
final int height = child.getMeasuredHeight();
2016-05-25 23:49:47 +02:00
2016-10-11 13:57:01 +02:00
int childLeft;
int childTop;
2016-05-25 23:49:47 +02:00
2016-10-11 13:57:01 +02:00
int gravity = lp.gravity;
if (gravity == -1) {
gravity = Gravity.TOP | Gravity.LEFT;
}
2015-07-22 20:56:37 +02:00
2016-10-11 13:57:01 +02:00
final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.CENTER_HORIZONTAL:
childLeft = (right - left - width) / 2 + lp.leftMargin - lp.rightMargin;
break;
case Gravity.RIGHT:
childLeft = right - width - lp.rightMargin;
break;
case Gravity.LEFT:
default:
childLeft = lp.leftMargin;
}
2016-05-25 23:49:47 +02:00
2016-10-11 13:57:01 +02:00
switch (verticalGravity) {
case Gravity.CENTER_VERTICAL:
childTop = (bottom - top - height) / 2 + lp.topMargin - lp.bottomMargin;
break;
case Gravity.BOTTOM:
childTop = (bottom - top) - height - lp.bottomMargin;
break;
default:
childTop = lp.topMargin;
}
2017-03-31 01:58:05 +02:00
if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
childLeft += lastInsets.getSystemWindowInsetLeft();
}
2016-10-11 13:57:01 +02:00
child.layout(childLeft, childTop, childLeft + width, childTop + height);
2016-05-25 23:49:47 +02:00
}
}
if (layoutCount == 0 && startAnimationRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(startAnimationRunnable);
startAnimationRunnable.run();
startAnimationRunnable = null;
}
2021-03-19 11:25:58 +01:00
keyboardChanged = false;
2015-07-22 20:56:37 +02:00
}
@Override
2016-05-25 23:49:47 +02:00
public boolean onInterceptTouchEvent(MotionEvent event) {
if (canDismissWithSwipe()) {
2018-07-30 04:07:02 +02:00
return processTouchEvent(event, true);
2016-05-25 23:49:47 +02:00
}
return super.onInterceptTouchEvent(event);
}
@Override
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
if (maybeStartTracking && !startedTracking) {
onTouchEvent(null);
}
super.requestDisallowInterceptTouchEvent(disallowIntercept);
}
2015-07-22 20:56:37 +02:00
2016-05-25 23:49:47 +02:00
@Override
public boolean hasOverlappingRendering() {
return false;
2015-07-22 20:56:37 +02:00
}
2017-03-31 01:58:05 +02:00
2020-04-24 11:21:58 +02:00
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
2021-06-25 02:43:10 +02:00
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (navBarColorKey != null) {
2021-09-20 00:10:42 +02:00
backgroundPaint.setColor(getThemedColor(navBarColorKey));
2020-04-24 11:21:58 +02:00
} else {
2021-06-25 02:43:10 +02:00
backgroundPaint.setColor(navBarColor);
2020-04-24 11:21:58 +02:00
}
2021-06-25 02:43:10 +02:00
} else {
backgroundPaint.setColor(0xff000000);
}
if ((drawNavigationBar && bottomInset != 0) || currentPanTranslationY != 0) {
float translation = 0;
2020-12-23 08:48:30 +01:00
if (scrollNavBar || Build.VERSION.SDK_INT >= 29 && getAdditionalMandatoryOffsets() > 0) {
float dist = containerView.getMeasuredHeight() - containerView.getTranslationY();
translation = Math.max(0, bottomInset - dist);
}
2020-09-30 15:48:47 +02:00
int navBarHeight = drawNavigationBar ? bottomInset : 0;
canvas.drawRect(containerView.getLeft() + backgroundPaddingLeft, getMeasuredHeight() - navBarHeight + translation - currentPanTranslationY, containerView.getRight() - backgroundPaddingLeft, getMeasuredHeight() + translation, backgroundPaint);
2021-06-25 02:43:10 +02:00
if (overlayDrawNavBarColor != 0) {
backgroundPaint.setColor(overlayDrawNavBarColor);
canvas.drawRect(containerView.getLeft() + backgroundPaddingLeft, getMeasuredHeight() - navBarHeight + translation - currentPanTranslationY, containerView.getRight() - backgroundPaddingLeft, getMeasuredHeight() + translation, backgroundPaint);
}
}
if (drawNavigationBar && rightInset != 0 && rightInset > leftInset && fullWidth && AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y) {
canvas.drawRect(containerView.getRight() - backgroundPaddingLeft, containerView.getTranslationY(), containerView.getRight() + rightInset, getMeasuredHeight(), backgroundPaint);
}
if (drawNavigationBar && leftInset != 0 && leftInset > rightInset && fullWidth && AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y) {
canvas.drawRect(0, containerView.getTranslationY(), containerView.getLeft() + backgroundPaddingLeft, getMeasuredHeight(), backgroundPaint);
2020-04-24 11:21:58 +02:00
}
2021-03-19 11:25:58 +01:00
if (containerView.getTranslationY() < 0) {
2021-09-20 00:10:42 +02:00
backgroundPaint.setColor(behindKeyboardColorKey != null ? getThemedColor(behindKeyboardColorKey) : behindKeyboardColor);
2021-03-19 11:25:58 +01:00
canvas.drawRect(containerView.getLeft() + backgroundPaddingLeft, containerView.getY() + containerView.getMeasuredHeight(), containerView.getRight() - backgroundPaddingLeft, getMeasuredHeight(), backgroundPaint);
}
2020-04-24 11:21:58 +02:00
}
2017-03-31 01:58:05 +02:00
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
2020-04-24 11:21:58 +02:00
if (lastInsets != null && keyboardHeight != 0) {
2021-09-20 00:10:42 +02:00
backgroundPaint.setColor(behindKeyboardColorKey != null ? getThemedColor(behindKeyboardColorKey) : behindKeyboardColor);
2020-04-24 11:21:58 +02:00
canvas.drawRect(containerView.getLeft() + backgroundPaddingLeft, getMeasuredHeight() - keyboardHeight - (drawNavigationBar ? bottomInset : 0), containerView.getRight() - backgroundPaddingLeft, getMeasuredHeight() - (drawNavigationBar ? bottomInset : 0), backgroundPaint);
}
2017-03-31 01:58:05 +02:00
onContainerDraw(canvas);
}
2016-05-25 23:49:47 +02:00
}
@RequiresApi(api = Build.VERSION_CODES.Q)
private int getAdditionalMandatoryOffsets() {
if (!calcMandatoryInsets) {
return 0;
}
Insets insets = lastInsets.getSystemGestureInsets();
return !keyboardVisible && drawNavigationBar && insets != null && (insets.left != 0 || insets.right != 0) ? insets.bottom : 0;
}
2016-05-25 23:49:47 +02:00
public interface BottomSheetDelegateInterface {
void onOpenAnimationStart();
2020-06-25 17:28:24 +02:00
2016-05-25 23:49:47 +02:00
void onOpenAnimationEnd();
2020-06-25 17:28:24 +02:00
2017-03-31 01:58:05 +02:00
boolean canDismiss();
2016-05-25 23:49:47 +02:00
}
2015-07-22 20:56:37 +02:00
2020-07-26 10:03:38 +02:00
public void setCalcMandatoryInsets(boolean value) {
calcMandatoryInsets = value;
drawNavigationBar = value;
}
2016-05-25 23:49:47 +02:00
public static class BottomSheetDelegate implements BottomSheetDelegateInterface {
2015-07-22 20:56:37 +02:00
@Override
2016-05-25 23:49:47 +02:00
public void onOpenAnimationStart() {
2015-07-22 20:56:37 +02:00
}
@Override
2016-05-25 23:49:47 +02:00
public void onOpenAnimationEnd() {
2015-07-22 20:56:37 +02:00
}
2017-03-31 01:58:05 +02:00
@Override
public boolean canDismiss() {
return true;
}
2015-05-21 23:27:27 +02:00
}
2020-06-25 17:28:24 +02:00
public static class BottomSheetCell extends LinearLayout {
2015-05-21 23:27:27 +02:00
2021-09-20 00:10:42 +02:00
private final Theme.ResourcesProvider resourcesProvider;
2015-05-21 23:27:27 +02:00
private TextView textView;
2015-06-29 19:12:11 +02:00
private ImageView imageView;
2020-04-24 11:21:58 +02:00
int currentType;
2015-05-21 23:27:27 +02:00
2015-12-09 19:27:52 +01:00
public BottomSheetCell(Context context, int type) {
2021-09-20 00:10:42 +02:00
this(context, type, null);
}
public BottomSheetCell(Context context, int type, Theme.ResourcesProvider resourcesProvider) {
2015-05-21 23:27:27 +02:00
super(context);
2021-09-20 00:10:42 +02:00
this.resourcesProvider = resourcesProvider;
2015-05-21 23:27:27 +02:00
2020-04-24 11:21:58 +02:00
currentType = type;
2020-06-25 17:28:24 +02:00
setOrientation(LinearLayout.HORIZONTAL);
setBackground(Theme.getSelectorDrawable(false));
super.setGravity(Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
2015-06-29 19:12:11 +02:00
imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.CENTER);
2021-09-20 11:14:20 +02:00
imageView.setColorFilter(new PorterDuffColorFilter(getThemedColor(Theme.key_dialogIcon), PorterDuff.Mode.SRC_IN));
2020-06-25 17:28:24 +02:00
addView(imageView, LayoutHelper.createLinear(56, 48));
2015-05-21 23:27:27 +02:00
textView = new TextView(context);
2015-06-29 19:12:11 +02:00
textView.setLines(1);
textView.setSingleLine(true);
textView.setEllipsize(TextUtils.TruncateAt.END);
2016-05-25 23:49:47 +02:00
if (type == 0) {
2021-09-20 00:10:42 +02:00
textView.setTextColor(getThemedColor(Theme.key_dialogTextBlack));
2015-06-29 19:12:11 +02:00
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
2020-06-25 17:28:24 +02:00
textView.setGravity(Gravity.CENTER_VERTICAL);
textView.setPadding(AndroidUtilities.dp(16), 0, 0, 0);
addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL));
2016-05-25 23:49:47 +02:00
} else if (type == 1) {
2021-09-20 00:10:42 +02:00
textView.setTextColor(getThemedColor(Theme.key_dialogTextBlack));
2015-12-09 19:27:52 +01:00
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
2020-06-25 17:28:24 +02:00
textView.setGravity(Gravity.CENTER);
addView(textView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
2020-04-24 11:21:58 +02:00
} else if (type == 2) {
textView.setGravity(Gravity.CENTER);
2021-09-20 00:10:42 +02:00
textView.setTextColor(getThemedColor(Theme.key_featuredStickers_buttonText));
2020-04-24 11:21:58 +02:00
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
2021-09-20 00:10:42 +02:00
textView.setBackground(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), getThemedColor(Theme.key_featuredStickers_addButton), getThemedColor(Theme.key_featuredStickers_addButtonPressed)));
2020-06-25 17:28:24 +02:00
addView(textView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0, 16, 16, 16, 16));
2015-06-29 19:12:11 +02:00
}
2015-05-21 23:27:27 +02:00
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2020-04-24 11:21:58 +02:00
int height = currentType == 2 ? 80 : 48;
if (currentType == 0) {
widthMeasureSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY);
}
2020-04-24 11:21:58 +02:00
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(height), MeasureSpec.EXACTLY));
2015-06-29 19:12:11 +02:00
}
2015-12-09 19:27:52 +01:00
public void setTextColor(int color) {
textView.setTextColor(color);
}
2021-06-25 02:43:10 +02:00
public void setIconColor(int color) {
imageView.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
}
2015-12-09 19:27:52 +01:00
public void setGravity(int gravity) {
textView.setGravity(gravity);
}
2015-06-29 19:12:11 +02:00
public void setTextAndIcon(CharSequence text, int icon) {
setTextAndIcon(text, icon, null, false);
}
public void setTextAndIcon(CharSequence text, Drawable icon) {
setTextAndIcon(text, 0, icon, false);
2019-12-31 14:08:08 +01:00
}
public void setTextAndIcon(CharSequence text, int icon, Drawable drawable, boolean bigTitle) {
2015-06-29 19:12:11 +02:00
textView.setText(text);
if (icon != 0 || drawable != null) {
if (drawable != null) {
imageView.setImageDrawable(drawable);
} else {
imageView.setImageResource(icon);
}
2015-06-29 19:12:11 +02:00
imageView.setVisibility(VISIBLE);
2020-06-25 17:28:24 +02:00
textView.setPadding(0, 0, 0, 0);
2015-06-29 19:12:11 +02:00
} else {
2020-06-25 17:28:24 +02:00
imageView.setVisibility(GONE);
textView.setPadding(AndroidUtilities.dp(bigTitle ? 21 : 16), 0, 0, 0);
2015-06-29 19:12:11 +02:00
}
2015-05-21 23:27:27 +02:00
}
2020-04-24 11:21:58 +02:00
public TextView getTextView() {
return textView;
}
public ImageView getImageView() {
return imageView;
}
2021-09-20 00:10:42 +02:00
private int getThemedColor(String key) {
Integer color = resourcesProvider != null ? resourcesProvider.getColor(key) : null;
return color != null ? color : Theme.getColor(key);
}
2015-05-21 23:27:27 +02:00
}
2017-12-08 18:35:59 +01:00
public void setAllowNestedScroll(boolean value) {
allowNestedScroll = value;
if (!allowNestedScroll) {
containerView.setTranslationY(0);
}
}
2019-12-31 14:08:08 +01:00
public BottomSheet(Context context, boolean needFocus) {
2021-09-20 00:10:42 +02:00
this(context, needFocus, null);
}
2021-09-20 11:14:20 +02:00
2021-09-20 00:10:42 +02:00
public BottomSheet(Context context, boolean needFocus, Theme.ResourcesProvider resourcesProvider) {
2016-04-22 15:49:00 +02:00
super(context, R.style.TransparentDialog);
2021-09-20 00:10:42 +02:00
this.resourcesProvider = resourcesProvider;
2016-04-22 15:49:00 +02:00
2021-03-19 11:25:58 +01:00
if (Build.VERSION.SDK_INT >= 30) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
} else if (Build.VERSION.SDK_INT >= 21) {
2016-04-22 15:49:00 +02:00
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
}
2020-06-25 17:28:24 +02:00
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
2016-05-25 23:49:47 +02:00
ViewConfiguration vc = ViewConfiguration.get(context);
touchSlop = vc.getScaledTouchSlop();
2016-04-22 15:49:00 +02:00
Rect padding = new Rect();
2020-06-25 17:28:24 +02:00
shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow).mutate();
2021-09-20 11:14:20 +02:00
shadowDrawable.setColorFilter(new PorterDuffColorFilter(getThemedColor(Theme.key_dialogBackground), PorterDuff.Mode.SRC_IN));
2016-04-22 15:49:00 +02:00
shadowDrawable.getPadding(padding);
backgroundPaddingLeft = padding.left;
backgroundPaddingTop = padding.top;
2015-05-21 23:27:27 +02:00
2017-03-31 01:58:05 +02:00
container = new ContainerView(getContext()) {
@Override
public boolean drawChild(Canvas canvas, View child, long drawingTime) {
try {
return allowDrawContent && super.drawChild(canvas, child, drawingTime);
} catch (Exception e) {
FileLog.e(e);
}
return true;
}
};
2016-05-25 23:49:47 +02:00
container.setBackgroundDrawable(backDrawable);
2015-11-26 22:04:02 +01:00
focusable = needFocus;
if (Build.VERSION.SDK_INT >= 21) {
2015-10-29 18:10:07 +01:00
container.setFitsSystemWindows(true);
2018-08-27 10:33:11 +02:00
container.setOnApplyWindowInsetsListener((v, insets) -> {
2021-04-14 03:44:46 +02:00
int newTopInset = insets.getSystemWindowInsetTop();
if ((newTopInset != 0 || AndroidUtilities.isInMultiwindow) && statusBarHeight != 0 && statusBarHeight != newTopInset) {
statusBarHeight = newTopInset;
}
2018-08-27 10:33:11 +02:00
lastInsets = insets;
v.requestLayout();
2021-01-28 15:15:51 +01:00
if (Build.VERSION.SDK_INT >= 30) {
return WindowInsets.CONSUMED;
} else {
return insets.consumeSystemWindowInsets();
}
2015-11-26 22:04:02 +01:00
});
2021-03-19 11:25:58 +01:00
if (Build.VERSION.SDK_INT >= 30) {
container.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
} else {
container.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
2015-10-29 18:10:07 +01:00
}
2016-05-25 23:49:47 +02:00
backDrawable.setAlpha(0);
2015-05-21 23:27:27 +02:00
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Window window = getWindow();
2021-01-28 15:15:51 +01:00
/*if (Build.VERSION.SDK_INT >= 30) {
window.setDecorFitsSystemWindows(true);
}*/
2015-06-29 19:12:11 +02:00
window.setWindowAnimations(R.style.DialogNoAnimation);
2015-07-22 20:56:37 +02:00
setContentView(container, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
if (useLightStatusBar && Build.VERSION.SDK_INT >= 23) {
2019-12-31 14:08:08 +01:00
int color = Theme.getColor(Theme.key_actionBarDefault, null, true);
if (color == 0xffffffff) {
int flags = container.getSystemUiVisibility();
flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
container.setSystemUiVisibility(flags);
}
}
2020-12-23 08:48:30 +01:00
if (useLightNavBar && Build.VERSION.SDK_INT >= 26) {
AndroidUtilities.setLightNavigationBar(getWindow(), false);
}
2019-12-31 14:08:08 +01:00
2016-05-25 23:49:47 +02:00
if (containerView == null) {
2020-06-25 17:28:24 +02:00
containerView = new LinearLayout(getContext()) {
2016-05-25 23:49:47 +02:00
@Override
public boolean hasOverlappingRendering() {
return false;
2015-07-22 20:56:37 +02:00
}
2017-03-31 01:58:05 +02:00
@Override
public void setTranslationY(float translationY) {
super.setTranslationY(translationY);
onContainerTranslationYChanged(translationY);
}
2020-06-25 17:28:24 +02:00
{
setOrientation(VERTICAL);
}
2016-05-25 23:49:47 +02:00
};
containerView.setBackgroundDrawable(shadowDrawable);
2017-03-31 01:58:05 +02:00
containerView.setPadding(backgroundPaddingLeft, (applyTopPadding ? AndroidUtilities.dp(8) : 0) + backgroundPaddingTop - 1, backgroundPaddingLeft, (applyBottomPadding ? AndroidUtilities.dp(8) : 0));
2016-05-25 23:49:47 +02:00
}
2016-04-22 15:49:00 +02:00
containerView.setVisibility(View.INVISIBLE);
2015-07-22 20:56:37 +02:00
container.addView(containerView, 0, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM));
2015-05-21 23:27:27 +02:00
if (title != null) {
2019-01-23 18:03:33 +01:00
titleView = new TextView(getContext());
titleView.setText(title);
2020-06-25 17:28:24 +02:00
titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
titleView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
titleView.setMinHeight(AndroidUtilities.dp(25));
2019-12-31 14:08:08 +01:00
if (bigTitle) {
2020-06-25 17:28:24 +02:00
titleView.setSingleLine(true);
titleView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
2021-09-20 11:14:20 +02:00
titleView.setTextColor(getThemedColor(Theme.key_dialogTextBlue2));
2019-12-31 14:08:08 +01:00
titleView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
} else {
2021-09-20 00:10:42 +02:00
titleView.setTextColor(getThemedColor(Theme.key_dialogTextGray2));
2019-12-31 14:08:08 +01:00
}
titleView.setGravity(Gravity.CENTER_VERTICAL);
2020-06-25 17:28:24 +02:00
containerView.addView(titleView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 21, 15, 21, 0));
2018-08-27 10:33:11 +02:00
titleView.setOnTouchListener((v, event) -> true);
}
2015-06-29 19:12:11 +02:00
if (customView != null) {
if (customView.getParent() != null) {
ViewGroup viewGroup = (ViewGroup) customView.getParent();
viewGroup.removeView(customView);
}
2020-06-25 17:28:24 +02:00
containerView.addView(customView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 0));
2016-05-25 23:49:47 +02:00
} else {
if (items != null) {
2020-06-25 17:28:24 +02:00
FrameLayout rootView = new ScrollView(getContext());
LinearLayout rowView = new LinearLayout(getContext());
rowView.setOrientation(LinearLayout.VERTICAL);
rootView.addView(rowView, new ScrollView.LayoutParams(-1, -1));
containerView.addView(rootView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 0));
2016-05-25 23:49:47 +02:00
for (int a = 0; a < items.length; a++) {
2017-03-31 01:58:05 +02:00
if (items[a] == null) {
continue;
}
2021-09-20 00:10:42 +02:00
BottomSheetCell cell = new BottomSheetCell(getContext(), 0, resourcesProvider);
cell.setTextAndIcon(items[a], itemIcons != null ? itemIcons[a] : 0, null, bigTitle);
2020-06-25 17:28:24 +02:00
rowView.addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 56, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 0));
2016-05-25 23:49:47 +02:00
cell.setTag(a);
2018-08-27 10:33:11 +02:00
cell.setOnClickListener(v -> dismissWithButtonClick((Integer) v.getTag()));
2016-05-25 23:49:47 +02:00
itemViews.add(cell);
}
2015-05-21 23:27:27 +02:00
}
}
2016-04-22 15:49:00 +02:00
WindowManager.LayoutParams params = window.getAttributes();
2015-05-21 23:27:27 +02:00
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
params.gravity = Gravity.TOP | Gravity.LEFT;
2016-04-22 15:49:00 +02:00
params.dimAmount = 0;
params.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
2019-06-04 12:14:50 +02:00
if (focusable) {
2020-09-30 15:48:47 +02:00
params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
2019-06-04 12:14:50 +02:00
} else {
2015-11-26 22:04:02 +01:00
params.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
}
2019-05-14 14:08:05 +02:00
if (isFullscreen) {
2019-01-23 18:03:33 +01:00
if (Build.VERSION.SDK_INT >= 21) {
params.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR |
WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
}
params.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
2019-06-04 12:14:50 +02:00
container.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN);
2019-01-23 18:03:33 +01:00
}
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
2019-05-14 14:08:05 +02:00
if (Build.VERSION.SDK_INT >= 28) {
params.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
}
2016-04-22 15:49:00 +02:00
window.setAttributes(params);
2015-07-22 20:56:37 +02:00
}
2015-06-29 19:12:11 +02:00
2020-12-24 20:58:45 +01:00
public void setUseLightStatusBar(boolean value) {
useLightStatusBar = value;
if (Build.VERSION.SDK_INT >= 23) {
int color = Theme.getColor(Theme.key_actionBarDefault, null, true);
int flags = container.getSystemUiVisibility();
if (useLightStatusBar && color == 0xffffffff) {
flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
} else {
flags &=~ View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
}
container.setSystemUiVisibility(flags);
}
}
2019-08-22 01:53:26 +02:00
public boolean isFocusable() {
return focusable;
}
public void setFocusable(boolean value) {
if (focusable == value) {
return;
}
focusable = value;
Window window = getWindow();
WindowManager.LayoutParams params = window.getAttributes();
if (focusable) {
2020-09-30 15:48:47 +02:00
params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
2020-06-25 17:28:24 +02:00
params.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
2019-08-22 01:53:26 +02:00
} else {
params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
params.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
}
window.setAttributes(params);
}
2017-03-31 01:58:05 +02:00
public void setShowWithoutAnimation(boolean value) {
showWithoutAnimation = value;
}
public void setBackgroundColor(int color) {
2020-06-25 17:28:24 +02:00
shadowDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
2015-07-22 20:56:37 +02:00
@Override
public void show() {
super.show();
2015-11-26 22:04:02 +01:00
if (focusable) {
2020-09-30 15:48:47 +02:00
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
2015-11-26 22:04:02 +01:00
}
2015-07-22 20:56:37 +02:00
dismissed = false;
2016-05-25 23:49:47 +02:00
cancelSheetAnimation();
2017-03-31 01:58:05 +02:00
containerView.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.displaySize.x + backgroundPaddingLeft * 2, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.displaySize.y, View.MeasureSpec.AT_MOST));
if (showWithoutAnimation) {
2020-12-23 08:48:30 +01:00
backDrawable.setAlpha(dimBehind ? dimBehindAlpha : 0);
2017-03-31 01:58:05 +02:00
containerView.setTranslationY(0);
return;
2015-07-22 20:56:37 +02:00
}
backDrawable.setAlpha(0);
2016-05-25 23:49:47 +02:00
if (Build.VERSION.SDK_INT >= 18) {
layoutCount = 2;
2020-12-23 08:48:30 +01:00
containerView.setTranslationY((Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0) + containerView.getMeasuredHeight());
2016-05-25 23:49:47 +02:00
AndroidUtilities.runOnUIThread(startAnimationRunnable = new Runnable() {
2015-08-13 11:23:31 +02:00
@Override
public void run() {
2016-10-11 13:57:01 +02:00
if (startAnimationRunnable != this || dismissed) {
2016-05-25 23:49:47 +02:00
return;
}
startAnimationRunnable = null;
2015-08-13 11:23:31 +02:00
startOpenAnimation();
}
2021-12-07 14:02:02 +01:00
}, openNoDelay ? 0 : 150);
2015-08-13 11:23:31 +02:00
} else {
2015-07-22 20:56:37 +02:00
startOpenAnimation();
}
}
2015-06-29 19:12:11 +02:00
2020-04-24 11:21:58 +02:00
public ColorDrawable getBackDrawable() {
return backDrawable;
}
public int getBackgroundPaddingTop() {
return backgroundPaddingTop;
}
2017-03-31 01:58:05 +02:00
public void setAllowDrawContent(boolean value) {
if (allowDrawContent != value) {
allowDrawContent = value;
container.setBackgroundDrawable(allowDrawContent ? backDrawable : null);
container.invalidate();
}
}
2016-05-25 23:49:47 +02:00
protected boolean canDismissWithSwipe() {
2019-12-31 14:08:08 +01:00
return canDismissWithSwipe;
}
public void setCanDismissWithSwipe(boolean value) {
canDismissWithSwipe = value;
2016-05-25 23:49:47 +02:00
}
2016-10-11 13:57:01 +02:00
protected boolean onContainerTouchEvent(MotionEvent event) {
return false;
}
2021-12-30 11:52:40 +01:00
protected boolean onScrollUp(float translationY) {
return false;
}
protected void onScrollUpEnd(float translationY) {
}
protected void onScrollUpBegin(float translationY) {}
2016-10-11 13:57:01 +02:00
2016-04-22 15:49:00 +02:00
public void setCustomView(View view) {
customView = view;
}
public void setTitle(CharSequence value) {
2019-12-31 14:08:08 +01:00
setTitle(value, false);
}
public void setTitle(CharSequence value, boolean big) {
2016-04-22 15:49:00 +02:00
title = value;
2019-12-31 14:08:08 +01:00
bigTitle = big;
2020-06-25 17:28:24 +02:00
setApplyTopPadding(true);
2016-04-22 15:49:00 +02:00
}
public void setApplyTopPadding(boolean value) {
applyTopPadding = value;
}
public void setApplyBottomPadding(boolean value) {
applyBottomPadding = value;
}
2016-10-11 13:57:01 +02:00
protected boolean onCustomMeasure(View view, int width, int height) {
return false;
}
protected boolean onCustomLayout(View view, int left, int top, int right, int bottom) {
return false;
}
protected boolean canDismissWithTouchOutside() {
return true;
}
2019-01-23 18:03:33 +01:00
public TextView getTitleView() {
return titleView;
}
2017-03-31 01:58:05 +02:00
protected void onContainerTranslationYChanged(float translationY) {
}
2016-05-25 23:49:47 +02:00
private void cancelSheetAnimation() {
if (currentSheetAnimation != null) {
currentSheetAnimation.cancel();
2016-05-25 23:49:47 +02:00
currentSheetAnimation = null;
2019-08-22 01:53:26 +02:00
currentSheetAnimationType = 0;
2015-07-22 20:56:37 +02:00
}
}
2021-01-28 15:15:51 +01:00
public void setOnHideListener(OnDismissListener listener) {
onHideListener = listener;
}
2021-11-05 11:06:49 +01:00
protected int getTargetOpenTranslationY() {
return 0;
}
2015-07-22 20:56:37 +02:00
private void startOpenAnimation() {
2016-10-11 13:57:01 +02:00
if (dismissed) {
return;
}
2016-04-22 15:49:00 +02:00
containerView.setVisibility(View.VISIBLE);
2016-05-25 23:49:47 +02:00
if (!onCustomOpenAnimation()) {
if (Build.VERSION.SDK_INT >= 20 && useHardwareLayer) {
2016-04-25 21:26:41 +02:00
container.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
containerView.setTranslationY(containerView.getMeasuredHeight());
2019-08-22 01:53:26 +02:00
currentSheetAnimationType = 1;
currentSheetAnimation = new AnimatorSet();
currentSheetAnimation.playTogether(
ObjectAnimator.ofFloat(containerView, View.TRANSLATION_Y, 0),
2020-12-23 08:48:30 +01:00
ObjectAnimator.ofInt(backDrawable, AnimationProperties.COLOR_DRAWABLE_ALPHA, dimBehind ? dimBehindAlpha : 0));
2019-08-22 01:53:26 +02:00
currentSheetAnimation.setDuration(400);
currentSheetAnimation.setInterpolator(openInterpolator);
currentSheetAnimation.addListener(new AnimatorListenerAdapter() {
2015-07-22 20:56:37 +02:00
@Override
public void onAnimationEnd(Animator animation) {
2016-05-25 23:49:47 +02:00
if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
currentSheetAnimation = null;
2019-08-22 01:53:26 +02:00
currentSheetAnimationType = 0;
2016-05-25 23:49:47 +02:00
if (delegate != null) {
delegate.onOpenAnimationEnd();
}
if (useHardwareLayer) {
container.setLayerType(View.LAYER_TYPE_NONE, null);
}
2019-06-04 12:14:50 +02:00
if (isFullscreen) {
WindowManager.LayoutParams params = getWindow().getAttributes();
params.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(params);
}
2015-07-22 20:56:37 +02:00
}
2019-07-18 15:01:39 +02:00
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.startAllHeavyOperations, 512);
2016-05-25 23:49:47 +02:00
}
@Override
public void onAnimationCancel(Animator animation) {
2016-05-25 23:49:47 +02:00
if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
currentSheetAnimation = null;
2019-08-22 01:53:26 +02:00
currentSheetAnimationType = 0;
2015-07-22 20:56:37 +02:00
}
}
});
2019-07-18 15:01:39 +02:00
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.stopAllHeavyOperations, 512);
2019-08-22 01:53:26 +02:00
currentSheetAnimation.start();
2015-07-22 20:56:37 +02:00
}
2015-05-21 23:27:27 +02:00
}
2016-05-25 23:49:47 +02:00
public void setDelegate(BottomSheetDelegateInterface bottomSheetDelegate) {
delegate = bottomSheetDelegate;
2015-05-21 23:27:27 +02:00
}
2020-06-25 17:28:24 +02:00
public LinearLayout getContainer() {
2015-05-21 23:27:27 +02:00
return container;
}
2016-05-25 23:49:47 +02:00
public ViewGroup getSheetContainer() {
2015-07-22 20:56:37 +02:00
return containerView;
2015-05-21 23:27:27 +02:00
}
2015-06-29 19:12:11 +02:00
public int getTag() {
return tag;
}
2019-05-14 14:08:05 +02:00
public void setDimBehind(boolean value) {
dimBehind = value;
}
2020-12-23 08:48:30 +01:00
public void setDimBehindAlpha(int value) {
dimBehindAlpha = value;
}
2015-06-29 19:12:11 +02:00
public void setItemText(int item, CharSequence text) {
if (item < 0 || item >= itemViews.size()) {
return;
}
BottomSheetCell cell = itemViews.get(item);
cell.textView.setText(text);
}
2019-01-23 18:03:33 +01:00
public void setItemColor(int item, int color, int icon) {
if (item < 0 || item >= itemViews.size()) {
return;
}
BottomSheetCell cell = itemViews.get(item);
cell.textView.setTextColor(color);
2020-06-25 17:28:24 +02:00
cell.imageView.setColorFilter(new PorterDuffColorFilter(icon, PorterDuff.Mode.SRC_IN));
2019-01-23 18:03:33 +01:00
}
2021-06-25 02:43:10 +02:00
public ArrayList<BottomSheetCell> getItemViews() {
return itemViews;
}
2019-05-14 14:08:05 +02:00
public void setItems(CharSequence[] i, int[] icons, final OnClickListener listener) {
items = i;
itemIcons = icons;
onClickListener = listener;
}
2019-01-23 18:03:33 +01:00
public void setTitleColor(int color) {
if (titleView == null) {
return;
}
titleView.setTextColor(color);
}
2016-05-25 23:49:47 +02:00
public boolean isDismissed() {
return dismissed;
}
2015-07-22 20:56:37 +02:00
public void dismissWithButtonClick(final int item) {
2015-05-21 23:27:27 +02:00
if (dismissed) {
return;
}
2015-07-22 20:56:37 +02:00
dismissed = true;
2016-05-25 23:49:47 +02:00
cancelSheetAnimation();
2019-08-22 01:53:26 +02:00
currentSheetAnimationType = 2;
currentSheetAnimation = new AnimatorSet();
currentSheetAnimation.playTogether(
2020-03-30 14:00:09 +02:00
ObjectAnimator.ofFloat(containerView, View.TRANSLATION_Y, containerView.getMeasuredHeight() + AndroidUtilities.dp(10)),
ObjectAnimator.ofInt(backDrawable, AnimationProperties.COLOR_DRAWABLE_ALPHA, 0)
);
2019-08-22 01:53:26 +02:00
currentSheetAnimation.setDuration(180);
currentSheetAnimation.setInterpolator(CubicBezierInterpolator.EASE_OUT);
currentSheetAnimation.addListener(new AnimatorListenerAdapter() {
2015-05-21 23:27:27 +02:00
@Override
public void onAnimationEnd(Animator animation) {
2016-05-25 23:49:47 +02:00
if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
currentSheetAnimation = null;
2019-08-22 01:53:26 +02:00
currentSheetAnimationType = 0;
2016-05-25 23:49:47 +02:00
if (onClickListener != null) {
onClickListener.onClick(BottomSheet.this, item);
2015-05-21 23:27:27 +02:00
}
2018-08-27 10:33:11 +02:00
AndroidUtilities.runOnUIThread(() -> {
try {
BottomSheet.super.dismiss();
} catch (Exception e) {
FileLog.e(e);
2016-05-25 23:49:47 +02:00
}
});
}
2019-07-18 15:01:39 +02:00
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.startAllHeavyOperations, 512);
2016-05-25 23:49:47 +02:00
}
@Override
public void onAnimationCancel(Animator animation) {
2016-05-25 23:49:47 +02:00
if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
currentSheetAnimation = null;
2019-08-22 01:53:26 +02:00
currentSheetAnimationType = 0;
2016-05-25 23:49:47 +02:00
}
2015-05-21 23:27:27 +02:00
}
});
2019-07-18 15:01:39 +02:00
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.stopAllHeavyOperations, 512);
2019-08-22 01:53:26 +02:00
currentSheetAnimation.start();
2015-05-21 23:27:27 +02:00
}
2020-09-30 15:48:47 +02:00
@Override
public boolean dispatchTouchEvent(@NonNull MotionEvent ev) {
if (dismissed) {
return false;
}
return super.dispatchTouchEvent(ev);
}
2015-05-21 23:27:27 +02:00
@Override
public void dismiss() {
2017-03-31 01:58:05 +02:00
if (delegate != null && !delegate.canDismiss()) {
return;
}
2015-05-21 23:27:27 +02:00
if (dismissed) {
return;
}
dismissed = true;
2021-01-28 15:15:51 +01:00
if (onHideListener != null) {
onHideListener.onDismiss(this);
}
2016-05-25 23:49:47 +02:00
cancelSheetAnimation();
2021-02-23 12:53:38 +01:00
long duration = 0;
2016-05-25 23:49:47 +02:00
if (!allowCustomAnimation || !onCustomCloseAnimation()) {
2019-08-22 01:53:26 +02:00
currentSheetAnimationType = 2;
currentSheetAnimation = new AnimatorSet();
currentSheetAnimation.playTogether(
2020-09-30 15:48:47 +02:00
ObjectAnimator.ofFloat(containerView, View.TRANSLATION_Y, containerView.getMeasuredHeight() + container.keyboardHeight + AndroidUtilities.dp(10)),
2020-03-30 14:00:09 +02:00
ObjectAnimator.ofInt(backDrawable, AnimationProperties.COLOR_DRAWABLE_ALPHA, 0)
);
2016-05-25 23:49:47 +02:00
if (useFastDismiss) {
int height = containerView.getMeasuredHeight();
2021-02-23 12:53:38 +01:00
duration = Math.max(60, (int) (250 * (height - containerView.getTranslationY()) / (float) height));
currentSheetAnimation.setDuration(duration);
2016-05-25 23:49:47 +02:00
useFastDismiss = false;
} else {
2021-02-23 12:53:38 +01:00
currentSheetAnimation.setDuration(duration = 250);
2016-05-25 23:49:47 +02:00
}
2020-09-30 15:48:47 +02:00
currentSheetAnimation.setInterpolator(CubicBezierInterpolator.DEFAULT);
2019-08-22 01:53:26 +02:00
currentSheetAnimation.addListener(new AnimatorListenerAdapter() {
2015-07-22 20:56:37 +02:00
@Override
public void onAnimationEnd(Animator animation) {
2016-05-25 23:49:47 +02:00
if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
currentSheetAnimation = null;
2019-08-22 01:53:26 +02:00
currentSheetAnimationType = 0;
2018-08-27 10:33:11 +02:00
AndroidUtilities.runOnUIThread(() -> {
try {
dismissInternal();
} catch (Exception e) {
FileLog.e(e);
2015-07-22 20:56:37 +02:00
}
2016-05-25 23:49:47 +02:00
});
}
2019-07-18 15:01:39 +02:00
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.startAllHeavyOperations, 512);
2016-05-25 23:49:47 +02:00
}
@Override
public void onAnimationCancel(Animator animation) {
2016-05-25 23:49:47 +02:00
if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
currentSheetAnimation = null;
2019-08-22 01:53:26 +02:00
currentSheetAnimationType = 0;
2016-05-25 23:49:47 +02:00
}
2015-07-22 20:56:37 +02:00
}
});
2019-07-18 15:01:39 +02:00
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.stopAllHeavyOperations, 512);
2019-08-22 01:53:26 +02:00
currentSheetAnimation.start();
2015-07-22 20:56:37 +02:00
}
2021-02-23 12:53:38 +01:00
Bulletin bulletin = Bulletin.getVisibleBulletin();
if (bulletin != null && bulletin.isShowing()) {
if (duration > 0) {
bulletin.hide((long) (duration * 0.6f));
} else {
bulletin.hide();
}
}
2015-05-21 23:27:27 +02:00
}
2020-04-24 11:21:58 +02:00
public int getSheetAnimationType() {
return currentSheetAnimationType;
}
2016-10-11 13:57:01 +02:00
public void dismissInternal() {
try {
super.dismiss();
} catch (Exception e) {
2017-03-31 01:58:05 +02:00
FileLog.e(e);
2016-10-11 13:57:01 +02:00
}
2016-05-25 23:49:47 +02:00
}
protected boolean onCustomCloseAnimation() {
return false;
}
protected boolean onCustomOpenAnimation() {
return false;
}
2015-05-21 23:27:27 +02:00
public static class Builder {
private BottomSheet bottomSheet;
public Builder(Context context) {
2021-09-20 00:10:42 +02:00
this(context, false);
2015-11-26 22:04:02 +01:00
}
public Builder(Context context, boolean needFocus) {
2021-09-20 00:10:42 +02:00
this(context, needFocus, null);
}
public Builder(Context context, boolean needFocus, Theme.ResourcesProvider resourcesProvider) {
bottomSheet = new BottomSheet(context, needFocus, resourcesProvider);
2015-05-21 23:27:27 +02:00
}
public Builder setItems(CharSequence[] items, final OnClickListener onClickListener) {
bottomSheet.items = items;
bottomSheet.onClickListener = onClickListener;
return this;
}
2015-06-29 19:12:11 +02:00
public Builder setItems(CharSequence[] items, int[] icons, final OnClickListener onClickListener) {
bottomSheet.items = items;
bottomSheet.itemIcons = icons;
bottomSheet.onClickListener = onClickListener;
return this;
}
2015-05-21 23:27:27 +02:00
public Builder setCustomView(View view) {
bottomSheet.customView = view;
return this;
}
2020-10-30 11:26:29 +01:00
public View getCustomView() {
return bottomSheet.customView;
}
2015-06-29 19:12:11 +02:00
public Builder setTitle(CharSequence title) {
2019-12-31 14:08:08 +01:00
return setTitle(title, false);
}
public Builder setTitle(CharSequence title, boolean big) {
2015-06-29 19:12:11 +02:00
bottomSheet.title = title;
2019-12-31 14:08:08 +01:00
bottomSheet.bigTitle = big;
2015-06-29 19:12:11 +02:00
return this;
}
2015-05-21 23:27:27 +02:00
public BottomSheet create() {
return bottomSheet;
}
2019-05-14 14:08:05 +02:00
public BottomSheet setDimBehind(boolean value) {
bottomSheet.dimBehind = value;
return bottomSheet;
}
2015-05-21 23:27:27 +02:00
public BottomSheet show() {
bottomSheet.show();
return bottomSheet;
}
2015-06-29 19:12:11 +02:00
public Builder setTag(int tag) {
bottomSheet.tag = tag;
return this;
}
public Builder setUseHardwareLayer(boolean value) {
bottomSheet.useHardwareLayer = value;
return this;
}
2015-06-29 19:12:11 +02:00
public Builder setDelegate(BottomSheetDelegate delegate) {
bottomSheet.setDelegate(delegate);
return this;
}
2016-04-22 15:49:00 +02:00
public Builder setApplyTopPadding(boolean value) {
bottomSheet.applyTopPadding = value;
return this;
}
public Builder setApplyBottomPadding(boolean value) {
bottomSheet.applyBottomPadding = value;
2015-07-22 20:56:37 +02:00
return this;
}
2018-07-30 04:07:02 +02:00
public Runnable getDismissRunnable() {
return bottomSheet.dismissRunnable;
}
2015-07-22 20:56:37 +02:00
public BottomSheet setUseFullWidth(boolean value) {
bottomSheet.fullWidth = value;
2015-05-21 23:27:27 +02:00
return bottomSheet;
}
2019-01-23 18:03:33 +01:00
public BottomSheet setUseFullscreen(boolean value) {
2019-05-14 14:08:05 +02:00
bottomSheet.isFullscreen = value;
2019-01-23 18:03:33 +01:00
return bottomSheet;
}
2015-05-21 23:27:27 +02:00
}
2017-03-31 01:58:05 +02:00
2020-04-24 11:21:58 +02:00
public int getLeftInset() {
2017-03-31 01:58:05 +02:00
if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
return lastInsets.getSystemWindowInsetLeft();
}
return 0;
}
2020-04-24 11:21:58 +02:00
public int getRightInset() {
2019-05-14 14:08:05 +02:00
if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
return lastInsets.getSystemWindowInsetRight();
}
return 0;
}
2020-04-24 11:21:58 +02:00
public int getBottomInset() {
return bottomInset;
}
2017-03-31 01:58:05 +02:00
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
}
public void onContainerDraw(Canvas canvas) {
}
2019-12-31 14:08:08 +01:00
2020-04-24 11:21:58 +02:00
public ArrayList<ThemeDescription> getThemeDescriptions() {
2019-12-31 14:08:08 +01:00
return null;
}
2020-09-30 15:48:47 +02:00
public void setCurrentPanTranslationY(float currentPanTranslationY) {
this.currentPanTranslationY = currentPanTranslationY;
container.invalidate();
}
2021-06-25 02:43:10 +02:00
private int overlayDrawNavBarColor;
public void setOverlayNavBarColor(int color) {
overlayDrawNavBarColor = color;
if (container != null) {
container.invalidate();
}
if (Color.alpha(color) > 120) {
AndroidUtilities.setLightStatusBar(getWindow(), false);
AndroidUtilities.setLightNavigationBar(getWindow(), false);
} else {
AndroidUtilities.setLightNavigationBar(getWindow(), !useLightNavBar);
AndroidUtilities.setLightStatusBar(getWindow(), !useLightStatusBar);
}
}
public ViewGroup getContainerView() {
return containerView;
}
public int getCurrentAccount() {
return currentAccount;
}
2021-09-20 00:10:42 +02:00
protected int getThemedColor(String key) {
Integer color = resourcesProvider != null ? resourcesProvider.getColor(key) : null;
return color != null ? color : Theme.getColor(key);
}
2021-12-07 14:02:02 +01:00
public void setOpenNoDelay(boolean openNoDelay) {
this.openNoDelay = openNoDelay;
}
2015-05-21 23:27:27 +02:00
}