管灌系统巡查员智能手机App
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/**
 *
 */
package com.dayu.pipirrapp.view;
 
import android.app.Activity;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
 
import com.dayu.pipirrapp.R;
 
 
/***
 * 标题视图
 *
 * @author shisl
 * @time 2015-4-29
 */
public class TitleBar  {
    /**
     * 左侧/右侧图标和中间标题
     */
    private View titleView;
 
    /**
     * 左侧/右侧图标和中间标题
     */
    private RelativeLayout rl_title_bar;
 
    /**
     * 跟布局
     */
    private LinearLayout ll_title_bar;
 
    /**
     * 左侧图标
     */
    private ImageView iv_left_icon;
 
    /**
     * 右侧图标
     */
    private ImageView iv_rightIco;
 
    /**
     * 中间标题
     */
    private TextView tv_title_middle;
 
    /**
     * 右侧标题
     */
    private TextView tv_title_right;
 
    /**
     * 构造方法:用于获取对象
     */
    public TitleBar(Activity context) {
        titleView = context.findViewById(R.id.rl_title_bar);
        rl_title_bar = (RelativeLayout) titleView.findViewById(R.id.rl_title_bar);
        ll_title_bar = (LinearLayout) context.findViewById(R.id.ll_title_bar);
        tv_title_middle = (TextView) titleView.findViewById(R.id.tv_title_middle);
        tv_title_right = (TextView) titleView.findViewById(R.id.tv_title_right);
        iv_left_icon = (ImageView) titleView.findViewById(R.id.iv_left_icon);
        iv_rightIco = (ImageView) titleView.findViewById(R.id.iv_rightIco);
    }
 
    /**
     * 用于设置标题栏文字
     *
     * @param titleText 传入要设置的标题
     * @return
     */
    public TitleBar setTitleText(String titleText) {
        if (!TextUtils.isEmpty(titleText)) {
            tv_title_middle.setText(titleText);
        }
        return this;
    }
 
    /**
     * 设置标题栏文字颜色
     *
     * @return
     */
    public TitleBar setTitleTextColor() {
        tv_title_middle.setTextColor(Color.WHITE);
        return this;
    }
 
    /**
     * 设置标题栏右边的文字
     *
     * @return
     */
    public TitleBar setTitleRight(String rightTitle) {
        if (!TextUtils.isEmpty(rightTitle)) {
            tv_title_right.setVisibility(View.VISIBLE);
            iv_rightIco.setVisibility(View.GONE);
            tv_title_right.setTextColor(Color.WHITE);
            tv_title_right.setText(rightTitle);
        }
        return this;
    }
 
 
    /**
     * 用于设置标题栏左边要显示的图片
     *
     * @param resId 标题栏左边的图标的id,一般为返回图标
     * @return
     */
    public TitleBar setLeftIco(int resId) {
        iv_left_icon.setVisibility(resId > 0 ? View.VISIBLE : View.GONE);
        iv_left_icon.setImageResource(resId);
        return this;
    }
 
    /**
     * 用于设置标题栏左边要显示的图片
     *
     * @return
     */
    public TitleBar setLeftIco() {
        iv_left_icon.setVisibility(View.VISIBLE);
        iv_left_icon.setImageResource(R.drawable.vector_arrows_left_white);
        return this;
    }
 
 
    /**
     * 用于设置标题栏右边要显示的图片
     *
     * @param resId 标题栏右边的图标id
     * @return
     */
    public TitleBar setRightIco(int resId) {
        iv_rightIco.setVisibility(resId > 0 ? View.VISIBLE : View.GONE);
        iv_rightIco.setImageResource(resId);
        return this;
    }
 
    /**
     * 用户设置 标题栏右侧的图标的背景drawable
     *
     * @param resId drawable的id
     * @return
     */
    public TitleBar setRightIconBgDr(int resId) {
        iv_rightIco.setVisibility(resId > 0 ? View.VISIBLE : View.GONE);
//            iv_rightIco.setImageResource(R.drawable.ic_back_selector);
        return this;
    }
 
 
    /**
     * 用户设置 标题栏右侧的图标的背景drawable
     *
     * @return
     */
    public TitleBar setRightIconBgDr() {
        iv_rightIco.setVisibility(View.GONE);
//            iv_rightIco.setImageResource(R.drawable.ic_back_selector);
        return this;
    }
 
    /**
     * 用于设置标题栏左边图片的单击事件
     *
     * @param listener 传入的事件对象
     * @return
     */
    public TitleBar setLeftIcoListening(View.OnClickListener listener) {
        if (iv_left_icon.getVisibility() == View.VISIBLE) {
            iv_left_icon.setOnClickListener(listener);
        }
        return this;
    }
 
    /**
     * 用于设置标题栏右边图片的单击事件
     *
     * @param listener 传入的事件对象
     * @return
     */
    public TitleBar setRightIcoListening(View.OnClickListener listener) {
 
        if (iv_rightIco.getVisibility() == View.VISIBLE) {
            iv_rightIco.setOnClickListener(listener);
        }
        return this;
    }
}