2014-06-04 01:31:48 +02:00
|
|
|
/*
|
2019-01-23 18:03:33 +01:00
|
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
2014-06-04 01:31:48 +02:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2019-01-23 18:03:33 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2018.
|
2014-06-04 01:31:48 +02:00
|
|
|
*/
|
|
|
|
|
2014-11-13 21:10:14 +01:00
|
|
|
package org.telegram.ui.ActionBar;
|
2014-06-04 01:31:48 +02:00
|
|
|
|
|
|
|
import android.content.Context;
|
2014-11-17 03:44:57 +01:00
|
|
|
import android.graphics.drawable.Drawable;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.view.View;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.view.ViewGroup;
|
2014-06-04 01:31:48 +02:00
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2020-09-30 15:48:47 +02:00
|
|
|
import org.telegram.ui.Adapters.FiltersView;
|
2021-01-28 15:15:51 +01:00
|
|
|
import org.telegram.ui.Components.RLottieDrawable;
|
|
|
|
import org.telegram.ui.Components.RLottieImageView;
|
2014-06-04 01:31:48 +02:00
|
|
|
|
|
|
|
public class ActionBarMenu extends LinearLayout {
|
|
|
|
|
2014-11-11 23:16:17 +01:00
|
|
|
protected ActionBar parentActionBar;
|
2017-03-31 01:58:05 +02:00
|
|
|
protected boolean isActionMode;
|
2014-06-04 01:31:48 +02:00
|
|
|
|
2014-11-11 23:16:17 +01:00
|
|
|
public ActionBarMenu(Context context, ActionBar layer) {
|
2014-06-04 01:31:48 +02:00
|
|
|
super(context);
|
|
|
|
setOrientation(LinearLayout.HORIZONTAL);
|
2014-11-11 23:16:17 +01:00
|
|
|
parentActionBar = layer;
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public ActionBarMenu(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
protected void updateItemsBackgroundColor() {
|
|
|
|
int count = getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = getChildAt(a);
|
|
|
|
if (view instanceof ActionBarMenuItem) {
|
|
|
|
view.setBackgroundDrawable(Theme.createSelectorDrawable(isActionMode ? parentActionBar.itemsActionModeBackgroundColor : parentActionBar.itemsBackgroundColor));
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void updateItemsColor() {
|
|
|
|
int count = getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = getChildAt(a);
|
|
|
|
if (view instanceof ActionBarMenuItem) {
|
|
|
|
((ActionBarMenuItem) view).setIconColor(isActionMode ? parentActionBar.itemsActionModeColor : parentActionBar.itemsColor);
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
2014-11-17 03:44:57 +01:00
|
|
|
public ActionBarMenuItem addItem(int id, Drawable drawable) {
|
2019-07-18 15:01:39 +02:00
|
|
|
return addItem(id, 0, null, isActionMode ? parentActionBar.itemsActionModeBackgroundColor : parentActionBar.itemsBackgroundColor, drawable, AndroidUtilities.dp(48), null);
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
public ActionBarMenuItem addItem(int id, int icon) {
|
2017-03-31 01:58:05 +02:00
|
|
|
return addItem(id, icon, isActionMode ? parentActionBar.itemsActionModeBackgroundColor : parentActionBar.itemsBackgroundColor);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
|
2019-07-18 15:01:39 +02:00
|
|
|
public ActionBarMenuItem addItem(int id, CharSequence text) {
|
|
|
|
return addItem(id, 0, text, isActionMode ? parentActionBar.itemsActionModeBackgroundColor : parentActionBar.itemsBackgroundColor, null, 0, text);
|
|
|
|
}
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
public ActionBarMenuItem addItem(int id, int icon, int backgroundColor) {
|
2019-07-18 15:01:39 +02:00
|
|
|
return addItem(id, icon, null, backgroundColor, null, AndroidUtilities.dp(48), null);
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ActionBarMenuItem addItemWithWidth(int id, int icon, int width) {
|
2019-07-18 15:01:39 +02:00
|
|
|
return addItem(id, icon, null, isActionMode ? parentActionBar.itemsActionModeBackgroundColor : parentActionBar.itemsBackgroundColor, null, width, null);
|
2014-11-14 16:40:15 +01:00
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public ActionBarMenuItem addItemWithWidth(int id, int icon, int width, CharSequence title) {
|
2019-07-18 15:01:39 +02:00
|
|
|
return addItem(id, icon, null, isActionMode ? parentActionBar.itemsActionModeBackgroundColor : parentActionBar.itemsBackgroundColor, null, width, title);
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
|
|
|
|
2019-07-18 15:01:39 +02:00
|
|
|
public ActionBarMenuItem addItem(int id, int icon, CharSequence text, int backgroundColor, Drawable drawable, int width, CharSequence title) {
|
|
|
|
ActionBarMenuItem menuItem = new ActionBarMenuItem(getContext(), this, backgroundColor, isActionMode ? parentActionBar.itemsActionModeColor : parentActionBar.itemsColor, text != null);
|
2014-06-04 01:31:48 +02:00
|
|
|
menuItem.setTag(id);
|
2019-07-18 15:01:39 +02:00
|
|
|
if (text != null) {
|
|
|
|
menuItem.textView.setText(text);
|
|
|
|
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(width != 0 ? width : ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
|
|
layoutParams.leftMargin = layoutParams.rightMargin = AndroidUtilities.dp(14);
|
|
|
|
addView(menuItem, layoutParams);
|
|
|
|
} else {
|
|
|
|
if (drawable != null) {
|
2021-01-28 15:15:51 +01:00
|
|
|
if (drawable instanceof RLottieDrawable) {
|
|
|
|
menuItem.iconView.setAnimation((RLottieDrawable) drawable);
|
|
|
|
} else {
|
|
|
|
menuItem.iconView.setImageDrawable(drawable);
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
} else if (icon != 0) {
|
|
|
|
menuItem.iconView.setImageResource(icon);
|
|
|
|
}
|
|
|
|
addView(menuItem, new LinearLayout.LayoutParams(width, ViewGroup.LayoutParams.MATCH_PARENT));
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
menuItem.setOnClickListener(view -> {
|
|
|
|
ActionBarMenuItem item = (ActionBarMenuItem) view;
|
|
|
|
if (item.hasSubMenu()) {
|
|
|
|
if (parentActionBar.actionBarMenuOnItemClick.canOpenMenu()) {
|
|
|
|
item.toggleSubMenu();
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
2018-08-27 10:33:11 +02:00
|
|
|
} else if (item.isSearchField()) {
|
|
|
|
parentActionBar.onSearchFieldVisibilityChanged(item.toggleSearch(true));
|
|
|
|
} else {
|
|
|
|
onItemClick((Integer) view.getTag());
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
});
|
2019-05-14 14:08:05 +02:00
|
|
|
if (title != null) {
|
|
|
|
menuItem.setContentDescription(title);
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
return menuItem;
|
|
|
|
}
|
|
|
|
|
2014-06-04 18:00:42 +02:00
|
|
|
public void hideAllPopupMenus() {
|
2016-06-24 12:27:15 +02:00
|
|
|
int count = getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
2014-06-04 01:31:48 +02:00
|
|
|
View view = getChildAt(a);
|
|
|
|
if (view instanceof ActionBarMenuItem) {
|
2015-07-22 20:56:37 +02:00
|
|
|
((ActionBarMenuItem) view).closeSubMenu();
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
protected void setPopupItemsColor(int color, boolean icon) {
|
2019-12-31 14:08:08 +01:00
|
|
|
for (int a = 0, count = getChildCount(); a < count; a++) {
|
|
|
|
final View view = getChildAt(a);
|
2017-03-31 01:58:05 +02:00
|
|
|
if (view instanceof ActionBarMenuItem) {
|
2019-12-31 14:08:08 +01:00
|
|
|
((ActionBarMenuItem) view).setPopupItemsColor(color, icon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void setPopupItemsSelectorColor(int color) {
|
|
|
|
for (int a = 0, count = getChildCount(); a < count; a++) {
|
|
|
|
final View view = getChildAt(a);
|
|
|
|
if (view instanceof ActionBarMenuItem) {
|
|
|
|
((ActionBarMenuItem) view).setPopupItemsSelectorColor(color);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void redrawPopup(int color) {
|
2019-12-31 14:08:08 +01:00
|
|
|
for (int a = 0, count = getChildCount(); a < count; a++) {
|
|
|
|
final View view = getChildAt(a);
|
2017-03-31 01:58:05 +02:00
|
|
|
if (view instanceof ActionBarMenuItem) {
|
2019-12-31 14:08:08 +01:00
|
|
|
((ActionBarMenuItem) view).redrawPopup(color);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
public void onItemClick(int id) {
|
2014-11-11 23:16:17 +01:00
|
|
|
if (parentActionBar.actionBarMenuOnItemClick != null) {
|
|
|
|
parentActionBar.actionBarMenuOnItemClick.onItemClick(id);
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clearItems() {
|
2016-04-25 21:26:41 +02:00
|
|
|
removeAllViews();
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onMenuButtonPressed() {
|
2016-06-24 12:27:15 +02:00
|
|
|
int count = getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
2014-06-04 01:31:48 +02:00
|
|
|
View view = getChildAt(a);
|
|
|
|
if (view instanceof ActionBarMenuItem) {
|
2015-07-22 20:56:37 +02:00
|
|
|
ActionBarMenuItem item = (ActionBarMenuItem) view;
|
|
|
|
if (item.getVisibility() != VISIBLE) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (item.hasSubMenu()) {
|
2014-06-04 01:31:48 +02:00
|
|
|
item.toggleSubMenu();
|
2014-11-20 15:45:33 +01:00
|
|
|
break;
|
2015-07-22 20:56:37 +02:00
|
|
|
} else if (item.overrideMenuClick) {
|
|
|
|
onItemClick((Integer) item.getTag());
|
|
|
|
break;
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public void closeSearchField(boolean closeKeyboard) {
|
2016-06-24 12:27:15 +02:00
|
|
|
int count = getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
2014-06-04 01:31:48 +02:00
|
|
|
View view = getChildAt(a);
|
|
|
|
if (view instanceof ActionBarMenuItem) {
|
2015-07-22 20:56:37 +02:00
|
|
|
ActionBarMenuItem item = (ActionBarMenuItem) view;
|
2020-04-24 11:21:58 +02:00
|
|
|
if (item.isSearchField() && item.isSearchFieldVisible()) {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (item.listener == null || item.listener.canCollapseSearch()) {
|
|
|
|
parentActionBar.onSearchFieldVisibilityChanged(false);
|
|
|
|
item.toggleSearch(closeKeyboard);
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public void setSearchTextColor(int color, boolean placeholder) {
|
|
|
|
int count = getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = getChildAt(a);
|
|
|
|
if (view instanceof ActionBarMenuItem) {
|
|
|
|
ActionBarMenuItem item = (ActionBarMenuItem) view;
|
|
|
|
if (item.isSearchField()) {
|
|
|
|
if (placeholder) {
|
|
|
|
item.getSearchField().setHintTextColor(color);
|
|
|
|
} else {
|
|
|
|
item.getSearchField().setTextColor(color);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-18 15:01:39 +02:00
|
|
|
public void setSearchFieldText(String text) {
|
|
|
|
int count = getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = getChildAt(a);
|
|
|
|
if (view instanceof ActionBarMenuItem) {
|
|
|
|
ActionBarMenuItem item = (ActionBarMenuItem) view;
|
|
|
|
if (item.isSearchField()) {
|
|
|
|
item.setSearchFieldText(text, false);
|
|
|
|
item.getSearchField().setSelection(text.length());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
public void onSearchPressed() {
|
|
|
|
int count = getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = getChildAt(a);
|
|
|
|
if (view instanceof ActionBarMenuItem) {
|
|
|
|
ActionBarMenuItem item = (ActionBarMenuItem) view;
|
|
|
|
if (item.isSearchField()) {
|
|
|
|
item.onSearchPressed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public void openSearchField(boolean toggle, String text, boolean animated) {
|
2016-06-24 12:27:15 +02:00
|
|
|
int count = getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
2015-03-19 00:09:45 +01:00
|
|
|
View view = getChildAt(a);
|
|
|
|
if (view instanceof ActionBarMenuItem) {
|
2015-07-22 20:56:37 +02:00
|
|
|
ActionBarMenuItem item = (ActionBarMenuItem) view;
|
2015-03-19 00:09:45 +01:00
|
|
|
if (item.isSearchField()) {
|
2015-03-26 18:34:47 +01:00
|
|
|
if (toggle) {
|
2015-09-24 22:52:02 +02:00
|
|
|
parentActionBar.onSearchFieldVisibilityChanged(item.toggleSearch(true));
|
2015-03-26 18:34:47 +01:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
item.setSearchFieldText(text, animated);
|
2015-03-19 00:09:45 +01:00
|
|
|
item.getSearchField().setSelection(text.length());
|
|
|
|
break;
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
public void setFilter(FiltersView.MediaFilterData filter) {
|
|
|
|
int count = getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = getChildAt(a);
|
|
|
|
if (view instanceof ActionBarMenuItem) {
|
|
|
|
ActionBarMenuItem item = (ActionBarMenuItem) view;
|
|
|
|
if (item.isSearchField()) {
|
|
|
|
item.addSearchFilter(filter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
public ActionBarMenuItem getItem(int id) {
|
|
|
|
View v = findViewWithTag(id);
|
|
|
|
if (v instanceof ActionBarMenuItem) {
|
2015-07-22 20:56:37 +02:00
|
|
|
return (ActionBarMenuItem) v;
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setEnabled(boolean enabled) {
|
|
|
|
super.setEnabled(enabled);
|
|
|
|
int count = getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = getChildAt(a);
|
|
|
|
view.setEnabled(enabled);
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 01:31:48 +02:00
|
|
|
}
|