分类目录归档:webos开发

hp palm webos 开发

enyo.kind

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
enyo.kind = function(inProps) {
    // kind-name to constructor map could be faulty now that a new kind exists, so we simply destroy the memoizations
    enyo._kindCtors = {};
    // extract 'name' property
    var name = inProps.name || "";
    // extract 'kind' property
    var kind = inProps.isa || inProps.kind;
    // if we have an explicit kind property that is undefined, we probably tried
    // to reference an kind that is not yet in scope
    if ((kind === undefined) && ("kind" in inProps)) {
        throw "enyo.kind: Attempt to subclass an 'undefined' kind. Check dependencies for [" + name + "].";
    }
    // establish base class reference
    var base = kind && enyo.constructorForKind(kind);
    var isa = base && base.prototype || null;
    // make a boilerplate constructor
    var ctor = enyo.kind.makeCtor();
    delete inProps.name;
    // semi-reserved word 'constructor' causes problems with Prototype and IE, so we rename it here
    if (inProps.hasOwnProperty("constructor")) {
        inProps._constructor = inProps.constructor;
        delete inProps.constructor;
    }
    // create our prototype
    //ctor.prototype = isa ? enyo.delegate(isa) : {};
    enyo.setPrototype(ctor, isa ? enyo.delegate(isa) : {});
    // put in our props
    enyo.mixin(ctor.prototype, inProps);
    // alias class name as 'kind' in the prototype
    ctor.prototype.kindName = name;
    // cache super-class constructor
    ctor.prototype.base = base;
    // reference our real constructor
    ctor.prototype.ctor = ctor;
    // support pluggable 'features'
    enyo.forEach(enyo.kind.features, function(fn){ fn(ctor, inProps); });
    // put reference into namespace
    enyo.setObject(name, ctor);
    return ctor;
};

kernel/Oop.js
enyo.kind

enyo.kind: function(inProps)
Creates a JavaScript constructor function with a prototype defined by inProps.

enyo.kind makes it easy to build a constructor-with-prototype (like a class) that has advanced features like prototype-chaining (inheritance).

A plug-in system is included for extending the abilities of the kind generator, and constructors are allowed to perform custom operations when subclassed.

Special Property Names

Generally the properties defined in inProps are copied directly to the generated prototype, but certain property names trigger special processing.

Examples of special properties are:

name: the name property defines the name of the created constructor in the global namespace (intermediate objects are created automatically). name is not copied directly to the prototype, but is instead stored as kindName.

1
2
3
4
5
6
7
8
9
// Creates a function MyNamespace.MyKind with a prototype.
// MyNamespace.MyKind.prototype.kindName is set to "MyNamespace.MyKind".
// MyNamespace.MyKind.prototype.plainProperty is set to "foo".
enyo.kind({
    name: "MyNamespace.MyKind"
    plainProperty: "foo"
});
// Make an instance of the new kind
var myk = new MyNamespace.MyKind();

kind: the name of or reference to a kind to derive from, like a super-class. The new constructor’s prototype is chained to the prototype specified by kind, and the base property in the new prototype is set to reference the kind constructor.

1
2
3
4
5
6
7
// Create a function MyKind with a prototype, derived from enyo.Object.
// MyKind.prototype.kindName is set to "MyKind".
// MyKind.prototype.base is set to enyo.Object.
enyo.kind({
    name: "MyKind",
    kind: enyo.Object
});

constructor: a function to call when a new instance is created. Actually stored on the prototype as _constructor.

1
2
3
4
5
6
7
8
9
10
11
// Create a function MyKind with a prototype, derived from enyo.Object.
// _constructor_ is called when an instance is created.
enyo.kind({
    name: "MyKind",
    kind: enyo.Object,
    constructor: function() {
        this.instanceArray = [];
        // call the constructor inherited from Object
        this.inherited(arguments);
    }
});

statics: properties from any statics object are copied onto the constructor directly, instead of the prototype.

1
2
3
4
5
6
7
8
9
10
11
// Create a kind with a static method.
enyo.kind({
    name: "MyKind",
    statics: {
        info: function() {
            return "MyKind is a kind with statics.";
        }
    }
});
// invoke the static info() method of MyKind
console.log(MyKind.info());

Certain kinds in the framework define their own special properties. For example, see the published property supported by enyo.Object.

inherited

The inherited feature allows you to easily call the super-kind method for any method that has been overridden.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
enyo.kind({
    name: "MyKind",
    doWork: function() {
        this.work++;
    }
});

