Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4C4D0CE0F for ; Wed, 19 Jun 2013 00:17:43 +0000 (UTC) Received: (qmail 18566 invoked by uid 500); 19 Jun 2013 00:17:43 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 18540 invoked by uid 500); 19 Jun 2013 00:17:43 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 18393 invoked by uid 99); 19 Jun 2013 00:17:42 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Jun 2013 00:17:42 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 9D63D8A7DA7; Wed, 19 Jun 2013 00:17:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: purplecabbage@apache.org To: commits@cordova.apache.org Date: Wed, 19 Jun 2013 00:17:45 -0000 Message-Id: <301aff926a174f52b7862c7d727899a0@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [04/50] [abbrv] plugin code becomes common code http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/dec32ea1/wp8/template/Plugins/MimeTypeMapper.cs ---------------------------------------------------------------------- diff --git a/wp8/template/Plugins/MimeTypeMapper.cs b/wp8/template/Plugins/MimeTypeMapper.cs deleted file mode 100644 index a2794f5..0000000 --- a/wp8/template/Plugins/MimeTypeMapper.cs +++ /dev/null @@ -1,101 +0,0 @@ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -using System.Collections.Generic; -using System.IO; - -namespace WPCordovaClassLib.Cordova.Commands -{ - /// - /// Represents file extension to mime type mapper. - /// - public static class MimeTypeMapper - { - /// - /// For unknown type it is recommended to use 'application/octet-stream' - /// http://stackoverflow.com/questions/1176022/unknown-file-type-mime - /// - private static string DefaultMimeType = "application/octet-stream"; - - /// - /// Stores mime type for all necessary extension - /// - private static readonly Dictionary MIMETypesDictionary = new Dictionary - { - {"avi", "video/x-msvideo"}, - {"bmp", "image/bmp"}, - {"gif", "image/gif"}, - {"html","text/html"}, - {"jpe", "image/jpeg"}, - {"jpeg", "image/jpeg"}, - {"jpg", "image/jpeg"}, - {"js","text/javascript"}, - {"mov", "video/quicktime"}, - {"mp2", "audio/mpeg"}, - {"mp3", "audio/mpeg"}, - {"mp4", "video/mp4"}, - {"mpe", "video/mpeg"}, - {"mpeg", "video/mpeg"}, - {"mpg", "video/mpeg"}, - {"mpga", "audio/mpeg"}, - {"pbm", "image/x-portable-bitmap"}, - {"pcm", "audio/x-pcm"}, - {"pct", "image/pict"}, - {"pgm", "image/x-portable-graymap"}, - {"pic", "image/pict"}, - {"pict", "image/pict"}, - {"png", "image/png"}, - {"pnm", "image/x-portable-anymap"}, - {"pnt", "image/x-macpaint"}, - {"pntg", "image/x-macpaint"}, - {"ppm", "image/x-portable-pixmap"}, - {"qt", "video/quicktime"}, - {"ra", "audio/x-pn-realaudio"}, - {"ram", "audio/x-pn-realaudio"}, - {"ras", "image/x-cmu-raster"}, - {"rgb", "image/x-rgb"}, - {"snd", "audio/basic"}, - {"txt", "text/plain"}, - {"tif", "image/tiff"}, - {"tiff", "image/tiff"}, - {"wav", "audio/x-wav"}, - {"wbmp", "image/vnd.wap.wbmp"}, - - }; - /// - /// Gets mime type by file extension - /// - /// file name to extract extension - /// mime type - public static string GetMimeType(string fileName) - { - string ext = Path.GetExtension(fileName); - - // invalid extension - if (string.IsNullOrEmpty(ext) || !ext.StartsWith(".")) - { - return DefaultMimeType; - } - - ext = ext.Remove(0, 1); - - if (MIMETypesDictionary.ContainsKey(ext)) - { - return MIMETypesDictionary[ext]; - } - - return DefaultMimeType; - } - } -} http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/dec32ea1/wp8/template/Plugins/NetworkStatus.cs ---------------------------------------------------------------------- diff --git a/wp8/template/Plugins/NetworkStatus.cs b/wp8/template/Plugins/NetworkStatus.cs deleted file mode 100644 index 12eb061..0000000 --- a/wp8/template/Plugins/NetworkStatus.cs +++ /dev/null @@ -1,129 +0,0 @@ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -using System; -using System.Diagnostics; -using System.Net; -using System.Net.NetworkInformation; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Documents; -using System.Windows.Ink; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Animation; -using System.Windows.Shapes; -using Microsoft.Phone.Net.NetworkInformation; - -namespace WPCordovaClassLib.Cordova.Commands -{ - - // http://msdn.microsoft.com/en-us/library/microsoft.phone.net.networkinformation(v=VS.92).aspx - // http://msdn.microsoft.com/en-us/library/microsoft.phone.net.networkinformation.devicenetworkinformation(v=VS.92).aspx - - public class NetworkStatus : BaseCommand - { - const string UNKNOWN = "unknown"; - const string ETHERNET = "ethernet"; - const string WIFI = "wifi"; - const string CELL_2G = "2g"; - const string CELL_3G = "3g"; - const string CELL_4G = "4g"; - const string NONE = "none"; - const string CELL = "cellular"; - - private bool HasCallback = false; - - public NetworkStatus() - { - DeviceNetworkInformation.NetworkAvailabilityChanged += new EventHandler(ChangeDetected); - } - - public override void OnResume(object sender, Microsoft.Phone.Shell.ActivatedEventArgs e) - { - this.getConnectionInfo(""); - } - - public void getConnectionInfo(string empty) - { - HasCallback = true; - updateConnectionType(checkConnectionType()); - } - - private string checkConnectionType() - { - if (DeviceNetworkInformation.IsNetworkAvailable) - { - if (DeviceNetworkInformation.IsWiFiEnabled) - { - return WIFI; - } - else - { - return DeviceNetworkInformation.IsCellularDataEnabled ? CELL : UNKNOWN; - } - } - return NONE; - } - - private string checkConnectionType(NetworkInterfaceSubType type) - { - switch (type) - { - case NetworkInterfaceSubType.Cellular_1XRTT: //cell - case NetworkInterfaceSubType.Cellular_GPRS: //cell - return CELL; - case NetworkInterfaceSubType.Cellular_EDGE: //2 - return CELL_2G; - case NetworkInterfaceSubType.Cellular_3G: - case NetworkInterfaceSubType.Cellular_EVDO: //3 - case NetworkInterfaceSubType.Cellular_EVDV: //3 - case NetworkInterfaceSubType.Cellular_HSPA: //3 - return CELL_3G; - case NetworkInterfaceSubType.WiFi: - return WIFI; - case NetworkInterfaceSubType.Unknown: - case NetworkInterfaceSubType.Desktop_PassThru: - default: - return UNKNOWN; - } - } - - void ChangeDetected(object sender, NetworkNotificationEventArgs e) - { - switch (e.NotificationType) - { - case NetworkNotificationType.InterfaceConnected: - updateConnectionType(checkConnectionType(e.NetworkInterface.InterfaceSubtype)); - break; - case NetworkNotificationType.InterfaceDisconnected: - updateConnectionType(NONE); - break; - default: - break; - } - } - - private void updateConnectionType(string type) - { - // This should also implicitly fire offline/online events as that is handled on the JS side - if (this.HasCallback) - { - PluginResult result = new PluginResult(PluginResult.Status.OK, type); - result.KeepCallback = true; - DispatchCommandResult(result); - } - } - } -} http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/dec32ea1/wp8/template/Plugins/Notification.cs ---------------------------------------------------------------------- diff --git a/wp8/template/Plugins/Notification.cs b/wp8/template/Plugins/Notification.cs deleted file mode 100644 index 0759c72..0000000 --- a/wp8/template/Plugins/Notification.cs +++ /dev/null @@ -1,361 +0,0 @@ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -using System; -using System.Windows; -using System.Windows.Controls; -using Microsoft.Devices; -using System.Runtime.Serialization; -using System.Threading; -using System.Windows.Resources; -using Microsoft.Phone.Controls; -using Microsoft.Xna.Framework.Audio; -using WPCordovaClassLib.Cordova.UI; -using System.Diagnostics; - - -namespace WPCordovaClassLib.Cordova.Commands -{ - public class Notification : BaseCommand - { - static ProgressBar progressBar = null; - const int DEFAULT_DURATION = 5; - - private NotificationBox notifyBox; - - private PhoneApplicationPage Page - { - get - { - PhoneApplicationPage page = null; - PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame; - if (frame != null) - { - page = frame.Content as PhoneApplicationPage; - } - return page; - } - } - - // blink api - doesn't look like there is an equivalent api we can use... - - [DataContract] - public class AlertOptions - { - [OnDeserializing] - public void OnDeserializing(StreamingContext context) - { - // set defaults - this.message = "message"; - this.title = "Alert"; - this.buttonLabel = "ok"; - } - - /// - /// message to display in the alert box - /// - [DataMember] - public string message; - - /// - /// title displayed on the alert window - /// - [DataMember] - public string title; - - /// - /// text to display on the button - /// - [DataMember] - public string buttonLabel; - } - - public void alert(string options) - { - string[] args = JSON.JsonHelper.Deserialize(options); - AlertOptions alertOpts = new AlertOptions(); - alertOpts.message = args[0]; - alertOpts.title = args[1]; - alertOpts.buttonLabel = args[2]; - string aliasCurrentCommandCallbackId = args[3]; - - Deployment.Current.Dispatcher.BeginInvoke(() => - { - PhoneApplicationPage page = Page; - if (page != null) - { - Grid grid = page.FindName("LayoutRoot") as Grid; - if (grid != null) - { - var previous = notifyBox; - notifyBox = new NotificationBox(); - notifyBox.Tag = new { previous = previous, callbackId = aliasCurrentCommandCallbackId }; - notifyBox.PageTitle.Text = alertOpts.title; - notifyBox.SubTitle.Text = alertOpts.message; - Button btnOK = new Button(); - btnOK.Content = alertOpts.buttonLabel; - btnOK.Click += new RoutedEventHandler(btnOK_Click); - btnOK.Tag = 1; - notifyBox.ButtonPanel.Children.Add(btnOK); - grid.Children.Add(notifyBox); - - if (previous == null) - { - page.BackKeyPress += page_BackKeyPress; - } - } - } - else - { - DispatchCommandResult(new PluginResult(PluginResult.Status.INSTANTIATION_EXCEPTION)); - } - }); - } - - public void confirm(string options) - { - string[] args = JSON.JsonHelper.Deserialize(options); - AlertOptions alertOpts = new AlertOptions(); - alertOpts.message = args[0]; - alertOpts.title = args[1]; - alertOpts.buttonLabel = args[2]; - string aliasCurrentCommandCallbackId = args[3]; - - Deployment.Current.Dispatcher.BeginInvoke(() => - { - PhoneApplicationPage page = Page; - if (page != null) - { - Grid grid = page.FindName("LayoutRoot") as Grid; - if (grid != null) - { - var previous = notifyBox; - notifyBox = new NotificationBox(); - notifyBox.Tag = new { previous = previous, callbackId = aliasCurrentCommandCallbackId }; - notifyBox.PageTitle.Text = alertOpts.title; - notifyBox.SubTitle.Text = alertOpts.message; - - string[] labels = JSON.JsonHelper.Deserialize(alertOpts.buttonLabel); - - if (labels == null) - { - labels = alertOpts.buttonLabel.Split(','); - } - - for (int n = 0; n < labels.Length; n++) - { - Button btn = new Button(); - btn.Content = labels[n]; - btn.Tag = n; - btn.Click += new RoutedEventHandler(btnOK_Click); - notifyBox.ButtonPanel.Children.Add(btn); - } - - grid.Children.Add(notifyBox); - if (previous == null) - { - page.BackKeyPress += page_BackKeyPress; - } - } - } - else - { - DispatchCommandResult(new PluginResult(PluginResult.Status.INSTANTIATION_EXCEPTION)); - } - }); - } - - void page_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e) - { - PhoneApplicationPage page = sender as PhoneApplicationPage; - string callbackId = ""; - if (page != null && notifyBox != null) - { - Grid grid = page.FindName("LayoutRoot") as Grid; - if (grid != null) - { - grid.Children.Remove(notifyBox); - dynamic notifBoxData = notifyBox.Tag; - notifyBox = notifBoxData.previous as NotificationBox; - callbackId = notifBoxData.callbackId as string; - } - if (notifyBox == null) - { - page.BackKeyPress -= page_BackKeyPress; - } - e.Cancel = true; - } - - DispatchCommandResult(new PluginResult(PluginResult.Status.OK, 0), callbackId); - } - - void btnOK_Click(object sender, RoutedEventArgs e) - { - Button btn = sender as Button; - FrameworkElement notifBoxParent = null; - int retVal = 0; - string callbackId = ""; - if (btn != null) - { - retVal = (int)btn.Tag + 1; - - notifBoxParent = btn.Parent as FrameworkElement; - while ((notifBoxParent = notifBoxParent.Parent as FrameworkElement) != null && - !(notifBoxParent is NotificationBox)) ; - } - if (notifBoxParent != null) - { - PhoneApplicationPage page = Page; - if (page != null) - { - Grid grid = page.FindName("LayoutRoot") as Grid; - if (grid != null) - { - grid.Children.Remove(notifBoxParent); - } - - dynamic notifBoxData = notifBoxParent.Tag; - notifyBox = notifBoxData.previous as NotificationBox; - callbackId = notifBoxData.callbackId as string; - - if (notifyBox == null) - { - page.BackKeyPress -= page_BackKeyPress; - } - } - - } - DispatchCommandResult(new PluginResult(PluginResult.Status.OK, retVal),callbackId); - } - - - - public void beep(string options) - { - string[] args = JSON.JsonHelper.Deserialize(options); - int times = int.Parse(args[0]); - - string resourcePath = BaseCommand.GetBaseURL() + "resources/notification-beep.wav"; - - StreamResourceInfo sri = Application.GetResourceStream(new Uri(resourcePath, UriKind.Relative)); - - if (sri != null) - { - SoundEffect effect = SoundEffect.FromStream(sri.Stream); - SoundEffectInstance inst = effect.CreateInstance(); - ThreadPool.QueueUserWorkItem((o) => - { - // cannot interact with UI !! - do - { - inst.Play(); - Thread.Sleep(effect.Duration + TimeSpan.FromMilliseconds(100)); - } - while (--times > 0); - - }); - - } - - // TODO: may need a listener to trigger DispatchCommandResult after the alarm has finished executing... - DispatchCommandResult(); - } - - // Display an indeterminate progress indicator - public void activityStart(string unused) - { - - Deployment.Current.Dispatcher.BeginInvoke(() => - { - PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame; - - if (frame != null) - { - PhoneApplicationPage page = frame.Content as PhoneApplicationPage; - - if (page != null) - { - var temp = page.FindName("LayoutRoot"); - Grid grid = temp as Grid; - if (grid != null) - { - if (progressBar != null) - { - grid.Children.Remove(progressBar); - } - progressBar = new ProgressBar(); - progressBar.IsIndeterminate = true; - progressBar.IsEnabled = true; - - grid.Children.Add(progressBar); - } - } - } - }); - } - - - // Remove our indeterminate progress indicator - public void activityStop(string unused) - { - Deployment.Current.Dispatcher.BeginInvoke(() => - { - if (progressBar != null) - { - progressBar.IsEnabled = false; - PhoneApplicationFrame frame = Application.Current.RootVisual as PhoneApplicationFrame; - if (frame != null) - { - PhoneApplicationPage page = frame.Content as PhoneApplicationPage; - if (page != null) - { - Grid grid = page.FindName("LayoutRoot") as Grid; - if (grid != null) - { - grid.Children.Remove(progressBar); - } - } - } - progressBar = null; - } - }); - } - - public void vibrate(string vibrateDuration) - { - - int msecs = 200; // set default - - try - { - string[] args = JSON.JsonHelper.Deserialize(vibrateDuration); - - msecs = int.Parse(args[0]); - if (msecs < 1) - { - msecs = 1; - } - } - catch (FormatException) - { - - } - - VibrateController.Default.Start(TimeSpan.FromMilliseconds(msecs)); - - // TODO: may need to add listener to trigger DispatchCommandResult when the vibration ends... - DispatchCommandResult(); - } - } -} http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/dec32ea1/wp8/template/Plugins/UI/AudioCaptureTask.cs ---------------------------------------------------------------------- diff --git a/wp8/template/Plugins/UI/AudioCaptureTask.cs b/wp8/template/Plugins/UI/AudioCaptureTask.cs deleted file mode 100644 index 3d7d60f..0000000 --- a/wp8/template/Plugins/UI/AudioCaptureTask.cs +++ /dev/null @@ -1,107 +0,0 @@ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -using System; -using System.IO; -using System.Windows; -using Microsoft.Phone.Controls; -using Microsoft.Phone.Tasks; - -namespace WPCordovaClassLib.Cordova.UI -{ - /// - /// Allows an application to launch the Audio Recording application. - /// Use this to allow users to record audio from your application. - /// - public class AudioCaptureTask - { - /// - /// Represents recorded audio returned from a call to the Show method of - /// a WPCordovaClassLib.Cordova.Controls.AudioCaptureTask object - /// - public class AudioResult : TaskEventArgs - { - /// - /// Initializes a new instance of the AudioResult class. - /// - public AudioResult() - { } - - /// - /// Initializes a new instance of the AudioResult class - /// with the specified Microsoft.Phone.Tasks.TaskResult. - /// - /// Associated Microsoft.Phone.Tasks.TaskResult - public AudioResult(TaskResult taskResult) - : base(taskResult) - { } - - /// - /// Gets the file name of the recorded audio. - /// - public Stream AudioFile { get; internal set; } - - /// - /// Gets the stream containing the data for the recorded audio. - /// - public string AudioFileName { get; internal set; } - } - - /// - /// Occurs when a audio recording task is completed. - /// - public event EventHandler Completed; - - /// - /// Shows Audio Recording application - /// - public void Show() - { - Deployment.Current.Dispatcher.BeginInvoke(() => - { - var root = Application.Current.RootVisual as PhoneApplicationFrame; - - root.Navigated += new System.Windows.Navigation.NavigatedEventHandler(NavigationService_Navigated); - - string baseUrl = WPCordovaClassLib.Cordova.Commands.BaseCommand.GetBaseURL(); - // dummy parameter is used to always open a fresh version - root.Navigate(new System.Uri( baseUrl + "CordovaLib/UI/AudioRecorder.xaml?dummy=" + Guid.NewGuid().ToString(), UriKind.Relative)); - - }); - } - - /// - /// Performs additional configuration of the recording application. - /// - /// - /// - private void NavigationService_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e) - { - if (!(e.Content is AudioRecorder)) return; - - (Application.Current.RootVisual as PhoneApplicationFrame).Navigated -= NavigationService_Navigated; - - AudioRecorder audioRecorder = (AudioRecorder)e.Content; - - if (audioRecorder != null) - { - audioRecorder.Completed += this.Completed; - } - else if (this.Completed != null) - { - this.Completed(this, new AudioResult(TaskResult.Cancel)); - } - } - } -} http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/dec32ea1/wp8/template/Plugins/UI/AudioRecorder.xaml ---------------------------------------------------------------------- diff --git a/wp8/template/Plugins/UI/AudioRecorder.xaml b/wp8/template/Plugins/UI/AudioRecorder.xaml deleted file mode 100644 index 0fd26ab..0000000 --- a/wp8/template/Plugins/UI/AudioRecorder.xaml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - - - - -