重新想象 Windows 8.1 Store Apps (85) - 警报通知(闹钟), Tile 的新特性
作者:webabcd
介绍
重新想象 Windows 8.1 Store Apps 之通知的新特性
- 警报通知(闹钟)
- Tile 的新特性
示例
1、演示 win8.1 中新增的警报 toast(闹钟)
AlarmToast.xaml
<Page
x:Class="Windows81.Notification.AlarmToast"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows81.Notification"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="120 0 0 0"> <TextBlock Name="lblMsg" FontSize="14.667" Margin="0 10 0 0" /> </StackPanel>
</Grid>
</Page>
AlarmToast.xaml.cs
/*
* 演示 win8.1 中新增的警报 toast(闹钟)
*
* 关于 toast 的基础请参见:http://www.cnblogs.com/webabcd/archive/2013/06/20/3145356.html
*
*
* 注:
* 1、需要在 manifest 中设置支持 toast 通知和锁屏通知
* 2、需要在 manifest 中的 Application/Extensions 内做如下设置
* <!--声明此 app 是一个“闹钟”应用,其会出现在“设置”->“电脑和设备”->“锁屏应用”->“选择要显示提醒的应用”列表中-->
<m2:Extension Category="windows.alarm" />
<!--为了演示 Notification/AlarmToast 需要如下设置一个后台任务-->
<Extension Category="windows.backgroundTasks" EntryPoint="SampleForAlarmToast">
<BackgroundTasks>
<Task Type="audio" />
<Task Type="timer" />
</BackgroundTasks>
</Extension>
* 3、系统静音也能播放声音
* 4、不受免打扰时间的限制
*/ using System;
using Windows.ApplicationModel.Background;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation; namespace Windows81.Notification
{
public sealed partial class AlarmToast : Page
{
public AlarmToast()
{
this.InitializeComponent(); this.Loaded += AlarmToast_Loaded;
} protected async override void OnNavigatedTo(NavigationEventArgs e)
{
try
{
// 向系统请求成为闹钟应用的权限,会弹出确认对话框
await AlarmApplicationManager.RequestAccessAsync().AsTask(); // 获取当前应用程序的成为闹钟应用的权限(AlarmAccessStatus 枚举)
// Unspecified - 用户未响应应用程序设置警报的权限请求
// AllowedWithWakeupCapability - 用户已经为应用程序授予设置警报的权限,并且警报可以将计算机从待机状态唤醒
// AllowedWithoutWakeupCapability - 用户已经为应用程序授予设置警报的权限,但是警报无法将计算机从待机状态唤醒
// Denied - 用户已拒绝该应用程序设置警报的权限
AlarmAccessStatus alarmAccessStatus = AlarmApplicationManager.GetAccessStatus();
lblMsg.Text = alarmAccessStatus.ToString();
}
catch (Exception ex)
{
lblMsg.Text = ex.ToString();
}
} void AlarmToast_Loaded(object sender, RoutedEventArgs e)
{
// 关于 toast 通知详见:http://www.cnblogs.com/webabcd/archive/2013/06/20/3145356.html
string toastXmlString =
"<toast duration=\"long\">\n" +
"<visual>\n" +
"<binding template=\"ToastText02\">\n" +
"<text id=\"1\">text1</text>\n" +
"<text id=\"2\">text2</text>\n" +
"</binding>\n" +
"</visual>\n" +
"<commands scenario=\"alarm\">\n" + // 除了 alarm 还有 incomingCall
"<command id=\"snooze\"/>\n" + // snooze 代表在闹钟 toast 中显示“暂停”按钮(小睡一会)
"<command id=\"dismiss\"/>\n" + // dismiss 代表在闹钟 toast 中显示“取消”按钮
"</commands>\n" +
// 闹钟铃声: Notification.Default, Notification.IM, Notification.Mail, Notification.Reminder, Notification.SMS, Notification.Looping.Alarm, Notification.Looping.Alarm2, Notification.Looping.Alarm3, Notification.Looping.Alarm4, Notification.Looping.Alarm5, Notification.Looping.Alarm6, Notification.Looping.Alarm7, Notification.Looping.Alarm8, Notification.Looping.Alarm9, Notification.Looping.Alarm10, Notification.Looping.Call, Notification.Looping.Call2, Notification.Looping.Call3, Notification.Looping.Call4, Notification.Looping.Call5, Notification.Looping.Call6, Notification.Looping.Call7, Notification.Looping.Call8, Notification.Looping.Call9, Notification.Looping.Call10
"<audio src=\"Notification.Looping.Alarm2\" loop=\"true\" />\n" +
"</toast>\n"; var toastDOM = new Windows.Data.Xml.Dom.XmlDocument();
toastDOM.LoadXml(toastXmlString); var toastNotifier = Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier();
// 闹钟 toast 提示出现后,如果点击“暂停”(snooze)按钮,则第 3 个参数指定的时间过后继续弹出闹钟 toast,本例是 120 秒
var customAlarmScheduledToast = new Windows.UI.Notifications.ScheduledToastNotification(toastDOM, DateTime.Now.AddSeconds(), TimeSpan.FromSeconds(), );
toastNotifier.AddToSchedule(customAlarmScheduledToast);
}
}
}
2、win8.1 中的 tile 模板增加到 75 个
Tile.xaml
<Page
x:Class="Windows81.Notification.Tile"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows81.Notification"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<Grid.Resources>
<Style x:Key="ItemTitleStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="14.667"/>
</Style> <ItemsPanelTemplate x:Key="StoreFrontGridItemsPanelTemplate">
<WrapGrid MaximumRowsOrColumns="3" VerticalChildrenAlignment="Top" HorizontalChildrenAlignment="Left"/>
</ItemsPanelTemplate> <Style x:Key="StoreFrontTileStyle" TargetType="GridViewItem">
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="Height" Value="310" />
<Setter Property="Width" Value="310" />
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="5" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Top" />
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="TabNavigation" Value="Local" />
</Style> <DataTemplate x:Key="StoreFrontTileTemplate">
<Grid HorizontalAlignment="Left" Background="Transparent">
<StackPanel Orientation="Vertical">
<TextBlock TextWrapping="Wrap" VerticalAlignment="Center" Text="{Binding FileName}" HorizontalAlignment="Left" />
<Image Source="{Binding Path}" Stretch="None" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,10,0,0"/>
</StackPanel>
</Grid>
</DataTemplate>
</Grid.Resources> <!--显示 75 种不同的 Tile 模板-->
<GridView x:Name="gridView" Margin="120 0 0 0"
ItemTemplate="{StaticResource StoreFrontTileTemplate}"
ItemContainerStyle="{StaticResource StoreFrontTileStyle}"
ItemsPanel="{StaticResource StoreFrontGridItemsPanelTemplate}"
BorderBrush="LightGray" VerticalAlignment="Top"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
SelectionMode="None" />
</Grid>
</Page>
Tile.xaml.cs
/*
* win8.1 中的 tile 模板增加到 75 个
*
*
* 关于 tile 的基础请参见:http://www.cnblogs.com/webabcd/archive/2013/06/24/3151864.html
*
*
* win 8.1 中 tile 的新特性如下:
* 1、tile 分 4 种:小 = Square70x70, 中等 = Square150x150, 长方形 = Wide310x150, 大 = Square310x310
* 2、可以在 manifest 中指定 app 安装后默认的 tile 类型
* 3、使用 tile 模板时,其命名规则也变了,参见 NotificationsExtensions 项目(比如 win8 中的 TileSquareImage 在 win8.1 中变为了 TileSquare150x150Image)
* 4、tile 基础(通过 NotificationsExtensions 创建)参见:http://www.cnblogs.com/webabcd/archive/2013/06/24/3151864.html
* 5、tile 基础(通过手工构造 xml)参见:http://www.cnblogs.com/webabcd/archive/2013/06/17/3139740.html
* 6、如果想要支持 Square310x310,则必须要支持 Wide310x150
* 7、建议为缩放比例 0.8x、1x、1.4x 和 1.8x 提供相对应的资源,以达到更好的显示效果
* 8、tile 的通知队列,除了 TileUpdater.EnableNotificationQueue() 外还支持只在指定大小的 tile 上启用 tile 队列:TileUpdater.EnableNotificationQueueForSquare150x150(), TileUpdater.EnableNotificationQueueForSquare310x310(), TileUpdater.EnableNotificationQueueForWide310x150()
* 9、新增 SecondaryTile.PhoneticName,可以指定 SecondaryTile 的名字的拼音,系统将据此排序 UI
* 10、为了同时支持 win8 和 win8.1 新增了 fallback 属性,类似如下使用(找不到 TileSquare150x150Image 的话则用 TileSquareImage,找不到 TileWide310x150Image 的话则用 TileWideImage)
<tile>
<visual version="2">
<binding template="TileSquare150x150Image" fallback="TileSquareImage" branding="None">
<image id="1" src="Assets/Images/w6.png"/>
</binding>
<binding template="TileWide310x150Image" fallback="TileWideImage" branding="None">
<image id="1" src="Assets/Images/sq5.png"/>
</binding>
<binding template="TileSquare310x310Image" branding="None">
<image id="1" src="Assets/Images/sq6.png"/>
</binding>
</visual>
</tile>
*/ using System;
using System.Linq;
using Windows.ApplicationModel;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation; namespace Windows81.Notification
{
public sealed partial class Tile : Page
{
public Tile()
{
this.InitializeComponent();
} protected async override void OnNavigatedTo(NavigationEventArgs e)
{
// Windows81/Notification/tiles 文件夹内 75 张图片分别用于演示 Tile 的 75 种模板 var folder = await Package.Current.InstalledLocation.GetFolderAsync(@"Notification\tiles");
var files = await folder.GetFilesAsync(); var dataSource = from p in files
select new
{
FileName = p.DisplayName,
Path = "ms-appx:///Notification/tiles/" + p.Name
}; gridView.ItemsSource = dataSource;
}
}
}
OK
[源码下载]
重新想象 Windows 8.1 Store Apps (85) - 警报通知(闹钟), Tile 的新特性的更多相关文章
- 重新想象 Windows 8.1 Store Apps 系列文章索引
[源码下载] [重新想象 Windows 8 Store Apps 系列文章] 重新想象 Windows 8.1 Store Apps 系列文章索引 作者:webabcd 1.重新想象 Windows ...
- 重新想象 Windows 8.1 Store Apps (81) - 控件增强: WebView 之加载本地 html, 智能替换 html 中的 url 引用, 通过 Share Contract 分享 WebView 中的内容, 为 WebView 截图
[源码下载] 重新想象 Windows 8.1 Store Apps (81) - 控件增强: WebView 之加载本地 html, 智能替换 html 中的 url 引用, 通过 Share Co ...
- 重新想象 Windows 8.1 Store Apps (72) - 新增控件: AppBar, CommandBar
[源码下载] 重新想象 Windows 8.1 Store Apps (72) - 新增控件: AppBar, CommandBar 作者:webabcd 介绍重新想象 Windows 8.1 Sto ...
- 重新想象 Windows 8.1 Store Apps (73) - 新增控件: DatePicker, TimePicker
[源码下载] 重新想象 Windows 8.1 Store Apps (73) - 新增控件: DatePicker, TimePicker 作者:webabcd 介绍重新想象 Windows 8.1 ...
- 重新想象 Windows 8.1 Store Apps (74) - 新增控件: Flyout, MenuFlyout, SettingsFlyout
[源码下载] 重新想象 Windows 8.1 Store Apps (74) - 新增控件: Flyout, MenuFlyout, SettingsFlyout 作者:webabcd 介绍重新想象 ...
- 重新想象 Windows 8.1 Store Apps (75) - 新增控件: Hub, Hyperlink
[源码下载] 重新想象 Windows 8.1 Store Apps (75) - 新增控件: Hub, Hyperlink 作者:webabcd 介绍重新想象 Windows 8.1 Store A ...
- 重新想象 Windows 8.1 Store Apps (76) - 新增控件: SearchBox
[源码下载] 重新想象 Windows 8.1 Store Apps (76) - 新增控件: SearchBox 作者:webabcd 介绍重新想象 Windows 8.1 Store Apps 之 ...
- 重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件增加了 PlaceholderText 属性
[源码下载] 重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件 ...
- 重新想象 Windows 8.1 Store Apps (78) - 控件增强: ScrollViewer, FlipView, Popup
[源码下载] 重新想象 Windows 8.1 Store Apps (78) - 控件增强: ScrollViewer, FlipView, Popup 作者:webabcd 介绍重新想象 Wind ...
随机推荐
- C++的黑科技
周二面了腾讯,之前只投了TST内推,貌似就是TST面试了 其中有一个问题,"如何产生一个不能被继承的类",这道题我反反复复只想到,将父类的构造函数私有,让子类不能调用,最后归结出一 ...
- 康力优蓝机器人 -- 优友U05类人型机器人发布
[寒武计划]优友U05类人型机器人发布: http://digi.tech.qq.com/a/20151124/043234.htm?pgv_ref=aio2015&ptlang=2052 北 ...
- Binary Tree Postorder Traversal--leetcode难题讲解系列
https://leetcode.com/problems/binary-tree-postorder-traversal/ Given a binary tree, return the posto ...
- 自定义控件的自定义的属性attrs.xml下的declare-styleable中format详解
最近在摸索自定义控件,查找到一些自定义属性的一些资料,解决转载记载下来:看了此详解才方便理解! 我们在做项目的时候,由于android自带的属性不能满足需求,android提供了自定义属性的方法,其中 ...
- 构造Lambda表达式
/// <summary> /// 构造Lambda表达式 /// </summary> /// <typeparam name="T">< ...
- Delphi 10.1 Berlin Starter Edition
Delphi 10.1 Berlin Starter Edition Embarcadero® Delphi 10.1 Berlin Starter is a great way to get sta ...
- C# 装箱与拆箱
知识点 值类型. 值类型是在栈中分配内存,在声明时初始化才能使用,不能为null. 值类型超出作用范围系统自动释放内存. 主要由两类组成:结构,枚举(enum),结构分为以下几类: ...
- 前端模块化:RequireJS
前言 前端模块化能解决什么问题? 模块的版本管理 提高可维护性 -- 通过模块化,可以让每个文件职责单一,非常有利于代码的维护 按需加载 -- 提高显示效率 更好的依赖处理 -- 传统的开发模式,如果 ...
- 使用 IntelliJ IDEA 2016和Maven创建Java Web项目的详细步骤及相关问题解决办法
Maven简介 相对于传统的项目,Maven 下管理和构建的项目真的非常好用和简单,所以这里也强调下,尽量使用此类工具进行项目构建, 它可以管理项目的整个生命周期. 可以通过其命令做所有相关的工作,其 ...
- iOS-动态计算Label的高度
一. 要求 1.根据网络请求的回来的字符串内容,动态计算Label的高度. 二. 注意点 1. 要注意设置label 的 numberOfLines 为0; 2. MAXFLOAT 的作用. 设置高度 ...