2015-05-21 23:27:27 +02:00
|
|
|
/*
|
2015-10-29 18:10:07 +01:00
|
|
|
* This is the source code of Telegram for Android v. 3.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).
|
|
|
|
*
|
2016-01-11 18:19:48 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2016.
|
2015-05-21 23:27:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui.ActionBar;
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
import android.animation.Animator;
|
2015-07-22 20:56:37 +02:00
|
|
|
import android.animation.AnimatorListenerAdapter;
|
|
|
|
import android.animation.AnimatorSet;
|
|
|
|
import android.animation.ObjectAnimator;
|
|
|
|
import android.annotation.SuppressLint;
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.app.Dialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
2015-07-22 20:56:37 +02:00
|
|
|
import android.graphics.Canvas;
|
|
|
|
import android.graphics.Paint;
|
|
|
|
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;
|
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;
|
|
|
|
import android.view.View;
|
2015-06-29 19:12:11 +02:00
|
|
|
import android.view.ViewAnimationUtils;
|
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.view.animation.AccelerateInterpolator;
|
|
|
|
import android.view.animation.DecelerateInterpolator;
|
|
|
|
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.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
|
|
|
import org.telegram.messenger.AnimationCompat.AnimatorListenerAdapterProxy;
|
|
|
|
import org.telegram.messenger.AnimationCompat.AnimatorSetProxy;
|
|
|
|
import org.telegram.messenger.AnimationCompat.ObjectAnimatorProxy;
|
|
|
|
import org.telegram.messenger.AnimationCompat.ViewProxy;
|
|
|
|
import org.telegram.messenger.LocaleController;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.messenger.FileLog;
|
|
|
|
import org.telegram.messenger.R;
|
|
|
|
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 {
|
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
private LinearLayout containerView;
|
2015-05-21 23:27:27 +02:00
|
|
|
private FrameLayout container;
|
2015-11-26 22:04:02 +01:00
|
|
|
private Object lastInsets;
|
2015-06-29 19:12:11 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
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;
|
2015-07-22 20:56:37 +02:00
|
|
|
private boolean fullWidth;
|
2015-06-29 19:12:11 +02:00
|
|
|
private boolean isGrid;
|
|
|
|
private ColorDrawable backgroundDrawable = new ColorDrawable(0xff000000);
|
2015-07-22 20:56:37 +02:00
|
|
|
private static Drawable shadowDrawable;
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
private boolean focusable;
|
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
private Paint ciclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
|
|
|
|
private static int backgroundPaddingTop;
|
|
|
|
private static int backgroundPaddingLeft;
|
|
|
|
|
|
|
|
private boolean useRevealAnimation;
|
|
|
|
private float revealRadius;
|
2015-06-29 19:12:11 +02:00
|
|
|
private int revealX;
|
|
|
|
private int revealY;
|
2015-07-22 20:56:37 +02:00
|
|
|
private boolean applyTopPaddings = true;
|
2015-06-29 19:12:11 +02:00
|
|
|
|
|
|
|
private DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator();
|
|
|
|
private AccelerateInterpolator accelerateInterpolator = new AccelerateInterpolator();
|
|
|
|
|
|
|
|
private ArrayList<BottomSheetCell> itemViews = new ArrayList<>();
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
private BottomSheetDelegateInterface delegate;
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
public interface BottomSheetDelegateInterface {
|
2015-06-29 19:12:11 +02:00
|
|
|
void onOpenAnimationStart();
|
2015-07-22 20:56:37 +02:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
void onOpenAnimationEnd();
|
2015-07-22 20:56:37 +02:00
|
|
|
|
|
|
|
void onRevealAnimationStart(boolean open);
|
|
|
|
|
|
|
|
void onRevealAnimationEnd(boolean open);
|
|
|
|
|
|
|
|
void onRevealAnimationProgress(boolean open, float radius, int x, int y);
|
|
|
|
|
|
|
|
View getRevealView();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class BottomSheetDelegate implements BottomSheetDelegateInterface {
|
|
|
|
@Override
|
|
|
|
public void onOpenAnimationStart() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onOpenAnimationEnd() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRevealAnimationStart(boolean open) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRevealAnimationEnd(boolean open) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRevealAnimationProgress(boolean open, float radius, int x, int y) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getRevealView() {
|
|
|
|
return null;
|
|
|
|
}
|
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;
|
|
|
|
private boolean isGrid;
|
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);
|
2015-12-09 19:27:52 +01:00
|
|
|
isGrid = type == 1;
|
2015-05-21 23:27:27 +02:00
|
|
|
|
|
|
|
setBackgroundResource(R.drawable.list_selector);
|
2015-12-09 19:27:52 +01:00
|
|
|
if (type != 1) {
|
2015-06-29 19:12:11 +02:00
|
|
|
setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
imageView = new ImageView(context);
|
|
|
|
imageView.setScaleType(ImageView.ScaleType.CENTER);
|
2015-12-09 19:27:52 +01:00
|
|
|
if (type == 1) {
|
2015-06-29 19:12:11 +02:00
|
|
|
addView(imageView, LayoutHelper.createFrame(48, 48, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 8, 0, 0));
|
|
|
|
} else {
|
|
|
|
addView(imageView, LayoutHelper.createFrame(24, 24, 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);
|
2015-12-09 19:27:52 +01:00
|
|
|
if (type == 1) {
|
2015-06-29 19:12:11 +02:00
|
|
|
textView.setTextColor(0xff757575);
|
|
|
|
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
|
|
|
|
addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 60, 0, 0));
|
2015-12-09 19:27:52 +01:00
|
|
|
} else if (type == 0) {
|
2015-06-29 19:12:11 +02:00
|
|
|
textView.setTextColor(0xff212121);
|
|
|
|
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));
|
2015-12-09 19:27:52 +01:00
|
|
|
} else if (type == 2) {
|
|
|
|
textView.setGravity(Gravity.CENTER);
|
|
|
|
textView.setTextColor(0xff212121);
|
|
|
|
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) {
|
2015-06-29 19:12:11 +02:00
|
|
|
super.onMeasure(isGrid ? MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(96), MeasureSpec.EXACTLY) : widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(isGrid ? 80 : 48), MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
if (!isGrid) {
|
|
|
|
textView.setPadding(LocaleController.isRTL ? 0 : AndroidUtilities.dp(56), 0, LocaleController.isRTL ? AndroidUtilities.dp(56) : 0, 0);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
imageView.setVisibility(INVISIBLE);
|
|
|
|
textView.setPadding(0, 0, 0, 0);
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
public BottomSheet(Context context, boolean needFocus) {
|
2015-05-21 23:27:27 +02:00
|
|
|
super(context);
|
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
container = new FrameLayout(getContext()) {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
int width = MeasureSpec.getSize(widthMeasureSpec);
|
|
|
|
int height = MeasureSpec.getSize(heightMeasureSpec);
|
|
|
|
|
|
|
|
setMeasuredDimension(width, height);
|
|
|
|
boolean isPortrait = width < height;
|
|
|
|
|
|
|
|
if (containerView != null) {
|
|
|
|
int left = useRevealAnimation && Build.VERSION.SDK_INT <= 19 ? 0 : backgroundPaddingLeft;
|
|
|
|
if (!fullWidth) {
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
int side = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.8f);
|
|
|
|
containerView.measure(MeasureSpec.makeMeasureSpec(side + left * 2, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
|
|
|
|
} else {
|
|
|
|
int maxWidth = Math.min(AndroidUtilities.dp(480), width);
|
|
|
|
containerView.measure(isPortrait ? MeasureSpec.makeMeasureSpec(width + left * 2, MeasureSpec.EXACTLY) : MeasureSpec.makeMeasureSpec((int) Math.max(width * 0.8f, maxWidth) + left * 2, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
containerView.measure(MeasureSpec.makeMeasureSpec(width + left * 2, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
|
|
|
|
}
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
int childCount = getChildCount();
|
|
|
|
for (int i = 0; i < childCount; i++) {
|
|
|
|
View child = getChildAt(i);
|
|
|
|
if (child.getVisibility() == GONE || child == containerView) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
if (lastInsets != null && Build.VERSION.SDK_INT >= 21) {
|
|
|
|
WindowInsets wi = (WindowInsets) lastInsets;
|
|
|
|
wi = wi.replaceSystemWindowInsets(wi.getSystemWindowInsetLeft(), wi.getSystemWindowInsetTop(), 0, wi.getSystemWindowInsetBottom());
|
|
|
|
child.dispatchApplyWindowInsets(wi);
|
|
|
|
}
|
|
|
|
measureChildWithMargins(child, MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), 0, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY), 0);
|
2015-08-13 11:23:31 +02:00
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
if (containerView != null) {
|
|
|
|
int l = ((right - left) - containerView.getMeasuredWidth()) / 2;
|
|
|
|
int t = (bottom - top) - containerView.getMeasuredHeight();
|
|
|
|
containerView.layout(l, t, l + containerView.getMeasuredWidth(), t + getMeasuredHeight());
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
|
|
|
|
final int count = getChildCount();
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
final View child = getChildAt(i);
|
|
|
|
if (child.getVisibility() == GONE || child == containerView) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-12-09 19:27:52 +01:00
|
|
|
final FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) child.getLayoutParams();
|
2015-08-13 11:23:31 +02:00
|
|
|
|
|
|
|
final int width = child.getMeasuredWidth();
|
|
|
|
final int height = child.getMeasuredHeight();
|
|
|
|
|
|
|
|
int childLeft;
|
|
|
|
int childTop;
|
|
|
|
|
|
|
|
int gravity = lp.gravity;
|
|
|
|
if (gravity == -1) {
|
|
|
|
gravity = Gravity.TOP | Gravity.LEFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
child.layout(childLeft, childTop, childLeft + width, childTop + height);
|
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
}
|
|
|
|
};
|
2015-05-21 23:27:27 +02:00
|
|
|
container.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
dismiss();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2015-06-29 19:12:11 +02:00
|
|
|
container.setBackgroundDrawable(backgroundDrawable);
|
2015-11-26 22:04:02 +01:00
|
|
|
focusable = needFocus;
|
|
|
|
if (Build.VERSION.SDK_INT >= 21 && !focusable) {
|
2015-10-29 18:10:07 +01:00
|
|
|
container.setFitsSystemWindows(true);
|
2015-11-26 22:04:02 +01:00
|
|
|
container.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
|
|
|
|
@SuppressLint("NewApi")
|
|
|
|
@Override
|
|
|
|
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
|
|
|
|
lastInsets = insets;
|
|
|
|
container.requestLayout();
|
|
|
|
return insets.consumeSystemWindowInsets();
|
|
|
|
}
|
|
|
|
});
|
2015-10-29 18:10:07 +01:00
|
|
|
container.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
Window window = getWindow();
|
|
|
|
window.setBackgroundDrawableResource(R.drawable.transparent);
|
|
|
|
window.requestFeature(Window.FEATURE_NO_TITLE);
|
2015-06-29 19:12:11 +02:00
|
|
|
window.setWindowAnimations(R.style.DialogNoAnimation);
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
if (shadowDrawable == null) {
|
|
|
|
Rect padding = new Rect();
|
|
|
|
shadowDrawable = getContext().getResources().getDrawable(R.drawable.sheet_shadow);
|
|
|
|
shadowDrawable.getPadding(padding);
|
|
|
|
backgroundPaddingLeft = padding.left;
|
|
|
|
backgroundPaddingTop = padding.top;
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
setContentView(container, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
|
|
|
|
|
|
|
ciclePaint.setColor(0xffffffff);
|
|
|
|
|
|
|
|
containerView = new LinearLayout(getContext()) {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
|
if (useRevealAnimation && Build.VERSION.SDK_INT <= 19) {
|
|
|
|
canvas.drawCircle(revealX, revealY, revealRadius, ciclePaint);
|
|
|
|
//shadowDrawable.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
|
|
|
|
//shadowDrawable.draw(canvas);
|
|
|
|
}
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
@Override
|
|
|
|
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
|
|
|
|
return super.drawChild(canvas, child, drawingTime);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
containerView.setWillNotDraw(false);
|
2015-05-21 23:27:27 +02:00
|
|
|
containerView.setOrientation(LinearLayout.VERTICAL);
|
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
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
if (title != null) {
|
|
|
|
TextView titleView = new TextView(getContext());
|
|
|
|
titleView.setLines(1);
|
|
|
|
titleView.setSingleLine(true);
|
|
|
|
titleView.setText(title);
|
|
|
|
titleView.setTextColor(0xff757575);
|
|
|
|
titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
2016-03-06 02:49:31 +01:00
|
|
|
titleView.setEllipsize(TextUtils.TruncateAt.MIDDLE);
|
2015-06-29 19:12:11 +02:00
|
|
|
titleView.setPadding(AndroidUtilities.dp(16), 0, AndroidUtilities.dp(16), AndroidUtilities.dp(8));
|
|
|
|
titleView.setGravity(Gravity.CENTER_VERTICAL);
|
|
|
|
containerView.addView(titleView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
|
|
|
|
titleView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (customView != null) {
|
|
|
|
if (customView.getParent() != null) {
|
|
|
|
ViewGroup viewGroup = (ViewGroup) customView.getParent();
|
|
|
|
viewGroup.removeView(customView);
|
|
|
|
}
|
|
|
|
containerView.addView(customView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
if (items != null) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (customView != null) {
|
|
|
|
FrameLayout frameLayout = new FrameLayout(getContext());
|
|
|
|
frameLayout.setPadding(0, AndroidUtilities.dp(8), 0, 0);
|
|
|
|
containerView.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 16));
|
|
|
|
|
|
|
|
View lineView = new View(getContext());
|
|
|
|
lineView.setBackgroundColor(0xffd2d2d2);
|
|
|
|
frameLayout.addView(lineView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));
|
|
|
|
}
|
|
|
|
FrameLayout rowLayout = null;
|
|
|
|
int lastRowLayoutNum = 0;
|
2015-05-21 23:27:27 +02:00
|
|
|
for (int a = 0; a < items.length; a++) {
|
2015-12-09 19:27:52 +01:00
|
|
|
BottomSheetCell cell = new BottomSheetCell(getContext(), isGrid ? 1 : 0);
|
2015-06-29 19:12:11 +02:00
|
|
|
cell.setTextAndIcon(items[a], itemIcons != null ? itemIcons[a] : 0);
|
|
|
|
if (isGrid) {
|
|
|
|
int row = a / 3;
|
|
|
|
if (rowLayout == null || lastRowLayoutNum != row) {
|
|
|
|
rowLayout = new FrameLayout(getContext());
|
|
|
|
lastRowLayoutNum = row;
|
|
|
|
containerView.addView(rowLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 80, 0, lastRowLayoutNum != 0 ? 8 : 0, 0, 0));
|
|
|
|
rowLayout.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
int col = a % 3;
|
|
|
|
int gravity;
|
|
|
|
if (col == 0) {
|
|
|
|
gravity = Gravity.LEFT | Gravity.TOP;
|
|
|
|
} else if (col == 1) {
|
|
|
|
gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
|
|
|
|
} else {
|
|
|
|
gravity = Gravity.RIGHT | Gravity.TOP;
|
|
|
|
}
|
|
|
|
rowLayout.addView(cell, LayoutHelper.createFrame(96, 80, gravity));
|
|
|
|
} else {
|
|
|
|
containerView.addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
|
|
|
|
}
|
|
|
|
cell.setTag(a);
|
|
|
|
cell.setOnClickListener(new View.OnClickListener() {
|
2015-05-21 23:27:27 +02:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
dismissWithButtonClick((Integer) v.getTag());
|
|
|
|
}
|
|
|
|
});
|
2015-06-29 19:12:11 +02:00
|
|
|
itemViews.add(cell);
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowManager.LayoutParams params = getWindow().getAttributes();
|
|
|
|
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
params.gravity = Gravity.TOP | Gravity.LEFT;
|
2015-11-26 22:04:02 +01:00
|
|
|
if (!focusable) {
|
|
|
|
params.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
|
|
|
|
params.dimAmount = 0;
|
|
|
|
params.flags &= ~WindowManager.LayoutParams.FLAG_DIM_BEHIND;
|
|
|
|
} else {
|
|
|
|
params.dimAmount = 0.2f;
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
if (Build.VERSION.SDK_INT < 21) {
|
|
|
|
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
getWindow().setAttributes(params);
|
2015-07-22 20:56:37 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
|
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;
|
|
|
|
if (Build.VERSION.SDK_INT >= 21 || !useRevealAnimation) {
|
|
|
|
containerView.setBackgroundDrawable(shadowDrawable);
|
|
|
|
} else {
|
|
|
|
containerView.setBackgroundDrawable(null);
|
|
|
|
}
|
|
|
|
int left = useRevealAnimation && Build.VERSION.SDK_INT <= 19 ? 0 : backgroundPaddingLeft;
|
|
|
|
int top = useRevealAnimation && Build.VERSION.SDK_INT <= 19 ? 0 : backgroundPaddingTop;
|
|
|
|
containerView.setPadding(left, (applyTopPaddings ? AndroidUtilities.dp(8) : 0) + top, left, (applyTopPaddings ? AndroidUtilities.dp(isGrid ? 16 : 8) : 0));
|
2015-08-13 11:23:31 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
startOpenAnimation();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2015-07-22 20:56:37 +02:00
|
|
|
startOpenAnimation();
|
|
|
|
}
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
protected void setRevealRadius(float radius) {
|
|
|
|
revealRadius = radius;
|
|
|
|
delegate.onRevealAnimationProgress(!dismissed, radius, revealX, revealY);
|
|
|
|
if (Build.VERSION.SDK_INT <= 19) {
|
|
|
|
containerView.invalidate();
|
|
|
|
}
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
protected float getRevealRadius() {
|
|
|
|
return revealRadius;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
@SuppressLint("NewApi")
|
|
|
|
private void startRevealAnimation(final boolean open) {
|
|
|
|
if (open) {
|
|
|
|
backgroundDrawable.setAlpha(0);
|
|
|
|
containerView.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
backgroundDrawable.setAlpha(51);
|
|
|
|
}
|
|
|
|
ViewProxy.setTranslationY(containerView, 0);
|
|
|
|
|
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
|
|
|
|
|
|
|
View view = delegate.getRevealView();
|
|
|
|
if (view.getVisibility() == View.VISIBLE && ((ViewGroup) view.getParent()).getVisibility() == View.VISIBLE) {
|
|
|
|
final int coords[] = new int[2];
|
|
|
|
view.getLocationInWindow(coords);
|
|
|
|
float top;
|
|
|
|
if (Build.VERSION.SDK_INT <= 19) {
|
|
|
|
top = AndroidUtilities.displaySize.y - containerView.getMeasuredHeight() - AndroidUtilities.statusBarHeight;
|
|
|
|
} else {
|
|
|
|
top = containerView.getY();
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
revealX = coords[0] + view.getMeasuredWidth() / 2;
|
|
|
|
revealY = (int) (coords[1] + view.getMeasuredHeight() / 2 - top);
|
|
|
|
if (Build.VERSION.SDK_INT <= 19) {
|
|
|
|
revealY -= AndroidUtilities.statusBarHeight;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
revealX = AndroidUtilities.displaySize.x / 2 + backgroundPaddingLeft;
|
|
|
|
revealY = (int) (AndroidUtilities.displaySize.y - containerView.getY());
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
int corners[][] = new int[][]{
|
|
|
|
{0, 0},
|
|
|
|
{0, containerView.getMeasuredHeight()},
|
|
|
|
{containerView.getMeasuredWidth(), 0},
|
|
|
|
{containerView.getMeasuredWidth(), containerView.getMeasuredHeight()}
|
|
|
|
};
|
|
|
|
int finalRevealRadius = 0;
|
|
|
|
for (int a = 0; a < 4; a++) {
|
|
|
|
finalRevealRadius = Math.max(finalRevealRadius, (int) Math.ceil(Math.sqrt((revealX - corners[a][0]) * (revealX - corners[a][0]) + (revealY - corners[a][1]) * (revealY - corners[a][1]))));
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayList<Animator> animators = new ArrayList<>(3);
|
|
|
|
animators.add(ObjectAnimator.ofFloat(this, "revealRadius", open ? 0 : finalRevealRadius, open ? finalRevealRadius : 0));
|
|
|
|
animators.add(ObjectAnimator.ofInt(backgroundDrawable, "alpha", open ? 51 : 0));
|
|
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
|
|
containerView.setElevation(AndroidUtilities.dp(10));
|
2015-08-13 11:23:31 +02:00
|
|
|
try {
|
|
|
|
animators.add(ViewAnimationUtils.createCircularReveal(containerView, revealX <= containerView.getMeasuredWidth() ? revealX : containerView.getMeasuredWidth(), revealY, open ? 0 : finalRevealRadius, open ? finalRevealRadius : 0));
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
animatorSet.setDuration(300);
|
|
|
|
} else {
|
|
|
|
if (!open) {
|
|
|
|
animatorSet.setDuration(200);
|
|
|
|
containerView.setPivotX(revealX <= containerView.getMeasuredWidth() ? revealX : containerView.getMeasuredWidth());
|
|
|
|
containerView.setPivotY(revealY);
|
|
|
|
animators.add(ObjectAnimator.ofFloat(containerView, "scaleX", 0.0f));
|
|
|
|
animators.add(ObjectAnimator.ofFloat(containerView, "scaleY", 0.0f));
|
|
|
|
animators.add(ObjectAnimator.ofFloat(containerView, "alpha", 0.0f));
|
|
|
|
} else {
|
|
|
|
animatorSet.setDuration(250);
|
|
|
|
containerView.setScaleX(1);
|
|
|
|
containerView.setScaleY(1);
|
|
|
|
containerView.setAlpha(1);
|
|
|
|
if (Build.VERSION.SDK_INT <= 19) {
|
|
|
|
animatorSet.setStartDelay(20);
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
animatorSet.playTogether(animators);
|
|
|
|
animatorSet.addListener(new AnimatorListenerAdapter() {
|
2015-06-29 19:12:11 +02:00
|
|
|
@Override
|
2015-07-22 20:56:37 +02:00
|
|
|
public void onAnimationStart(Animator animation) {
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.onRevealAnimationStart(open);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.onRevealAnimationEnd(open);
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
containerView.invalidate();
|
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
|
|
|
container.setLayerType(View.LAYER_TYPE_NONE, null);
|
|
|
|
}
|
|
|
|
if (!open) {
|
|
|
|
containerView.setVisibility(View.INVISIBLE);
|
|
|
|
try {
|
|
|
|
BottomSheet.super.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
});
|
2015-07-22 20:56:37 +02:00
|
|
|
animatorSet.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void startOpenAnimation() {
|
|
|
|
if (Build.VERSION.SDK_INT >= 20) {
|
|
|
|
container.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
|
|
|
}
|
|
|
|
if (containerView.getMeasuredHeight() == 0) {
|
|
|
|
containerView.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.displaySize.x, View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.displaySize.y, View.MeasureSpec.AT_MOST));
|
|
|
|
}
|
|
|
|
if (useRevealAnimation) {
|
|
|
|
startRevealAnimation(true);
|
|
|
|
} else {
|
|
|
|
ViewProxy.setTranslationY(containerView, containerView.getMeasuredHeight());
|
|
|
|
backgroundDrawable.setAlpha(0);
|
|
|
|
AnimatorSetProxy animatorSetProxy = new AnimatorSetProxy();
|
|
|
|
animatorSetProxy.playTogether(
|
|
|
|
ObjectAnimatorProxy.ofFloat(containerView, "translationY", 0),
|
2015-11-26 22:04:02 +01:00
|
|
|
ObjectAnimatorProxy.ofInt(backgroundDrawable, "alpha", focusable ? 0 : 51));
|
2015-07-22 20:56:37 +02:00
|
|
|
animatorSetProxy.setDuration(200);
|
|
|
|
animatorSetProxy.setStartDelay(20);
|
|
|
|
animatorSetProxy.setInterpolator(new DecelerateInterpolator());
|
|
|
|
animatorSetProxy.addListener(new AnimatorListenerAdapterProxy() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Object animation) {
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.onOpenAnimationEnd();
|
|
|
|
}
|
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
|
|
|
container.setLayerType(View.LAYER_TYPE_NONE, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
animatorSetProxy.start();
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setDelegate(BottomSheetDelegate delegate) {
|
|
|
|
this.delegate = delegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public FrameLayout getContainer() {
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
|
|
|
public LinearLayout 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setItemText(int item, CharSequence text) {
|
|
|
|
if (item < 0 || item >= itemViews.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
BottomSheetCell cell = itemViews.get(item);
|
|
|
|
cell.textView.setText(text);
|
|
|
|
}
|
|
|
|
|
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;
|
2015-05-21 23:27:27 +02:00
|
|
|
AnimatorSetProxy animatorSetProxy = new AnimatorSetProxy();
|
|
|
|
animatorSetProxy.playTogether(
|
2015-07-22 20:56:37 +02:00
|
|
|
ObjectAnimatorProxy.ofFloat(containerView, "translationY", containerView.getMeasuredHeight() + AndroidUtilities.dp(10)),
|
2015-06-29 19:12:11 +02:00
|
|
|
ObjectAnimatorProxy.ofInt(backgroundDrawable, "alpha", 0)
|
2015-05-21 23:27:27 +02:00
|
|
|
);
|
|
|
|
animatorSetProxy.setDuration(180);
|
|
|
|
animatorSetProxy.setInterpolator(new AccelerateInterpolator());
|
|
|
|
animatorSetProxy.addListener(new AnimatorListenerAdapterProxy() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Object animation) {
|
|
|
|
if (onClickListener != null) {
|
|
|
|
onClickListener.onClick(BottomSheet.this, item);
|
|
|
|
}
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
BottomSheet.super.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
animatorSetProxy.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void dismiss() {
|
|
|
|
if (dismissed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dismissed = true;
|
2015-07-22 20:56:37 +02:00
|
|
|
if (useRevealAnimation) {
|
|
|
|
startRevealAnimation(false);
|
|
|
|
} else {
|
|
|
|
AnimatorSetProxy animatorSetProxy = new AnimatorSetProxy();
|
|
|
|
animatorSetProxy.playTogether(
|
|
|
|
ObjectAnimatorProxy.ofFloat(containerView, "translationY", containerView.getMeasuredHeight() + AndroidUtilities.dp(10)),
|
|
|
|
ObjectAnimatorProxy.ofInt(backgroundDrawable, "alpha", 0)
|
|
|
|
);
|
|
|
|
animatorSetProxy.setDuration(180);
|
|
|
|
animatorSetProxy.setInterpolator(new AccelerateInterpolator());
|
|
|
|
animatorSetProxy.addListener(new AnimatorListenerAdapterProxy() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Object animation) {
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
BottomSheet.super.dismiss();
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
animatorSetProxy.start();
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static class Builder {
|
|
|
|
|
|
|
|
private BottomSheet bottomSheet;
|
|
|
|
|
|
|
|
public Builder(Context context) {
|
2015-11-26 22:04:02 +01:00
|
|
|
bottomSheet = new BottomSheet(context, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Builder(Context context, boolean needFocus) {
|
|
|
|
bottomSheet = new BottomSheet(context, needFocus);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
public Builder setUseRevealAnimation() {
|
|
|
|
if (Build.VERSION.SDK_INT >= 18 && !AndroidUtilities.isTablet()) {
|
|
|
|
bottomSheet.useRevealAnimation = true;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Builder setDelegate(BottomSheetDelegate delegate) {
|
|
|
|
bottomSheet.setDelegate(delegate);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Builder setIsGrid(boolean value) {
|
|
|
|
bottomSheet.isGrid = value;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
public Builder setApplyTopPaddings(boolean value) {
|
|
|
|
bottomSheet.applyTopPaddings = value;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public BottomSheet setUseFullWidth(boolean value) {
|
|
|
|
bottomSheet.fullWidth = value;
|
2015-05-21 23:27:27 +02:00
|
|
|
return bottomSheet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|