自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

HarmonyOS分布式應(yīng)用智能三角警示牌解讀

開(kāi)發(fā) 前端 分布式 OpenHarmony
我們?cè)O(shè)計(jì)了智能移動(dòng)三角警示牌以解決該問(wèn)題。本智能三角警示牌通過(guò)手機(jī)HAP可以與其相連,控制運(yùn)動(dòng)方向和速度,使其停放在事故現(xiàn)場(chǎng)后方合適的位置,從而能夠保障用戶的人身和財(cái)產(chǎn)安全。

[[439635]]

想了解更多內(nèi)容,請(qǐng)?jiān)L問(wèn):

51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos.51cto.com

前言

HarmonyOS是 一款面向萬(wàn)物互聯(lián)時(shí)代的、全新的分布式操作系統(tǒng),其分布式技術(shù)能力(分布式軟總線、分布式設(shè)備虛擬化、分布式數(shù)據(jù)管理、分布式任務(wù)調(diào)度)一直受到廣大開(kāi)發(fā)者的極大關(guān)注,使用戶對(duì)HarmonyOS有著很高的贊許。

我們開(kāi)發(fā)的《分布式智能三角警示牌應(yīng)用》,以在日常生活中,公路上發(fā)生交通事故時(shí)通常是事故相關(guān)人員手持三角反光警示牌步行至目的地處放置,人為放置具有引發(fā)二次事故的風(fēng)險(xiǎn),因此我們?cè)O(shè)計(jì)了智能移動(dòng)三角警示牌以解決該問(wèn)題。本智能三角警示牌通過(guò)手機(jī)HAP可以與其相連,控制運(yùn)動(dòng)方向和速度,使其停放在事故現(xiàn)場(chǎng)后方合適的位置,從而能夠保障用戶的人身和財(cái)產(chǎn)安全。

當(dāng)在控制警示牌運(yùn)動(dòng)過(guò)程中,有緊急事情或其它情況,可以將當(dāng)前的操作流轉(zhuǎn)到另外一臺(tái)設(shè)備中進(jìn)行操作,其運(yùn)動(dòng)軌跡就是通過(guò)分布式數(shù)據(jù)服務(wù)來(lái)保證兩臺(tái)設(shè)備間數(shù)據(jù)的一致性。

效果展示

#星光計(jì)劃2.0#HarmonyOS分布式應(yīng)用智能三角警示牌解讀-鴻蒙HarmonyOS技術(shù)社區(qū)
#星光計(jì)劃2.0#HarmonyOS分布式應(yīng)用智能三角警示牌解讀-鴻蒙HarmonyOS技術(shù)社區(qū)

一、創(chuàng)建“智能三角警示牌”HAP工程

1、安裝和配置DevEco Studio

2.1 Release

安裝的鏈接:https://developer.harmonyos.com/cn/develop/deveco-studio

IDE的使用指南,很詳細(xì):https://developer.harmonyos.com/cn/docs/documentation/doc-guides/tools_overview-0000001053582387

我的本案例使用的最新的 2.1.0.501版本,SDK:API Version 5

2、選擇一個(gè)模版,創(chuàng)建一個(gè)Java Phone應(yīng)用

#星光計(jì)劃2.0#HarmonyOS分布式應(yīng)用智能三角警示牌解讀-鴻蒙HarmonyOS技術(shù)社區(qū)

==點(diǎn)擊Next ==

#星光計(jì)劃2.0#HarmonyOS分布式應(yīng)用智能三角警示牌解讀-鴻蒙HarmonyOS技術(shù)社區(qū)

點(diǎn)擊Finish完成創(chuàng)建HAP工程

3、智能三角警示牌應(yīng)用包結(jié)構(gòu)

首先完成智能三角警示牌應(yīng)用包結(jié)構(gòu)設(shè)計(jì),結(jié)構(gòu)如下:

#星光計(jì)劃2.0#HarmonyOS分布式應(yīng)用智能三角警示牌解讀-鴻蒙HarmonyOS技術(shù)社區(qū) 

二、智能三角警示牌應(yīng)用核心代碼實(shí)現(xiàn)

