-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(android): add kotlin template and code base flag
Closes TIMOB-27906 Co-authored-by: Hans Knöchel <hansemannn@users.noreply.github.com>
- Loading branch information
1 parent
fd53a51
commit 23c3aea
Showing
7 changed files
with
231 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
86 changes: 86 additions & 0 deletions
86
...oid/templates/module/kotlin/template/android/src/{{ModuleIdAsFolder}}/ExampleProxy.kt.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* This file was auto-generated by the Titanium Module SDK helper for Android | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2009-2020 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 <%- moduleId %> | ||
|
||
import android.app.Activity | ||
import org.appcelerator.kroll.KrollDict | ||
import org.appcelerator.kroll.annotations.Kroll.* | ||
import org.appcelerator.kroll.common.Log | ||
import org.appcelerator.kroll.common.TiConfig | ||
import org.appcelerator.titanium.TiC | ||
import org.appcelerator.titanium.proxy.TiViewProxy | ||
import org.appcelerator.titanium.util.TiConvert | ||
import org.appcelerator.titanium.view.TiCompositeLayout | ||
import org.appcelerator.titanium.view.TiCompositeLayout.LayoutArrangement | ||
import org.appcelerator.titanium.view.TiUIView | ||
|
||
// This proxy can be created by calling <%- moduleNameCamel %>.createExample({ message: 'hello world' }) | ||
@proxy(creatableInModule = <%- moduleNameCamel %>Module::class) | ||
class ExampleProxy : TiViewProxy() { | ||
|
||
companion object { | ||
// Standard Debugging variables | ||
private const val LCAT = "ExampleProxy" | ||
private val DBG = TiConfig.LOGD | ||
} | ||
|
||
private inner class ExampleView(proxy: TiViewProxy) : TiUIView(proxy) { | ||
override fun processProperties(d: KrollDict) { | ||
super.processProperties(d) | ||
} | ||
|
||
init { | ||
var arrangement = LayoutArrangement.DEFAULT | ||
if (proxy.hasProperty(TiC.PROPERTY_LAYOUT)) { | ||
val layoutProperty = TiConvert.toString(proxy.getProperty(TiC.PROPERTY_LAYOUT)) | ||
if (layoutProperty == TiC.LAYOUT_HORIZONTAL) { | ||
arrangement = LayoutArrangement.HORIZONTAL | ||
} else if (layoutProperty == TiC.LAYOUT_VERTICAL) { | ||
arrangement = LayoutArrangement.VERTICAL | ||
} | ||
} | ||
setNativeView(TiCompositeLayout(proxy.activity, arrangement)) | ||
} | ||
} | ||
|
||
override fun createView(activity: Activity): TiUIView { | ||
val view: TiUIView = ExampleView(this) | ||
view.layoutParams.autoFillsHeight = true | ||
view.layoutParams.autoFillsWidth = true | ||
return view | ||
} | ||
|
||
// Handle creation options | ||
override fun handleCreationDict(options: KrollDict) { | ||
super.handleCreationDict(options) | ||
if (options.containsKey("message")) { | ||
Log.d(LCAT, "example created with message: " + options["message"]) | ||
} | ||
} | ||
|
||
// Methods | ||
|
||
@method | ||
fun printMessage(message: String) { | ||
Log.d(LCAT, "printing message: $message") | ||
} | ||
|
||
// Properties | ||
|
||
@get:method | ||
@get:getProperty | ||
@set:method | ||
@set:setProperty | ||
var message: String | ||
get() = "Hello World from my module" | ||
set(message) { | ||
Log.d(LCAT, "Tried setting module message to: $message") | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
.../module/kotlin/template/android/src/{{ModuleIdAsFolder}}/{{ModuleNameCamel}}Module.kt.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* This file was auto-generated by the Titanium Module SDK helper for Android | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2009-present 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 <%- moduleId %>; | ||
|
||
import org.appcelerator.kroll.KrollModule | ||
import org.appcelerator.kroll.KrollDict | ||
import org.appcelerator.kroll.annotations.Kroll.* | ||
import org.appcelerator.kroll.common.Log | ||
import org.appcelerator.kroll.common.TiConfig | ||
import org.appcelerator.titanium.TiApplication | ||
|
||
@module(name = "<%- moduleNameCamel %>", id = "ti.<%- moduleId %>") | ||
class <%- moduleNameCamel %>Module: KrollModule() { | ||
|
||
// NOTE: You can develop Titanium Android modules in Android Studio. Follow these three steps: | ||
// 1. Build the empty module | ||
// 2. Drag the "build" folder into Android Studio | ||
// 3. Start developing! All dependencies and code completions are supported! | ||
|
||
companion object { | ||
// Standard Debugging variables | ||
private const val LCAT = "<%- moduleNameCamel %>Module" | ||
private val DBG = TiConfig.LOGD | ||
|
||
// You can define constants with @Kroll.constant, for example: | ||
// @constant private val EXTERNAL_NAME = "EXTERNAL_NAME" | ||
|
||
@onAppCreate | ||
fun onAppCreate(app: TiApplication?) { | ||
Log.d(LCAT, "inside onAppCreate") | ||
// put module init code that needs to run when the application is created | ||
} | ||
} | ||
|
||
// Methods | ||
|
||
@method | ||
fun example(): String { | ||
Log.d(LCAT, "example() called") | ||
return "hello world" | ||
} | ||
|
||
@method | ||
fun testMethod(params: KrollDict) { | ||
Log.d(LCAT, "testMethod() called") | ||
|
||
// Access the parameters passed as an Object, e.g. "myModule.testMethod({ name: 'John Doe', flag: true })" | ||
val name = params.getString("name") | ||
val flag = params.optBoolean("flag", false); | ||
|
||
// Fire an event that can be added via "myModule.addEventListener('shown', ...)" | ||
val event = KrollDict() | ||
event["name"] = name | ||
event["flag"] = flag | ||
|
||
fireEvent("", event) | ||
} | ||
|
||
// Properties | ||
|
||
@get:getProperty | ||
@get:method | ||
@set:setProperty | ||
@set:method | ||
var exampleProp: String | ||
get() { | ||
Log.d(LCAT, "get example property") | ||
return "hello world" | ||
} | ||
set(value) { | ||
Log.d(LCAT, "set example property: $value") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters