Skip to content

Commit

Permalink
Migrated to Composable views on the Android example
Browse files Browse the repository at this point in the history
  • Loading branch information
kdewald committed Mar 27, 2024
1 parent 3390a2d commit 99f34c6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
2 changes: 2 additions & 0 deletions examples/simpleble-android/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion examples/simpleble-android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,30 @@ android {
}
buildFeatures {
viewBinding = true
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = "1.5.11"
}

}

dependencies {

implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
//implementation("androidx.constraintlayout:constraintlayout:2.1.4")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

implementation("androidx.compose.ui:ui:1.6.4")
implementation("androidx.compose.ui:ui-tooling:1.6.4")
implementation("androidx.compose.ui:ui-tooling-preview:1.6.4")
implementation("androidx.compose.foundation:foundation:1.6.4")
implementation("androidx.compose.material:material:1.6.4")
implementation("androidx.activity:activity-ktx:1.8.2")
implementation("androidx.activity:activity-compose:1.8.2")
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
package org.simpleble.android_examples

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import org.simpleble.android_examples.databinding.ActivityMainBinding
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable

class MainActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
setContent {
MaterialTheme {
Surface {
Greeting(stringFromJNI())
}
}
}
}

// Example of a call to a native method
binding.sampleText.text = stringFromJNI()
@Composable
fun Greeting(text: String) {
Text(text = text)
}

/**
* A native method that is implemented by the 'android_examples' native library,
* which is packaged with this application.
*/
external fun stringFromJNI(): String

companion object {
// Used to load the 'android_examples' library on application startup.
init {
System.loadLibrary("android_examples")
}
Expand Down
2 changes: 1 addition & 1 deletion examples/simpleble-android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.2.2" apply false
id("org.jetbrains.kotlin.android") version "1.9.22" apply false
id("org.jetbrains.kotlin.android") version "1.9.23" apply false
}

0 comments on commit 99f34c6

Please sign in to comment.