From d9e328836d6fb634e92124805f4f2897d9887a8b Mon Sep 17 00:00:00 2001 From: edmishchenko <87074420+edmishchenko@users.noreply.github.com> Date: Mon, 29 Jan 2024 11:30:32 +0100 Subject: [PATCH] Update --- docs/css/getStarted.css | 22 +- docs/css/style.css | 21 +- docs/getStarted.html | 617 ++++++++++++++++++++++------------------ docs/img/icon_logo.png | Bin 0 -> 778 bytes docs/index.html | 22 +- 5 files changed, 373 insertions(+), 309 deletions(-) create mode 100644 docs/img/icon_logo.png diff --git a/docs/css/getStarted.css b/docs/css/getStarted.css index 4ff8419..ce7c03f 100644 --- a/docs/css/getStarted.css +++ b/docs/css/getStarted.css @@ -365,7 +365,10 @@ main .second-column .container .article-block p { margin-bottom: auto; } -main .second-column .container .article-block button { +main .second-column .container .article-block a { + display: flex; + align-items: center; + justify-content: center; height: 50px; border-radius: 4px; background: transparent; @@ -378,9 +381,11 @@ main .second-column .container .article-block button { font-family: 'Inter', sans-serif; margin-top: auto; margin-bottom: 18px; + text-decoration: none; + text-align: center; } -main .second-column .container .article-block button:hover { +main .second-column .container .article-block a:hover { background: rgba(241, 8, 55, 1); color: rgba(255, 255, 255, 1); } @@ -415,6 +420,7 @@ footer .social-media-container svg { @media (max-width: 992px) { header { + top: 0; position: fixed; background: #FFFFFF; width: 90%; @@ -426,7 +432,11 @@ footer .social-media-container svg { } main { - margin-top: 80px; + margin-top: 140px; + box-sizing: border-box; + position: fixed; + overflow-y: auto; + height: calc(100vh - 100px); } main .first-column { @@ -481,6 +491,12 @@ footer .social-media-container svg { animation: slideIn 0.5s ease-out; } + .footer { + padding-bottom: 100px; + width: 100%; + margin-top: 0; + } + @keyframes slideIn { from { transform: translateY(-100%); diff --git a/docs/css/style.css b/docs/css/style.css index f073884..7886cb0 100644 --- a/docs/css/style.css +++ b/docs/css/style.css @@ -5,7 +5,6 @@ html , body { } body { - width: 100%; margin: 0 auto; padding: 0; overflow: hidden; @@ -13,9 +12,9 @@ body { background-image: url("../img/background-desktop.png"); background-repeat: no-repeat; background-position: center; - background-attachment: fixed; background-size: cover; background-color: #0C0C2C; + background-attachment: fixed; display: flex; flex-direction: column; } @@ -56,7 +55,6 @@ main { position: absolute; left: 55%; top: 28vh; - /*bottom: -5%;*/ padding-left: 5%; } @@ -81,6 +79,7 @@ main { line-height: 0.99vw; cursor: pointer; font-family: 'Mona Sans', sans-serif; + text-decoration: none; } .content .download:hover { @@ -91,10 +90,6 @@ main { background: rgba(210, 4, 45, 1); } -.content .download-link { - text-decoration: none; -} - .content .get-started { background: transparent; border-radius: 0.5em; @@ -108,6 +103,7 @@ main { margin-left: 1.04vw; cursor: pointer; font-family: 'Mona Sans', sans-serif; + text-decoration: none; } .content .get-started:hover { @@ -127,7 +123,7 @@ main { color: rgba(255, 255, 255, 0.6); position: absolute; padding-top: 0.4vw; - margin-top: 0.4vw; + margin-top: 1.2vw; } .content .swift-for-android-text { @@ -193,9 +189,10 @@ footer .social-media-container svg { overflow-y: scroll; overflow-x: hidden; margin: 0 auto; - background-size: cover; - background-position: 69%; - background-repeat: no-repeat; + background-position: 69% top; + background-attachment: scroll; + background-size: 1190px auto; + background-color: rgb(18, 8, 66); } header .logo { @@ -256,7 +253,7 @@ footer .social-media-container svg { padding-bottom: 16px; } - .content .download { + .content .third-column .download { width: 100%; height: 59px; margin-top: 16px; diff --git a/docs/getStarted.html b/docs/getStarted.html index f5547a1..abb0559 100644 --- a/docs/getStarted.html +++ b/docs/getStarted.html @@ -5,7 +5,7 @@ Swift for Android - + @@ -26,16 +26,16 @@
Getting started

- Prerequisites
- Install
- Hello World
- Go Further
+ Prerequisites
+ Install
+ Hello World
+ Go Further

Getting Started with Swift for Android

-
+

1. Prerequisites

Before you begin Swift development for Android, make sure you have the following tools installed: @@ -48,7 +48,7 @@

1. Prerequisites

href="https://www.scade.io/download">Scade Download.
-
+

2. How to Install Swift for Android

For macOS

@@ -92,261 +92,261 @@

For macOS

For Linux

Currently Swift for Android is available for macOS only. It will be available for Linux very soon.
-

3. Next Steps: Create a Hello World App on Android Studio using Swift

-
Refer here to quickly create and run the app on Android Studio using Swift.
-
-

How to Create a Hello World Application

-
    -
  1. Open Android Studio.
  2. -
  3. Begin a new project by selecting "File" > "New" > "New Project."
  4. -
+

3. Next Steps: Create a Hello World App on Android Studio using Swift

+
Refer here to quickly create and run the app on Android Studio using Swift.
-
- -
+

How to Create a Hello World Application

+
    +
  1. Open Android Studio.
  2. +
  3. Begin a new project by selecting "File" > "New" > "New Project."
  4. +
-
    -
  1. Choose a suitable template; for this guide, select "Empty Views Activity."
  2. -
  3. Note: Ensure you choose "Empty Views Activity," not "Empty Activity."
  4. -
  5. Provide project details such as name (e.g., SwiftAndroidExample) and package name
 (e.g., com.example.myapplication).
  6. -
  7. Click "Next" to proceed.
  8. -
+
+ +
-

Initializing Swift Package Manager (SPM) Project

+
    +
  1. Choose a suitable template; for this guide, select "Empty Views Activity."
  2. +
  3. Note: Ensure you choose "Empty Views Activity," not "Empty Activity."
  4. +
  5. Provide project details such as name (e.g., SwiftAndroidExample) and package name
 (e.g., com.example.myapplication).
  6. +
  7. Click "Next" to proceed.
  8. +
-
    -
  1. To create a new Swift Package Manager (SPM) project within the app/src/main/swift subdirectory, run the following commands in the terminal:
  2. -
+

Initializing Swift Package Manager (SPM) Project

-
-
- -
-
-    cd SwiftAndroidExample/app/src/main/swift
+        
    +
  1. To create a new Swift Package Manager (SPM) project within the app/src/main/swift subdirectory, run the following commands in the terminal:
  2. +
- swift package init --name SwiftAndroidExample -
+
+
+
+
+cd SwiftAndroidExample/app/src/main/swift
 
-            
-    It will set up a new SPM project named SwiftAndroidExample inside the swift subdirectory. This project structure allows you to efficiently manage Swift dependencies and build your Swift code as a separate module within your Android Studio project.
+swift package init --name SwiftAndroidExample
             
+
- +
+It will set up a new SPM project named SwiftAndroidExample inside the swift subdirectory. This project structure allows you to efficiently manage Swift dependencies and build your Swift code as a separate module within your Android Studio project.
+        
-

Configure Gradle in build.gradle

+ -
    -
  1. In your Android project, access the app/build.gradle file.
  2. -
  3. Enhance the android section by adding:
  4. -
+

Configure Gradle in build.gradle

-
-
- -
-
-    android {
-        sourceSets {
-            main {
-                jniLibs.srcDirs = ["lib"]
-            }
+        
    +
  1. In your Android project, access the app/build.gradle file.
  2. +
  3. Enhance the android section by adding:
  4. +
+ +
+
+ +
+
+android {
+    sourceSets {
+        main {
+            jniLibs.srcDirs = ["lib"]
         }
     }
-                
-
- -
-    This informs Gradle to locate JNI libraries in the lib subdirectory.
+}
             
+
-
    -
  1. In the dependencies section, include:
  2. -
+
+This informs Gradle to locate JNI libraries in the lib subdirectory.
+        
-
-
- -
-
-    In the dependencies section, include:
-                
-
+
    +
  1. In the dependencies section, include:
  2. +
-

- This line instructs Gradle to include .jar libraries in the resulting APK. -

+
+
+ +
+
+In the dependencies section, include:
+            
+
-
    -
  1. At the end of build.gradle, insert the following custom Gradle task:
  2. -
+

+This line instructs Gradle to include .jar libraries in the resulting APK. +

-
-
- -
-
-    task buildSwiftProject(type: Exec) {
+        
    +
  1. At the end of build.gradle, insert the following custom Gradle task:
  2. +
- commandLine 'scd', +
+
+ +
+
+task buildSwiftProject(type: Exec) {
 
-                'archive', '--type', 'android',
+    commandLine 'scd',
 
-                '--path', 'src/main/swift',
+            'archive', '--type', 'android',
 
-                '--platform', 'android-arm64-v8a',
+            '--path', 'src/main/swift',
 
-                '--platform', 'android-x86_64'
-    }
+            '--platform', 'android-arm64-v8a',
 
-    tasks.whenTaskAdded { task ->
+            '--platform', 'android-x86_64'
+}
 
-        if (task.name == 'assembleDebug' || task.name == 'assembleRelease') {
+tasks.whenTaskAdded { task ->
 
-            task.dependsOn buildSwiftProject
+    if (task.name == 'assembleDebug' || task.name == 'assembleRelease') {
 
-        }
+        task.dependsOn buildSwiftProject
 
     }
-                
+ +} +
+
+ +

Initialize Swift Runtime and Load JNI Library

+
    +
  1. In MainActivity.java, add Swift runtime initialization in the onCreate method:
  2. +
+ +
+
+
+
+@Override
 
-            

Initialize Swift Runtime and Load JNI Library

-
    -
  1. In MainActivity.java, add Swift runtime initialization in the onCreate method:
  2. -
+protected void onCreate(Bundle savedInstanceState) { -
-
- -
-
-    @Override
+    super.onCreate(savedInstanceState);
 
-    protected void onCreate(Bundle savedInstanceState) {
+    setContentView(R.layout.activity_main);
 
-        super.onCreate(savedInstanceState);
+    try {
 
-        setContentView(R.layout.activity_main);
+        org.swift.swiftfoundation.SwiftFoundation.Initialize(this, false);
 
-        try {
+    } catch (Exception err) {
 
-            org.swift.swiftfoundation.SwiftFoundation.Initialize(this, false);
+        android.util.Log.e("Swift", "Can't initialize Swift Foundation: " + err.toString());
 
-        } catch (Exception err) {
+    }
 
-            android.util.Log.e("Swift", "Can't initialize Swift Foundation: " + err.toString());
+    // Continue with your activity code
 
-        }
+}
+            
+
- // Continue with your activity code +
    +
  1. Load the JNI library using:
  2. +
- } -
+
+
+
+
+System.loadLibrary("SwiftAndroidExample");
+            
+
-
    -
  1. Load the JNI library using:
  2. -
+

Java Methods Calling Swift Implementation

+

In your Android application, you can declare Java methods that serve as bridges to Swift code. The implementation of these methods will be written in Swift, allowing seamless integration between the two languages. Here's an example:

-
-
- -
-
-    System.loadLibrary("SwiftAndroidExample");
-                
+
+
+
+
+public class MainActivity extends AppCompatActivity {
 
-            

Java Methods Calling Swift Implementation

-

In your Android application, you can declare Java methods that serve as bridges to Swift code. The implementation of these methods will be written in Swift, allowing seamless integration between the two languages. Here's an example:

- -
-
- -
-
-    public class MainActivity extends AppCompatActivity {
+    // Declare a native method in Java, with the implementation in Swift
 
-        // Declare a native method in Java, with the implementation in Swift
+    public native void printHelloWorld();
 
-        public native void printHelloWorld();
+    // This method is called from Swift code, and the result is sent as an input parameter
 
-        // This method is called from Swift code, and the result is sent as an input parameter
+    public void printText(String validationResult) {
 
-        public void printText(String validationResult) {
+        // Assuming headerTV is a TextView in your layout
 
-            // Assuming headerTV is a TextView in your layout
+        headerTV.setText(validationResult);
+    }
 
-            headerTV.setText(validationResult);
-        }
+    // ... Rest of your MainActivity code
+}
+            
+
- // ... Rest of your MainActivity code - } -
-
+

The Swift implementation of printHelloWorld and the Swift code calling printText will complete the interaction between Java and Swift, providing a seamless integration of functionalities in your Android application.

-

The Swift implementation of printHelloWorld and the Swift code calling printText will complete the interaction between Java and Swift, providing a seamless integration of functionalities in your Android application.

+

Swift Implementation for Java Methods

+

The MainActivity_printHelloWorld function is annotated with @_silgen_name to set the native name for the function when called from Java. It takes the JNI environment (env) and the Java activity (activity) as parameters. Inside this function, you create a JObject wrapper for the Java activity and call the updateTasksList function to perform the desired interaction with the Java code.

-

Swift Implementation for Java Methods

-

The MainActivity_printHelloWorld function is annotated with @_silgen_name to set the native name for the function when called from Java. It takes the JNI environment (env) and the Java activity (activity) as parameters. Inside this function, you create a JObject wrapper for the Java activity and call the updateTasksList function to perform the desired interaction with the Java code.

+
+
+ +
+
+import Dispatch
 
-            
-
- -
-
-    import Dispatch
+import Foundation
 
-    import Foundation
+import Java
 
-    import Java
+// Function to update tasks list in Java
 
-    // Function to update tasks list in Java
+public func updateTasksList(activity: JObject) {
 
-    public func updateTasksList(activity: JObject) {
+  // Call the Java method "printText" with the message "Hello World!"
 
-      // Call the Java method "printText" with the message "Hello World!"
+  activity.call(method: "printText", "Hello World!")
 
-      activity.call(method: "printText", "Hello World!")
+}
 
-    }
+// Use @_silgen_name attribute to set native name for a function called from Java
 
-    // Use @_silgen_name attribute to set native name for a function called from Java
+@_silgen_name("Java_com_example_swiftandroidexample_MainActivity_printHelloWorld")
 
-    @_silgen_name("Java_com_example_swiftandroidexample_MainActivity_printHelloWorld")
+public func MainActivity_printHelloWorld(
 
-    public func MainActivity_printHelloWorld(
+  env: UnsafeMutablePointer<JNIEnv>, activity: JavaObject
 
-      env: UnsafeMutablePointer<JNIEnv>, activity: JavaObject
+) {
 
-    ) {
+  // Create JObject wrapper for the activity object
 
-      // Create JObject wrapper for the activity object
+  let mainActivity = JObject(activity)
 
-      let mainActivity = JObject(activity)
+  // Call the Swift function to update tasks list in Java
 
-      // Call the Swift function to update tasks list in Java
+  updateTasksList(activity: mainActivity)
 
-      updateTasksList(activity: mainActivity)
+}
+            
+
- } -
-
+

This Swift code demonstrates the integration of Swift functions with Java methods, allowing for bidirectional communication between Swift and Java in your Android application.

-

This Swift code demonstrates the integration of Swift functions with Java methods, allowing for bidirectional communication between Swift and Java in your Android application.

+

Run the Hello World App

+

Run the Android Appusing Swift’s code like you would run any Android project in Android Studio, on Android Emulator/Physical device. You should be able to see Hello World.

-

Run the Hello World App

-

Run the Android Appusing Swift’s code like you would run any Android project in Android Studio, on Android Emulator/Physical device. You should be able to see Hello World.

+ - +

Source Code: Please find the source code of Hello World App(Swift for Android) here

+
-

Source Code: Please find the source code of Hello World App(Swift for Android) here

-
-
-
+

Go Further

Ready to dive deeper? Here are some hand-picked resources covering various Swift features.

@@ -355,31 +355,64 @@

Go Further

Implement RecyclerView using Swift PM libraries

-

Swift for Android: How to use Swift-Crypto with Android Studio

-

Using Swift PM libraries in the Android Studio projects

-
+
@@ -422,8 +455,8 @@

Go Further

- + \ No newline at end of file diff --git a/docs/img/icon_logo.png b/docs/img/icon_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..90c760ca9442f9da2a6822a821c284cc9bcbadb1 GIT binary patch literal 778 zcmV+l1NHogP)EBrU#adhsL9^DCv)-T={(!s+Jttm6WGo#|D!(+vX zfwC_!fR3GWD|D%}Q`-#kH#-R{gwl=?Gf0sg$qJFN<3JAItQ#ZF*gzD!puzj&uffaF zZl+#gg&;d)s!*Dl+x;N}{sv0GfKBh7+#Y~rC&vnrvSX<`=0{MHRR|L~cM7Z!soco~ zgH}Lu-5}7453|LWd#|VBazXX2%?%NdUD%cb8x7{;t}>XaR^s;Ob~LOIv7J=TRLzy0 zaJHYU!8fQ+u5&+=CLJ6;I@fT;JQigyRLJ z;5>+jX<^^g-tgk~A@hAH7)-`h*gWIB#2@3ZIK6u4M`lb~SuL9*Ua~Lo+mm&lVA9G9 zPvp>tDps)Qn6(0rs#=Nq{a36YIJLDlLc+ab2Y#LvUfoI*jM$lvp#&S(-R_Tvw}#0& zv?9iCSf-z~mFLrBl?6+{!*QU~zOikCb%Eg$l3E;1Sc!rW$^%_Htv#2D9@#NvB?>0` z)UZQV2(n|!N*s)iorD#_`}FMoktr+4pJON5v0(&?*(F;ccE0~S;2dVSLVym81tGU` z5AW$Cgwr33^GIgr?%Zi9gF!fh{jIm3r(l5e;YyJ^c~%H{W*G}cl{<=Dk@4hp$4D>{ z2|E}_krl#}olG!f2ZO*N(!_`z_3N#$D*^Z - - + Swift for Android - + + @@ -22,17 +22,13 @@

Full Swift 5.8 support for 32-and 64-bit architectures on Android arm64 / x86_64 / arm / x86

- - - +

For macOS 10.15 or later

- - - +