PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/WazeWP7/FreeMapMainScreen.xaml.cs

http://github.com/meirtsvi/WazeWP7
C# | 1380 lines | 577 code | 177 blank | 626 comment | 89 complexity | 38a4375436916048279add4f18ec18c5 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. /* This class paints Waze to the screen, and take care of user keyboard and trackwheel input,
  2. * as well as the menus.
  3. *
  4. * Menus :
  5. * For the menus, we have both the main menu ( with all the options shown when
  6. * centered on car ) , the context menu - which has only the soft keys options, and
  7. * context specific options, and the miniMenu, which shows a menu in middle of the screen
  8. * to enable quick access to important actions like new address, me on map, etc.
  9. * Deciding which menu to show is done through priority - if there are miniMenu items available,
  10. * we show the miniMenu. Then we try the context menu, and only if no items exist in the
  11. * context menu as well, we open the full menu. This logic is in the overriden MakeMenu() method.
  12. *
  13. *
  14. * Keydown :
  15. * We get key presses and pass them on to rim_on_menu_button() in roadmap_main.c().
  16. * There are a few exceptions - The menu buttons requires additional processing before opening
  17. * the menu, so we call rim_on_menu_button() in roadmap_main.c. This needs to be done immediately,
  18. * so we call this function using Cibyl.Call instead of UIWorker thread. To prevent concurrency issues,
  19. * we do this call on a different thread, and allocate a differnt stack just for this, using
  20. * setStackAddress().
  21. * Also we don't handle all keys - Such as the send and end key buttons, to enable users to
  22. * make calls and go to the background.
  23. *
  24. *
  25. * Painting the screen : the Graphics object of this screen is given to roadmap_canvas.c,
  26. * and there is filled up with all the relevant drawing. ( lines, texts, etc. ).
  27. * the painting of the screen, ( through roadmap_canvas_refresh ), reaches the
  28. * paint() and refresh methods.
  29. *
  30. *
  31. */
  32. using System;
  33. using System.Collections.Generic;
  34. using System.Linq;
  35. using System.Net;
  36. using System.Windows;
  37. using System.Windows.Controls;
  38. using System.Windows.Documents;
  39. using System.Windows.Input;
  40. using System.Windows.Media;
  41. using System.Windows.Media.Animation;
  42. using System.Windows.Shapes;
  43. using Microsoft.Phone.Controls;
  44. using System.ComponentModel;
  45. using System.Text;
  46. using System.IO;
  47. using System.Collections;
  48. using System.Threading;
  49. using System.Windows.Media.Imaging;
  50. using Microsoft.Phone.Shell;
  51. using System.IO.IsolatedStorage;
  52. using Microsoft.Phone.Tasks;
  53. //using AppLimit.CloudComputing.SharpBox;
  54. //using AppLimit.CloudComputing.SharpBox.DropBox;
  55. using System.Windows.Resources;
  56. using SharpGIS;
  57. namespace WazeWP7
  58. {
  59. public partial class FreeMapMainScreen : WazeApplicationPage
  60. {
  61. private static FreeMapMainScreen m_this;
  62. //todomt private static Locale m_initial_locale;
  63. private BitmapImage m_bitmap;
  64. private List<object> m_menuItems = new List<object>();
  65. private List<object> m_contextMenuItems;
  66. private List<object> m_MiniMenuItems;
  67. private static int c_on_key_down;
  68. private static int c_on_menu_key_down;
  69. private static bool menu_open = false;
  70. private static int c_on_navigation_movement;
  71. private static int c_on_navigation_click;
  72. private static int c_key_down_value_addr;
  73. private static int c_on_orientation_change;
  74. private static int c_on_canvas_button_pressed;
  75. private static int c_on_canvas_button_released;
  76. private static int c_on_canvas_button_moved;
  77. //todomt private static Dialog waiting_dialog;
  78. private static int keyDownStackAddress = 0;
  79. private bool pushMiniMenu = false;
  80. private int isLandscapeScreen;
  81. private bool isUIWorkerInit = false;
  82. private static bool dummy = false;
  83. private PageOrientation m_CurrentOrientation;
  84. private bool m_isMenuVisible = false;
  85. private bool m_isPageActive = false;
  86. private Canvas m_mainGraphics = null;
  87. public FreeMapMainScreen()
  88. {
  89. InitializeComponent();
  90. m_this = this;
  91. PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
  92. Loaded += new RoutedEventHandler(Page_Loaded);
  93. }
  94. void BuildApplicationBar()
  95. {
  96. // Set the page's ApplicationBar to a new instance of ApplicationBar
  97. ApplicationBar = new ApplicationBar();
  98. // Hide the app bar by default:
  99. ApplicationBar.IsVisible = true;
  100. PopApplicationBar();
  101. ApplicationBar.StateChanged += new EventHandler<ApplicationBarStateChangedEventArgs>(ApplicationBar_StateChanged);
  102. }
  103. protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
  104. {
  105. // Start with calling the base implementation
  106. base.OnNavigatedTo(e);
  107. m_isPageActive = true;
  108. }
  109. protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
  110. {
  111. // Start with calling the base implementation
  112. base.OnNavigatedFrom(e);
  113. m_isPageActive = false;
  114. }
  115. // void CopySounds(object obj)
  116. // {
  117. // try
  118. // {
  119. // //Thread.Sleep(5000);
  120. // var store = IsolatedStorageFile.GetUserStoreForApplication();
  121. // if (!store.DirectoryExists("/sound") || !store.FileExists("/sound/heb/within.wav"))
  122. // {
  123. // List<string> file_list = new List<string>();
  124. ///* file_list.Add("200.mp3");
  125. // file_list.Add("800.mp3");
  126. // file_list.Add("200meters.mp3");
  127. // file_list.Add("800meters.mp3");
  128. // file_list.Add("alert_1.mp3");
  129. // file_list.Add("ApproachSpeedCam.mp3");
  130. // file_list.Add("Arrive.mp3");
  131. // file_list.Add("click.mp3");
  132. // file_list.Add("click_long.mp3");
  133. // file_list.Add("Exit.mp3");
  134. // file_list.Add("Fifth.mp3");
  135. // file_list.Add("First.mp3");
  136. // file_list.Add("Fourth.mp3");
  137. // file_list.Add("KeepLeft.mp3");
  138. // file_list.Add("KeepRight.mp3");
  139. // file_list.Add("m.mp3");
  140. // file_list.Add("Police.mp3");
  141. // file_list.Add("rec_end.mp3");
  142. // file_list.Add("rec_start.mp3");
  143. // file_list.Add("Roundabout.mp3");
  144. // file_list.Add("Second.mp3");
  145. // file_list.Add("Seventh.mp3");
  146. // file_list.Add("Sixth.mp3");
  147. // file_list.Add("Straight.mp3");
  148. // file_list.Add("Third.mp3");
  149. // file_list.Add("TickerPoints.mp3");
  150. // file_list.Add("TurnLeft.mp3");
  151. // file_list.Add("TurnRight.mp3");*/
  152. // file_list.Add("within.mp3");
  153. // file_list.Add("200.wav");
  154. // file_list.Add("800.wav");
  155. // file_list.Add("200meters.wav");
  156. // file_list.Add("800meters.wav");
  157. // file_list.Add("alert_1.wav");
  158. // file_list.Add("ApproachSpeedCam.wav");
  159. // file_list.Add("Arrive.wav");
  160. // file_list.Add("click.wav");
  161. // file_list.Add("click_long.wav");
  162. // file_list.Add("Exit.wav");
  163. // file_list.Add("Fifth.wav");
  164. // file_list.Add("First.wav");
  165. // file_list.Add("Fourth.wav");
  166. // file_list.Add("KeepLeft.wav");
  167. // file_list.Add("KeepRight.wav");
  168. // file_list.Add("m.wav");
  169. // file_list.Add("Police.wav");
  170. // file_list.Add("rec_end.wav");
  171. // file_list.Add("rec_start.wav");
  172. // file_list.Add("Roundabout.wav");
  173. // file_list.Add("Second.wav");
  174. // file_list.Add("Seventh.wav");
  175. // file_list.Add("Sixth.wav");
  176. // file_list.Add("Straight.wav");
  177. // file_list.Add("Third.wav");
  178. // file_list.Add("TickerPoints.wav");
  179. // file_list.Add("TurnLeft.wav");
  180. // file_list.Add("TurnRight.wav");
  181. // file_list.Add("within.wav");
  182. // store.CreateDirectory("/sound");
  183. // store.CreateDirectory("/sound/eng");
  184. // store.CreateDirectory("/sound/heb");
  185. // Syscalls.CopyFile("/WazeWP7;component/resources/prompt_list.txt", "prompt_list.txt");
  186. ///* return;
  187. // // not sure why waze is unable to d/l the file to userstore by itself so i'm copying the file from resources dir to userstore manually.
  188. // Stream input = Syscalls.GetFileStream("/WazeWP7;component/resources/prompt_list.txt", FileMode.Open);
  189. // Stream output = new IsolatedStorageFileStream("prompt_list.txt", FileMode.CreateNew, FileAccess.Write, store);
  190. // byte[] file_buffer = new byte[input.Length];
  191. // input.Read(file_buffer, 0, file_buffer.Length);
  192. // output.Write(file_buffer, 0, file_buffer.Length);
  193. // input.Close();
  194. // output.Close();*/
  195. // foreach (string file in file_list)
  196. // {
  197. // Syscalls.CopyFile("/WazeWP7;component/resources/sound/eng/" + file, "/sound/eng/" + file);
  198. // Syscalls.CopyFile("/WazeWP7;component/resources/sound/heb/" + file, "/sound/heb/" + file);
  199. ///* try
  200. // {
  201. // Stream source = App.GetResourceStream(new Uri("/WazeWP7;component/resources/sound/eng/" + file, UriKind.Relative)).Stream;
  202. // Stream target = new IsolatedStorageFileStream("/sound/eng/" + file, FileMode.CreateNew, FileAccess.Write, store);
  203. // byte[] buffer = new byte[source.Length];
  204. // source.Read(buffer, 0, buffer.Length);
  205. // target.Write(buffer, 0, buffer.Length);
  206. // source.Close();
  207. // target.Close();
  208. // source = App.GetResourceStream(new Uri("/WazeWP7;component/resources/sound/heb/" + file, UriKind.Relative)).Stream;
  209. // target = new IsolatedStorageFileStream("/sound/heb/" + file, FileMode.CreateNew, FileAccess.Write, store);
  210. // buffer = new byte[source.Length];
  211. // source.Read(buffer, 0, buffer.Length);
  212. // target.Write(buffer, 0, buffer.Length);
  213. // source.Close();
  214. // target.Close();
  215. // }
  216. // catch (Exception)
  217. // {
  218. // // best effort
  219. // }*/
  220. // }
  221. // }
  222. // }
  223. // catch (Exception)
  224. // {
  225. // // do nothing
  226. // }
  227. // }
  228. void CopySounds()
  229. {
  230. try
  231. {
  232. var store = IsolatedStorageFile.GetUserStoreForApplication();
  233. if (!store.DirectoryExists("/sound"))
  234. {
  235. store.CreateDirectory("/sound");
  236. store.CreateDirectory("/sound/eng");
  237. store.CreateDirectory("/sound/heb");
  238. Syscalls.CopyFile("/WazeWP7;component/resources/prompt_list.txt", "prompt_list.txt");
  239. }
  240. }
  241. catch (Exception)
  242. {
  243. // do nothing
  244. }
  245. }
  246. static FreemapApp app;
  247. void Page_Loaded(object sender, RoutedEventArgs e)
  248. {
  249. if (m_mainGraphics == null)
  250. {
  251. m_mainGraphics = new Canvas();
  252. LayoutRoot.Children.Add(m_mainGraphics);
  253. BuildApplicationBar();
  254. //isLandscapeScreen = 0; //todomt getVisibleWidth()> getVisibleHeight() ? 1 : 0;
  255. isLandscapeScreen = 1; //todomt getVisibleWidth()> getVisibleHeight() ? 1 : 0;
  256. this.
  257. CopySounds();
  258. app = new FreemapApp();
  259. try
  260. {
  261. app.Main(null);
  262. }
  263. catch (Exception ex)
  264. {
  265. MessageBox.Show("error in init " + ex);
  266. }
  267. }
  268. }
  269. /// <summary>
  270. /// Check if phone is currently reported to be landscape.
  271. /// </summary>
  272. /// <returns></returns>
  273. public bool IsPhoneLandscape()
  274. {
  275. return (m_CurrentOrientation & PageOrientation.Landscape) == PageOrientation.Landscape;
  276. }
  277. private static int _deviceHight = 800;
  278. private static int _deviceWidth = 480;
  279. /// <summary>
  280. /// Get the drawing Width according to the phone's position
  281. /// </summary>
  282. /// <returns></returns>
  283. public int getVisibleWidth()
  284. {
  285. if (IsPhoneLandscape())
  286. {
  287. isLandscapeScreen = 1;
  288. return _deviceHight;
  289. }
  290. else
  291. {
  292. isLandscapeScreen = 0;
  293. return _deviceWidth;
  294. }
  295. }
  296. /// <summary>
  297. /// Get the drawing Hight according to the phone's position
  298. /// </summary>
  299. /// <returns></returns>
  300. public int getVisibleHeight()
  301. {
  302. if (IsPhoneLandscape())
  303. {
  304. isLandscapeScreen = 1;
  305. return _deviceWidth;
  306. }
  307. else
  308. {
  309. isLandscapeScreen = 0;
  310. return _deviceHight;
  311. }
  312. }
  313. public static FreeMapMainScreen get() { return m_this; }
  314. public static void setKeyDownAddr(int addr) { c_key_down_value_addr = addr; }
  315. public void revertToInitialLocale()
  316. {
  317. //todomt Locale.setDefaultInput(m_initial_locale);
  318. }
  319. public void openBrowser(String url)
  320. {
  321. /* todomt
  322. ThreadStart starter = delegate
  323. {
  324. BrowserSession browserSession = Browser.getDefaultSession();
  325. browserSession.displayPage(url); //or your intranet site
  326. };
  327. new Thread(starter).Start();
  328. */
  329. }
  330. protected void paint(Canvas graphics)
  331. {
  332. /* todomt2
  333. if (m_bitmap != null)
  334. graphics.DrawImage(m_bitmap, 0, 0, getVisibleWidth(), getVisibleHeight());
  335. */
  336. }
  337. /// <summary>
  338. /// Refresh the graphics.
  339. /// Repaint the screen using the update graphic element list.
  340. /// This is heavy as eache change in the MainGraphics children wil trigger dependencies code.
  341. /// </summary>
  342. /// <param name="list"></param>
  343. public void refresh(Canvas newGraphics)
  344. {
  345. if (!m_isPageActive)
  346. {
  347. return;
  348. }
  349. Dispatcher.BeginInvoke(() =>
  350. {
  351. this.LayoutRoot.Children.Remove(m_mainGraphics);
  352. newGraphics.IsHitTestVisible = false;
  353. m_mainGraphics = newGraphics;
  354. this.LayoutRoot.Children.Add(m_mainGraphics);
  355. });
  356. }
  357. public void removeMenuItemByLabel(String text)
  358. {
  359. for (int i = 0; i < m_menuItems.Count; i++)
  360. {
  361. WazeMenuItem m = (WazeMenuItem)m_menuItems[i];
  362. if (text.CompareTo(m.ToString()) == 0)
  363. {
  364. m_menuItems.RemoveAt(i);
  365. }
  366. }
  367. }
  368. //private static bool perf_button_added = false;
  369. public static WazeMenuItem MeOnMapItem = null;
  370. private static ManualResetEvent graphic_sync = new ManualResetEvent(false);
  371. private void addIconMenuItem (string iconResouce, string text, WazeMenuItem wazeMenuItem)
  372. {
  373. ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri(iconResouce, UriKind.Relative));
  374. appBarButton.Text = text;
  375. appBarButton.Click += delegate
  376. {
  377. wazeMenuItem.CallCallback();
  378. // Hide bar after asking to show me
  379. ApplicationBar.IsVisible = false;
  380. };
  381. System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
  382. {
  383. ApplicationBar.Buttons.Add(appBarButton);
  384. });
  385. }
  386. public void addMenuItem(String text, int ordinal, int priority, int wrapper_callback, int callback, int push_at_start)
  387. {
  388. for (int i = 0; i < m_menuItems.Count; i++)
  389. {
  390. WazeMenuItem m = (WazeMenuItem)m_menuItems[i];
  391. if (text.CompareTo(m.ToString()) == 0)
  392. {
  393. return; // item already exists, don't add.
  394. }
  395. }
  396. WazeMenuItem new_item = new WazeMenuItem(text, ordinal, priority, wrapper_callback, callback);
  397. if (push_at_start == 1)
  398. {
  399. m_menuItems.Insert(0, new_item);
  400. }
  401. else
  402. {
  403. m_menuItems.Add(new_item);
  404. }
  405. bool addMenuItem = true;
  406. if (text.ToLower().Equals("me on map") || text.Equals("הצג אותי"))
  407. {
  408. MeOnMapItem = new_item;
  409. addIconMenuItem("Resources/compas.png", text, MeOnMapItem);
  410. addMenuItem = false;
  411. }
  412. else if (text.ToLower().Equals("drive to") || text.Equals("נווט"))
  413. {
  414. addIconMenuItem("Resources/search.png", text, new_item);
  415. addMenuItem = false;
  416. }
  417. else if (text.ToLower().Equals("report") || text.Equals("דווח"))
  418. {
  419. addIconMenuItem("Resources/i.png", text, new_item);
  420. addMenuItem = false;
  421. }
  422. else if (text.ToLower().Equals("my favorites") || text.Equals("המועדפים שלי"))
  423. {
  424. addIconMenuItem("Resources/favorites.png", text, new_item);
  425. addMenuItem = false;
  426. }
  427. /*
  428. if (!perf_button_added)
  429. {
  430. perf_button_added = true;
  431. System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
  432. {
  433. ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem("Save perf data");
  434. appBarMenuItem.Click += EmailLogFile;
  435. ApplicationBar.MenuItems.Add(appBarMenuItem);
  436. });
  437. System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
  438. {
  439. ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem("Clear perf data");
  440. appBarMenuItem.Click += delegate { Syscalls.fis.Clear(); };
  441. ApplicationBar.MenuItems.Add(appBarMenuItem);
  442. });
  443. }
  444. */
  445. /*
  446. if (!isSendMailAdded)
  447. {
  448. isSendMailAdded = true;
  449. System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
  450. {
  451. ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem("Email log file");
  452. appBarMenuItem.Click += EmailLogFile;
  453. ApplicationBar.MenuItems.Add(appBarMenuItem);
  454. });
  455. }*/
  456. if (addMenuItem)
  457. {
  458. System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
  459. {
  460. // Create a new menu item with the localized string from AppResources
  461. ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(text);
  462. if (text.ToLower().Equals("about") || text.Equals("אודות"))
  463. {
  464. appBarMenuItem.Click += delegate
  465. {
  466. string name = System.Reflection.Assembly.GetExecutingAssembly().FullName;
  467. System.Reflection.AssemblyName asmName = new System.Reflection.AssemblyName(name);
  468. //System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
  469. Version version = asmName.Version;
  470. String s = String.Format("{0}.{1}.{2}.{3}",
  471. version.Major,
  472. version.Minor,
  473. version.Build,
  474. version.Revision);
  475. AboutDialog ad = new AboutDialog();
  476. ad.SetVersion(s);
  477. FreeMapMainScreen.get().GetPopupPanel().Children.Add(ad);
  478. // Hide bar after asking to show me
  479. ApplicationBar.IsVisible = false;
  480. };
  481. ApplicationBar.MenuItems.Add(appBarMenuItem);
  482. appBarMenuItem = new ApplicationBarMenuItem("טען מפה");
  483. appBarMenuItem.Click += delegate
  484. {
  485. /* TileStorage ts = (TileStorage)CRunTime.objectRepository[Syscalls.ts_id];
  486. UnZipper uz = new UnZipper(Application.GetResourceStream(new Uri("/WazeWP7;component/resources/tiles.zip", UriKind.Relative)).Stream);
  487. int index = 0;
  488. foreach (string filename in uz.FileNamesInZip)
  489. {
  490. int tile_index = int.Parse(filename);
  491. Stream st = uz.GetFileStream(filename);
  492. BinaryReader br = new BinaryReader(st);
  493. byte[] tile_bytes = new byte[st.Length];
  494. br.Read(tile_bytes, 0, tile_bytes.Length);
  495. ts.storeTileEx(77001, tile_index, tile_bytes);
  496. index++;
  497. }*/
  498. UnZipper uz = new UnZipper(Application.GetResourceStream(new Uri("/WazeWP7;component/resources/tel_aviv_till_hod_hasharon.zip", UriKind.Relative)).Stream);
  499. foreach (string filename in uz.FileNamesInZip)
  500. {
  501. Stream st = uz.GetFileStream(filename);
  502. Syscalls.CopyFileFromStream(st, filename);
  503. }
  504. Syscalls.NOPH_TileStorage_initialize(Syscalls.ts_id);
  505. /*
  506. StreamResourceInfo info = Application.GetResourceStream(new Uri("/WazeWP7;component/resources/tiles/file_list.txt", UriKind.Relative));
  507. using (StreamReader reader = new StreamReader(info.Stream))
  508. {
  509. string line = reader.ReadLine();
  510. while (line != null)
  511. {
  512. int tile_index = int.Parse(line);
  513. Stream tile = Application.GetResourceStream(new Uri("/WazeWP7;component/resources/tiles/" + line, UriKind.Relative)).Stream;
  514. BinaryReader br = new BinaryReader(tile);
  515. byte[] tile_bytes = new byte[tile.Length];
  516. br.Read(tile_bytes, 0, tile_bytes.Length);
  517. ts.storeTileEx(77001, tile_index, tile_bytes);
  518. line = reader.ReadLine();
  519. }
  520. }*/
  521. // Hide bar after asking to show me
  522. ApplicationBar.IsVisible = false;
  523. MessageBox.Show("Finished");
  524. };
  525. }
  526. else
  527. {
  528. appBarMenuItem.Click += (delegate
  529. {
  530. new_item.CallCallback();
  531. // Hide bar after asking to show me
  532. ApplicationBar.IsVisible = false;
  533. });
  534. }
  535. ApplicationBar.MenuItems.Add(appBarMenuItem);
  536. });
  537. }
  538. }
  539. /*
  540. private static bool isSendMailAdded = false;
  541. private CloudStorage _storage;
  542. private void EmailLogFile(object sender, EventArgs e)
  543. {
  544. _storage = new CloudStorage();
  545. // instanciate a new credentials object, e.g. for dropbox
  546. DropBoxCredentials credentials = new AppLimit.CloudComputing.SharpBox.DropBox.DropBoxCredentials();
  547. // attach the application information
  548. credentials.ConsumerKey = "jpjmdvm8lrm9529";
  549. credentials.ConsumerSecret = "zxjv2r5s4796t6e";
  550. // add the account information
  551. credentials.UserName = "meir.tsvi@live.com";
  552. credentials.Password = "maverick";
  553. // instanciate a cloud storage configuration, e.g. for dropbox
  554. DropBoxConfiguration configuration = DropBoxConfiguration.GetStandardConfiguration();
  555. // instanciate the cloudstorage manager
  556. CloudStorage storage = new CloudStorage();
  557. _storage.BeginOpenRequest(OpenAsyncCallback, DropBoxConfiguration.GetStandardConfiguration(), credentials);
  558. }
  559. private void OpenAsyncCallback(IAsyncResult ar)
  560. {
  561. // this callback is part of the work thread form the pool
  562. // we have to invoke the ui calls in the ui thread
  563. // end the assync call and take the token
  564. ICloudStorageAccessToken token = _storage.EndOpenRequest(ar);
  565. // get the root, that works why we are in the worker thread
  566. ICloudDirectoryEntry root = _storage.GetRoot();
  567. if (root == null)
  568. {
  569. Console.WriteLine("No root object found");
  570. }
  571. else
  572. {
  573. // create the file
  574. ICloudFileSystemEntry file = _storage.CreateFile(root, DateTime.Now.ToFileTime()+ ".csv");
  575. // upload the data
  576. Stream data = file.GetContentStream(FileAccess.Write);
  577. int sz = Syscalls.fis.Count;
  578. for (int i=0; i<sz; i++)
  579. {
  580. function_info fi = Syscalls.fis[i];
  581. byte[] buffer = Syscalls.StringToAscii(fi.name + "," + fi.start + "," + fi.finish+ "\r\n");
  582. data.Write(buffer, 0, buffer.Length);
  583. }
  584. // close the stream
  585. data.Close();
  586. }
  587. // close the cloud storage connection
  588. if (_storage.IsOpened)
  589. {
  590. _storage.Close();
  591. }
  592. }
  593. */
  594. public void setLocale(String text)
  595. {
  596. //todomt if (text.Length > 0)
  597. //todomt Locale.setDefaultInput(Locale.get(text));
  598. //todomt else
  599. //todomt Locale.setDefaultInput(Locale.getDefault());
  600. }
  601. public void addMenuItemSeparator(int ordinal)
  602. {
  603. m_menuItems.Add(WazeMenuItem.separator(ordinal));
  604. }
  605. /*todomt
  606. protected void onMenuDismissed(Menu menu)
  607. {
  608. menu_open = false;
  609. for (int i = 0; i < m_contextMenuItems.Count; ++i)
  610. {
  611. m_MiniMenuItems[i] = null;
  612. }
  613. }*/
  614. /*
  615. public void fillMenuOptions(WazeMenu menu, int instance)
  616. {
  617. bool haveContext = false;
  618. bool hasMiniMenu = false;
  619. if ((instance == Menu.INSTANCE_CONTEXT) || (pushMiniMenu))
  620. {
  621. for (int i = 0; i < m_MiniMenuItems.Count; ++i)
  622. {
  623. WazeMenuItem item = (WazeMenuItem)m_MiniMenuItems[i];
  624. if (item != null)
  625. {
  626. menu.Add(item);
  627. hasMiniMenu = true;
  628. }
  629. }
  630. }
  631. if (!hasMiniMenu)
  632. {
  633. for (int i = 0; i < m_contextMenuItems.Count; ++i)
  634. {
  635. MenuItem item = (MenuItem)m_contextMenuItems[i];
  636. if (item != null)
  637. {
  638. menu.add(item);
  639. haveContext = true;
  640. }
  641. }
  642. }
  643. if (((!haveContext) && (!hasMiniMenu)))
  644. {
  645. for (int i = 0; i < m_menuItems.Count; ++i)
  646. {
  647. menu.add((MenuItem)m_menuItems[i]);
  648. }
  649. }
  650. }
  651. protected void makeMenu(Menu menu, int instance)
  652. {
  653. if (instance == Menu.INSTANCE_CONTEXT_SELECTION)
  654. {
  655. return;
  656. }
  657. if (instance == Menu.INSTANCE_DEFAULT)
  658. {
  659. //Menu items to show only in full menu
  660. }
  661. if (instance == Menu.INSTANCE_CONTEXT)
  662. {
  663. //Menu items to show only in short menu
  664. }
  665. if (instance == Menu.INSTANCE_DEFAULT || instance == Menu.INSTANCE_CONTEXT)
  666. {
  667. fillMenuOptions(menu, instance);
  668. }
  669. pushMiniMenu = false; // reset the variable to false.
  670. if (instance != Menu.INSTANCE_CONTEXT)
  671. super.makeMenu(menu, instance);
  672. }
  673. static public void updateUTF8Key(int keycode)
  674. {
  675. char c = Keypad.map(keycode);
  676. updateUTF8Key(c);
  677. }
  678. static public void updateUTF8Key(char c)
  679. {
  680. if (c_key_down_value_addr == 0) return;
  681. String s = String.valueOf(c);
  682. try {
  683. byte[] b = s.getBytes("UTF-8");
  684. CRunTime.memcpy(c_key_down_value_addr, b, 0, b.length);
  685. CRunTime.memoryWriteByte(c_key_down_value_addr + b.length, 0);
  686. } catch (Exception e) {
  687. CRunTime.memoryWriteByte(c_key_down_value_addr, 0);
  688. e.printStackTrace();
  689. }
  690. }
  691. */
  692. protected bool keyDown(Key keycode, int time)
  693. {
  694. Console.WriteLine("***** keyDown *****");
  695. Console.WriteLine("keycode=" + keycode);
  696. if (keyDownStackAddress == 0)
  697. {
  698. Logger.log("keyDownStackAddress = 0, before stack init ");
  699. return true;
  700. }
  701. if (keycode == Key.Escape)
  702. {
  703. Console.WriteLine("***** MENU BUTTON PRESSED *****");
  704. menu_open = true;
  705. try
  706. {
  707. if (c_on_menu_key_down == 0)
  708. {
  709. c_on_menu_key_down = CibylCallTable.getAddressByName("rim_on_menu_button");
  710. }
  711. if (c_on_menu_key_down != 0)
  712. {
  713. CibylCallTable.fcall(c_on_menu_key_down, keyDownStackAddress, (int)keycode, 0, time, 0);
  714. //CibylCallTable.fcall(c_on_menu_key_down, keyDownStackAddress, (int)keycode, 0, time, 0);
  715. }
  716. }
  717. catch (Exception t)
  718. {
  719. Logger.log("Exception in UI action: " + t);
  720. }
  721. return false; // return false so RIM will open the menu as necessary.
  722. }
  723. else if (keycode == Key.Subtract)
  724. {
  725. SoundMgr.updateSoundLevel(-10);
  726. }
  727. else if (keycode == Key.Add)
  728. {
  729. SoundMgr.updateSoundLevel(10);
  730. }
  731. else if (keycode == Key.Enter)
  732. {
  733. if (c_on_key_down == 0)
  734. c_on_key_down = CibylCallTable.getAddressByName("rim_on_key_down");
  735. UIWorker.addUIEvent(c_on_key_down, 0x0000000a, 0, time, 0, true);
  736. //UIWorker.addUIEvent(c_on_key_down, 0x0000000a, status, time, 0, true);
  737. }
  738. else if (keycode == Key.Left)
  739. {
  740. if (c_on_key_down == 0)
  741. c_on_key_down = CibylCallTable.getAddressByName("rim_on_key_down");
  742. UIWorker.addUIEvent(c_on_key_down, 27, 0, time, 0, true);
  743. }
  744. else
  745. {
  746. try
  747. {
  748. if (c_on_key_down == 0)
  749. c_on_key_down = CibylCallTable.getAddressByName("rim_on_key_down");
  750. }
  751. catch (Exception t)
  752. {
  753. Logger.log("Exception in keyDown: " + t);
  754. throw; //todomt
  755. //Environment.Exit(0);
  756. }
  757. if (c_on_key_down != 0)
  758. {
  759. UIWorker.addUIEvent(c_on_key_down, (int)keycode, 0, time, 0, true);
  760. //UIWorker.addUIEvent(c_on_key_down, (int)keycode, todomt status, time, 0, true);
  761. }
  762. }
  763. return true;
  764. }
  765. /*
  766. protected bool keyControl(char c, int status, int time){
  767. if (c == Characters.CONTROL_VOLUME_UP){
  768. SoundMgr.updateSoundLevel(+10);
  769. return true;
  770. } else if (c == Characters.CONTROL_VOLUME_DOWN){
  771. SoundMgr.updateSoundLevel(-10);
  772. return true;
  773. }
  774. return super.keyControl(c, status, time);
  775. }
  776. protected bool navigationClick( int status, int time)
  777. {
  778. Console.WriteLine("***** navigationClick *****");
  779. Console.WriteLine("status=" + Integer.toHexString(status));
  780. if ((status & (KeypadListener.STATUS_FOUR_WAY|KeypadListener.STATUS_TRACKWHEEL))== 0) {
  781. if (status!= 0)
  782. Logger.log("navClick ignored status "+ Integer.toHexString(status));
  783. return true;
  784. }
  785. bool used = false;
  786. try
  787. {
  788. if (c_on_navigation_click == 0)
  789. c_on_navigation_click = CibylCallTable.getAddressByName("rim_on_navigation_click");
  790. } catch (Exception t) {
  791. Logger.log("Exception in navigationClick: " + t);
  792. Environment.Exit(0);
  793. }
  794. if (c_on_navigation_click != 0)
  795. {
  796. UIWorker.addUIEvent(c_on_navigation_click, status, time, 0, 0, true);
  797. }
  798. return true;
  799. }
  800. */
  801. protected bool navigationMovement(int dx, int dy, int status, int time)
  802. {
  803. // Console.WriteLine("***** navigationMovement *****");
  804. // Console.WriteLine("dx=" + dx + " dy=" + dy + " status=" + Integer.toHexString(status));
  805. //m_graphics.copyArea(0, 0, getVisibleWidth(), getVisibleHeight(), dx * 30, dy * 30);
  806. //refresh();
  807. try
  808. {
  809. if (c_on_navigation_movement == 0)
  810. c_on_navigation_movement = CibylCallTable.getAddressByName("rim_on_navigation_movement");
  811. }
  812. catch (Exception t)
  813. {
  814. Logger.log("Exception in navigationMovement: " + t);
  815. throw; //todomt
  816. //Environment.Exit(0);
  817. }
  818. if (c_on_navigation_movement != 0)
  819. {
  820. UIWorker.addUIEvent(c_on_navigation_movement, dx, dy, status, time, true, true);
  821. }
  822. // Console.WriteLine("used=" + used);
  823. return true;
  824. }
  825. /* todomt
  826. public static void popUpYesNoDialog( int textAddr, String yesButtonStr, String noButtonStr, int yesCallback, int noCallback, int blocking){
  827. String sText = CRunTime.charPtrToString(textAddr, 8000);
  828. UiApplication.getUiApplication().invokeAndWait(new Runnable()
  829. {
  830. public void run()
  831. {
  832. Dialog d = new Dialog(sText,
  833. new String[]{noButtonStr,yesButtonStr},
  834. new int[]{Dialog.NO,Dialog.YES},
  835. Dialog.YES,
  836. new Bitmap(0,0));
  837. if(blocking==0){
  838. //None blocking option
  839. d.setDialogClosedListener(new DialogClosedListener(){
  840. public void dialogClosed(Dialog d,int dialogReturnValue){
  841. if (dialogReturnValue == Dialog.NO){
  842. try{
  843. UIWorker.addUIEvent(noCallback, 0, 0, 0, 0, true);
  844. }catch(Exception t){
  845. UIWorker.addUIEventLog("Exception while calling noCallback in FreemapMainScreen.java -> popUpYesNoDialog" + t);
  846. }
  847. }
  848. if (dialogReturnValue == Dialog.YES){ ;
  849. try{
  850. UIWorker.addUIEvent(yesCallback, 0, 0, 0, 0, true);
  851. }catch(Exception t){
  852. UIWorker.addUIEventLog("Exception while calling yesCallback in FreemapMainScreen.java -> popUpYesNoDialog" + t);
  853. }
  854. }
  855. }
  856. });
  857. d.show();
  858. }else if(blocking ==1){
  859. int index_chosen;
  860. index_chosen = d.doModal();
  861. if(index_chosen == Dialog.YES ){
  862. try{
  863. UIWorker.addUIEvent(yesCallback, 0, 0, 0, 0, true);
  864. }catch(Exception t){
  865. UIWorker.addUIEventLog("Exception while calling yesCallback in FreemapMainScreen.java -> popUpYesNoDialog" + t);
  866. }
  867. }
  868. else if ( index_chosen == Dialog.NO ){
  869. try{
  870. UIWorker.addUIEvent(noCallback, 0, 0, 0, 0, true);
  871. }catch(Exception t){
  872. UIWorker.addUIEventLog("Exception while calling noCallback in FreemapMainScreen.java -> popUpYesNoDialog" + t);
  873. }
  874. }
  875. }else{
  876. UIWorker.addUIEventLog("ERROR - input parameter blocking in popUpYesNoDialog is not valid.");
  877. }
  878. }
  879. });
  880. }
  881. */
  882. public static void setStackAddress(int addr)
  883. {
  884. keyDownStackAddress = addr;
  885. }
  886. /*todomt
  887. // Screen interface
  888. protected void sublayout(int w, int h)
  889. {
  890. checkOrientationChanged(w, h);
  891. super.sublayout(w, h);
  892. }
  893. */
  894. /*todomt
  895. protected bool touchEvent(TouchEvent te) {
  896. Console.WriteLine("touchEvent type "+Integer.toString(te.getEvent()));
  897. if(te.getEvent()==TouchEvent.CANCEL)
  898. return true;
  899. int x = te.getX(1);
  900. int y = te.getY(1);
  901. if(x<0|| x>this.getWidth()|| y<0|| y>this.getHeight()) {
  902. Logger.log("touchedEvent type " + Integer.toString(te.getEvent()) + " x=" + Integer.toString(x)+ " y=" + Integer.toString(x)+
  903. " outside "+Integer.toString(getWidth()) + "x" + Integer.toString(getHeight()));
  904. return super.touchEvent(te);
  905. }
  906. switch (te.getEvent()) {
  907. case TouchEvent.DOWN:
  908. touchDownEvent(x,y);
  909. break;
  910. case TouchEvent.UP:
  911. touchUpEvent(x,y);
  912. break;
  913. case TouchEvent.MOVE:
  914. touchMovedEvent(x,y);
  915. break;
  916. default:
  917. return super.touchEvent(te);
  918. }
  919. return true;
  920. }
  921. */
  922. private void checkOrientationChanged(int w, int h)
  923. {
  924. //calculate current orientation based on width and height
  925. // Commented out, we use the size methods to calculate our size.
  926. //int isLandscape = w > h ? 1 : 0;
  927. //if (isLandscape == isLandscapeScreen)
  928. //{
  929. // return;
  930. //}
  931. int isLandscape = isLandscapeScreen;
  932. if (!isUIWorkerInit)
  933. {
  934. // verify that UIWorker is initialized
  935. isUIWorkerInit = UIWorker.isInit();
  936. if (!isUIWorkerInit)
  937. return;
  938. }
  939. //isLandscapeScreen = isLandscape;
  940. try
  941. {
  942. if (c_on_orientation_change == 0)
  943. c_on_orientation_change = CibylCallTable.getAddressByName("rim_on_orientation_change");
  944. }
  945. catch (Exception t)
  946. {
  947. Logger.log("Exception in checkOrientationChanged: " + t);
  948. throw; //todomt
  949. //Environment.Exit(0);
  950. }
  951. if (c_on_orientation_change != 0)
  952. {
  953. UIWorker.addUIEvent(c_on_orientation_change, isLandscape, 0, 0, 0, true);
  954. }
  955. }
  956. private void touchDownEvent(int x, int y)
  957. {
  958. // If listbox is in progress, ignore map touch
  959. if (Syscalls.MiniMenuIsOn)
  960. {
  961. return;
  962. }
  963. // Backdoor: Pressing on the GPS icon area will start emulating GPS on the device
  964. if (x < 50 && y < 50)
  965. {
  966. // Auto hide on timeout.
  967. Thread threadDispatchMessage = new Thread(new ThreadStart(
  968. delegate()
  969. {
  970. GpsManager.getInstance().SwitchGPSEmulation();
  971. if (GpsManager.getInstance().GPSEmulationIsOn)
  972. {
  973. MessageBoxFactory.messageBoxTimed("GPS", "אמולצית GPS הופעלה", "OK", 5);
  974. }
  975. else
  976. {
  977. MessageBoxFactory.messageBoxTimed("GPS", "אמולצית GPS כובתה", "OK", 5);
  978. }
  979. }));
  980. threadDispatchMessage.Start();
  981. }
  982. int appBarArea = 0;
  983. //if (IsPhoneLandscape())
  984. //{
  985. // appBarArea = getVisibleWidth() - x;
  986. //}
  987. //else
  988. //{
  989. appBarArea = getVisibleHeight() - y;
  990. //}
  991. // Handle appbar visibility
  992. if (appBarArea < 60)
  993. {
  994. PopApplicationBar();
  995. }
  996. try
  997. {
  998. if (c_on_canvas_button_pressed == 0)
  999. c_on_canvas_button_pressed = CibylCallTable.getAddressByName("rim_on_canvas_button_pressed");
  1000. }
  1001. catch (Exception t)
  1002. {
  1003. Logger.log("Exception in touchDownEvent: " + t);
  1004. throw; //todomt
  1005. //Environment.Exit(0);
  1006. }
  1007. if (c_on_canvas_button_pressed != 0)
  1008. {
  1009. UIWorker.addUIEvent(c_on_canvas_button_pressed, x, y, 0, 0, true);
  1010. }
  1011. }
  1012. private void PopApplicationBar()
  1013. {
  1014. // Open the application bar
  1015. ApplicationBar.IsVisible = true;
  1016. // Auto hide after 15 sec if menu is closed.
  1017. Thread threadAutoHide = new Thread(new ThreadStart(
  1018. delegate()
  1019. {
  1020. // Wait before autohide if appbar menu is open:
  1021. do
  1022. {
  1023. Thread.Sleep(15000);
  1024. } while (m_isMenuVisible);
  1025. // Menu is minimized, we are allowed to hide it.
  1026. Dispatcher.BeginInvoke(() =>
  1027. {
  1028. ApplicationBar.IsVisible = false;
  1029. });
  1030. }));
  1031. threadAutoHide.Start();
  1032. }
  1033. private void touchUpEvent(int x, int y)
  1034. {
  1035. try
  1036. {
  1037. if (c_on_canvas_button_released == 0)
  1038. c_on_canvas_button_released = CibylCallTable.getAddressByName("rim_on_canvas_button_released");
  1039. }
  1040. catch (Exception t)
  1041. {
  1042. Logger.log("Exception in touchUpEvent: " + t);
  1043. throw; //todomt
  1044. //Environment.Exit(0);
  1045. }
  1046. if (c_on_canvas_button_pressed != 0)
  1047. {
  1048. UIWorker.addUIEvent(c_on_canvas_button_released, x, y, 0, 0, true);
  1049. }
  1050. }
  1051. private void touchMovedEvent(int x, int y)
  1052. {
  1053. try
  1054. {
  1055. if (c_on_canvas_button_moved == 0)
  1056. c_on_canvas_button_moved = CibylCallTable.getAddressByName("rim_on_canvas_button_moved");
  1057. }
  1058. catch (Exception t)
  1059. {
  1060. Logger.log("Exception in touchMovedEvent: " + t);
  1061. throw; //todomt
  1062. //Environment.Exit(0);
  1063. }
  1064. if (c_on_canvas_button_pressed != 0)
  1065. {
  1066. UIWorker.addUIEvent(c_on_canvas_button_moved, x, y, 0, 0, true);
  1067. }
  1068. }
  1069. static bool mouse_down = false;
  1070. private void ContentPanel_KeyDown(object sender, KeyEventArgs e)
  1071. {
  1072. keyDown(e.Key, 0);
  1073. }
  1074. private void ContentPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1075. {
  1076. mouse_down = true;
  1077. touchDownEvent((int)e.GetPosition(LayoutRoot).X, (int)e.GetPosition(LayoutRoot).Y);
  1078. }
  1079. private void ContentPanel_MouseMove(object sender, MouseEventArgs e)
  1080. {
  1081. if (mouse_down)
  1082. {
  1083. touchMovedEvent((int)e.GetPosition(LayoutRoot).X, (int)e.GetPosition(LayoutRoot).Y);
  1084. }
  1085. }
  1086. private void ContentPanel_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  1087. {
  1088. if (mouse_down)
  1089. {
  1090. mouse_down = false;
  1091. touchUpEvent((int)e.GetPosition(LayoutRoot).X, (int)e.GetPosition(LayoutRoot).Y);
  1092. }
  1093. }
  1094. private void PhoneApplicationPage_KeyDown(object sender, KeyEventArgs e)
  1095. {
  1096. ContentPanel_KeyDown(sender, e);
  1097. }
  1098. private void PhoneApplicationPage_BackKeyPress(object sender, CancelEventArgs e)
  1099. {
  1100. if (MeOnMapItem != null)
  1101. {
  1102. MeOnMapItem.CallCallback();
  1103. }
  1104. e.Cancel = true;
  1105. }
  1106. private void LayoutRoot_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  1107. {
  1108. UIElement el = (UIElement)sender;
  1109. LayoutRoot.CaptureMouse();
  1110. //el.CaptureMouse();
  1111. ContentPanel_MouseLeftButtonDown(sender, e);
  1112. }
  1113. private void LayoutRoot_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  1114. {
  1115. UIElement el = (UIElement)sender;
  1116. LayoutRoot.ReleaseMouseCapture();
  1117. //el.ReleaseMouseCapture();
  1118. ContentPanel_MouseLeftButtonUp(sender, e);
  1119. }
  1120. pr

Large files files are truncated, but you can click here to view the full file