openEventsPlatformApp/plugins/cordova-plugin-statusbar/src/wp/StatusBar.cs
plugins/cordova-plugin-statusbar/src/wp/StatusBar.csRaw
1/*
2 Licensed under the Apache License, Version 2.0 (the "License");
3 you may not use this file except in compliance with the License.
4 You may obtain a copy of the License at
5
6 http://www.apache.org/licenses/LICENSE-2.0
7
8 Unless required by applicable law or agreed to in writing, software
9 distributed under the License is distributed on an "AS IS" BASIS,
10 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 See the License for the specific language governing permissions and
12 limitations under the License.
13*/
14
15
16using Microsoft.Phone.Shell;
17using System;
18using System.Collections;
19using System.Collections.Generic;
20using System.Diagnostics;
21using System.Globalization;
22using System.Threading;
23using System.Windows;
24using System.Windows.Media;
25using System.Windows.Threading;
26
27
28/*
29 * http://www.idev101.com/code/User_Interface/StatusBar.html
30 * https://developer.apple.com/library/ios/documentation/userexperience/conceptual/transitionguide/Bars.html
31 * https://developer.apple.com/library/ios/documentation/uikit/reference/UIApplication_Class/Reference/Reference.html#//apple_ref/c/econst/UIStatusBarStyleDefault
32 * */
33
34
35namespace WPCordovaClassLib.Cordova.Commands
36{
37 public class StatusBar : BaseCommand
38 {
39
40 // returns an argb value, if the hex is only rgb, it will be full opacity
41 protected Color ColorFromHex(string hexString)
42 {
43 string cleanHex = hexString.Replace("#", "").Replace("0x", "");
44 // turn #FFF into #FFFFFF
45 if (cleanHex.Length == 3)
46 {
47 cleanHex = "" + cleanHex[0] + cleanHex[0] + cleanHex[1] + cleanHex[1] + cleanHex[2] + cleanHex[2];
48 }
49 // add an alpha 100% if it is missing
50 if (cleanHex.Length == 6)
51 {
52 cleanHex = "FF" + cleanHex;
53 }
54 int argb = Int32.Parse(cleanHex, NumberStyles.HexNumber);
55 Color clr = Color.FromArgb((byte)((argb & 0xff000000) >> 0x18),
56 (byte)((argb & 0xff0000) >> 0x10),
57 (byte)((argb & 0xff00) >> 8),
58 (byte)(argb & 0xff));
59 return clr;
60 }
61
62 public void _ready(string options)
63 {
64 Deployment.Current.Dispatcher.BeginInvoke(() =>
65 {
66 bool isVis = SystemTray.IsVisible;
67 // TODO: pass this to JS
68 //Debug.WriteLine("Result::" + res);
69 DispatchCommandResult(new PluginResult(PluginResult.Status.OK, isVis));
70 });
71 }
72
73 public void overlaysWebView(string options)
74 { //exec(null, null, "StatusBar", "overlaysWebView", [doOverlay]);
75 // string arg = JSON.JsonHelper.Deserialize<string[]>(options)[0];
76 }
77
78 public void styleDefault(string options)
79 { //exec(null, null, "StatusBar", "styleDefault", []);
80 Deployment.Current.Dispatcher.BeginInvoke(() =>
81 {
82 SystemTray.ForegroundColor = Colors.Black;
83 });
84 }
85
86 public void styleLightContent(string options)
87 { //exec(null, null, "StatusBar", "styleLightContent", []);
88
89 Deployment.Current.Dispatcher.BeginInvoke(() =>
90 {
91 SystemTray.ForegroundColor = Colors.White;
92 });
93 }
94
95 public void styleBlackTranslucent(string options)
96 { //exec(null, null, "StatusBar", "styleBlackTranslucent", []);
97 styleLightContent(options);
98 }
99
100 public void styleBlackOpaque(string options)
101 { //exec(null, null, "StatusBar", "styleBlackOpaque", []);
102 styleLightContent(options);
103 }
104
105 public void backgroundColorByName(string options)
106 { //exec(null, null, "StatusBar", "backgroundColorByName", [colorname]);
107 // this should NOT be called, js should now be using/converting color names to hex
108 }
109
110 public void backgroundColorByHexString(string options)
111 { //exec(null, null, "StatusBar", "backgroundColorByHexString", [hexString]);
112 string argb = JSON.JsonHelper.Deserialize<string[]>(options)[0];
113
114 Color clr = ColorFromHex(argb);
115
116 Deployment.Current.Dispatcher.BeginInvoke(() =>
117 {
118 SystemTray.Opacity = clr.A / 255.0d;
119 SystemTray.BackgroundColor = clr;
120
121 });
122 }
123
124 public void hide(string options)
125 { //exec(null, null, "StatusBar", "hide", []);
126 Deployment.Current.Dispatcher.BeginInvoke(() =>
127 {
128 SystemTray.IsVisible = false;
129 });
130
131 }
132
133 public void show(string options)
134 { //exec(null, null, "StatusBar", "show", []);
135 Deployment.Current.Dispatcher.BeginInvoke(() =>
136 {
137 SystemTray.IsVisible = true;
138 });
139 }
140 }
141}