J2ME之家

匿名投稿 投稿指南 RSS订阅 J2ME通告:
搜索: 您的位置主页>Windows Mobile>

windows mobile使用方向感知控件创建自适应用户界面

2008-8-13 22:09:56 来源:microsoft 责任编辑: 【 点击: 我要投稿 [进入论坛]

移动应用积木

  • 组合界面应用积木
  • 配置应用积木
  • 连接监视应用积木
  • 无连接服务代理应用积木
  • 数据访问应用积木
  • 密码验证应用积木
  • 订阅管理应用积木
  • 程序更新应用积木

 

组合界面应用积木

  • 常用名称是 Mobile CAB
  • 提供创建复杂用户界面的架构和实现
    • 提倡独立构造组件,并且相互协作
    • 使用 MVP(Model – View – Presenter)设计模式创建用户界面
    • 使用服务注册来构架组件
    • 功能模块间允许独立开发
    • 组件间使用最少的信息数据共享和进行通信
  • 非常有价值,但需要投入大量的时间去研究和适应

 

配置应用积木

  • .NET CF 2.0 不支持应用配置文件
  • 配置应用积木实现支持:桌面版 Framework 的子集
    • 创建、定义配置文件的类库
    • 读取和枚举配置文件的 API
    • 读取配置文件加密内容
  • ConfigSectionEncrypt 工具,包括加密配置文件部分内容

 

定制配置例子

在 <configSections>,定义设置类型是 ConfigSectionHandler

<configSections>
  <section name="myConfigSettings" type="MyConfig.MyNamespace.MySettingsSection,MyConfig.Assembly" />
</configSections>
  <myConfigSettings>
<mySettingItems>
    <add Name="Item1" Type="CustomItem1" Value="1" />
    <add Name="Item2" Type="CustomItem2" Value="2" Alternative="Item3" />
    <add Name="Item3" Type="CustomItem3" Value="3" />
  </mySettingItems>
</myConfigSettings>


定义 ConfigurationSectionHandler

  • 定义 Section Handler 的类
    • Custom Configuration Element
    • Custom Configuration Element Collection
    • Custom Configuration Section
  • Simple process
    • 从 Microsoft.Patterns.Mobile.Configuration 中的类继承
    • 定义属性和方法

 

public class mySettingItemElement: ConfigurationElement
{
  [ConfigurationProperty("Name", IsRequired = true)]
  public String Name
  {
    get { return (String)this["Name"]; }
  }
    …
}

从配置文件中读取配置

  • 读取配置与 .Net Framework 中 System.Configuration 使用是一样的

     

    using Microsoft.Practices.Mobile.Configuration;

      MySettingsSection configSection=ConfigurationManager.GetSection(sectionName) as MySettingsSection;
      foreach (MySettingItemElement item in configSection.MySettingItems)
      {     String itemName = item.Name;
        String itemType = item.Type;
        Int32 itemValue = item.Value;
        String itemAlternative = String.Empty;
        if (item.Alternative != null)
          itemAlternative = item.Alternative;
        // Do something with the configuration data...
      }

    连接监视器应用积木

    • 监视设备上网络连接
      • 电话:GPRS/CDMA/UMTS(Universal Mobile Telecommunications System,3G 技术)
      • 网卡:WiFi,Wired connection
      • 桌面连接:DTPT(Desktop passthrough from cradle)
    • API 提供连接状态,网络状态,网络改变事件等等
    • 在 App.config 中定义连接监视器设置:

     

    <Connections>
      <ConnectionItems>
        <add Type="CellConnection" Price="8"/>
        <add Type="NicConnection" Price="2"/>
        <add Type="DesktopConnection" Price="1"/>
      </ConnectionItems>
    </Connections>

    无连接服务代理应用积木

  • 管理在无网络连接情况下使用 WebService 的服务

     

    无连接服务代理应用积木

  • 代码例子:初始化请求管理器

     

    public void SetupDisconnectedAgent()
    {
      // Get the catalog of endpoints from the config file.
      IEndpointCatalog catalog = GetEndpointCatalog();
      // Create the connection monitor
      ConnectionMonitor cnMonitor = GetConnectionMonitor();
      // Create the connection adapter
      IConnectionMonitor connAdapter=new ConnectionMonitorAdapter(cnMonitor);
      // Create request manager to manage the disconnected
      // transmissions
      RequestManager reqManager = RequestManager.Instance;
      // Initialise the request mgr with endpoints,
      // connections, & database
      reqManager.Initialize(catalog, connAdapter,
        _databaseManager.Database);
      reqManager.StartAutomaticDispatch();
    }

    产生客户端代理

    • 添加 Web 引用
      • 在 Solution Explorer 中右键选择 Web Reference
      • 选择 Mobile Factory – 在菜单选择创建 Disconnected Service Agent
      • 使用默认向导创建

     

    发送请求

    • 发送请求和调用 Web Service 方法一样
      • 调用 DisconnectedServiceAgent proxy 的实例
      • DSA 在 SQL CE 数据库中保存请求
      • 请求管理器处理向 Web 服务器发送的请求

     

    // Get reference to the Request Manager
    RequestManager reqManager = RequestManager.Instance;
    // Create inst. of tool-generated Disconnected Service Agent
    OrderServiceDisconnectedAgent orderService = new OrderServiceDisconnectedAgent(reqManager.RequestQueue);
    // Queue a request to our Web service
    orderService.PostOrder(StoreID, userID, postData);

    处理返回结果

    • 在 web Service 调用结束调用回调函数
      • 使用工具产生回调方法
      • 在应用中根据需要进行更新

     

    public class OrderServiceDisconnectedAgentCallback : OrderServiceDisconnectedAgentCallbackBase
    {
      public override void OnPostOrderReturn(Request request, object[] parameters, object returnValue)
      {
        // Web service call successful ; handle the response…
      }
      public override OnExceptionAction OnPostOrderException(Request request, Exception ex)
      {
        // Web service threw exception – get it to retry
        return OnExceptionAction.Retry;
      }
    }


  • Tag:创建 适应 控件 感知 使用 方向   " < 应用
    责任编辑:
  • 用户名: (新注册)密码: 匿名:  请文明参与讨论,禁止漫骂攻击。
    评论总数: [ 查看全部 ] 网友评论
    热门文章
    关于我们 - 联系我们 - 广告服务 - 法律声明 - RSS订阅 - 网站地图 - 返回顶部