Skip to content
This repository has been archived by the owner on Feb 12, 2021. It is now read-only.

Commit

Permalink
Added Windows Phone 8.1 XAML support
Browse files Browse the repository at this point in the history
A couple of pragma warnings point to areas where a solution is needed
for a known issue or incomplete solution. Open RateMyAppXAML.sln for
testing.
  • Loading branch information
ltomuta committed Jul 16, 2014
1 parent 1e94875 commit 57ff261
Show file tree
Hide file tree
Showing 38 changed files with 3,138 additions and 25 deletions.
118 changes: 104 additions & 14 deletions RateMyApp/Controls/FeedbackOverlay.xaml.cs
Expand Up @@ -12,18 +12,31 @@
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Info;
using Microsoft.Phone.Tasks;
using System;
using System.ComponentModel;
using System.Globalization;
using System.Threading;
using System.Windows;
using RateMyApp.Helpers;

#if SILVERLIGHT
using Microsoft.Phone.Controls;
using Microsoft.Phone.Info;
using Microsoft.Phone.Tasks;
using System.Windows.Controls;
using System.Windows.Media;
using Visibility = System.Windows.Visibility;
#else
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
using Windows.ApplicationModel.Email;
using System.IO;
using Windows.Storage;
using Windows.Security.ExchangeActiveSyncProvisioning;
using Windows.ApplicationModel.Resources;
#endif

using RateMyApp.Helpers;
using RateMyApp.Resources;

