新闻资讯APP开发流程(三)-- app.js

 

 如果注释里写的一样,我们将使用单window程序模板,

 在app.js里我们主要做几件事情:

-引导程序并载入我们需要的数据

-检测程序运行的设备类型,平台版本或网络连接

-载入并打开顶层的UI组件

 

 

 我们为android、iphone、ipad平台做判断,根据相应的平台载入相应的程序模板。

而事实上,因为校长追求平台UI的统一性,其实以上操作是多余的,也可以不用,因为所有的UI都是共用的,我们将全程使用view组件,view组件相当于web开发中的div层,所以这样做的结果就是所有平台的UI都是一样的,而且自定义UI样式非常方便,比如说,如果底部使用传统的tabGroup,那么在titanium中你会发现,tab样式是非常难改变的。

 

并且titanium最佳实践里提到我们尽可能使用单上下文。

 

 

 

 

app.js

/*
 * Single Window Application Template:
 * A basic starting point for your application.  Mostly a blank canvas.
 * 
 * In app.js, we generally take care of a few things:
 * - Bootstrap the application with any data we need
 * - Check for dependencies like device type, platform version or network connection
 * - Require and open our top-level UI component
 *  
 */

//bootstrap and check dependencies
if (Ti.version < 1.8 ) {
    alert('Sorry - this application template requires Titanium Mobile SDK 1.8 or later');          
}

// This is a single context application with mutliple windows in a stack
(function() {
    //determine platform and form factor and render approproate components
    var osname = Ti.Platform.osname,
        version = Ti.Platform.version,
        height = Ti.Platform.displayCaps.platformHeight,
        width = Ti.Platform.displayCaps.platformWidth;
    
    //considering tablet to have one dimension over 900px - this is imperfect, so you should feel free to decide
    //yourself what you consider a tablet form factor for android
    var isTablet = osname === 'ipad' || (osname === 'android' && (width > 899 || height > 899));
    
    var Window;
    if (isTablet) {
        Window = require('ui/tablet/ApplicationWindow');
    }
    else {
        // Android uses platform-specific properties to create windows.
        // All other platforms follow a similar UI pattern.
        if (osname === 'android') {
            Window = require('ui/handheld/android/ApplicationWindow');
        }
        else {
            Window = require('ui/handheld/ApplicationWindow');
        }
    }
    new Window().open();
})();

转载于:https://www.cnblogs.com/xiaozhanga4/archive/2012/06/21/2557774.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值