|
|
|
|
|
|
|
|
import aicare.net.cn.sdk.tmpsrepositoryandroid.utils.L; |
|
|
import aicare.net.cn.sdk.tmpsrepositoryandroid.utils.L; |
|
|
import aicare.net.cn.sdk.tmpsrepositoryandroid.utils.ParseData; |
|
|
import aicare.net.cn.sdk.tmpsrepositoryandroid.utils.ParseData; |
|
|
import aicare.net.cn.sdk.tmpsrepositoryandroid.utils.SPUtils; |
|
|
import aicare.net.cn.sdk.tmpsrepositoryandroid.utils.SPUtils; |
|
|
import aicare.net.cn.sdk.tmpsrepositoryandroid.utils.T; |
|
|
|
|
|
import aicare.net.cn.sdk.tmpsrepositoryandroid.views.SetIdDialog; |
|
|
import aicare.net.cn.sdk.tmpsrepositoryandroid.views.SetIdDialog; |
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity implements View.OnClickListener, |
|
|
|
|
|
TpmsScan.TpmsScanListener, OnIdSetListener { |
|
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity implements View.OnClickListener, TpmsScan.TpmsScanListener, OnIdSetListener { |
|
|
|
|
|
|
|
|
private Button btn_get_info, btn_clear_log, btn_stop_scan; |
|
|
|
|
|
|
|
|
private Button btn_get_info, btn_clear_log, btn_stop_scan; |
|
|
private TextView tv_left_front, tv_right_front, tv_left_rear, tv_right_rear; |
|
|
private TextView tv_left_front, tv_right_front, tv_left_rear, tv_right_rear; |
|
|
private ListView lv_show_log; |
|
|
private ListView lv_show_log; |
|
|
private LinearLayout ll_set_id; |
|
|
private LinearLayout ll_set_id; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mTpmsScan = new TpmsScan(MainActivity.this); |
|
|
mTpmsScan = new TpmsScan(MainActivity.this); |
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
|
|
requestPermissions(LOCATION_PERMISSION,1); |
|
|
|
|
|
|
|
|
requestPermissions(LOCATION_PERMISSION, 1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(leftFront)) { |
|
|
if (TextUtils.isEmpty(leftFront)) { |
|
|
tv_left_front.setText(R.string.please_set_id); |
|
|
tv_left_front.setText(R.string.please_set_id); |
|
|
} else { |
|
|
} else { |
|
|
tv_left_front.setText(String |
|
|
|
|
|
.format(getResources().getString(R.string.left_front_id), leftFront)); |
|
|
|
|
|
|
|
|
tv_left_front.setText(getString(R.string.left_front_hint) + ":" + leftFront); |
|
|
} |
|
|
} |
|
|
if (TextUtils.isEmpty(rightFront)) { |
|
|
if (TextUtils.isEmpty(rightFront)) { |
|
|
tv_right_front.setText(R.string.please_set_id); |
|
|
tv_right_front.setText(R.string.please_set_id); |
|
|
} else { |
|
|
} else { |
|
|
tv_right_front.setText(String |
|
|
|
|
|
.format(getResources().getString(R.string.right_front_id), rightFront)); |
|
|
|
|
|
|
|
|
tv_right_front.setText(getString(R.string.left_rear_hint) + ":" + rightFront); |
|
|
} |
|
|
} |
|
|
if (TextUtils.isEmpty(leftRear)) { |
|
|
if (TextUtils.isEmpty(leftRear)) { |
|
|
tv_left_rear.setText(R.string.please_set_id); |
|
|
tv_left_rear.setText(R.string.please_set_id); |
|
|
} else { |
|
|
} else { |
|
|
tv_left_rear.setText(String |
|
|
|
|
|
.format(getResources().getString(R.string.left_rear_id), leftRear)); |
|
|
|
|
|
|
|
|
tv_left_rear.setText(getString(R.string.right_front_hint) + ":" + leftRear); |
|
|
} |
|
|
} |
|
|
if (TextUtils.isEmpty(rightRear)) { |
|
|
if (TextUtils.isEmpty(rightRear)) { |
|
|
tv_right_rear.setText(R.string.please_set_id); |
|
|
tv_right_rear.setText(R.string.please_set_id); |
|
|
} else { |
|
|
} else { |
|
|
tv_right_rear.setText(String |
|
|
|
|
|
.format(getResources().getString(R.string.right_rear_id), rightRear)); |
|
|
|
|
|
|
|
|
tv_right_rear.setText(getString(R.string.right_rear_hint) + ":" + rightRear); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void onClick(View v) { |
|
|
public void onClick(View v) { |
|
|
switch (v.getId()) { |
|
|
switch (v.getId()) { |
|
|
|
|
|
|
|
|
break; |
|
|
break; |
|
|
case R.id.btn_get_info: |
|
|
case R.id.btn_get_info: |
|
|
if (deviceIdMap.isEmpty() || noId()) { |
|
|
if (deviceIdMap.isEmpty() || noId()) { |
|
|
T.showLong(this, R.string.please_set_id); |
|
|
|
|
|
|
|
|
mTpmsScan.startScan(); |
|
|
} else { |
|
|
} else { |
|
|
if (mTpmsScan != null && deviceIdMap != null) { |
|
|
if (mTpmsScan != null && deviceIdMap != null) { |
|
|
mDeviceIdS = null; |
|
|
mDeviceIdS = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void onGetData(byte[] bytes,String mac, String deviceId, int rssi, float pressure,int pressureUnit, float battery, |
|
|
|
|
|
int temp,int tempUnit, int status, float mcuVersion, int year, int month, int day, |
|
|
|
|
|
float bleVersion) { |
|
|
|
|
|
|
|
|
|
|
|
if (deviceIdMap != null) { |
|
|
|
|
|
for (Config.DevicePosition devicePosition : deviceIdMap.keySet()) { |
|
|
|
|
|
if (TextUtils.equals(deviceId, deviceIdMap.get(devicePosition))) { |
|
|
|
|
|
Config.DeviceState deviceState = Config.DeviceState.NORMAL; |
|
|
|
|
|
switch (status) { |
|
|
|
|
|
case 1: |
|
|
|
|
|
deviceState = Config.DeviceState.LEAK; |
|
|
|
|
|
break; |
|
|
|
|
|
case 2: |
|
|
|
|
|
deviceState = Config.DeviceState.INFLATE; |
|
|
|
|
|
break; |
|
|
|
|
|
case 3: |
|
|
|
|
|
deviceState = Config.DeviceState.START; |
|
|
|
|
|
break; |
|
|
|
|
|
case 4: |
|
|
|
|
|
deviceState = Config.DeviceState.POWER_ON; |
|
|
|
|
|
break; |
|
|
|
|
|
case 5: |
|
|
|
|
|
deviceState = Config.DeviceState.WEAK_UP; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
StringBuffer buffer = new StringBuffer(); |
|
|
|
|
|
buffer.append("设备位置:"); |
|
|
|
|
|
buffer.append(getPosition(devicePosition)); |
|
|
|
|
|
buffer.append(", 设备id:"); |
|
|
|
|
|
buffer.append(deviceId); |
|
|
|
|
|
buffer.append(", 电压:"); |
|
|
|
|
|
buffer.append(battery); |
|
|
|
|
|
buffer.append(", 气压:"); |
|
|
|
|
|
buffer.append(pressure); |
|
|
|
|
|
buffer.append(", 温度:"); |
|
|
|
|
|
buffer.append(temp); |
|
|
|
|
|
buffer.append(", 状态:"); |
|
|
|
|
|
buffer.append(getState(deviceState)); |
|
|
|
|
|
buffer.append(", 时间:"); |
|
|
|
|
|
buffer.append(ParseData.getTime()); |
|
|
|
|
|
sendMsg(buffer.toString()); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public void onGetData(byte[] bytes, String mac, String deviceId, int rssi, float pressure, int pressureUnit, float battery, int temp, int tempUnit, int status, float mcuVersion, int year, |
|
|
|
|
|
int month, int day, float bleVersion) { |
|
|
|
|
|
StringBuffer buffer = new StringBuffer(); |
|
|
|
|
|
for (Config.DevicePosition devicePosition : deviceIdMap.keySet()) { |
|
|
|
|
|
if (TextUtils.equals(deviceId, deviceIdMap.get(devicePosition))) { |
|
|
|
|
|
buffer.append("Location:"); |
|
|
|
|
|
buffer.append(getPosition(devicePosition)); |
|
|
|
|
|
buffer.append(", "); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void onStopScan() { |
|
|
|
|
|
sendMsg("停止扫描"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void onBluetoothStateOn() { |
|
|
|
|
|
T.showLong(this, "蓝牙已开启!"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void onBluetoothStateOff() { |
|
|
|
|
|
T.showLong(this, "蓝牙已关闭!"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Config.DeviceState deviceState = Config.DeviceState.NORMAL; |
|
|
|
|
|
switch (status) { |
|
|
|
|
|
case 1: |
|
|
|
|
|
deviceState = Config.DeviceState.LEAK; |
|
|
|
|
|
break; |
|
|
|
|
|
case 2: |
|
|
|
|
|
deviceState = Config.DeviceState.INFLATE; |
|
|
|
|
|
break; |
|
|
|
|
|
case 3: |
|
|
|
|
|
deviceState = Config.DeviceState.START; |
|
|
|
|
|
break; |
|
|
|
|
|
case 4: |
|
|
|
|
|
deviceState = Config.DeviceState.POWER_ON; |
|
|
|
|
|
break; |
|
|
|
|
|
case 5: |
|
|
|
|
|
deviceState = Config.DeviceState.WEAK_UP; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
buffer.append("deviceId:"); |
|
|
|
|
|
buffer.append(deviceId); |
|
|
|
|
|
buffer.append(", battery:"); |
|
|
|
|
|
buffer.append(battery); |
|
|
|
|
|
buffer.append(", pressure:"); |
|
|
|
|
|
buffer.append(pressure); |
|
|
|
|
|
buffer.append(", Temp:"); |
|
|
|
|
|
buffer.append(temp); |
|
|
|
|
|
buffer.append(", status:"); |
|
|
|
|
|
buffer.append(getState(deviceState)); |
|
|
|
|
|
buffer.append(", time:"); |
|
|
|
|
|
buffer.append(ParseData.getTime()); |
|
|
|
|
|
sendMsg(buffer.toString()); |
|
|
|
|
|
|
|
|
public void onBluetoothTurningOn() { |
|
|
|
|
|
T.showLong(this, "蓝牙开启中!"); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void onBluetoothTurningOff() { |
|
|
|
|
|
T.showLong(this, "蓝牙关闭中!"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String getPosition(Config.DevicePosition devicePosition) { |
|
|
private String getPosition(Config.DevicePosition devicePosition) { |
|
|
switch (devicePosition) { |
|
|
switch (devicePosition) { |
|
|
case LEFT_FRONT: |
|
|
case LEFT_FRONT: |
|
|
return "左前"; |
|
|
|
|
|
|
|
|
return getString(R.string.left_front_hint); |
|
|
case RIGHT_FRONT: |
|
|
case RIGHT_FRONT: |
|
|
return "右前"; |
|
|
|
|
|
|
|
|
return getString(R.string.left_rear_hint); |
|
|
case LEFT_REAR: |
|
|
case LEFT_REAR: |
|
|
return "左后"; |
|
|
|
|
|
|
|
|
return getString(R.string.right_front_hint); |
|
|
case RIGHT_REAR: |
|
|
case RIGHT_REAR: |
|
|
return "右后"; |
|
|
|
|
|
|
|
|
return getString(R.string.right_rear_hint); |
|
|
default: |
|
|
default: |
|
|
return ""; |
|
|
return ""; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private String getState(Config.DeviceState deviceState) { |
|
|
private String getState(Config.DeviceState deviceState) { |
|
|
switch (deviceState) { |
|
|
switch (deviceState) { |
|
|
case NORMAL: |
|
|
case NORMAL: |
|
|
return "正常"; |
|
|
|
|
|
|
|
|
return getString(R.string.normal); |
|
|
case LEAK: |
|
|
case LEAK: |
|
|
return "漏气"; |
|
|
|
|
|
|
|
|
return getString(R.string.leak); |
|
|
case INFLATE: |
|
|
case INFLATE: |
|
|
return "充气"; |
|
|
|
|
|
|
|
|
return getString(R.string.inflatable); |
|
|
case START: |
|
|
case START: |
|
|
return "启动"; |
|
|
|
|
|
|
|
|
return getString(R.string.start); |
|
|
case POWER_ON: |
|
|
case POWER_ON: |
|
|
return "上电"; |
|
|
|
|
|
|
|
|
return getString(R.string.power_on); |
|
|
case WEAK_UP: |
|
|
case WEAK_UP: |
|
|
return "唤醒"; |
|
|
|
|
|
|
|
|
return getString(R.string.wake); |
|
|
case TEMP_ERROR: |
|
|
case TEMP_ERROR: |
|
|
return "温度异常"; |
|
|
|
|
|
|
|
|
return getString(R.string.temp_err); |
|
|
case BATTERY_ERROR: |
|
|
case BATTERY_ERROR: |
|
|
return "电量异常"; |
|
|
|
|
|
|
|
|
return getString(R.string.battery_err); |
|
|
case UNKNOWN: |
|
|
case UNKNOWN: |
|
|
return "未知"; |
|
|
|
|
|
|
|
|
return getString(R.string.unknown); |
|
|
default: |
|
|
default: |
|
|
return ""; |
|
|
return ""; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
private boolean noId() { |
|
|
private boolean noId() { |
|
|
if (deviceIdMap != null && !deviceIdMap.isEmpty()) { |
|
|
if (deviceIdMap != null && !deviceIdMap.isEmpty()) { |
|
|
if (TextUtils.isEmpty(deviceIdMap.get(Config.DevicePosition.LEFT_FRONT)) && TextUtils |
|
|
|
|
|
.isEmpty(deviceIdMap.get(Config.DevicePosition.LEFT_REAR)) && TextUtils |
|
|
|
|
|
.isEmpty(deviceIdMap.get(Config.DevicePosition.RIGHT_FRONT)) && TextUtils |
|
|
|
|
|
.isEmpty(deviceIdMap.get(Config.DevicePosition.RIGHT_REAR))) {//当所有ID都为空时,停止扫描 |
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(deviceIdMap.get(Config.DevicePosition.LEFT_FRONT)) && TextUtils.isEmpty(deviceIdMap.get(Config.DevicePosition.LEFT_REAR)) && TextUtils |
|
|
|
|
|
.isEmpty(deviceIdMap.get(Config.DevicePosition.RIGHT_FRONT)) && TextUtils.isEmpty(deviceIdMap.get(Config.DevicePosition.RIGHT_REAR))) { |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |