Browse Source

Update jar

master
陈福行 4 years ago
parent
commit
6e3f7abb4c

+ 0
- 10
.idea/codeStyles/Project.xml View File

<emptyLine /> <emptyLine />
</value> </value>
</option> </option>
<option name="RIGHT_MARGIN" value="100" />
<AndroidXmlCodeStyleSettings>
<option name="USE_CUSTOM_SETTINGS" value="true" />
</AndroidXmlCodeStyleSettings>
<JavaCodeStyleSettings> <JavaCodeStyleSettings>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
<value />
</option>
<option name="IMPORT_LAYOUT_TABLE"> <option name="IMPORT_LAYOUT_TABLE">
<value> <value>
<package name="android" withSubpackages="true" static="false" /> <package name="android" withSubpackages="true" static="false" />
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" /> <option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
</XML> </XML>
<codeStyleSettings language="XML"> <codeStyleSettings language="XML">
<option name="FORCE_REARRANGE_MODE" value="1" />
<indentOptions> <indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" /> <option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions> </indentOptions>

+ 2
- 0
.idea/gradle.xml View File

<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>
<option name="testRunner" value="PLATFORM" />
<option name="distributionType" value="DEFAULT_WRAPPED" /> <option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules"> <option name="modules">

+ 25
- 0
.idea/jarRepositories.xml View File

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="BintrayJCenter" />
<option name="name" value="BintrayJCenter" />
<option name="url" value="https://jcenter.bintray.com/" />
</remote-repository>
<remote-repository>
<option name="id" value="Google" />
<option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository>
</component>
</project>

+ 234
- 117
app/src/main/java/aicare/net/cn/sdk/pabulumsdkrepositoryandroid/MainActivity.java View File

import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnCheckedChanged; import butterknife.OnCheckedChanged;
import butterknife.OnClick; import butterknife.OnClick;
import cn.net.aicare.pabulumlibrary.PabulumSDK;
import cn.net.aicare.pabulumlibrary.bleprofile.BleProfileService; import cn.net.aicare.pabulumlibrary.bleprofile.BleProfileService;
import cn.net.aicare.pabulumlibrary.entity.FoodData; import cn.net.aicare.pabulumlibrary.entity.FoodData;
import cn.net.aicare.pabulumlibrary.pabulum.PabulumService; import cn.net.aicare.pabulumlibrary.pabulum.PabulumService;
import cn.net.aicare.pabulumlibrary.utils.PabulumBleConfig; import cn.net.aicare.pabulumlibrary.utils.PabulumBleConfig;
import cn.net.aicare.pabulumlibrary.utils.ParseData; import cn.net.aicare.pabulumlibrary.utils.ParseData;