enyo.kind({
    name: "MyDerivedKind",
    kind: "MyKind",
    doWork: function() {
        if (this.shouldDoWork) {
            this.inherited(arguments);
        }
    }
});

The first argument to inherited is required to be the literal arguments, which is a special JavaScript variable that contains information about the executing function.

mojo的工程目录结构

未经许可,请勿转载。

app 包含组成一个WEBOS程序所需要的assistants, models, 和views. 程序通过查找类似的文件名来关联assistants和views。如– first-assistant.js和first-scene.html.
assistants Assistant是一些avascript函数的集合。使用SDK提供的controller来定义stage, scene或application的行为
models 包含程序使用的数据模型. 并不是所有的程序都需要models, 所以不存在models目录或目录为空是很正常的.
views 存放每一个scene, 包含scene的主要HTML视图文件和scene用来显示动态数据的模板。
images 保存程序中使用的到图片
stylesheets 包含程序指定的样式,并用修改程序默认的风格。
Main.css 包含程序的样式
Appinfo.json appinfo.json 文件包含加载和启动程序的一些必要信息. 最主要的属性是ID, 每个程序的ID必须不同,ID对应到程序的目录名称。
Icon.png 在Launcher中显示的图标. 尺寸为 64 * 64像素.
Index.html Stage的HTML布局文件. 提供程序的总体布局. 当scenes进入stage时,他们的HTML (在views文件夹中)文件导入到index.html中.
Sources.json 这个文件告诉框架每个scene 应该使用哪个assistant和view。(包括stage assistant和application assistant).

webos开发之eclipse插件安装

eclipse插件地址:https://cdn.downloads.palm.com/sdkdownloads/eclipse-update-site/site.xml

安装完成后重启eclipse

创建一个helloworld程序。然后启动模拟器,再run as webos application。

hp官方教程:https://developer.palm.com/index.php?option=com_content&id=1639#InstallingEclipsewiththeSDK-CreateApp

webos Stages的种类及创建stage

mojo提供了四种基本的Stage。
card(默认):这是经常使用的一种,最大化后会充满整个屏幕,如果不是全屏模式的话,在card的底部会显示提示条, 顶部会有状态栏。
Dashboard:用来给一些后台运行的程序显示环境信息或提供一个动态的窗口。
Banner Alert:相当于WINDOWS开发里的气泡吧。出在card底部显示一些提示信息,包含一个图标和文字信息,几秒钟后会消失。
Pop-up Alert:相当与WINDOWS里的弹出框,有些按钮在里面,必须在用户点了某一个按钮后才消失。

创建stage
createStageWithCallback()方法用来创建stage.调用需要三个参数。第一个参数是配置参数,第二个是回调函数,就是创建窗口结束后要进行的操作,第三个是窗口的类型,上面四种类型中的一种,可选参数,默认为card.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var MainStageName = "main";

function AppAssistant (appController) {
}

AppAssistant.prototype.handleLaunch = function (launchParams) {
  // Look for an existing main stage by name.
  var stageProxy = this.controller.getStageProxy(MainStageName);
  var stageController = this.controller.getStageController(MainStageName);
 
  //如果etStageController()和 getStageProxy()都返回空, 则说明stage还没有被创建或者已创建但不可用。
  if (stageProxy) {
      // 如果stage已存在,就把它显示到界面最前面
      // 如果只有proxy(没有stageController), 那stage已经被focus了。
      if (stageController) {
          stageController.window.focus();
      }
  } else {
      // Create a callback function to set up the new main stage
      // after it is done loading. It is passed the new stage controller
      // as the first parameter.
      var pushMainScene = function(stageController) {
          stageController.pushScene("main");
      };
      var stageArguments = {name: "MainStageName", lightweight: true};
      // 最后一个参数指定stage类型
      this.controller.createStageWithCallback(stageArguments, pushMainScene, "card");
  }
};

webos mojo 开发国际化

为了支持国际化,render会先根据指定的相对路径来查找应用的resource目录。例如,如果以模板路径’main/details’来调用render,并且当前语言环境是”en_us”。render就会先去resources/es_us/views/main/details.html’中查找模板文件,如果找不到,再去查找’views/main/details.html’

所以国际化的时候,只需要在resources目录下创建不同的语言环境目录,然后把不同语言的模板文件放在这个目录里,把默认语言的模板文件放在views/main下。