`
longgangbai
  • 浏览: 7256856 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论
阅读更多

            针对Titanium中需要特定的功能可能需要开发者定制,如二维码等。所以需要自己开发相关的module在项目中使用。

 

开发环境准备

  下载titanium studio

  下载eclipse + ant

  下载android sdk

  下载android ndk

 

官方推荐:

注意:必须参考下面的官方网址,   python在windows环境下不用安装,本身titanium studio已经装了

https://wiki.appcelerator.org/display/guides/Android+Module+Development+Guide

 

 

关于titanium自动生成module的模板在:

${Titanium SDK}\mobilesdk\win32\1.8.2\module\android\templates\src\___MODULE_ID_AS_FOLDER___

本文将简单一下关于titanium module的描述。

 

 

ant编译module工程

1)将此工程放到eclipse下(带有ant环境),编辑builder.properties文件,加上android ndk路径。如下:

android.ndk=C:\android-ndk\android-ndk-r8

 

针对android的NDK如果在环境变量中设置,那么就可以不再builder.properties文件中设置,否则必须设置。

 

 

模块代理类如下:

/**
 * This file was auto-generated by the Titanium Module SDK helper for Android
 * Appcelerator Titanium Mobile
 * Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 *
 */
package com.easyway;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.util.Log;
import org.appcelerator.titanium.util.TiConfig;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.view.TiCompositeLayout;
import org.appcelerator.titanium.view.TiCompositeLayout.LayoutArrangement;
import org.appcelerator.titanium.view.TiUIView;

import android.app.Activity;


// This proxy can be created by calling Hellomodule.createExample({message: "hello world"})
@Kroll.proxy(creatableInModule=HellomoduleModule.class)
public class ExampleProxy extends TiViewProxy
{
	// Standard Debugging variables
	private static final String LCAT = "ExampleProxy";
	private static final boolean DBG = TiConfig.LOGD;

	private class ExampleView extends TiUIView
	{
		public ExampleView(TiViewProxy proxy) {
			super(proxy);
			LayoutArrangement arrangement = LayoutArrangement.DEFAULT;

			if (proxy.hasProperty(TiC.PROPERTY_LAYOUT)) {
				String layoutProperty = TiConvert.toString(proxy.getProperty(TiC.PROPERTY_LAYOUT));
				if (layoutProperty.equals(TiC.LAYOUT_HORIZONTAL)) {
					arrangement = LayoutArrangement.HORIZONTAL;
				} else if (layoutProperty.equals(TiC.LAYOUT_VERTICAL)) {
					arrangement = LayoutArrangement.VERTICAL;
				}
			}
			setNativeView(new TiCompositeLayout(proxy.getActivity(), arrangement));
		}

		@Override
		public void processProperties(KrollDict d)
		{
			super.processProperties(d);
		}
	}


	// Constructor
	public ExampleProxy()
	{
		super();
	}

	@Override
	public TiUIView createView(Activity activity)
	{
		TiUIView view = new ExampleView(this);
		view.getLayoutParams().autoFillsHeight = true;
		view.getLayoutParams().autoFillsWidth = true;
		return view;
	}

	// Handle creation options
	@Override
	public void handleCreationDict(KrollDict options)
	{
		super.handleCreationDict(options);
		
		if (options.containsKey("message")) {
			Log.d(LCAT, "example created with message: " + options.get("message"));
		}
	}
	
	// Methods
	@Kroll.method
	public void printMessage(String message)
	{
		Log.d(LCAT, "printing message: " + message);
	}


	@Kroll.getProperty @Kroll.method
	public String getMessage()
	{
        return "Hello World from my module";
	}

	@Kroll.setProperty @Kroll.method
	public void setMessage(String message)
	{
	    Log.d(LCAT, "Tried setting module message to: " + message);
	}
}

 

 

 

/**
 * This file was auto-generated by the Titanium Module SDK helper for Android
 * Appcelerator Titanium Mobile
 * Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 *
 */
package com.easyway;

import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.annotations.Kroll;

import org.appcelerator.titanium.TiApplication;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.kroll.common.TiConfig;


@Kroll.module(name="Hellomodule", id="com.easyway")
public class HellomoduleModule extends KrollModule
{

	// Standard Debugging variables
	private static final String LCAT = "HellomoduleModule";
	private static final boolean DBG = TiConfig.LOGD;

	// You can define constants with @Kroll.constant, for example:
	// @Kroll.constant public static final String EXTERNAL_NAME = value;
	
	public HellomoduleModule()
	{
		super();
	}

	@Kroll.onAppCreate
	public static void onAppCreate(TiApplication app)
	{
		Log.d(LCAT, "inside onAppCreate");
		// put module init code that needs to run when the application is created
	}

	// Methods
	@Kroll.method
	public String example()
	{
		Log.d(LCAT, "example called");
		return "hello world";
	}
	
	// Properties
	@Kroll.getProperty
	public String getExampleProp()
	{
		Log.d(LCAT, "get example property");
		return "hello world";
	}
	
	
	@Kroll.setProperty
	public void setExampleProp(String value) {
		Log.d(LCAT, "set example property: " + value);
	}

}

 

 

编译成功后会在dist目录下生成相应的zip包。

 

如何调用的module

1.配置tiapp.xml文件中模块

    <modules>
      <module version="1.1">com.easyway</module>
    </modules>

 2.将zip解压之后的modules拷贝到对应的titanium module应用的根目录中。

如下:

 

3.调用:

// This is a test harness for your module
// You should do something interesting in this harness 
// to test out the module and to provide instructions 
// to users on how to use it by example.


// open a single window
var win = Ti.UI.createWindow({
	backgroundColor:'white'
});
var label = Ti.UI.createLabel();
win.add(label);
win.open();

// TODO: write your module tests here
var hellomodule = require('com.easyway');
Ti.API.info("module is => " + hellomodule);

label.text = hellomodule.example();

Ti.API.info("module exampleProp is => " + hellomodule.exampleProp);
hellomodule.exampleProp = "This is a test value";

if (Ti.Platform.name == "android") {
	var proxy = hellomodule.createExample({
		message: "Creating an example Proxy",
		backgroundColor: "red",
		width: 100,
		height: 100,
		top: 100,
		left: 150
	});

	proxy.printMessage("Hello world!");
	proxy.message = "Hi world!.  It's me again.";
	proxy.printMessage("Hello world!");
	win.add(proxy);
}

 

 

 

 

分享到:
评论

相关推荐

    titanium_module_jpush_android:极光推送的module,针对Android平台

    titanium_module_jpush_android 极光推送的安卓封装(ios平台我用rpush在自己的服务器发,没做module) 作者刘明星 Appcelerator安卓开发比较悲催,无法使用google的gcm,只能绕道,用国内的服务,极光推送还不错。 ...

    vscode-appcelerator-titanium:用于Visual Studio Code的Appcelerator开发工具和UI包

    命令描述键绑定Titanium: Create application 创建一个新的Titanium应用程序项目-- Titanium: Create module 创建一个新的Titanium模块项目-- Titanium: Enable LiveView 启用LiveView -- Titanium: Disable ...

    android-parse-titanium-module:Parse.com Android SDK 的 Titanium 模块

    适用于 Android 的 Parse.com Titanium 模块关于模块该模块的存在是为了向 Appcelerator 开发人员提供一个开源(在 MIT 许可下获得许可)Android 模块来包装 Android Parse SDK 的功能。 它试图保持与 iOS Titanium ...

    ti.moddevguide:Appcelerator Titanium本机模块指南

    本机模块开发人员可以使用它来了解为Titanium构建自己的本机模块的基本和高级概念。功能性此示例模块在iOS和Android上提供以下组件: 模块/应用生命周期 查看/代理关系 发送和接收事件( fireEvent和...

    TiLookback:用于包装 Lookback SDK 的 Appcelerator Titanium 模块

    回顾描述TiLookback 模块包装了 Lookback iOS SDK 以在 Titanium 移动应用程序中使用iOS 回溯 SDK 版本 0.6 HD 此模块仅应用于临时或开发项目。 如果您希望在 App Store 项目中使用它,请将此存储库中的 Loopback....

    triple-demo:三重演示

    三重演示三重演示先决条件 &gt;= 0.10 用于Android开发的 用于 iOS 开发的 注册一个设置如果您已经安装了 Titanium 环境,则可以直接跳到安装triple . $ sudo npm install -g titanium$ titanium setup$ titanium sdk ...

    YaTriple:又一个三倍

    $ ti create --type module --platforms ios --id foo --name foo --workspace-dir . --url http:// $ cd foo/iphone $ ./build.py $ yatriple -a ../example/app.js -m ./foo-iphone-1.0.0.zip 安装 $ npm install ...

    playcognition:逐步完成Play Cognition网站

    该项目的目标是存储开发本机Node.js插件所需的所有逻辑,而不必检查NODE_MODULE_VERSION并使自己陷入宏观NODE_MODULE_VERSION 。 该项目还包含一些帮助程序实用程序,这些实用程序使附加组件的开发更加愉快。新闻与...

    Predestinate:自己的项目,社交交友,自己封装的socket

    app为实际开发module。其他module视功能进行添加 app目录具体文件夹功能: ./bean/目录为统一实体类存放目录,在该目录下根据具体的模块分别建立二级目录存放bean对象。如./bean/center存放个人中心的bean对象。 ./...

    shine-server

    此应用程序是为 ShineSeniors 项目开发的。 它基于 Django 1.6.10 和两勺 django 模板。 主要目标 来自MQTT经纪人的Demulplex数据(包括传感器读数,日志和统计信息) REST API 层 设置 在你的 bashrc 文件中,根据...

    网络应用

    HazPanEnCasa 该项目的生成: 版本11.0.2 版本5.2.3 版本11.0.3 版本5.0开发服务器您必须将以下命令复制并粘贴到终端中: git clone git@github.com:hazpanencasa/webapp.gitnpm install然后运行ng serve开发服务器...

    Project-Heart-Disease-

    您还可以使用ng generate directive|pipe|service|class|guard|interface|enum|module 。 建造 运行ng build来构建项目。 构建工件将存储在dist/目录中。 使用--prod标志进行生产构建。 运行单元测试 运行ng test以...

    angular-adminLTE:集成angular 6 + admin LTE

    开发服务器为开发服务器运行ng serve 。 导航到http://localhost:4200/ 。 如果您更改任何源文件,该应用程序将自动重新加载。代码脚手架运行ng generate component component-name生成一个新的组件。 您还可以使用...

    todomvc-angular

    开发服务器为开发服务器运行ng serve 。 导航到http://localhost:4200/ 。 如果您更改任何源文件,该应用程序将自动重新加载。代码脚手架运行ng generate component component-name生成一个新的组件。 您还可以使用...

    todo-mvc-angular-5-or-6-:这是todoMVC的一个分支

    您还可以使用ng generate directive|pipe|service|class|guard|interface|enum|module 。 建造 运行ng build来构建项目。 构建工件将存储在dist/目录中。 使用--prod标志进行生产构建。 运行单元测试 运行ng test以...

    carRental-FrontEnd

    您还可以使用ng generate directive|pipe|service|class|guard|interface|enum|module 。 建造 运行ng build来构建项目。 构建工件将存储在dist/目录中。 使用--prod标志进行生产构建。 运行单元测试 运行ng test以...

    crud-Angular9

    开发服务器为开发服务器运行ng serve 。 导航到http://localhost:4200/ 。 如果您更改任何源文件,该应用程序将自动重新加载。代码脚手架运行ng generate component component-name生成一个新的组件。 您还可以使用...

    angular-lecture1-task1

    开发服务器为开发服务器运行ng serve 。 导航到http://localhost:4200/ 。 如果您更改任何源文件,该应用程序将自动重新加载。代码脚手架运行ng generate component component-name生成一个新的组件。 您还可以使用...

    portafolio:使用angular创建一个Web应用程序

    开发服务器为开发服务器运行ng serve 。 导航到http://localhost:4200/ 。 如果您更改任何源文件,该应用程序将自动重新加载。代码脚手架运行ng generate component component-name生成一个新的组件。 您还可以使用...

    angular-qiankun-base-demo:前昆的URL更改错误

    您还可以使用ng generate directive|pipe|service|class|guard|interface|enum|module 。 建造 运行ng build来构建项目。 构建工件将存储在dist/目录中。 使用--prod标志进行生产构建。 运行单元测试 运行ng test以...

Global site tag (gtag.js) - Google Analytics