public class MainActivity extends BaseActivity implements SetRssiDialog.OnQueryListener { public class MainActivity extends BaseActivity implements SetRssiDialog.OnQueryListener {


private final static String TAG = MainActivity.class.getSimpleName(); private final static String TAG = MainActivity.class.getSimpleName();
TextView tvShowVersion; TextView tvShowVersion;
@BindView(R.id.rg_unit) @BindView(R.id.rg_unit)
RadioGroup rgUnit; RadioGroup rgUnit;
@BindView(R.id.rg_unit_two)
RadioGroup rgUnitTwo;
@BindView(R.id.et_set_weight) @BindView(R.id.et_set_weight)
EditText etSetWeight; EditText etSetWeight;
@BindView(R.id.tv_show_result) @BindView(R.id.tv_show_result)
@BindView(R.id.tv_show_time) @BindView(R.id.tv_show_time)
TextView tv_show_time; TextView tv_show_time;


@OnClick({R.id.btn_title_right, R.id.tv_show_state, R.id.btn_set_weight, R.id.btn_tare,
R.id.btn_power_off, R.id.btn_cal, R.id.btn_all_cal, R.id.btn_fat, R.id.btn_all_fat,
R.id.btn_pro, R.id.btn_all_pro, R.id.btn_car, R.id.btn_all_car, R.id.btn_fib,
R.id.btn_all_fib, R.id.btn_cho, R.id.btn_all_cho, R.id.btn_sod, R.id.btn_all_sod,
R.id.btn_sug, R.id.btn_all_sug, R.id.btn_write_value, R.id.btn_did,
R.id.btn_get_version, R.id.btn_start, R.id.btn_start_less, R.id.btn_pause,
R.id.btn_reset, R.id.btn_pause_less})
@OnClick({R.id.btn_title_right, R.id.tv_show_state, R.id.btn_set_weight, R.id.btn_tare, R.id.btn_power_off, R.id.btn_cal, R.id.btn_all_cal, R.id.btn_fat, R.id.btn_all_fat, R.id.btn_pro,
R.id.btn_all_pro, R.id.btn_car, R.id.btn_all_car, R.id.btn_fib, R.id.btn_all_fib, R.id.btn_cho, R.id.btn_all_cho, R.id.btn_sod, R.id.btn_all_sod, R.id.btn_sug, R.id.btn_all_sug,
R.id.btn_write_value, R.id.btn_did, R.id.btn_get_version, R.id.btn_start, R.id.btn_start_less, R.id.btn_pause, R.id.btn_reset, R.id.btn_pause_less, R.id.btn_get_units})
void onClick(View view) { void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.btn_title_right: case R.id.btn_title_right:
handler.postDelayed(disconnectRunnable, 1000); handler.postDelayed(disconnectRunnable, 1000);
} }
break; break;
//获取DID 2018-12-3
case R.id.btn_did: case R.id.btn_did:
if (binder != null) { if (binder != null) {
L.i(TAG, "点击请求获取did");
binder.getDid(); binder.getDid();
} }
break; break;
//2019/4/29 //2019/4/29
case R.id.btn_start: case R.id.btn_start:
if (binder != null) { if (binder != null) {
L.i(TAG, "开始计时");
binder.startTime(); binder.startTime();
} }
break; //2019/6/25
break; //2019/5/22
case R.id.btn_start_less: case R.id.btn_start_less:
if (binder != null) { if (binder != null) {
L.i(TAG, "倒计时开始");
binder.startTimeLess(180); binder.startTimeLess(180);
} }
break; break;
//2019/6/25 //2019/6/25
case R.id.btn_pause: case R.id.btn_pause:
if (binder != null) { if (binder != null) {
L.i(TAG, "Positive timing pause");
L.i(TAG, "正计时暂停");
binder.pauseTime(80); binder.pauseTime(80);
} }
break; break;
//2019/6/25 //2019/6/25
case R.id.btn_pause_less: case R.id.btn_pause_less:
if (binder != null) { if (binder != null) {
L.i(TAG, "Countdown pause");
L.i(TAG, "倒计时暂停");
binder.pauseTimeLess(90); binder.pauseTimeLess(90);
} }
break; break;
//2019/4/29 //2019/4/29
case R.id.btn_reset: case R.id.btn_reset:
if (binder != null) { if (binder != null) {
L.i(TAG, "重置计时");
binder.resetTime(); binder.resetTime();
} }
break; break;
case R.id.btn_write_value: case R.id.btn_write_value:
if (binder != null) { if (binder != null) {
//透传数据测试
byte[] value = initRandomByteArr(new Random().nextInt(21)); byte[] value = initRandomByteArr(new Random().nextInt(21));
L.e(TAG, "value: " + ParseData.arr2Str(value)); L.e(TAG, "value: " + ParseData.arr2Str(value));
binder.writeValue(value); binder.writeValue(value);
break; break;
case R.id.btn_get_version: case R.id.btn_get_version:
if (binder != null) { if (binder != null) {
L.i(TAG, "点击请求获取版本号");
binder.getVersion(); binder.getVersion();


}
break;
case R.id.btn_get_units:
if (binder != null) {
L.i(TAG, "点击请求获取单位列表");
binder.getUnits();

} }
break; break;
default: default:
if (TextUtils.isEmpty(data)) { if (TextUtils.isEmpty(data)) {
T.showShort(this, R.string.pls_input_weight); T.showShort(this, R.string.pls_input_weight);
} else { } else {
int wei = Integer.valueOf(data);
int wei = Integer.parseInt(data);
if (binder != null) { if (binder != null) {
switch (id) { switch (id) {
case R.id.btn_cal: case R.id.btn_cal:
} }
} }


@OnCheckedChanged({R.id.rb_g, R.id.rb_lb, R.id.rb_ml, R.id.rb_oz, R.id.rb_kg, R.id.rb_fg})
@OnCheckedChanged({R.id.rb_g, R.id.rb_lb, R.id.rb_ml, R.id.rb_oz, R.id.rb_kg, R.id.rb_fg, R.id.rb_ml_milk, R.id.rb_ml_water, R.id.rb_floz_milk, R.id.rb_floz_water, R.id.rb_lb_lb})
void onCheckedChange(RadioButton radioButton, boolean isChecked) { void onCheckedChange(RadioButton radioButton, boolean isChecked) {
if (isBleChangeUnit) { if (isBleChangeUnit) {
isBleChangeUnit = false; isBleChangeUnit = false;
binder.setUnit(PabulumBleConfig.UNIT_FG); binder.setUnit(PabulumBleConfig.UNIT_FG);
} }
break; break;
case R.id.rb_ml_milk:
if (binder != null) {
binder.setUnit(PabulumBleConfig.UNIT_ML_MILK);
}
break;
case R.id.rb_ml_water:
if (binder != null) {
binder.setUnit(PabulumBleConfig.UNIT_ML_WATER);
}
break;
case R.id.rb_floz_milk:
if (binder != null) {
binder.setUnit(PabulumBleConfig.UNIT_FL_OZ_MILK);
}
break;
case R.id.rb_floz_water:
if (binder != null) {
binder.setUnit(PabulumBleConfig.UNIT_FL_OZ_WATER);
}
break;
case R.id.rb_lb_lb:
if (binder != null) {
binder.setUnit(PabulumBleConfig.UNIT_LB_LB);
}
break;
} }
} }
} }
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
L.isDebug = true; L.isDebug = true;
setContentView(R.layout.main); setContentView(R.layout.main);
// PabulumSDK.getInstance().init(this, "66617c04a3bbc7d2", "001814ae6212dd8c4657444c4b");
PabulumSDK.getInstance().init(this);
initData(); initData();
ButterKnife.bind(this); ButterKnife.bind(this);
initViews(); initViews();
if (!AppUtils.isLocServiceEnable(this)) { if (!AppUtils.isLocServiceEnable(this)) {
T.showShort(this,this.getString(R.string.permissions_server));
T.showShort(this, this.getString(R.string.permissions_server));
} }


if (ensureBLESupported()) {
if (ensureBLESupported()) {//判断设备是否支持BLE,true(支持),反之则反。


initPermissions(); initPermissions();
} }
} }





/**
* 设置状态信息
*
* @param object
*/
private void setState(Object object) { private void setState(Object object) {
if (object instanceof Integer) { if (object instanceof Integer) {
tvShowState.setText((Integer) object); tvShowState.setText((Integer) object);
} }
} }



/**
* 设置信号显示
*
* @param object
*/
private void setCurrentRssi(Object object) { private void setCurrentRssi(Object object) {
if (object == null) { if (object == null) {
tvShowRssi.setText(R.string.no_rssi); tvShowRssi.setText(R.string.no_rssi);
} else { } else {
if (object instanceof Integer) { if (object instanceof Integer) {
tvShowRssi.setText(String.format(getResources().getString(R.string.current_rssi),
(Integer) object));
tvShowRssi.setText(String.format(getResources().getString(R.string.current_rssi), (Integer) object));
} }
} }
} }
@Override @Override
protected void getTimeStatus(int status) { protected void getTimeStatus(int status) {
//2019/4/29 //2019/4/29
Toast.makeText(MainActivity.this, "getTimeStatus:" + status, Toast.LENGTH_SHORT).show();
L.i(TAG, "获取操作状态:" + status);
Toast.makeText(MainActivity.this, "操作状态:" + status, Toast.LENGTH_SHORT).show();
} }


@Override @Override
protected void getCountdownStart(int time) { protected void getCountdownStart(int time) {
//2019/5/22 //2019/5/22
Toast.makeText(MainActivity.this, "getCountdownStart:" + time, Toast.LENGTH_SHORT).show();
L.i(TAG, "倒计时开始:" + time);
Toast.makeText(MainActivity.this, "倒计时开始:" + time, Toast.LENGTH_SHORT).show();
} }


@Override @Override
protected void getSynTime(byte cmdType, int timeS) { protected void getSynTime(byte cmdType, int timeS) {
//2019/5/22 //2019/5/22
String tyepName="";
String tyepName = "";
switch (cmdType) { switch (cmdType) {


case PabulumBleConfig.SYN_TIME: case PabulumBleConfig.SYN_TIME:
tyepName="Time synchronization";
//时间同步
tyepName = "时间同步";
break; break;
case PabulumBleConfig.SYN_TIME_LESS: case PabulumBleConfig.SYN_TIME_LESS:
tyepName="Countdown time synchronization";
//倒计时时间同步
tyepName = "倒计时时间同步";
break; break;
case PabulumBleConfig.TIMING_PAUSE: case PabulumBleConfig.TIMING_PAUSE:
tyepName="Positive timing pause";
Toast.makeText(MainActivity.this,"Positive timing pause", Toast.LENGTH_SHORT).show();
//正计时暂停时间同步
tyepName = "正计时暂停时间同步";
Toast.makeText(MainActivity.this, "正计时暂停", Toast.LENGTH_SHORT).show();
break; break;
case PabulumBleConfig.TIMING_PAUSE_LESS: case PabulumBleConfig.TIMING_PAUSE_LESS:
tyepName="Countdown pause";
Toast.makeText(MainActivity.this,"Countdown pause", Toast.LENGTH_SHORT).show();
//倒计时暂停时间同步
tyepName = "倒计时暂停时间同步";
Toast.makeText(MainActivity.this, "倒计时暂停", Toast.LENGTH_SHORT).show();
break; break;


} }
L.i(TAG, "TIME:" + timeS + "||" + tyepName);
L.i(TAG, "获取时间同步:" + timeS + "||" + tyepName);
tv_show_time.setText("TIME:" + timeS); tv_show_time.setText("TIME:" + timeS);
} }


@Override @Override
protected void getBleDID(int did) {
L.i(TAG, "getBleDID:" + did);
tvShowDid.setText("DID:" + did);
}


@Override
protected void getUnits(int[] units) {
L.i(TAG, "支持的单位列表 = " + Arrays.toString(units));
}

@Override
protected void getErrCodes(int[] ints) {
super.getErrCodes(ints);
}
protected void getPenetrateData(byte[] data) {
L.i(TAG, "透传数据:" + ParseData.arr2Str(data));


@Override
protected void getStopAlarm() {
super.getStopAlarm();
} }


@Override @Override
protected void getPenetrateData(byte[] data) {
L.i(TAG, "透传数据:" + ParseData.arr2Str(data));
protected void getBleDID(int did) {
L.i(TAG, "获取did成功:" + did);
tvShowDid.setText("DID:" + did);
} }


/**
* 设置右边title
*
* @param rssi
*/
private void setTitleRight(int rssi) { private void setTitleRight(int rssi) {
btnTitleRight.setText(String.format(getResources().getString(R.string.default_rssi), rssi)); btnTitleRight.setText(String.format(getResources().getString(R.string.default_rssi), rssi));
} }


@Override @Override
protected void onServiceBinded(BleProfileService.LocalBinder binder) {

protected void onServiceBinded(BleProfileService.LocalBinder binder) {//成功绑定服务
/*
获取服务的binder通过binder执行蓝牙操作
*/
this.binder = (PabulumService.PabulumBinder) binder; this.binder = (PabulumService.PabulumBinder) binder;
this.binder.getDeviceAddress();
this.binder.getDeviceName();
this.binder.getDeviceAddress();//获取当前连接设备的蓝牙地址
this.binder.getDeviceName();//获取当前连接设备的名称
L.e(TAG, "onServiceBinded绑定服务成功:" + binder);
} }


@Override @Override
case BleProfileService.STATE_CONNECTED: case BleProfileService.STATE_CONNECTED:
L.e(TAG, "onDeviceConnected"); L.e(TAG, "onDeviceConnected");
if (binder != null) { if (binder != null) {
setState(String.format(getResources().getString(R.string.current_device),
binder.getDeviceAddress()));
setState(String.format(getResources().getString(R.string.current_device), binder.getDeviceAddress()));
} }
break; break;
case BleProfileService.STATE_DISCONNECTED: case BleProfileService.STATE_DISCONNECTED:
} }
}, 1000); }, 1000);
break; break;
case BleProfileService.STATE_INDICATION_SUCCESS:
case BleProfileService.STATE_INDICATION_SUCCESS://订阅蓝牙服务成功
L.e(TAG, "onIndicationSuccess"); L.e(TAG, "onIndicationSuccess");
if (binder != null) { if (binder != null) {
binder.setUnit(preUnit);
binder.setUnit(preUnit);//设置单位(订阅成功后,同步APP单位到蓝牙,保持两端单位一致)
} }
rgUnit.check(R.id.rb_g); rgUnit.check(R.id.rb_g);
break; break;
T.showLong(this, "msg = " + msg + "; code = " + errorCode); T.showLong(this, "msg = " + msg + "; code = " + errorCode);
} }


private int countRssi = 0;
private int countRssi = 0;//判断是否需要断开


@Override @Override
public void onReadRssi(int rssi) { public void onReadRssi(int rssi) {
} }
} }


private int countWei = 0;
private int countWei = 0;//判断数据是否稳定


@Override @Override
protected void getUnit(byte unitType) {
protected void getUnit(byte unitType) {//秤返回的单位信息
L.e(TAG, "unitType = " + unitType); L.e(TAG, "unitType = " + unitType);
preUnit = unitType;
showUnit(preUnit);
}


@Override
protected void getUnits(int[] units) {//支持的单位列表
L.e(TAG, "支持的单位列表 = " + Arrays.toString(units));
} }


@Override @Override
protected void getBleVersion(String version) { protected void getBleVersion(String version) {
L.e(TAG, "version = " + version); L.e(TAG, "version = " + version);
T.showShort(this, "获取版本号成功");
setBleVersion(String.format(getResources().getString(R.string.ble_version), version)); setBleVersion(String.format(getResources().getString(R.string.ble_version), version));
} }


} }


@Override @Override
protected void bluetoothStateOn() {
protected void bluetoothStateOn() {//蓝牙已开启
super.bluetoothStateOn(); super.bluetoothStateOn();
setState(R.string.ble_state_on); setState(R.string.ble_state_on);
L.e(TAG, "bluetoothStateOn"); L.e(TAG, "bluetoothStateOn");


@Override @Override
protected void getFoodData(FoodData foodData) { protected void getFoodData(FoodData foodData) {
if (foodData == null) {//2017-06-16
if (foodData == null) {//2017-06-16为空直接返回
return; return;
} }
L.e(TAG, "weight = " + foodData.getData()); L.e(TAG, "weight = " + foodData.getData());
if (foodData.getUnit() != preUnit) { if (foodData.getUnit() != preUnit) {
preUnit = foodData.getUnit(); preUnit = foodData.getUnit();
isBleChangeUnit = true; isBleChangeUnit = true;
switch (preUnit) {
case PabulumBleConfig.UNIT_G:
rgUnit.check(R.id.rb_g);
break;
case PabulumBleConfig.UNIT_ML:
rgUnit.check(R.id.rb_ml);
break;
case PabulumBleConfig.UNIT_LB:
rgUnit.check(R.id.rb_lb);
break;
case PabulumBleConfig.UNIT_OZ:
rgUnit.check(R.id.rb_oz);
break;
case PabulumBleConfig.UNIT_KG:
rgUnit.check(R.id.rb_kg);
break;
case PabulumBleConfig.UNIT_FG:
rgUnit.check(R.id.rb_fg);
break;
}
showUnit(preUnit);
} }
String unitStr = getUnitStr(preUnit);

tvShowResult.setText(preWeight+" "+unitStr + "\nType:" + foodData.getDeviceType()+ "\n" + foodData.getWeight() + "g");
}


private void showUnit(int preUnit) {
switch (preUnit) {
case PabulumBleConfig.UNIT_G:
rgUnit.check(R.id.rb_g);
break;
case PabulumBleConfig.UNIT_ML:
rgUnit.check(R.id.rb_ml);
break;
case PabulumBleConfig.UNIT_LB:
rgUnit.check(R.id.rb_lb);
break;
case PabulumBleConfig.UNIT_OZ:
rgUnit.check(R.id.rb_oz);
break;
case PabulumBleConfig.UNIT_KG:
rgUnit.check(R.id.rb_kg);
break;
case PabulumBleConfig.UNIT_FG:
rgUnit.check(R.id.rb_fg);
break;
case PabulumBleConfig.UNIT_ML_MILK:
rgUnitTwo.check(R.id.rb_ml_milk);
break;
case PabulumBleConfig.UNIT_ML_WATER:
rgUnitTwo.check(R.id.rb_ml_water);
break;
case PabulumBleConfig.UNIT_FL_OZ_MILK:
rgUnitTwo.check(R.id.rb_floz_milk);
break;
case PabulumBleConfig.UNIT_FL_OZ_WATER:
rgUnitTwo.check(R.id.rb_floz_water);
break;
case PabulumBleConfig.UNIT_LB_LB:
rgUnitTwo.check(R.id.rb_lb_lb);
break;
}
}


tvShowResult.setText(preWeight + "\n" + foodData.getDeviceType() + "\n" + foodData.getWeight());

private String getUnitStr(int preUnit) {
String unitStr=getString(R.string.unit_g);
switch (preUnit) {
case PabulumBleConfig.UNIT_G:
unitStr=getString(R.string.unit_g);
break;
case PabulumBleConfig.UNIT_ML:
unitStr=getString(R.string.unit_ml);
break;
case PabulumBleConfig.UNIT_LB:
unitStr=getString(R.string.unit_lb_oz);
break;
case PabulumBleConfig.UNIT_OZ:
unitStr=getString(R.string.unit_oz);
break;
case PabulumBleConfig.UNIT_KG:
unitStr=getString(R.string.unit_kg);
break;
case PabulumBleConfig.UNIT_FG:
unitStr=getString(R.string.unit_fg);
break;
case PabulumBleConfig.UNIT_ML_MILK:
unitStr=getString(R.string.unit_ml_milk);
break;
case PabulumBleConfig.UNIT_ML_WATER:
unitStr=getString(R.string.unit_ml_water);
break;
case PabulumBleConfig.UNIT_FL_OZ_MILK:
unitStr=getString(R.string.unit_oz_milk);
break;
case PabulumBleConfig.UNIT_FL_OZ_WATER:
unitStr=getString(R.string.unit_oz_water);
break;
case PabulumBleConfig.UNIT_LB_LB:
unitStr=getString(R.string.unit_lb);
break;
}
return unitStr;
} }


@Override @Override
protected void bluetoothStateOff() {
protected void bluetoothStateOff() {//蓝牙已关闭
super.bluetoothStateOff(); super.bluetoothStateOff();
setState(R.string.ble_state_off); setState(R.string.ble_state_off);
L.e(TAG, "bluetoothStateOff"); L.e(TAG, "bluetoothStateOff");
} }


@Override @Override
protected void bluetoothTurningOff() {
protected void bluetoothTurningOff() {//蓝牙正在关闭
super.bluetoothTurningOff(); super.bluetoothTurningOff();
L.e(TAG, "bluetoothTurningOff"); L.e(TAG, "bluetoothTurningOff");
} }


@Override @Override
protected void bluetoothTurningOn() {
protected void bluetoothTurningOn() {//蓝牙正在打开
super.bluetoothTurningOn(); super.bluetoothTurningOn();
L.e(TAG, "bluetoothTurningOn"); L.e(TAG, "bluetoothTurningOn");
} }
L.e(TAG, "onDestroy"); L.e(TAG, "onDestroy");
stopScan(); stopScan();
if (binder != null) { if (binder != null) {
binder.disconnect();
binder.disconnect();//若Activity关闭时,不需要继续保持连接,可以在此断开连接
} }
} }


} }





/**
* 初始化请求权限
*/
private void initPermissions() { private void initPermissions() {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, 1);
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, 1);
} }