1、config.json權(quán)限配置

  1. "reqPermissions": [ 
  2.       { 
  3.         "name""ohos.permission.INTERNET" 
  4.       }, 
  5.       { 
  6.         "name""ohos.permission.GET_NETWORK_INFO" 
  7.       }, 
  8.       { 
  9.         "name""ohos.permission.MICROPHONE" 
  10.       }, 
  11.       { 
  12.         "name""android.permission.RECORD_AUDIO" 
  13.       }, 
  14.       { 
  15.         "name""ohos.permission.DISTRIBUTED_DATASYNC" 
  16.       }, 
  17.       { 
  18.         "name""ohos.permission.servicebus.ACCESS_SERVICE" 
  19.       }, 
  20.       { 
  21.         "name""com.huawei.hwddmp.servicebus.BIND_SERVICE" 
  22.       }, 
  23.       { 
  24.         "name""ohos.permission.DISTRIBUTED_DEVICE_STATE_CHANGE" 
  25.       }, 
  26.       { 
  27.         "name""ohos.permission.GET_DISTRIBUTED_DEVICE_INFO" 
  28.       }, 
  29.       { 
  30.         "name""ohos.permission.GET_BUNDLE_INFO" 
  31.       }, 
  32.       { 
  33.         "name": "ohos.p 
  34. ermission.LOCATION" 
  35.       } 
  36.     ] 

