Skip to content

Commit 68ce9a8

Browse files
committed
Add Kotlin support
1 parent 59e3b90 commit 68ce9a8

File tree

6 files changed

+119
-5
lines changed

6 files changed

+119
-5
lines changed

bin/templates/project/Activity.kt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
package __ID__;
21+
22+
import android.os.Bundle;
23+
import org.apache.cordova.*;
24+
25+
class __ACTIVITY__ : CordovaActivity() {
26+
override fun onCreate(savedInstanceState: Bundle?) {
27+
super.onCreate(savedInstanceState)
28+
29+
// enable Cordova apps to be started in the background
30+
val extras = intent.extras
31+
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
32+
moveTaskToBack(true)
33+
}
34+
35+
// Set by <content src="index.html" /> in config.xml
36+
loadUrl(launchUrl)
37+
}
38+
}

bin/templates/project/app/build.gradle

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
*/
1919

2020
apply plugin: 'com.android.application'
21+
apply plugin: 'kotlin-android'
2122

2223
buildscript {
24+
ext.kotlin_version = '1.2.41'
2325
repositories {
2426
mavenCentral()
2527
jcenter()
@@ -30,13 +32,14 @@ buildscript {
3032

3133
dependencies {
3234
classpath 'com.android.tools.build:gradle:3.1.0'
35+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
3336
}
3437
}
3538

3639
// Allow plugins to declare Maven dependencies via build-extras.gradle.
3740
allprojects {
3841
repositories {
39-
mavenCentral();
42+
mavenCentral()
4043
jcenter()
4144
}
4245
}
@@ -51,11 +54,11 @@ ext {
5154
apply from: '../CordovaLib/cordova.gradle'
5255
// The value for android.compileSdkVersion.
5356
if (!project.hasProperty('cdvCompileSdkVersion')) {
54-
cdvCompileSdkVersion = null;
57+
cdvCompileSdkVersion = null
5558
}
5659
// The value for android.buildToolsVersion.
5760
if (!project.hasProperty('cdvBuildToolsVersion')) {
58-
cdvBuildToolsVersion = null;
61+
cdvBuildToolsVersion = null
5962
}
6063
// Sets the versionCode to the given value.
6164
if (!project.hasProperty('cdvVersionCode')) {
@@ -257,6 +260,7 @@ android {
257260

258261
dependencies {
259262
implementation fileTree(dir: 'libs', include: '*.jar')
263+
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
260264
// SUB-PROJECT DEPENDENCIES START
261265
debugCompile(project(path: ":CordovaLib", configuration: "debug"))
262266
releaseCompile(project(path: ":CordovaLib", configuration: "release"))

test/app/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
apply plugin: 'com.android.application'
20+
apply plugin: 'kotlin-android'
2021

2122
android {
2223
compileSdkVersion 27
@@ -49,4 +50,8 @@ dependencies {
4950
implementation 'com.android.support:appcompat-v7:26.1.0'
5051
testImplementation 'junit:junit:4.12'
5152
testImplementation 'org.json:json:20140107'
53+
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
54+
}
55+
repositories {
56+
mavenCentral()
5257
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
package org.apache.cordova.unittests
21+
22+
import android.content.Intent
23+
import android.support.test.rule.ActivityTestRule
24+
import android.support.test.runner.AndroidJUnit4
25+
26+
import org.apache.cordova.engine.SystemWebView
27+
import org.junit.Before
28+
import org.junit.Rule
29+
import org.junit.Test
30+
import org.junit.runner.RunWith
31+
32+
import junit.framework.Assert.assertEquals
33+
34+
/**
35+
* The purpose of this test is to test the default application that is generated by Cordova itself
36+
*
37+
*/
38+
@RunWith(AndroidJUnit4::class)
39+
public class KotlinStandardActivityTest {
40+
41+
// Don't launch the activity, we're going to send it intents
42+
@get:Rule
43+
var mActivityRule = ActivityTestRule(
44+
StandardActivity::class.java, true, false)
45+
46+
@Before
47+
fun launchApplicationWithIntent() {
48+
val intent = Intent()
49+
intent.putExtra("startUrl", FALSE_URI)
50+
intent.putExtra("backgroundcolor", "#0000ff")
51+
mActivityRule.launchActivity(intent)
52+
}
53+
54+
@Test
55+
fun webViewCheck() {
56+
val activity = mActivityRule.getActivity() as StandardActivity
57+
//Fish the webview out of the mostly locked down Activity using the Android SDK
58+
val view = activity.getWindow().getCurrentFocus()
59+
assertEquals(SystemWebView::class, view::class)
60+
}
61+
62+
companion object {
63+
private val FALSE_URI = "http://www.google.com"
64+
}
65+
66+
}

test/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2020

2121
buildscript {
22+
ext.kotlin_version = '1.2.41'
2223
repositories {
2324
jcenter()
2425
google()
2526
}
2627
dependencies {
2728
classpath 'com.android.tools.build:gradle:3.0.1'
29+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
2830

2931
// NOTE: Do not place your application dependencies here; they belong
3032
// in the individual module build.gradle files
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Wed Oct 25 11:17:25 PDT 2017
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
43
zipStoreBase=GRADLE_USER_HOME
54
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-bin.zip

0 commit comments

Comments
 (0)