123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Shapes;
- using Microsoft.Phone.Controls;
- using System.IO;
- using System.Windows.Resources;
- using System.IO.IsolatedStorage;
- using System.Net.Browser;
- using System.Windows.Navigation;
- namespace WhereAmI
- {
-
-
-
-
-
- public partial class MainPage : PhoneApplicationPage
- {
- private BrowserMouseHelper moveHelper;
-
-
- public MainPage()
- {
- InitializeComponent();
- webBrowser.Opacity = 0;
-
- webBrowser.IsGeolocationEnabled = true;
- webBrowser.IsScriptEnabled = true;
- moveHelper = new BrowserMouseHelper(ref webBrowser);
- moveHelper.ScrollDisabled = true;
-
- SaveFilesToIsoStore();
-
- webBrowser.ScriptNotify += new EventHandler<NotifyEventArgs>(webBrowser_ScriptNotify);
- }
-
-
-
-
- protected override void OnNavigatedTo(NavigationEventArgs e)
- {
- base.OnNavigatedTo(e);
- webBrowser.Navigate(new Uri("html_content/index.html", UriKind.Relative));
- }
-
-
-
-
- protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
- {
- base.OnBackKeyPress(e);
- if (isInfoVisible())
- {
- e.Cancel = true;
- CloseInfo();
- }
- else
- {
- e.Cancel = false;
- }
- }
-
-
-
-
-
- void webBrowser_ScriptNotify(object sender, NotifyEventArgs e)
- {
- MessageBox.Show(e.Value);
- }
-
-
-
-
-
- private void webBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
- {
- logo.Opacity = 0;
-
- webBrowser.Opacity = 1;
- }
-
-
-
- private void SaveFilesToIsoStore()
- {
-
-
-
- string[] files = {
- "html_content/index.html",
- "html_content/css/whereami.css",
- "html_content/images/marker.png",
- "html_content/js/geolocation.js",
- "html_content/js/staticmap.js"
- };
- IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
-
- isoStore.Remove();
- foreach (string f in files)
- {
- StreamResourceInfo sr = Application.GetResourceStream(new Uri(f, UriKind.Relative));
- using (BinaryReader br = new BinaryReader(sr.Stream))
- {
- byte[] data = br.ReadBytes((int)sr.Stream.Length);
- SaveToIsoStore(f, data);
- }
- }
- }
- private void SaveToIsoStore(string fileName, byte[] data)
- {
- string strBaseDir = string.Empty;
- string delimStr = "/";
- char[] delimiter = delimStr.ToCharArray();
- string[] dirsPath = fileName.Split(delimiter);
-
- IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
-
- for (int i = 0; i < dirsPath.Length - 1; i++)
- {
- strBaseDir = System.IO.Path.Combine(strBaseDir, dirsPath[i]);
- isoStore.CreateDirectory(strBaseDir);
- }
-
- if (isoStore.FileExists(fileName))
- {
- isoStore.DeleteFile(fileName);
- }
-
- using (BinaryWriter bw = new BinaryWriter(isoStore.CreateFile(fileName)))
- {
- bw.Write(data);
- bw.Close();
- }
- }
-
-
-
- private void UpdateMap()
- {
- try
- {
- if (isInfoVisible() == false)
- webBrowser.InvokeScript("update");
- }
- catch { }
- }
-
-
-
-
- private bool isInfoVisible()
- {
- try
- {
- int ret = Int32.Parse((string)(webBrowser.InvokeScript("isInfoVisible")));
- if (ret == 0)
- return false;
- else
- return true;
- }
- catch
- {
- return false;
- }
- }
-
-
-
- private void ShowInfo()
- {
- try
- {
- webBrowser.InvokeScript("showInfo");
- }
- catch { }
- }
-
-
-
- private void CloseInfo()
- {
- try
- {
- webBrowser.InvokeScript("closeInfo");
- }
- catch { }
- }
- private void ApplicationBarMenuItem_Click(object sender, EventArgs e)
- {
- ShowInfo();
- }
- private void ApplicationBarMenuItem_Click_1(object sender, EventArgs e)
- {
- UpdateMap();
- }
- private void ApplicationBarIconButton_Click(object sender, EventArgs e)
- {
- UpdateMap();
- }
- private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
- {
- ShowInfo();
- }
- }
- }
|