Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
applied CB-6268 backgroundcolor to WP7 also
  • Loading branch information
purplecabbage committed Mar 24, 2014
1 parent d60dfb5 commit cc1d54fcb2a00b49e498c872db68449e2bcbfcc0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 8 deletions.
@@ -18,11 +18,13 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Resources;
using System.Xml.Linq;
using WPCordovaClassLib.Cordova;
@@ -152,6 +154,7 @@ public CordovaView()
}
}

ApplyConfigurationPreferences();

browserDecorators = new Dictionary<string, IBrowserDecorator>();

@@ -187,6 +190,26 @@ void CreateDecorators()

}

/// <summary>
/// Applies configuration preferences. Only BackgroundColor+fullscreen is currently supported.
/// </summary>
private void ApplyConfigurationPreferences()
{
string bgColor = configHandler.GetPreference("backgroundcolor");

if (!String.IsNullOrEmpty(bgColor)) {
try
{
Browser.Background = new SolidColorBrush(ColorFromHex(bgColor));
}
catch (Exception ex)
{
Debug.WriteLine("Unable to parse BackgroundColor value '{0}'. Error: {1}", bgColor, ex.Message);
}
}

}



void AppClosing(object sender, ClosingEventArgs e)
@@ -508,6 +531,31 @@ private void GapBrowser_Navigated(object sender, System.Windows.Navigation.Navig
}
}

/// <summary>
/// Converts hex color string to a new System.Windows.Media.Color structure.
/// If the hex is only rgb, it will be full opacity.
/// </summary>
protected Color ColorFromHex(string hexString)
{
string cleanHex = hexString.Replace("#", "").Replace("0x", "");
// turn #FFF into #FFFFFF
if (cleanHex.Length == 3)
{
cleanHex = "" + cleanHex[0] + cleanHex[0] + cleanHex[1] + cleanHex[1] + cleanHex[2] + cleanHex[2];
}
// add an alpha 100% if it is missing
if (cleanHex.Length == 6)
{
cleanHex = "FF" + cleanHex;
}
int argb = Int32.Parse(cleanHex, NumberStyles.HexNumber);
Color clr = Color.FromArgb((byte)((argb & 0xff000000) >> 0x18),
(byte)((argb & 0xff0000) >> 0x10),
(byte)((argb & 0xff00) >> 8),
(byte)(argb & 0xff));
return clr;
}


}
}
@@ -179,20 +179,22 @@ public CordovaView()
}

/// <summary>
/// Applies configuration preferences. Only BackgroundColor is currently supported.
/// Applies configuration preferences. Only BackgroundColor+fullscreen is currently supported.
/// </summary>
private void ApplyConfigurationPreferences()
{
string bgColor = configHandler.GetPreference("backgroundcolor");

if (String.IsNullOrEmpty(bgColor)) return;
try
if (!String.IsNullOrEmpty(bgColor))
{
Browser.Background = new SolidColorBrush(ColorFromHex(bgColor));
}
catch (Exception ex)
{
Debug.WriteLine("Unable to parse BackgroundColor value '{0}'. Error: {1}", bgColor, ex.Message);
try
{
Browser.Background = new SolidColorBrush(ColorFromHex(bgColor));
}
catch (Exception ex)
{
Debug.WriteLine("Unable to parse BackgroundColor value '{0}'. Error: {1}", bgColor, ex.Message);
}
}
}

0 comments on commit cc1d54f

Please sign in to comment.