2、分布式數(shù)據(jù)服務(wù)核心代碼

  1. import com.google.gson.Gson; 
  2. import com.google.gson.reflect.TypeToken; 
  3. import com.isoftstone.smartcar.app.common.Constant; 
  4. import com.isoftstone.smartcar.app.model.DrivingMap; 
  5. import com.isoftstone.smartcar.app.model.DrivingRecord; 
  6. import com.isoftstone.smartcar.app.model.ReportRecord; 
  7. import com.isoftstone.smartcar.app.utils.DrivingReportComparator; 
  8. import com.isoftstone.smartcar.app.utils.ReportRecordComparator; 
  9. import com.isoftstone.smartcar.app.utils.StringUtils; 
  10. import ohos.app.Context; 
  11. import ohos.data.distributed.common.*; 
  12. import ohos.data.distributed.device.DeviceFilterStrategy; 
  13. import ohos.data.distributed.device.DeviceInfo; 
  14. import ohos.data.distributed.user.SingleKvStore; 
  15. import ohos.hiviewdfx.HiLog; 
  16. import ohos.hiviewdfx.HiLogLabel; 
  17. import java.util.ArrayList; 
  18. import java.util.List; 
  19. /** 
  20.  * 分布式數(shù)據(jù)庫(kù)類(lèi)服務(wù) 
  21.  */ 
  22. public class SmartShareService { 
  23.     private static final HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, 0x00201, "SmartshareService"); 
  24.     private static SmartShareService smartShareService; 
  25.     private static SingleKvStore singleKvStore; 
  26.     private static KvManager kvManager; 
  27.     private final Context context; 
  28.     public static SmartShareService getInstance(Context context) { 
  29.         if (smartShareService == null) { 
  30.             smartShareService = new SmartShareService(context); 
  31.         } 
  32.         return smartShareService; 
  33.     } 
  34.     private SmartShareService(Context context){ 
  35.             this.context = context; 
  36.     } 
  37.     /** 
  38.      * 分布式數(shù)據(jù)庫(kù)初始化 
  39.      */ 
  40.     public void init() { 
  41.         KvManagerConfig config = new KvManagerConfig(context); 
  42.         kvManager = KvManagerFactory.getInstance().createKvManager(config); 
  43.         Options options = new Options();        options.setCreateIfMissing(true).setEncrypt(false).setKvStoreType(KvStoreType.SINGLE_VERSION).setAutoSync(true); 
  44.         singleKvStore = kvManager.getKvStore(options, Constant.SMART_SHARE_NAME); 
  45.         HiLog.info(label,"初始化成功!"); 
  46.         //return singleKvStore; 
  47.     } 
  48.     /** 
  49.      * 新增行駛記錄 
  50.      * @param drivingRecord 行駛記錄對(duì)象 
  51.      */ 
  52.     public void insertDrivingRecord(DrivingRecord drivingRecord){ 
  53.         Gson gson = new Gson(); 
  54.         String resultJson = gson.toJson(drivingRecord);        singleKvStore.putString(Constant.DRIVING_REPORT_PREFIX+drivingRecord.getId(),resultJson); 
  55.         HiLog.info(label,"新增行駛記錄成功!"); 
  56.     } 
  57.     /** 
  58.      * 批量新增行駛記錄軌跡 
  59.      * @param drivingId 行駛記錄標(biāo)識(shí) 
  60.      * @param drivingMapLst 行駛記錄軌跡列表 
  61.      */ 
  62.     public void insertDrivingMap(String drivingId, List<DrivingMap> drivingMapLst){ 
  63.         Gson gson = new Gson(); 
  64.         String resultJson = gson.toJson(drivingMapLst);        singleKvStore.putString(Constant.DRIVING_MAP_PREFIX+drivingId,resultJson); 
  65.         HiLog.info(label,"批量新增行駛記錄軌跡成功!"); 
  66.     } 
  67.     /** 
  68.      * 新增上報(bào)記錄 
  69.      * @param drivingId 行駛記錄標(biāo)識(shí) 
  70.      * @param reportRecord 上報(bào)記錄對(duì)象 
  71.      */ 
  72.     public void insertReportRecord(String drivingId, ReportRecord reportRecord){ 
  73.         Gson gson = new Gson(); 
  74.         List<Entry> entrys = singleKvStore.getEntries(Constant.REPORT_RECORD_PREFIX+drivingId); 
  75.         if (entrys == null || entrys.size() == 0){ 
  76.             List<ReportRecord> reportRecordLst = new ArrayList<>(); 
  77.             reportRecordLst.add(reportRecord); 
  78.             String resultJson1 = gson.toJson(reportRecordLst);            singleKvStore.putString(Constant.REPORT_RECORD_PREFIX+drivingId,resultJson1); 
  79.             HiLog.info(label,"新增上報(bào)記錄成功!"); 
  80.         } else { 
  81.             String resultJson = entrys.get(0).getValue().getString(); 
  82.             List<ReportRecord> reportRecordLst = gson.fromJson(resultJson, new TypeToken<List<ReportRecord>>() {}.getType()); 
  83.             reportRecordLst.add(reportRecord); 
  84.             String resultJson1 = gson.toJson(reportRecordLst); 
  85.             singleKvStore.putString(Constant.REPORT_RECORD_PREFIX+drivingId,resultJson1); 
  86.             HiLog.info(label,"新增上報(bào)記錄列表成功!"); 
  87.         } 
  88.     } 
  89.     /** 
  90.      * 設(shè)置保險(xiǎn)電話 
  91.      * @param key       保險(xiǎn)key 
  92.      * @param telphone  保險(xiǎn)key對(duì)應(yīng)的值 
  93.      */ 
  94.     public void setupInsuranceTelphone(String key,String telphone){ 
  95.         singleKvStore.putString(Constant.TEL_PREFIX+key,telphone); 
  96.         HiLog.info(label,"設(shè)置保險(xiǎn)電話成功!"); 
  97.     } 
  98.     /** 
  99.      * 獲取保險(xiǎn)電話 
  100.      * @param key 保險(xiǎn)電話key 
  101.      * @return 保險(xiǎn)電話 
  102.      */ 
  103.     public String getInsuranceTelphone(String key){ 
  104.         String tel = ""
  105.         List<Entry> entrys = singleKvStore.getEntries(Constant.TEL_PREFIX+key); 
  106.         if (entrys != null && entrys.size()>0) { 
  107.             tel = entrys.get(0).getValue().getString(); 
  108.             HiLog.info(label,"獲取保險(xiǎn)電話成功!"+tel); 
  109.         } else { 
  110.             HiLog.info(label,"沒(méi)有獲取保險(xiǎn)電話!"); 
  111.         } 
  112.         return tel; 
  113.     } 
  114.     /** 
  115.      * 設(shè)置IP 
  116.      * @param key  IP的key 
  117.      * @param value IP的value 
  118.      */ 
  119.     public void setIp(String key,String value){ 
  120.         singleKvStore.putString(Constant.IP_PREFIX+key,value); 
  121.         HiLog.info(label,"設(shè)置IP成功!"); 
  122.     } 
  123.     /** 
  124.      * 獲取IP 
  125.      * @param key  IP的key 
  126.      * @return IP的值 
  127.      */ 
  128.     public String getIp(String key){ 
  129.         String tmpIp = ""
  130.         List<Entry> entrys = singleKvStore.getEntries(Constant.IP_PREFIX+key); 
  131.         if (entrys != null && entrys.size()>0) { 
  132.             tmpIp = entrys.get(0).getValue().getString(); 
  133.             HiLog.info(label,"獲取IP成功!"+tmpIp); 
  134.         } else { 
  135.             HiLog.info(label,"沒(méi)有獲取到IP!"); 
  136.         } 
  137.         return tmpIp; 
  138.     } 
  139.     /** 
  140.      * 獲取行駛記錄列表 
  141.      * @return 行駛記錄列表 
  142.      */ 
  143.     public List<DrivingRecord> getDrivingRecords(){ 
  144.         List<DrivingRecord> drivingReporList = new ArrayList<>(); 
  145.         List<Entry> entrys = singleKvStore.getEntries(Constant.DRIVING_REPORT_PREFIX); 
  146.         for(Entry entry:entrys){ 
  147.             String key = entry.getKey(); 
  148.             String value = entry.getValue().getString(); 
  149.             HiLog.info(label,"獲取到行駛記錄的數(shù)據(jù):key:" + key+",value:"+value); 
  150.             Gson gson = new Gson(); 
  151.             DrivingRecord drivingRecord = gson.fromJson(value, DrivingRecord.class); 
  152.             //HiLog.info(label,drivingRecord.getId()); 
  153.             drivingReporList.add(drivingRecord); 
  154.         } 
  155.         //排序 
  156.         if (drivingReporList.size() > 0) { 
  157.             DrivingReportComparator drivingReportComparator = new DrivingReportComparator(); 
  158.             drivingReporList.sort(drivingReportComparator); 
  159.         } 
  160.         return drivingReporList; 
  161.     } 
  162.     /** 
  163.      * 獲取行駛記錄軌跡列表 
  164.      * @param drivingId 行駛記錄標(biāo)識(shí) 
  165.      * @return  行駛記錄軌跡列表 
  166.      */ 
  167.     public List<DrivingMap> getDrivingMap(String drivingId){ 
  168.         String resultJson = singleKvStore.getString(Constant.DRIVING_MAP_PREFIX+drivingId); 
  169.         Gson gson = new Gson(); 
  170.  
  171.         return gson.fromJson(resultJson, new TypeToken<List<DrivingMap>>() {}.getType()); 
  172.     } 
  173.     /** 
  174.      * 獲取上報(bào)記錄列表 
  175.      * @param drivingId 行駛記錄標(biāo)識(shí) 
  176.      * @return 上報(bào)記錄列表 
  177.      */ 
  178.     public List<ReportRecord> getReportRecords(String drivingId){ 
  179.         List<Entry> entrys = singleKvStore.getEntries(Constant.REPORT_RECORD_PREFIX+drivingId); 
  180.         if (entrys == null || entrys.size() == 0){ 
  181.             HiLog.info(label,"獲取上報(bào)記錄為空!"); 
  182.             return null
  183.         } else { 
  184.             Gson gson = new Gson(); 
  185.             Entry entry = entrys.get(0); 
  186.             String resultJson = entry.getValue().getString(); 
  187.             List<ReportRecord> reportRecordLst = gson.fromJson(resultJson, new TypeToken<List<ReportRecord>>() {}.getType()); 
  188.             HiLog.info(label,"獲取上報(bào)記錄成功!"+reportRecordLst.size()); 
  189.  
  190.             if (reportRecordLst!=null && reportRecordLst.size() > 0) { 
  191.                 //排序 
  192.                 ReportRecordComparator reportRecordComparator = new ReportRecordComparator(); 
  193.                 reportRecordLst.sort(reportRecordComparator); 
  194.             } 
  195.             return reportRecordLst; 
  196.         } 
  197.     } 
  198.     /** 
  199.      * 同步數(shù)據(jù) 
  200.      */ 
  201.     public void syncData() { 
  202.         List<DeviceInfo> deviceInfoList = kvManager.getConnectedDevicesInfo(DeviceFilterStrategy.NO_FILTER); 
  203.         List<String> deviceIdList = new ArrayList<>(); 
  204.         String deviceId; 
  205.         for (DeviceInfo deviceInfo : deviceInfoList) { 
  206.             deviceId = deviceInfo.getId(); 
  207.             HiLog.info(label,"deviceId = " + deviceId); 
  208.             deviceIdList.add(deviceId); 
  209.         } 
  210.         HiLog.info(label,"deviceIdList.size() = " + deviceIdList.size()); 
  211.         if (deviceIdList.size() > 0) { 
  212.             singleKvStore.sync(deviceIdList, SyncMode.PUSH_ONLY); 
  213.         } else { 
  214.             HiLog.error(label,"沒(méi)有共享設(shè)備"); 
  215.         } 
  216.     } 
  217.     /** 
  218.      * 注冊(cè)回調(diào)接口 
  219.      * @param kvStoreObserver  kvStore對(duì)象 
  220.      */ 
  221.     public void registerCallback(KvStoreObserver kvStoreObserver) { 
  222.         singleKvStore.subscribe(SubscribeType.SUBSCRIBE_TYPE_ALL, kvStoreObserver); 
  223.     } 
  224.     /** 
  225.      * 清空數(shù)據(jù) 
  226.      */ 
  227.     public void clearAllData() { 
  228.         List<Entry> entrys = singleKvStore.getEntries(""); 
  229.         if (entrys!=null && entrys.size()>0){ 
  230.             for(Entry entry:entrys){ 
  231.                 singleKvStore.delete(entry.getKey()); 
  232.             } 
  233.             HiLog.info(label,"清空數(shù)據(jù)成功"); 
  234.         } else { 
  235.             HiLog.info(label,"沒(méi)有數(shù)據(jù)要清空"); 
  236.         } 
  237.     } 
  238.     /** 
  239.      * 從現(xiàn)有的行駛記錄中獲取drivingId 
  240.      * @return 返回行駛記錄標(biāo)識(shí) 
  241.      */ 
  242.     public String getDrivingId(){ 
  243.         String drivingId = ""
  244.         List<Entry> entrys = singleKvStore.getEntries(Constant.DRIVING_REPORT_PREFIX); 
  245.         if (entrys != null && entrys.size() > 0){ 
  246.             List<DrivingRecord> drivingReporList = new ArrayList<>(); 
  247.             for(Entry entry:entrys){ 
  248.                 String value = entry.getValue().getString(); 
  249.                 Gson gson = new Gson(); 
  250.                 DrivingRecord drivingRecord = gson.fromJson(value, DrivingRecord.class); 
  251.                 String dateStr = drivingRecord.getDrivingDate(); 
  252.                 if (StringUtils.isDiffHour(dateStr)){ 
  253.                     drivingReporList.add(drivingRecord); 
  254.                 } 
  255.                 HiLog.info(label,drivingRecord.getId()); 
  256.                 drivingReporList.add(drivingRecord); 
  257.             } 
  258.             if (drivingReporList.size() > 0) { 
  259.                 //排序 
  260.                 DrivingReportComparator drivingReportComparator = new DrivingReportComparator(); 
  261.                 drivingReporList.sort(drivingReportComparator); 
  262.  
  263.                 drivingId = drivingReporList.get(0).getId(); 
  264.                 HiLog.info(label,"找到符合條件的drivingId:"+drivingId); 
  265.             } else { 
  266.                 HiLog.info(label,"沒(méi)有找到符合條件的drivingId"); 
  267.             } 
  268.         } else { 
  269.             HiLog.info(label,"行駛記錄為空,沒(méi)有找到符合條件的drivingId"); 
  270.         } 
  271.  
  272.         return drivingId; 
  273.     } 

3、行駛記錄代碼

  1. import com.isoftstone.smartcar.app.ResourceTable; 
  2. import com.isoftstone.smartcar.app.model.DrivingRecord; 
  3. import com.isoftstone.smartcar.app.provider.DrivingRecordProvider; 
  4. import com.isoftstone.smartcar.app.service.SmartShareService; 
  5. import ohos.aafwk.ability.AbilitySlice; 
  6. import ohos.aafwk.content.Intent; 
  7. import ohos.aafwk.content.Operation; 
  8. import ohos.agp.components.Component; 
  9. import ohos.agp.components.Image; 
  10. import ohos.agp.components.ListContainer; 
  11. import java.util.List; 
  12. /** 
  13.  * 行駛記錄 
  14.  */ 
  15. public class DrivingRecordsAbilitySlice extends AbilitySlice implements Component.ClickedListener { 
  16.     private ListContainer lcRecords; 
  17.     private SmartShareService shareService; 
  18.     private List<DrivingRecord> drivingRecordList; 
  19.     private DrivingRecordProvider drivingRecordProvider; 
  20.     @Override 
  21.     public void onStart(Intent intent) { 
  22.         super.onStart(intent); 
  23.         super.setUIContent(ResourceTable.Layout_ability_driving_records); 
  24.         initUI(); 
  25.     } 
  26.     private void initUI() { 
  27.         shareService = SmartShareService.getInstance(this); 
  28.         shareService.init(); 
  29.         Image iBack = (Image) findComponentById(ResourceTable.Id_i_back); 
  30.         iBack.setClickedListener(this); 
  31.         lcRecords = (ListContainer) findComponentById(ResourceTable.Id_lc_records); 
  32.         drivingRecordList = getData(); 
  33.         drivingRecordProvider = new DrivingRecordProvider(drivingRecordList, this); 
  34.         lcRecords.setItemProvider(drivingRecordProvider); 
  35.         lcRecords.setItemClickedListener(new ListContainer.ItemClickedListener() { 
  36.             @Override 
  37.             public void onItemClicked(ListContainer listContainer, Component component, int i, long l) { 
  38.                 Intent intent = new Intent(); 
  39.                 DrivingRecord drivingRecord = (DrivingRecord) drivingRecordProvider.getItem(i); 
  40.                 intent.setParam("drivingId", drivingRecord.getId()); 
  41.                 intent.setParam("lat", drivingRecord.getLatitude()); 
  42.                 intent.setParam("lng", drivingRecord.getLongitude()); 
  43.                 Operation operation = new Intent.OperationBuilder() 
  44.                         .withDeviceId(""
  45.                         .withBundleName("com.isoftstone.smartcar.app"
  46.                         .withAbilityName("com.isoftstone.smartcar.app.DrivingRecordsDetailAbility"
  47.                         .build(); 
  48.                 intent.setOperation(operation); 
  49.                 startAbility(intent); 
  50.                 //terminate(); 
  51.             } 
  52.         }); 
  53.     } 
  54.     @Override 
  55.     public void onActive() { 
  56.         super.onActive(); 
  57.         drivingRecordList = getData(); 
  58.         drivingRecordProvider = new DrivingRecordProvider(drivingRecordList, this); 
  59.         lcRecords.setItemProvider(drivingRecordProvider); 
  60.     } 
  61.     @Override 
  62.     public void onForeground(Intent intent) { 
  63.         super.onForeground(intent); 
  64.     } 
  65.     @Override 
  66.     public void onClick(Component component) { 
  67.         if (component.getId() == ResourceTable.Id_i_back) { 
  68.             terminateAbility(); 
  69.         } 
  70.     } 
  71.     private List<DrivingRecord> getData() { 
  72.         return shareService.getDrivingRecords(); 
  73.     } 

4、行駛記錄詳情代碼

  1. import com.isoftstone.smartcar.app.ResourceTable; 
  2. import com.isoftstone.smartcar.app.model.DrivingMap; 
  3. import com.isoftstone.smartcar.app.model.ReportRecord; 
  4. import com.isoftstone.smartcar.app.provider.ReportRecordProvider; 
  5. import com.isoftstone.smartcar.app.service.SmartShareService; 
  6. import com.isoftstone.smartcar.app.utils.CoordinateConverter; 
  7. import com.isoftstone.smartcar.app.widget.carmap.LatLng; 
  8. import com.isoftstone.smartcar.app.widget.carmap.TinyMap; 
  9. import ohos.aafwk.ability.AbilitySlice; 
  10. import ohos.aafwk.content.Intent; 
  11. import ohos.agp.components.Component; 
  12. import ohos.agp.components.Image; 
  13. import ohos.agp.components.ListContainer; 
  14. import ohos.agp.utils.Point; 
  15. import ohos.hiviewdfx.HiLog; 
  16. import ohos.hiviewdfx.HiLogLabel; 
  17. import ohos.multimodalinput.event.KeyEvent; 
  18. import java.util.ArrayList; 
  19. import java.util.List; 
  20. import java.util.Timer; 
  21. import java.util.TimerTask; 
  22.  
  23. /** 
  24.  * 行駛記錄詳情 
  25.  */ 
  26. public class DrivingRecordsDetailAbilitySlice extends AbilitySlice implements Component.ClickedListener { 
  27.     private static final HiLogLabel logLabel = new HiLogLabel(HiLog.LOG_APP, 0x00100, "DrivingRecordsDetailAbilitySlice"); 
  28.  
  29.     private TinyMap map; 
  30.     private String drivingId; 
  31.     private SmartShareService shareService; 
  32.  
  33.     @Override 
  34.     protected void onStart(Intent intent) { 
  35.         super.onStart(intent); 
  36.         super.setUIContent(ResourceTable.Layout_ability_driving_records_detail); 
  37.         initUI(intent); 
  38.     } 
  39.  
  40.     private void initUI(Intent intent) { 
  41.         Image iBack = (Image) findComponentById(ResourceTable.Id_i_back); 
  42.         iBack.setClickedListener(this); 
  43.         map = (TinyMap) findComponentById(ResourceTable.Id_map); 
  44.         ListContainer reportListContainer = (ListContainer) findComponentById(ResourceTable.Id_report_records); 
  45.         drivingId = intent.getStringParam("drivingId"); 
  46.         shareService = SmartShareService.getInstance(this); 
  47.         shareService.init(); 
  48.  
  49.         new Timer().schedule(new TimerTask() { 
  50.             @Override 
  51.             public void run() { 
  52.                 getUITaskDispatcher().asyncDispatch(new Runnable() { 
  53.                     @Override 
  54.                     public void run() { 
  55.                         setMap(); 
  56.                     } 
  57.                 }); 
  58.             } 
  59.         },500); 
  60.  
  61.         List<ReportRecord> reportRecords = shareService.getReportRecords(drivingId); 
  62.         ReportRecordProvider reportRecordProvider = new ReportRecordProvider(reportRecords, this); 
  63.         reportListContainer.setItemProvider(reportRecordProvider); 
  64.     } 
  65.  
  66.     @Override 
  67.     public void onClick(Component component) { 
  68.         if (component.getId() == ResourceTable.Id_i_back) {//present(new DrivingRecordsAbilitySlice(), new Intent()); 
  69.             terminate(); 
  70.         } 
  71.     } 
  72.  
  73.     @Override 
  74.     public boolean onKeyUp(int keyCode, KeyEvent keyEvent) { 
  75.         HiLog.error(logLabel,keyEvent.getKeyCode()+""); 
  76.         if (keyCode==KeyEvent.KEY_BACK){ 
  77.             //present(new DrivingRecordsAbilitySlice(), new Intent()); 
  78.             terminate(); 
  79.             return true
  80.         } 
  81.         return super.onKeyDown(keyCode, keyEvent); 
  82.     } 
  83.  
  84.     private LatLng WGS84ToMercator(LatLng latLng) { 
  85.         return CoordinateConverter.WGS84ToMercator(latLng.getLng(), latLng.getLat()); 
  86.     } 
  87.  
  88.     private void setMap() { 
  89.         map.initMap(); 
  90.         List<DrivingMap> drivingMaps = shareService.getDrivingMap(drivingId); 
  91.  
  92.         LatLng startLatLng0 = new LatLng(Double.parseDouble(drivingMaps.get(0).getLatitude()), Double.parseDouble(drivingMaps.get(0).getLongitude())); 
  93.         LatLng startLatLng = new LatLng((float) WGS84ToMercator(startLatLng0).getLat(), (float) WGS84ToMercator(startLatLng0).getLng()); 
  94.         map.setCenterPoint((float) startLatLng.getLng(), (float) startLatLng.getLat()); 
  95.  
  96.         LatLng endLatLng0 = new LatLng(Double.parseDouble(drivingMaps.get(drivingMaps.size() - 1).getLatitude()), Double.parseDouble(drivingMaps.get(drivingMaps.size() - 1).getLongitude())); 
  97.         LatLng endLatLng = new LatLng((float) WGS84ToMercator(endLatLng0).getLat(), (float) WGS84ToMercator(endLatLng0).getLng()); 
  98.         map.setStartElement((float) startLatLng.getLng(), (float) startLatLng.getLat(), ResourceTable.Media_start_location); 
  99.         map.setEndElement((float) endLatLng.getLng(), (float) endLatLng.getLat(), ResourceTable.Media_end_location); 
  100.         List<LatLng> latLngs = new ArrayList<>(); 
  101.         for (DrivingMap drivingMap : drivingMaps) { 
  102.             LatLng latLng = new LatLng(Double.parseDouble(drivingMap.getLatitude()), Double.parseDouble(drivingMap.getLongitude())); 
  103.             Point p = new Point((float) WGS84ToMercator(latLng).getLng(), (float) WGS84ToMercator(latLng).getLat()); 
  104.             latLngs.add(new LatLng(p.getPointY(), p.getPointX())); 
  105.         } 
  106.         map.setPaths(latLngs); 
  107.     } 

想了解更多內(nèi)容,請(qǐng)?jiān)L問(wèn):

51CTO和華為官方合作共建的鴻蒙技術(shù)社區(qū)

https://harmonyos.51cto.com

 

責(zé)任編輯:jianghua 來(lái)源: 鴻蒙社區(qū)
相關(guān)推薦

2021-12-13 11:07:10

鴻蒙HarmonyOS應(yīng)用

2021-12-14 14:47:18

鴻蒙HarmonyOS應(yīng)用

2019-02-13 13:41:07

MemCache分布式HashMap

2020-11-20 09:45:19

HarmonyOS

2013-06-18 14:00:59

HDFS分布式文件系統(tǒng)

2012-07-20 14:40:22

2019-04-30 14:17:56

中關(guān)村零售業(yè)創(chuàng)業(yè)者

2024-07-26 08:45:54

2021-10-21 10:03:09

鴻蒙HarmonyOS應(yīng)用

2021-11-16 09:38:10

鴻蒙HarmonyOS應(yīng)用

2021-05-28 09:52:00

鴻蒙HarmonyOS應(yīng)用

2018-12-14 10:06:22

緩存分布式系統(tǒng)

2021-01-21 09:45:36

鴻蒙HarmonyOS分布式

2019-10-10 09:16:34

Zookeeper架構(gòu)分布式

2023-05-29 14:07:00

Zuul網(wǎng)關(guān)系統(tǒng)

2017-09-01 05:35:58

分布式計(jì)算存儲(chǔ)

2019-06-19 15:40:06

分布式鎖RedisJava

2021-07-22 10:20:21

鴻蒙HarmonyOS應(yīng)用

2011-04-01 14:28:58

zabbix應(yīng)用proxy

2020-11-19 11:43:26

HarmonyOS
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)