From: d15521469561 Date: Fri, 31 Mar 2023 13:04:04 +0000 (+0800) Subject: 1.修复短信 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=7ab28e2e35837c609b7d5cc11a246a96fbbc1a5c;p=mirrors%2FASR1603_G5.git 1.修复短信 2.通话记录 --- diff --git a/3.code/1.watch/2.code/appWechat.py b/3.code/1.watch/2.code/appWechat.py index a4eabbf6..398eae08 100644 --- a/3.code/1.watch/2.code/appWechat.py +++ b/3.code/1.watch/2.code/appWechat.py @@ -7,14 +7,14 @@ import ujson import ql_fs import audio from machine import Pin -from ext.ui import style_font_youyuan_20,style_screen,Screen,style_font_youyuan_20_black,style_contact_btn +from ext.ui import style_font_youyuan_20,style_screen,Screen,style_font_youyuan_20_black,style_img import audio from machine import Pin -from ext.protocol import ProtoCol +from ext.protocol import ProtoCol,UnicodeHexStr_To_Utf8Str style_wechat_r_btn = lv.style_t() style_wechat_r_btn.init() -style_wechat_r_btn.set_bg_color(lv.color_make(0x26, 0xf6, 0x23)) +style_wechat_r_btn.set_bg_color(lv.color_make(0x00, 0xff, 0x2a)) style_wechat_r_btn.set_border_width(0) style_wechat_r_btn.set_shadow_opa(0) @@ -100,29 +100,37 @@ class WechatScreen(Screen): self.record_test = audio.Record() self.aud = audio.Audio(0) self.aud.set_pa(Pin.GPIO29) - self.aud.setVolume(10) + self.aud.setVolume(11) self.meta = wechat_screen - self.countdown = 0 wechat_press_btn.add_event_cb(lambda e: self.talking(e), lv.EVENT.LONG_PRESSED, None) wechat_press_btn.add_event_cb(lambda e: self.sending(e), lv.EVENT.RELEASED, None) self.timer = osTimer() self.second_timer = osTimer() + self.play_timer = osTimer() + wechat_label.set_text(" ") - self.startX = 0 + self.startY = 0 + self.startWidth = 0 self.check_json = 0 self.wechat_list =lv.obj() EventMesh.subscribe("wechat_updata_list_show", self.wechat_updata_list_show) EventMesh.subscribe("get_wechat_data", self.get_wechat_data) EventMesh.subscribe("set_wechat_data", self.set_wechat_data) self.countdown = 1 + self.count_img = 0 + self.play_img_cnt = None + self.play_text = None + self.play_sec = 0 + self.sec_num = 0 def get_wechat_data(self,event, msg): return [self.MXA_MSG,self.wechat_num ,self.wechat_recode_list] def set_wechat_data(self, event, msg): + self.MXA_MSG = msg[0] self.wechat_num = msg[1] self.wechat_recode_list = msg[2] @@ -135,27 +143,25 @@ class WechatScreen(Screen): def wechat_updata_list_show(self, event, msg): if (self.wechat_list.has_flag(lv.obj.FLAG.HIDDEN)) == False: - # tmp = EventMesh.publish("get_wechat_data") - # self.MXA_MSG = tmp[0] - # self.wechat_num = tmp[1] - # self.wechat_recode_list = tmp[2] - #print("wechat_updata_list_show self.MXA_MSG:{} self.wechat_num:{} self.wechat_recode_list:{}".format(self.MXA_MSG,self.wechat_num,self.wechat_recode_list)) - self.updata_list_show(2) + self.timer.start(1 * 1000, 0, self.reciving) + def updata_list_show(self,index): #print("self.wechat_list.get_hidden:{}".format(self.wechat_list.has_flag(lv.obj.FLAG.HIDDEN))) - if index == 2 or index == 0: + if index == 0: #读取json文件中的键作为label文本; - + self.startWidth = 0 + self.startY = 0 # print("self.wechat_recode_list:{}".format(self.wechat_recode_list)) self.wechat_list.delete()#先删除一次控件 - self.wechat_list.clear_flag(lv.obj.FLAG.HIDDEN)#隐藏列表选项方框 + self.wechat_list = lv.obj(wechat_screen) self.wechat_list.set_pos(0, 0) self.wechat_list.set_size(240, 250) self.wechat_list.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF) self.wechat_list.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT) + self.play_img_cnt = None #print("self.wechat_list.self.wechat_num:{}".format(self.wechat_num)) if self.wechat_num != 0: j = 1 @@ -168,55 +174,102 @@ class WechatScreen(Screen): if j > len(self.wechat_recode_list) : break j+=1 - print("key :{}".format(key)) - print("self.wechat_recode_list:{}".format(self.wechat_recode_list[key])) + # print("key :{}".format(key)) + # print("self.wechat_recode_list:{}".format(self.wechat_recode_list[key])) value = self.wechat_recode_list[key] - msg_tmp = value[2:] - msg_tmp = int(msg_tmp) - startX = 20+msg_tmp*10 - startY = 52*i + self.startY = 52*i + if value.find("S:") != -1 or value.find("R:") != -1: + msg_tmp = value[2:] + msg_tmp = int(msg_tmp) + self.startWidth = 55+msg_tmp*10 + + elif value.find("T:") != -1:#文字显示 + msg_tmp = value[2:] + size = len(msg_tmp) + self.startWidth = size*20 + print("self.startWidth :{} size:{}".format(self.startWidth,size)) + if self.startWidth > 200: + self.startWidth = 200 + contact_btn = lv.btn(self.wechat_list) - if value.find("S:") != -1: - contact_btn.set_size(startX,50) - contact_btn.set_pos(10,startY ) + if value.find("R:") != -1: + contact_btn.set_size(self.startWidth,50) + contact_btn.set_pos(10,self.startY ) contact_btn.add_style(style_wechat_s_btn, lv.PART.MAIN | lv.STATE.DEFAULT) contact_btn.add_event_cb(lambda e: self.play_label(e), lv.EVENT.CLICKED, None) _btn_label1 = lv.label(contact_btn) - _btn_label1.set_long_mode(lv.label.LONG.DOT) - _btn_label1.set_text(str(msg_tmp)) + _btn_label1.set_size(40, 40) + _btn_label1.set_pos(35, 8) + _btn_label1.set_text(str(msg_tmp)+'\"') + _btn_label1.add_style(style_font_youyuan_20_black, lv.PART.MAIN | lv.STATE.DEFAULT) _btn_label2 = lv.label(contact_btn) _btn_label2.set_size(0, 0) - _btn_label2.set_text(key) - _btn_label2.set_long_mode(lv.label.LONG.DOT) + _btn_label2.set_text('R:'+key) - elif value.find("R:") != -1 : - contact_btn.set_size(startX,50) - contact_btn.set_pos(230-startX,startY ) + + _btn_img = lv.img(contact_btn) + _btn_img.set_pos(5, 0) + _btn_img.set_size(30, 30) + _btn_img.set_src("E:/static/APP/wechat/R_3.png") + _btn_img.add_style(style_img, lv.PART.MAIN | lv.STATE.DEFAULT) + + elif value.find("S:") != -1 : + contact_btn.set_size(self.startWidth,50) + contact_btn.set_pos(230-self.startWidth,self.startY ) contact_btn.add_style(style_wechat_r_btn, lv.PART.MAIN | lv.STATE.DEFAULT) contact_btn.add_event_cb(lambda e: self.play_label(e), lv.EVENT.CLICKED, None) _btn_label1 = lv.label(contact_btn) - _btn_label1.set_long_mode(lv.label.LONG.DOT) + _btn_label1.set_size(40, 40) + _btn_label1.set_pos(self.startWidth-72, 8) + _btn_label1.set_text(str(msg_tmp)+'\"') + + _btn_label1.add_style(style_font_youyuan_20_black, lv.PART.MAIN | lv.STATE.DEFAULT) + + _btn_label2 = lv.label(contact_btn) + _btn_label2.set_size(0, 0) + _btn_label2.set_text('S:'+key) + + + _btn_img = lv.img(contact_btn) + _btn_img.set_pos(self.startWidth-50, 0) + _btn_img.set_size(30, 30) + _btn_img.set_src("E:/static/APP/wechat/S_3.png") + _btn_img.add_style(style_img, lv.PART.MAIN | lv.STATE.DEFAULT) + + elif value.find("T:") != -1 :#显示文字 + contact_btn.set_size(self.startWidth,50) + contact_btn.set_pos(10,self.startY ) + contact_btn.add_style(style_wechat_s_btn, lv.PART.MAIN | lv.STATE.DEFAULT) + contact_btn.add_event_cb(lambda e: self.play_label(e), + lv.EVENT.CLICKED, None) + + _btn_label1 = lv.label(contact_btn) + _btn_label1.set_size(200, 60) + _btn_label1.set_pos(0, 0) _btn_label1.set_text(str(msg_tmp)) + _btn_label1.set_long_mode(lv.label.LONG.DOT) _btn_label1.add_style(style_font_youyuan_20_black, lv.PART.MAIN | lv.STATE.DEFAULT) _btn_label2 = lv.label(contact_btn) _btn_label2.set_size(0, 0) - _btn_label2.set_text(key) - _btn_label2.set_long_mode(lv.label.LONG.DOT) - elif value.find("T:") != -1 : - pass + _btn_label2.set_text('T:'+key) + - if index == 2:#为了加载的时候不要每次都从头开始显示 - bottom_btn = self.wechat_list.get_child(-1) - bottom_btn.scroll_to_view(lv.ANIM.OFF) - + # _btn_img = lv.img(contact_btn) + # _btn_img.set_pos(0, 0) + # _btn_img.set_size(0, 0) + # _btn_img.set_src("E:/static/APP/wechat/R_3.png") + # _btn_img.add_style(style_img, lv.PART.MAIN | lv.STATE.DEFAULT) + + bottom_btn = self.wechat_list.get_child(-1) + bottom_btn.scroll_to_view(lv.ANIM.OFF) def initialization(self): @@ -226,8 +279,13 @@ class WechatScreen(Screen): #读取json文件中的字典放到self.phonebook中 #创建btn self.updata_list_show(0) - + self.count_img = 0 + self.play_sec = 0 + + #按下录音 def talking(self,e): + self.play_timer.stop() + self.aud.stop() self.wechat_list.add_flag(lv.obj.FLAG.HIDDEN)#隐藏列表选项方框 self.countdown = 1 wechat_label.clear_flag(lv.obj.FLAG.HIDDEN) @@ -246,10 +304,13 @@ class WechatScreen(Screen): self.record_test.start("E:/static/audio_amr/amr/{}.amr".format(self.wechat_num),16) self.second_timer.start(1000, 1, self.reduce_second) - - - def sending(self,e): + + #松开发送 + def reciving(self,e): + self.updata_list_show(0) + #松开发送 + def sending(self,e): wechat_label.clear_flag(lv.obj.FLAG.HIDDEN) wechat_label.set_text("发送中") wechat_press_label_countdown.add_flag(lv.obj.FLAG.HIDDEN) @@ -262,11 +323,10 @@ class WechatScreen(Screen): #record.json文件里的json元素为记录编号,json键值:"S:"开头为发送的语音,"R:"为接收的语音,后面跟随语音长度;"T:"为接收的文字信息。 #写序号 - print("self.countdown :{} self.wechat_num:{}".format(self.countdown,self.wechat_num)) - self.wechat_recode_list["%02d"%(self.wechat_num)] = "S:{}".format(str(self.countdown)) self.record_test.stop() #停止錄音 self.second_timer.stop() #停止计时器 - + print("self.countdown :{} self.wechat_num:{}".format(self.countdown,self.wechat_num)) + self.wechat_recode_list["%02d"%(self.wechat_num)] = "S:{}".format(str(self.countdown)) with open("ext/static/audio_amr/num.txt","w") as fd: fd.write(str(self.wechat_num)) @@ -277,31 +337,85 @@ class WechatScreen(Screen): with open("ext/static/audio_amr/record.json","w",encoding="utf-8") as fd: ujson.dump(self.wechat_recode_list,fd) # print("WechatScreen:record:{}".format(self.wechat_recode_list)) - + def play_img_cb(self,*args): + print("self.count_img :{} self.play_text:{}".format(self.count_img,self.play_text)) + self.count_img+=1 + if self.count_img > 3: + self.count_img = 1 + if self.play_text == "R:": + self.play_img_cnt.set_src("E:/static/APP/wechat/R_{}.png".format(self.count_img)) + elif self.play_text == "S:": + self.play_img_cnt.set_src("E:/static/APP/wechat/S_{}.png".format(self.count_img)) + + self.sec_num+=1 + if self.sec_num % 2 == 0: + print("self.play_sec:{}".format(self.play_sec)) + if self.play_sec > 0: + self.play_sec -= 1 + if self.play_sec == 0: + self.play_timer.stop() + if self.play_text == "R:": + self.play_img_cnt.set_src("E:/static/APP/wechat/R_3.png") + elif self.play_text == "S:": + self.play_img_cnt.set_src("E:/static/APP/wechat/S_3.png") + + #点击播放 def play_label(self,e): - num = e.get_target().get_child(1).get_text() - num = int(num) - a = audio.Audio(0) - a.play(1, 0, 'E:/static/audio_amr/amr/{}.amr'.format(num)) #文件名前面要加上路径 - + self.sec_num = 0 + # print("play_label self.play_text:{}".format(self.play_text)) + if self.play_text != None and self.play_img_cnt != None: #停止东画还原到3图标 + if self.play_text == "R:": + self.play_img_cnt.set_src("E:/static/APP/wechat/R_3.png") + elif self.play_text == "S:": + self.play_img_cnt.set_src("E:/static/APP/wechat/S_3.png") + + self.count_img = 0 #喇叭动画显示的数量 + play_img = e.get_target() + self.play_img_cnt = play_img.get_child(2) + text = play_img.get_child(1).get_text() + self.play_text = text[0:2] #区分左右喇叭动画显示 "R":左边 "S:"右边 "T:":左边 + + play_img_s = play_img.get_child(0).get_text() + play_img_s = play_img_s.split('"') + play_img_s = play_img_s[0]#获取实际显示秒数 '"'前面实际的秒数 + + if self.play_text == "R:" or self.play_text == "S:": + self.play_sec = int(play_img_s) + self.play_timer.start(500, 1, self.play_img_cb) + # print("play_label self.count_img :{} self.play_text:{} play_img_s:{} self.play_sec:{}".format(self.count_img,self.play_text,play_img_s,self.play_sec)) + # #R:04 + + num_amr = play_img.get_child(1).get_text() + num_amr = num_amr.split(':') + num_amr = num_amr[1]#获取实际秒数 + i = int(num_amr) + # print("num:{}".format(i)) + if self.play_text == "R:" or self.play_text == "S:":#过滤掉文字显示 不需要播放音频文件 + self.aud = audio.Audio(0) + self.aud.stop()# + self.aud.play(1, 0, 'E:/static/audio_amr/amr/{}.amr'.format(i)) #文件名前面要加上路径 + + #松手2秒后发送数据 def hide_label(self,*args): #读音频amr二进制数据 path = "/ext/static/audio_amr/amr/{}.amr".format(self.wechat_num) - with open(path,"rb") as fd: buf = bytearray(ql_fs.path_getsize(path)) fd.readinto(buf) - print("hide_label self.countdown ...:{}".format(self.countdown)) senddata = [self.countdown,buf] EventMesh.publish(constants.PROTOCOL.TK_SEND,senddata) #隐藏显示文本 显示列表显示框 wechat_label.add_flag(lv.obj.FLAG.HIDDEN) wechat_label.set_text(" ") - self.wechat_list.clear_flag(lv.obj.FLAG.HIDDEN)#隐藏列表选项方框 - self.updata_list_show(2) + self.updata_list_show(0) + def Close(self): + self.play_timer.stop() + self.record_test.stop() #停止錄音 + self.second_timer.stop() #停止计时器 + self.aud.stop() def reduce_second(self,*args): if self.countdown < 15: @@ -422,6 +536,53 @@ class TK_ProtoCol(ProtoCol): +class MESSAGE_ProtoCol(ProtoCol): + """微聊""" + TYPE = "MESSAGE" + + + def send(self, event, msg): + + #[XT*334588000000156*0007*MESSAGE] + send_data = "SZKW*%s*0007*MESSAGE"%(self.imei) + MD5_SIGN = self.pack_MD5_head(send_data) + data = "[%s%s]"%(str(MD5_SIGN),send_data) + #print("POWEROFF_ProtoCol:send:%s"%(data)) + # 通过socket发送到服务器端 + EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND, data) + def recv(self, event, msg): + """ + + @param event: 微聊文字 + @param msg: 接收到的下行数据 + """ + msg = msg[1:-1] + + msg_s = msg.decode('ascii') + msg_s = msg_s.split(',') + msg_s = msg_s[1] + print("msg_tmp:len:{}\r\n data:{}".format(len(msg_s),msg_s)) + + + get_wechat_data = EventMesh.publish("get_wechat_data") + wechat_num = get_wechat_data[1] + MXA_MSG = get_wechat_data[0] + wechat_recode_list = get_wechat_data[2] + if wechat_num >= MXA_MSG: + wechat_num = 0 + wechat_num += 1 + msg_txt = {} + # 0 1 2 3 + print("msg_tmp:init {}".format(msg_s)) + msg_txt = UnicodeHexStr_To_Utf8Str(msg_s) + print("msg_txt:{}".format(msg_txt)) + wechat_recode_list["%02d"%(wechat_num)] = "T:{}".format(msg_txt) + EventMesh.publish("set_wechat_data",[MXA_MSG,wechat_num,wechat_recode_list]) + print("wechat_recode_list:len data:{}".format(wechat_recode_list)) + EventMesh.publish(constants.PROTOCOL.MESSAGE_SEND) + EventMesh.publish("wechat_updata_list_show") + + diff --git a/3.code/1.watch/2.code/constants.py b/3.code/1.watch/2.code/constants.py index e113d0bf..f4e2ffc4 100644 --- a/3.code/1.watch/2.code/constants.py +++ b/3.code/1.watch/2.code/constants.py @@ -26,6 +26,9 @@ class PROTOCOL: TK_SEND = "TK_SEND" TK_RECV = "TK_RECV" + MESSAGE_SEND = "MESSAGE_SEND" + MESSAGE_RECV = "MESSAGE_RECV" + class EVENT: CHANNEL_SOCKET_SEND = "CHANNEL_SOCKET_SEND" diff --git a/3.code/1.watch/2.code/main_1.py b/3.code/1.watch/2.code/main_1.py index a3560f58..5b81abd4 100644 --- a/3.code/1.watch/2.code/main_1.py +++ b/3.code/1.watch/2.code/main_1.py @@ -49,14 +49,14 @@ if __name__ == '__main__': import ext.mgr as mgr import ext.ui as _ui from ext.mgr import ConfigStoreManager, DeviceInfoManager, LocationManager, SockManager, \ - NetManager, BatteryManager,AddrBookManager,MsgdetailManager,CallLogManager,PhoneCallingManager + NetManager, BatteryManager,AddrBookManager,MsgdetailManager,PhoneCallingManager,CallLogManager from ext.appAlipay import Alipay ,AlipayOpenScreen,Alipay_1_1,Alipay_invite,Alipay_inviting,\ Alipay_success,Alipay_paycode,Alipay_pay_success,Alipay_collect,Alipay_parent from ext.ui_WatchFaceScreen import WatchFaceScreen from ext.ui_main_menu import MainMenuScreen - from usr.appWechat import WechatScreen,TK_ProtoCol + from ext.appWechat import WechatScreen,TK_ProtoCol,MESSAGE_ProtoCol import ext.ui_setting as _ui_setting - from usr.test_sms import PopupScreen,MsgManager + from usr.test_sms import PopupScreen,CallLogScreen,DialingScreen #from usr.ui_wechat import WechatScreen,TK_ProtoCol btn_device = BtnDevice(tp_cst816) @@ -94,8 +94,8 @@ if __name__ == '__main__': ui.add_screen(_ui_setting.AlarmvolumeScreen()) ui.add_screen(_ui_setting.MsgvolumeScreen()) ui.add_screen(_ui_setting.PhoneringScreen()) - ui.add_screen(_ui.DialingScreen()) - ui.add_screen(_ui.CallLogScreen()) + ui.add_screen(DialingScreen()) + ui.add_screen(CallLogScreen()) ui.add_screen(AlipayOpenScreen()) ui.add_screen(Alipay_1_1()) ui.add_screen(Alipay_invite()) @@ -130,7 +130,7 @@ if __name__ == '__main__': app.append_manager(NetManager()) app.append_manager(LocationManager()) app.append_manager(AddrBookManager()) - app.append_manager(MsgManager()) + app.append_manager(mgr.MsgManager()) app.append_manager(MsgdetailManager()) app.append_manager(CallLogManager()) app.append_manager(PhoneCallingManager()) @@ -145,6 +145,7 @@ if __name__ == '__main__': pcr.add_support(POWEROFF_ProtoCol()) pcr.add_support(PHL_ProtoCol()) pcr.add_support(TK_ProtoCol()) + pcr.add_support(MESSAGE_ProtoCol()) sm = SockManager() sm.add_support_resolver(pcr) app.append_manager(sm) diff --git a/3.code/1.watch/2.code/mgr.py b/3.code/1.watch/2.code/mgr.py index 1f850564..a8ed3f1a 100644 --- a/3.code/1.watch/2.code/mgr.py +++ b/3.code/1.watch/2.code/mgr.py @@ -660,11 +660,12 @@ class DeviceInfoManager(Abstract): """ rtc_time = self.rtc.datetime() date = ("%d月%d日" % (rtc_time[1], rtc_time[2])) + year = ("%o4d" % (rtc_time[0])) week = ("星期%s"%(self.get_week(rtc_time[3]))) time = [rtc_time[4], rtc_time[5]] time_quantum = ("%s" % (self.get_time_bucket(rtc_time[4]))) - - result = [time, time_quantum, date , week] + + result = [time, time_quantum, date , week,year] #时分,上午下午,日期,星期 return result @@ -1156,8 +1157,8 @@ class MsgManager(Abstract): def get_msg_detail(self, event, msg): - self.msg_detail = sms.searchTextMsg(self.msg_nums) - print("self.msg_detai {}:".format(self.msg_detai)) + # self.msg_detail = sms.searchTextMsg(self.msg_nums) + # print("self.msg_detai {}:".format(self.msg_detai)) return{ "小明":"有内鬼,停止交易", "小红":"今晚十点一起吃饭" @@ -1192,15 +1193,17 @@ class CallLogManager(Abstract): def __init__(self): self.log = [ #电话 次数 时间 姓名 - ["15692025051","2","12:59","哥"], - ["15692025051","3","12:49","爸"], - ["15692025051","4","12:39","妈"], + ["554592025051","2","12:59","哥gd考"], + ["15521469561","3","12:49","爸"], + ["156525051","4","12:39","妈"], ["15692025051","4","12:39","姐"], - ["15692029951","1","12:39","哥"], - ["15692466051","2","12:35","嫂子"], - ["15692025051","6","12:59","妹"], + ["15521469561","1","12:39","哥"], + ["5666051","2","12:35","嫂子"], + ["15521469561","6","12:59","妹"], ] - + a = {"15692025051":{"mane":"baba","time":"12:49","count":"6"}} + b = a["15692025051"] + b ={"mane":"baba","time":"12:49","count":"6"} def post_processor_after_instantiation(self): EventMesh.subscribe("get_call_log_list", self.get) diff --git a/3.code/1.watch/2.code/protocol.py b/3.code/1.watch/2.code/protocol.py index 3f5391d5..8696917a 100644 --- a/3.code/1.watch/2.code/protocol.py +++ b/3.code/1.watch/2.code/protocol.py @@ -53,8 +53,12 @@ def UnicodeHexStr_To_Utf8Str(str): if(i%4==3): #每2字节获取一个int,拿到转换后的unicode int #print(odata.to_bytes(2, 'big')) #result.append(odata) - tmp = unicode_to_utf8(odata)#拿到转换后的utf8 int - tmp2 = tmp.to_bytes(3, 'big') #转ytes + if odata > 255: + tmp = unicode_to_utf8(odata)#拿到转换后的utf8 int + tmp2 = tmp.to_bytes(3, 'big') #转bytes + else : + tmp2 = odata.to_bytes(1, 'big') + #print("tmp2:{}".format(tmp2)) result = result + tmp2 odata = 0 i+=1 @@ -419,29 +423,35 @@ class PHL_ProtoCol(ProtoCol): # print("phonebook:msg:%s\r\n"%msg) msg_tmp = msg.decode('ascii') msg_tmp = msg_tmp.split(',') - print("phonebook:len:{}\r\n data:{}".format(len(msg_tmp),msg_tmp)) + # print("phonebook:len:{}\r\n data:{}".format(len(msg_tmp),msg_tmp)) - #check_json = ql_fs.path_exists("/usr/phonebook.json") - #self.phonebook = EventMesh.publish("get_addr_book_list") - #print("check_json %d"%check_json) phonebook = {} msg_tmp = msg_tmp[1:] # print("msg_tmp1:{}".format(msg_tmp)) j = 0 + i = 0 phonebook_oldtmp = {} # 0 1 2 3 for phonebook_tmp in msg_tmp: j+=1 # print("phonebook_tmp:{}".format(phonebook_tmp)) + if (j%2) == 0: - phonebook[UnicodeHexStr_To_Utf8Str(phonebook_tmp)] = phonebook_oldtmp + i+=1 + phonebook_name = UnicodeHexStr_To_Utf8Str(phonebook_tmp) + phonebook_name = "{}:{}".format("%03d"%i,phonebook_name) + phonebook[phonebook_name] = phonebook_oldtmp + phonebook_oldtmp = phonebook_tmp - print("phonebook!!!:{}".format(str(phonebook))) - with open("usr/phonebook.json","w",encoding="utf-8") as fd: + # print("phonebook_oldtmp!!!:{}".format(str(phonebook_oldtmp))) + # print("phonebook!!!:{}".format(str(phonebook))) + with open("ext/phonebook.json","w",encoding="utf-8") as fd: ujson.dump(phonebook,fd) print("创建电话簿") EventMesh.publish(constants.PROTOCOL.PHL_SEND) + EventMesh.publish("contact_updata_list_show") + #协议 class TK_ProtoCol(ProtoCol): @@ -552,7 +562,7 @@ class ProtoColResolver(object): def handler(self, data): # 这里接收数据 - #print("handler -> {}".format(data)) + print("handler -> {}".format(data)) # if data.startswith('Init;'): # data = data[5:] # EventMesh.publish(constants.EVENT.SET_KEY, {"value": ujson.loads(data)['KEY']}) diff --git a/3.code/1.watch/2.code/static/APP/wechat/R_1.png b/3.code/1.watch/2.code/static/APP/wechat/R_1.png index aeddf4c6..dfc8af1e 100644 Binary files a/3.code/1.watch/2.code/static/APP/wechat/R_1.png and b/3.code/1.watch/2.code/static/APP/wechat/R_1.png differ diff --git a/3.code/1.watch/2.code/static/APP/wechat/R_2.png b/3.code/1.watch/2.code/static/APP/wechat/R_2.png index e7861e04..07f2ea2a 100644 Binary files a/3.code/1.watch/2.code/static/APP/wechat/R_2.png and b/3.code/1.watch/2.code/static/APP/wechat/R_2.png differ diff --git a/3.code/1.watch/2.code/static/APP/wechat/R_3.png b/3.code/1.watch/2.code/static/APP/wechat/R_3.png index 8c6c4e0b..d9e83ed4 100644 Binary files a/3.code/1.watch/2.code/static/APP/wechat/R_3.png and b/3.code/1.watch/2.code/static/APP/wechat/R_3.png differ diff --git a/3.code/1.watch/2.code/static/APP/wechat/S_1.png b/3.code/1.watch/2.code/static/APP/wechat/S_1.png index dfc8af1e..aeddf4c6 100644 Binary files a/3.code/1.watch/2.code/static/APP/wechat/S_1.png and b/3.code/1.watch/2.code/static/APP/wechat/S_1.png differ diff --git a/3.code/1.watch/2.code/static/APP/wechat/S_2.png b/3.code/1.watch/2.code/static/APP/wechat/S_2.png index 07f2ea2a..e7861e04 100644 Binary files a/3.code/1.watch/2.code/static/APP/wechat/S_2.png and b/3.code/1.watch/2.code/static/APP/wechat/S_2.png differ diff --git a/3.code/1.watch/2.code/static/APP/wechat/S_3.png b/3.code/1.watch/2.code/static/APP/wechat/S_3.png index d9e83ed4..8c6c4e0b 100644 Binary files a/3.code/1.watch/2.code/static/APP/wechat/S_3.png and b/3.code/1.watch/2.code/static/APP/wechat/S_3.png differ diff --git a/3.code/1.watch/2.code/test_sms.py b/3.code/1.watch/2.code/test_sms.py index d60e04e6..f02192a8 100644 --- a/3.code/1.watch/2.code/test_sms.py +++ b/3.code/1.watch/2.code/test_sms.py @@ -1,27 +1,30 @@ -import utime -import osTimer + import lvgl as lv from ext import EventMesh -from machine import Timer -import voiceCall -import osTimer -from ext import constants -from misc import Power -import pm -import ujson -import audio -import ql_fs import sms -import audio -from machine import Pin -from ext.lcd import gpio_backlight,lcd,lcd_ctrl,tp_cst816 -from ext.ui import style_screen,style_font_youyuan_20,style_contact_btn,style_common_bg_rect_btn_pressed,Screen,style_wechat_btn +from ext.ui import style_screen,style_font_youyuan_20_black,style_font_youyuan_20,Screen,style_contact_btn,style_img from ext.common import Abstract +import voiceCall +import ql_fs +import ujson +from ext.protocol import ProtoCol,UnicodeHexStr_To_Utf8Str +from ext import constants +import osTimer +import utime + MSG_FLAG = 0 MSG_MAX = 10 #最大显示短信内容条数 +style_sms_bg_btn = lv.style_t() +style_sms_bg_btn.init() +#style_sms_bg_btn.set_bg_color(lv.color_make(0x00, 0xff, 0x2a)) +style_sms_bg_btn.set_bg_color(lv.color_make(0xff, 0xff, 0xff)) +style_sms_bg_btn.set_border_width(0) +style_sms_bg_btn.set_shadow_opa(0) + + msg_list_screen = lv.obj() msg_screen = lv.obj(msg_list_screen) msg_screen.center() @@ -68,7 +71,8 @@ no_msg_text.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) def msg_cb(args): index = args[1] storage = args[2] - print('New message! storage:{},index:{}'.format(storage, index)) + EventMesh.publish("sms_updata_list_show") + #print('New message! storage:{},index:{}'.format(storage, index)) sms.setCallback(msg_cb) @@ -83,71 +87,67 @@ class PopupScreen(Screen): self.meta = msg_list_screen self.msg_detail = {} self.msg_nums = 0 + self.sms_detail_list = lv.obj() + EventMesh.subscribe("sms_updata_list_show", self.sms_create_list) def post_processor_before_initialization(self): - # self.msg_nums = EventMesh.publish("get_msg_nums") - self.msg_nums = sms.getMsgNums() - print("self.msg_nums:{} type:{}".format(self.msg_nums,type(sms.getMsgNums()))) - + self.msg_nums = sms.getMsgNums() #获取短信条数 def initialization(self): - global MSG_FLAG - if MSG_FLAG == 0 : - self.btn_create() + self.msg_nums = sms.getMsgNums() + # print("self.msg_nums:{} type:{}".format(self.msg_nums,type(sms.getMsgNums()))) + self.btn_create(0) + def sms_create_list(self,event,msg): + self.msg_nums = sms.getMsgNums() + self.btn_create(1) - def btn_create(self): - global MSG_FLAG - MSG_FLAG = 1 + def btn_create(self,msg): i = 0 j = 0 if self.msg_nums > 0: no_msg_text.add_flag(lv.obj.FLAG.HIDDEN) + self.sms_detail_list.delete()#先删除一次控件 + + self.sms_detail_list = lv.obj(msg_list_screen) + self.sms_detail_list.set_pos(0, 50) + self.sms_detail_list.set_size(240, 270) + self.sms_detail_list.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF) + self.sms_detail_list.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT) if self.msg_nums > 10: j = self.msg_nums-10 for i in range(self.msg_nums): - if i > MSG_MAX: + if i > (MSG_MAX-1): break - #print("sms.searchTextMsg(i):{} type:{}".format(sms.searchTextMsg(i),type(sms.searchTextMsg(i)))) + tmp = sms.searchTextMsg(j) - self.msg_detail[0] = tmp[0] - self.msg_detail[1] = tmp[1] - msg_btn = lv.btn(msg_list_t) - msg_btn.set_size(240,80) - msg_btn.set_pos(0,82*i) - msg_btn.add_style(style_contact_btn, lv.PART.MAIN | lv.STATE.DEFAULT) - msg_btn.add_style(style_common_bg_rect_btn_pressed, lv.PART.MAIN | lv.STATE.PRESSED) + # print("self.msg_nums:{} sms.searchTextMsg(i):{} tmp[0]:{} tmp[1]:{} j:{} i:{}".format(self.msg_nums,sms.searchTextMsg(j),tmp[0],tmp[1],j,i)) + msg_btn = lv.btn(self.sms_detail_list) + msg_btn.set_size(240,90) + msg_btn.set_pos(0,92*i) + msg_btn.add_style(style_sms_bg_btn, lv.PART.MAIN | lv.STATE.DEFAULT) msg_btn.add_event_cb(lambda e: self.calling(e), lv.EVENT.CLICKED, None) - - - - _btn_label2 = lv.label(msg_btn) _btn_label2.set_pos(0, 5) _btn_label2.set_size(180, 25) - _btn_label2.set_text(str(self.msg_detail[0])) + _btn_label2.set_text(tmp[0]) _btn_label2.set_long_mode(lv.label.LONG.DOT) - _btn_label2.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) + _btn_label2.add_style(style_font_youyuan_20_black, lv.PART.MAIN | lv.STATE.DEFAULT) # - _btn_label1 = lv.label(msg_btn) - _btn_label1.set_pos(0, 0) - _btn_label1.set_long_mode(lv.label.LONG.DOT) - _btn_label1.set_size(0, 0) - _btn_label1.set_text(str(i)) - - detail = self.msg_detail[1] + detail = tmp[1] _btn_label3 = lv.label(msg_btn) - _btn_label3.set_pos(0, 25) - _btn_label3.set_size(220, 30) - _btn_label3.set_text(str(detail)) - _btn_label3.set_long_mode(lv.label.LONG.DOT) - _btn_label3.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) - + _btn_label3.set_pos(0, 34) + _btn_label3.set_size(220, 35) + _btn_label3.set_text(detail) + _btn_label3.add_style(style_font_youyuan_20_black, lv.PART.MAIN | lv.STATE.DEFAULT) i = i + 1 j += 1 + if msg == 1: + bottom_btn = self.sms_detail_list.get_child(-1) + bottom_btn.scroll_to_view(lv.ANIM.OFF) else: no_msg_text.clear_flag(lv.obj.FLAG.HIDDEN) @@ -155,9 +155,8 @@ class PopupScreen(Screen): #上传标题和内容 _name = e.get_target().get_child(0).get_text() EventMesh.publish("save_msg_name", _name) - #_content = e.get_target().get_child(1).get_text() - conten = e.get_target().get_child(2).get_text() - EventMesh.publish("save_msg_content", conten) + content = e.get_target().get_child(1).get_text() + EventMesh.publish("save_msg_content", content) #显示详细页面 EventMesh.publish("load_screen", {"screen": "msg_detail"}) @@ -171,6 +170,284 @@ class PopupScreen(Screen): +# -------------------------------------------call_log screen---------------------------------------------------------- +call_log_screen = lv.obj() +call_log = lv.obj(call_log_screen) +call_log.center() +call_log.set_size(240, 320) +call_log.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT) + +call_log_screen = lv.obj() +call_log = lv.obj(call_log_screen) +call_log.center() +call_log.set_size(240, 320) +call_log.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT) + +contacts_cont_list= lv.obj(call_log) +contacts_cont_list.set_pos(0, 50) +contacts_cont_list.set_size(240, 270) +contacts_cont_list.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF) +contacts_cont_list.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT) + +call_log_title = lv.label(call_log) +call_log_title.set_pos(0, 10) +call_log_title.set_size(240, 40) +call_log_title.set_long_mode(lv.label.LONG.WRAP) +call_log_title.set_text("通话记录") +call_log_title.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) +call_log_title.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) + +none_call_log_title = lv.label(contacts_cont_list) +none_call_log_title.set_pos(0, 120) +none_call_log_title.set_size(240, 40) +none_call_log_title.set_long_mode(lv.label.LONG.WRAP) +none_call_log_title.set_text("暂无记录") +none_call_log_title.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) +none_call_log_title.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) + + +CALLLOG_FLAG = 0 +class CallLogScreen(Screen): + NAME = "call_log" + + def __init__(self): + super().__init__() + self.meta = call_log_screen + self.log_list = [] + self.read_call_log = {} + self.check_json = ql_fs.path_exists("ext/Call_log.json") + + if self.check_json == True: + with open("ext/Call_log.json","r",encoding="utf-8") as fd: + self.read_call_log = ujson.load(fd) + print("读取通话记录") + + def post_processor_before_initialization(self): + self.log_list = EventMesh.publish("get_call_log_list") + + def initialization(self): + self.btn_create() + + def btn_create(self): + h = 0 + if self.check_json == True: + sort_tmp = self.read_call_log.values() + # # print("self.call_log :{}\r\n".format(self.read_call_log)) + sort_new = sorted(sort_tmp, key = lambda i: i['timesec'],reverse = True)#按照时间戳进行排序 去掉最旧的一次数据如果满了五十条 + # print("self.call_log :{} \r\n sort_new:{}\r\n".format(self.read_call_log,sort_new)) + none_call_log_title.add_flag(lv.obj.FLAG.HIDDEN) + for sort_new_tmp in sort_new: #字典 key value + num_count = sort_new_tmp["count"]#获取通话次数 + num_name = sort_new_tmp["name"]#获取名称 + num_phonnum = sort_new_tmp["number"]#获取电话号码 + num_time = sort_new_tmp["time"]#获取电话号码 + + # print("num_count :{} num_name:{} num_time:{}".format(num_count,num_name,num_time)) + _btn = lv.btn(contacts_cont_list) + _btn.set_size(230,50) + _btn.set_pos(0,52*h) + _btn.add_style(style_contact_btn, lv.PART.MAIN | lv.STATE.DEFAULT) + _btn.add_event_cb(lambda e: self.calling(e), + lv.EVENT.CLICKED, None) + + + _btn_label2 = lv.label(_btn) + _btn_label2.set_pos(0, 5) + _btn_label2.set_size(100, 25) + _btn_label2.set_text(num_phonnum) + _btn_label2.add_style(style_font_youyuan_20_black, lv.PART.MAIN | lv.STATE.DEFAULT) + # + _btn_label3 = lv.label(_btn) + _btn_label3.set_pos(100, 5) + _btn_label3.set_size(100, 25) + _btn_label3.set_text("(" + str(num_count) + ") " + num_name) + _btn_label3.add_style(style_font_youyuan_20_black, lv.PART.MAIN | lv.STATE.DEFAULT) + + h = h + 1 + else: + none_call_log_title.clear_flag(lv.obj.FLAG.HIDDEN) + + + def calling(self,e): + print("e.get_text():{} {}".format(e.get_target().get_child(0).get_text(),e.get_target().get_child(1).get_text())) + phonnum = int(e.get_target().get_child(0).get_text()) + phnoname = e.get_target().get_child(1).get_text() + phnoname_tmp = phnoname.split(')') + phnoname_tmp = phnoname_tmp[1] + + print("phonnum :{} _msg:{}".format(phonnum,phnoname_tmp)) + EventMesh.publish("save_phonenum",phonnum) + EventMesh.publish("save_phonename",phnoname_tmp) + EventMesh.publish("load_screen", {"screen": "dialing"}) + + def done_return(self): + EventMesh.publish("load_screen", {"screen": "watchface"}) + + def btn1_release(self): + EventMesh.publish("load_screen", {"screen": "watchface"}) + + def btn8_press(self): + EventMesh.publish("load_screen", {"screen": "watchface"}) + + +class CallLogManager(Abstract): + # 通话记录 + def __init__(self): + self.log = [ + #电话 次数 时间 姓名 + ["15692025051","2","12:59","哥"], + ["15692025051","3","12:49","爸"], + ["15521469561","4","12:39","妈"], + ["15692025051","4","12:39","姐"], + ["15521469561","1","12:39","哥"], + ["15692466051","2","12:35","嫂子"], + ["15521469561","6","12:59","妹"], + ] + + def post_processor_after_instantiation(self): + EventMesh.subscribe("get_call_log_list", self.get) + + def get(self, event, msg): + return self.log + + def call_usr(self,event,msg): + content = self.log[msg] + # 参数1 姓名 参数2 电话 参数3 1/主动呼叫 0别人呼叫 + EventMesh.publish("call_in", [content[2], content[0], 1]) + +dialing_screen = lv.obj() +dialing = lv.obj(dialing_screen) +dialing.center() +dialing.set_size(240, 320) +dialing.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT) + +dialing_img = lv.img(dialing) +dialing_img.set_pos(80, 20) +dialing_img.set_size(64, 64) +dialing_img.set_src("E:/static/IMAGE_NOTICE_CALL.jpg") +dialing_img.add_style(style_img, lv.PART.MAIN | lv.STATE.DEFAULT) + +dialing_name = lv.label(dialing) +dialing_name.set_pos(0, 100) +dialing_name.set_size(240, 50) +dialing_name.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) +dialing_name.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) + +dialing_content = lv.label(dialing) +dialing_content.set_pos(0, 160) +dialing_content.set_size(240, 50) +dialing_content.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) +dialing_content.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) + +hangup_imgbtn = lv.img(dialing) +hangup_imgbtn.set_size(64, 64) +hangup_imgbtn.set_src("E:/static/IMG_CC_HUNGUP1.jpg") +hangup_imgbtn.add_flag(lv.obj.FLAG.CLICKABLE) +hangup_imgbtn.add_style(style_img, lv.PART.MAIN | lv.STATE.DEFAULT) +hangup_imgbtn.set_pos(80, 220) + +CALL_LOG_MAX = 50 + +class DialingScreen(Screen): + NAME = "dialing" + + def __init__(self): + super().__init__() + self.meta = dialing_screen + hangup_imgbtn.add_event_cb(lambda e: self.hangup(e), + lv.EVENT.CLICKED, None) + self.call_log = {} + self.call_log_value = {} + self.read_call_log = {} + self.number_tmp = {} + + def initialization(self): + #获取字符串 + name = EventMesh.publish("get_phonename") + content = EventMesh.publish("get_phonenum") + time = EventMesh.publish("screen_get_time") + # ["15692025051","2","12:59","哥gdh符合双方和开发商开发好看的思考"], + # 格式:{"电话号码":{"timesec":'时间戳',"number":'电话号码',"name":'名字',"time":'时间',"count":'通话次数'}} + + dialing_name.set_text(name)#名称 + dialing_content.set_text(content)#电话号码 + num = 0 + check_json = ql_fs.path_exists("ext/Call_log.json") + + date_tmp = utime.localtime() + time_tmp = utime.mktime(date_tmp) + # print("time_tmp:{}".format(time_tmp)) + + if check_json == True: + with open("ext/Call_log.json","r",encoding="utf-8") as fd: + self.read_call_log = ujson.load(fd) + print("读取通话记录") + + b = content in self.read_call_log.keys()#查找key中是否包含content电话号码 True 包含在里面 False不包含在里面 + + # print("b:{}".format(b)) + + if b == True:#查找是否有相同的电话号码 有就直接读出来的次数上加一 没有则从1开始加起 + number_tmp = {} + number_tmp = self.read_call_log[content] #通话次数加一 + num_tmp_t = number_tmp["count"] + # print("number_tmp:{} self.read_call_log.value:{}".format(number_tmp,self.read_call_log.values())) + else : + num_tmp_t = 0 + num = num_tmp_t + else: + num = 0 #通话次数 + + sort_tmp = {} + sort_tmp = self.read_call_log.values() + sort_new = {} + sort_new = sorted(sort_tmp, key = lambda i: i['timesec'],reverse = True)#按照时间戳进行排序 去掉最旧的一次数据如果满了五十条 + print("self.read_call_log:{} sort_new:{}\r\n".format(self.read_call_log,sort_new)) + #popitem + i = 0 + if len(self.read_call_log) > CALL_LOG_MAX: + for sort_new_tmp in sort_new: #字典 key value + i+=1 # 1 + if i > CALL_LOG_MAX:#大于50条把最后几条删除掉只保留前面50调最新的数据 + key_tmp = sort_new_tmp["number"] + # print("key :{} value:{} len:{} value_tmp:{} key_tmp:{}\r\n".format(key,value,len(self.read_call_log),value_tmp,key_tmp)) + del self.read_call_log[key_tmp] + # print("delte :{}".format(self.read_call_log)) + + # print("self.read_call_log end :{}\r\n".format(self.read_call_log)) + + tmp = {} + tmp["count"]= num+1 #通话次数 + tmp["time"]= "{}:{}".format("%02d"%(time[0][0]),"%02d"%(time[0][1]))#通湖时间 + tmp["name"]= name #名称 + tmp["timesec"]= time_tmp #时间戳 + tmp["number"] = content + + self.read_call_log[content] = tmp + # sort_tmp = self.read_call_log.values() + # # print("self.call_log :{}\r\n".format(self.read_call_log)) + # sort_new = sorted(sort_tmp, key = lambda i: i['timesec'],reverse = True)#按照时间戳进行排序 去掉最旧的一次数据如果满了五十条 + with open("ext/Call_log.json","w",encoding="utf-8") as fd: + ujson.dump(self.read_call_log,fd) + print("创建通话记录") + + + + def done_return(self): + EventMesh.publish("load_screen", {"screen": "watchface"}) + + def hangup(self,e): + voiceCall.callEnd() + EventMesh.publish("load_screen", {"screen": "contacts"}) + + def btn1_release(self): + EventMesh.publish("load_screen", {"screen": "watchface"}) + + def btn8_press(self): + EventMesh.publish("load_screen", {"screen": "watchface"}) + + + @@ -201,7 +478,4 @@ class MsgManager(Abstract): "小红":"今晚十点一起吃饭" } - - - - + \ No newline at end of file diff --git a/3.code/1.watch/2.code/ui.py b/3.code/1.watch/2.code/ui.py index e0e30659..7bdf44fd 100644 --- a/3.code/1.watch/2.code/ui.py +++ b/3.code/1.watch/2.code/ui.py @@ -12,6 +12,7 @@ import ujson import audio import ql_fs import audio +import sms from machine import Pin from ext.lcd import gpio_backlight,lcd,lcd_ctrl,tp_cst816 import uos @@ -108,7 +109,7 @@ style_wechat_btn.set_shadow_opa(0) style_contact_btn = lv.style_t() style_contact_btn.init() -style_contact_btn.set_bg_color(lv.color_make(0x1E, 0x26, 0xff)) +style_contact_btn.set_bg_color(lv.color_make(0xff, 0xff, 0xff)) style_contact_btn.set_border_width(0) style_contact_btn.set_shadow_opa(0) @@ -945,23 +946,26 @@ dialing.set_size(240, 320) dialing.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT) dialing_img = lv.img(dialing) -dialing_img.set_pos(80, 50) +dialing_img.set_pos(80, 20) dialing_img.set_size(64, 64) dialing_img.set_src("E:/static/IMAGE_NOTICE_CALL.jpg") dialing_img.add_style(style_img, lv.PART.MAIN | lv.STATE.DEFAULT) -dialing_label = lv.label(dialing) -dialing_label.set_pos(0, 150) -dialing_label.set_size(240, 50) -dialing_label.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) -dialing_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) +dialing_name = lv.label(dialing) +dialing_name.set_pos(0, 100) +dialing_name.set_size(240, 50) +dialing_name.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) +dialing_name.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) + +dialing_content = lv.label(dialing) +dialing_content.set_pos(0, 160) +dialing_content.set_size(240, 50) +dialing_content.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) +dialing_content.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) hangup_imgbtn = lv.img(dialing) hangup_imgbtn.set_size(64, 64) hangup_imgbtn.set_src("E:/static/IMG_CC_HUNGUP1.jpg") - - - hangup_imgbtn.add_flag(lv.obj.FLAG.CLICKABLE) hangup_imgbtn.add_style(style_img, lv.PART.MAIN | lv.STATE.DEFAULT) hangup_imgbtn.set_pos(80, 220) @@ -1287,7 +1291,6 @@ class CallLogScreen(Screen): _btn.set_size(230,50) _btn.set_pos(0,52*h + 50) _btn.add_style(style_contact_btn, lv.PART.MAIN | lv.STATE.DEFAULT) - _btn.add_style(style_common_bg_rect_btn_pressed, lv.PART.MAIN | lv.STATE.PRESSED) _btn.add_event_cb(lambda e: self.calling(e), lv.EVENT.CLICKED, None) @@ -1302,22 +1305,23 @@ class CallLogScreen(Screen): _btn_label2.set_size(100, 25) _btn_label2.set_text(each[0]) _btn_label2.set_long_mode(lv.label.LONG.DOT) - _btn_label2.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) + _btn_label2.add_style(style_font_youyuan_20_black, lv.PART.MAIN | lv.STATE.DEFAULT) # _btn_label3 = lv.label(_btn) _btn_label3.set_pos(100, 5) _btn_label3.set_size(100, 25) _btn_label3.set_text("(" + each[1] + ") " + each[3]) _btn_label3.set_long_mode(lv.label.LONG.DOT) - _btn_label3.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) + _btn_label3.add_style(style_font_youyuan_20_black, lv.PART.MAIN | lv.STATE.DEFAULT) h = h + 1 def calling(self,e): _i = int(e.get_target().get_child(0).get_text()) _msg = self.log_list[_i] - print("_i..........%d",_i) + print("_i :{} _msg:{}".format(_i,_msg)) EventMesh.publish("save_phonenum",_msg[0]) + EventMesh.publish("save_phonename",_msg[3]) EventMesh.publish("load_screen", {"screen": "dialing"}) def done_return(self): @@ -1339,21 +1343,22 @@ class DialingScreen(Screen): self.meta = dialing_screen hangup_imgbtn.add_event_cb(lambda e: self.hangup(e), lv.EVENT.CLICKED, None) - self.value = "" def initialization(self): #获取字符串 - self.value = EventMesh.publish("get_phonenum") - print("dialing %s\r\n"%self.value) - dialing_label.set_text(self.value) + name = EventMesh.publish("get_phonename") + content = EventMesh.publish("get_phonenum") + # print("name %s content %s\r\n"%(name,content)) + dialing_name.set_text(name)#名称 + dialing_content.set_text(content)#电话号码 def done_return(self): EventMesh.publish("load_screen", {"screen": "watchface"}) def hangup(self,e): voiceCall.callEnd() - EventMesh.publish("load_screen", {"screen": "watchface"}) + EventMesh.publish("load_screen", {"screen": "contacts"}) def btn1_release(self): EventMesh.publish("load_screen", {"screen": "watchface"}) @@ -1362,84 +1367,154 @@ class DialingScreen(Screen): EventMesh.publish("load_screen", {"screen": "watchface"}) +############短信############################### +MSG_FLAG = 0 MSG_FLAG = 0 +MSG_MAX = 10 #最大显示短信内容条数 + +style_sms_bg_btn = lv.style_t() +style_sms_bg_btn.init() +#style_sms_bg_btn.set_bg_color(lv.color_make(0x00, 0xff, 0x2a)) +style_sms_bg_btn.set_bg_color(lv.color_make(0xff, 0xff, 0xff)) +style_sms_bg_btn.set_border_width(0) +style_sms_bg_btn.set_shadow_opa(0) + + +msg_list_screen = lv.obj() +msg_screen = lv.obj(msg_list_screen) +msg_screen.center() +msg_screen.set_size(240, 320) +msg_screen.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT) + +msg_top_title = lv.label(msg_screen) +msg_top_title.set_pos(0, 10) +msg_top_title.set_size(240, 40) +msg_top_title.set_text("信息") +msg_top_title.set_long_mode(lv.label.LONG.WRAP) +msg_top_title.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) +msg_top_title.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) + +msg_cont_detail = lv.obj(msg_screen) +msg_cont_detail.set_pos(0, 50) +msg_cont_detail.set_size(240, 270) +msg_cont_detail.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) + + +msg_list_t= lv.obj(msg_list_screen) +msg_list_t.set_pos(0, 50) +msg_list_t.set_size(240, 270) +msg_list_t.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF) +msg_list_t.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT) + + +no_msg_text = lv.label(msg_list_t) +no_msg_text.set_pos(0, 120) +no_msg_text.set_size(240, 40) +no_msg_text.set_text("暂无信息") +no_msg_text.set_long_mode(lv.label.LONG.WRAP) +no_msg_text.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) +no_msg_text.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) + + + + + + + + + +def msg_cb(args): + index = args[1] + storage = args[2] + EventMesh.publish("sms_updata_list_show") + #print('New message! storage:{},index:{}'.format(storage, index)) + +sms.setCallback(msg_cb) + + + class PopupScreen(Screen): NAME = "popup" def __init__(self): super().__init__() # -------------------------------------------popup_menu screen---------------------------------------------------------- - self.meta = lv.obj() - self.meta.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF) - # add style for watchface - self.meta.add_style(style_screen, lv.PART.MAIN|lv.STATE.DEFAULT) - - self.msg_title = lv.label(self.meta) - self.msg_title.set_pos(0, 10) - self.msg_title.set_size(240, 40) - self.msg_title.set_text("信息") - self.msg_title.set_long_mode(lv.label.LONG.WRAP) - self.msg_title.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) - self.msg_title.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) - + self.meta = msg_list_screen + self.msg_detail = {} + self.msg_nums = 0 + self.sms_detail_list = lv.obj() + EventMesh.subscribe("sms_updata_list_show", self.sms_create_list) def post_processor_before_initialization(self): - check_json = ql_fs.path_exists("/usr/msg.json") - self.msg_detail = EventMesh.publish("get_msg_detail") - if check_json == False: - with open("usr/msg.json","w",encoding="utf-8") as fd: - ujson.dump(self.msg_detail,fd) - print("创建短信") - else: - with open("usr/msg.json","r",encoding="utf-8") as fd: - self.msg_detail = ujson.load(fd) - print("读取短信") - + self.msg_nums = sms.getMsgNums() #获取短信条数 def initialization(self): - global MSG_FLAG - if MSG_FLAG == 0: - self.btn_create() + self.msg_nums = sms.getMsgNums() + # print("self.msg_nums:{} type:{}".format(self.msg_nums,type(sms.getMsgNums()))) + self.btn_create(0) + def sms_create_list(self,event,msg): + self.msg_nums = sms.getMsgNums() + self.btn_create(1) - def btn_create(self): - global MSG_FLAG - MSG_FLAG = 1 + def btn_create(self,msg): i = 0 - for key in self.msg_detail.keys(): - msg_btn = lv.btn(self.meta) - msg_btn.set_size(240,50) - msg_btn.set_pos(0,52*i) - msg_btn.add_style(style_contact_btn, lv.PART.MAIN | lv.STATE.DEFAULT) - msg_btn.add_style(style_common_bg_rect_btn_pressed, lv.PART.MAIN | lv.STATE.PRESSED) - msg_btn.add_event_cb(lambda e: self.calling(e), - lv.EVENT.PRESSED, None) - - contact_btn_label = lv.label(msg_btn) - contact_btn_label.set_text(key) - contact_btn_label.align(lv.ALIGN.LEFT_MID, 10, 0) - contact_btn_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) - - detail = self.msg_detail[key] - print("------:",detail) - contact_content_label = lv.label(msg_btn) - contact_content_label.set_text(detail[:15]) - contact_content_label.align(lv.ALIGN.LEFT_MID, 80, 0) - contact_content_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) - i = i + 1 + j = 0 + if self.msg_nums > 0: + no_msg_text.add_flag(lv.obj.FLAG.HIDDEN) + self.sms_detail_list.delete()#先删除一次控件 + + self.sms_detail_list = lv.obj(msg_list_screen) + self.sms_detail_list.set_pos(0, 50) + self.sms_detail_list.set_size(240, 270) + self.sms_detail_list.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF) + self.sms_detail_list.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT) + if self.msg_nums > 10: + j = self.msg_nums-10 + for i in range(self.msg_nums): + if i > (MSG_MAX-1): + break + + tmp = sms.searchTextMsg(j) + # print("self.msg_nums:{} sms.searchTextMsg(i):{} tmp[0]:{} tmp[1]:{} j:{} i:{}".format(self.msg_nums,sms.searchTextMsg(j),tmp[0],tmp[1],j,i)) + msg_btn = lv.btn(self.sms_detail_list) + msg_btn.set_size(240,90) + msg_btn.set_pos(0,92*i) + msg_btn.add_style(style_sms_bg_btn, lv.PART.MAIN | lv.STATE.DEFAULT) + msg_btn.add_event_cb(lambda e: self.calling(e), + lv.EVENT.CLICKED, None) + _btn_label2 = lv.label(msg_btn) + _btn_label2.set_pos(0, 5) + _btn_label2.set_size(180, 25) + _btn_label2.set_text(tmp[0]) + _btn_label2.set_long_mode(lv.label.LONG.DOT) + _btn_label2.add_style(style_font_youyuan_20_black, lv.PART.MAIN | lv.STATE.DEFAULT) + # + + detail = tmp[1] + _btn_label3 = lv.label(msg_btn) + _btn_label3.set_pos(0, 34) + _btn_label3.set_size(220, 35) + _btn_label3.set_text(detail) + _btn_label3.add_style(style_font_youyuan_20_black, lv.PART.MAIN | lv.STATE.DEFAULT) + + i = i + 1 + j += 1 + if msg == 1: + bottom_btn = self.sms_detail_list.get_child(-1) + bottom_btn.scroll_to_view(lv.ANIM.OFF) + else: + no_msg_text.clear_flag(lv.obj.FLAG.HIDDEN) + def calling(self,e): #上传标题和内容 _name = e.get_target().get_child(0).get_text() EventMesh.publish("save_msg_name", _name) - #_content = e.get_target().get_child(1).get_text() - EventMesh.publish("save_msg_content", self.msg_detail[_name]) - print(_name,self.msg_detail[_name]) + content = e.get_target().get_child(1).get_text() + EventMesh.publish("save_msg_content", content) + #显示详细页面 EventMesh.publish("load_screen", {"screen": "msg_detail"}) - - - def done_bottom_to_top(self): - EventMesh.publish("load_screen", {"screen": "watchface"}) def done_return(self): EventMesh.publish("load_screen", {"screen": "watchface"}) @@ -1448,6 +1523,10 @@ class PopupScreen(Screen): def btn8_press(self): EventMesh.publish("load_screen", {"screen": "watchface"}) + + + + class MsgDetailScreen(Screen): NAME = "msg_detail" @@ -1671,7 +1750,7 @@ class StepScreen(Screen): def btn8_press(self): EventMesh.publish("load_screen", {"screen": "watchface"}) -# -------------------------------------------contacts screen---------------------------------------------------------- +# -----------------------------联系人--------------contacts screen---------------------------------------------------------- contacts_screen = lv.obj() contacts = lv.obj(contacts_screen) @@ -1680,15 +1759,21 @@ contacts.set_size(240, 320) contacts.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT) contacts.set_scrollbar_mode(0) +contacts_cont= lv.obj(contacts_screen) +contacts_cont.set_pos(0, 50) +contacts_cont.set_size(240, 270) +contacts_cont.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF) +contacts_cont.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT) + +contacts_top_title = lv.label(contacts) +contacts_top_title.set_pos(0, 10) +contacts_top_title.set_size(240, 40) +contacts_top_title.set_text("联系人") +contacts_top_title.set_long_mode(lv.label.LONG.WRAP) +contacts_top_title.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) +contacts_top_title.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) -contacts_cont = lv.obj(contacts_screen) -contacts_cont.set_pos(0, 0) -contacts_cont.set_size(240, 320) -contacts_cont_style = ContStyle() -contacts_cont.add_style( - contacts_cont_style.style_cont(0, lv.color_make(0x00, 0x00, 0x00), lv.color_make(0x00, 0x00, 0x00), 255), - lv.PART.MAIN | lv.STATE.DEFAULT) contact_none_label = lv.label(contacts_cont) contact_none_label.set_pos(0, 120) @@ -1711,67 +1796,110 @@ class ContactsScreen(Screen): self.phone_num = {} self.name = [] self.check_json = 0 + self.timer = osTimer() + self.contact_detail_list = lv.obj() + EventMesh.subscribe("contact_updata_list_show", self.btn_create_list) def post_processor_before_initialization(self): - self.check_json = ql_fs.path_exists("/usr/phonebook.json") + self.check_json = ql_fs.path_exists("ext/phonebook.json") self.phonebook = EventMesh.publish("get_addr_book_list") - print("check_json %d"%(self.check_json)) + # print("check_json %d"%(self.check_json)) self.count = 0 if self.check_json == True: - with open("usr/phonebook.json","r",encoding="utf-8") as fd: + with open("ext/phonebook.json","r",encoding="utf-8") as fd: self.phonebook = ujson.load(fd) print("读取电话簿") - # if check_json == False: - # # with open("usr/phonebook.json","w",encoding="utf-8") as fd: - # # ujson.dump(self.phonebook,fd) - # # print("创建电话簿") - # else: - # with open("usr/phonebook.json","r",encoding="utf-8") as fd: - # self.phonebook = ujson.load(fd) - # print("读取电话簿") - def initialization(self): #读取json文件中的字典放到self.phonebook中 #创建btn - self.btn_create() + self.count = 0 + self.btn_create_list_show(0) - def btn_create(self): + def btn_create_list(self,event,msg): + self.post_processor_before_initialization() + self.timer.start(1 * 1000, 0, self.OutTime_s) + + def OutTime_s(self,e): + self.btn_create_list_show(1) + def btn_create_list_show(self,state): + #读取json文件中的键作为label文本; if self.check_json == True: contact_none_label.add_flag(lv.obj.FLAG.HIDDEN)#隐藏空文本 - for key,value in dict.items(self.phonebook): #字典 key value - - print("self.phonebook value %s \r\n %s"%(key,value)) - contact_btn = lv.btn(contacts_cont) + j =0 + i = 0 + # print("self.phonebook sorted :{} len(self.phonebook) :{}".format(sorted(self.phonebook.keys()),len(self.phonebook))) + phonebook_keys = sorted(self.phonebook.keys()) + # new_sys1 = sorted(self.phonebook.items(), key=lambda d: d[0], reverse=False) + # print("new_sys1 :{} ".format(new_sys1)) + + # new_sys2 = sorted(self.phonebook.items(), key=lambda d: d[1], reverse=False) + # print("new_sys2 :{} ".format(new_sys2)) + self.contact_detail_list.delete()#先删除一次控件 + self.contact_detail_list = lv.obj(contacts_screen) + self.contact_detail_list.set_pos(0, 50) + self.contact_detail_list.set_size(240, 270) + self.contact_detail_list.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF) + self.contact_detail_list.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT) + for i in range(len(self.phonebook)): #字典 key value + if j > 50: + j = 0 + j+=1 + name = self.phonebook[phonebook_keys[j-1]] + key_tmp = phonebook_keys[j-1] + + # print("name :{} key_tmp:{}".format(name,key_tmp)) + + contact_btn = lv.btn(self.contact_detail_list) contact_btn.set_size(230,80) - contact_btn.set_pos(0,82*self.count ) + contact_btn.set_pos(0,82*i ) contact_btn.add_style(style_contact_btn, lv.PART.MAIN | lv.STATE.DEFAULT) # contact_btn.add_style(style_contact_btn_pressed, lv.PART.MAIN | lv.STATE.PRESSED) contact_btn.add_event_cb(lambda e: self.calling(e), lv.EVENT.CLICKED, None) - contact_btn_label = lv.label(contact_btn) - contact_btn_label.set_text(key+'\r\n'+ value) - contact_btn.set_style_text_align(lv.TEXT_ALIGN.LEFT ,0) - # contact_btn_label.align(lv.ALIGN.LEFT, 10, 0) - contact_btn_label.add_style(style_font_youyuan_20_black, lv.PART.MAIN | lv.STATE.DEFAULT) + contact_btn_label_1 = lv.label(contact_btn) + contact_btn_label_1.set_pos(0, 5) + contact_btn_label_1.set_size(180, 25) + contact_btn_label_1.set_text(key_tmp[4:]) + contact_btn_label_1.set_long_mode(lv.label.LONG.DOT) + contact_btn_label_1.add_style(style_font_youyuan_20_black, lv.PART.MAIN | lv.STATE.DEFAULT) + + contact_btn_label_1 = lv.label(contact_btn) + contact_btn_label_1.set_pos(0, 5) + contact_btn_label_1.set_size(0, 0) + contact_btn_label_1.set_text(key_tmp) + + + contact_btn_label_2 = lv.label(contact_btn) + contact_btn_label_2.set_pos(0, 30) + contact_btn_label_2.set_size(220, 35) + contact_btn_label_2.set_text(name) + contact_btn_label_2.add_style(style_font_youyuan_20_black, lv.PART.MAIN | lv.STATE.DEFAULT) - self.count += 1 + i += 1 + if state == 1: + bottom_btn = self.contact_detail_list.get_child(-1) + bottom_btn.scroll_to_view(lv.ANIM.OFF) else: contact_none_label.clear_flag(lv.obj.FLAG.HIDDEN) #显示空文本 + self.contact_detail_list.add_flag(lv.obj.FLAG.HIDDEN)#隐藏空文本 def calling(self,e): - _msg = e.get_target().get_child(0).get_text() - _msg = _msg.split('\r\n') - EventMesh.publish("save_phonenum", _msg[0]) - self.phone_num = self.phonebook[_msg[0]] - # print(_msg,self.phone_num,_msg) - voiceCall.callStart(self.phone_num) + _msg = e.get_target().get_child(1).get_text() + print("_msg:{}".format(_msg)) + msg_tmp = _msg.split(':') + msg_tmp = msg_tmp[1] + EventMesh.publish("save_phonename", msg_tmp) + + phone_num = self.phonebook[_msg] + EventMesh.publish("save_phonenum", phone_num) + voiceCall.callStart(phone_num) EventMesh.publish("load_screen", {"screen": "dialing"}) def done_return(self): @@ -1784,6 +1912,9 @@ class ContactsScreen(Screen): EventMesh.publish("load_screen", {"screen": "watchface"}) + + + class AlarmScreen(Screen): NAME = "alarm" diff --git a/3.code/1.watch/2.code/ui_setting.py b/3.code/1.watch/2.code/ui_setting.py index 1dfac3d8..8447c824 100644 --- a/3.code/1.watch/2.code/ui_setting.py +++ b/3.code/1.watch/2.code/ui_setting.py @@ -880,9 +880,9 @@ class RestoreScreen(Screen): def confirm(self, e): global ret ret = 0 - ret = ql_fs.path_exists("/usr/phonebook.json") + ret = ql_fs.path_exists("/ext/phonebook.json") if ret == True : - ql_fs.rmdirs("/usr/phonebook.json") + ql_fs.rmdirs("ext/phonebook.json") else: pass Power.powerRestart()