├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── user │ │ └── myapplication │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ ├── com │ │ │ ├── example │ │ │ │ └── user │ │ │ │ │ └── myapplication │ │ │ │ │ ├── MainActivity.kt │ │ │ │ │ └── SwiftApp.kt │ │ │ └── johnholdsworth │ │ │ │ └── swiftbindings │ │ │ │ ├── SwiftHelloBinding.java │ │ │ │ ├── SwiftHelloTest.java │ │ │ │ └── SwiftHelloTypes.java │ │ └── org │ │ │ └── swiftjava │ │ │ ├── com_johnholdsworth │ │ │ ├── SwiftHelloBinding_ListenerProxy.java │ │ │ ├── SwiftHelloTest_TestListenerProxy.java │ │ │ ├── SwiftHelloTest_TestResponderAdapterProxy.java │ │ │ └── SwiftHelloTypes_TextListenerProxy.java │ │ │ └── java_swift │ │ │ └── RunnableProxy.java │ ├── res │ │ ├── layout │ │ │ ├── activity_main.xml │ │ │ └── content_main.xml │ │ ├── menu │ │ │ └── menu_main.xml │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── raw │ │ │ └── cacert.pem │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ └── swift │ │ ├── Package.swift │ │ └── Sources │ │ ├── Statics.swift │ │ ├── SwiftHelloBinding.swift │ │ ├── SwiftHelloBinding_Listener.swift │ │ ├── SwiftHelloBinding_Responder.swift │ │ ├── SwiftHelloTest.swift │ │ ├── SwiftHelloTestImpl.swift │ │ ├── SwiftHelloTest_SwiftTestListener.swift │ │ ├── SwiftHelloTest_TestListener.swift │ │ ├── SwiftHelloTest_TestResponderAdapter.swift │ │ ├── SwiftHelloTypes.swift │ │ ├── SwiftHelloTypes_ListenerMap.swift │ │ ├── SwiftHelloTypes_ListenerMapList.swift │ │ ├── SwiftHelloTypes_Planet.swift │ │ ├── SwiftHelloTypes_StringMap.swift │ │ ├── SwiftHelloTypes_StringMapList.swift │ │ ├── SwiftHelloTypes_TextListener.swift │ │ └── swifthello.swift │ └── test │ └── java │ └── com │ └── example │ └── user │ └── myapplication │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── hybrid.t2d ├── settings.gradle └── swift-android-kotlin.iml /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | jniLibs 9 | /captures 10 | .externalNativeBuild 11 | *.pins 12 | *.resolved 13 | .build 14 | build 15 | jniLibs 16 | Packages 17 | *.class 18 | *.so 19 | *.apk 20 | vcs.xml 21 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 40 | 1.8 41 | 42 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kotlin example for the Android Swift toolchain. 2 | 3 | ![](http://johnholdsworth.com/swiftjava.png?v=1) 4 | 5 | An example application for mixing Swift and Kotlin in an Android application. This allows you to reuse model layer code from your iOS application when porting to Android. The "binding" between the Kotlin or Java code and Swift is completely type safe with all JNI code automatically generated using a script. Building the Swift code is performed using the Swift Package manager and a small gradle plugin. 6 | 7 | Requires a build of the latest Android toolchain downloadable [here](http://johnholdsworth.com/android_toolchain.tgz). Once you've extracted the toolchain, run `swift-install/setup.sh` to get started and install the gradle plugin. You then run `./gradlew installDebug` or build the project in Android Studio. Make sure the that the `ANDROID_HOME` environment variable is set to the path to an [Android SDK](https://developer.android.com/studio/index.html). The phone must be api 21 aka Android v5+ aka Lollipop or better (I used an LG K4.) 8 | 9 | To create a new application, decide on a pair of interfaces to connect to and from your Swift 10 | code and place them in a [Java Source](https://github.com/SwiftJava/swift-android-kotlin/blob/master/app/src/main/java/com/johnholdsworth/swiftbindings/SwiftHelloBinding.java). Use the command `./genswift.sh` in the [SwiftJava Project](https://github.com/SwiftJava/SwiftJava) to generate Swift (& Java) sources to include in your application or adapt the [genhello.sh](https://github.com/SwiftJava/SwiftJava/blob/master/genhello.sh) script. Your app's only 11 | [Package.swift](https://github.com/SwiftJava/swift-android-kotlin/blob/master/app/src/main/swift/Package.swift) 12 | dependency should be the core JNI interfacing code [java_swift](https://github.com/SwiftJava/java_swift). 13 | 14 | This example is coded to work with version 7 of the toolchain which has some additional requirements 15 | to work around requirements of the Swift port of Foundation. The cache directory used by web operations 16 | needs to be setup in the environment variable "TMPDIR". This would usually be the value of 17 | Context.getCacheDir().getPath() from the java side. In addition, to be able to use SSL you 18 | need to add a [CARoot info file](http://curl.haxx.se/docs/caextract.html) to the application's 19 | raw resources and copy it to this cache directory to be picked up by Foundation as follows: 20 | 21 | setenv("URLSessionCertificateAuthorityInfoFile", cacheDir! + "/cacert.pem", 1) 22 | setenv("TMPDIR", cacheDir!, 1) 23 | 24 | If you don't want peer validation you have the following option (not recommended at all) 25 | 26 | setenv("URLSessionCertificateAuthorityInfoFile", “INSECURE_SSL_NO_VERIFY”, 1) 27 | 28 | ## Simple demo of Swift code accessed over JNI. 29 | 30 | To build, setup the Gradle plugin, then run `./gradlew installDebug` 31 | 32 | This demo is licensed under the Creative Commons CC0 license: 33 | do whatever you want. 34 | 35 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 23 | 24 | 25 | 26 | 27 | 28 | 34 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'net.zhuoweizhang.swiftandroid' 4 | 5 | android { 6 | compileSdkVersion 25 7 | buildToolsVersion "26.0.1" 8 | defaultConfig { 9 | applicationId "com.example.user.myapplication" 10 | minSdkVersion 21 11 | targetSdkVersion 25 12 | versionCode 1 13 | versionName "1.0" 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | } 22 | } 23 | 24 | dependencies { 25 | compile fileTree(dir: 'libs', include: ['*.jar', '**/*.so']) 26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 27 | exclude group: 'com.android.support', module: 'support-annotations' 28 | }) 29 | compile 'com.android.support:appcompat-v7:25.3.1' 30 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 31 | compile 'com.android.support:design:25.3.1' 32 | testCompile 'junit:junit:4.12' 33 | compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 34 | } 35 | repositories { 36 | mavenCentral() 37 | } 38 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/user/Android/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/user/myapplication/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.user.myapplication; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.example.user.myapplication", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 14 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/user/myapplication/MainActivity.kt: -------------------------------------------------------------------------------- 1 | 2 | package com.example.user.myapplication 3 | 4 | import android.os.Bundle 5 | import android.support.design.widget.FloatingActionButton 6 | import android.support.design.widget.Snackbar 7 | import android.support.v7.app.AppCompatActivity 8 | import android.support.v7.widget.Toolbar 9 | import android.view.Menu 10 | import android.view.MenuItem 11 | import android.widget.TextView 12 | 13 | import com.johnholdsworth.swiftbindings.SwiftHelloBinding.Listener 14 | import com.johnholdsworth.swiftbindings.SwiftHelloBinding.Responder 15 | 16 | import com.johnholdsworth.swiftbindings.SwiftHelloTypes.TextListener 17 | import com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMap 18 | import com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMapList 19 | import com.johnholdsworth.swiftbindings.SwiftHelloTypes.StringMap 20 | import com.johnholdsworth.swiftbindings.SwiftHelloTypes.StringMapList 21 | 22 | import com.johnholdsworth.swiftbindings.SwiftHelloTest.TestListener 23 | import com.johnholdsworth.swiftbindings.SwiftHelloTest.SwiftTestListener 24 | 25 | import java.io.* 26 | 27 | class MainActivity : AppCompatActivity(), Responder { 28 | 29 | /** Implemented in src/main/swift/Sources/main.swift **/ 30 | internal external fun bind(self: Responder): Listener 31 | 32 | override fun onCreate(savedInstanceState: Bundle?) { 33 | super.onCreate(savedInstanceState) 34 | setContentView(R.layout.activity_main) 35 | val toolbar = findViewById(R.id.toolbar) as Toolbar 36 | setSupportActionBar(toolbar) 37 | 38 | val fab = findViewById(R.id.fab) as FloatingActionButton 39 | fab.setOnClickListener { view -> 40 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 41 | .setAction("Action", null).show() 42 | } 43 | 44 | Thread() { 45 | loadNativeDependencies() 46 | 47 | listener = bind(this) 48 | val context = SwiftApp.sharedApplication.getApplicationContext() 49 | val cacheDir = context?.getCacheDir()?.getPath() 50 | val pemfile = cacheDir + "/cacert.pem" 51 | val pemStream = SwiftApp.sharedApplication.getResources()?.openRawResource(R.raw.cacert) 52 | copyResource(pemStream, pemfile) 53 | listener.setCacheDir(cacheDir) 54 | 55 | basicTests(10) 56 | 57 | listener.processText("World") 58 | }.start() 59 | } 60 | 61 | private fun basicTests(reps: Int) { 62 | for (i in 1..reps) { 63 | try { 64 | listener.throwException() 65 | } catch (e: Exception) { 66 | System.out.println("**** Got Swift Exception ****") 67 | e.printStackTrace() 68 | } 69 | } 70 | 71 | for (i in 1..reps) { 72 | listener.processStringMap(StringMap(hashMapOf("hello" to "world"))) 73 | listener.processStringMapList(StringMapList(hashMapOf(("hello" to Array(1, { "world" }))))) 74 | } 75 | 76 | val tester = listener.testResponder(2) 77 | for (i in 1..reps) { 78 | SwiftTestListener().respond(tester) 79 | } 80 | } 81 | 82 | private fun copyResource(`in`: InputStream?, to: String) { 83 | try { 84 | val out = FileOutputStream(to) 85 | `in`?.copyTo(out) 86 | `in`?.close() 87 | out.close() 88 | } catch (e: IOException) { 89 | e.printStackTrace() 90 | System.out.println("" + e) 91 | } 92 | 93 | } 94 | 95 | override fun onCreateOptionsMenu(menu: Menu): Boolean { 96 | // Inflate the menu; this adds items to the action bar if it is present. 97 | menuInflater.inflate(R.menu.menu_main, menu) 98 | return true 99 | } 100 | 101 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 102 | // Handle action bar item clicks here. The action bar will 103 | // automatically handle clicks on the Home/Up button, so long 104 | // as you specify a parent activity in AndroidManifest.xml. 105 | val id = item.itemId 106 | 107 | 108 | if (id == R.id.action_settings) { 109 | return true 110 | } 111 | 112 | return super.onOptionsItemSelected(item) 113 | } 114 | 115 | override fun processedNumber(number: Double) { 116 | val myText = findViewById(R.id.mytext) as TextView 117 | myText.text = "Result of swift return42() function is " + number 118 | } 119 | 120 | override fun processedText(text: String) { 121 | runOnUiThread { 122 | val myText = findViewById(R.id.mytext) as TextView 123 | myText.text = "Processed text: " + text 124 | } 125 | } 126 | 127 | override fun processedTextListener(text: TextListener) { 128 | processedText( text.getText() ); 129 | } 130 | 131 | override fun processedTextListenerArray(text: Array?) { 132 | processedText( text!![0].getText() ); 133 | } 134 | 135 | override fun processedTextListener2dArray(text: Array>?) { 136 | processedText( text!![0][0].getText() ); 137 | } 138 | 139 | override fun processMap(map: ListenerMap?) { 140 | listener.processedMap( map ) 141 | } 142 | 143 | override fun processMapList(map: ListenerMapList?) { 144 | listener.processedMapList( map ) 145 | } 146 | 147 | override fun processedStringMap(map: StringMap?) { 148 | System.out.println("StringMapList: "+map!!) 149 | } 150 | 151 | override fun processedStringMapList(map: StringMapList?) { 152 | System.out.println("StringMap: "+map!!) 153 | } 154 | 155 | override fun throwException(): Double { 156 | throw Exception("Java test exception") 157 | } 158 | 159 | override fun debug(msg: String): Array { 160 | System.out.println("Swift: " + msg) 161 | return arrayOf("!" + msg, msg + "!") 162 | } 163 | 164 | override fun onMainThread(runnable: Runnable?) { 165 | runOnUiThread(runnable) 166 | } 167 | 168 | override fun testResponder(loopback: Int): TestListener { 169 | val test = SwiftTestListener() 170 | if ( loopback > 0 ) { 171 | test.setLoopback( listener.testResponder(loopback - 1 ) ) 172 | } 173 | return test 174 | } 175 | 176 | companion object { 177 | 178 | internal lateinit var listener: Listener 179 | 180 | private fun loadNativeDependencies() { 181 | // Load libraries 182 | System.loadLibrary("swifthello") 183 | } 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/user/myapplication/SwiftApp.kt: -------------------------------------------------------------------------------- 1 | package com.example.user.myapplication 2 | 3 | import android.app.Application 4 | 5 | class SwiftApp : Application() { 6 | 7 | override fun onCreate() { 8 | super.onCreate() 9 | sharedApplication = this 10 | } 11 | 12 | companion object { 13 | 14 | lateinit var sharedApplication: Application 15 | private set 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/johnholdsworth/swiftbindings/SwiftHelloBinding.java: -------------------------------------------------------------------------------- 1 | 2 | package com.johnholdsworth.swiftbindings; 3 | 4 | import com.johnholdsworth.swiftbindings.SwiftHelloTypes.TextListener; 5 | import com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMap; 6 | import com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMapList; 7 | import com.johnholdsworth.swiftbindings.SwiftHelloTypes.StringMap; 8 | import com.johnholdsworth.swiftbindings.SwiftHelloTypes.StringMapList; 9 | 10 | public interface SwiftHelloBinding { 11 | 12 | // Messages from JavaActivity to Swift 13 | public interface Listener { 14 | 15 | public void setCacheDir( String cacheDir ); 16 | 17 | public void processNumber( double number ); 18 | 19 | public void processText( String text ); 20 | 21 | public void processedMap( ListenerMap map ); 22 | 23 | public void processedMapList( ListenerMapList map ); 24 | 25 | public void processStringMap( StringMap map ); 26 | 27 | public void processStringMapList( StringMapList map ); 28 | 29 | public double throwException() throws Exception; 30 | 31 | public SwiftHelloTest.TestListener testResponder( int loopback ); 32 | 33 | } 34 | 35 | // Messages from Swift back to Activity 36 | public interface Responder { 37 | 38 | public void processedNumber( double number ); 39 | 40 | public void processedText( String text ); 41 | 42 | public void processedTextListener( TextListener text ); 43 | 44 | public void processedTextListenerArray( TextListener text[] ); 45 | 46 | public void processedTextListener2dArray( TextListener text[][] ); 47 | 48 | public void processMap( ListenerMap map ); 49 | 50 | public void processMapList( ListenerMapList map ); 51 | 52 | public void processedStringMap( StringMap map ); 53 | 54 | public void processedStringMapList( StringMapList map ); 55 | 56 | public double throwException() throws Exception; 57 | 58 | public String[] debug( String msg ); 59 | 60 | public void onMainThread( Runnable runnable ); 61 | 62 | public SwiftHelloTest.TestListener testResponder( int loopback ); 63 | 64 | } 65 | 66 | } 67 | 68 | -------------------------------------------------------------------------------- /app/src/main/java/com/johnholdsworth/swiftbindings/SwiftHelloTest.java: -------------------------------------------------------------------------------- 1 | 2 | // auto generated by ../../../../gentests.rb 3 | 4 | package com.johnholdsworth.swiftbindings; 5 | 6 | import com.johnholdsworth.swiftbindings.SwiftHelloTypes.TextListener; 7 | import com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMap; 8 | import com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMapList; 9 | 10 | public interface SwiftHelloTest { 11 | 12 | public interface TestListener { 13 | 14 | public void setLoopback( TestListener loopback ); 15 | 16 | public boolean booleanMethod( boolean arg ); 17 | public boolean[] booleanArrayMethod( boolean arg[] ); 18 | public boolean[][] boolean2dArrayMethod( boolean arg[][] ); 19 | 20 | public byte byteMethod( byte arg ); 21 | public byte[] byteArrayMethod( byte arg[] ); 22 | public byte[][] byte2dArrayMethod( byte arg[][] ); 23 | 24 | public char charMethod( char arg ); 25 | public char[] charArrayMethod( char arg[] ); 26 | public char[][] char2dArrayMethod( char arg[][] ); 27 | 28 | public short shortMethod( short arg ); 29 | public short[] shortArrayMethod( short arg[] ); 30 | public short[][] short2dArrayMethod( short arg[][] ); 31 | 32 | public int intMethod( int arg ); 33 | public int[] intArrayMethod( int arg[] ); 34 | public int[][] int2dArrayMethod( int arg[][] ); 35 | 36 | public long longMethod( long arg ); 37 | public long[] longArrayMethod( long arg[] ); 38 | public long[][] long2dArrayMethod( long arg[][] ); 39 | 40 | public float floatMethod( float arg ); 41 | public float[] floatArrayMethod( float arg[] ); 42 | public float[][] float2dArrayMethod( float arg[][] ); 43 | 44 | public double doubleMethod( double arg ); 45 | public double[] doubleArrayMethod( double arg[] ); 46 | public double[][] double2dArrayMethod( double arg[][] ); 47 | 48 | public String StringMethod( String arg ); 49 | public String[] StringArrayMethod( String arg[] ); 50 | public String[][] String2dArrayMethod( String arg[][] ); 51 | 52 | public TestListener TestListenerMethod( TestListener arg ); 53 | public TestListener[] TestListenerArrayMethod( TestListener arg[] ); 54 | public TestListener[][] TestListener2dArrayMethod( TestListener arg[][] ); 55 | 56 | public ListenerMap testMap( ListenerMap arg ); 57 | public ListenerMapList testMapList( ListenerMapList arg ); 58 | 59 | } 60 | 61 | public static class TestResponderAdapter implements TestListener { 62 | 63 | public TestListener loopback; 64 | 65 | public void setLoopback( TestListener loopback ) { 66 | this.loopback = loopback; 67 | } 68 | 69 | public boolean booleanMethod( boolean arg ) { 70 | return loopback != null ? loopback.booleanMethod( arg ) : arg; 71 | } 72 | 73 | public boolean[] booleanArrayMethod( boolean arg[] ) { 74 | return loopback != null ? loopback.booleanArrayMethod( arg ) : arg; 75 | } 76 | 77 | public boolean[][] boolean2dArrayMethod( boolean arg[][] ) { 78 | return loopback != null ? loopback.boolean2dArrayMethod( arg ) : arg; 79 | } 80 | 81 | public byte byteMethod( byte arg ) { 82 | return loopback != null ? loopback.byteMethod( arg ) : arg; 83 | } 84 | 85 | public byte[] byteArrayMethod( byte arg[] ) { 86 | return loopback != null ? loopback.byteArrayMethod( arg ) : arg; 87 | } 88 | 89 | public byte[][] byte2dArrayMethod( byte arg[][] ) { 90 | return loopback != null ? loopback.byte2dArrayMethod( arg ) : arg; 91 | } 92 | 93 | public char charMethod( char arg ) { 94 | return loopback != null ? loopback.charMethod( arg ) : arg; 95 | } 96 | 97 | public char[] charArrayMethod( char arg[] ) { 98 | return loopback != null ? loopback.charArrayMethod( arg ) : arg; 99 | } 100 | 101 | public char[][] char2dArrayMethod( char arg[][] ) { 102 | return loopback != null ? loopback.char2dArrayMethod( arg ) : arg; 103 | } 104 | 105 | public short shortMethod( short arg ) { 106 | return loopback != null ? loopback.shortMethod( arg ) : arg; 107 | } 108 | 109 | public short[] shortArrayMethod( short arg[] ) { 110 | return loopback != null ? loopback.shortArrayMethod( arg ) : arg; 111 | } 112 | 113 | public short[][] short2dArrayMethod( short arg[][] ) { 114 | return loopback != null ? loopback.short2dArrayMethod( arg ) : arg; 115 | } 116 | 117 | public int intMethod( int arg ) { 118 | return loopback != null ? loopback.intMethod( arg ) : arg; 119 | } 120 | 121 | public int[] intArrayMethod( int arg[] ) { 122 | return loopback != null ? loopback.intArrayMethod( arg ) : arg; 123 | } 124 | 125 | public int[][] int2dArrayMethod( int arg[][] ) { 126 | return loopback != null ? loopback.int2dArrayMethod( arg ) : arg; 127 | } 128 | 129 | public long longMethod( long arg ) { 130 | return loopback != null ? loopback.longMethod( arg ) : arg; 131 | } 132 | 133 | public long[] longArrayMethod( long arg[] ) { 134 | return loopback != null ? loopback.longArrayMethod( arg ) : arg; 135 | } 136 | 137 | public long[][] long2dArrayMethod( long arg[][] ) { 138 | return loopback != null ? loopback.long2dArrayMethod( arg ) : arg; 139 | } 140 | 141 | public float floatMethod( float arg ) { 142 | return loopback != null ? loopback.floatMethod( arg ) : arg; 143 | } 144 | 145 | public float[] floatArrayMethod( float arg[] ) { 146 | return loopback != null ? loopback.floatArrayMethod( arg ) : arg; 147 | } 148 | 149 | public float[][] float2dArrayMethod( float arg[][] ) { 150 | return loopback != null ? loopback.float2dArrayMethod( arg ) : arg; 151 | } 152 | 153 | public double doubleMethod( double arg ) { 154 | return loopback != null ? loopback.doubleMethod( arg ) : arg; 155 | } 156 | 157 | public double[] doubleArrayMethod( double arg[] ) { 158 | return loopback != null ? loopback.doubleArrayMethod( arg ) : arg; 159 | } 160 | 161 | public double[][] double2dArrayMethod( double arg[][] ) { 162 | return loopback != null ? loopback.double2dArrayMethod( arg ) : arg; 163 | } 164 | 165 | public String StringMethod( String arg ) { 166 | return loopback != null ? loopback.StringMethod( arg ) : arg; 167 | } 168 | 169 | public String[] StringArrayMethod( String arg[] ) { 170 | return loopback != null ? loopback.StringArrayMethod( arg ) : arg; 171 | } 172 | 173 | public String[][] String2dArrayMethod( String arg[][] ) { 174 | return loopback != null ? loopback.String2dArrayMethod( arg ) : arg; 175 | } 176 | 177 | public TestListener TestListenerMethod( TestListener arg ) { 178 | return loopback != null ? loopback.TestListenerMethod( arg ) : arg; 179 | } 180 | 181 | public TestListener[] TestListenerArrayMethod( TestListener arg[] ) { 182 | return loopback != null ? loopback.TestListenerArrayMethod( arg ) : arg; 183 | } 184 | 185 | public TestListener[][] TestListener2dArrayMethod( TestListener arg[][] ) { 186 | return loopback != null ? loopback.TestListener2dArrayMethod( arg ) : arg; 187 | } 188 | 189 | public ListenerMap testMap( ListenerMap arg ) { 190 | return loopback != null ? loopback.testMap( arg ) : arg; 191 | } 192 | 193 | public ListenerMapList testMapList( ListenerMapList arg ) { 194 | return loopback != null ? loopback.testMapList( arg ) : arg; 195 | } 196 | 197 | } 198 | 199 | public static class SwiftTestListener extends TestResponderAdapter { 200 | 201 | static int tcount = 0; 202 | 203 | public void respond( TestListener responder ) { 204 | tcount += 1; 205 | System.out.println("Java -> Swift "+tcount+"..."); 206 | 207 | 208 | if ( true ) { 209 | boolean reference = true; 210 | boolean referenceArray[] = new boolean [] {reference}; 211 | boolean reference2dArray[][] = new boolean [][] {referenceArray}; 212 | 213 | boolean response = responder.booleanMethod( reference ); 214 | boolean responseArray[] = responder.booleanArrayMethod( referenceArray ); 215 | boolean response2dArray[][] = responder.boolean2dArrayMethod( reference2dArray ); 216 | 217 | if ( response != reference ) { 218 | System.out.println("Bool: "+response+" != "+reference); 219 | } 220 | if ( responseArray[0] != referenceArray[0] ) { 221 | System.out.println("Bool: "+responseArray[0]+" != "+referenceArray[0]); 222 | } 223 | if ( response2dArray[0][0] != reference2dArray[0][0] ) { 224 | System.out.println("Bool: "+response2dArray[0][0]+" != "+reference2dArray[0][0]); 225 | } 226 | } 227 | 228 | if ( true ) { 229 | byte reference = 123; 230 | byte referenceArray[] = new byte [] {reference}; 231 | byte reference2dArray[][] = new byte [][] {referenceArray}; 232 | 233 | byte response = responder.byteMethod( reference ); 234 | byte responseArray[] = responder.byteArrayMethod( referenceArray ); 235 | byte response2dArray[][] = responder.byte2dArrayMethod( reference2dArray ); 236 | 237 | if ( response != reference ) { 238 | System.out.println("Int8: "+response+" != "+reference); 239 | } 240 | if ( responseArray[0] != referenceArray[0] ) { 241 | System.out.println("Int8: "+responseArray[0]+" != "+referenceArray[0]); 242 | } 243 | if ( response2dArray[0][0] != reference2dArray[0][0] ) { 244 | System.out.println("Int8: "+response2dArray[0][0]+" != "+reference2dArray[0][0]); 245 | } 246 | } 247 | 248 | if ( true ) { 249 | char reference = 123; 250 | char referenceArray[] = new char [] {reference}; 251 | char reference2dArray[][] = new char [][] {referenceArray}; 252 | 253 | char response = responder.charMethod( reference ); 254 | char responseArray[] = responder.charArrayMethod( referenceArray ); 255 | char response2dArray[][] = responder.char2dArrayMethod( reference2dArray ); 256 | 257 | if ( response != reference ) { 258 | System.out.println("UInt16: "+response+" != "+reference); 259 | } 260 | if ( responseArray[0] != referenceArray[0] ) { 261 | System.out.println("UInt16: "+responseArray[0]+" != "+referenceArray[0]); 262 | } 263 | if ( response2dArray[0][0] != reference2dArray[0][0] ) { 264 | System.out.println("UInt16: "+response2dArray[0][0]+" != "+reference2dArray[0][0]); 265 | } 266 | } 267 | 268 | if ( true ) { 269 | short reference = 123; 270 | short referenceArray[] = new short [] {reference}; 271 | short reference2dArray[][] = new short [][] {referenceArray}; 272 | 273 | short response = responder.shortMethod( reference ); 274 | short responseArray[] = responder.shortArrayMethod( referenceArray ); 275 | short response2dArray[][] = responder.short2dArrayMethod( reference2dArray ); 276 | 277 | if ( response != reference ) { 278 | System.out.println("Int16: "+response+" != "+reference); 279 | } 280 | if ( responseArray[0] != referenceArray[0] ) { 281 | System.out.println("Int16: "+responseArray[0]+" != "+referenceArray[0]); 282 | } 283 | if ( response2dArray[0][0] != reference2dArray[0][0] ) { 284 | System.out.println("Int16: "+response2dArray[0][0]+" != "+reference2dArray[0][0]); 285 | } 286 | } 287 | 288 | if ( true ) { 289 | int reference = 123; 290 | int referenceArray[] = new int [] {reference}; 291 | int reference2dArray[][] = new int [][] {referenceArray}; 292 | 293 | int response = responder.intMethod( reference ); 294 | int responseArray[] = responder.intArrayMethod( referenceArray ); 295 | int response2dArray[][] = responder.int2dArrayMethod( reference2dArray ); 296 | 297 | if ( response != reference ) { 298 | System.out.println("Int: "+response+" != "+reference); 299 | } 300 | if ( responseArray[0] != referenceArray[0] ) { 301 | System.out.println("Int: "+responseArray[0]+" != "+referenceArray[0]); 302 | } 303 | if ( response2dArray[0][0] != reference2dArray[0][0] ) { 304 | System.out.println("Int: "+response2dArray[0][0]+" != "+reference2dArray[0][0]); 305 | } 306 | } 307 | 308 | if ( true ) { 309 | long reference = 123; 310 | long referenceArray[] = new long [] {reference}; 311 | long reference2dArray[][] = new long [][] {referenceArray}; 312 | 313 | long response = responder.longMethod( reference ); 314 | long responseArray[] = responder.longArrayMethod( referenceArray ); 315 | long response2dArray[][] = responder.long2dArrayMethod( reference2dArray ); 316 | 317 | if ( response != reference ) { 318 | System.out.println("Int64: "+response+" != "+reference); 319 | } 320 | if ( responseArray[0] != referenceArray[0] ) { 321 | System.out.println("Int64: "+responseArray[0]+" != "+referenceArray[0]); 322 | } 323 | if ( response2dArray[0][0] != reference2dArray[0][0] ) { 324 | System.out.println("Int64: "+response2dArray[0][0]+" != "+reference2dArray[0][0]); 325 | } 326 | } 327 | 328 | if ( true ) { 329 | float reference = 123; 330 | float referenceArray[] = new float [] {reference}; 331 | float reference2dArray[][] = new float [][] {referenceArray}; 332 | 333 | float response = responder.floatMethod( reference ); 334 | float responseArray[] = responder.floatArrayMethod( referenceArray ); 335 | float response2dArray[][] = responder.float2dArrayMethod( reference2dArray ); 336 | 337 | if ( response != reference ) { 338 | System.out.println("Float: "+response+" != "+reference); 339 | } 340 | if ( responseArray[0] != referenceArray[0] ) { 341 | System.out.println("Float: "+responseArray[0]+" != "+referenceArray[0]); 342 | } 343 | if ( response2dArray[0][0] != reference2dArray[0][0] ) { 344 | System.out.println("Float: "+response2dArray[0][0]+" != "+reference2dArray[0][0]); 345 | } 346 | } 347 | 348 | if ( true ) { 349 | double reference = 123; 350 | double referenceArray[] = new double [] {reference}; 351 | double reference2dArray[][] = new double [][] {referenceArray}; 352 | 353 | double response = responder.doubleMethod( reference ); 354 | double responseArray[] = responder.doubleArrayMethod( referenceArray ); 355 | double response2dArray[][] = responder.double2dArrayMethod( reference2dArray ); 356 | 357 | if ( response != reference ) { 358 | System.out.println("Double: "+response+" != "+reference); 359 | } 360 | if ( responseArray[0] != referenceArray[0] ) { 361 | System.out.println("Double: "+responseArray[0]+" != "+referenceArray[0]); 362 | } 363 | if ( response2dArray[0][0] != reference2dArray[0][0] ) { 364 | System.out.println("Double: "+response2dArray[0][0]+" != "+reference2dArray[0][0]); 365 | } 366 | } 367 | 368 | if ( true ) { 369 | String reference = "123"; 370 | String referenceArray[] = new String [] {reference}; 371 | String reference2dArray[][] = new String [][] {referenceArray}; 372 | 373 | String response = responder.StringMethod( reference ); 374 | String responseArray[] = responder.StringArrayMethod( referenceArray ); 375 | String response2dArray[][] = responder.String2dArrayMethod( reference2dArray ); 376 | } 377 | 378 | if ( true ) { 379 | TestListener reference = new SwiftTestListener(); 380 | TestListener referenceArray[] = new TestListener [] {reference}; 381 | TestListener reference2dArray[][] = new TestListener [][] {referenceArray}; 382 | 383 | TestListener response = responder.TestListenerMethod( reference ); 384 | TestListener responseArray[] = responder.TestListenerArrayMethod( referenceArray ); 385 | TestListener response2dArray[][] = responder.TestListener2dArrayMethod( reference2dArray ); 386 | } 387 | } 388 | 389 | } 390 | 391 | } 392 | -------------------------------------------------------------------------------- /app/src/main/java/com/johnholdsworth/swiftbindings/SwiftHelloTypes.java: -------------------------------------------------------------------------------- 1 | 2 | // Shared types/interfaces between Java and Swift in example applications 3 | 4 | package com.johnholdsworth.swiftbindings; 5 | 6 | import java.util.Map; 7 | import java.util.HashMap; 8 | 9 | public interface SwiftHelloTypes { 10 | 11 | // An example of publishing an object to Java. 12 | // Add the associated protocol to an class and 13 | // objects can be passed to a responder message. 14 | public interface TextListener { 15 | public String getText(); 16 | } 17 | 18 | // These are required because of type erasure in Java jars 19 | public static class ListenerMap extends HashMap { 20 | public static Class valueClass() { 21 | return TextListener.class; 22 | } 23 | } 24 | 25 | public static class ListenerMapList extends HashMap { 26 | public static Class valueClass() { 27 | return (new TextListener [] {}).getClass(); 28 | } 29 | } 30 | 31 | public static class StringMap extends HashMap { 32 | public static Class valueClass() { 33 | return String.class; 34 | } 35 | public StringMap() { 36 | super(); 37 | } 38 | @SuppressWarnings("unchecked") 39 | public StringMap(Map map) { 40 | super(map); 41 | } 42 | } 43 | 44 | public static class StringMapList extends HashMap { 45 | public static Class valueClass() { 46 | return (new String [] {}).getClass(); 47 | } 48 | public StringMapList() { 49 | super(); 50 | } 51 | @SuppressWarnings("unchecked") 52 | public StringMapList(Map map) { 53 | super(map); 54 | } 55 | } 56 | 57 | public static enum Planet { 58 | MERCURY (3.303e+23, 2.4397e6), 59 | VENUS (4.869e+24, 6.0518e6), 60 | EARTH (5.976e+24, 6.37814e6), 61 | MARS (6.421e+23, 3.3972e6), 62 | JUPITER (1.9e+27, 7.1492e7), 63 | SATURN (5.688e+26, 6.0268e7), 64 | URANUS (8.686e+25, 2.5559e7), 65 | NEPTUNE (1.024e+26, 2.4746e7); 66 | 67 | private final double mass; // in kilograms 68 | private final double radius; // in meters 69 | Planet(double mass, double radius) { 70 | this.mass = mass; 71 | this.radius = radius; 72 | } 73 | public double mass() { return mass; } 74 | public double radius() { return radius; } 75 | 76 | // universal gravitational constant (m3 kg-1 s-2) 77 | public static final double G = 6.67300E-11; 78 | 79 | public double surfaceGravity() { 80 | return G * mass / (radius * radius); 81 | } 82 | public double surfaceWeight(double otherMass) { 83 | return otherMass * surfaceGravity(); 84 | } 85 | } 86 | } 87 | 88 | 89 | -------------------------------------------------------------------------------- /app/src/main/java/org/swiftjava/com_johnholdsworth/SwiftHelloBinding_ListenerProxy.java: -------------------------------------------------------------------------------- 1 | 2 | /// generated by: genswift.java 'java/lang|java/util|java/sql|java/awt|javax/swing' /// 3 | 4 | /// interface com.johnholdsworth.swiftbindings.SwiftHelloBinding$Listener /// 5 | 6 | package org.swiftjava.com_johnholdsworth; 7 | 8 | @SuppressWarnings("JniMissingFunction") 9 | public class SwiftHelloBinding_ListenerProxy implements com.johnholdsworth.swiftbindings.SwiftHelloBinding.Listener { 10 | 11 | // address of proxy object 12 | long __swiftObject; 13 | 14 | SwiftHelloBinding_ListenerProxy( long __swiftObject ) { 15 | this.__swiftObject = __swiftObject; 16 | } 17 | 18 | /// public abstract void com.johnholdsworth.swiftbindings.SwiftHelloBinding$Listener.processNumber(double) 19 | 20 | public native void __processNumber( long __swiftObject, double number ); 21 | 22 | public void processNumber( double number ) { 23 | __processNumber( __swiftObject, number ); 24 | } 25 | 26 | /// public abstract void com.johnholdsworth.swiftbindings.SwiftHelloBinding$Listener.processStringMap(com.johnholdsworth.swiftbindings.SwiftHelloTypes$StringMap) 27 | 28 | public native void __processStringMap( long __swiftObject, com.johnholdsworth.swiftbindings.SwiftHelloTypes.StringMap map ); 29 | 30 | public void processStringMap( com.johnholdsworth.swiftbindings.SwiftHelloTypes.StringMap map ) { 31 | __processStringMap( __swiftObject, map ); 32 | } 33 | 34 | /// public abstract void com.johnholdsworth.swiftbindings.SwiftHelloBinding$Listener.processStringMapList(com.johnholdsworth.swiftbindings.SwiftHelloTypes$StringMapList) 35 | 36 | public native void __processStringMapList( long __swiftObject, com.johnholdsworth.swiftbindings.SwiftHelloTypes.StringMapList map ); 37 | 38 | public void processStringMapList( com.johnholdsworth.swiftbindings.SwiftHelloTypes.StringMapList map ) { 39 | __processStringMapList( __swiftObject, map ); 40 | } 41 | 42 | /// public abstract void com.johnholdsworth.swiftbindings.SwiftHelloBinding$Listener.processText(java.lang.String) 43 | 44 | public native void __processText( long __swiftObject, java.lang.String text ); 45 | 46 | public void processText( java.lang.String text ) { 47 | __processText( __swiftObject, text ); 48 | } 49 | 50 | /// public abstract void com.johnholdsworth.swiftbindings.SwiftHelloBinding$Listener.processedMap(com.johnholdsworth.swiftbindings.SwiftHelloTypes$ListenerMap) 51 | 52 | public native void __processedMap( long __swiftObject, com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMap map ); 53 | 54 | public void processedMap( com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMap map ) { 55 | __processedMap( __swiftObject, map ); 56 | } 57 | 58 | /// public abstract void com.johnholdsworth.swiftbindings.SwiftHelloBinding$Listener.processedMapList(com.johnholdsworth.swiftbindings.SwiftHelloTypes$ListenerMapList) 59 | 60 | public native void __processedMapList( long __swiftObject, com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMapList map ); 61 | 62 | public void processedMapList( com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMapList map ) { 63 | __processedMapList( __swiftObject, map ); 64 | } 65 | 66 | /// public abstract void com.johnholdsworth.swiftbindings.SwiftHelloBinding$Listener.setCacheDir(java.lang.String) 67 | 68 | public native void __setCacheDir( long __swiftObject, java.lang.String cacheDir ); 69 | 70 | public void setCacheDir( java.lang.String cacheDir ) { 71 | __setCacheDir( __swiftObject, cacheDir ); 72 | } 73 | 74 | /// public abstract com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener com.johnholdsworth.swiftbindings.SwiftHelloBinding$Listener.testResponder(int) 75 | 76 | public native com.johnholdsworth.swiftbindings.SwiftHelloTest.TestListener __testResponder( long __swiftObject, int loopback ); 77 | 78 | public com.johnholdsworth.swiftbindings.SwiftHelloTest.TestListener testResponder( int loopback ) { 79 | return __testResponder( __swiftObject, loopback ); 80 | } 81 | 82 | /// public abstract double com.johnholdsworth.swiftbindings.SwiftHelloBinding$Listener.throwException() throws java.lang.Exception 83 | 84 | public native double __throwException( long __swiftObject ); 85 | 86 | public double throwException() throws java.lang.Exception { 87 | return __throwException( __swiftObject ); 88 | } 89 | 90 | public native void __finalize( long __swiftObject ); 91 | 92 | public void finalize() { 93 | __finalize( __swiftObject ); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /app/src/main/java/org/swiftjava/com_johnholdsworth/SwiftHelloTest_TestListenerProxy.java: -------------------------------------------------------------------------------- 1 | 2 | /// generated by: genswift.java 'java/lang|java/util|java/sql|java/awt|javax/swing' /// 3 | 4 | /// interface com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener /// 5 | 6 | package org.swiftjava.com_johnholdsworth; 7 | 8 | @SuppressWarnings("JniMissingFunction") 9 | public class SwiftHelloTest_TestListenerProxy implements com.johnholdsworth.swiftbindings.SwiftHelloTest.TestListener { 10 | 11 | // address of proxy object 12 | long __swiftObject; 13 | 14 | SwiftHelloTest_TestListenerProxy( long __swiftObject ) { 15 | this.__swiftObject = __swiftObject; 16 | } 17 | 18 | /// public abstract java.lang.String[][] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.String2dArrayMethod(java.lang.String[][]) 19 | 20 | public native java.lang.String[][] __String2dArrayMethod( long __swiftObject, java.lang.String[][] arg ); 21 | 22 | public java.lang.String[][] String2dArrayMethod( java.lang.String[][] arg ) { 23 | return __String2dArrayMethod( __swiftObject, arg ); 24 | } 25 | 26 | /// public abstract java.lang.String[] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.StringArrayMethod(java.lang.String[]) 27 | 28 | public native java.lang.String[] __StringArrayMethod( long __swiftObject, java.lang.String[] arg ); 29 | 30 | public java.lang.String[] StringArrayMethod( java.lang.String[] arg ) { 31 | return __StringArrayMethod( __swiftObject, arg ); 32 | } 33 | 34 | /// public abstract java.lang.String com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.StringMethod(java.lang.String) 35 | 36 | public native java.lang.String __StringMethod( long __swiftObject, java.lang.String arg ); 37 | 38 | public java.lang.String StringMethod( java.lang.String arg ) { 39 | return __StringMethod( __swiftObject, arg ); 40 | } 41 | 42 | /// public abstract com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener[][] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.TestListener2dArrayMethod(com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener[][]) 43 | 44 | public native com.johnholdsworth.swiftbindings.SwiftHelloTest.TestListener[][] __TestListener2dArrayMethod( long __swiftObject, com.johnholdsworth.swiftbindings.SwiftHelloTest.TestListener[][] arg ); 45 | 46 | public com.johnholdsworth.swiftbindings.SwiftHelloTest.TestListener[][] TestListener2dArrayMethod( com.johnholdsworth.swiftbindings.SwiftHelloTest.TestListener[][] arg ) { 47 | return __TestListener2dArrayMethod( __swiftObject, arg ); 48 | } 49 | 50 | /// public abstract com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener[] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.TestListenerArrayMethod(com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener[]) 51 | 52 | public native com.johnholdsworth.swiftbindings.SwiftHelloTest.TestListener[] __TestListenerArrayMethod( long __swiftObject, com.johnholdsworth.swiftbindings.SwiftHelloTest.TestListener[] arg ); 53 | 54 | public com.johnholdsworth.swiftbindings.SwiftHelloTest.TestListener[] TestListenerArrayMethod( com.johnholdsworth.swiftbindings.SwiftHelloTest.TestListener[] arg ) { 55 | return __TestListenerArrayMethod( __swiftObject, arg ); 56 | } 57 | 58 | /// public abstract com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.TestListenerMethod(com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener) 59 | 60 | public native com.johnholdsworth.swiftbindings.SwiftHelloTest.TestListener __TestListenerMethod( long __swiftObject, com.johnholdsworth.swiftbindings.SwiftHelloTest.TestListener arg ); 61 | 62 | public com.johnholdsworth.swiftbindings.SwiftHelloTest.TestListener TestListenerMethod( com.johnholdsworth.swiftbindings.SwiftHelloTest.TestListener arg ) { 63 | return __TestListenerMethod( __swiftObject, arg ); 64 | } 65 | 66 | /// public abstract boolean[][] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.boolean2dArrayMethod(boolean[][]) 67 | 68 | public native boolean[][] __boolean2dArrayMethod( long __swiftObject, boolean[][] arg ); 69 | 70 | public boolean[][] boolean2dArrayMethod( boolean[][] arg ) { 71 | return __boolean2dArrayMethod( __swiftObject, arg ); 72 | } 73 | 74 | /// public abstract boolean[] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.booleanArrayMethod(boolean[]) 75 | 76 | public native boolean[] __booleanArrayMethod( long __swiftObject, boolean[] arg ); 77 | 78 | public boolean[] booleanArrayMethod( boolean[] arg ) { 79 | return __booleanArrayMethod( __swiftObject, arg ); 80 | } 81 | 82 | /// public abstract boolean com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.booleanMethod(boolean) 83 | 84 | public native boolean __booleanMethod( long __swiftObject, boolean arg ); 85 | 86 | public boolean booleanMethod( boolean arg ) { 87 | return __booleanMethod( __swiftObject, arg ); 88 | } 89 | 90 | /// public abstract byte[][] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.byte2dArrayMethod(byte[][]) 91 | 92 | public native byte[][] __byte2dArrayMethod( long __swiftObject, byte[][] arg ); 93 | 94 | public byte[][] byte2dArrayMethod( byte[][] arg ) { 95 | return __byte2dArrayMethod( __swiftObject, arg ); 96 | } 97 | 98 | /// public abstract byte[] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.byteArrayMethod(byte[]) 99 | 100 | public native byte[] __byteArrayMethod( long __swiftObject, byte[] arg ); 101 | 102 | public byte[] byteArrayMethod( byte[] arg ) { 103 | return __byteArrayMethod( __swiftObject, arg ); 104 | } 105 | 106 | /// public abstract byte com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.byteMethod(byte) 107 | 108 | public native byte __byteMethod( long __swiftObject, byte arg ); 109 | 110 | public byte byteMethod( byte arg ) { 111 | return __byteMethod( __swiftObject, arg ); 112 | } 113 | 114 | /// public abstract char[][] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.char2dArrayMethod(char[][]) 115 | 116 | public native char[][] __char2dArrayMethod( long __swiftObject, char[][] arg ); 117 | 118 | public char[][] char2dArrayMethod( char[][] arg ) { 119 | return __char2dArrayMethod( __swiftObject, arg ); 120 | } 121 | 122 | /// public abstract char[] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.charArrayMethod(char[]) 123 | 124 | public native char[] __charArrayMethod( long __swiftObject, char[] arg ); 125 | 126 | public char[] charArrayMethod( char[] arg ) { 127 | return __charArrayMethod( __swiftObject, arg ); 128 | } 129 | 130 | /// public abstract char com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.charMethod(char) 131 | 132 | public native char __charMethod( long __swiftObject, char arg ); 133 | 134 | public char charMethod( char arg ) { 135 | return __charMethod( __swiftObject, arg ); 136 | } 137 | 138 | /// public abstract double[][] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.double2dArrayMethod(double[][]) 139 | 140 | public native double[][] __double2dArrayMethod( long __swiftObject, double[][] arg ); 141 | 142 | public double[][] double2dArrayMethod( double[][] arg ) { 143 | return __double2dArrayMethod( __swiftObject, arg ); 144 | } 145 | 146 | /// public abstract double[] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.doubleArrayMethod(double[]) 147 | 148 | public native double[] __doubleArrayMethod( long __swiftObject, double[] arg ); 149 | 150 | public double[] doubleArrayMethod( double[] arg ) { 151 | return __doubleArrayMethod( __swiftObject, arg ); 152 | } 153 | 154 | /// public abstract double com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.doubleMethod(double) 155 | 156 | public native double __doubleMethod( long __swiftObject, double arg ); 157 | 158 | public double doubleMethod( double arg ) { 159 | return __doubleMethod( __swiftObject, arg ); 160 | } 161 | 162 | /// public abstract float[][] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.float2dArrayMethod(float[][]) 163 | 164 | public native float[][] __float2dArrayMethod( long __swiftObject, float[][] arg ); 165 | 166 | public float[][] float2dArrayMethod( float[][] arg ) { 167 | return __float2dArrayMethod( __swiftObject, arg ); 168 | } 169 | 170 | /// public abstract float[] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.floatArrayMethod(float[]) 171 | 172 | public native float[] __floatArrayMethod( long __swiftObject, float[] arg ); 173 | 174 | public float[] floatArrayMethod( float[] arg ) { 175 | return __floatArrayMethod( __swiftObject, arg ); 176 | } 177 | 178 | /// public abstract float com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.floatMethod(float) 179 | 180 | public native float __floatMethod( long __swiftObject, float arg ); 181 | 182 | public float floatMethod( float arg ) { 183 | return __floatMethod( __swiftObject, arg ); 184 | } 185 | 186 | /// public abstract int[][] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.int2dArrayMethod(int[][]) 187 | 188 | public native int[][] __int2dArrayMethod( long __swiftObject, int[][] arg ); 189 | 190 | public int[][] int2dArrayMethod( int[][] arg ) { 191 | return __int2dArrayMethod( __swiftObject, arg ); 192 | } 193 | 194 | /// public abstract int[] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.intArrayMethod(int[]) 195 | 196 | public native int[] __intArrayMethod( long __swiftObject, int[] arg ); 197 | 198 | public int[] intArrayMethod( int[] arg ) { 199 | return __intArrayMethod( __swiftObject, arg ); 200 | } 201 | 202 | /// public abstract int com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.intMethod(int) 203 | 204 | public native int __intMethod( long __swiftObject, int arg ); 205 | 206 | public int intMethod( int arg ) { 207 | return __intMethod( __swiftObject, arg ); 208 | } 209 | 210 | /// public abstract long[][] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.long2dArrayMethod(long[][]) 211 | 212 | public native long[][] __long2dArrayMethod( long __swiftObject, long[][] arg ); 213 | 214 | public long[][] long2dArrayMethod( long[][] arg ) { 215 | return __long2dArrayMethod( __swiftObject, arg ); 216 | } 217 | 218 | /// public abstract long[] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.longArrayMethod(long[]) 219 | 220 | public native long[] __longArrayMethod( long __swiftObject, long[] arg ); 221 | 222 | public long[] longArrayMethod( long[] arg ) { 223 | return __longArrayMethod( __swiftObject, arg ); 224 | } 225 | 226 | /// public abstract long com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.longMethod(long) 227 | 228 | public native long __longMethod( long __swiftObject, long arg ); 229 | 230 | public long longMethod( long arg ) { 231 | return __longMethod( __swiftObject, arg ); 232 | } 233 | 234 | /// public abstract void com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.setLoopback(com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener) 235 | 236 | public native void __setLoopback( long __swiftObject, com.johnholdsworth.swiftbindings.SwiftHelloTest.TestListener loopback ); 237 | 238 | public void setLoopback( com.johnholdsworth.swiftbindings.SwiftHelloTest.TestListener loopback ) { 239 | __setLoopback( __swiftObject, loopback ); 240 | } 241 | 242 | /// public abstract short[][] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.short2dArrayMethod(short[][]) 243 | 244 | public native short[][] __short2dArrayMethod( long __swiftObject, short[][] arg ); 245 | 246 | public short[][] short2dArrayMethod( short[][] arg ) { 247 | return __short2dArrayMethod( __swiftObject, arg ); 248 | } 249 | 250 | /// public abstract short[] com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.shortArrayMethod(short[]) 251 | 252 | public native short[] __shortArrayMethod( long __swiftObject, short[] arg ); 253 | 254 | public short[] shortArrayMethod( short[] arg ) { 255 | return __shortArrayMethod( __swiftObject, arg ); 256 | } 257 | 258 | /// public abstract short com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.shortMethod(short) 259 | 260 | public native short __shortMethod( long __swiftObject, short arg ); 261 | 262 | public short shortMethod( short arg ) { 263 | return __shortMethod( __swiftObject, arg ); 264 | } 265 | 266 | /// public abstract com.johnholdsworth.swiftbindings.SwiftHelloTypes$ListenerMap com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.testMap(com.johnholdsworth.swiftbindings.SwiftHelloTypes$ListenerMap) 267 | 268 | public native com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMap __testMap( long __swiftObject, com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMap arg ); 269 | 270 | public com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMap testMap( com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMap arg ) { 271 | return __testMap( __swiftObject, arg ); 272 | } 273 | 274 | /// public abstract com.johnholdsworth.swiftbindings.SwiftHelloTypes$ListenerMapList com.johnholdsworth.swiftbindings.SwiftHelloTest$TestListener.testMapList(com.johnholdsworth.swiftbindings.SwiftHelloTypes$ListenerMapList) 275 | 276 | public native com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMapList __testMapList( long __swiftObject, com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMapList arg ); 277 | 278 | public com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMapList testMapList( com.johnholdsworth.swiftbindings.SwiftHelloTypes.ListenerMapList arg ) { 279 | return __testMapList( __swiftObject, arg ); 280 | } 281 | 282 | public native void __finalize( long __swiftObject ); 283 | 284 | public void finalize() { 285 | __finalize( __swiftObject ); 286 | } 287 | 288 | } 289 | -------------------------------------------------------------------------------- /app/src/main/java/org/swiftjava/com_johnholdsworth/SwiftHelloTypes_TextListenerProxy.java: -------------------------------------------------------------------------------- 1 | 2 | /// generated by: genswift.java 'java/lang|java/util|java/sql|java/awt|javax/swing' /// 3 | 4 | /// interface com.johnholdsworth.swiftbindings.SwiftHelloTypes$TextListener /// 5 | 6 | package org.swiftjava.com_johnholdsworth; 7 | 8 | @SuppressWarnings("JniMissingFunction") 9 | public class SwiftHelloTypes_TextListenerProxy implements com.johnholdsworth.swiftbindings.SwiftHelloTypes.TextListener { 10 | 11 | // address of proxy object 12 | long __swiftObject; 13 | 14 | SwiftHelloTypes_TextListenerProxy( long __swiftObject ) { 15 | this.__swiftObject = __swiftObject; 16 | } 17 | 18 | /// public abstract java.lang.String com.johnholdsworth.swiftbindings.SwiftHelloTypes$TextListener.getText() 19 | 20 | public native java.lang.String __getText( long __swiftObject ); 21 | 22 | public java.lang.String getText() { 23 | return __getText( __swiftObject ); 24 | } 25 | 26 | public native void __finalize( long __swiftObject ); 27 | 28 | public void finalize() { 29 | __finalize( __swiftObject ); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/org/swiftjava/java_swift/RunnableProxy.java: -------------------------------------------------------------------------------- 1 | 2 | /// generated by: genswift.java 'java/lang|java/util|java/sql|java/awt|javax/swing' /// 3 | 4 | /// interface java.lang.Runnable /// 5 | 6 | package org.swiftjava.java_swift; 7 | 8 | @SuppressWarnings("JniMissingFunction") 9 | public class RunnableProxy implements java.lang.Runnable { 10 | 11 | // address of proxy object 12 | long __swiftObject; 13 | 14 | RunnableProxy( long __swiftObject ) { 15 | this.__swiftObject = __swiftObject; 16 | } 17 | 18 | /// public abstract void java.lang.Runnable.run() 19 | 20 | public native void __run( long __swiftObject ); 21 | 22 | public void run() { 23 | __run( __swiftObject ); 24 | } 25 | 26 | public native void __finalize( long __swiftObject ); 27 | 28 | public void finalize() { 29 | __finalize( __swiftObject ); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftJava/swift-android-kotlin/5514cf5c8da9609793470b384d991ffeb7a11281/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftJava/swift-android-kotlin/5514cf5c8da9609793470b384d991ffeb7a11281/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftJava/swift-android-kotlin/5514cf5c8da9609793470b384d991ffeb7a11281/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftJava/swift-android-kotlin/5514cf5c8da9609793470b384d991ffeb7a11281/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftJava/swift-android-kotlin/5514cf5c8da9609793470b384d991ffeb7a11281/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftJava/swift-android-kotlin/5514cf5c8da9609793470b384d991ffeb7a11281/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftJava/swift-android-kotlin/5514cf5c8da9609793470b384d991ffeb7a11281/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftJava/swift-android-kotlin/5514cf5c8da9609793470b384d991ffeb7a11281/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftJava/swift-android-kotlin/5514cf5c8da9609793470b384d991ffeb7a11281/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwiftJava/swift-android-kotlin/5514cf5c8da9609793470b384d991ffeb7a11281/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 16dp 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | My Application 3 | Settings 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 |