Skip to content

Commit 9951a9a

Browse files
committed
完成基本功能:
1. 连接 2. 读取写入手环各个蓝牙特性 3. 读取rssi 4. 读取电池状态 5. 配对
0 parents  commit 9951a9a

23 files changed

+657
-0
lines changed

.classpath

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="gen"/>
5+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6+
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
7+
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
8+
<classpathentry kind="output" path="bin/classes"/>
9+
</classpath>

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin

.project

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>miband-android</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.jdt.core.javabuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
</natures>
33+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding//src/com/zhaoxiaodan/miband/Profile.java=UTF-8

AndroidManifest.xml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.zhaoxiaodan.miband_android"
3+
android:versionCode="1"
4+
android:versionName="1.0" >
5+
6+
<uses-sdk
7+
android:minSdkVersion="21"
8+
android:targetSdkVersion="21" />
9+
10+
<application
11+
android:allowBackup="true"
12+
android:icon="@drawable/ic_launcher"
13+
android:label="@string/app_name"
14+
android:theme="@style/AppTheme" >
15+
</application>
16+
17+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** Automatically generated file. DO NOT MODIFY */
2+
package com.zhaoxiaodan.miband_android;
3+
4+
public final class BuildConfig {
5+
public final static boolean DEBUG = true;
6+
}
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* AUTO-GENERATED FILE. DO NOT MODIFY.
2+
*
3+
* This class was automatically generated by the
4+
* aapt tool from the resource data it found. It
5+
* should not be modified by hand.
6+
*/
7+
8+
package com.zhaoxiaodan.miband_android;
9+
10+
public final class R {
11+
public static final class attr {
12+
}
13+
public static final class drawable {
14+
public static int ic_launcher=0x7f020000;
15+
}
16+
public static final class string {
17+
public static int app_name=0x7f030000;
18+
}
19+
public static final class style {
20+
/**
21+
Base application theme, dependent on API level. This theme is replaced
22+
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
23+
24+
25+
Theme customizations available in newer API levels can go in
26+
res/values-vXX/styles.xml, while customizations related to
27+
backward-compatibility can go here.
28+
29+
30+
Base application theme for API 11+. This theme completely replaces
31+
AppBaseTheme from res/values/styles.xml on API 11+ devices.
32+
33+
API 11 theme customizations can go here.
34+
35+
Base application theme for API 14+. This theme completely replaces
36+
AppBaseTheme from BOTH res/values/styles.xml and
37+
res/values-v11/styles.xml on API 14+ devices.
38+
39+
API 14 theme customizations can go here.
40+
*/
41+
public static int AppBaseTheme=0x7f040000;
42+
/** Application theme.
43+
All customizations that are NOT specific to a particular API-level can go here.
44+
*/
45+
public static int AppTheme=0x7f040001;
46+
}
47+
}

libs/android-support-v4.jar

1.1 MB
Binary file not shown.

proguard-project.txt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# To enable ProGuard in your project, edit project.properties
2+
# to define the proguard.config property as described in that file.
3+
#
4+
# Add project specific ProGuard rules here.
5+
# By default, the flags in this file are appended to flags specified
6+
# in ${sdk.dir}/tools/proguard/proguard-android.txt
7+
# You can edit the include path and order by changing the ProGuard
8+
# include property in project.properties.
9+
#
10+
# For more details, see
11+
# http://developer.android.com/guide/developing/tools/proguard.html
12+
13+
# Add any project specific keep options here:
14+
15+
# If your project uses WebView with JS, uncomment the following
16+
# and specify the fully qualified class name to the JavaScript interface
17+
# class:
18+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19+
# public *;
20+
#}

project.properties

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This file is automatically generated by Android Tools.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must be checked in Version Control Systems.
5+
#
6+
# To customize properties used by the Ant build system edit
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
#
10+
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11+
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12+
13+
# Project target.
14+
target=android-19
15+
android.library=true

res/drawable-hdpi/ic_launcher.png

9.18 KB
Loading

res/drawable-mdpi/ic_launcher.png

5.11 KB
Loading

res/drawable-xhdpi/ic_launcher.png

14 KB
Loading

