zoukankan      html  css  js  c++  java
  • windows8 重力加速度感应

    加速度传感器
    演示了使用Windows.Devices.Sensors。 加速度计的API。
    这个简单的允许用户浏览加速军队沿X -,Y -,和一3-axis Z-axes加速度计。你可以选择三种情况之一:
    •加速度计数据的事件
    •加速度计摇事件
    •现有加速度计阅读
    Acclerometer数据事件
    当你选择使按钮加速度计数据项目的选择,应用程序将开始流加速度传感器读数中实时。
    加速度计摇事件
    当你选择使按钮加速度计摇事件选项,这个应用程序显示的累积数目的震动的事件每一次事件发生。(这个应用程序首先增加事件计数,然后使最近的价值。)
    现有加速度计阅读
    当你选择让按钮为当前的加速度计阅读选项,这个应用程序将恢复最近的加速度计的阅读。

     class SuspensionManager

    {
        static private Dictionary<stringobject> sessionState_ = new Dictionary<stringobject>();
        static private List<Type> knownTypes_ = new List<Type>();
        private const string filename = "_sessionState.xml";

        // Provides access to the currect session state
        static public Dictionary<stringobject> SessionState
        {
            get { return sessionState_; }
        }

        // Allows custom types to be added to the list of types that can be serialized
        static public List<Type> KnownTypes
        {
            get { return knownTypes_; }
        }

        // Save the current session state
        static async public Task SaveAsync()
        {
            // Get the output stream for the SessionState file.
            StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
            IRandomAccessStream raStream = await file.OpenAsync(FileAccessMode.ReadWrite);
            using (IOutputStream outStream = raStream.GetOutputStreamAt(0))
            {
                // Serialize the Session State.
                DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary<stringobject>), knownTypes_);
                serializer.WriteObject(outStream.AsStreamForWrite(), sessionState_);
                await outStream.FlushAsync();
            }
        }

        // Restore the saved sesison state
        static async public Task RestoreAsync()
        {
            // Get the input stream for the SessionState file.
            try
            {
                StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(filename);
                if (file == nullreturn;
                IInputStream inStream = await file.OpenSequentialReadAsync();

                // Deserialize the Session State.
                DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary<stringobject>), knownTypes_);
                sessionState_ = (Dictionary<stringobject>)serializer.ReadObject(inStream.AsStreamForRead());
            }
            catch (Exception)
            {
                // Restoring state is best-effort.  If it fails, the app will just come up with a new session.
            }
        }
    }

    完整Demo

    /Files/risk/windows8/重力加速度感应sample.rar 

    作者:risk
    出处:http://www.cnblogs.com/risk
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    快速启动jar包脚本【Linux】
    解决Linux报错:/bin/bash^M: 坏的解释器: 没有那个文件或目录
    学习——nginx(2021/09/23)
    react hook中的状态管理方式
    findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of DomWrapper which is inside StrictMode.
    祝胡老师节日快乐
    vue3+ts+AntV/L7加载钻取地图
    实用的 Bash 快捷键
    react antd form 自定义表单验证validator 需要注意的细节,否则会无法触发表单提交。
    execjs
  • 原文地址:https://www.cnblogs.com/risk/p/2494691.html
Copyright © 2011-2022 走看看