1
wxr
2023-04-23 2cd55265ccff3b0a267d7953b2dd9e5dca437aa6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package com.videogo.widget.loading;
 
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
 
import ezviz.ezopensdk.R;
 
public class LoadingTextView extends FrameLayout {
 
    public static final int NOTEXT = -1;
    public static final int HORIZONTAL = 0;
    public static final int VERTICAL = 1;
 
    private LinearLayout mParentLayout;
    private LoadingView mLoadingView;
    private TextView mTextView;
 
    private int mTextPadding;
 
    public LoadingTextView(Context context) {
        this(context, null);
    }
 
    public LoadingTextView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }
 
    public LoadingTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
 
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LoadingTextView, defStyle,
                R.style.LoadingTextView);
        int style = a.getInt(R.styleable.LoadingTextView_textStyle, LinearLayout.VERTICAL);
        int gravity = a.getInt(R.styleable.LoadingTextView_gravity, Gravity.CENTER);
        ColorStateList textColor = a.getColorStateList(R.styleable.LoadingTextView_textColor);
        int textSize = a.getDimensionPixelOffset(R.styleable.LoadingTextView_textSize, 15);
        mTextPadding = a.getDimensionPixelOffset(R.styleable.LoadingTextView_textPadding, 0);
        CharSequence text = a.getText(R.styleable.LoadingTextView_android_text);
        a.recycle();
 
        LayoutInflater layoutInflater = LayoutInflater.from(context);
        View view = layoutInflater.inflate(R.layout.loading_text_view, this, false);
        addView(view);
 
        mParentLayout = (LinearLayout) view;
        mLoadingView = (LoadingView) view.findViewById(R.id.loading_view);
        mTextView = (TextView) view.findViewById(R.id.loading_text);
 
        setTextStyle(style);
        mParentLayout.setGravity(gravity);
 
        mTextView.setTextColor(textColor);
        mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        setText(text);
    }
 
    public void setTextStyle(int style) {
        if (style == -1) {
            mTextView.setVisibility(View.GONE);
        } else {
            if (style != mParentLayout.getOrientation()) {
                mParentLayout.setOrientation(style);
                LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mTextView.getLayoutParams();
                if (style == LinearLayout.VERTICAL) {
                    layoutParams.leftMargin = 0;
                    layoutParams.topMargin = mTextPadding;
                } else {
                    layoutParams.leftMargin = mTextPadding;
                    layoutParams.topMargin = 0;
                }
            }
            mTextView.setVisibility(View.VISIBLE);
        }
    }
 
    public void setText(CharSequence text) {
        mTextView.setText(text);
    }
 
    public void setText(int resid) {
        mTextView.setText(resid);
    }
}