/
PhoneTheme.cs
88 lines (69 loc) · 2.71 KB
/
PhoneTheme.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System.Runtime.Serialization;
using WP7GapClassLib.PhoneGap;
using WP7GapClassLib.PhoneGap.Commands;
using WP7GapClassLib.PhoneGap.JSON;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Phone.Controls;
using System.Windows;
using System.Windows.Media;
namespace PhoneGap.Extension.Commands
{
public class PhoneTheme : BaseCommand
{
#region Constants
#endregion
#region Live tiles options
/// <summary>
/// Represents selected on device theme
/// </summary>
[DataContract]
public class PhoneThemeInfo
{
[DataMember(IsRequired = false, Name = "backgroundColor")]
public string BackgroundColor { get; set; }
[DataMember(IsRequired = false, Name = "isDark")]
public bool IsDark { get; set; }
[DataMember(IsRequired = false, Name = "isLight")]
public bool IsLight { get; set; }
[DataMember(IsRequired = false, Name = "accentColor")]
public string AccentColor { get; set; }
}
#endregion
public void get(string options)
{
try
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
try
{
PhoneThemeInfo themeInfo = new PhoneThemeInfo();
themeInfo.BackgroundColor = this.ColorToHtmlHex((Color)Application.Current.Resources["PhoneBackgroundColor"]);
themeInfo.IsLight = (Visibility)Application.Current.Resources["PhoneLightThemeVisibility"] == Visibility.Visible;
themeInfo.IsDark = (Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"] == Visibility.Visible;
themeInfo.AccentColor = this.ColorToHtmlHex((Color)Application.Current.Resources["PhoneAccentColor"]);
DispatchCommandResult(new PluginResult(PluginResult.Status.OK, themeInfo));
}
catch (Exception e)
{
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, e.Message));
}
});
}
catch (Exception e)
{
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Error updating application tile"));
}
}
string ColorToHtmlHex(Color color)
{
return String.Format("#{0:X2}{1:X2}{2:X2}",
color.R,
color.G,
color.B);
}
}
}