@Override @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults); super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode != 1) { if (requestCode != 1) {
return; return;
} }
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
startScan();
startScan();//开始扫描
} else { } else {


if (ActivityCompat.shouldShowRequestPermissionRationale(this, permissions[0])) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, permissions[0])) {
new AlertDialog.Builder(this).setTitle(this.getString(R.string.hint)).setMessage(this.getString(R.string.permissions)).setPositiveButton(this.getString(R.string.query), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package",
getApplicationContext().getPackageName(), null);
intent.setData(uri);
startActivity(intent);
}
}).setNegativeButton(getString(R.string.cancel),
new DialogInterface.OnClickListener() {
//权限请求失败,但未选中“不再提示”选项
new AlertDialog.Builder(this).setTitle(this.getString(R.string.hint)).setMessage(this.getString(R.string.permissions))
.setPositiveButton(this.getString(R.string.query), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//引导用户至设置页手动授权
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getApplicationContext().getPackageName(), null);
intent.setData(uri);
startActivity(intent);
}
}).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (dialog != null) { if (dialog != null) {
} }
}).show(); }).show();
} else { } else {
new AlertDialog.Builder(this).setTitle(this.getString(R.string.hint)).setMessage(this.getString(R.string.permissions)).setPositiveButton(this.getString(R.string.query), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package",
getApplicationContext().getPackageName(), null);
intent.setData(uri);
startActivity(intent);

}
}).setNegativeButton(getString(R.string.cancel),
new DialogInterface.OnClickListener() {
//权限请求失败,选中“不再提示”选项
// T.showShort(MainActivity.this, "获取权限失败");
new AlertDialog.Builder(this).setTitle(this.getString(R.string.hint)).setMessage(this.getString(R.string.permissions))
.setPositiveButton(this.getString(R.string.query), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//引导用户至设置页手动授权
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getApplicationContext().getPackageName(), null);
intent.setData(uri);
startActivity(intent);

}
}).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (dialog != null) { if (dialog != null) {

+ 133
- 65
app/src/main/res/layout/main.xml View File

<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/system_theme"
android:clipToPadding="true"
android:divider="@drawable/main_divider"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:showDividers="middle">

<include layout="@layout/activity_title" />
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/system_theme"
android:clipToPadding="true"
android:divider="@drawable/main_divider"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:showDividers="middle"
tools:ignore="ButtonStyle"
>

<include layout="@layout/activity_title"/>


<TextView <TextView
android:id="@+id/tv_show_state" android:id="@+id/tv_show_state"
style="@style/Base_Text_View" />
style="@style/Base_Text_View"/>


<TextView <TextView
android:id="@+id/tv_show_rssi" android:id="@+id/tv_show_rssi"
style="@style/Base_Text_View" />
style="@style/Base_Text_View"/>


<TextView <TextView
android:id="@+id/tv_show_version" android:id="@+id/tv_show_version"
style="@style/Base_Text_View" />
style="@style/Base_Text_View"/>


<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:id="@+id/rg_unit" android:id="@+id/rg_unit"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center"
android:gravity="center|start"
android:orientation="horizontal"> android:orientation="horizontal">


<RadioButton <RadioButton
android:id="@+id/rb_g" android:id="@+id/rb_g"
style="@style/Base_Radio_Button" style="@style/Base_Radio_Button"
android:text="g" />
android:text="g"/>


<RadioButton <RadioButton
android:id="@+id/rb_ml" android:id="@+id/rb_ml"
style="@style/Base_Radio_Button" style="@style/Base_Radio_Button"
android:text="ml" />
android:text="ml"/>


<RadioButton <RadioButton
android:id="@+id/rb_lb" android:id="@+id/rb_lb"
style="@style/Base_Radio_Button" style="@style/Base_Radio_Button"
android:text="lb" />
android:text="lb:oz"/>


<RadioButton <RadioButton
android:id="@+id/rb_oz" android:id="@+id/rb_oz"
style="@style/Base_Radio_Button" style="@style/Base_Radio_Button"
android:text="oz" />
android:text="oz"/>


<RadioButton <RadioButton
android:id="@+id/rb_kg" android:id="@+id/rb_kg"
style="@style/Base_Radio_Button" style="@style/Base_Radio_Button"
android:text="kg" />
android:text="kg"/>


<RadioButton <RadioButton
android:id="@+id/rb_fg" android:id="@+id/rb_fg"
style="@style/Base_Radio_Button" style="@style/Base_Radio_Button"
android:text="斤" />
android:text="斤"/>



</RadioGroup> </RadioGroup>


</LinearLayout> </LinearLayout>


<LinearLayout
<RadioGroup
android:id="@+id/rg_unit_two"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center|start"
android:orientation="horizontal"> android:orientation="horizontal">


<RadioButton
android:id="@+id/rb_ml_milk"
style="@style/Base_Radio_Button"
android:text="牛奶ml"/>

<RadioButton
android:id="@+id/rb_ml_water"
style="@style/Base_Radio_Button"
android:text="水ml"/>

<RadioButton
android:id="@+id/rb_floz_milk"
style="@style/Base_Radio_Button"
android:text="牛奶floz"/>

<RadioButton
android:id="@+id/rb_floz_water"
style="@style/Base_Radio_Button"
android:text="水floz"/>
<RadioButton
android:id="@+id/rb_lb_lb"
style="@style/Base_Radio_Button"
android:text="lb"/>

</RadioGroup>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone">

<EditText <EditText
android:id="@+id/et_set_weight" android:id="@+id/et_set_weight"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1" android:layout_weight="1"
android:hint="@string/pls_input_weight" android:hint="@string/pls_input_weight"
android:inputType="number" />
android:inputType="number"/>


<Button <Button
android:id="@+id/btn_set_weight" android:id="@+id/btn_set_weight"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/set_weight" />
android:text="@string/set_weight"/>
</LinearLayout> </LinearLayout>


<LinearLayout <LinearLayout
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:orientation="horizontal" android:orientation="horizontal"
android:visibility="gone">
android:visibility="gone"

>


<Button <Button
android:id="@+id/btn_cal" android:id="@+id/btn_cal"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="2dp" android:layout_marginRight="2dp"
android:text="卡路里" />
android:text="卡路里"/>


<Button <Button
android:id="@+id/btn_all_cal" android:id="@+id/btn_all_cal"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="总卡路里" />
android:text="总卡路里"/>


<Button <Button
android:id="@+id/btn_sug" android:id="@+id/btn_sug"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="2dp" android:layout_marginLeft="2dp"
android:layout_marginRight="2dp" android:layout_marginRight="2dp"
android:text="糖" />
android:text="糖"/>


<Button <Button
android:id="@+id/btn_all_sug" android:id="@+id/btn_all_sug"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="总糖" />
android:text="总糖"/>


</LinearLayout> </LinearLayout>


android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="2dp" android:layout_marginRight="2dp"
android:text="脂肪" />
android:text="脂肪"/>


<Button <Button
android:id="@+id/btn_all_fat" android:id="@+id/btn_all_fat"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="总脂肪" />
android:text="总脂肪"/>


<Button <Button
android:id="@+id/btn_pro" android:id="@+id/btn_pro"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="2dp" android:layout_marginLeft="2dp"
android:layout_marginRight="2dp" android:layout_marginRight="2dp"
android:text="蛋白质" />
android:text="蛋白质"/>


<Button <Button
android:id="@+id/btn_all_pro" android:id="@+id/btn_all_pro"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="总蛋白质" />
android:text="总蛋白质"/>


</LinearLayout> </LinearLayout>


android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="2dp" android:layout_marginRight="2dp"
android:text="碳水" />
android:text="碳水"/>


<Button <Button
android:id="@+id/btn_all_car" android:id="@+id/btn_all_car"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="总碳水" />
android:text="总碳水"/>


<Button <Button
android:id="@+id/btn_fib" android:id="@+id/btn_fib"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="2dp" android:layout_marginLeft="2dp"
android:layout_marginRight="2dp" android:layout_marginRight="2dp"
android:text="纤维" />
android:text="纤维"/>


<Button <Button
android:id="@+id/btn_all_fib" android:id="@+id/btn_all_fib"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="总纤维" />
android:text="总纤维"/>


</LinearLayout> </LinearLayout>


android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="2dp" android:layout_marginRight="2dp"
android:text="胆固醇" />
android:text="胆固醇"/>


<Button <Button
android:id="@+id/btn_all_cho" android:id="@+id/btn_all_cho"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="总胆固醇" />
android:text="总胆固醇"/>


<Button <Button
android:id="@+id/btn_sod" android:id="@+id/btn_sod"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="2dp" android:layout_marginLeft="2dp"
android:layout_marginRight="2dp" android:layout_marginRight="2dp"
android:text="钠" />
android:text="钠"/>


<Button <Button
android:id="@+id/btn_all_sod" android:id="@+id/btn_all_sod"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="总钠" />
android:text="总钠"/>


</LinearLayout> </LinearLayout>


android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="2dp" android:layout_marginRight="2dp"
android:text="@string/zero" />
android:text="@string/zero"/>


<Button <Button
android:id="@+id/btn_power_off" android:id="@+id/btn_power_off"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/shut_down" />
android:text="@string/shut_down"/>


<Button <Button
android:id="@+id/btn_write_value" android:id="@+id/btn_write_value"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/write" />
android:text="@string/write"/>


<Button <Button
android:id="@+id/btn_get_version" android:id="@+id/btn_get_version"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/get_version" />
android:text="@string/get_version"/>




</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">


<Button
android:id="@+id/btn_get_units"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/get_units"/>
</LinearLayout> </LinearLayout>


<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:orientation="horizontal">
android:orientation="horizontal"
android:visibility="gone">


<Button <Button
android:id="@+id/btn_start" android:id="@+id/btn_start"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="2dp" android:layout_marginRight="2dp"
android:text="@string/timing" />
android:text="@string/timing"/>


<Button <Button
android:id="@+id/btn_reset" android:id="@+id/btn_reset"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/reset" />
<Button
android:id="@+id/btn_did"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="2dp"
android:text="DID" />
android:text="@string/reset"/>



</LinearLayout> </LinearLayout>


android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:orientation="horizontal">
android:orientation="horizontal"
android:visibility="gone">




<Button <Button
android:id="@+id/btn_start_less" android:id="@+id/btn_start_less"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/countdown" />
android:text="@string/countdown"/>


<Button <Button
android:id="@+id/btn_pause" android:id="@+id/btn_pause"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/pause" />
android:text="@string/pause"/>

<Button <Button
android:id="@+id/btn_pause_less" android:id="@+id/btn_pause_less"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/pause_less" />
android:text="@string/pause_less"
/>




</LinearLayout> </LinearLayout>


<TextView
android:id="@+id/tv_show_did"
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textSize="18dp"
android:text="DID:"
/>
android:gravity="center_horizontal"
android:orientation="horizontal">

<TextView
android:id="@+id/tv_show_did"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="DID:"
android:textSize="18dp"
/>

<Button
android:id="@+id/btn_did"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="2dp"
android:text="DID"/>
</LinearLayout>



<TextView <TextView
android:id="@+id/tv_show_time" android:id="@+id/tv_show_time"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textSize="18dp"
android:text="TIME:" android:text="TIME:"
android:textSize="18dp"
/> />


<TextView <TextView
android:gravity="center" android:gravity="center"
android:textColor="@color/black_theme" android:textColor="@color/black_theme"
android:textSize="28sp" android:textSize="28sp"
android:textStyle="bold" />
android:textStyle="bold"/>
</LinearLayout> </LinearLayout>



+ 14
- 0
app/src/main/res/values-zh/strings.xml View File

<string name="hint">提示</string> <string name="hint">提示</string>
<string name="permissions">请求使用定位权限搜索蓝牙设备</string> <string name="permissions">请求使用定位权限搜索蓝牙设备</string>
<string name="permissions_server">没有开启定位服务</string> <string name="permissions_server">没有开启定位服务</string>

<string name="unit_g">g</string>
<string name="unit_ml">ml</string>
<string name="unit_lb_oz">lb:oz</string>
<string name="unit_oz">oz</string>
<string name="unit_kg">kg</string>
<string name="unit_fg">斤</string>
<string name="unit_ml_milk">ml(牛奶)</string>
<string name="unit_ml_water">ml(水)</string>
<string name="unit_oz_milk">oz(牛奶)</string>
<string name="unit_oz_water">oz(水)</string>
<string name="unit_lb">lb</string>


</resources> </resources>

+ 17
- 2
app/src/main/res/values/strings.xml View File

<?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="app_name">PabulumSDK</string>
<string name="app_name">Ipabulum SDK</string>


<string name="not_support_ble">Your device supports BLE!</string> <string name="not_support_ble">Your device supports BLE!</string>
<string name="scan_ing">Scanning...</string> <string name="scan_ing">Scanning...</string>
<string name="zero">zero</string> <string name="zero">zero</string>
<string name="shut_down">Shut down</string> <string name="shut_down">Shut down</string>
<string name="get_version">Get version</string> <string name="get_version">Get version</string>
<string name="get_units">Get Units</string>
<string name="timing">Timing</string> <string name="timing">Timing</string>
<string name="countdown">Countdown</string> <string name="countdown">Countdown</string>
<string name="pause">Pause</string> <string name="pause">Pause</string>
<string name="hint">Prompt</string> <string name="hint">Prompt</string>
<string name="permissions">Request to search for Bluetooth devices with targeting permissions</string> <string name="permissions">Request to search for Bluetooth devices with targeting permissions</string>
<string name="permissions_server">Location service is not turned on</string> <string name="permissions_server">Location service is not turned on</string>
<string name="get_units">getUnits</string>


<string name="unit_g">g</string>
<string name="unit_ml">ml</string>
<string name="unit_lb_oz">lb:oz</string>
<string name="unit_oz">oz</string>
<string name="unit_kg">kg</string>
<string name="unit_fg">斤</string>
<string name="unit_ml_milk">ml(milk)</string>
<string name="unit_ml_water">ml(water)</string>
<string name="unit_oz_milk">oz(milk)</string>
<string name="unit_oz_water">oz(water)</string>
<string name="unit_lb">lb</string>

</resources> </resources>

+ 1
- 1
pabulumlibrary/build.gradle View File

minSdkVersion 19 minSdkVersion 19
targetSdkVersion 29 targetSdkVersion 29
versionCode 1 versionCode 1
versionName "1.2.6"
versionName "1.2.7"


testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"



BIN
pabulumlibrary/libs/AicareUtils.jar View File


BIN
pabulumlibrary/libs/PabulumLibrary.jar View File


BIN
pabulumlibrary/libs/arm64-v8a/libaicare-lib.so View File


BIN
pabulumlibrary/libs/armeabi-v7a/libaicare-lib.so View File


BIN
pabulumlibrary/libs/x86/libaicare-lib.so View File


BIN
pabulumlibrary/libs/x86_64/libaicare-lib.so View File


Loading…
Cancel
Save