1 / 7

邊做邊學 Widgets

第三集 Widget 與 Mobile 6.5 的互動. 邊做邊學 Widgets. Blog: http://www.dotblogs.com.tw/bauann/ Email: bauann@gmail.com Forum: http://social.msdn.microsoft.com/Forums/zh-TW/803/threads. 議程. Widget.SystemState Demo 偵測電池狀態以及螢幕轉向偵測 我想將一些文字資訊儲存起來可以嗎 Demo 儲存簡單的文字資料 Menu 的使用 Demo Menu 的使用方式.

zubin
Télécharger la présentation

邊做邊學 Widgets

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第三集 Widget與Mobile 6.5的互動 邊做邊學Widgets • Blog: http://www.dotblogs.com.tw/bauann/ • Email: bauann@gmail.com • Forum: http://social.msdn.microsoft.com/Forums/zh-TW/803/threads

  2. 議程 • Widget.SystemState • Demo 偵測電池狀態以及螢幕轉向偵測 • 我想將一些文字資訊儲存起來可以嗎 • Demo 儲存簡單的文字資料 • Menu的使用 • Demo Menu的使用方式

  3. Widget.SystemState • CradlePresent 裝置是否連接到底座(USB連線)/ boolean • DisplayRotation 裝置螢幕的顯示方向(角度)/ int (0~360度) • PhoneHomeService / boolean 是否已在電信網路上註冊 • PhoneOperatorName 電信服務提供者的名稱 / string • PhoneRoaming 是否處於漫遊的狀態下 / boolean • PhoneSignalStrength 信號強度(電話)/ int (百分比) • PowerBatteryState 電池狀態,電池是否處於低電量 / int • PowerBatteryStrength 電池剩餘電量 / int (百分比)

  4. Demo SystemState • 取得資料 / 狀態 • systemState = widget.createObject("SystemState"); • alert(systemState.DisplayRotation); • 事件掛載 / 通知 • systemState = widget.createObject("SystemState"); • varDisplayRotation = systemState.DisplayRotation; • DisplayRotation.addEventListener("changed", functionName);

  5. Demo 儲存文字資料 • 儲存 / setPreferenceForKey • 讀取 / preferenceForKey • 資料存放在各自的隔離儲存區中,不同的widget應用程式不能夠交互存取 • 儲存的值會一直存在,直到下次改變 • 容量上限 4000 bytes (每個key值) • 以未編碼(加密)的方式儲存在裝置值中,不要儲存敏感性資料 • function Read() { alert(widget.preferenceForKey(“KeyName")); • } • function Save() { • widget.setPreferenceForKey( • “KeyValue”, “KeyName"); • }

  6. Menu物件 • widget.menu • createMenuItem(id) / 建立一個特定ID值得MenuItem項目 • append(item) / 增加一個MenuItem物件到”右邊”的Menu清單中 • clear() / 清除meun項目 • getMenuItemById(id) / 利用ID值取得MenuItem項目 • Remove(item) / 將某個項目從Menu清單中移除 • setSoftKey(item,id) / 指定menu對應到左/右鍵 • id:rightSoftKeyIndex / leftSoftKeyIndex • MenuItem • text/ 顯示在畫面上的文字 • onSelect / 按下時所引發的事件 • ex,newMenu.onSelect = function(itemid) { … }

  7. Demo Menu • function leftMenuClick() { • gMenu.clear(); • } • <script type="text/javascript"> • vargMenu = widget.menu; • varleftMenu = gMenu.createMenuItem(1001); • leftMenu.text = "Remove"; • leftMenu.onSelect = leftMenuClick; • gMenu.setSoftKey(leftMenu, gMenu.leftSoftKeyIndex); • </script>

More Related