Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
llama.cpp
Commits
4cc1a614
Commit
4cc1a614
authored
Nov 11, 2024
by
xuxzh1
🎱
Browse files
init
parents
Pipeline
#1891
canceled with stages
Changes
288
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
821 additions
and
0 deletions
+821
-0
examples/llama.android/app/build.gradle.kts
examples/llama.android/app/build.gradle.kts
+65
-0
examples/llama.android/app/proguard-rules.pro
examples/llama.android/app/proguard-rules.pro
+21
-0
examples/llama.android/app/src/main/AndroidManifest.xml
examples/llama.android/app/src/main/AndroidManifest.xml
+30
-0
examples/llama.android/app/src/main/java/com/example/llama/Downloadable.kt
...droid/app/src/main/java/com/example/llama/Downloadable.kt
+119
-0
examples/llama.android/app/src/main/java/com/example/llama/MainActivity.kt
...droid/app/src/main/java/com/example/llama/MainActivity.kt
+154
-0
examples/llama.android/app/src/main/java/com/example/llama/MainViewModel.kt
...roid/app/src/main/java/com/example/llama/MainViewModel.kt
+105
-0
examples/llama.android/app/src/main/java/com/example/llama/ui/theme/Color.kt
...oid/app/src/main/java/com/example/llama/ui/theme/Color.kt
+11
-0
examples/llama.android/app/src/main/java/com/example/llama/ui/theme/Theme.kt
...oid/app/src/main/java/com/example/llama/ui/theme/Theme.kt
+70
-0
examples/llama.android/app/src/main/java/com/example/llama/ui/theme/Type.kt
...roid/app/src/main/java/com/example/llama/ui/theme/Type.kt
+34
-0
examples/llama.android/app/src/main/res/drawable/ic_launcher_background.xml
...roid/app/src/main/res/drawable/ic_launcher_background.xml
+170
-0
examples/llama.android/app/src/main/res/drawable/ic_launcher_foreground.xml
...roid/app/src/main/res/drawable/ic_launcher_foreground.xml
+30
-0
examples/llama.android/app/src/main/res/mipmap-anydpi/ic_launcher.xml
...ma.android/app/src/main/res/mipmap-anydpi/ic_launcher.xml
+6
-0
examples/llama.android/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml
...roid/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml
+6
-0
examples/llama.android/app/src/main/res/mipmap-hdpi/ic_launcher.webp
...ama.android/app/src/main/res/mipmap-hdpi/ic_launcher.webp
+0
-0
examples/llama.android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
...droid/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
+0
-0
examples/llama.android/app/src/main/res/mipmap-mdpi/ic_launcher.webp
...ama.android/app/src/main/res/mipmap-mdpi/ic_launcher.webp
+0
-0
examples/llama.android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
...droid/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
+0
-0
examples/llama.android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
...ma.android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
+0
-0
examples/llama.android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
...roid/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
+0
-0
examples/llama.android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
...a.android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
+0
-0
No files found.
Too many changes to show.
To preserve performance only
288 of 288+
files are displayed.
Plain diff
Email patch
examples/llama.android/app/build.gradle.kts
0 → 100644
View file @
4cc1a614
plugins
{
id
(
"com.android.application"
)
id
(
"org.jetbrains.kotlin.android"
)
}
android
{
namespace
=
"com.example.llama"
compileSdk
=
34
defaultConfig
{
applicationId
=
"com.example.llama"
minSdk
=
33
targetSdk
=
34
versionCode
=
1
versionName
=
"1.0"
testInstrumentationRunner
=
"androidx.test.runner.AndroidJUnitRunner"
vectorDrawables
{
useSupportLibrary
=
true
}
}
buildTypes
{
release
{
isMinifyEnabled
=
false
proguardFiles
(
getDefaultProguardFile
(
"proguard-android-optimize.txt"
),
"proguard-rules.pro"
)
}
}
compileOptions
{
sourceCompatibility
=
JavaVersion
.
VERSION_1_8
targetCompatibility
=
JavaVersion
.
VERSION_1_8
}
kotlinOptions
{
jvmTarget
=
"1.8"
}
buildFeatures
{
compose
=
true
}
composeOptions
{
kotlinCompilerExtensionVersion
=
"1.5.1"
}
}
dependencies
{
implementation
(
"androidx.core:core-ktx:1.12.0"
)
implementation
(
"androidx.lifecycle:lifecycle-runtime-ktx:2.6.2"
)
implementation
(
"androidx.activity:activity-compose:1.8.2"
)
implementation
(
platform
(
"androidx.compose:compose-bom:2023.08.00"
))
implementation
(
"androidx.compose.ui:ui"
)
implementation
(
"androidx.compose.ui:ui-graphics"
)
implementation
(
"androidx.compose.ui:ui-tooling-preview"
)
implementation
(
"androidx.compose.material3:material3"
)
implementation
(
project
(
":llama"
))
testImplementation
(
"junit:junit:4.13.2"
)
androidTestImplementation
(
"androidx.test.ext:junit:1.1.5"
)
androidTestImplementation
(
"androidx.test.espresso:espresso-core:3.5.1"
)
androidTestImplementation
(
platform
(
"androidx.compose:compose-bom:2023.08.00"
))
androidTestImplementation
(
"androidx.compose.ui:ui-test-junit4"
)
debugImplementation
(
"androidx.compose.ui:ui-tooling"
)
debugImplementation
(
"androidx.compose.ui:ui-test-manifest"
)
}
examples/llama.android/app/proguard-rules.pro
0 → 100644
View file @
4cc1a614
# Add project specific ProGuard rules here.
#
You
can
control
the
set
of
applied
configuration
files
using
the
#
proguardFiles
setting
in
build
.
gradle
.
#
#
For
more
details
,
see
#
http
://
developer
.
android
.
com
/
guide
/
developing
/
tools
/
proguard
.
html
#
If
your
project
uses
WebView
with
JS
,
uncomment
the
following
#
and
specify
the
fully
qualified
class
name
to
the
JavaScript
interface
#
class
:
#-
keepclassmembers
class
fqcn
.
of
.
javascript
.
interface
.
for
.
webview
{
#
public
*
;
#
}
#
Uncomment
this
to
preserve
the
line
number
information
for
#
debugging
stack
traces
.
#-
keepattributes
SourceFile
,
LineNumberTable
#
If
you
keep
the
line
number
information
,
uncomment
this
to
#
hide
the
original
source
file
name
.
#-
renamesourcefileattribute
SourceFile
examples/llama.android/app/src/main/AndroidManifest.xml
0 → 100644
View file @
4cc1a614
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<application
android:allowBackup=
"true"
android:dataExtractionRules=
"@xml/data_extraction_rules"
android:fullBackupContent=
"@xml/backup_rules"
android:icon=
"@mipmap/ic_launcher"
android:label=
"@string/app_name"
android:roundIcon=
"@mipmap/ic_launcher_round"
android:supportsRtl=
"true"
android:theme=
"@style/Theme.LlamaAndroid"
>
<activity
android:name=
".MainActivity"
android:exported=
"true"
android:theme=
"@style/Theme.LlamaAndroid"
>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
</manifest>
examples/llama.android/app/src/main/java/com/example/llama/Downloadable.kt
0 → 100644
View file @
4cc1a614
package
com.example.llama
import
android.app.DownloadManager
import
android.net.Uri
import
android.util.Log
import
androidx.compose.material3.Button
import
androidx.compose.material3.Text
import
androidx.compose.runtime.Composable
import
androidx.compose.runtime.getValue
import
androidx.compose.runtime.mutableDoubleStateOf
import
androidx.compose.runtime.mutableStateOf
import
androidx.compose.runtime.remember
import
androidx.compose.runtime.rememberCoroutineScope
import
androidx.compose.runtime.setValue
import
androidx.core.database.getLongOrNull
import
androidx.core.net.toUri
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.launch
import
java.io.File
data class
Downloadable
(
val
name
:
String
,
val
source
:
Uri
,
val
destination
:
File
)
{
companion
object
{
@JvmStatic
private
val
tag
:
String
?
=
this
::
class
.
qualifiedName
sealed
interface
State
data
object
Ready
:
State
data class
Downloading
(
val
id
:
Long
):
State
data class
Downloaded
(
val
downloadable
:
Downloadable
):
State
data class
Error
(
val
message
:
String
):
State
@JvmStatic
@Composable
fun
Button
(
viewModel
:
MainViewModel
,
dm
:
DownloadManager
,
item
:
Downloadable
)
{
var
status
:
State
by
remember
{
mutableStateOf
(
if
(
item
.
destination
.
exists
())
Downloaded
(
item
)
else
Ready
)
}
var
progress
by
remember
{
mutableDoubleStateOf
(
0.0
)
}
val
coroutineScope
=
rememberCoroutineScope
()
suspend
fun
waitForDownload
(
result
:
Downloading
,
item
:
Downloadable
):
State
{
while
(
true
)
{
val
cursor
=
dm
.
query
(
DownloadManager
.
Query
().
setFilterById
(
result
.
id
))
if
(
cursor
==
null
)
{
Log
.
e
(
tag
,
"dm.query() returned null"
)
return
Error
(
"dm.query() returned null"
)
}
if
(!
cursor
.
moveToFirst
()
||
cursor
.
count
<
1
)
{
cursor
.
close
()
Log
.
i
(
tag
,
"cursor.moveToFirst() returned false or cursor.count < 1, download canceled?"
)
return
Ready
}
val
pix
=
cursor
.
getColumnIndex
(
DownloadManager
.
COLUMN_BYTES_DOWNLOADED_SO_FAR
)
val
tix
=
cursor
.
getColumnIndex
(
DownloadManager
.
COLUMN_TOTAL_SIZE_BYTES
)
val
sofar
=
cursor
.
getLongOrNull
(
pix
)
?:
0
val
total
=
cursor
.
getLongOrNull
(
tix
)
?:
1
cursor
.
close
()
if
(
sofar
==
total
)
{
return
Downloaded
(
item
)
}
progress
=
(
sofar
*
1.0
)
/
total
delay
(
1000L
)
}
}
fun
onClick
()
{
when
(
val
s
=
status
)
{
is
Downloaded
->
{
viewModel
.
load
(
item
.
destination
.
path
)
}
is
Downloading
->
{
coroutineScope
.
launch
{
status
=
waitForDownload
(
s
,
item
)
}
}
else
->
{
item
.
destination
.
delete
()
val
request
=
DownloadManager
.
Request
(
item
.
source
).
apply
{
setTitle
(
"Downloading model"
)
setDescription
(
"Downloading model: ${item.name}"
)
setAllowedNetworkTypes
(
DownloadManager
.
Request
.
NETWORK_WIFI
)
setDestinationUri
(
item
.
destination
.
toUri
())
}
viewModel
.
log
(
"Saving ${item.name} to ${item.destination.path}"
)
Log
.
i
(
tag
,
"Saving ${item.name} to ${item.destination.path}"
)
val
id
=
dm
.
enqueue
(
request
)
status
=
Downloading
(
id
)
onClick
()
}
}
}
Button
(
onClick
=
{
onClick
()
},
enabled
=
status
!
is
Downloading
)
{
when
(
status
)
{
is
Downloading
->
Text
(
text
=
"Downloading ${(progress * 100).toInt()}%"
)
is
Downloaded
->
Text
(
"Load ${item.name}"
)
is
Ready
->
Text
(
"Download ${item.name}"
)
is
Error
->
Text
(
"Download ${item.name}"
)
}
}
}
}
}
examples/llama.android/app/src/main/java/com/example/llama/MainActivity.kt
0 → 100644
View file @
4cc1a614
package
com.example.llama
import
android.app.ActivityManager
import
android.app.DownloadManager
import
android.content.ClipData
import
android.content.ClipboardManager
import
android.net.Uri
import
android.os.Bundle
import
android.os.StrictMode
import
android.os.StrictMode.VmPolicy
import
android.text.format.Formatter
import
androidx.activity.ComponentActivity
import
androidx.activity.compose.setContent
import
androidx.activity.viewModels
import
androidx.compose.foundation.layout.Box
import
androidx.compose.foundation.layout.Column
import
androidx.compose.foundation.layout.Row
import
androidx.compose.foundation.layout.fillMaxSize
import
androidx.compose.foundation.layout.padding
import
androidx.compose.foundation.lazy.LazyColumn
import
androidx.compose.foundation.lazy.items
import
androidx.compose.foundation.lazy.rememberLazyListState
import
androidx.compose.material3.Button
import
androidx.compose.material3.LocalContentColor
import
androidx.compose.material3.MaterialTheme
import
androidx.compose.material3.OutlinedTextField
import
androidx.compose.material3.Surface
import
androidx.compose.material3.Text
import
androidx.compose.runtime.Composable
import
androidx.compose.ui.Modifier
import
androidx.compose.ui.unit.dp
import
androidx.core.content.getSystemService
import
com.example.llama.ui.theme.LlamaAndroidTheme
import
java.io.File
class
MainActivity
(
activityManager
:
ActivityManager
?
=
null
,
downloadManager
:
DownloadManager
?
=
null
,
clipboardManager
:
ClipboardManager
?
=
null
,
):
ComponentActivity
()
{
private
val
tag
:
String
?
=
this
::
class
.
simpleName
private
val
activityManager
by
lazy
{
activityManager
?:
getSystemService
<
ActivityManager
>()
!!
}
private
val
downloadManager
by
lazy
{
downloadManager
?:
getSystemService
<
DownloadManager
>()
!!
}
private
val
clipboardManager
by
lazy
{
clipboardManager
?:
getSystemService
<
ClipboardManager
>()
!!
}
private
val
viewModel
:
MainViewModel
by
viewModels
()
// Get a MemoryInfo object for the device's current memory status.
private
fun
availableMemory
():
ActivityManager
.
MemoryInfo
{
return
ActivityManager
.
MemoryInfo
().
also
{
memoryInfo
->
activityManager
.
getMemoryInfo
(
memoryInfo
)
}
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
StrictMode
.
setVmPolicy
(
VmPolicy
.
Builder
(
StrictMode
.
getVmPolicy
())
.
detectLeakedClosableObjects
()
.
build
()
)
val
free
=
Formatter
.
formatFileSize
(
this
,
availableMemory
().
availMem
)
val
total
=
Formatter
.
formatFileSize
(
this
,
availableMemory
().
totalMem
)
viewModel
.
log
(
"Current memory: $free / $total"
)
viewModel
.
log
(
"Downloads directory: ${getExternalFilesDir(null)}"
)
val
extFilesDir
=
getExternalFilesDir
(
null
)
val
models
=
listOf
(
Downloadable
(
"Phi-2 7B (Q4_0, 1.6 GiB)"
,
Uri
.
parse
(
"https://huggingface.co/ggml-org/models/resolve/main/phi-2/ggml-model-q4_0.gguf?download=true"
),
File
(
extFilesDir
,
"phi-2-q4_0.gguf"
),
),
Downloadable
(
"TinyLlama 1.1B (f16, 2.2 GiB)"
,
Uri
.
parse
(
"https://huggingface.co/ggml-org/models/resolve/main/tinyllama-1.1b/ggml-model-f16.gguf?download=true"
),
File
(
extFilesDir
,
"tinyllama-1.1-f16.gguf"
),
),
Downloadable
(
"Phi 2 DPO (Q3_K_M, 1.48 GiB)"
,
Uri
.
parse
(
"https://huggingface.co/TheBloke/phi-2-dpo-GGUF/resolve/main/phi-2-dpo.Q3_K_M.gguf?download=true"
),
File
(
extFilesDir
,
"phi-2-dpo.Q3_K_M.gguf"
)
),
)
setContent
{
LlamaAndroidTheme
{
// A surface container using the 'background' color from the theme
Surface
(
modifier
=
Modifier
.
fillMaxSize
(),
color
=
MaterialTheme
.
colorScheme
.
background
)
{
MainCompose
(
viewModel
,
clipboardManager
,
downloadManager
,
models
,
)
}
}
}
}
}
@Composable
fun
MainCompose
(
viewModel
:
MainViewModel
,
clipboard
:
ClipboardManager
,
dm
:
DownloadManager
,
models
:
List
<
Downloadable
>
)
{
Column
{
val
scrollState
=
rememberLazyListState
()
Box
(
modifier
=
Modifier
.
weight
(
1f
))
{
LazyColumn
(
state
=
scrollState
)
{
items
(
viewModel
.
messages
)
{
Text
(
it
,
style
=
MaterialTheme
.
typography
.
bodyLarge
.
copy
(
color
=
LocalContentColor
.
current
),
modifier
=
Modifier
.
padding
(
16
.
dp
)
)
}
}
}
OutlinedTextField
(
value
=
viewModel
.
message
,
onValueChange
=
{
viewModel
.
updateMessage
(
it
)
},
label
=
{
Text
(
"Message"
)
},
)
Row
{
Button
({
viewModel
.
send
()
})
{
Text
(
"Send"
)
}
Button
({
viewModel
.
bench
(
8
,
4
,
1
)
})
{
Text
(
"Bench"
)
}
Button
({
viewModel
.
clear
()
})
{
Text
(
"Clear"
)
}
Button
({
viewModel
.
messages
.
joinToString
(
"\n"
).
let
{
clipboard
.
setPrimaryClip
(
ClipData
.
newPlainText
(
""
,
it
))
}
})
{
Text
(
"Copy"
)
}
}
Column
{
for
(
model
in
models
)
{
Downloadable
.
Button
(
viewModel
,
dm
,
model
)
}
}
}
}
examples/llama.android/app/src/main/java/com/example/llama/MainViewModel.kt
0 → 100644
View file @
4cc1a614
package
com.example.llama
import
android.llama.cpp.LLamaAndroid
import
android.util.Log
import
androidx.compose.runtime.getValue
import
androidx.compose.runtime.mutableStateOf
import
androidx.compose.runtime.setValue
import
androidx.lifecycle.ViewModel
import
androidx.lifecycle.viewModelScope
import
kotlinx.coroutines.flow.catch
import
kotlinx.coroutines.launch
class
MainViewModel
(
private
val
llamaAndroid
:
LLamaAndroid
=
LLamaAndroid
.
instance
()):
ViewModel
()
{
companion
object
{
@JvmStatic
private
val
NanosPerSecond
=
1_000_000_000.0
}
private
val
tag
:
String
?
=
this
::
class
.
simpleName
var
messages
by
mutableStateOf
(
listOf
(
"Initializing..."
))
private
set
var
message
by
mutableStateOf
(
""
)
private
set
override
fun
onCleared
()
{
super
.
onCleared
()
viewModelScope
.
launch
{
try
{
llamaAndroid
.
unload
()
}
catch
(
exc
:
IllegalStateException
)
{
messages
+=
exc
.
message
!!
}
}
}
fun
send
()
{
val
text
=
message
message
=
""
// Add to messages console.
messages
+=
text
messages
+=
""
viewModelScope
.
launch
{
llamaAndroid
.
send
(
text
)
.
catch
{
Log
.
e
(
tag
,
"send() failed"
,
it
)
messages
+=
it
.
message
!!
}
.
collect
{
messages
=
messages
.
dropLast
(
1
)
+
(
messages
.
last
()
+
it
)
}
}
}
fun
bench
(
pp
:
Int
,
tg
:
Int
,
pl
:
Int
,
nr
:
Int
=
1
)
{
viewModelScope
.
launch
{
try
{
val
start
=
System
.
nanoTime
()
val
warmupResult
=
llamaAndroid
.
bench
(
pp
,
tg
,
pl
,
nr
)
val
end
=
System
.
nanoTime
()
messages
+=
warmupResult
val
warmup
=
(
end
-
start
).
toDouble
()
/
NanosPerSecond
messages
+=
"Warm up time: $warmup seconds, please wait..."
if
(
warmup
>
5.0
)
{
messages
+=
"Warm up took too long, aborting benchmark"
return
@launch
}
messages
+=
llamaAndroid
.
bench
(
512
,
128
,
1
,
3
)
}
catch
(
exc
:
IllegalStateException
)
{
Log
.
e
(
tag
,
"bench() failed"
,
exc
)
messages
+=
exc
.
message
!!
}
}
}
fun
load
(
pathToModel
:
String
)
{
viewModelScope
.
launch
{
try
{
llamaAndroid
.
load
(
pathToModel
)
messages
+=
"Loaded $pathToModel"
}
catch
(
exc
:
IllegalStateException
)
{
Log
.
e
(
tag
,
"load() failed"
,
exc
)
messages
+=
exc
.
message
!!
}
}
}
fun
updateMessage
(
newMessage
:
String
)
{
message
=
newMessage
}
fun
clear
()
{
messages
=
listOf
()
}
fun
log
(
message
:
String
)
{
messages
+=
message
}
}
examples/llama.android/app/src/main/java/com/example/llama/ui/theme/Color.kt
0 → 100644
View file @
4cc1a614
package
com.example.llama.ui.theme
import
androidx.compose.ui.graphics.Color
val
Purple80
=
Color
(
0xFFD0BCFF
)
val
PurpleGrey80
=
Color
(
0xFFCCC2DC
)
val
Pink80
=
Color
(
0xFFEFB8C8
)
val
Purple40
=
Color
(
0xFF6650a4
)
val
PurpleGrey40
=
Color
(
0xFF625b71
)
val
Pink40
=
Color
(
0xFF7D5260
)
examples/llama.android/app/src/main/java/com/example/llama/ui/theme/Theme.kt
0 → 100644
View file @
4cc1a614
package
com.example.llama.ui.theme
import
android.app.Activity
import
android.os.Build
import
androidx.compose.foundation.isSystemInDarkTheme
import
androidx.compose.material3.MaterialTheme
import
androidx.compose.material3.darkColorScheme
import
androidx.compose.material3.dynamicDarkColorScheme
import
androidx.compose.material3.dynamicLightColorScheme
import
androidx.compose.material3.lightColorScheme
import
androidx.compose.runtime.Composable
import
androidx.compose.runtime.SideEffect
import
androidx.compose.ui.graphics.toArgb
import
androidx.compose.ui.platform.LocalContext
import
androidx.compose.ui.platform.LocalView
import
androidx.core.view.WindowCompat
private
val
DarkColorScheme
=
darkColorScheme
(
primary
=
Purple80
,
secondary
=
PurpleGrey80
,
tertiary
=
Pink80
)
private
val
LightColorScheme
=
lightColorScheme
(
primary
=
Purple40
,
secondary
=
PurpleGrey40
,
tertiary
=
Pink40
/* Other default colors to override
background = Color(0xFFFFFBFE),
surface = Color(0xFFFFFBFE),
onPrimary = Color.White,
onSecondary = Color.White,
onTertiary = Color.White,
onBackground = Color(0xFF1C1B1F),
onSurface = Color(0xFF1C1B1F),
*/
)
@Composable
fun
LlamaAndroidTheme
(
darkTheme
:
Boolean
=
isSystemInDarkTheme
(),
// Dynamic color is available on Android 12+
dynamicColor
:
Boolean
=
true
,
content
:
@Composable
()
->
Unit
)
{
val
colorScheme
=
when
{
dynamicColor
&&
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
S
->
{
val
context
=
LocalContext
.
current
if
(
darkTheme
)
dynamicDarkColorScheme
(
context
)
else
dynamicLightColorScheme
(
context
)
}
darkTheme
->
DarkColorScheme
else
->
LightColorScheme
}
val
view
=
LocalView
.
current
if
(!
view
.
isInEditMode
)
{
SideEffect
{
val
window
=
(
view
.
context
as
Activity
).
window
window
.
statusBarColor
=
colorScheme
.
primary
.
toArgb
()
WindowCompat
.
getInsetsController
(
window
,
view
).
isAppearanceLightStatusBars
=
darkTheme
}
}
MaterialTheme
(
colorScheme
=
colorScheme
,
typography
=
Typography
,
content
=
content
)
}
examples/llama.android/app/src/main/java/com/example/llama/ui/theme/Type.kt
0 → 100644
View file @
4cc1a614
package
com.example.llama.ui.theme
import
androidx.compose.material3.Typography
import
androidx.compose.ui.text.TextStyle
import
androidx.compose.ui.text.font.FontFamily
import
androidx.compose.ui.text.font.FontWeight
import
androidx.compose.ui.unit.sp
// Set of Material typography styles to start with
val
Typography
=
Typography
(
bodyLarge
=
TextStyle
(
fontFamily
=
FontFamily
.
Default
,
fontWeight
=
FontWeight
.
Normal
,
fontSize
=
16
.
sp
,
lineHeight
=
24
.
sp
,
letterSpacing
=
0.5
.
sp
)
/* Other default text styles to override
titleLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 22.sp,
lineHeight = 28.sp,
letterSpacing = 0.sp
),
labelSmall = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Medium,
fontSize = 11.sp,
lineHeight = 16.sp,
letterSpacing = 0.5.sp
)
*/
)
examples/llama.android/app/src/main/res/drawable/ic_launcher_background.xml
0 → 100644
View file @
4cc1a614
<?xml version="1.0" encoding="utf-8"?>
<vector
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:width=
"108dp"
android:height=
"108dp"
android:viewportWidth=
"108"
android:viewportHeight=
"108"
>
<path
android:fillColor=
"#3DDC84"
android:pathData=
"M0,0h108v108h-108z"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M9,0L9,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M19,0L19,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M29,0L29,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M39,0L39,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M49,0L49,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M59,0L59,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M69,0L69,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M79,0L79,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M89,0L89,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M99,0L99,108"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,9L108,9"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,19L108,19"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,29L108,29"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,39L108,39"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,49L108,49"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,59L108,59"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,69L108,69"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,79L108,79"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,89L108,89"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M0,99L108,99"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M19,29L89,29"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M19,39L89,39"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M19,49L89,49"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M19,59L89,59"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M19,69L89,69"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M19,79L89,79"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M29,19L29,89"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M39,19L39,89"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M49,19L49,89"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M59,19L59,89"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M69,19L69,89"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
<path
android:fillColor=
"#00000000"
android:pathData=
"M79,19L79,89"
android:strokeWidth=
"0.8"
android:strokeColor=
"#33FFFFFF"
/>
</vector>
examples/llama.android/app/src/main/res/drawable/ic_launcher_foreground.xml
0 → 100644
View file @
4cc1a614
<vector
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:aapt=
"http://schemas.android.com/aapt"
android:width=
"108dp"
android:height=
"108dp"
android:viewportWidth=
"108"
android:viewportHeight=
"108"
>
<path
android:pathData=
"M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z"
>
<aapt:attr
name=
"android:fillColor"
>
<gradient
android:endX=
"85.84757"
android:endY=
"92.4963"
android:startX=
"42.9492"
android:startY=
"49.59793"
android:type=
"linear"
>
<item
android:color=
"#44000000"
android:offset=
"0.0"
/>
<item
android:color=
"#00000000"
android:offset=
"1.0"
/>
</gradient>
</aapt:attr>
</path>
<path
android:fillColor=
"#FFFFFF"
android:fillType=
"nonZero"
android:pathData=
"M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth=
"1"
android:strokeColor=
"#00000000"
/>
</vector>
examples/llama.android/app/src/main/res/mipmap-anydpi/ic_launcher.xml
0 → 100644
View file @
4cc1a614
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<background
android:drawable=
"@drawable/ic_launcher_background"
/>
<foreground
android:drawable=
"@drawable/ic_launcher_foreground"
/>
<monochrome
android:drawable=
"@drawable/ic_launcher_foreground"
/>
</adaptive-icon>
examples/llama.android/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml
0 → 100644
View file @
4cc1a614
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<background
android:drawable=
"@drawable/ic_launcher_background"
/>
<foreground
android:drawable=
"@drawable/ic_launcher_foreground"
/>
<monochrome
android:drawable=
"@drawable/ic_launcher_foreground"
/>
</adaptive-icon>
examples/llama.android/app/src/main/res/mipmap-hdpi/ic_launcher.webp
0 → 100644
View file @
4cc1a614
1.37 KB
examples/llama.android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
0 → 100644
View file @
4cc1a614
2.83 KB
examples/llama.android/app/src/main/res/mipmap-mdpi/ic_launcher.webp
0 → 100644
View file @
4cc1a614
982 Bytes
examples/llama.android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
0 → 100644
View file @
4cc1a614
1.73 KB
examples/llama.android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
0 → 100644
View file @
4cc1a614
1.86 KB
examples/llama.android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
0 → 100644
View file @
4cc1a614
3.83 KB
examples/llama.android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
0 → 100644
View file @
4cc1a614
2.82 KB
Prev
1
…
7
8
9
10
11
12
13
14
15
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment