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

132 lines
4.2 KiB
Java
Raw Normal View History

2015-05-21 23:27:27 +02:00
/*
2019-01-23 18:03:33 +01:00
* This is the source code of Telegram for Android v. 5.x.x.
2015-05-21 23:27:27 +02:00
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
2019-01-23 18:03:33 +01:00
* Copyright Nikolai Kudashov, 2013-2018.
2015-05-21 23:27:27 +02:00
*/
package org.telegram.ui.Components;
import android.content.Context;
2019-05-14 14:08:05 +02:00
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
2015-05-21 23:27:27 +02:00
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.LocaleController;
2015-05-21 23:27:27 +02:00
import org.telegram.messenger.R;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.ActionBar.Theme;
2015-05-21 23:27:27 +02:00
public class EmptyTextProgressView extends FrameLayout {
private TextView textView;
2017-03-31 01:58:05 +02:00
private RadialProgressView progressBar;
2015-05-21 23:27:27 +02:00
private boolean inLayout;
private boolean showAtCenter;
public EmptyTextProgressView(Context context) {
super(context);
2017-03-31 01:58:05 +02:00
progressBar = new RadialProgressView(context);
2015-05-21 23:27:27 +02:00
progressBar.setVisibility(INVISIBLE);
addView(progressBar, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
textView = new TextView(context);
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
2017-03-31 01:58:05 +02:00
textView.setTextColor(Theme.getColor(Theme.key_emptyListPlaceholder));
2015-05-21 23:27:27 +02:00
textView.setGravity(Gravity.CENTER);
textView.setVisibility(INVISIBLE);
2015-07-22 20:56:37 +02:00
textView.setPadding(AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20), 0);
2015-05-21 23:27:27 +02:00
textView.setText(LocaleController.getString("NoResult", R.string.NoResult));
addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
2018-08-27 10:33:11 +02:00
setOnTouchListener((v, event) -> true);
2015-05-21 23:27:27 +02:00
}
public void showProgress() {
textView.setVisibility(INVISIBLE);
progressBar.setVisibility(VISIBLE);
}
public void showTextView() {
textView.setVisibility(VISIBLE);
progressBar.setVisibility(INVISIBLE);
}
public void setText(String text) {
textView.setText(text);
}
2017-03-31 01:58:05 +02:00
public void setTextColor(int color) {
textView.setTextColor(color);
}
public void setProgressBarColor(int color) {
progressBar.setProgressColor(color);
}
2019-05-14 14:08:05 +02:00
public void setTopImage(int resId) {
if (resId == 0) {
textView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
} else {
Drawable drawable = getContext().getResources().getDrawable(resId).mutate();
if (drawable != null) {
drawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_emptyListPlaceholder), PorterDuff.Mode.MULTIPLY));
}
textView.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);
textView.setCompoundDrawablePadding(AndroidUtilities.dp(1));
}
}
2015-10-29 18:10:07 +01:00
public void setTextSize(int size) {
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, size);
}
2015-05-21 23:27:27 +02:00
public void setShowAtCenter(boolean value) {
showAtCenter = value;
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
inLayout = true;
int width = r - l;
int height = b - t;
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
int x = (width - child.getMeasuredWidth()) / 2;
int y;
if (showAtCenter) {
2019-07-18 15:01:39 +02:00
y = (height / 2 - child.getMeasuredHeight()) / 2 + getPaddingTop();
2015-05-21 23:27:27 +02:00
} else {
2019-07-18 15:01:39 +02:00
y = (height - child.getMeasuredHeight()) / 2 + getPaddingTop();
2015-05-21 23:27:27 +02:00
}
child.layout(x, y, x + child.getMeasuredWidth(), y + child.getMeasuredHeight());
}
inLayout = false;
}
@Override
public void requestLayout() {
if (!inLayout) {
super.requestLayout();
}
}
2016-05-25 23:49:47 +02:00
@Override
public boolean hasOverlappingRendering() {
return false;
}
2015-05-21 23:27:27 +02:00
}