Commit 7b0ef205 by chengchong

qweq

parent bc25d7a6
package com.example.blu.toys.activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
......@@ -38,7 +39,7 @@ public class SearchingActivity extends BaseActivity {
@RequiresApi(api = Build.VERSION_CODES.N)
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
@Subscribe(threadMode = ThreadMode.MAIN)
public void GoDeviceListPage(List<BleDevice> bleDevices) {
goActivity(SelectDeviceActivity.class);
}
......
......@@ -38,35 +38,31 @@ public class SelectDeviceActivity extends BaseActivity {
@Override
public void init(Bundle savedInstanceState) {
EventBus.getDefault().register(this);
}
@Override
public void initData() {
if (bleDevices == null) {
bleDevices = new ArrayList<>();
}
mRecyclerView.setLayoutManager(getLinearLayout());
bleDeviceAdapter = new BleDeviceAdapter(R.layout.ble_devices_item, bleDevices);
mRecyclerView.setAdapter(bleDeviceAdapter);
}
@Override
public void initData() {
bleDeviceAdapter.setOnItemClickListener((adapter, view, position) -> {
BleDevice bleDevice = (BleDevice) adapter.getItem(position);
BlePlay.getInstance().connectedBleDevice(bleDevice);
});
showBleDevices();
}
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
public void showBleDevices(List<BleDevice> bles) {
public void showBleDevices() {
List<BleDevice> bles = BlePlay.getInstance().getScanResultList();
if (CollectionUtils.isEmpty(bles)) {
return;
}
if (bleDevices == null) {
bleDevices = new ArrayList<>();
}
bleDevices.clear();
for (int i = 0; i < bles.size(); i++) {
BleDevice bleDevice = bles.get(i);
String deviceName = bleDevice.getName();
......
......@@ -40,8 +40,10 @@ public class SetTimeActivity extends BaseActivity {
WheelView wheelMinute;
@BindView(R.id.wheel_second)
WheelView wheelSecond;
@BindView(R.id.wheel_am_pm)
WheelView wheelAmPm;
// @BindView(R.id.wheel_am_pm)
// WheelView wheelAmPm;
// amPmList.add("AM");
// amPmList.add("PM");
@BindView(R.id.wheel_hour_dw)
WheelView wheelHour_dw;
......@@ -59,20 +61,14 @@ public class SetTimeActivity extends BaseActivity {
TypefaceTextView will;
private ArrayList<String> hourList = new ArrayList<>();
private ArrayList<String> minuteList = new ArrayList<>();
private ArrayList<String> secondList = new ArrayList<>();
private ArrayList<String> amPmList = new ArrayList<>();
private int amOrPm = 0;
private ArrayList<String> sixList = new ArrayList<>();
private ArrayList<String> selectTime = new ArrayList<>();
String selectHour;
String selectMin;
String selectSec;
String selectHour_dw;
String selectMin_dw;
String selectSec_dw;
int hour = 0;
int min = 0;
......@@ -84,212 +80,225 @@ public class SetTimeActivity extends BaseActivity {
return R.layout.activity_set_time;
}
@Override
public void init(Bundle savedInstanceState) {
wheelHour.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
@Override
public void onSelected(int selectedIndex, String item) {
if (StringUtils.isEmpty(item)) {
//不能动
int indexHour = hourList.indexOf(selectHour);
wheelHour.setSeletion(indexHour);
return;
}
//设置底部的时间
private void setDwTime() {
Date time = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(time);
int nowHour = calendar.get(Calendar.HOUR);//时(12小时制)
int currHour = LocalDateUtils.getHour(time);
int currMinute = LocalDateUtils.getSecond(time);
int currSecond = LocalDateUtils.getMinute(time);
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;
}
String hour = wheelHour.getSeletedItem();
String minute = wheelMinute.getSeletedItem();
String second = wheelSecond.getSeletedItem();
// 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));
}
});
int selectHourTime;
int selectMinTime;
int selectSecTime;
String selectHour_dw;
String selectMin_dw;
String selectSec_dw;
wheelMinute.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
@Override
public void onSelected(int selectedIndex, String item) {
if (StringUtils.isEmpty(item)) {
int indexMinute = minuteList.indexOf(selectMin);
wheelMinute.setSeletion(indexMinute);
return;
//小时
if (hour.startsWith("0")) {
hour = hour.substring(1);
}
selectHourTime = Integer.parseInt(hour);
Calendar calendar = Calendar.getInstance();
int nowHour = calendar.get(Calendar.HOUR);//时(12小时制)
int nowMin = calendar.get(Calendar.MINUTE);
int dowHour = selectHourTime - currHour;
String currentSelectHour;
if (selectHour.startsWith("0")) {
currentSelectHour = item.substring(1);
if (dowHour < 10) {
selectHour_dw = "0" + dowHour;
} else {
currentSelectHour = selectHour;
selectHour_dw = String.valueOf(dowHour);
}
wheelHour_dw.setSeletion(selectTime.indexOf(selectHour_dw));
Integer selectHourTime = Integer.valueOf(currentSelectHour);
if (selectHourTime < nowHour) {
ToastUtils.show("选择的时间不能小于当前时间");
return;
//分钟
if (minute.startsWith("0")) {
minute = minute.substring(1);
}
selectMinTime = Integer.parseInt(minute);
if (selectHourTime > nowHour) {
selectMin = item;
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 (selectHourTime == nowHour) {
if (item.startsWith("0")) {
item = item.substring(1);
//秒
if (second.startsWith("0")) {
second = second.substring(1);
}
Integer selectMinTime = Integer.valueOf(item);
if (selectMinTime < nowMin) {
int indexMinute = minuteList.indexOf(selectMin);
wheelMinute.setSeletion(indexMinute);
ToastUtils.show("选择的时间不能小于当前时间");
selectSecTime = Integer.parseInt(second);
int dowSec = selectSecTime - currSecond;
if (dowSec < 10) {
selectSec_dw = "0" + dowSec;
} else {
selectMin = item;
selectSec_dw = String.valueOf(dowSec);
}
wheelSecond_dw.setSeletion(sixList.indexOf(selectSec_dw));
}
if (selectMin.startsWith("0")) {
item = item.substring(1);
//设置顶部的时间
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);
Integer selectMinTime = Integer.valueOf(item);
if (dwHour.startsWith("0")) {
dwHour = dwHour.substring(1);
}
dwHourTime = Integer.parseInt(dwHour);
//设置下面的时间
// int dowMin = selectMinTime - nowMin;
// if (dowMin < 10) {
// selectMin_dw = "0" + dowMin;
// } else {
// selectMin_dw = String.valueOf(dowMin);
// }
//
// wheelMinute_dw.setSeletion(minuteList.indexOf(selectMin_dw));
selectHourTime = selectHourTime + dwHourTime;
if (selectHourTime < 10) {
hour = "0" + selectHourTime;
} else {
hour = String.valueOf(selectHourTime);
}
});
wheelHour.setSeletion(hourList.indexOf(hour));
//秒的选择
wheelSecond.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
@Override
public void onSelected(int selectedIndex, String item) {
if (StringUtils.isEmpty(item)) {
int indexSecond = secondList.indexOf(selectSec);
wheelSecond.setSeletion(indexSecond);
return;
//分钟
if (minute.startsWith("0")) {
minute = minute.substring(1);
}
selectMinTime = Integer.parseInt(minute);
Date time = new Date();
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;
if (dwMinute.startsWith("0")) {
dwMinute = dwMinute.substring(1);
}
Integer currentSelectHour = Integer.valueOf(currentHour);
dwMinTime = Integer.parseInt(dwMinute);
String currentMin;
if (selectMin.startsWith("0")) {
currentMin = item.substring(1);
selectMinTime = selectMinTime + dwMinTime;
if (selectMinTime < 10) {
minute = "0" + selectMinTime;
} else {
currentMin = selectMin;
minute = String.valueOf(selectMinTime);
}
Integer currentSelectMin = Integer.valueOf(currentMin);
wheelMinute.setSeletion(sixList.indexOf(minute));
//当小时大于当前的时间
if (currentSelectHour >= nowHour) {
if (currentSelectMin > nowMinute) {
selectSec = item;
//秒
if (second.startsWith("0")) {
second = second.substring(1);
}
selectSecTime = Integer.parseInt(second);
if (dwSecond.startsWith("0")) {
dwSecond = dwSecond.substring(1);
}
dwSecTime = Integer.parseInt(dwSecond);
if (currentSelectMin == nowMinute) {
String sec;
if (item.startsWith("0")) {
sec = item.substring(1);
selectSecTime = selectSecTime + dwSecTime;
if (selectSecTime < 10) {
second = "0" + selectSecTime;
} else {
sec = item;
second = String.valueOf(selectSecTime);
}
Integer selectSecTime = Integer.valueOf(sec);
//计算秒
if (selectSecTime < nowSecond) {
int indexSec = secondList.indexOf(selectMin);
wheelSecond.setSeletion(indexSec);
ToastUtils.show("选择的时间不能小于当前时间");
} else {
selectMin = item;
wheelSecond.setSeletion(sixList.indexOf(second));
}
//
// int dowSec = selectSecTime - nowSecond;
// if (dowSec < 10) {
// selectSec_dw = "0" + dowSec;
// } else {
// selectSec_dw = String.valueOf(dowSec);
// }
//
// wheelSecond_dw.setSeletion(secondList.indexOf(selectSec_dw));
@Override
public void init(Bundle savedInstanceState) {
wheelHour.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
@Override
public void onSelected(int selectedIndex, String item) {
if (StringUtils.isEmpty(item)) {
//不能动
int indexHour = hourList.indexOf(selectHour);
wheelHour.setSeletion(indexHour);
return;
}
setDwTime();
} else {
ToastUtils.show("选择的时间不能小于当前时间");
}
});
wheelMinute.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
@Override
public void onSelected(int selectedIndex, String item) {
if (StringUtils.isEmpty(item)) {
int indexMinute = sixList.indexOf(selectMin);
wheelMinute.setSeletion(indexMinute);
return;
}
setDwTime();
}
});
wheelHour_dw.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
//秒的选择
wheelSecond.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
@Override
public void onSelected(int selectedIndex, String item) {
selectHour_dw = hourList.get(selectedIndex);
if (StringUtils.isEmpty(item)) {
int indexSecond = sixList.indexOf(selectSec);
wheelSecond.setSeletion(indexSecond);
return;
}
setDwTime();
}
});
wheelHour_dw.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
@Override
public void onSelected(int selectedIndex, String item) {
setUpTime();
}
});
wheelMinute_dw.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
@Override
public void onSelected(int selectedIndex, String item) {
selectMin_dw = minuteList.get(selectedIndex);
setUpTime();
}
});
......@@ -297,56 +306,46 @@ public class SetTimeActivity extends BaseActivity {
wheelSecond_dw.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
@Override
public void onSelected(int selectedIndex, String item) {
selectSec_dw = secondList.get(selectedIndex);
setUpTime();
}
});
}
@Override
public void initData() {
Date time = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(time);
int hour = calendar.get(Calendar.HOUR);//时(12小时制)
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;
}
int hour = LocalDateUtils.getHour(time);
int minute = LocalDateUtils.getSecond(time);
int second = LocalDateUtils.getMinute(time);
hourList.clear();
minuteList.clear();
secondList.clear();
amPmList.add("AM");
amPmList.add("PM");
hourList.clear();
sixList.clear();
hourList.add("00");
for (int i = 1; i <= 12; i++) {
for (int i = 1; i <= 24; i++) {
if (i < 10) {
hourList.add("0" + i);
} else {
hourList.add(String.valueOf(i));
}
}
for (int i = 0; i <= 59; i++) {
if (i < 10) {
minuteList.add("0" + i);
secondList.add("0" + i);
sixList.add("0" + i);
} else {
minuteList.add(String.valueOf(i));
secondList.add(String.valueOf(i));
sixList.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 {
///分////
wheelMinute.setOffset(3);// 对话框中当前项上面和下面的项数
wheelMinute.setItems(minuteList);// 设置数据源
wheelMinute.setItems(sixList);// 设置数据源
if (minute < 10) {
selectMin = "0" + minute;
} else {
selectMin = String.valueOf(minute);
}
int indexMinute = minuteList.indexOf(selectMin);
int indexMinute = sixList.indexOf(selectMin);
wheelMinute.setSeletion(indexMinute);// 默认选中第三项
///秒////
wheelSecond.setOffset(3);
wheelSecond.setItems(secondList);// 设置数据源
wheelSecond.setItems(sixList);// 设置数据源
if (second < 10) {
selectSec = "0" + second;
} else {
selectSec = String.valueOf(second);
}
int indexSecond = secondList.indexOf(selectSec);
int indexSecond = sixList.indexOf(selectSec);
wheelSecond.setSeletion(indexSecond);
wheelAmPm.setOffset(2);// 对话框中当前项上面和下面的项数
wheelAmPm.setItems(amPmList);// 设置数据源
wheelAmPm.setSeletion(amOrPm);// 默认选中第三项
/////////下////////
///时////
wheelHour_dw.setOffset(3);
wheelHour_dw.setItems(hourList);
wheelHour_dw.setItems(selectTime);
wheelHour_dw.setSeletion(0);
///分////
wheelMinute_dw.setOffset(3);// 对话框中当前项上面和下面的项数
wheelMinute_dw.setItems(minuteList);// 设置数据源
wheelMinute_dw.setItems(sixList);// 设置数据源
wheelMinute_dw.setSeletion(0);// 默认选中第三项
///秒////
wheelSecond_dw.setOffset(3);
wheelSecond_dw.setItems(secondList);
wheelSecond_dw.setItems(sixList);
wheelSecond_dw.setSeletion(0);
}
......@@ -426,6 +420,10 @@ public class SetTimeActivity extends BaseActivity {
ToastUtils.show("请打开蓝牙");
return;
}
String selectHour_dw = wheelHour_dw.getSeletedItem();
String selectMin_dw = wheelMinute_dw.getSeletedItem();
String selectSec_dw = wheelSecond_dw.getSeletedItem();
if (TextUtils.isEmpty(selectHour_dw)) {
hour = 0;
} else if (selectHour_dw.startsWith("0")) {
......
......@@ -47,6 +47,15 @@ public class BlePlay {
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() {
if (instance == null) {
......@@ -99,7 +108,8 @@ public class BlePlay {
@Override
public void onScanFinished(List<BleDevice> scanResultList) {
LogUtils.e("扫描介素获取设备列表");
EventBus.getDefault().postSticky(scanResultList);
setScanResultList(scanResultList);
EventBus.getDefault().post(scanResultList);
}
});
}
......
......@@ -77,7 +77,8 @@ public class TrafficLightBean {
this.cmd= BitOperator.integerTo1Byte(protocolNo);
this.suspendAndContinue=BitOperator.integerTo1Byte(suspendAndContinue);
this.timeRemaining=BitOperator.integerTo2Bytes(timeRemaining);
System.out.println("传入的剩余时间:"+timeRemaining);
this.timeRemaining=toLH(timeRemaining); //BitOperator.integerTo2Bytes();
this.brightness=BitOperator.integerTo1Byte(brightness);
this.openSoundNo=BitOperator.integerTo1Byte(openSoundNo);
this.closeSoundNo=BitOperator.integerTo1Byte(closeSoundNo);
......@@ -106,6 +107,18 @@ public class TrafficLightBean {
}
/**
* int 转换小端
* @param n
* @return
*/
public static byte[] toLH(int n) {
byte[] b = new byte[2];
b[0] = (byte) (n & 0xff);
b[1] = (byte) (n >> 8 & 0xff);
return b;
}
public byte[] toByte(){
//数据要加密的
......
package com.example.blu.toys.utils;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
......@@ -158,6 +160,16 @@ public class LocalDateUtils {
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 {
}
public static void main(String[] args) {
System.out.println(getLocalDateTimeStr());
System.out.println(getLocalDateStr());
......
......@@ -80,8 +80,7 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp_75"
android:background="@drawable/black_thumb"
>
android:background="@drawable/black_thumb">
<LinearLayout
android:layout_width="match_parent"
......@@ -132,12 +131,12 @@
android:layout_gravity="center_vertical" />
<com.example.blu.toys.view.WheelView
android:id="@+id/wheel_am_pm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp" />
<!-- <com.example.blu.toys.view.WheelView-->
<!-- android:id="@+id/wheel_am_pm"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_gravity="center_vertical"-->
<!-- android:layout_marginLeft="20dp" />-->
</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