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

1118 lines
43 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;
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;
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;
2019-05-14 14:08:05 +02:00
import androidx.core.view.NestedScrollingParent;
import androidx.core.view.NestedScrollingParentHelper;
import androidx.core.view.ViewCompat;
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;
import android.widget.FrameLayout;
2015-06-29 19:12:11 +02:00
import android.widget.ImageView;
2015-05-21 23:27:27 +02:00
import android.widget.TextView;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.LocaleController;
2015-05-21 23:27:27 +02:00
import org.telegram.messenger.FileLog;
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-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;
2016-04-22 15:49:00 +02:00
private WindowInsets lastInsets;
2015-06-29 19:12:11 +02:00
2016-05-25 23:49:47 +02:00
private Runnable startAnimationRunnable;
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;
2016-10-11 13:57:01 +02:00
protected boolean fullWidth;
2019-05-14 14:08:05 +02:00
protected boolean isFullscreen;
2016-05-25 23:49:47 +02:00
protected ColorDrawable backDrawable = new ColorDrawable(0xff000000);
private boolean allowCustomAnimation = true;
2017-03-31 01:58:05 +02:00
private boolean showWithoutAnimation;
2016-05-25 23:49:47 +02:00
private int touchSlop;
private boolean useFastDismiss;
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;
2017-12-08 18:35:59 +01:00
private boolean allowNestedScroll = true;
2016-04-22 15:49:00 +02:00
private Drawable shadowDrawable;
2019-05-14 14:08:05 +02:00
protected int backgroundPaddingTop;
protected int backgroundPaddingLeft;
2015-07-22 20:56:37 +02:00
2016-04-22 15:49:00 +02:00
private boolean applyTopPadding = true;
private boolean applyBottomPadding = true;
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;
2015-07-22 20:56:37 +02:00
2018-07-30 04:07:02 +02:00
protected View nestedScrollChild;
2016-10-11 13:57:01 +02:00
protected class ContainerView extends FrameLayout 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;
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);
}
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);
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);
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));
2016-05-25 23:49:47 +02:00
currentAnimation.setDuration((int) (150 * (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;
}
}
2018-07-30 04:07:02 +02:00
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;
}
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;
}
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;
velocityTracker.addMovement(ev);
if (maybeStartTracking && !startedTracking && (dy > 0 && dy / 3.0f > Math.abs(dx) && Math.abs(dy) >= touchSlop)) {
startedTrackingY = (int) ev.getY();
maybeStartTracking = false;
startedTracking = true;
requestDisallowInterceptTouchEvent(true);
} else if (startedTracking) {
float translationY = containerView.getTranslationY();
2016-05-25 23:49:47 +02:00
translationY += dy;
if (translationY < 0) {
translationY = 0;
}
containerView.setTranslationY(translationY);
2016-05-25 23:49:47 +02:00
startedTrackingY = (int) ev.getY();
}
} else if (ev == null || ev != null && ev.getPointerId(0) == startedTrackingPointerId && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_POINTER_UP)) {
if (velocityTracker == null) {
velocityTracker = VelocityTracker.obtain();
}
velocityTracker.computeCurrentVelocity(1000);
float translationY = containerView.getTranslationY();
2016-05-25 23:49:47 +02:00
if (startedTracking || translationY != 0) {
checkDismiss(velocityTracker.getXVelocity(), velocityTracker.getYVelocity());
startedTracking = false;
} else {
maybeStartTracking = false;
startedTracking = false;
}
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);
if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
height -= lastInsets.getSystemWindowInsetBottom();
2016-05-25 23:49:47 +02:00
}
setMeasuredDimension(width, height);
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
}
@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) {
if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
left += lastInsets.getSystemWindowInsetLeft();
2017-03-31 01:58:05 +02:00
right -= lastInsets.getSystemWindowInsetRight();
2016-05-25 23:49:47 +02:00
}
2017-03-31 01:58:05 +02:00
int t = (bottom - top) - containerView.getMeasuredHeight();
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();
}
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;
}
2016-10-11 13:57:01 +02:00
if (!onCustomLayout(child, left, top, right, bottom)) {
final FrameLayout.LayoutParams lp = (FrameLayout.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.TOP:
childTop = lp.topMargin;
break;
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;
}
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
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
onContainerDraw(canvas);
}
2016-05-25 23:49:47 +02:00
}
public interface BottomSheetDelegateInterface {
void onOpenAnimationStart();
void onOpenAnimationEnd();
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
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
}
2015-12-09 19:27:52 +01:00
public static class BottomSheetCell extends FrameLayout {
2015-05-21 23:27:27 +02:00
private TextView textView;
2015-06-29 19:12:11 +02:00
private ImageView imageView;
2015-05-21 23:27:27 +02:00
2015-12-09 19:27:52 +01:00
public BottomSheetCell(Context context, int type) {
2015-05-21 23:27:27 +02:00
super(context);
2019-07-18 15:01:39 +02:00
setBackground(null);
2017-03-31 01:58:05 +02:00
setBackgroundDrawable(Theme.getSelectorDrawable(false));
2019-05-14 14:08:05 +02:00
//setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);
2015-06-29 19:12:11 +02:00
imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.CENTER);
2017-03-31 01:58:05 +02:00
imageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogIcon), PorterDuff.Mode.MULTIPLY));
2019-05-14 14:08:05 +02:00
addView(imageView, LayoutHelper.createFrame(56, 48, Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT)));
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.setGravity(Gravity.CENTER_HORIZONTAL);
textView.setEllipsize(TextUtils.TruncateAt.END);
2016-05-25 23:49:47 +02:00
if (type == 0) {
2017-03-31 01:58:05 +02:00
textView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
2015-06-29 19:12:11 +02:00
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
addView(textView, LayoutHelper.createFrame(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) {
2015-12-09 19:27:52 +01:00
textView.setGravity(Gravity.CENTER);
2017-03-31 01:58:05 +02:00
textView.setTextColor(Theme.getColor(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"));
addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
2015-06-29 19:12:11 +02:00
}
2015-05-21 23:27:27 +02:00
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2016-05-25 23:49:47 +02:00
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(48), 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);
}
public void setGravity(int gravity) {
textView.setGravity(gravity);
}
2015-06-29 19:12:11 +02:00
public void setTextAndIcon(CharSequence text, int icon) {
textView.setText(text);
if (icon != 0) {
imageView.setImageResource(icon);
imageView.setVisibility(VISIBLE);
2019-05-14 14:08:05 +02:00
textView.setPadding(AndroidUtilities.dp(LocaleController.isRTL ? 16 : 72), 0, AndroidUtilities.dp(LocaleController.isRTL ? 72 : 16), 0);
2015-06-29 19:12:11 +02:00
} else {
imageView.setVisibility(INVISIBLE);
2019-05-14 14:08:05 +02:00
textView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);
2015-06-29 19:12:11 +02:00
}
2015-05-21 23:27:27 +02:00
}
}
2016-05-25 23:49:47 +02:00
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
}
2017-12-08 18:35:59 +01:00
public void setAllowNestedScroll(boolean value) {
allowNestedScroll = value;
if (!allowNestedScroll) {
containerView.setTranslationY(0);
}
}
2019-05-14 14:08:05 +02:00
public BottomSheet(Context context, boolean needFocus, int backgroundType) {
2016-04-22 15:49:00 +02:00
super(context, R.style.TransparentDialog);
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);
}
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();
2019-05-14 14:08:05 +02:00
if (backgroundType == 0) {
shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow).mutate();
} else if (backgroundType == 1) {
shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow_round).mutate();
}
2017-03-31 01:58:05 +02:00
shadowDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogBackground), PorterDuff.Mode.MULTIPLY));
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) -> {
lastInsets = insets;
v.requestLayout();
return insets.consumeSystemWindowInsets();
2015-11-26 22:04:02 +01:00
});
2015-10-29 18:10:07 +01:00
container.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
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();
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));
2016-05-25 23:49:47 +02:00
if (containerView == null) {
containerView = new FrameLayout(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);
}
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
int topOffset = 0;
if (title != null) {
2019-01-23 18:03:33 +01:00
titleView = new TextView(getContext());
titleView.setLines(1);
titleView.setSingleLine(true);
titleView.setText(title);
titleView.setTextColor(Theme.getColor(Theme.key_dialogTextGray2));
titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
titleView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
titleView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), AndroidUtilities.dp(8));
titleView.setGravity(Gravity.CENTER_VERTICAL);
containerView.addView(titleView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48));
2018-08-27 10:33:11 +02:00
titleView.setOnTouchListener((v, event) -> true);
topOffset += 48;
}
2015-06-29 19:12:11 +02:00
if (customView != null) {
if (customView.getParent() != null) {
ViewGroup viewGroup = (ViewGroup) customView.getParent();
viewGroup.removeView(customView);
}
containerView.addView(customView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, topOffset, 0, 0));
2016-05-25 23:49:47 +02:00
} else {
if (items != null) {
FrameLayout rowLayout = null;
int lastRowLayoutNum = 0;
for (int a = 0; a < items.length; a++) {
2017-03-31 01:58:05 +02:00
if (items[a] == null) {
continue;
}
2016-05-25 23:49:47 +02:00
BottomSheetCell cell = new BottomSheetCell(getContext(), 0);
cell.setTextAndIcon(items[a], itemIcons != null ? itemIcons[a] : 0);
containerView.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP, 0, topOffset, 0, 0));
topOffset += 48;
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) {
params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
} 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
2017-03-31 01:58:05 +02:00
public void setShowWithoutAnimation(boolean value) {
showWithoutAnimation = value;
}
public void setBackgroundColor(int color) {
shadowDrawable.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
}
2015-07-22 20:56:37 +02:00
@Override
public void show() {
super.show();
2015-11-26 22:04:02 +01:00
if (focusable) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
}
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) {
2019-05-14 14:08:05 +02:00
backDrawable.setAlpha(dimBehind ? 51 : 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;
2017-03-31 01:58:05 +02:00
containerView.setTranslationY(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();
}
2016-05-25 23:49:47 +02:00
}, 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
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() {
return true;
}
2016-10-11 13:57:01 +02:00
protected boolean onContainerTouchEvent(MotionEvent event) {
return false;
}
2016-04-22 15:49:00 +02:00
public void setCustomView(View view) {
customView = view;
}
public void setTitle(CharSequence value) {
title = value;
}
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;
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());
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(
ObjectAnimator.ofFloat(containerView, "translationY", 0),
2019-05-14 14:08:05 +02:00
ObjectAnimator.ofInt(backDrawable, "alpha", dimBehind ? 51 : 0));
animatorSet.setDuration(400);
animatorSet.setStartDelay(20);
2019-05-14 14:08:05 +02:00
animatorSet.setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT);
2017-03-31 01:58:05 +02:00
animatorSet.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;
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;
2015-07-22 20:56:37 +02:00
}
}
});
2019-07-18 15:01:39 +02:00
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.stopAllHeavyOperations, 512);
animatorSet.start();
currentSheetAnimation = animatorSet;
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
}
public FrameLayout getContainer() {
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;
}
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);
cell.imageView.setColorFilter(new PorterDuffColorFilter(icon, PorterDuff.Mode.MULTIPLY));
}
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();
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(
ObjectAnimator.ofFloat(containerView, "translationY", containerView.getMeasuredHeight() + AndroidUtilities.dp(10)),
ObjectAnimator.ofInt(backDrawable, "alpha", 0)
);
animatorSet.setDuration(180);
2019-05-14 14:08:05 +02:00
animatorSet.setInterpolator(CubicBezierInterpolator.EASE_OUT);
2017-03-31 01:58:05 +02:00
animatorSet.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;
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;
}
2015-05-21 23:27:27 +02:00
}
});
2019-07-18 15:01:39 +02:00
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.stopAllHeavyOperations, 512);
animatorSet.start();
currentSheetAnimation = animatorSet;
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;
2016-05-25 23:49:47 +02:00
cancelSheetAnimation();
if (!allowCustomAnimation || !onCustomCloseAnimation()) {
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(
ObjectAnimator.ofFloat(containerView, "translationY", containerView.getMeasuredHeight() + AndroidUtilities.dp(10)),
ObjectAnimator.ofInt(backDrawable, "alpha", 0)
);
2016-05-25 23:49:47 +02:00
if (useFastDismiss) {
int height = containerView.getMeasuredHeight();
animatorSet.setDuration(Math.max(60, (int) (180 * (height - containerView.getTranslationY()) / (float) height)));
2016-05-25 23:49:47 +02:00
useFastDismiss = false;
} else {
animatorSet.setDuration(180);
2016-05-25 23:49:47 +02:00
}
2019-05-14 14:08:05 +02:00
animatorSet.setInterpolator(CubicBezierInterpolator.EASE_OUT);
2017-03-31 01:58:05 +02:00
animatorSet.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;
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;
}
2015-07-22 20:56:37 +02:00
}
});
2019-07-18 15:01:39 +02:00
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.stopAllHeavyOperations, 512);
animatorSet.start();
currentSheetAnimation = animatorSet;
2015-07-22 20:56:37 +02:00
}
2015-05-21 23:27:27 +02:00
}
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;
2019-05-14 14:08:05 +02:00
public Builder(Context context, boolean needFocus, int backgroundType) {
bottomSheet = new BottomSheet(context, needFocus, backgroundType);
}
2015-05-21 23:27:27 +02:00
public Builder(Context context) {
2019-05-14 14:08:05 +02:00
bottomSheet = new BottomSheet(context, false, 0);
2015-11-26 22:04:02 +01:00
}
public Builder(Context context, boolean needFocus) {
2019-05-14 14:08:05 +02:00
bottomSheet = new BottomSheet(context, needFocus, 0);
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;
}
2015-06-29 19:12:11 +02:00
public Builder setTitle(CharSequence title) {
bottomSheet.title = title;
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
protected int getLeftInset() {
if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
return lastInsets.getSystemWindowInsetLeft();
}
return 0;
}
2019-05-14 14:08:05 +02:00
protected int getRightInset() {
if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
return lastInsets.getSystemWindowInsetRight();
}
return 0;
}
2017-03-31 01:58:05 +02:00
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
}
public void onContainerDraw(Canvas canvas) {
}
2015-05-21 23:27:27 +02:00
}