NekoX/TMessagesProj/src/main/java/org/telegram/ui/Components/PickerBottomLayout.java

130 lines
6.7 KiB
Java
Raw Normal View History

2015-01-02 23:15:07 +01:00
/*
* This is the source code of Telegram for Android v. 2.0.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.
2015-01-02 23:15:07 +01:00
*/
package org.telegram.ui.Components;
import android.content.Context;
2017-03-31 01:58:05 +02:00
import android.graphics.drawable.Drawable;
2015-01-02 23:15:07 +01:00
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
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.LocaleController;
2015-01-02 23:15:07 +01:00
import org.telegram.messenger.R;
2016-04-22 15:49:00 +02:00
import org.telegram.ui.ActionBar.Theme;
2015-01-02 23:15:07 +01:00
2015-07-22 20:56:37 +02:00
public class PickerBottomLayout extends FrameLayout {
2015-01-02 23:15:07 +01:00
public LinearLayout doneButton;
2015-01-02 23:15:07 +01:00
public TextView cancelButton;
2020-06-25 17:28:55 +02:00
public LinearLayout middleButton;
public TextView middleButtonTextView;
2015-01-02 23:15:07 +01:00
public TextView doneButtonTextView;
public TextView doneButtonBadgeTextView;
2022-06-21 04:51:00 +02:00
private Theme.ResourcesProvider resourcesProvider;
2015-01-02 23:15:07 +01:00
2015-07-22 20:56:37 +02:00
public PickerBottomLayout(Context context) {
2022-06-21 04:51:00 +02:00
this(context, true, null);
2015-07-22 20:56:37 +02:00
}
public PickerBottomLayout(Context context, boolean darkTheme) {
2022-06-21 04:51:00 +02:00
this(context, darkTheme, null);
}
public PickerBottomLayout(Context context, boolean darkTheme, Theme.ResourcesProvider resourcesProvider) {
2015-01-02 23:15:07 +01:00
super(context);
2022-06-21 04:51:00 +02:00
this.resourcesProvider = resourcesProvider;
2015-07-22 20:56:37 +02:00
2022-06-21 04:51:00 +02:00
setBackgroundColor(Theme.getColor(darkTheme ? Theme.key_dialogBackground : Theme.key_windowBackgroundWhite, resourcesProvider));
2015-01-02 23:15:07 +01:00
cancelButton = new TextView(context);
cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
2022-06-21 04:51:00 +02:00
cancelButton.setTextColor(Theme.getColor(Theme.key_picker_enabledButton, resourcesProvider));
2015-01-02 23:15:07 +01:00
cancelButton.setGravity(Gravity.CENTER);
2022-06-21 04:51:00 +02:00
cancelButton.setBackground(Theme.createSelectorDrawable(Theme.getColor(Theme.key_picker_enabledButton, resourcesProvider) & 0x0fffffff, 0));
2019-12-31 14:08:08 +01:00
cancelButton.setPadding(AndroidUtilities.dp(33), 0, AndroidUtilities.dp(33), 0);
2015-01-02 23:15:07 +01:00
cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase());
cancelButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
2015-11-26 22:04:02 +01:00
addView(cancelButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
2015-01-02 23:15:07 +01:00
2020-06-25 17:28:55 +02:00
LinearLayout rightLayout = new LinearLayout(context);
rightLayout.setOrientation(LinearLayout.HORIZONTAL);
rightLayout.setGravity(Gravity.CENTER_VERTICAL);
addView(rightLayout, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT));
middleButton = new LinearLayout(context);
middleButton.setOrientation(LinearLayout.HORIZONTAL);
middleButton.setBackgroundDrawable(Theme.createSelectorDrawable(0x0f000000, 0));
middleButton.setPadding(AndroidUtilities.dp(33), 0, AndroidUtilities.dp(33), 0);
middleButton.setVisibility(GONE);
rightLayout.addView(middleButton);
middleButtonTextView = new TextView(context);
middleButtonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
middleButtonTextView.setTextColor(Theme.getColor(Theme.key_picker_enabledButton));
middleButtonTextView.setGravity(Gravity.CENTER);
middleButtonTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8));
middleButtonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
middleButton.addView(middleButtonTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL));
doneButton = new LinearLayout(context);
doneButton.setOrientation(LinearLayout.HORIZONTAL);
2022-06-21 04:51:00 +02:00
doneButton.setBackground(Theme.createSelectorDrawable(Theme.getColor(Theme.key_picker_enabledButton, resourcesProvider) & 0x0fffffff, 0));
2019-12-31 14:08:08 +01:00
doneButton.setPadding(AndroidUtilities.dp(33), 0, AndroidUtilities.dp(33), 0);
2020-06-25 17:28:55 +02:00
rightLayout.addView(doneButton);
2015-01-02 23:15:07 +01:00
doneButtonBadgeTextView = new TextView(context);
doneButtonBadgeTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
doneButtonBadgeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
2022-06-21 04:51:00 +02:00
doneButtonBadgeTextView.setTextColor(Theme.getColor(Theme.key_picker_badgeText, resourcesProvider));
2015-01-02 23:15:07 +01:00
doneButtonBadgeTextView.setGravity(Gravity.CENTER);
2022-06-21 04:51:00 +02:00
Drawable drawable = Theme.createRoundRectDrawable(AndroidUtilities.dp(11), Theme.getColor(Theme.key_picker_badge, resourcesProvider));
2017-03-31 01:58:05 +02:00
doneButtonBadgeTextView.setBackgroundDrawable(drawable);
2015-01-02 23:15:07 +01:00
doneButtonBadgeTextView.setMinWidth(AndroidUtilities.dp(23));
doneButtonBadgeTextView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), AndroidUtilities.dp(1));
2015-11-26 22:04:02 +01:00
doneButton.addView(doneButtonBadgeTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 23, Gravity.CENTER_VERTICAL, 0, 0, 10, 0));
2015-01-02 23:15:07 +01:00
doneButtonTextView = new TextView(context);
doneButtonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
2022-06-21 04:51:00 +02:00
doneButtonTextView.setTextColor(Theme.getColor(Theme.key_picker_enabledButton, resourcesProvider));
2015-01-02 23:15:07 +01:00
doneButtonTextView.setGravity(Gravity.CENTER);
doneButtonTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8));
doneButtonTextView.setText(LocaleController.getString("Send", R.string.Send).toUpperCase());
doneButtonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
2015-11-26 22:04:02 +01:00
doneButton.addView(doneButtonTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL));
2015-01-02 23:15:07 +01:00
}
public void updateSelectedCount(int count, boolean disable) {
if (count == 0) {
doneButtonBadgeTextView.setVisibility(View.GONE);
if (disable) {
2019-08-22 01:53:26 +02:00
doneButtonTextView.setTag(Theme.key_picker_disabledButton);
2022-06-21 04:51:00 +02:00
doneButtonTextView.setTextColor(Theme.getColor(Theme.key_picker_disabledButton, resourcesProvider));
2015-01-02 23:15:07 +01:00
doneButton.setEnabled(false);
} else {
2019-08-22 01:53:26 +02:00
doneButtonTextView.setTag(Theme.key_picker_enabledButton);
2022-06-21 04:51:00 +02:00
doneButtonTextView.setTextColor(Theme.getColor(Theme.key_picker_enabledButton, resourcesProvider));
2015-01-02 23:15:07 +01:00
}
} else {
doneButtonBadgeTextView.setVisibility(View.VISIBLE);
doneButtonBadgeTextView.setText(String.format("%d", count));
2019-08-22 01:53:26 +02:00
doneButtonTextView.setTag(Theme.key_picker_enabledButton);
2022-06-21 04:51:00 +02:00
doneButtonTextView.setTextColor(Theme.getColor(Theme.key_picker_enabledButton, resourcesProvider));
2015-01-02 23:15:07 +01:00
if (disable) {
doneButton.setEnabled(true);
}
}
}
}