Commit 4801fa6f468394effa71989eff511897562a56e9
1 parent
793e2ae4
添加资源文件,类文件
Showing
15 changed files
with
327 additions
and
0 deletions
C5/app/src/main/java/com/sunvote/xpadapp/server/BatteryReceiver.java
0 → 100644
1 | +package com.sunvote.xpadapp.server; | |
2 | + | |
3 | +import android.content.BroadcastReceiver; | |
4 | +import android.content.Context; | |
5 | +import android.content.Intent; | |
6 | +import android.util.Log; | |
7 | + | |
8 | +public class BatteryReceiver extends BroadcastReceiver { | |
9 | + int mCurrentLevel = 0; | |
10 | + int m_total = 0; | |
11 | + String m_strPercent; | |
12 | + | |
13 | + @Override | |
14 | + public void onReceive(Context context, Intent intent) { | |
15 | + final String action = intent.getAction(); | |
16 | + if (action.equalsIgnoreCase(Intent.ACTION_BATTERY_CHANGED)) { | |
17 | + Log.i("james-fan", "get battery change broad"); | |
18 | + } | |
19 | + // mCurrentLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); | |
20 | + //m_total = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1); | |
21 | + mCurrentLevel = intent.getExtras().getInt("level");// 获得当前电量 | |
22 | + m_total = intent.getExtras().getInt("scale");// 获得总电量 | |
23 | + int percent = mCurrentLevel * 100 / m_total; | |
24 | + m_strPercent = percent + "%"; | |
25 | + iReceiveData.onReceiveData(); | |
26 | + } | |
27 | + | |
28 | + public int getCurrentLevel() { | |
29 | + return mCurrentLevel; | |
30 | + } | |
31 | + | |
32 | + public int getTotal() { | |
33 | + return m_total; | |
34 | + } | |
35 | + | |
36 | + public String getBatteryPercent() { | |
37 | + return m_strPercent; | |
38 | + } | |
39 | + | |
40 | + private IReceiveData iReceiveData; | |
41 | + public void setOnReceiveResultData(IReceiveData receiveData){ | |
42 | + iReceiveData = receiveData; | |
43 | + } | |
44 | + | |
45 | + public interface IReceiveData{ | |
46 | + void onReceiveData(); | |
47 | + } | |
48 | +} | |
0 | 49 | \ No newline at end of file | ... | ... |
C5/app/src/main/java/com/sunvote/xpadapp/widget/StatusBarView.java
0 → 100644
1 | +package com.sunvote.xpadapp.widget; | |
2 | + | |
3 | +import android.annotation.SuppressLint; | |
4 | +import android.content.Context; | |
5 | +import android.content.Intent; | |
6 | +import android.content.IntentFilter; | |
7 | +import android.util.AttributeSet; | |
8 | +import android.view.LayoutInflater; | |
9 | +import android.view.View; | |
10 | +import android.view.ViewGroup; | |
11 | +import android.widget.LinearLayout; | |
12 | + | |
13 | +import com.sunvote.statusbar.view.BarItem; | |
14 | +import com.sunvote.xpadapp.R; | |
15 | + | |
16 | +public class StatusBarView extends LinearLayout { | |
17 | + Context mContext; | |
18 | + //信号图标,基站编号,CH,终端ID,电池电量图标,系统时间 | |
19 | + BarItem barSignal,barBasestation,barCh,barTerminalId,barBattery,barSystemtime; | |
20 | + | |
21 | + public StatusBarView(Context context) { | |
22 | + this(context, null); | |
23 | + } | |
24 | + | |
25 | + public StatusBarView(Context context, AttributeSet attrs) { | |
26 | + this(context, attrs, 0); | |
27 | + } | |
28 | + | |
29 | + View view; | |
30 | + @SuppressLint("NewApi") | |
31 | + public StatusBarView(Context context, AttributeSet attrs, int defStyle) { | |
32 | + super(context, attrs, defStyle); | |
33 | + init(context, attrs, defStyle); | |
34 | + } | |
35 | + | |
36 | + private void init(Context ctx, AttributeSet attrs, int defStyle){ | |
37 | + mContext=ctx; | |
38 | + LayoutInflater ll = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
39 | + ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT); | |
40 | + view = ll.inflate(R.layout.status_icon_view, null); | |
41 | + view.setLayoutParams(lp); | |
42 | + | |
43 | + barSignal = (BarItem)view.findViewById(R.id.bar_signal); | |
44 | + barBasestation = (BarItem) view.findViewById(R.id.bar_basestation); | |
45 | + barCh = (BarItem) view.findViewById(R.id.bar_ch); | |
46 | + barTerminalId = (BarItem) view.findViewById(R.id.bar_terminalId); | |
47 | + barBattery = (BarItem) view.findViewById(R.id.bar_battery); | |
48 | + barSystemtime = (BarItem) view.findViewById(R.id.bar_systemtime); | |
49 | + addView(view); | |
50 | + } | |
51 | + | |
52 | + public void setBackgroundColor(int color){ | |
53 | + view.setBackgroundColor(color); | |
54 | + } | |
55 | + /** | |
56 | + * 设置信号图标 | |
57 | + * @param rssi | |
58 | + */ | |
59 | + public void setStatusSignal(int rssi){ | |
60 | + barSignal.setIcon(R.mipmap.signal); | |
61 | + if (rssi < 95){ | |
62 | + barSignal.setIcon(R.mipmap.signal_1); | |
63 | + } | |
64 | + if (rssi < 85){ | |
65 | + barSignal.setIcon(R.mipmap.signal_2); | |
66 | + } | |
67 | + if (rssi < 75) { | |
68 | + barSignal.setIcon(R.mipmap.signal_3); | |
69 | + } | |
70 | + if (rssi < 65) { | |
71 | + barSignal.setIcon(R.mipmap.signal_4); | |
72 | + } | |
73 | + if (rssi < 55) { | |
74 | + barSignal.setIcon(R.mipmap.signal_5); | |
75 | + } | |
76 | + } | |
77 | + | |
78 | + /** | |
79 | + * 设置基站编号 | |
80 | + * @param value | |
81 | + */ | |
82 | + public void setStatusBarBaseId(int value){ | |
83 | + barBasestation.setText(String.format("基站编号:%s",value+"")); | |
84 | + } | |
85 | + | |
86 | + /** | |
87 | + * 设置CH | |
88 | + * @param value | |
89 | + */ | |
90 | + public void setStatusCH(int value){ | |
91 | + barCh.setText(String.format("CH:%s",value)); | |
92 | + } | |
93 | + | |
94 | + /** | |
95 | + * 设置终端编号 | |
96 | + * @param value | |
97 | + */ | |
98 | + public void setStatusKeyId(int value){ | |
99 | + barTerminalId.setText(String.format("终端编号:%s",value)); | |
100 | + } | |
101 | + | |
102 | + /** | |
103 | + * 设置电量 | |
104 | + * @param battery | |
105 | + */ | |
106 | + public void setStatusBattery(int battery, String BatteryPercent){ | |
107 | + if(battery > 0 && battery <= 10){ | |
108 | + barBattery.setIcon(R.mipmap.battery); | |
109 | + }else if(battery > 10 && battery <= 40){ | |
110 | + barBattery.setIcon(R.mipmap.battery_1); | |
111 | + }else if(battery > 40 && battery <= 60){ | |
112 | + barBattery.setIcon(R.mipmap.battery_2); | |
113 | + }else if(battery > 60 && battery <= 80){ | |
114 | + barBattery.setIcon(R.mipmap.battery_3); | |
115 | + }else if(battery > 80 && battery <= 100){ | |
116 | + barBattery.setIcon(R.mipmap.battery_4); | |
117 | + }else{ | |
118 | + barBattery.setIcon(R.mipmap.battery); | |
119 | + } | |
120 | + barBattery.setText(BatteryPercent); | |
121 | + } | |
122 | + | |
123 | + /** | |
124 | + * 返回时间控件 | |
125 | + * @param | |
126 | + */ | |
127 | + public BarItem getTimeCtl(){ | |
128 | + return barSystemtime; | |
129 | + } | |
130 | +} | ... | ... |
C5/app/src/main/java/com/sunvote/xpadapp/widget/TimeThread.java
0 → 100644
1 | +package com.sunvote.xpadapp.widget; | |
2 | +import android.os.Handler; | |
3 | +import android.os.Message; | |
4 | +import android.widget.TextView; | |
5 | + | |
6 | +import com.sunvote.statusbar.view.BarItem; | |
7 | + | |
8 | +import java.text.SimpleDateFormat; | |
9 | +import java.util.Calendar; | |
10 | +import java.util.Date; | |
11 | + | |
12 | +/** | |
13 | + * Copyright: Copyright (c) 2018-2025 | |
14 | + * Class: 实时更新时间的线程 | |
15 | + * | |
16 | + * @author: | |
17 | + * @date: 2018/11/21 | |
18 | + * describe: | |
19 | + */ | |
20 | +public class TimeThread extends Thread { | |
21 | + public BarItem tvDate; | |
22 | + private int msgKey1 = 22; | |
23 | + | |
24 | + public TimeThread(BarItem tvDate) { | |
25 | + this.tvDate = tvDate; | |
26 | + } | |
27 | + | |
28 | + @Override | |
29 | + public void run() { | |
30 | + do { | |
31 | + try { | |
32 | + Thread.sleep(1000); | |
33 | + Message msg = new Message(); | |
34 | + msg.what = msgKey1; | |
35 | + mHandler.sendMessage(msg); | |
36 | + } catch (InterruptedException e) { | |
37 | + e.printStackTrace(); | |
38 | + } | |
39 | + } while (true); | |
40 | + } | |
41 | + | |
42 | + private Handler mHandler = new Handler() { | |
43 | + @Override | |
44 | + public void handleMessage(Message msg) { | |
45 | + super.handleMessage(msg); | |
46 | + switch (msg.what) { | |
47 | + case 22: | |
48 | + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); | |
49 | + String date = sdf.format(new Date()); | |
50 | + tvDate.setText(date + getWeek()); | |
51 | + break; | |
52 | + | |
53 | + default: | |
54 | + break; | |
55 | + } | |
56 | + } | |
57 | + }; | |
58 | + | |
59 | + /** | |
60 | + * 获取今天星期几 | |
61 | + * @return | |
62 | + */ | |
63 | + public static String getWeek() { | |
64 | + Calendar cal = Calendar.getInstance(); | |
65 | + int i = cal.get(Calendar.DAY_OF_WEEK); | |
66 | + switch (i) { | |
67 | + case 1: | |
68 | + return "周日"; | |
69 | + case 2: | |
70 | + return "周一"; | |
71 | + case 3: | |
72 | + return "周二"; | |
73 | + case 4: | |
74 | + return "周三"; | |
75 | + case 5: | |
76 | + return "周四"; | |
77 | + case 6: | |
78 | + return "周五"; | |
79 | + case 7: | |
80 | + return "周六"; | |
81 | + default: | |
82 | + return ""; | |
83 | + } | |
84 | + } | |
85 | +} | ... | ... |
C5/app/src/main/res/layout/status_icon_view.xml
0 → 100644
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<com.sunvote.statusbar.view.StatusBar | |
3 | + xmlns:android="http://schemas.android.com/apk/res/android" | |
4 | + xmlns:tools="http://schemas.android.com/tools" | |
5 | + android:layout_width="match_parent" | |
6 | + android:layout_height="@dimen/status_bar_height" | |
7 | + android:orientation="horizontal" | |
8 | + android:padding="2dp" | |
9 | + android:dividerPadding="2dp" | |
10 | + android:showDividers="middle" | |
11 | + android:divider="@drawable/status_bar_divider" | |
12 | + android:gravity="left|center_vertical" | |
13 | + tools:ignore="MissingDefaultResource"> | |
14 | + <com.sunvote.statusbar.view.BarItem | |
15 | + android:id="@+id/bar_signal" | |
16 | + android:layout_width="wrap_content" | |
17 | + android:layout_height="match_parent" | |
18 | + android:gravity="left|center_vertical" | |
19 | + android:layout_weight="1" | |
20 | + android:text="" | |
21 | + android:textColor="@android:color/white"/> | |
22 | + <com.sunvote.statusbar.view.BarItem | |
23 | + android:id="@+id/bar_basestation" | |
24 | + android:layout_width="wrap_content" | |
25 | + android:layout_height="match_parent" | |
26 | + android:gravity="left" | |
27 | + android:visibility="invisible" | |
28 | + android:text="" | |
29 | + android:layout_weight="0.1" | |
30 | + android:textColor="@android:color/white"/> | |
31 | + <com.sunvote.statusbar.view.BarItem | |
32 | + android:id="@+id/bar_ch" | |
33 | + android:layout_width="wrap_content" | |
34 | + android:layout_height="match_parent" | |
35 | + android:gravity="right" | |
36 | + android:text="" | |
37 | + android:visibility="invisible" | |
38 | + android:layout_weight="1" | |
39 | + android:textColor="@android:color/white"/> | |
40 | + <com.sunvote.statusbar.view.BarItem | |
41 | + android:id="@+id/bar_terminalId" | |
42 | + android:layout_width="wrap_content" | |
43 | + android:layout_height="match_parent" | |
44 | + android:gravity="center" | |
45 | + android:text="" | |
46 | + android:layout_weight="8" | |
47 | + android:textColor="@android:color/white"/> | |
48 | + <com.sunvote.statusbar.view.BarItem | |
49 | + android:id="@+id/bar_systemtime" | |
50 | + android:layout_width="wrap_content" | |
51 | + android:layout_height="match_parent" | |
52 | + android:gravity="right|center" | |
53 | + android:text="" | |
54 | + android:layout_weight="2" | |
55 | + android:textColor="@android:color/white"/> | |
56 | + <com.sunvote.statusbar.view.BarItem | |
57 | + android:id="@+id/bar_battery" | |
58 | + android:layout_width="wrap_content" | |
59 | + android:layout_height="match_parent" | |
60 | + android:gravity="right|center" | |
61 | + android:text="" | |
62 | + android:layout_weight="0.1" | |
63 | + android:textColor="@android:color/white"/> | |
64 | +</com.sunvote.statusbar.view.StatusBar> | ... | ... |
C5/app/src/main/res/mipmap-hdpi/battery.png
0 → 100644
15.4 KB
C5/app/src/main/res/mipmap-hdpi/battery_1.png
0 → 100644
15.5 KB
C5/app/src/main/res/mipmap-hdpi/battery_2.png
0 → 100644
15.5 KB
C5/app/src/main/res/mipmap-hdpi/battery_3.png
0 → 100644
15.5 KB
C5/app/src/main/res/mipmap-hdpi/battery_4.png
0 → 100644
15.4 KB
C5/app/src/main/res/mipmap-hdpi/signal.png
0 → 100644
16 KB
C5/app/src/main/res/mipmap-hdpi/signal_1.png
0 → 100644
16.1 KB
C5/app/src/main/res/mipmap-hdpi/signal_2.png
0 → 100644
16.2 KB
C5/app/src/main/res/mipmap-hdpi/signal_3.png
0 → 100644
16.2 KB
C5/app/src/main/res/mipmap-hdpi/signal_4.png
0 → 100644
16.2 KB
C5/app/src/main/res/mipmap-hdpi/signal_5.png
0 → 100644
15.7 KB