namespace RateMyApp.Controls
Expand All @@ -36,16 +49,16 @@ namespace RateMyApp.Controls
public partial class FeedbackOverlay : UserControl
{
public static readonly DependencyProperty VisibilityForDesignProperty =
DependencyProperty.Register("VisibilityForDesign", typeof(System.Windows.Visibility), typeof(FeedbackOverlay), new PropertyMetadata(System.Windows.Visibility.Collapsed, null));
DependencyProperty.Register("VisibilityForDesign", typeof(Visibility), typeof(FeedbackOverlay), new PropertyMetadata(Visibility.Collapsed, null));

public static void SetVisibilityForDesign(FeedbackOverlay element, System.Windows.Visibility value)
public static void SetVisibilityForDesign(FeedbackOverlay element, Visibility value)
{
element.SetValue(VisibilityForDesignProperty, value);
}

public static System.Windows.Visibility GetVisibilityForDesign(FeedbackOverlay element)
public static Visibility GetVisibilityForDesign(FeedbackOverlay element)
{
return (System.Windows.Visibility)element.GetValue(VisibilityForDesignProperty);
return (Visibility)element.GetValue(VisibilityForDesignProperty);
}

// Use this from XAML to control whether animation is on or off
Expand Down Expand Up @@ -459,8 +472,10 @@ public static string GetLanguageOverride(FeedbackOverlay element)
// Use this for detecting visibility change on code
public event EventHandler VisibilityChanged = null;

#if SILVERLIGHT
// PhoneApplicationFrame needed for detecting back presses
private PhoneApplicationFrame _rootFrame = null;
#endif

// Title of the review/feedback notification
private string Title
Expand Down Expand Up @@ -614,26 +629,38 @@ private void FeedbackOverlay_Loaded(object sender, RoutedEventArgs e)
/// </summary>
private void AttachBackKeyPressed()
{
#if SILVERLIGHT
if (_rootFrame == null)
{
_rootFrame = Application.Current.RootVisual as PhoneApplicationFrame;
_rootFrame.BackKeyPress += FeedbackOverlay_BackKeyPress;
}
#else
Windows.Phone.UI.Input.HardwareButtons.BackPressed += FeedbackOverlay_BackKeyPress;
#endif
}

/// <summary>
/// Handle back key presses.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
#if SILVERLIGHT
private void FeedbackOverlay_BackKeyPress(object sender, CancelEventArgs e)
#else
private void FeedbackOverlay_BackKeyPress(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
#endif
{
// If back is pressed whilst notification is open, close
// the notification and cancel back to stop app from exiting.
if (Visibility == System.Windows.Visibility.Visible)
if (Visibility == Visibility.Visible)
{
OnNoClick();
#if SILVERLIGHT
e.Cancel = true;
#else
e.Handled = true;
#endif
}
}

Expand Down Expand Up @@ -700,7 +727,11 @@ private void OnNoClick()
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
#if SILVERLIGHT
private void hideContent_Completed(object sender, EventArgs e)
#else
private void hideContent_Completed(object sender, object e)
#endif
{
ShowFeedback();
}
Expand Down Expand Up @@ -757,19 +788,24 @@ private void yesButton_Click(object sender, RoutedEventArgs e)
/// </summary>
private void Review()
{
FeedbackHelper.Default.Reviewed();
FeedbackHelper.Default.Review();

var marketplace = new MarketplaceReviewTask();
marketplace.Show();
//var marketplace = new MarketplaceReviewTask();
//marketplace.Show();
}

/// <summary>
/// Launch feedback email.
/// </summary>
#if SILVERLIGHT
private void Feedback()
#else
private async void Feedback()
#endif
{
string version = string.Empty;

#if SILVERLIGHT
var appManifestResourceInfo = Application.GetResourceStream(new Uri("WMAppManifest.xml", UriKind.Relative));

using (var appManifestStream = appManifestResourceInfo.Stream)
Expand All @@ -796,13 +832,35 @@ private void Feedback()
var parts = asm.FullName.Split(',');
version = parts[1].Split('=')[1];
}
#else
var uri = new System.Uri("ms-appx:///AppxManifest.xml");
StorageFile file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri);
using (var rastream = await file.OpenReadAsync())
using (var appManifestStream = rastream.AsStreamForRead())
{
using (var reader = XmlReader.Create(appManifestStream, new XmlReaderSettings { IgnoreWhitespace = true, IgnoreComments = true }))
{
var doc = XDocument.Load(reader);
var app = doc.Descendants("Identity").FirstOrDefault();
if (app != null)
{
var versionAttribute = app.Attribute("Version");
if (versionAttribute != null)
{
version = versionAttribute.Value;
}
}
}
}
#endif

string company = GetCompanyName(this);
if (company == null || company.Length <= 0)
{
company = "<Company>";
}

#if SILVERLIGHT
// Body text including hardware, firmware and software info
string body = string.Format(FeedbackOverlay.GetFeedbackBody(this),
DeviceStatus.DeviceName,
Expand All @@ -819,6 +877,25 @@ private void Feedback()
email.Body = body;

email.Show();
#else
var easClientDeviceInformation = new EasClientDeviceInformation();

// Body text including hardware, firmware and software info
string body = string.Format(FeedbackOverlay.GetFeedbackBody(this),
easClientDeviceInformation.SystemProductName,
easClientDeviceInformation.SystemManufacturer,
easClientDeviceInformation.SystemFirmwareVersion,
easClientDeviceInformation.SystemHardwareVersion,
version,
company);

// Send an Email with attachment
EmailMessage email = new EmailMessage();
email.To.Add(new EmailRecipient(FeedbackOverlay.GetFeedbackTo(this)));
email.Subject = string.Format(FeedbackOverlay.GetFeedbackSubject(this), GetApplicationName());
email.Body = body;
await EmailManager.ShowComposeNewEmailAsync(email);
#endif
}

/// <summary>
Expand All @@ -834,14 +911,14 @@ private void SetVisibility(bool visible)
PreparePanoramaPivot(false);
FeedbackOverlay.SetIsVisible(this, true);
FeedbackOverlay.SetIsNotVisible(this, false);
Visibility = System.Windows.Visibility.Visible;
Visibility = Visibility.Visible;
}
else
{
PreparePanoramaPivot(true);
FeedbackOverlay.SetIsVisible(this, false);
FeedbackOverlay.SetIsNotVisible(this, true);
Visibility = System.Windows.Visibility.Collapsed;
Visibility = Visibility.Collapsed;
}

if (wasVisible != visible)
Expand Down Expand Up @@ -894,11 +971,19 @@ private void PreparePanoramaPivot(bool hitTestVisible)
/// </summary>
private void OverrideLanguage()
{
#if SILVERLIGHT
CultureInfo originalCulture = Thread.CurrentThread.CurrentUICulture;
CultureInfo newCulture = new CultureInfo(GetLanguageOverride(this));

Thread.CurrentThread.CurrentCulture = newCulture;
Thread.CurrentThread.CurrentUICulture = newCulture;
#else
CultureInfo originalCulture = CultureInfo.DefaultThreadCurrentUICulture;
CultureInfo newCulture = new CultureInfo(GetLanguageOverride(this));

CultureInfo.DefaultThreadCurrentCulture = newCulture;
CultureInfo.DefaultThreadCurrentUICulture = newCulture;
#endif

SetFeedbackBody(this, AppResources.FeedbackBody);
SetFeedbackMessage1(this, string.Format(AppResources.FeedbackMessage1, GetApplicationName()));
Expand All @@ -912,8 +997,13 @@ private void OverrideLanguage()
SetRatingTitle(this, string.Format(AppResources.RatingTitle, GetApplicationName()));
SetRatingYes(this, AppResources.RatingYes);

#if SILVERLIGHT
Thread.CurrentThread.CurrentCulture = originalCulture;
Thread.CurrentThread.CurrentUICulture = originalCulture;
#else
CultureInfo.DefaultThreadCurrentCulture = originalCulture;
CultureInfo.DefaultThreadCurrentUICulture = originalCulture;
#endif
}

/// <summary>
Expand Down
64 changes: 64 additions & 0 deletions RateMyApp/Controls/FeedbackOverlayXAML.xaml
@@ -0,0 +1,64 @@
<!--
Copyright (c) 2013-2014 Microsoft Mobile. All rights reserved.
Nokia, Nokia Connecting People, Nokia Developer, and HERE are trademarks
and/or registered trademarks of Nokia Corporation. Other product and company
names mentioned herein may be trademarks or trade names of their respective
owners.
See the license text file delivered with this project for more information.
-->

<UserControl x:Class="RateMyApp.Controls.FeedbackOverlay"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource ContentControlFontSize}"
Foreground="{StaticResource PhoneForegroundBrush}"
Visibility="{Binding VisibilityForDesign, RelativeSource={RelativeSource Self}}"
d:DesignHeight="480" d:DesignWidth="480">

<UserControl.Resources>
<Storyboard x:Name="showContent">
<DoubleAnimation Duration="0:0:0.5" To="1" Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="Opacity" />
<DoubleAnimation Duration="0:0:0.5" To="0" Storyboard.TargetName="xProjection" Storyboard.TargetProperty="RotationX" />
</Storyboard>
<Storyboard x:Name="hideContent">
<DoubleAnimation Duration="0:0:0.5" To="0" Storyboard.TargetName="LayoutRoot" Storyboard.TargetProperty="Opacity" />
<DoubleAnimation Duration="0:0:0.5" To="90" Storyboard.TargetName="xProjection" Storyboard.TargetProperty="RotationX" />
</Storyboard>
</UserControl.Resources>

<Grid x:Name="LayoutRoot">
<Rectangle Fill="{StaticResource PhoneBackgroundBrush}" Opacity="0.6"/>
<Border x:Name="content" VerticalAlignment="Top" Background="{StaticResource PhoneChromeBrush}">
<Grid Margin="24">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<TextBlock x:Name="title" Grid.ColumnSpan="2" Margin="12,0,12,0" HorizontalAlignment="Left"
Style="{StaticResource MessageDialogTitleStyle}" FontWeight="Bold" TextWrapping="Wrap" />

<TextBlock x:Name="message" Grid.ColumnSpan="2" Grid.Row="1" Margin="12,12,12,12" HorizontalAlignment="Left"
Style="{StaticResource MessageDialogContentStyle}" TextWrapping="Wrap" />

<Button x:Name="yesButton" Margin="0,0,0,0" Grid.Row="2" HorizontalAlignment="Center" Grid.Column="0" />
<Button x:Name="noButton" Margin="0,0,0,0" Grid.Row="2" HorizontalAlignment="Center" Grid.Column="1" />

</Grid>
<Border.Projection>
<PlaneProjection x:Name="xProjection" />
</Border.Projection>
</Border>
</Grid>
</UserControl>

0 comments on commit 57ff261

Please sign in to comment.