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
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    Maven关于web.xml中Servlet和Servlet映射的问题
    intellij idea的Maven项目运行报程序包找不到的错误
    修改Maven项目默认JDK版本
    刷题15. 3Sum
    刷题11. Container With Most Water
    刷题10. Regular Expression Matching
    刷题5. Longest Palindromic Substring
    刷题4. Median of Two Sorted Arrays
    刷题3. Longest Substring Without Repeating Characters
    刷题2. Add Two Numbers
  • 原文地址:https://www.cnblogs.com/risk/p/2494691.html
Copyright © 2011-2022 走看看