Commit 7b0ef205 by chengchong

qweq

parent bc25d7a6
package com.example.blu.toys.activity; package com.example.blu.toys.activity;
import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
...@@ -38,7 +39,7 @@ public class SearchingActivity extends BaseActivity { ...@@ -38,7 +39,7 @@ public class SearchingActivity extends BaseActivity {
@RequiresApi(api = Build.VERSION_CODES.N) @RequiresApi(api = Build.VERSION_CODES.N)
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true) @Subscribe(threadMode = ThreadMode.MAIN)
public void GoDeviceListPage(List<BleDevice> bleDevices) { public void GoDeviceListPage(List<BleDevice> bleDevices) {
goActivity(SelectDeviceActivity.class); goActivity(SelectDeviceActivity.class);
} }
......
...@@ -38,35 +38,31 @@ public class SelectDeviceActivity extends BaseActivity { ...@@ -38,35 +38,31 @@ public class SelectDeviceActivity extends BaseActivity {
@Override @Override
public void init(Bundle savedInstanceState) { public void init(Bundle savedInstanceState) {
EventBus.getDefault().register(this); EventBus.getDefault().register(this);
}
@Override
public void initData() {
if (bleDevices == null) { if (bleDevices == null) {
bleDevices = new ArrayList<>(); bleDevices = new ArrayList<>();
} }
mRecyclerView.setLayoutManager(getLinearLayout()); mRecyclerView.setLayoutManager(getLinearLayout());
bleDeviceAdapter = new BleDeviceAdapter(R.layout.ble_devices_item, bleDevices); bleDeviceAdapter = new BleDeviceAdapter(R.layout.ble_devices_item, bleDevices);
mRecyclerView.setAdapter(bleDeviceAdapter); mRecyclerView.setAdapter(bleDeviceAdapter);
}
@Override
public void initData() {
bleDeviceAdapter.setOnItemClickListener((adapter, view, position) -> { bleDeviceAdapter.setOnItemClickListener((adapter, view, position) -> {
BleDevice bleDevice = (BleDevice) adapter.getItem(position); BleDevice bleDevice = (BleDevice) adapter.getItem(position);
BlePlay.getInstance().connectedBleDevice(bleDevice); BlePlay.getInstance().connectedBleDevice(bleDevice);
}); });
showBleDevices();
} }
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true) public void showBleDevices() {
public void showBleDevices(List<BleDevice> bles) { List<BleDevice> bles = BlePlay.getInstance().getScanResultList();
if (CollectionUtils.isEmpty(bles)) { if (CollectionUtils.isEmpty(bles)) {
return; return;
} }
if (bleDevices == null) {
bleDevices = new ArrayList<>();
}
bleDevices.clear(); bleDevices.clear();
for (int i = 0; i < bles.size(); i++) { for (int i = 0; i < bles.size(); i++) {
BleDevice bleDevice = bles.get(i); BleDevice bleDevice = bles.get(i);
String deviceName = bleDevice.getName(); String deviceName = bleDevice.getName();
......
...@@ -40,8 +40,10 @@ public class SetTimeActivity extends BaseActivity { ...@@ -40,8 +40,10 @@ public class SetTimeActivity extends BaseActivity {
WheelView wheelMinute; WheelView wheelMinute;
@BindView(R.id.wheel_second) @BindView(R.id.wheel_second)
WheelView wheelSecond; WheelView wheelSecond;
@BindView(R.id.wheel_am_pm) // @BindView(R.id.wheel_am_pm)
WheelView wheelAmPm; // WheelView wheelAmPm;
// amPmList.add("AM");
// amPmList.add("PM");
@BindView(R.id.wheel_hour_dw) @BindView(R.id.wheel_hour_dw)
WheelView wheelHour_dw; WheelView wheelHour_dw;
...@@ -59,20 +61,14 @@ public class SetTimeActivity extends BaseActivity { ...@@ -59,20 +61,14 @@ public class SetTimeActivity extends BaseActivity {
TypefaceTextView will; TypefaceTextView will;
private ArrayList<String> hourList = new ArrayList<>(); private ArrayList<String> hourList = new ArrayList<>();
private ArrayList<String> minuteList = new ArrayList<>(); private ArrayList<String> sixList = new ArrayList<>();
private ArrayList<String> secondList = new ArrayList<>(); private ArrayList<String> selectTime = new ArrayList<>();
private ArrayList<String> amPmList = new ArrayList<>();
private int amOrPm = 0;
String selectHour; String selectHour;
String selectMin; String selectMin;
String selectSec; String selectSec;
String selectHour_dw;
String selectMin_dw;
String selectSec_dw;
int hour = 0; int hour = 0;
int min = 0; int min = 0;
...@@ -84,6 +80,165 @@ public class SetTimeActivity extends BaseActivity { ...@@ -84,6 +80,165 @@ public class SetTimeActivity extends BaseActivity {
return R.layout.activity_set_time; return R.layout.activity_set_time;
} }
//设置底部的时间
private void setDwTime() {
Date time = new Date();
int currHour = LocalDateUtils.getHour(time);
int currMinute = LocalDateUtils.getSecond(time);
int currSecond = LocalDateUtils.getMinute(time);
String hour = wheelHour.getSeletedItem();
String minute = wheelMinute.getSeletedItem();
String second = wheelSecond.getSeletedItem();
int selectHourTime;
int selectMinTime;
int selectSecTime;
String selectHour_dw;
String selectMin_dw;
String selectSec_dw;
//小时
if (hour.startsWith("0")) {
hour = hour.substring(1);
}
selectHourTime = Integer.parseInt(hour);
int dowHour = selectHourTime - currHour;
if (dowHour < 10) {
selectHour_dw = "0" + dowHour;
} else {
selectHour_dw = String.valueOf(dowHour);
}
wheelHour_dw.setSeletion(selectTime.indexOf(selectHour_dw));
//分钟
if (minute.startsWith("0")) {
minute = minute.substring(1);
}
selectMinTime = Integer.parseInt(minute);
int dowMin = selectMinTime - currMinute;
if (dowMin < 10) {
selectMin_dw = "0" + dowMin;
} else {
selectMin_dw = String.valueOf(dowMin);
}
wheelMinute_dw.setSeletion(sixList.indexOf(selectMin_dw));
//秒
if (second.startsWith("0")) {
second = second.substring(1);
}
selectSecTime = Integer.parseInt(second);
int dowSec = selectSecTime - currSecond;
if (dowSec < 10) {
selectSec_dw = "0" + dowSec;
} else {
selectSec_dw = String.valueOf(dowSec);
}
wheelSecond_dw.setSeletion(sixList.indexOf(selectSec_dw));
}
//设置顶部的时间
private void setUpTime() {
String hour = wheelHour.getSeletedItem();
String minute = wheelMinute.getSeletedItem();
String second = wheelSecond.getSeletedItem();
String dwHour = wheelHour_dw.getSeletedItem();
String dwMinute = wheelMinute_dw.getSeletedItem();
String dwSecond = wheelSecond_dw.getSeletedItem();
int selectHourTime;
int selectMinTime;
int selectSecTime;
int dwHourTime;
int dwMinTime;
int dwSecTime;
if (hour.startsWith("0")) {
hour = hour.substring(1);
}
selectHourTime = Integer.parseInt(hour);
if (dwHour.startsWith("0")) {
dwHour = dwHour.substring(1);
}
dwHourTime = Integer.parseInt(dwHour);
selectHourTime = selectHourTime + dwHourTime;
if (selectHourTime < 10) {
hour = "0" + selectHourTime;
} else {
hour = String.valueOf(selectHourTime);
}
wheelHour.setSeletion(hourList.indexOf(hour));
//分钟
if (minute.startsWith("0")) {
minute = minute.substring(1);
}
selectMinTime = Integer.parseInt(minute);
if (dwMinute.startsWith("0")) {
dwMinute = dwMinute.substring(1);
}
dwMinTime = Integer.parseInt(dwMinute);
selectMinTime = selectMinTime + dwMinTime;
if (selectMinTime < 10) {
minute = "0" + selectMinTime;
} else {
minute = String.valueOf(selectMinTime);
}
wheelMinute.setSeletion(sixList.indexOf(minute));
//秒
if (second.startsWith("0")) {
second = second.substring(1);
}
selectSecTime = Integer.parseInt(second);
if (dwSecond.startsWith("0")) {
dwSecond = dwSecond.substring(1);
}
dwSecTime = Integer.parseInt(dwSecond);
selectSecTime = selectSecTime + dwSecTime;
if (selectSecTime < 10) {
second = "0" + selectSecTime;
} else {
second = String.valueOf(selectSecTime);
}
wheelSecond.setSeletion(sixList.indexOf(second));
}
@Override @Override
public void init(Bundle savedInstanceState) { public void init(Bundle savedInstanceState) {
...@@ -96,33 +251,7 @@ public class SetTimeActivity extends BaseActivity { ...@@ -96,33 +251,7 @@ public class SetTimeActivity extends BaseActivity {
wheelHour.setSeletion(indexHour); wheelHour.setSeletion(indexHour);
return; return;
} }
Date time = new Date(); setDwTime();
Calendar calendar = Calendar.getInstance();
calendar.setTime(time);
int nowHour = calendar.get(Calendar.HOUR);//时(12小时制)
if (item.startsWith("0")) {
item = item.substring(1);
}
//获取选择的时间
Integer selectHourTime = Integer.valueOf(item);
if (selectHourTime < nowHour) {
int indexHour = hourList.indexOf(selectHour);
wheelHour.setSeletion(indexHour);
ToastUtils.show("选择的时间不能小于当前时间");
return;
}
// selectHour = item;
// //下面的小时 显示
// int dowHour = selectHourTime - nowHour;
// if (dowHour < 10) {
// selectHour_dw = "0" + dowHour;
// } else {
// selectHour_dw = String.valueOf(dowHour);
// }
// wheelHour_dw.setSeletion(hourList.indexOf(selectHour_dw));
} }
}); });
...@@ -132,66 +261,12 @@ public class SetTimeActivity extends BaseActivity { ...@@ -132,66 +261,12 @@ public class SetTimeActivity extends BaseActivity {
@Override @Override
public void onSelected(int selectedIndex, String item) { public void onSelected(int selectedIndex, String item) {
if (StringUtils.isEmpty(item)) { if (StringUtils.isEmpty(item)) {
int indexMinute = minuteList.indexOf(selectMin); int indexMinute = sixList.indexOf(selectMin);
wheelMinute.setSeletion(indexMinute); wheelMinute.setSeletion(indexMinute);
return; return;
} }
setDwTime();
Calendar calendar = Calendar.getInstance();
int nowHour = calendar.get(Calendar.HOUR);//时(12小时制)
int nowMin = calendar.get(Calendar.MINUTE);
String currentSelectHour;
if (selectHour.startsWith("0")) {
currentSelectHour = item.substring(1);
} else {
currentSelectHour = selectHour;
}
Integer selectHourTime = Integer.valueOf(currentSelectHour);
if (selectHourTime < nowHour) {
ToastUtils.show("选择的时间不能小于当前时间");
return;
}
if (selectHourTime > nowHour) {
selectMin = item;
}
if (selectHourTime == nowHour) {
if (item.startsWith("0")) {
item = item.substring(1);
}
Integer selectMinTime = Integer.valueOf(item);
if (selectMinTime < nowMin) {
int indexMinute = minuteList.indexOf(selectMin);
wheelMinute.setSeletion(indexMinute);
ToastUtils.show("选择的时间不能小于当前时间");
} else {
selectMin = item;
}
}
if (selectMin.startsWith("0")) {
item = item.substring(1);
}
Integer selectMinTime = Integer.valueOf(item);
//设置下面的时间
// int dowMin = selectMinTime - nowMin;
// if (dowMin < 10) {
// selectMin_dw = "0" + dowMin;
// } else {
// selectMin_dw = String.valueOf(dowMin);
// }
//
// wheelMinute_dw.setSeletion(minuteList.indexOf(selectMin_dw));
} }
}); });
...@@ -201,77 +276,12 @@ public class SetTimeActivity extends BaseActivity { ...@@ -201,77 +276,12 @@ public class SetTimeActivity extends BaseActivity {
@Override @Override
public void onSelected(int selectedIndex, String item) { public void onSelected(int selectedIndex, String item) {
if (StringUtils.isEmpty(item)) { if (StringUtils.isEmpty(item)) {
int indexSecond = secondList.indexOf(selectSec); int indexSecond = sixList.indexOf(selectSec);
wheelSecond.setSeletion(indexSecond); wheelSecond.setSeletion(indexSecond);
return; return;
} }
Date time = new Date(); setDwTime();
Calendar calendar = Calendar.getInstance();
calendar.setTime(time);
int nowHour = calendar.get(Calendar.HOUR);//时(12小时制)
int nowMinute = calendar.get(Calendar.MINUTE);//分
int nowSecond = calendar.get(Calendar.SECOND);
String currentHour;
if (selectHour.startsWith("0")) {
currentHour = item.substring(1);
} else {
currentHour = selectHour;
}
Integer currentSelectHour = Integer.valueOf(currentHour);
String currentMin;
if (selectMin.startsWith("0")) {
currentMin = item.substring(1);
} else {
currentMin = selectMin;
}
Integer currentSelectMin = Integer.valueOf(currentMin);
//当小时大于当前的时间
if (currentSelectHour >= nowHour) {
if (currentSelectMin > nowMinute) {
selectSec = item;
}
if (currentSelectMin == nowMinute) {
String sec;
if (item.startsWith("0")) {
sec = item.substring(1);
} else {
sec = item;
}
Integer selectSecTime = Integer.valueOf(sec);
//计算秒
if (selectSecTime < nowSecond) {
int indexSec = secondList.indexOf(selectMin);
wheelSecond.setSeletion(indexSec);
ToastUtils.show("选择的时间不能小于当前时间");
} else {
selectMin = item;
}
//
// int dowSec = selectSecTime - nowSecond;
// if (dowSec < 10) {
// selectSec_dw = "0" + dowSec;
// } else {
// selectSec_dw = String.valueOf(dowSec);
// }
//
// wheelSecond_dw.setSeletion(secondList.indexOf(selectSec_dw));
}
} else {
ToastUtils.show("选择的时间不能小于当前时间");
}
} }
}); });
...@@ -280,8 +290,7 @@ public class SetTimeActivity extends BaseActivity { ...@@ -280,8 +290,7 @@ public class SetTimeActivity extends BaseActivity {
wheelHour_dw.setOnWheelViewListener(new WheelView.OnWheelViewListener() { wheelHour_dw.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
@Override @Override
public void onSelected(int selectedIndex, String item) { public void onSelected(int selectedIndex, String item) {
selectHour_dw = hourList.get(selectedIndex); setUpTime();
} }
}); });
...@@ -289,7 +298,7 @@ public class SetTimeActivity extends BaseActivity { ...@@ -289,7 +298,7 @@ public class SetTimeActivity extends BaseActivity {
wheelMinute_dw.setOnWheelViewListener(new WheelView.OnWheelViewListener() { wheelMinute_dw.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
@Override @Override
public void onSelected(int selectedIndex, String item) { public void onSelected(int selectedIndex, String item) {
selectMin_dw = minuteList.get(selectedIndex); setUpTime();
} }
}); });
...@@ -297,56 +306,46 @@ public class SetTimeActivity extends BaseActivity { ...@@ -297,56 +306,46 @@ public class SetTimeActivity extends BaseActivity {
wheelSecond_dw.setOnWheelViewListener(new WheelView.OnWheelViewListener() { wheelSecond_dw.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
@Override @Override
public void onSelected(int selectedIndex, String item) { public void onSelected(int selectedIndex, String item) {
selectSec_dw = secondList.get(selectedIndex); setUpTime();
} }
}); });
} }
@Override @Override
public void initData() { public void initData() {
Date time = new Date(); Date time = new Date();
Calendar calendar = Calendar.getInstance(); int hour = LocalDateUtils.getHour(time);
calendar.setTime(time); int minute = LocalDateUtils.getSecond(time);
int hour = calendar.get(Calendar.HOUR);//时(12小时制) int second = LocalDateUtils.getMinute(time);
int minute = calendar.get(Calendar.MINUTE);//分
int second = calendar.get(Calendar.SECOND);
int currTime = LocalDateUtils.getHour(time);
if (currTime > 12) {
amOrPm = 1;
} else {
amOrPm = 0;
}
hourList.clear();
minuteList.clear();
secondList.clear();
amPmList.add("AM"); hourList.clear();
amPmList.add("PM"); sixList.clear();
hourList.add("00"); hourList.add("00");
for (int i = 1; i <= 12; i++) { for (int i = 1; i <= 24; i++) {
if (i < 10) { if (i < 10) {
hourList.add("0" + i); hourList.add("0" + i);
} else { } else {
hourList.add(String.valueOf(i)); hourList.add(String.valueOf(i));
} }
} }
for (int i = 0; i <= 59; i++) { for (int i = 0; i <= 59; i++) {
if (i < 10) { if (i < 10) {
minuteList.add("0" + i); sixList.add("0" + i);
secondList.add("0" + i);
} else { } else {
minuteList.add(String.valueOf(i)); sixList.add(String.valueOf(i));
secondList.add(String.valueOf(i));
} }
}
for (int i = 1; i <= 16; i++) {
if (i < 10) {
selectTime.add("0" + i);
} else {
selectTime.add(String.valueOf(i));
}
} }
///时//// ///时////
...@@ -362,47 +361,42 @@ public class SetTimeActivity extends BaseActivity { ...@@ -362,47 +361,42 @@ public class SetTimeActivity extends BaseActivity {
///分//// ///分////
wheelMinute.setOffset(3);// 对话框中当前项上面和下面的项数 wheelMinute.setOffset(3);// 对话框中当前项上面和下面的项数
wheelMinute.setItems(minuteList);// 设置数据源 wheelMinute.setItems(sixList);// 设置数据源
if (minute < 10) { if (minute < 10) {
selectMin = "0" + minute; selectMin = "0" + minute;
} else { } else {
selectMin = String.valueOf(minute); selectMin = String.valueOf(minute);
} }
int indexMinute = minuteList.indexOf(selectMin); int indexMinute = sixList.indexOf(selectMin);
wheelMinute.setSeletion(indexMinute);// 默认选中第三项 wheelMinute.setSeletion(indexMinute);// 默认选中第三项
///秒//// ///秒////
wheelSecond.setOffset(3); wheelSecond.setOffset(3);
wheelSecond.setItems(secondList);// 设置数据源 wheelSecond.setItems(sixList);// 设置数据源
if (second < 10) { if (second < 10) {
selectSec = "0" + second; selectSec = "0" + second;
} else { } else {
selectSec = String.valueOf(second); selectSec = String.valueOf(second);
} }
int indexSecond = secondList.indexOf(selectSec); int indexSecond = sixList.indexOf(selectSec);
wheelSecond.setSeletion(indexSecond); wheelSecond.setSeletion(indexSecond);
wheelAmPm.setOffset(2);// 对话框中当前项上面和下面的项数
wheelAmPm.setItems(amPmList);// 设置数据源
wheelAmPm.setSeletion(amOrPm);// 默认选中第三项
/////////下//////// /////////下////////
///时//// ///时////
wheelHour_dw.setOffset(3); wheelHour_dw.setOffset(3);
wheelHour_dw.setItems(hourList); wheelHour_dw.setItems(selectTime);
wheelHour_dw.setSeletion(0); wheelHour_dw.setSeletion(0);
///分//// ///分////
wheelMinute_dw.setOffset(3);// 对话框中当前项上面和下面的项数 wheelMinute_dw.setOffset(3);// 对话框中当前项上面和下面的项数
wheelMinute_dw.setItems(minuteList);// 设置数据源 wheelMinute_dw.setItems(sixList);// 设置数据源
wheelMinute_dw.setSeletion(0);// 默认选中第三项 wheelMinute_dw.setSeletion(0);// 默认选中第三项
///秒//// ///秒////
wheelSecond_dw.setOffset(3); wheelSecond_dw.setOffset(3);
wheelSecond_dw.setItems(secondList); wheelSecond_dw.setItems(sixList);
wheelSecond_dw.setSeletion(0); wheelSecond_dw.setSeletion(0);
} }
...@@ -426,6 +420,10 @@ public class SetTimeActivity extends BaseActivity { ...@@ -426,6 +420,10 @@ public class SetTimeActivity extends BaseActivity {
ToastUtils.show("请打开蓝牙"); ToastUtils.show("请打开蓝牙");
return; return;
} }
String selectHour_dw = wheelHour_dw.getSeletedItem();
String selectMin_dw = wheelMinute_dw.getSeletedItem();
String selectSec_dw = wheelSecond_dw.getSeletedItem();
if (TextUtils.isEmpty(selectHour_dw)) { if (TextUtils.isEmpty(selectHour_dw)) {
hour = 0; hour = 0;
} else if (selectHour_dw.startsWith("0")) { } else if (selectHour_dw.startsWith("0")) {
......
...@@ -47,6 +47,15 @@ public class BlePlay { ...@@ -47,6 +47,15 @@ public class BlePlay {
private SpUtils mSpUtils; private SpUtils mSpUtils;
public List<BleDevice> getScanResultList() {
return scanResultList;
}
public void setScanResultList(List<BleDevice> scanResultList) {
this.scanResultList = scanResultList;
}
private List<BleDevice> scanResultList;
public static BlePlay getInstance() { public static BlePlay getInstance() {
if (instance == null) { if (instance == null) {
...@@ -99,7 +108,8 @@ public class BlePlay { ...@@ -99,7 +108,8 @@ public class BlePlay {
@Override @Override
public void onScanFinished(List<BleDevice> scanResultList) { public void onScanFinished(List<BleDevice> scanResultList) {
LogUtils.e("扫描介素获取设备列表"); LogUtils.e("扫描介素获取设备列表");
EventBus.getDefault().postSticky(scanResultList); setScanResultList(scanResultList);
EventBus.getDefault().post(scanResultList);
} }
}); });
} }
......
...@@ -5,142 +5,155 @@ import java.text.SimpleDateFormat; ...@@ -5,142 +5,155 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
public class TrafficLightBean { public class TrafficLightBean {
/** /**
* 固定头 1字节 * 固定头 1字节
*/ */
private byte begin=0x24; private byte begin=0x24;
/** /**
* 长度 1字节 * 长度 1字节
*/ */
private byte length=0x11; private byte length=0x11;
/** /**
* 协议编号 01:关机协议 02:暂停于继续协议 1字节 * 协议编号 01:关机协议 02:暂停于继续协议 1字节
*/ */
private byte cmd; private byte cmd;
/** /**
* 手机时间 yyMMddHHssmm 6个字节 * 手机时间 yyMMddHHssmm 6个字节
*/ */
private byte[] phoneTime; private byte[] phoneTime;
/** /**
* 暂停继续 0:暂停 1:继续 1字节 * 暂停继续 0:暂停 1:继续 1字节
*/ */
private byte suspendAndContinue; private byte suspendAndContinue;
/** /**
* 剩余时间(小端) 秒为单位 2字节 * 剩余时间(小端) 秒为单位 2字节
*/ */
private byte[] timeRemaining; private byte[] timeRemaining;
/** /**
* 亮度调节 0-100 1字节 * 亮度调节 0-100 1字节
*/ */
private byte brightness; private byte brightness;
/** /**
* 开机声音编号 1-20 1字节 * 开机声音编号 1-20 1字节
*/ */
private byte openSoundNo; private byte openSoundNo;
/** /**
* 关机声音编号 1-20 1字节 * 关机声音编号 1-20 1字节
*/ */
private byte closeSoundNo; private byte closeSoundNo;
/** /**
* 红绿灯变更方式 0: 由绿变红 1:由红变黄 1字节 * 红绿灯变更方式 0: 由绿变红 1:由红变黄 1字节
*/ */
private byte trafficLightUpdateSet; private byte trafficLightUpdateSet;
/** /**
* 警报开关 0:关 1:开 1字节 * 警报开关 0:关 1:开 1字节
*/ */
private byte alarm; private byte alarm;
private byte key; private byte key;
/** /**
* *
* @param protocolNo 协议编号 * @param protocolNo 协议编号
* @param suspendAndContinue 暂停或者继续 * @param suspendAndContinue 暂停或者继续
* @param timeRemaining 剩余时间 毫秒 * @param timeRemaining 剩余时间 毫秒
* @param brightness 亮度值 0-100 默认 50 * @param brightness 亮度值 0-100 默认 50
* @param openSoundNo 开机声音编号 默认 1 * @param openSoundNo 开机声音编号 默认 1
* @param closeSoundNo 关机声音编号 默认 10 * @param closeSoundNo 关机声音编号 默认 10
* @param trafficLightUpdateSet 红绿灯变更方式 默认 1 * @param trafficLightUpdateSet 红绿灯变更方式 默认 1
* @param alarm 报警状态 默认 0 * @param alarm 报警状态 默认 0
*/ */
public TrafficLightBean(Integer protocolNo,Integer suspendAndContinue,Integer timeRemaining,Integer brightness,Integer openSoundNo,Integer closeSoundNo,Integer trafficLightUpdateSet,Integer alarm){ public TrafficLightBean(Integer protocolNo,Integer suspendAndContinue,Integer timeRemaining,Integer brightness,Integer openSoundNo,Integer closeSoundNo,Integer trafficLightUpdateSet,Integer alarm){
this.cmd= BitOperator.integerTo1Byte(protocolNo); this.cmd= BitOperator.integerTo1Byte(protocolNo);
this.suspendAndContinue=BitOperator.integerTo1Byte(suspendAndContinue); this.suspendAndContinue=BitOperator.integerTo1Byte(suspendAndContinue);
this.timeRemaining=BitOperator.integerTo2Bytes(timeRemaining); System.out.println("传入的剩余时间:"+timeRemaining);
this.brightness=BitOperator.integerTo1Byte(brightness); this.timeRemaining=toLH(timeRemaining); //BitOperator.integerTo2Bytes();
this.openSoundNo=BitOperator.integerTo1Byte(openSoundNo); this.brightness=BitOperator.integerTo1Byte(brightness);
this.closeSoundNo=BitOperator.integerTo1Byte(closeSoundNo); this.openSoundNo=BitOperator.integerTo1Byte(openSoundNo);
this.trafficLightUpdateSet=BitOperator.integerTo1Byte(trafficLightUpdateSet); this.closeSoundNo=BitOperator.integerTo1Byte(closeSoundNo);
this.alarm=BitOperator.integerTo1Byte(alarm); this.trafficLightUpdateSet=BitOperator.integerTo1Byte(trafficLightUpdateSet);
SimpleDateFormat format= new SimpleDateFormat("yyMMddHHmmss"); this.alarm=BitOperator.integerTo1Byte(alarm);
String phoneTime= format.format(new Date()); SimpleDateFormat format= new SimpleDateFormat("yyMMddHHmmss");
this.phoneTime= BCD8421Operater.string2Bcd(phoneTime); String phoneTime= format.format(new Date());
String yy= phoneTime.substring(0,2); this.phoneTime= BCD8421Operater.string2Bcd(phoneTime);
String MM= phoneTime.substring(2,4); String yy= phoneTime.substring(0,2);
String dd= phoneTime.substring(4,6); String MM= phoneTime.substring(2,4);
String HH= phoneTime.substring(6,8); String dd= phoneTime.substring(4,6);
String mm= phoneTime.substring(8,10); String HH= phoneTime.substring(6,8);
String ss= phoneTime.substring(10,12); String mm= phoneTime.substring(8,10);
String ss= phoneTime.substring(10,12);
Integer bo1=BCD8421Operater.string2Bcd(yy)[0]+BCD8421Operater.string2Bcd(HH)[0];
Integer bo2=BCD8421Operater.string2Bcd(MM)[0]^BCD8421Operater.string2Bcd(mm)[0]; Integer bo1=BCD8421Operater.string2Bcd(yy)[0]+BCD8421Operater.string2Bcd(HH)[0];
Integer bo3=BCD8421Operater.string2Bcd(dd)[0]+BCD8421Operater.string2Bcd(ss)[0]; Integer bo2=BCD8421Operater.string2Bcd(MM)[0]^BCD8421Operater.string2Bcd(mm)[0];
Integer bo3=BCD8421Operater.string2Bcd(dd)[0]+BCD8421Operater.string2Bcd(ss)[0];
Integer key=(bo1^bo2)+bo3;
this.key=BitOperator.integerTo1Byte(key); Integer key=(bo1^bo2)+bo3;
this.key=BitOperator.integerTo1Byte(key);
System.out.println("时间:"+phoneTime);
System.out.println("key 10进制:"+key); System.out.println("时间:"+phoneTime);
System.out.println("key byte:"+this.key); System.out.println("key 10进制:"+key);
System.out.println("key byte:"+this.key);
}
}
public byte[] toByte(){ /**
//数据要加密的 * int 转换小端
byte[] resData=new byte[17]; * @param n
resData[0]=this.begin; * @return
resData[1]=this.length; */
resData[2]=BitOperator.integerTo1Byte(this.cmd+this.key); public static byte[] toLH(int n) {
resData[3]=this.phoneTime[0];//1 不需要加密 byte[] b = new byte[2];
resData[4]=this.phoneTime[1];//2 不需要加密 b[0] = (byte) (n & 0xff);
resData[5]=this.phoneTime[2];//3 不需要加密 b[1] = (byte) (n >> 8 & 0xff);
resData[6]=this.phoneTime[3];//4 不需要加密 return b;
resData[7]=this.phoneTime[4];//5 不需要急吗 }
resData[8]=this.phoneTime[5];//6 不需要加密
resData[9]=BitOperator.integerTo1Byte(this.suspendAndContinue+this.key); public byte[] toByte(){
resData[10]=BitOperator.integerTo1Byte(this.timeRemaining[0]+this.key); //数据要加密的
resData[11]=BitOperator.integerTo1Byte(this.timeRemaining[1]+this.key); byte[] resData=new byte[17];
resData[12]=BitOperator.integerTo1Byte(this.brightness+this.key); resData[0]=this.begin;
resData[13]=BitOperator.integerTo1Byte(this.openSoundNo+this.key); resData[1]=this.length;
resData[14]=BitOperator.integerTo1Byte(this.closeSoundNo+this.key); resData[2]=BitOperator.integerTo1Byte(this.cmd+this.key);
resData[15]=BitOperator.integerTo1Byte(this.trafficLightUpdateSet+this.key); resData[3]=this.phoneTime[0];//1 不需要加密
resData[16]=BitOperator.integerTo1Byte(this.alarm+this.key); resData[4]=this.phoneTime[1];//2 不需要加密
return resData; resData[5]=this.phoneTime[2];//3 不需要加密
} resData[6]=this.phoneTime[3];//4 不需要加密
resData[7]=this.phoneTime[4];//5 不需要急吗
public static void main(String[] args) { resData[8]=this.phoneTime[5];//6 不需要加密
TrafficLightBean trafficLightBean=new TrafficLightBean(2,0, resData[9]=BitOperator.integerTo1Byte(this.suspendAndContinue+this.key);
300,100,10,20,01,01); resData[10]=BitOperator.integerTo1Byte(this.timeRemaining[0]+this.key);
resData[11]=BitOperator.integerTo1Byte(this.timeRemaining[1]+this.key);
System.out.println(HexStringUtils.toHexString(trafficLightBean.toByte())); resData[12]=BitOperator.integerTo1Byte(this.brightness+this.key);
resData[13]=BitOperator.integerTo1Byte(this.openSoundNo+this.key);
// System.out.printf("00000000"); resData[14]=BitOperator.integerTo1Byte(this.closeSoundNo+this.key);
resData[15]=BitOperator.integerTo1Byte(this.trafficLightUpdateSet+this.key);
} resData[16]=BitOperator.integerTo1Byte(this.alarm+this.key);
return resData;
}
public static void main(String[] args) {
TrafficLightBean trafficLightBean=new TrafficLightBean(2,0,
300,100,10,20,01,01);
System.out.println(HexStringUtils.toHexString(trafficLightBean.toByte()));
// System.out.printf("00000000");
}
} }
\ No newline at end of file
package com.example.blu.toys.utils; package com.example.blu.toys.utils;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek; import java.time.DayOfWeek;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -158,6 +160,16 @@ public class LocalDateUtils { ...@@ -158,6 +160,16 @@ public class LocalDateUtils {
return format(LocalTime.now(), TIME_PATTERN); return format(LocalTime.now(), TIME_PATTERN);
} }
public static Date getDateTime(String time) {
SimpleDateFormat sdf = new SimpleDateFormat(TIME_PATTERN);//根据自己情况
try {
return sdf.parse(time);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
/** /**
* 获取当前星期字符串. * 获取当前星期字符串.
* *
...@@ -623,9 +635,6 @@ public class LocalDateUtils { ...@@ -623,9 +635,6 @@ public class LocalDateUtils {
} }
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(getLocalDateTimeStr()); System.out.println(getLocalDateTimeStr());
System.out.println(getLocalDateStr()); System.out.println(getLocalDateStr());
...@@ -708,9 +717,9 @@ public class LocalDateUtils { ...@@ -708,9 +717,9 @@ public class LocalDateUtils {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date()); //放入Date类型数据 calendar.setTime(new Date()); //放入Date类型数据
calendar.get(Calendar.HOUR); //时(12小时制) calendar.get(Calendar.HOUR); //时(12小时制)
calendar.get(Calendar.MINUTE); //分 calendar.get(Calendar.MINUTE); //分
calendar.get(Calendar.SECOND); calendar.get(Calendar.SECOND);
System.out.println(calendar.get(Calendar.HOUR) + "h" + calendar.get(Calendar.MINUTE) + "m" + calendar.get(Calendar.SECOND) + "s"); System.out.println(calendar.get(Calendar.HOUR) + "h" + calendar.get(Calendar.MINUTE) + "m" + calendar.get(Calendar.SECOND) + "s");
......
...@@ -80,8 +80,7 @@ ...@@ -80,8 +80,7 @@
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/dp_75" android:layout_height="@dimen/dp_75"
android:background="@drawable/black_thumb" android:background="@drawable/black_thumb">
>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -132,12 +131,12 @@ ...@@ -132,12 +131,12 @@
android:layout_gravity="center_vertical" /> android:layout_gravity="center_vertical" />
<com.example.blu.toys.view.WheelView <!-- <com.example.blu.toys.view.WheelView-->
android:id="@+id/wheel_am_pm" <!-- android:id="@+id/wheel_am_pm"-->
android:layout_width="wrap_content" <!-- android:layout_width="wrap_content"-->
android:layout_height="wrap_content" <!-- android:layout_height="wrap_content"-->
android:layout_gravity="center_vertical" <!-- android:layout_gravity="center_vertical"-->
android:layout_marginLeft="20dp" /> <!-- android:layout_marginLeft="20dp" />-->
</LinearLayout> </LinearLayout>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment