Skip to content

Commit de1a552

Browse files
committed
update cpu voltage ui
1 parent c92aadf commit de1a552

File tree

13 files changed

+179
-19
lines changed

13 files changed

+179
-19
lines changed

app/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
android:targetSdkVersion="24" />
99

1010
<application
11-
android:allowBackup="true"
1211
android:name="com.fadisu.cpurun.MyApplication"
12+
android:allowBackup="true"
1313
android:icon="@mipmap/ic_launcher"
1414
android:label="@string/app_name"
1515
android:supportsRtl="true"

app/src/main/java/com/fadisu/cpurun/activity/MainActivity.java

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.fadisu.cpurun.fragment.CpuRunTimeFragment;
1616
import com.fadisu.cpurun.fragment.CpuSceneFragment;
1717
import com.fadisu.cpurun.fragment.CpuStatusFragment;
18+
import com.fadisu.cpurun.fragment.CpuVoltageFragment;
1819
import com.fadisu.cpurun.fragment.DisplayFragment;
1920
import com.fadisu.cpurun.fragment.MemInfoFragment;
2021
import com.fadisu.cpurun.fragment.MoreFragment;
@@ -38,6 +39,7 @@ public class MainActivity extends FragmentActivity implements View.OnClickListen
3839
private Fragment mCpuStatusFragment;
3940
private Fragment mCpuSceneFragment;
4041
private Fragment mCpuRunTimeFragment;
42+
private Fragment mCpuVoltageFragment;
4143
private FragmentManager mFragmentManager;
4244

4345
private RadioButton mSysRb;
@@ -51,6 +53,8 @@ public class MainActivity extends FragmentActivity implements View.OnClickListen
5153
private RadioButton mDisplayRb;
5254
private RadioButton mBuildInfoRb;
5355
private RadioButton mCpuSceneFreq;
56+
private RadioButton mCpuVoltageRb;
57+
5458

5559
@Override
5660
protected void onCreate(Bundle savedInstanceState) {
@@ -80,6 +84,7 @@ private void initViews() {
8084
mCpuStatus = (RadioButton) findViewById(R.id.rb_cpu_status);
8185
mBuildInfoRb = (RadioButton) findViewById(R.id.rb_build_info);
8286
mCpuSceneFreq = (RadioButton) findViewById(R.id.rb_scene_freq);
87+
mCpuVoltageRb = (RadioButton) findViewById(R.id.rb_cpu_voltage);
8388
}
8489

8590
private void initValues() {
@@ -97,6 +102,7 @@ private void initValues() {
97102
mCpuStatusFragment = new CpuStatusFragment();
98103
mCpuRunTimeFragment = new CpuRunTimeFragment();
99104
mFragmentManager = getSupportFragmentManager();
105+
mCpuVoltageFragment = new CpuVoltageFragment();
100106

101107
changeFrament(mBaseInfoFragment, null, CoreInfoFragment.class.getSimpleName());
102108
}
@@ -113,6 +119,7 @@ private void initLisener() {
113119
mCpuStatus.setOnClickListener(this);
114120
mBuildInfoRb.setOnClickListener(this);
115121
mCpuSceneFreq.setOnClickListener(this);
122+
mCpuVoltageRb.setOnClickListener(this);
116123
}
117124

118125

@@ -140,6 +147,9 @@ public void changeFrament(Fragment fragment, Bundle bundle, String tag) {
140147
@Override
141148
public void onClick(View view) {
142149
switch (view.getId()) {
150+
case R.id.rb_cpu_voltage:
151+
changeFrament(mCpuVoltageFragment, null, CpuVoltageFragment.class.getSimpleName());
152+
break;
143153
case R.id.rb_scene_freq:
144154
changeFrament(mCpuSceneFragment, null, CpuSceneFragment.class.getSimpleName());
145155
break;

app/src/main/java/com/fadisu/cpurun/fragment/CpuStatusFragment.java

-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public void run() {
9191
if (null != result) {
9292
result.clear();
9393
result.addAll(CpuUtils.getCpuCurFreq(mContext));
94-
result.addAll(CpuUtils.getCpuVoltage());
9594
mHandler.sendEmptyMessage(UPDATE_UI);
9695
}
9796

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package com.fadisu.cpurun.fragment;
2+
3+
import android.content.Context;
4+
import android.os.Bundle;
5+
import android.os.Handler;
6+
import android.os.Message;
7+
import android.support.v4.app.Fragment;
8+
import android.view.LayoutInflater;
9+
import android.view.View;
10+
import android.view.ViewGroup;
11+
import android.widget.ListView;
12+
import android.widget.TextView;
13+
14+
import com.fadisu.cpurun.R;
15+
import com.fadisu.cpurun.adapter.CustomAdapter;
16+
import com.fadisu.cpurun.util.CpuUtils;
17+
18+
import java.util.ArrayList;
19+
import java.util.List;
20+
21+
22+
public class CpuVoltageFragment extends Fragment implements CustomAdapter.LayoutView {
23+
24+
public static final int UPDATE_UI = 0;
25+
26+
private boolean isRun;
27+
private Context mContext;
28+
private List<String> result;
29+
private Thread mThread;
30+
private CustomAdapter<String> mCustomAdapter;
31+
32+
private View mView;
33+
private ListView mListView;
34+
35+
private Handler mHandler = new Handler() {
36+
37+
@Override
38+
public void handleMessage(Message msg) {
39+
switch (msg.what) {
40+
case UPDATE_UI:
41+
mCustomAdapter.updateData((ArrayList<String>) result);
42+
break;
43+
default:
44+
break;
45+
}
46+
}
47+
};
48+
49+
@Override
50+
public void onAttach(Context context) {
51+
super.onAttach(context);
52+
mContext = context;
53+
}
54+
55+
@Override
56+
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
57+
mView = inflater.inflate(R.layout.fragment_base, container, false);
58+
initViews();
59+
initValues();
60+
initListeners();
61+
return mView;
62+
}
63+
64+
private void initViews() {
65+
mListView = (ListView) mView.findViewById(R.id.listview);
66+
}
67+
68+
private void initValues() {
69+
result = CpuUtils.getCpuVoltage();
70+
mCustomAdapter = new CustomAdapter<String>(result);
71+
mListView.setAdapter(mCustomAdapter);
72+
mHandler.sendEmptyMessage(UPDATE_UI);
73+
}
74+
75+
private void initListeners() {
76+
mCustomAdapter.setLayoutView(this);
77+
}
78+
79+
private void startTask() {
80+
mThread = new Thread(new Runnable() {
81+
@Override
82+
public void run() {
83+
while (isRun) {
84+
try {
85+
Thread.sleep(2000);
86+
} catch (InterruptedException e) {
87+
e.printStackTrace();
88+
}
89+
90+
if (null != result) {
91+
result.clear();
92+
result.addAll(CpuUtils.getCpuVoltage());
93+
mHandler.sendEmptyMessage(UPDATE_UI);
94+
}
95+
96+
}
97+
}
98+
});
99+
100+
mThread.start();
101+
}
102+
103+
@Override
104+
public void onResume() {
105+
super.onResume();
106+
isRun = true;
107+
108+
startTask();
109+
}
110+
111+
@Override
112+
public void onStop() {
113+
isRun = false;
114+
115+
if (mThread != null) {
116+
mThread.interrupt();
117+
}
118+
super.onStop();
119+
}
120+
121+
class ViewHolder {
122+
TextView tv_info;
123+
}
124+
125+
@Override
126+
public <T> View setView(int position, View convertView, ViewGroup parent) {
127+
ViewHolder holder = null;
128+
if (convertView == null) {
129+
convertView = LayoutInflater.from(mContext).inflate(R.layout.item_base, null);
130+
holder = new ViewHolder();
131+
convertView.setTag(holder);
132+
133+
holder.tv_info = (TextView) convertView.findViewById(R.id.tv_info);
134+
} else {
135+
holder = (ViewHolder) convertView.getTag();
136+
}
137+
138+
holder.tv_info.setText(result.get(position));
139+
140+
return convertView;
141+
}
142+
}

app/src/main/res/layout/activity_main.xml

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2-
xmlns:tools="http://schemas.android.com/tools"
32
android:layout_width="match_parent"
43
android:layout_height="match_parent"
54
android:orientation="vertical">
@@ -51,6 +50,16 @@
5150
android:layout_height="match_parent"
5251
android:background="@color/title_divider_bg" />
5352

53+
<RadioButton
54+
android:id="@+id/rb_cpu_voltage"
55+
style="@style/main_title_radio"
56+
android:text="@string/title_cpu_voltage" />
57+
58+
<View
59+
android:layout_width="0.5dip"
60+
android:layout_height="match_parent"
61+
android:background="@color/title_divider_bg" />
62+
5463
<RadioButton
5564
android:id="@+id/rb_scene_freq"
5665
style="@style/main_title_radio"

app/src/main/res/layout/fragment_base.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:orientation="vertical"
43
android:layout_width="match_parent"
5-
android:layout_height="match_parent">
4+
android:layout_height="match_parent"
5+
android:orientation="vertical">
66

77
<ListView
88
android:id="@+id/listview"

app/src/main/res/layout/fragment_core.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
android:id="@+id/tv_info"
99
android:layout_width="match_parent"
1010
android:layout_height="wrap_content"
11+
android:drawablePadding="5dp"
1112
android:drawableStart="@mipmap/logo_arm_cortex"
1213
android:gravity="center"
13-
android:drawablePadding="5dp"
1414
android:padding="10dp" />
1515

1616
<ListView

app/src/main/res/layout/fragment_display.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:orientation="vertical"
43
android:layout_width="match_parent"
5-
android:layout_height="match_parent">
4+
android:layout_height="match_parent"
5+
android:orientation="vertical">
66

77
<ListView
88
android:id="@+id/listview"
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:orientation="vertical"
43
android:layout_width="match_parent"
5-
android:layout_height="match_parent">
4+
android:layout_height="match_parent"
5+
android:orientation="vertical">
66

77
<TextView
8-
android:padding="10dp"
98
android:id="@+id/tv_info"
109
android:layout_width="match_parent"
11-
android:layout_height="match_parent" />
10+
android:layout_height="match_parent"
11+
android:padding="10dp" />
1212

1313
</LinearLayout>

app/src/main/res/layout/item_base.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
33
android:id="@+id/tv_info"
4-
android:padding="10dip"
54
android:layout_width="match_parent"
6-
android:layout_height="wrap_content">
5+
android:layout_height="wrap_content"
6+
android:padding="10dip">
77

88
</TextView>

app/src/main/res/values-zh/strings.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
2+
<resources>
33
<string name="app_name">CPU 工具</string>
44
<string name="cpu_freq">CPU 频率</string>
55

@@ -14,6 +14,7 @@
1414
<string name="title_display">显示信息</string>
1515
<string name="title_cpu_status">CPU 状态</string>
1616
<string name="title_cpu_scene_freq">CPU场景频率</string>
17+
<string name="title_cpu_voltage">CPU 电压</string>
1718

1819
<string name="cpu_core_number">CPU 核数: </string>
1920
<string name="cpu_bits">CPU 位数: </string>
@@ -33,7 +34,6 @@
3334
<string name="cpu_online_status_online">开启</string>
3435
<string name="cpu_online_status_offline">关闭</string>
3536
<string name="cpu_stoped">CPU %1$d: 已经停止</string>
36-
<string name="cpu_voltage">CPU 电压:</string>
3737

3838
<string name="phone_mode">本机型号: </string>
3939
<string name="phone_product">手机制造商: </string>

app/src/main/res/values/strings.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
2+
<resources>
33
<string name="app_name">CPU Tools</string>
44
<string name="cpu_freq">CPU Freq</string>
55

@@ -14,6 +14,7 @@
1414
<string name="title_display">Display</string>
1515
<string name="title_cpu_status">CPU status</string>
1616
<string name="title_cpu_scene_freq">CPU Scene Of Frequency</string>
17+
<string name="title_cpu_voltage">CPU Voltage</string>
1718

1819
<string name="cpu_core_number">CPU core number: </string>
1920
<string name="cpu_bits">CPU bit: </string>
@@ -33,7 +34,6 @@
3334
<string name="cpu_online_status_online">Online</string>
3435
<string name="cpu_online_status_offline">Offline</string>
3536
<string name="cpu_stoped">CPU %1$d: Stopped</string>
36-
<string name="cpu_voltage">CPU Voltage:</string>
3737

3838
<string name="phone_product">Phone product: </string>
3939
<string name="phone_band">Phone band: </string>

app/src/test/java/com/fadisu/cpurun/ExampleUnitTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.junit.Test;
44

5-
import static org.junit.Assert.*;
5+
import static org.junit.Assert.assertEquals;
66

77
/**
88
* To work on unit tests, switch the Test Artifact in the Build Variants view.

0 commit comments

Comments
 (0)