Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit 3929206

Browse files
committed
add ComposGraph3d demo
1 parent e260d13 commit 3929206

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3340
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

demoProjects/ComposeGraph3d/.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
plugins {
2+
id 'com.android.application'
3+
id 'org.jetbrains.kotlin.android'
4+
}
5+
6+
android {
7+
namespace 'android.support.composegraph3d'
8+
compileSdk 33
9+
10+
defaultConfig {
11+
applicationId "android.support.composegraph3d"
12+
minSdk 25
13+
targetSdk 33
14+
versionCode 1
15+
versionName "1.0"
16+
17+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18+
vectorDrawables {
19+
useSupportLibrary true
20+
}
21+
}
22+
23+
buildTypes {
24+
release {
25+
minifyEnabled false
26+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
27+
}
28+
}
29+
compileOptions {
30+
sourceCompatibility JavaVersion.VERSION_1_8
31+
targetCompatibility JavaVersion.VERSION_1_8
32+
}
33+
kotlinOptions {
34+
jvmTarget = '1.8'
35+
}
36+
buildFeatures {
37+
compose true
38+
}
39+
composeOptions {
40+
kotlinCompilerExtensionVersion '1.2.0'
41+
}
42+
packagingOptions {
43+
resources {
44+
excludes += '/META-INF/{AL2.0,LGPL2.1}'
45+
}
46+
}
47+
}
48+
49+
dependencies {
50+
51+
implementation 'androidx.core:core-ktx:1.7.0'
52+
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
53+
implementation 'androidx.activity:activity-compose:1.3.1'
54+
implementation "androidx.compose.ui:ui:$compose_ui_version"
55+
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
56+
implementation 'androidx.compose.material:material:1.2.0'
57+
testImplementation 'junit:junit:4.13.2'
58+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
59+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
60+
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_ui_version"
61+
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
62+
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"
63+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package android.support.composegraph3d
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("android.support.composegraph3d", appContext.packageName)
23+
}
24+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:dataExtractionRules="@xml/data_extraction_rules"
8+
android:fullBackupContent="@xml/backup_rules"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:supportsRtl="true"
12+
android:theme="@style/Theme.ComposeGraph3d"
13+
tools:targetApi="31">
14+
<activity
15+
android:name=".MainActivity"
16+
android:exported="true"
17+
android:label="@string/app_name"
18+
android:theme="@style/Theme.ComposeGraph3d">
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
22+
<category android:name="android.intent.category.LAUNCHER" />
23+
</intent-filter>
24+
</activity>
25+
</application>
26+
27+
</manifest>
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package android.support.composegraph3d
2+
3+
import android.os.Bundle
4+
import android.support.composegraph3d.lib.Graph
5+
import android.support.composegraph3d.ui.theme.ComposeGraph3dTheme
6+
import androidx.activity.ComponentActivity
7+
import androidx.activity.compose.setContent
8+
import androidx.compose.foundation.Canvas
9+
import androidx.compose.foundation.background
10+
import androidx.compose.foundation.gestures.detectDragGestures
11+
import androidx.compose.foundation.layout.*
12+
import androidx.compose.material.MaterialTheme
13+
import androidx.compose.material.Surface
14+
import androidx.compose.material.Text
15+
import androidx.compose.runtime.*
16+
import androidx.compose.ui.Modifier
17+
import androidx.compose.ui.geometry.Offset
18+
import androidx.compose.ui.graphics.Color
19+
import androidx.compose.ui.graphics.drawscope.scale
20+
import androidx.compose.ui.input.pointer.pointerInput
21+
import androidx.compose.ui.layout.HorizontalAlignmentLine
22+
import androidx.compose.ui.layout.onPlaced
23+
import androidx.compose.ui.tooling.preview.Preview
24+
import androidx.compose.ui.unit.dp
25+
import kotlinx.coroutines.isActive
26+
27+
class MainActivity : ComponentActivity() {
28+
override fun onCreate(savedInstanceState: Bundle?) {
29+
super.onCreate(savedInstanceState)
30+
setContent {
31+
ComposeGraph3dTheme {
32+
// A surface container using the 'background' color from the theme
33+
Surface(
34+
modifier = Modifier.fillMaxSize(),
35+
color = MaterialTheme.colors.background
36+
) {
37+
Greeting("Android")
38+
}
39+
}
40+
}
41+
}
42+
}
43+
44+
@Composable
45+
fun Greeting(name: String) {
46+
val w = 600
47+
val h = 600
48+
Column(
49+
modifier = Modifier
50+
.background(Color.LightGray)
51+
.fillMaxSize()
52+
) {
53+
Text(text = "Hello $name!")
54+
Graph3D(
55+
Modifier.fillMaxWidth().aspectRatio(1f)
56+
57+
.background(Color.White))
58+
Text(text = "Hello $name!")
59+
}
60+
}
61+
62+
63+
@Composable
64+
fun Graph3D(modifier: Modifier) {
65+
var graph = remember { Graph() }
66+
val time = remember { mutableStateOf(System.nanoTime()) }
67+
68+
LaunchedEffect(Unit) {
69+
while (isActive) {
70+
withFrameNanos {
71+
time.value = System.nanoTime()
72+
}
73+
}
74+
}
75+
76+
var bitmap = graph.getImageForTime(time.value)
77+
78+
Canvas(modifier = modifier
79+
.onPlaced {
80+
graph.setSize(it.size.width, it.size.width)
81+
}
82+
.pointerInput(Unit) {
83+
detectDragGestures(
84+
onDragStart = {
85+
graph.dragStart(it)
86+
},
87+
onDragEnd = {
88+
graph.dragStopped()
89+
},
90+
onDragCancel = {
91+
graph.dragStopped()
92+
},
93+
onDrag = { change, dragAmount ->
94+
graph.drag(change, dragAmount)
95+
}
96+
)
97+
}) {
98+
scale(2.0f, pivot = Offset(0f,0f)) {
99+
drawImage(bitmap)
100+
}
101+
}
102+
103+
}
104+
105+
@Preview(showBackground = true)
106+
@Composable
107+
fun DefaultPreview() {
108+
ComposeGraph3dTheme {
109+
Greeting("Android")
110+
}
111+
}

0 commit comments

Comments
 (0)