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

1663 lines
68 KiB
Java
Raw Normal View History

/*
2019-01-23 18:03:33 +01:00
* This is the source code of Telegram for Android v. 5.x.x.
* 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.
*/
2014-11-13 21:10:14 +01:00
package org.telegram.ui.ActionBar;
import android.animation.Animator;
2017-03-31 01:58:05 +02:00
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
2021-01-01 05:38:45 +01:00
import android.app.Activity;
import android.content.Context;
2014-11-11 23:16:17 +01:00
import android.content.res.Configuration;
2018-07-30 04:07:02 +02:00
import android.graphics.Canvas;
2022-03-11 17:49:54 +01:00
import android.graphics.Color;
2018-07-30 04:07:02 +02:00
import android.graphics.Paint;
2017-03-31 01:58:05 +02:00
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
2018-07-30 04:07:02 +02:00
import android.graphics.Rect;
import android.graphics.RectF;
2014-11-11 23:16:17 +01:00
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.Layout;
2020-09-30 15:48:47 +02:00
import android.text.SpannableString;
import android.text.StaticLayout;
2018-07-30 04:07:02 +02:00
import android.text.TextPaint;
2017-03-31 01:58:05 +02:00
import android.text.TextUtils;
2021-07-30 16:49:55 +02:00
import android.transition.ChangeBounds;
import android.transition.Fade;
import android.transition.TransitionManager;
import android.transition.TransitionSet;
import android.transition.TransitionValues;
import android.view.Gravity;
2014-11-11 23:16:17 +01:00
import android.view.MotionEvent;
import android.view.View;
2020-09-30 15:48:47 +02:00
import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
import android.widget.FrameLayout;
2014-11-11 23:16:17 +01:00
import android.widget.ImageView;
2022-03-11 17:49:54 +01:00
import androidx.core.graphics.ColorUtils;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.AndroidUtilities;
2018-07-30 04:07:02 +02:00
import org.telegram.messenger.LocaleController;
2022-03-11 17:49:54 +01:00
import org.telegram.messenger.NotificationCenter;
2019-05-14 14:08:05 +02:00
import org.telegram.messenger.R;
2021-01-01 05:38:45 +01:00
import org.telegram.messenger.SharedConfig;
2020-09-30 15:48:47 +02:00
import org.telegram.ui.Adapters.FiltersView;
2021-07-30 16:49:55 +02:00
import org.telegram.ui.Components.CubicBezierInterpolator;
2020-09-30 15:48:47 +02:00
import org.telegram.ui.Components.EllipsizeSpanAnimator;
2018-07-30 04:07:02 +02:00
import org.telegram.ui.Components.FireworksEffect;
import org.telegram.ui.Components.LayoutHelper;
2022-01-18 21:51:58 +01:00
import org.telegram.ui.Components.SizeNotifierFrameLayout;
2018-07-30 04:07:02 +02:00
import org.telegram.ui.Components.SnowflakesEffect;
2015-10-29 18:10:07 +01:00
import java.util.ArrayList;
2022-01-17 08:45:37 +01:00
import tw.nekomimi.nekogram.NekoConfig;
2019-12-30 14:00:42 +01:00
public class ActionBar extends FrameLayout {
2014-11-11 23:16:17 +01:00
public static class ActionBarMenuOnItemClick {
public void onItemClick(int id) {
}
public boolean canOpenMenu() {
return true;
}
}
private UnreadImageView backButtonImageView;
2020-09-30 15:48:47 +02:00
private SimpleTextView[] titleTextView = new SimpleTextView[2];
2016-04-22 15:49:00 +02:00
private SimpleTextView subtitleTextView;
2021-06-25 02:43:10 +02:00
private SimpleTextView additionalSubtitleTextView;
2014-11-24 15:14:40 +01:00
private View actionModeTop;
2021-01-01 05:38:45 +01:00
private int actionModeColor;
private int actionBarColor;
2014-11-11 23:16:17 +01:00
private ActionBarMenu menu;
private ActionBarMenu actionMode;
2020-09-30 15:48:47 +02:00
private String actionModeTag;
2019-05-14 14:08:05 +02:00
private boolean ignoreLayoutRequest;
2014-11-17 03:44:57 +01:00
private boolean occupyStatusBar = Build.VERSION.SDK_INT >= 21;
2015-10-29 18:10:07 +01:00
private boolean actionModeVisible;
private boolean addToContainer = true;
2019-01-23 18:03:33 +01:00
private boolean clipContent;
2016-04-22 15:49:00 +02:00
private boolean interceptTouches = true;
private int extraHeight;
private AnimatorSet actionModeAnimation;
2019-05-14 14:08:05 +02:00
private View actionModeExtraView;
private View actionModeTranslationView;
private View actionModeShowingView;
private View[] actionModeHidingViews;
2014-11-13 21:10:14 +01:00
2018-07-30 04:07:02 +02:00
private boolean supportsHolidayImage;
private SnowflakesEffect snowflakesEffect;
private FireworksEffect fireworksEffect;
private Paint.FontMetricsInt fontMetricsInt;
private boolean manualStart;
private Rect rect;
private int titleRightMargin;
2014-11-18 06:01:04 +01:00
private boolean allowOverlayTitle;
private CharSequence lastTitle;
2020-09-30 15:48:47 +02:00
private CharSequence lastOverlayTitle;
private Object[] overlayTitleToSet = new Object[3];
2018-07-30 04:07:02 +02:00
private Runnable lastRunnable;
private boolean titleOverlayShown;
2017-07-08 18:32:04 +02:00
private Runnable titleActionRunnable;
2015-02-01 19:51:02 +01:00
private boolean castShadows = true;
2014-11-18 06:01:04 +01:00
2014-11-11 23:16:17 +01:00
protected boolean isSearchFieldVisible;
2016-04-22 15:49:00 +02:00
protected int itemsBackgroundColor;
2017-03-31 01:58:05 +02:00
protected int itemsActionModeBackgroundColor;
protected int itemsColor;
protected int itemsActionModeColor;
private boolean isBackOverlayVisible;
2014-11-11 23:16:17 +01:00
protected BaseFragment parentFragment;
public ActionBarMenuOnItemClick actionBarMenuOnItemClick;
2020-09-30 15:48:47 +02:00
private int titleColorToSet = 0;
2020-09-30 18:55:35 +02:00
private boolean overlayTitleAnimation;
2020-09-30 15:48:47 +02:00
private boolean titleAnimationRunning;
private boolean fromBottom;
2021-07-30 16:49:55 +02:00
private boolean centerScale;
private CharSequence subtitle;
2020-09-30 15:48:47 +02:00
2021-09-20 00:10:42 +02:00
private View.OnTouchListener interceptTouchEventListener;
private final Theme.ResourcesProvider resourcesProvider;
2020-09-30 15:48:47 +02:00
EllipsizeSpanAnimator ellipsizeSpanAnimator = new EllipsizeSpanAnimator(this);
public ActionBar(Context context) {
2021-09-20 00:10:42 +02:00
this(context, null);
}
public ActionBar(Context context, Theme.ResourcesProvider resourcesProvider) {
super(context);
2021-09-20 00:10:42 +02:00
this.resourcesProvider = resourcesProvider;
2018-08-27 10:33:11 +02:00
setOnClickListener(v -> {
2019-05-14 14:08:05 +02:00
if (isSearchFieldVisible()) {
return;
}
2018-08-27 10:33:11 +02:00
if (titleActionRunnable != null) {
titleActionRunnable.run();
2017-07-08 18:32:04 +02:00
}
});
}
2014-11-13 21:10:14 +01:00
private void createBackButtonImage() {
if (backButtonImageView != null) {
return;
}
backButtonImageView = new UnreadImageView(getContext());
2014-11-13 21:10:14 +01:00
backButtonImageView.setScaleType(ImageView.ScaleType.CENTER);
2017-03-31 01:58:05 +02:00
backButtonImageView.setBackgroundDrawable(Theme.createSelectorDrawable(itemsBackgroundColor));
if (itemsColor != 0) {
2020-06-25 17:12:58 +02:00
backButtonImageView.setColorFilter(new PorterDuffColorFilter(itemsColor, PorterDuff.Mode.SRC_IN));
2017-03-31 01:58:05 +02:00
}
2015-10-29 18:10:07 +01:00
backButtonImageView.setPadding(AndroidUtilities.dp(1), 0, 0, 0);
2015-07-22 20:56:37 +02:00
addView(backButtonImageView, LayoutHelper.createFrame(54, 54, Gravity.LEFT | Gravity.TOP));
2018-08-27 10:33:11 +02:00
backButtonImageView.setOnClickListener(v -> {
if (!actionModeVisible && isSearchFieldVisible) {
closeSearchField();
return;
}
if (actionBarMenuOnItemClick != null) {
actionBarMenuOnItemClick.onItemClick(-1);
2014-11-13 21:10:14 +01:00
}
});
2019-05-14 14:08:05 +02:00
backButtonImageView.setContentDescription(LocaleController.getString("AccDescrGoBack", R.string.AccDescrGoBack));
2014-11-13 21:10:14 +01:00
}
2014-11-11 23:16:17 +01:00
public void setBackButtonDrawable(Drawable drawable) {
2014-11-13 21:10:14 +01:00
if (backButtonImageView == null) {
createBackButtonImage();
}
2015-04-09 20:00:14 +02:00
backButtonImageView.setVisibility(drawable == null ? GONE : VISIBLE);
2014-11-11 23:16:17 +01:00
backButtonImageView.setImageDrawable(drawable);
2015-10-29 18:10:07 +01:00
if (drawable instanceof BackDrawable) {
2017-03-31 01:58:05 +02:00
BackDrawable backDrawable = (BackDrawable) drawable;
backDrawable.setRotation(isActionModeShowed() ? 1 : 0, false);
backDrawable.setRotatedColor(itemsActionModeColor);
backDrawable.setColor(itemsColor);
2021-06-25 02:43:10 +02:00
} else if (drawable instanceof MenuDrawable) {
MenuDrawable menuDrawable = (MenuDrawable) drawable;
menuDrawable.setBackColor(actionBarColor);
menuDrawable.setIconColor(itemsColor);
2015-10-29 18:10:07 +01:00
}
}
2019-05-14 14:08:05 +02:00
public void setBackButtonContentDescription(CharSequence description) {
if (backButtonImageView != null) {
backButtonImageView.setContentDescription(description);
}
}
2018-07-30 04:07:02 +02:00
public void setSupportsHolidayImage(boolean value) {
supportsHolidayImage = value;
if (supportsHolidayImage) {
fontMetricsInt = new Paint.FontMetricsInt();
rect = new Rect();
}
invalidate();
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (supportsHolidayImage && !titleOverlayShown && !LocaleController.isRTL && ev.getAction() == MotionEvent.ACTION_DOWN) {
Drawable drawable = Theme.getCurrentHolidayDrawable();
if (drawable != null && drawable.getBounds().contains((int) ev.getX(), (int) ev.getY())) {
manualStart = true;
2021-04-14 03:05:02 +02:00
if (snowflakesEffect == null) {
2021-01-07 10:47:52 +01:00
fireworksEffect = null;
2021-12-30 11:52:40 +01:00
snowflakesEffect = new SnowflakesEffect(0);
2021-04-14 03:05:02 +02:00
titleTextView[0].invalidate();
invalidate();
} else {
snowflakesEffect = null;
fireworksEffect = new FireworksEffect();
titleTextView[0].invalidate();
invalidate();
2018-07-30 04:07:02 +02:00
}
}
}
2021-09-20 00:10:42 +02:00
return interceptTouchEventListener != null && interceptTouchEventListener.onTouch(this, ev) || super.onInterceptTouchEvent(ev);
2018-07-30 04:07:02 +02:00
}
2020-03-30 14:00:09 +02:00
protected boolean shouldClipChild(View child) {
2021-06-25 02:43:10 +02:00
return clipContent && (child == titleTextView[0] || child == titleTextView[1] || child == subtitleTextView || child == menu || child == backButtonImageView || child == additionalSubtitleTextView);
2020-03-30 14:00:09 +02:00
}
2018-07-30 04:07:02 +02:00
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
2020-03-30 14:00:09 +02:00
boolean clip = shouldClipChild(child);
2019-01-23 18:03:33 +01:00
if (clip) {
canvas.save();
canvas.clipRect(0, -getTranslationY() + (occupyStatusBar ? AndroidUtilities.statusBarHeight : 0), getMeasuredWidth(), getMeasuredHeight());
}
2018-07-30 04:07:02 +02:00
boolean result = super.drawChild(canvas, child, drawingTime);
2021-01-01 05:38:45 +01:00
if (supportsHolidayImage && !titleOverlayShown && !LocaleController.isRTL && (child == titleTextView[0] || child == titleTextView[1])) {
2018-07-30 04:07:02 +02:00
Drawable drawable = Theme.getCurrentHolidayDrawable();
if (drawable != null) {
2021-01-01 05:38:45 +01:00
SimpleTextView titleView = (SimpleTextView) child;
2021-04-14 03:05:02 +02:00
if (titleView.getVisibility() == View.VISIBLE) {
2021-01-01 05:38:45 +01:00
TextPaint textPaint = titleView.getTextPaint();
textPaint.getFontMetricsInt(fontMetricsInt);
2021-04-14 03:05:02 +02:00
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
textPaint.getTextBounds(titleView.getText(), 0, 1, rect);
} else {
textPaint.getTextBounds(titleView.getText().toString(), 0, 1, rect);
}
2021-01-01 05:38:45 +01:00
int x = titleView.getTextStartX() + Theme.getCurrentHolidayDrawableXOffset() + (rect.width() - (drawable.getIntrinsicWidth() + Theme.getCurrentHolidayDrawableXOffset())) / 2;
int y = titleView.getTextStartY() + Theme.getCurrentHolidayDrawableYOffset() + (int) Math.ceil((titleView.getTextHeight() - rect.height()) / 2.0f);
drawable.setBounds(x, y - drawable.getIntrinsicHeight(), x + drawable.getIntrinsicWidth(), y);
drawable.setAlpha((int) (255 * titleView.getAlpha()));
2022-03-27 14:10:22 +02:00
drawable.setColorFilter(textPaint.getColor(), PorterDuff.Mode.MULTIPLY);
2021-01-01 05:38:45 +01:00
drawable.draw(canvas);
if (overlayTitleAnimationInProgress) {
child.invalidate();
invalidate();
}
}
2021-01-07 10:47:52 +01:00
}
2022-01-17 08:45:37 +01:00
if (NekoConfig.actionBarDecoration.Int() == 2) {
2021-01-07 10:47:52 +01:00
if (fireworksEffect == null) {
fireworksEffect = new FireworksEffect();
}
2022-01-17 08:45:37 +01:00
} else if (NekoConfig.actionBarDecoration.Int() == 1 || Theme.canStartHolidayAnimation()) {
2021-01-07 10:47:52 +01:00
if (snowflakesEffect == null) {
2021-12-31 19:10:02 +01:00
snowflakesEffect = new SnowflakesEffect(0);
2018-07-30 04:07:02 +02:00
}
2021-01-07 10:47:52 +01:00
} else if (!manualStart) {
2018-07-30 04:07:02 +02:00
if (snowflakesEffect != null) {
2021-01-07 10:47:52 +01:00
snowflakesEffect = null;
2018-07-30 04:07:02 +02:00
}
2021-01-07 10:47:52 +01:00
if (fireworksEffect != null) {
fireworksEffect = null;
}
}
if (snowflakesEffect != null) {
snowflakesEffect.onDraw(this, canvas);
} else if (fireworksEffect != null) {
fireworksEffect.onDraw(this, canvas);
2018-07-30 04:07:02 +02:00
}
}
2019-01-23 18:03:33 +01:00
if (clip) {
canvas.restore();
}
2018-07-30 04:07:02 +02:00
return result;
}
2019-01-23 18:03:33 +01:00
@Override
public void setTranslationY(float translationY) {
super.setTranslationY(translationY);
if (clipContent) {
invalidate();
}
}
2014-11-11 23:16:17 +01:00
public void setBackButtonImage(int resource) {
2014-11-13 21:10:14 +01:00
if (backButtonImageView == null) {
createBackButtonImage();
}
2015-04-09 20:00:14 +02:00
backButtonImageView.setVisibility(resource == 0 ? GONE : VISIBLE);
2014-11-11 23:16:17 +01:00
backButtonImageView.setImageResource(resource);
}
2016-10-11 13:57:01 +02:00
private void createSubtitleTextView() {
2016-04-22 15:49:00 +02:00
if (subtitleTextView != null) {
return;
}
2016-04-22 15:49:00 +02:00
subtitleTextView = new SimpleTextView(getContext());
subtitleTextView.setGravity(Gravity.LEFT);
2017-03-31 01:58:05 +02:00
subtitleTextView.setVisibility(GONE);
2021-09-20 00:10:42 +02:00
subtitleTextView.setTextColor(getThemedColor(Theme.key_actionBarDefaultSubtitle));
2016-04-22 15:49:00 +02:00
addView(subtitleTextView, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
2015-10-29 18:10:07 +01:00
}
2021-06-25 02:43:10 +02:00
public void createAdditionalSubtitleTextView() {
if (additionalSubtitleTextView != null) {
return;
}
additionalSubtitleTextView = new SimpleTextView(getContext());
additionalSubtitleTextView.setGravity(Gravity.LEFT);
additionalSubtitleTextView.setVisibility(GONE);
2021-09-20 00:10:42 +02:00
additionalSubtitleTextView.setTextColor(getThemedColor(Theme.key_actionBarDefaultSubtitle));
2021-06-25 02:43:10 +02:00
addView(additionalSubtitleTextView, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
}
public SimpleTextView getAdditionalSubtitleTextView() {
return additionalSubtitleTextView;
}
2015-10-29 18:10:07 +01:00
public void setAddToContainer(boolean value) {
addToContainer = value;
}
2020-02-13 19:26:53 +01:00
public boolean shouldAddToContainer() {
2015-10-29 18:10:07 +01:00
return addToContainer;
2014-11-11 23:16:17 +01:00
}
2019-01-23 18:03:33 +01:00
public void setClipContent(boolean value) {
clipContent = value;
}
2014-11-11 23:16:17 +01:00
public void setSubtitle(CharSequence value) {
2016-04-22 15:49:00 +02:00
if (value != null && subtitleTextView == null) {
2016-10-11 13:57:01 +02:00
createSubtitleTextView();
2014-11-11 23:16:17 +01:00
}
2016-04-22 15:49:00 +02:00
if (subtitleTextView != null) {
2021-07-30 16:49:55 +02:00
boolean isEmpty = TextUtils.isEmpty(value);
subtitleTextView.setVisibility(!isEmpty && !isSearchFieldVisible ? VISIBLE : GONE);
2020-09-30 18:55:35 +02:00
subtitleTextView.setAlpha(1f);
2021-07-30 16:49:55 +02:00
if (!isEmpty) {
subtitleTextView.setText(value);
}
subtitle = value;
}
}
2020-09-30 15:48:47 +02:00
private void createTitleTextView(int i) {
if (titleTextView[i] != null) {
return;
}
2020-09-30 15:48:47 +02:00
titleTextView[i] = new SimpleTextView(getContext());
titleTextView[i].setGravity(Gravity.LEFT);
if (titleColorToSet != 0) {
titleTextView[i].setTextColor(titleColorToSet);
} else {
2021-09-20 00:10:42 +02:00
titleTextView[i].setTextColor(getThemedColor(Theme.key_actionBarDefaultTitle));
2020-09-30 15:48:47 +02:00
}
titleTextView[i].setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
addView(titleTextView[i], 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
2014-11-11 23:16:17 +01:00
}
public void setTitleRightMargin(int value) {
titleRightMargin = value;
}
2014-11-11 23:16:17 +01:00
public void setTitle(CharSequence value) {
2020-09-30 15:48:47 +02:00
if (value != null && titleTextView[0] == null) {
createTitleTextView(0);
2014-11-11 23:16:17 +01:00
}
2020-09-30 15:48:47 +02:00
if (titleTextView[0] != null) {
2014-11-18 06:01:04 +01:00
lastTitle = value;
2020-09-30 15:48:47 +02:00
titleTextView[0].setVisibility(value != null && !isSearchFieldVisible ? VISIBLE : INVISIBLE);
titleTextView[0].setText(value);
}
2020-09-30 18:55:35 +02:00
fromBottom = false;
}
2017-03-31 01:58:05 +02:00
public void setTitleColor(int color) {
2020-09-30 15:48:47 +02:00
if (titleTextView[0] == null) {
createTitleTextView(0);
}
titleColorToSet = color;
titleTextView[0].setTextColor(color);
if (titleTextView[1] != null) {
titleTextView[1].setTextColor(color);
2017-03-31 01:58:05 +02:00
}
}
2016-10-11 13:57:01 +02:00
public void setSubtitleColor(int color) {
if (subtitleTextView == null) {
createSubtitleTextView();
}
subtitleTextView.setTextColor(color);
}
2020-09-30 15:48:47 +02:00
public void setTitleScrollNonFitText(boolean b) {
titleTextView[0].setScrollNonFitText(b);
}
2019-12-31 14:08:08 +01:00
public void setPopupItemsColor(int color, boolean icon, boolean forActionMode) {
if (forActionMode && actionMode != null) {
actionMode.setPopupItemsColor(color, icon);
} else if (!forActionMode && menu != null) {
2019-05-14 14:08:05 +02:00
menu.setPopupItemsColor(color, icon);
2017-03-31 01:58:05 +02:00
}
}
2019-12-31 14:08:08 +01:00
public void setPopupItemsSelectorColor(int color, boolean forActionMode) {
if (forActionMode && actionMode != null) {
actionMode.setPopupItemsSelectorColor(color);
} else if (!forActionMode && menu != null) {
menu.setPopupItemsSelectorColor(color);
}
}
public void setPopupBackgroundColor(int color, boolean forActionMode) {
if (forActionMode && actionMode != null) {
actionMode.redrawPopup(color);
} else if (!forActionMode && menu != null) {
2017-03-31 01:58:05 +02:00
menu.redrawPopup(color);
}
}
2016-04-22 15:49:00 +02:00
public SimpleTextView getSubtitleTextView() {
return subtitleTextView;
2015-07-22 20:56:37 +02:00
}
2016-04-22 15:49:00 +02:00
public SimpleTextView getTitleTextView() {
2020-09-30 15:48:47 +02:00
return titleTextView[0];
2014-11-11 23:16:17 +01:00
}
public String getTitle() {
2020-09-30 15:48:47 +02:00
if (titleTextView[0] == null) {
2014-11-11 23:16:17 +01:00
return null;
}
2020-09-30 15:48:47 +02:00
return titleTextView[0].getText().toString();
}
2016-10-11 13:57:01 +02:00
public String getSubtitle() {
2021-07-30 16:49:55 +02:00
if (subtitleTextView == null || subtitle == null) {
2016-10-11 13:57:01 +02:00
return null;
}
2021-07-30 16:49:55 +02:00
return subtitle.toString();
2016-10-11 13:57:01 +02:00
}
2014-11-11 23:16:17 +01:00
public ActionBarMenu createMenu() {
if (menu != null) {
return menu;
}
menu = new ActionBarMenu(getContext(), this);
2015-10-29 18:10:07 +01:00
addView(menu, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.RIGHT));
2014-11-11 23:16:17 +01:00
return menu;
}
public void setActionBarMenuOnItemClick(ActionBarMenuOnItemClick listener) {
actionBarMenuOnItemClick = listener;
}
2017-12-08 18:35:59 +01:00
public ActionBarMenuOnItemClick getActionBarMenuOnItemClick() {
return actionBarMenuOnItemClick;
}
2020-09-30 15:48:47 +02:00
public ImageView getBackButton() {
2017-03-31 01:58:05 +02:00
return backButtonImageView;
}
2014-11-11 23:16:17 +01:00
public ActionBarMenu createActionMode() {
2020-09-30 15:48:47 +02:00
return createActionMode(true, null);
2018-07-30 04:07:02 +02:00
}
2020-09-30 15:48:47 +02:00
public boolean actionModeIsExist(String tag) {
if (actionMode != null && ((actionModeTag == null && tag == null) || (actionModeTag != null && actionModeTag.equals(tag)))) {
return true;
}
return false;
}
public ActionBarMenu createActionMode(boolean needTop, String tag) {
if (actionModeIsExist(tag)) {
2014-11-11 23:16:17 +01:00
return actionMode;
}
2020-09-30 15:48:47 +02:00
if (actionMode != null) {
removeView(actionMode);
actionMode = null;
}
actionModeTag = tag;
2021-01-30 20:47:24 +01:00
actionMode = new ActionBarMenu(getContext(), this) {
@Override
public void setBackgroundColor(int color) {
2022-02-01 14:00:45 +01:00
actionModeColor = color;
if (!blurredBackground) {
super.setBackgroundColor(actionModeColor);
}
}
@Override
protected void dispatchDraw(Canvas canvas) {
2022-03-11 17:49:54 +01:00
if (blurredBackground && drawBlur) {
2022-02-01 14:00:45 +01:00
rectTmp.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
blurScrimPaint.setColor(actionModeColor);
2022-03-20 21:22:37 +01:00
contentView.drawBlurRect(canvas, 0, rectTmp, blurScrimPaint, true);
2022-02-01 14:00:45 +01:00
}
super.dispatchDraw(canvas);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (contentView != null) {
contentView.blurBehindViews.add(this);
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (contentView != null) {
contentView.blurBehindViews.remove(this);
}
2021-01-30 20:47:24 +01:00
}
};
2017-03-31 01:58:05 +02:00
actionMode.isActionMode = true;
2019-12-31 14:08:08 +01:00
actionMode.setClickable(true);
2021-09-20 00:10:42 +02:00
actionMode.setBackgroundColor(getThemedColor(Theme.key_actionBarActionModeDefault));
2015-10-29 18:10:07 +01:00
addView(actionMode, indexOfChild(backButtonImageView));
2014-11-17 03:44:57 +01:00
actionMode.setPadding(0, occupyStatusBar ? AndroidUtilities.statusBarHeight : 0, 0, 0);
2018-07-30 04:07:02 +02:00
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) actionMode.getLayoutParams();
layoutParams.height = LayoutHelper.MATCH_PARENT;
layoutParams.width = LayoutHelper.MATCH_PARENT;
2018-07-30 04:07:02 +02:00
layoutParams.bottomMargin = extraHeight;
2014-11-11 23:16:17 +01:00
layoutParams.gravity = Gravity.RIGHT;
actionMode.setLayoutParams(layoutParams);
2015-04-09 20:00:14 +02:00
actionMode.setVisibility(INVISIBLE);
2014-11-24 15:14:40 +01:00
2022-02-01 14:00:45 +01:00
// if (occupyStatusBar && needTop && actionModeTop == null && !blurredBackground) {
// actionModeTop = new View(getContext());
// actionModeTop.setBackgroundColor(getThemedColor(Theme.key_actionBarActionModeDefaultTop));
// addView(actionModeTop);
// layoutParams = (FrameLayout.LayoutParams) actionModeTop.getLayoutParams();
// layoutParams.height = AndroidUtilities.statusBarHeight;
// layoutParams.width = LayoutHelper.MATCH_PARENT;
// layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
// actionModeTop.setLayoutParams(layoutParams);
// actionModeTop.setVisibility(INVISIBLE);
// }
2014-11-24 15:14:40 +01:00
2014-11-11 23:16:17 +01:00
return actionMode;
}
public void showActionMode() {
2021-02-23 12:53:38 +01:00
showActionMode(true, null, null, null, null, null, 0);
2019-05-14 14:08:05 +02:00
}
2021-02-23 12:53:38 +01:00
public void showActionMode(boolean animated) {
showActionMode(animated, null, null, null, null, null, 0);
2019-05-14 14:08:05 +02:00
}
2021-02-23 22:47:48 +01:00
public void showActionMode(boolean animated, View extraView, View showingView, View[] hidingViews,
2021-01-01 16:23:48 +01:00
boolean[] hideView, View translationView, int translation) {
2015-10-29 18:10:07 +01:00
if (actionMode == null || actionModeVisible) {
return;
}
2015-10-29 18:10:07 +01:00
actionModeVisible = true;
2021-02-23 12:53:38 +01:00
if (animated) {
ArrayList<Animator> animators = new ArrayList<>();
animators.add(ObjectAnimator.ofFloat(actionMode, View.ALPHA, 0.0f, 1.0f));
if (hidingViews != null) {
for (int a = 0; a < hidingViews.length; a++) {
if (hidingViews[a] != null) {
animators.add(ObjectAnimator.ofFloat(hidingViews[a], View.ALPHA, 1.0f, 0.0f));
}
2019-05-14 14:08:05 +02:00
}
}
2021-02-23 12:53:38 +01:00
if (showingView != null) {
animators.add(ObjectAnimator.ofFloat(showingView, View.ALPHA, 0.0f, 1.0f));
2021-01-01 05:38:45 +01:00
}
2021-02-23 12:53:38 +01:00
if (translationView != null) {
animators.add(ObjectAnimator.ofFloat(translationView, View.TRANSLATION_Y, translation));
actionModeTranslationView = translationView;
}
actionModeExtraView = extraView;
actionModeShowingView = showingView;
actionModeHidingViews = hidingViews;
if (occupyStatusBar && actionModeTop != null && !SharedConfig.noStatusBar) {
animators.add(ObjectAnimator.ofFloat(actionModeTop, View.ALPHA, 0.0f, 1.0f));
}
if (SharedConfig.noStatusBar) {
2022-03-11 17:49:54 +01:00
if (ColorUtils.calculateLuminance(actionModeColor) < 0.7f) {
2021-02-23 12:53:38 +01:00
AndroidUtilities.setLightStatusBar(((Activity) getContext()).getWindow(), false);
} else {
AndroidUtilities.setLightStatusBar(((Activity) getContext()).getWindow(), true);
2015-10-29 18:10:07 +01:00
}
}
2021-02-23 12:53:38 +01:00
if (actionModeAnimation != null) {
actionModeAnimation.cancel();
}
actionModeAnimation = new AnimatorSet();
actionModeAnimation.playTogether(animators);
actionModeAnimation.setDuration(200);
actionModeAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
actionMode.setVisibility(VISIBLE);
if (occupyStatusBar && actionModeTop != null && !SharedConfig.noStatusBar) {
actionModeTop.setVisibility(VISIBLE);
2015-10-29 18:10:07 +01:00
}
2021-02-23 12:53:38 +01:00
}
@Override
public void onAnimationEnd(Animator animation) {
if (actionModeAnimation != null && actionModeAnimation.equals(animation)) {
actionModeAnimation = null;
if (titleTextView[0] != null) {
titleTextView[0].setVisibility(INVISIBLE);
}
2021-07-30 16:49:55 +02:00
if (subtitleTextView != null && !TextUtils.isEmpty(subtitle)) {
2021-02-23 12:53:38 +01:00
subtitleTextView.setVisibility(INVISIBLE);
}
if (menu != null) {
menu.setVisibility(INVISIBLE);
}
if (actionModeHidingViews != null) {
for (int a = 0; a < actionModeHidingViews.length; a++) {
if (actionModeHidingViews[a] != null) {
if (hideView == null || a >= hideView.length || hideView[a]) {
actionModeHidingViews[a].setVisibility(INVISIBLE);
}
2019-05-14 14:08:05 +02:00
}
}
}
}
2015-10-29 18:10:07 +01:00
}
2021-02-23 12:53:38 +01:00
@Override
public void onAnimationCancel(Animator animation) {
if (actionModeAnimation != null && actionModeAnimation.equals(animation)) {
actionModeAnimation = null;
}
}
});
actionModeAnimation.start();
if (backButtonImageView != null) {
Drawable drawable = backButtonImageView.getDrawable();
if (drawable instanceof BackDrawable) {
((BackDrawable) drawable).setRotation(1, true);
}
2021-02-23 12:53:38 +01:00
backButtonImageView.setBackgroundDrawable(Theme.createSelectorDrawable(itemsActionModeBackgroundColor));
2015-10-29 18:10:07 +01:00
}
2021-02-23 12:53:38 +01:00
} else {
actionMode.setAlpha(1.0f);
if (hidingViews != null) {
for (int a = 0; a < hidingViews.length; a++) {
if (hidingViews[a] != null) {
hidingViews[a].setAlpha(0.0f);
}
}
}
if (showingView != null) {
showingView.setAlpha(1.0f);
}
if (translationView != null) {
translationView.setTranslationY(translation);
actionModeTranslationView = translationView;
}
actionModeExtraView = extraView;
actionModeShowingView = showingView;
actionModeHidingViews = hidingViews;
if (occupyStatusBar && actionModeTop != null && !SharedConfig.noStatusBar) {
actionModeTop.setAlpha(1.0f);
}
if (SharedConfig.noStatusBar) {
2022-03-11 17:49:54 +01:00
if (ColorUtils.calculateLuminance(actionModeColor) < 0.7f) {
2021-02-23 12:53:38 +01:00
AndroidUtilities.setLightStatusBar(((Activity) getContext()).getWindow(), false);
} else {
AndroidUtilities.setLightStatusBar(((Activity) getContext()).getWindow(), true);
}
}
actionMode.setVisibility(VISIBLE);
if (occupyStatusBar && actionModeTop != null && !SharedConfig.noStatusBar) {
actionModeTop.setVisibility(VISIBLE);
}
if (titleTextView[0] != null) {
titleTextView[0].setVisibility(INVISIBLE);
}
2021-07-30 16:49:55 +02:00
if (subtitleTextView != null && !TextUtils.isEmpty(subtitle)) {
2021-02-23 12:53:38 +01:00
subtitleTextView.setVisibility(INVISIBLE);
}
if (menu != null) {
menu.setVisibility(INVISIBLE);
}
if (actionModeHidingViews != null) {
for (int a = 0; a < actionModeHidingViews.length; a++) {
if (actionModeHidingViews[a] != null) {
if (hideView == null || a >= hideView.length || hideView[a]) {
actionModeHidingViews[a].setVisibility(INVISIBLE);
}
}
}
}
if (backButtonImageView != null) {
Drawable drawable = backButtonImageView.getDrawable();
if (drawable instanceof BackDrawable) {
((BackDrawable) drawable).setRotation(1, false);
}
backButtonImageView.setBackgroundDrawable(Theme.createSelectorDrawable(itemsActionModeBackgroundColor));
2015-10-29 18:10:07 +01:00
}
}
}
2014-11-11 23:16:17 +01:00
public void hideActionMode() {
2015-10-29 18:10:07 +01:00
if (actionMode == null || !actionModeVisible) {
return;
}
2019-05-14 14:08:05 +02:00
actionMode.hideAllPopupMenus();
2015-10-29 18:10:07 +01:00
actionModeVisible = false;
ArrayList<Animator> animators = new ArrayList<>();
2019-05-14 14:08:05 +02:00
animators.add(ObjectAnimator.ofFloat(actionMode, View.ALPHA, 0.0f));
if (actionModeHidingViews != null) {
for (int a = 0; a < actionModeHidingViews.length; a++) {
2021-02-23 12:53:38 +01:00
if (actionModeHidingViews[a] != null) {
2019-05-14 14:08:05 +02:00
actionModeHidingViews[a].setVisibility(VISIBLE);
animators.add(ObjectAnimator.ofFloat(actionModeHidingViews[a], View.ALPHA, 1.0f));
}
}
}
if (actionModeTranslationView != null) {
animators.add(ObjectAnimator.ofFloat(actionModeTranslationView, View.TRANSLATION_Y, 0.0f));
actionModeTranslationView = null;
}
if (actionModeShowingView != null) {
animators.add(ObjectAnimator.ofFloat(actionModeShowingView, View.ALPHA, 0.0f));
}
2021-01-01 05:38:45 +01:00
if (occupyStatusBar && actionModeTop != null && !SharedConfig.noStatusBar) {
2019-05-14 14:08:05 +02:00
animators.add(ObjectAnimator.ofFloat(actionModeTop, View.ALPHA, 0.0f));
}
2021-01-01 05:38:45 +01:00
if (SharedConfig.noStatusBar) {
2022-03-11 17:49:54 +01:00
if (actionBarColor == 0) {
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.needCheckSystemBarColors);
2021-01-01 05:38:45 +01:00
} else {
2022-03-11 17:49:54 +01:00
if (ColorUtils.calculateLuminance(actionBarColor) < 0.7f) {
AndroidUtilities.setLightStatusBar(((Activity) getContext()).getWindow(), false);
} else {
AndroidUtilities.setLightStatusBar(((Activity) getContext()).getWindow(), true);
}
2021-01-01 05:38:45 +01:00
}
}
if (actionModeAnimation != null) {
actionModeAnimation.cancel();
}
actionModeAnimation = new AnimatorSet();
actionModeAnimation.playTogether(animators);
actionModeAnimation.setDuration(200);
2017-03-31 01:58:05 +02:00
actionModeAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (actionModeAnimation != null && actionModeAnimation.equals(animation)) {
actionModeAnimation = null;
actionMode.setVisibility(INVISIBLE);
2021-01-01 05:38:45 +01:00
if (occupyStatusBar && actionModeTop != null && !SharedConfig.noStatusBar) {
actionModeTop.setVisibility(INVISIBLE);
2016-05-25 23:49:47 +02:00
}
2019-05-14 14:08:05 +02:00
if (actionModeExtraView != null) {
actionModeExtraView.setVisibility(INVISIBLE);
}
2016-05-25 23:49:47 +02:00
}
}
2016-05-25 23:49:47 +02:00
@Override
public void onAnimationCancel(Animator animation) {
if (actionModeAnimation != null && actionModeAnimation.equals(animation)) {
actionModeAnimation = null;
2015-10-29 18:10:07 +01:00
}
}
});
actionModeAnimation.start();
2019-01-23 18:03:33 +01:00
if (!isSearchFieldVisible) {
2020-09-30 15:48:47 +02:00
if (titleTextView[0] != null) {
titleTextView[0].setVisibility(VISIBLE);
2019-01-23 18:03:33 +01:00
}
2021-07-30 16:49:55 +02:00
if (subtitleTextView != null && !TextUtils.isEmpty(subtitle)) {
2019-01-23 18:03:33 +01:00
subtitleTextView.setVisibility(VISIBLE);
}
2015-07-22 20:56:37 +02:00
}
2014-11-11 23:16:17 +01:00
if (menu != null) {
menu.setVisibility(VISIBLE);
}
2015-10-29 18:10:07 +01:00
if (backButtonImageView != null) {
Drawable drawable = backButtonImageView.getDrawable();
if (drawable instanceof BackDrawable) {
((BackDrawable) drawable).setRotation(0, true);
}
2017-03-31 01:58:05 +02:00
backButtonImageView.setBackgroundDrawable(Theme.createSelectorDrawable(itemsBackgroundColor));
2015-10-29 18:10:07 +01:00
}
2014-11-11 23:16:17 +01:00
}
2015-07-22 20:56:37 +02:00
public void showActionModeTop() {
if (occupyStatusBar && actionModeTop == null) {
actionModeTop = new View(getContext());
2021-09-20 00:10:42 +02:00
actionModeTop.setBackgroundColor(getThemedColor(Theme.key_actionBarActionModeDefaultTop));
2015-07-22 20:56:37 +02:00
addView(actionModeTop);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) actionModeTop.getLayoutParams();
layoutParams.height = AndroidUtilities.statusBarHeight;
layoutParams.width = LayoutHelper.MATCH_PARENT;
layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
actionModeTop.setLayoutParams(layoutParams);
}
}
2017-03-31 01:58:05 +02:00
public void setActionModeTopColor(int color) {
if (actionModeTop != null) {
actionModeTop.setBackgroundColor(color);
}
}
public void setSearchTextColor(int color, boolean placeholder) {
if (menu != null) {
menu.setSearchTextColor(color, placeholder);
}
}
2022-03-11 17:49:54 +01:00
public void setSearchCursorColor(int color) {
if (menu != null) {
menu.setSearchCursorColor(color);
}
}
2017-03-31 01:58:05 +02:00
public void setActionModeColor(int color) {
if (actionMode != null) {
2021-01-30 20:47:24 +01:00
actionMode.setBackgroundColor(color);
2017-03-31 01:58:05 +02:00
}
}
2021-01-30 20:47:24 +01:00
public void setActionModeOverrideColor(int color) {
actionModeColor = color;
}
2021-01-01 05:38:45 +01:00
@Override
public void setBackgroundColor(int color) {
super.setBackgroundColor(actionBarColor = color);
2021-06-25 02:43:10 +02:00
if (backButtonImageView != null) {
Drawable drawable = backButtonImageView.getDrawable();
if (drawable instanceof MenuDrawable) {
((MenuDrawable) drawable).setBackColor(color);
}
}
2021-01-01 05:38:45 +01:00
}
2014-11-11 23:16:17 +01:00
public boolean isActionModeShowed() {
2015-10-29 18:10:07 +01:00
return actionMode != null && actionModeVisible;
2014-11-11 23:16:17 +01:00
}
2021-06-25 02:43:10 +02:00
public boolean isActionModeShowed(String tag) {
return actionMode != null && actionModeVisible && ((actionModeTag == null && tag == null) || (actionModeTag != null && actionModeTag.equals(tag)));
}
2021-03-19 11:25:58 +01:00
AnimatorSet searchVisibleAnimator;
2019-12-31 14:08:08 +01:00
public void onSearchFieldVisibilityChanged(boolean visible) {
2014-11-11 23:16:17 +01:00
isSearchFieldVisible = visible;
2021-03-19 11:25:58 +01:00
if (searchVisibleAnimator != null) {
searchVisibleAnimator.cancel();
}
searchVisibleAnimator = new AnimatorSet();
final ArrayList<View> viewsToHide = new ArrayList<>();
2020-09-30 15:48:47 +02:00
if (titleTextView[0] != null) {
2021-03-19 11:25:58 +01:00
viewsToHide.add(titleTextView[0]);
2014-11-11 23:16:17 +01:00
}
2021-03-19 11:25:58 +01:00
2021-07-30 16:49:55 +02:00
if (subtitleTextView != null && !TextUtils.isEmpty(subtitle)) {
2021-03-19 11:25:58 +01:00
viewsToHide.add(subtitleTextView);
2016-04-22 15:49:00 +02:00
subtitleTextView.setVisibility(visible ? INVISIBLE : VISIBLE);
}
2021-03-19 11:25:58 +01:00
for (int i = 0; i < viewsToHide.size(); i++) {
View view = viewsToHide.get(i);
if (!visible) {
view.setVisibility(View.VISIBLE);
view.setAlpha(0);
view.setScaleX(0.95f);
view.setScaleY(0.95f);
}
searchVisibleAnimator.playTogether(ObjectAnimator.ofFloat(view, View.ALPHA, visible ? 0f : 1f));
searchVisibleAnimator.playTogether(ObjectAnimator.ofFloat(view, View.SCALE_Y, visible ? 0.95f : 1f));
searchVisibleAnimator.playTogether(ObjectAnimator.ofFloat(view, View.SCALE_X, visible ? 0.95f : 1f));
}
2021-07-30 16:49:55 +02:00
centerScale = true;
requestLayout();
2021-03-19 11:25:58 +01:00
searchVisibleAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
for (int i = 0; i < viewsToHide.size(); i++) {
View view = viewsToHide.get(i);
if (visible) {
view.setVisibility(View.INVISIBLE);
view.setAlpha(0);
} else {
view.setAlpha(1f);
}
}
2021-06-25 02:43:10 +02:00
if (visible) {
if (titleTextView[0] != null) {
titleTextView[0].setVisibility(View.GONE);
}
if (titleTextView[1] != null) {
titleTextView[1].setVisibility(View.GONE);
}
}
2021-03-19 11:25:58 +01:00
}
});
searchVisibleAnimator.setDuration(150).start();
2014-11-11 23:16:17 +01:00
Drawable drawable = backButtonImageView.getDrawable();
2019-05-14 14:08:05 +02:00
if (drawable instanceof MenuDrawable) {
MenuDrawable menuDrawable = (MenuDrawable) drawable;
menuDrawable.setRotateToBack(true);
menuDrawable.setRotation(visible ? 1 : 0, true);
2014-11-11 23:16:17 +01:00
}
}
2016-04-22 15:49:00 +02:00
public void setInterceptTouches(boolean value) {
interceptTouches = value;
}
2021-09-20 00:10:42 +02:00
public void setInterceptTouchEventListener(View.OnTouchListener listener) {
interceptTouchEventListener = listener;
}
2016-04-22 15:49:00 +02:00
public void setExtraHeight(int value) {
extraHeight = value;
2018-07-30 04:07:02 +02:00
if (actionMode != null) {
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) actionMode.getLayoutParams();
layoutParams.bottomMargin = extraHeight;
actionMode.setLayoutParams(layoutParams);
}
2016-04-22 15:49:00 +02:00
}
2014-11-11 23:16:17 +01:00
public void closeSearchField() {
2017-12-08 18:35:59 +01:00
closeSearchField(true);
}
public void closeSearchField(boolean closeKeyboard) {
2014-11-11 23:16:17 +01:00
if (!isSearchFieldVisible || menu == null) {
return;
}
2017-12-08 18:35:59 +01:00
menu.closeSearchField(closeKeyboard);
}
2019-01-23 18:03:33 +01:00
public void openSearchField(String text, boolean animated) {
2015-03-26 18:34:47 +01:00
if (menu == null || text == null) {
return;
}
2022-03-11 17:49:54 +01:00
menu.openSearchField(!isSearchFieldVisible, !isSearchFieldVisible, text, animated);
}
public void openSearchField(boolean animated) {
if (menu == null) {
return;
}
menu.openSearchField(!isSearchFieldVisible, false, "", animated);
}
2020-09-30 15:48:47 +02:00
public void setSearchFilter(FiltersView.MediaFilterData filter) {
if (menu != null) {
menu.setFilter(filter);
}
}
2019-07-18 15:01:39 +02:00
public void setSearchFieldText(String text) {
menu.setSearchFieldText(text);
}
2019-08-22 01:53:26 +02:00
public void onSearchPressed() {
menu.onSearchPressed();
}
2018-07-30 04:07:02 +02:00
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
if (backButtonImageView != null) {
backButtonImageView.setEnabled(enabled);
}
if (menu != null) {
menu.setEnabled(enabled);
}
if (actionMode != null) {
actionMode.setEnabled(enabled);
}
}
2019-05-14 14:08:05 +02:00
@Override
public void requestLayout() {
if (ignoreLayoutRequest) {
return;
}
super.requestLayout();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2015-07-22 20:56:37 +02:00
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
int actionBarHeight = getCurrentActionBarHeight();
int actionBarHeightSpec = MeasureSpec.makeMeasureSpec(actionBarHeight, MeasureSpec.EXACTLY);
2019-05-14 14:08:05 +02:00
ignoreLayoutRequest = true;
if (actionModeTop != null) {
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) actionModeTop.getLayoutParams();
layoutParams.height = AndroidUtilities.statusBarHeight;
}
if (actionMode != null) {
actionMode.setPadding(0, occupyStatusBar ? AndroidUtilities.statusBarHeight : 0, 0, 0);
}
ignoreLayoutRequest = false;
2016-04-22 15:49:00 +02:00
setMeasuredDimension(width, actionBarHeight + (occupyStatusBar ? AndroidUtilities.statusBarHeight : 0) + extraHeight);
2015-07-22 20:56:37 +02:00
int textLeft;
if (backButtonImageView != null && backButtonImageView.getVisibility() != GONE) {
backButtonImageView.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(54), MeasureSpec.EXACTLY), actionBarHeightSpec);
textLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 80 : 72);
} else {
textLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 26 : 18);
}
if (menu != null && menu.getVisibility() != GONE) {
int menuWidth;
2021-03-19 11:25:58 +01:00
boolean searchFieldIsVisible = menu.searchFieldVisible();
if (searchFieldIsVisible && !this.isSearchFieldVisible) {
menuWidth = MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST);
menu.measure(menuWidth, actionBarHeightSpec);
int itemsWidth = menu.getItemsMeasuredWidth();
menuWidth = MeasureSpec.makeMeasureSpec(width - AndroidUtilities.dp(AndroidUtilities.isTablet() ? 74 : 66) + menu.getItemsMeasuredWidth(), MeasureSpec.EXACTLY);
menu.translateXItems(-itemsWidth);
} else if (isSearchFieldVisible) {
2015-07-22 20:56:37 +02:00
menuWidth = MeasureSpec.makeMeasureSpec(width - AndroidUtilities.dp(AndroidUtilities.isTablet() ? 74 : 66), MeasureSpec.EXACTLY);
2021-03-19 11:25:58 +01:00
menu.translateXItems(0);
2015-07-22 20:56:37 +02:00
} else {
menuWidth = MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST);
2021-03-19 11:25:58 +01:00
menu.translateXItems(0);
2015-07-22 20:56:37 +02:00
}
menu.measure(menuWidth, actionBarHeightSpec);
2021-03-19 11:25:58 +01:00
2015-07-22 20:56:37 +02:00
}
2020-09-30 15:48:47 +02:00
for (int i = 0; i < 2; i++) {
if (titleTextView[0] != null && titleTextView[0].getVisibility() != GONE || subtitleTextView != null && subtitleTextView.getVisibility() != GONE) {
int availableWidth = width - (menu != null ? menu.getMeasuredWidth() : 0) - AndroidUtilities.dp(16) - textLeft - titleRightMargin;
2015-07-22 20:56:37 +02:00
2020-09-30 18:55:35 +02:00
if (((fromBottom && i == 0) || (!fromBottom && i == 1)) && overlayTitleAnimation && titleAnimationRunning) {
2020-09-30 15:48:47 +02:00
titleTextView[i].setTextSize(!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 18 : 20);
} else {
if (titleTextView[0] != null && titleTextView[0].getVisibility() != GONE && subtitleTextView != null && subtitleTextView.getVisibility() != GONE) {
if (titleTextView[i] != null) {
titleTextView[i].setTextSize(AndroidUtilities.isTablet() ? 20 : 18);
}
subtitleTextView.setTextSize(AndroidUtilities.isTablet() ? 16 : 14);
2021-06-25 02:43:10 +02:00
if (additionalSubtitleTextView != null) {
additionalSubtitleTextView.setTextSize(AndroidUtilities.isTablet() ? 16 : 14);
}
2020-09-30 15:48:47 +02:00
} else {
if (titleTextView[i] != null && titleTextView[i].getVisibility() != GONE) {
titleTextView[i].setTextSize(!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 18 : 20);
}
if (subtitleTextView != null && subtitleTextView.getVisibility() != GONE) {
subtitleTextView.setTextSize(!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 14 : 16);
}
2021-06-25 02:43:10 +02:00
if (additionalSubtitleTextView != null) {
additionalSubtitleTextView.setTextSize(!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 14 : 16);
}
2020-09-30 15:48:47 +02:00
}
}
if (titleTextView[i] != null && titleTextView[i].getVisibility() != GONE) {
titleTextView[i].measure(MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(24), MeasureSpec.AT_MOST));
2021-07-30 16:49:55 +02:00
if (centerScale) {
CharSequence text = titleTextView[i].getText();
titleTextView[i].setPivotX(titleTextView[i].getTextPaint().measureText(text, 0, text.length()) / 2f);
titleTextView[i].setPivotY((AndroidUtilities.dp(24) >> 1));
} else {
titleTextView[i].setPivotX(0);
titleTextView[i].setPivotY(0);
}
2019-01-23 18:03:33 +01:00
}
if (subtitleTextView != null && subtitleTextView.getVisibility() != GONE) {
2020-09-30 15:48:47 +02:00
subtitleTextView.measure(MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(20), MeasureSpec.AT_MOST));
2019-01-23 18:03:33 +01:00
}
2021-06-25 02:43:10 +02:00
if (additionalSubtitleTextView != null && additionalSubtitleTextView.getVisibility() != GONE) {
additionalSubtitleTextView.measure(MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(20), MeasureSpec.AT_MOST));
}
2019-01-23 18:03:33 +01:00
}
2015-07-22 20:56:37 +02:00
}
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
2021-06-25 02:43:10 +02:00
if (child.getVisibility() == GONE || child == titleTextView[0] || child == titleTextView[1] || child == subtitleTextView || child == menu || child == backButtonImageView || child == additionalSubtitleTextView) {
2015-07-22 20:56:37 +02:00
continue;
}
measureChildWithMargins(child, widthMeasureSpec, 0, MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY), 0);
}
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
int additionalTop = occupyStatusBar ? AndroidUtilities.statusBarHeight : 0;
int textLeft;
if (backButtonImageView != null && backButtonImageView.getVisibility() != GONE) {
backButtonImageView.layout(0, additionalTop, backButtonImageView.getMeasuredWidth(), additionalTop + backButtonImageView.getMeasuredHeight());
textLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 80 : 72);
} else {
textLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 26 : 18);
}
if (menu != null && menu.getVisibility() != GONE) {
2021-03-19 11:25:58 +01:00
int menuLeft = menu.searchFieldVisible() ? AndroidUtilities.dp(AndroidUtilities.isTablet() ? 74 : 66) : (right - left) - menu.getMeasuredWidth();
2015-07-22 20:56:37 +02:00
menu.layout(menuLeft, additionalTop, menuLeft + menu.getMeasuredWidth(), additionalTop + menu.getMeasuredHeight());
}
2020-09-30 15:48:47 +02:00
for (int i = 0; i < 2; i++) {
if (titleTextView[i] != null && titleTextView[i].getVisibility() != GONE) {
int textTop;
2020-09-30 18:55:35 +02:00
if (((fromBottom && i == 0) || (!fromBottom && i == 1)) && overlayTitleAnimation && titleAnimationRunning) {
2020-09-30 15:48:47 +02:00
textTop = (getCurrentActionBarHeight() - titleTextView[i].getTextHeight()) / 2;
} else {
if ((subtitleTextView != null && subtitleTextView.getVisibility() != GONE)) {
textTop = (getCurrentActionBarHeight() / 2 - titleTextView[i].getTextHeight()) / 2 + AndroidUtilities.dp(!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 2 : 3);
} else {
textTop = (getCurrentActionBarHeight() - titleTextView[i].getTextHeight()) / 2;
}
}
titleTextView[i].layout(textLeft, additionalTop + textTop, textLeft + titleTextView[i].getMeasuredWidth(), additionalTop + textTop + titleTextView[i].getTextHeight());
2015-07-22 20:56:37 +02:00
}
}
2016-04-22 15:49:00 +02:00
if (subtitleTextView != null && subtitleTextView.getVisibility() != GONE) {
int textTop = getCurrentActionBarHeight() / 2 + (getCurrentActionBarHeight() / 2 - subtitleTextView.getTextHeight()) / 2 - AndroidUtilities.dp(!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 1 : 1);
subtitleTextView.layout(textLeft, additionalTop + textTop, textLeft + subtitleTextView.getMeasuredWidth(), additionalTop + textTop + subtitleTextView.getTextHeight());
2015-07-22 20:56:37 +02:00
}
2021-06-25 02:43:10 +02:00
if (additionalSubtitleTextView != null && additionalSubtitleTextView.getVisibility() != GONE) {
int textTop = getCurrentActionBarHeight() / 2 + (getCurrentActionBarHeight() / 2 - additionalSubtitleTextView.getTextHeight()) / 2 - AndroidUtilities.dp(!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 1 : 1);
additionalSubtitleTextView.layout(textLeft, additionalTop + textTop, textLeft + additionalSubtitleTextView.getMeasuredWidth(), additionalTop + textTop + additionalSubtitleTextView.getTextHeight());
}
2015-07-22 20:56:37 +02:00
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
2021-06-25 02:43:10 +02:00
if (child.getVisibility() == GONE || child == titleTextView[0] || child == titleTextView[1] || child == subtitleTextView || child == menu || child == backButtonImageView || child == additionalSubtitleTextView) {
2015-07-22 20:56:37 +02:00
continue;
}
LayoutParams lp = (LayoutParams) child.getLayoutParams();
int width = child.getMeasuredWidth();
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.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);
}
2014-11-11 23:16:17 +01:00
}
public void onMenuButtonPressed() {
2019-05-14 14:08:05 +02:00
if (isActionModeShowed()) {
return;
}
2014-11-11 23:16:17 +01:00
if (menu != null) {
menu.onMenuButtonPressed();
}
}
protected void onPause() {
if (menu != null) {
menu.hideAllPopupMenus();
}
}
2014-11-18 06:01:04 +01:00
public void setAllowOverlayTitle(boolean value) {
allowOverlayTitle = value;
2014-11-11 23:16:17 +01:00
}
2018-07-30 04:07:02 +02:00
public void setTitleActionRunnable(Runnable action) {
lastRunnable = titleActionRunnable = action;
}
2020-09-30 15:48:47 +02:00
boolean overlayTitleAnimationInProgress;
2019-01-23 18:03:33 +01:00
public void setTitleOverlayText(String title, int titleId, Runnable action) {
if (!allowOverlayTitle || parentFragment.parentLayout == null) {
2014-11-11 23:16:17 +01:00
return;
}
2020-09-30 15:48:47 +02:00
overlayTitleToSet[0] = title;
overlayTitleToSet[1] = titleId;
overlayTitleToSet[2] = action;
if (overlayTitleAnimationInProgress) {
return;
}
if (lastOverlayTitle == null && title == null || (lastOverlayTitle != null && lastOverlayTitle.equals(title))) {
return;
}
lastOverlayTitle = title;
2019-01-23 18:03:33 +01:00
CharSequence textToSet = title != null ? LocaleController.getString(title, titleId) : lastTitle;
2020-09-30 15:48:47 +02:00
boolean ellipsize = false;
if (title != null) {
int index = TextUtils.indexOf(textToSet, "...");
if (index >= 0) {
SpannableString spannableString = SpannableString.valueOf(textToSet);
ellipsizeSpanAnimator.wrap(spannableString, index);
textToSet = spannableString;
ellipsize = true;
}
2014-11-18 06:01:04 +01:00
}
2020-09-30 15:48:47 +02:00
titleOverlayShown = title != null;
if ((textToSet != null && titleTextView[0] == null) || getMeasuredWidth() == 0 || (titleTextView[0] != null && titleTextView[0].getVisibility() != View.VISIBLE)) {
createTitleTextView(0);
2018-07-30 04:07:02 +02:00
if (supportsHolidayImage) {
2020-09-30 15:48:47 +02:00
titleTextView[0].invalidate();
2018-07-30 04:07:02 +02:00
invalidate();
}
2020-09-30 15:48:47 +02:00
titleTextView[0].setText(textToSet);
if (ellipsize) {
ellipsizeSpanAnimator.addView(titleTextView[0]);
} else {
ellipsizeSpanAnimator.removeView(titleTextView[0]);
}
} else if (titleTextView[0] != null) {
titleTextView[0].animate().cancel();
if (titleTextView[1] != null) {
titleTextView[1].animate().cancel();
}
if (titleTextView[1] == null) {
createTitleTextView(1);
}
titleTextView[1].setText(textToSet);
if (ellipsize) {
ellipsizeSpanAnimator.addView(titleTextView[1]);
}
overlayTitleAnimationInProgress = true;
SimpleTextView tmp = titleTextView[1];
titleTextView[1] = titleTextView[0];
titleTextView[0] = tmp;
titleTextView[0].setAlpha(0);
titleTextView[0].setTranslationY(-AndroidUtilities.dp(20));
titleTextView[0].animate()
.alpha(1f)
.translationY(0)
.setDuration(220).start();
ViewPropertyAnimator animator = titleTextView[1].animate()
.alpha(0);
if (subtitleTextView == null) {
animator.translationY(AndroidUtilities.dp(20));
} else {
animator.scaleY(0.7f).scaleX(0.7f);
}
2021-07-30 16:49:55 +02:00
requestLayout();
centerScale = true;
2020-09-30 15:48:47 +02:00
animator.setDuration(220).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (titleTextView[1] != null && titleTextView[1].getParent() != null) {
ViewGroup viewGroup = (ViewGroup) titleTextView[1].getParent();
viewGroup.removeView(titleTextView[1]);
}
ellipsizeSpanAnimator.removeView(titleTextView[1]);
titleTextView[1] = null;
overlayTitleAnimationInProgress = false;
setTitleOverlayText((String) overlayTitleToSet[0], (int) overlayTitleToSet[1], (Runnable) overlayTitleToSet[2]);
}
}).start();
2014-11-11 23:16:17 +01:00
}
2018-07-30 04:07:02 +02:00
titleActionRunnable = action != null ? action : lastRunnable;
2014-11-11 23:16:17 +01:00
}
2015-07-22 20:56:37 +02:00
public boolean isSearchFieldVisible() {
return isSearchFieldVisible;
}
2014-11-17 03:44:57 +01:00
public void setOccupyStatusBar(boolean value) {
occupyStatusBar = value;
if (actionMode != null) {
actionMode.setPadding(0, occupyStatusBar ? AndroidUtilities.statusBarHeight : 0, 0, 0);
}
2014-11-17 03:44:57 +01:00
}
public boolean getOccupyStatusBar() {
return occupyStatusBar;
}
2017-03-31 01:58:05 +02:00
public void setItemsBackgroundColor(int color, boolean isActionMode) {
if (isActionMode) {
itemsActionModeBackgroundColor = color;
if (actionModeVisible) {
if (backButtonImageView != null) {
backButtonImageView.setBackgroundDrawable(Theme.createSelectorDrawable(itemsActionModeBackgroundColor));
}
}
if (actionMode != null) {
actionMode.updateItemsBackgroundColor();
}
} else {
itemsBackgroundColor = color;
if (backButtonImageView != null) {
backButtonImageView.setBackgroundDrawable(Theme.createSelectorDrawable(itemsBackgroundColor));
}
if (menu != null) {
menu.updateItemsBackgroundColor();
}
}
}
public void setItemsColor(int color, boolean isActionMode) {
if (isActionMode) {
itemsActionModeColor = color;
if (actionMode != null) {
actionMode.updateItemsColor();
}
if (backButtonImageView != null) {
Drawable drawable = backButtonImageView.getDrawable();
if (drawable instanceof BackDrawable) {
((BackDrawable) drawable).setRotatedColor(color);
}
}
} else {
itemsColor = color;
if (backButtonImageView != null) {
if (itemsColor != 0) {
2020-06-25 17:12:58 +02:00
backButtonImageView.setColorFilter(new PorterDuffColorFilter(itemsColor, PorterDuff.Mode.SRC_IN));
2017-03-31 01:58:05 +02:00
Drawable drawable = backButtonImageView.getDrawable();
if (drawable instanceof BackDrawable) {
((BackDrawable) drawable).setColor(color);
2021-01-01 16:23:48 +01:00
} else if (drawable instanceof MenuDrawable) {
2020-09-30 15:48:47 +02:00
((MenuDrawable) drawable).setIconColor(color);
2017-03-31 01:58:05 +02:00
}
}
}
if (menu != null) {
menu.updateItemsColor();
}
2014-11-13 21:10:14 +01:00
}
2014-11-11 23:16:17 +01:00
}
2015-02-01 19:51:02 +01:00
public void setCastShadows(boolean value) {
castShadows = value;
}
public boolean getCastShadows() {
return castShadows;
}
2014-11-11 23:16:17 +01:00
@Override
public boolean onTouchEvent(MotionEvent event) {
2016-04-22 15:49:00 +02:00
return super.onTouchEvent(event) || interceptTouches;
}
2015-07-22 20:56:37 +02:00
public static int getCurrentActionBarHeight() {
if (AndroidUtilities.isTablet()) {
return AndroidUtilities.dp(64);
2016-10-11 13:57:01 +02:00
} else if (AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y) {
2015-07-22 20:56:37 +02:00
return AndroidUtilities.dp(48);
} else {
return AndroidUtilities.dp(56);
}
}
2015-10-29 18:10:07 +01:00
2020-09-30 15:48:47 +02:00
public void setTitleAnimated(CharSequence title, boolean fromBottom, long duration) {
2020-09-30 18:55:35 +02:00
if (titleTextView[0] == null || title == null) {
2020-09-30 15:48:47 +02:00
setTitle(title);
return;
}
2021-08-01 15:31:28 +02:00
boolean crossfade = overlayTitleAnimation && !TextUtils.isEmpty(subtitle);
2020-09-30 15:48:47 +02:00
if (crossfade) {
if (subtitleTextView.getVisibility() != View.VISIBLE) {
subtitleTextView.setVisibility(View.VISIBLE);
subtitleTextView.setAlpha(0);
}
subtitleTextView.animate().alpha(fromBottom ? 0 : 1f).setDuration(220).start();
}
if (titleTextView[1] != null) {
if (titleTextView[1].getParent() != null) {
ViewGroup viewGroup = (ViewGroup) titleTextView[1].getParent();
viewGroup.removeView(titleTextView[1]);
}
titleTextView[1] = null;
}
titleTextView[1] = titleTextView[0];
titleTextView[0] = null;
setTitle(title);
2020-09-30 18:55:35 +02:00
this.fromBottom = fromBottom;
2020-09-30 15:48:47 +02:00
titleTextView[0].setAlpha(0);
if (!crossfade) {
titleTextView[0].setTranslationY(fromBottom ? AndroidUtilities.dp(20) : -AndroidUtilities.dp(20));
}
titleTextView[0].animate().alpha(1f).translationY(0).setDuration(duration).start();
titleAnimationRunning = true;
ViewPropertyAnimator a = titleTextView[1].animate().alpha(0);
if (!crossfade) {
a.translationY(fromBottom ? -AndroidUtilities.dp(20) : AndroidUtilities.dp(20));
}
a.setDuration(duration).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
if (titleTextView[1] != null && titleTextView[1].getParent() != null) {
ViewGroup viewGroup = (ViewGroup) titleTextView[1].getParent();
viewGroup.removeView(titleTextView[1]);
}
titleTextView[1] = null;
titleAnimationRunning = false;
if (crossfade && fromBottom) {
subtitleTextView.setVisibility(View.GONE);
}
requestLayout();
}
}).start();
requestLayout();
}
2015-10-29 18:10:07 +01:00
@Override
public boolean hasOverlappingRendering() {
return false;
}
2020-09-30 15:48:47 +02:00
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
ellipsizeSpanAnimator.onAttachedToWindow();
2021-01-01 05:38:45 +01:00
if (SharedConfig.noStatusBar && actionModeVisible) {
2022-03-11 17:49:54 +01:00
if (ColorUtils.calculateLuminance(actionModeColor) < 0.7f) {
2021-01-01 05:38:45 +01:00
AndroidUtilities.setLightStatusBar(((Activity) getContext()).getWindow(), false);
} else {
AndroidUtilities.setLightStatusBar(((Activity) getContext()).getWindow(), true);
}
}
2020-09-30 15:48:47 +02:00
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
ellipsizeSpanAnimator.onDetachedFromWindow();
2021-01-01 05:38:45 +01:00
if (SharedConfig.noStatusBar && actionModeVisible) {
2022-03-11 17:49:54 +01:00
if (actionBarColor == 0) {
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.needCheckSystemBarColors);
2021-01-01 05:38:45 +01:00
} else {
2022-03-11 17:49:54 +01:00
if (ColorUtils.calculateLuminance(actionBarColor) < 0.7f) {
AndroidUtilities.setLightStatusBar(((Activity) getContext()).getWindow(), false);
} else {
AndroidUtilities.setLightStatusBar(((Activity) getContext()).getWindow(), true);
}
2021-01-01 05:38:45 +01:00
}
}
2020-09-30 15:48:47 +02:00
}
public ActionBarMenu getActionMode() {
return actionMode;
}
2020-09-30 18:55:35 +02:00
public void setOverlayTitleAnimation(boolean ovelayTitleAnimation) {
this.overlayTitleAnimation = ovelayTitleAnimation;
}
2021-07-30 16:49:55 +02:00
public void beginDelayedTransition() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
TransitionSet transitionSet = new TransitionSet();
transitionSet.setOrdering(TransitionSet.ORDERING_TOGETHER);
transitionSet.addTransition(new Fade());
transitionSet.addTransition(new ChangeBounds() {
public void captureStartValues(TransitionValues transitionValues) {
super.captureStartValues(transitionValues);
if (transitionValues.view instanceof SimpleTextView) {
float textSize = ((SimpleTextView) transitionValues.view).getTextPaint().getTextSize();
transitionValues.values.put("text_size", textSize);
}
}
public void captureEndValues(TransitionValues transitionValues) {
super.captureEndValues(transitionValues);
if (transitionValues.view instanceof SimpleTextView) {
float textSize = ((SimpleTextView) transitionValues.view).getTextPaint().getTextSize();
2021-07-30 16:49:55 +02:00
transitionValues.values.put("text_size", textSize);
}
}
@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
2021-07-31 01:39:13 +02:00
if (startValues != null && startValues.view instanceof SimpleTextView) {
2021-07-30 16:49:55 +02:00
AnimatorSet animatorSet = new AnimatorSet();
2021-09-20 00:10:42 +02:00
if (startValues != null && endValues != null) {
Animator animator = super.createAnimator(sceneRoot, startValues, endValues);
float s = (float) startValues.values.get("text_size") / (float) endValues.values.get("text_size");
startValues.view.setScaleX(s);
startValues.view.setScaleY(s);
if (animator != null) {
animatorSet.playTogether(animator);
}
2021-07-30 16:49:55 +02:00
}
animatorSet.playTogether(ObjectAnimator.ofFloat(startValues.view, SCALE_X, 1f));
animatorSet.playTogether(ObjectAnimator.ofFloat(startValues.view, SCALE_Y, 1f));
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation);
startValues.view.setLayerType(LAYER_TYPE_HARDWARE, null);
}
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
startValues.view.setLayerType(LAYER_TYPE_NONE, null);
}
});
return animatorSet;
} else {
return super.createAnimator(sceneRoot, startValues, endValues);
}
}
});
centerScale = false;
transitionSet.setDuration(220);
transitionSet.setInterpolator(CubicBezierInterpolator.DEFAULT);
TransitionManager.beginDelayedTransition(this, transitionSet);
}
}
2021-09-20 00:10:42 +02:00
private int getThemedColor(String key) {
Integer color = resourcesProvider != null ? resourcesProvider.getColor(key) : null;
if (color == null) {
color = parentFragment != null ? parentFragment.getThemedColor(key) : null;
}
return color != null ? color : Theme.getColor(key);
}
2022-01-18 21:51:58 +01:00
SizeNotifierFrameLayout contentView;
boolean blurredBackground;
public void setDrawBlurBackground(SizeNotifierFrameLayout contentView) {
blurredBackground = true;
this.contentView = contentView;
contentView.blurBehindViews.add(this);
setBackground(null);
}
2022-03-11 17:49:54 +01:00
public Paint blurScrimPaint = new Paint();
2022-01-18 21:51:58 +01:00
Rect rectTmp = new Rect();
@Override
protected void dispatchDraw(Canvas canvas) {
2022-03-11 17:49:54 +01:00
if (blurredBackground && actionBarColor != Color.TRANSPARENT) {
2022-01-18 21:51:58 +01:00
rectTmp.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
blurScrimPaint.setColor(actionBarColor);
2022-03-20 21:22:37 +01:00
contentView.drawBlurRect(canvas, getY(), rectTmp, blurScrimPaint, true);
2022-01-18 21:51:58 +01:00
}
super.dispatchDraw(canvas);
}
2022-01-20 08:25:09 +01:00
// NekoX Changes
private StaticLayout countLayout;
private class UnreadImageView extends ImageView {
public UnreadImageView(Context context) {
super(context);
}
private int unreadCount = 0;
private RectF rect = new RectF();
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (countLayout == null || unreadCount == 0)
return;
Paint paint = Theme.dialogs_countPaint;
String unreadCountString = unreadCount > 99 ? "99+" : Integer.toString(unreadCount);
int countWidth = Math.max(AndroidUtilities.dp(12), (int) Math.ceil(Theme.dialogs_countTextPaint.measureText(unreadCountString)));
int countLeft = getMeasuredWidth() - countWidth - AndroidUtilities.dp(20);
int countTop = 0;
int x = countLeft - AndroidUtilities.dp(5.5f);
rect.set(x, countTop, x + countWidth + AndroidUtilities.dp(11), countTop + AndroidUtilities.dp(23));
canvas.drawRoundRect(rect, 11.5f * AndroidUtilities.density, 11.5f * AndroidUtilities.density, paint);
canvas.save();
canvas.translate(countLeft, countTop + AndroidUtilities.dp(4));
countLayout.draw(canvas);
canvas.restore();
}
public void setUnread(int count) {
if (count != unreadCount) {
unreadCount = count;
String countString = count > 99 ? "99+" : Integer.toString(count);
int countWidth = count == 0 ? 0 : Math.max(AndroidUtilities.dp(12), (int) Math.ceil(Theme.dialogs_countTextPaint.measureText(countString)));
countLayout = new StaticLayout(countString, Theme.dialogs_countTextPaint, countWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
invalidate();
}
}
}
public void unreadBadgeSetCount(int count) {
2022-01-17 08:45:37 +01:00
if (backButtonImageView != null && NekoConfig.unreadBadgeOnBackButton.Bool()) {
backButtonImageView.setUnread(count);
}
}
2014-11-11 23:16:17 +01:00
}