res/values-v11/styles.xml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme for API 11+. This theme completely replaces
5+
AppBaseTheme from res/values/styles.xml on API 11+ devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
8+
<!-- API 11 theme customizations can go here. -->
9+
</style>
10+
11+
</resources>

res/values-v14/styles.xml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme for API 14+. This theme completely replaces
5+
AppBaseTheme from BOTH res/values/styles.xml and
6+
res/values-v11/styles.xml on API 14+ devices.
7+
-->
8+
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
9+
<!-- API 14 theme customizations can go here. -->
10+
</style>
11+
12+
</resources>

res/values/strings.xml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<resources>
2+
3+
<string name="app_name">miband-android</string>
4+
5+
</resources>

res/values/styles.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<resources>
2+
3+
<!--
4+
Base application theme, dependent on API level. This theme is replaced
5+
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
6+
-->
7+
<style name="AppBaseTheme" parent="android:Theme.Light">
8+
<!--
9+
Theme customizations available in newer API levels can go in
10+
res/values-vXX/styles.xml, while customizations related to
11+
backward-compatibility can go here.
12+
-->
13+
</style>
14+
15+
<!-- Application theme. -->
16+
<style name="AppTheme" parent="AppBaseTheme">
17+
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
18+
</style>
19+
20+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.zhaoxiaodan.miband;
2+
3+
public interface ActionCallback
4+
{
5+
public void onSuccess(Object data);
6+
public void onFail(int errorCode,String msg);
7+
}
+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package com.zhaoxiaodan.miband;
2+
3+
import java.text.ParseException;
4+
import java.text.SimpleDateFormat;
5+
import java.util.Date;
6+
import java.util.Locale;
7+
8+
public class BatteryInfo
9+
{
10+
11+
enum Status
12+
{
13+
/**
14+
* 未知状态
15+
*/
16+
unknow,
17+
18+
/**
19+
* 低电量
20+
*/
21+
low,
22+
23+
/**
24+
* 充电中
25+
*/
26+
charging,
27+
28+
/**
29+
* 满电, 且充电中
30+
*/
31+
fullAndCharging,
32+
33+
/**
34+
* 未在充电
35+
*/
36+
notChargin,
37+
}
38+
39+
/**
40+
* 电池电量百分比, level=40 表示有40%的电量
41+
*/
42+
private int level;
43+
44+
/**
45+
* 充电循环次数
46+
*/
47+
private int cycles;
48+
49+
/**
50+
* 当前状态
51+
*/
52+
private Status status;
53+
54+
/**
55+
* 最后充电时间
56+
*/
57+
private Date lastChargedDate;
58+
59+
private BatteryInfo()
60+
{
61+
62+
}
63+
64+
public static BatteryInfo fromByteData(byte[] data)
65+
{
66+
if (data.length < 10)
67+
{
68+
return null;
69+
}
70+
BatteryInfo info = new BatteryInfo();
71+
72+
info.level = data[0];
73+
info.status = data[9] <= 4 ? Status.values()[data[9]] : Status.unknow;
74+
info.cycles = 0xffff & (0xff & data[7] | (0xff & data[8]) << 8);
75+
try
76+
{
77+
info.lastChargedDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:SS", Locale.CHINA).parse(String.format(
78+
"%4d-%2d-%2d %2d:%2d:%2d", data[1] + 2000, data[2], data[3], data[4], data[5], data[6]));
79+
} catch (ParseException e)
80+
{
81+
e.printStackTrace();
82+
}
83+
84+
return info;
85+
}
86+
87+
public String toString()
88+
{
89+
return "cycles:" + this.getCycles()
90+
+ ",level:" + this.getLevel()
91+
+ ",status:" + this.getStatus()
92+
+ ",last:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:SS", Locale.CHINA).format(this.getLastChargedDate());
93+
}
94+
95+
public int getLevel()
96+
{
97+
return level;
98+
}
99+
100+
public int getCycles()
101+
{
102+
return cycles;
103+
}
104+
105+
public Status getStatus()
106+
{
107+
return status;
108+
}
109+
110+
public Date getLastChargedDate()
111+
{
112+
return lastChargedDate;
113+
}
114+
}

0 commit comments

Comments
 (0)