Browse Source

Update Android Examples

updateAndroidExamples
Igor Demin 2 years ago
parent
commit
ae1f72d7d5
  1. 8
      examples/codeviewer/android/build.gradle.kts
  2. 2
      examples/codeviewer/android/src/main/AndroidManifest.xml
  3. 8
      examples/codeviewer/build.gradle.kts
  4. 17
      examples/codeviewer/common/build.gradle.kts
  5. 6
      examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt
  6. 4
      examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt
  7. 1
      examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt
  8. 7
      examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt
  9. 2
      examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt
  10. 18
      examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Fonts.kt
  11. 21
      examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTreeView.kt
  12. 11
      examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt
  13. 2
      examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt
  14. 2
      examples/codeviewer/gradle.properties
  15. 8
      examples/imageviewer/android/build.gradle.kts
  16. 2
      examples/imageviewer/android/src/main/AndroidManifest.xml
  17. 10
      examples/imageviewer/common/build.gradle.kts
  18. 10
      examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/view/AndroidHover.kt
  19. 10
      examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/PointerMoveFilter.kt
  20. 74
      examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/FullscreenImage.kt
  21. 61
      examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MainScreen.kt
  22. 13
      examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MouseHover.kt
  23. 2
      examples/imageviewer/gradle.properties
  24. 6
      examples/issues/android/build.gradle.kts
  25. 2
      examples/issues/android/src/main/AndroidManifest.xml
  26. 8
      examples/issues/common/build.gradle.kts
  27. 13
      examples/issues/common/src/jvmAndAndroidMain/kotlin/androidx/ui/examples/jetissues/view/JetIssuesView.kt
  28. 2
      examples/issues/gradle.properties
  29. 10
      examples/todoapp-lite/android/build.gradle.kts
  30. 2
      examples/todoapp-lite/android/src/main/AndroidManifest.xml
  31. 6
      examples/todoapp-lite/common/build.gradle.kts
  32. 2
      examples/todoapp-lite/gradle.properties
  33. 15
      examples/visual-effects/.gitignore
  34. 6
      examples/widgets-gallery/android/build.gradle.kts
  35. 3
      examples/widgets-gallery/android/src/main/AndroidManifest.xml
  36. 10
      examples/widgets-gallery/common/build.gradle.kts
  37. 6
      examples/widgets-gallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt
  38. 6
      examples/widgets-gallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Resources.kt
  39. 6
      examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt
  40. 18
      examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/MainView.kt
  41. 8
      examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/WidgetsType.kt
  42. 2
      examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/utils/Text.kt
  43. 8
      examples/widgets-gallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt
  44. 2
      examples/widgets-gallery/gradle.properties

8
examples/codeviewer/android/build.gradle.kts

@ -5,11 +5,11 @@ plugins {
}
android {
compileSdkVersion(31)
compileSdk = 32
defaultConfig {
minSdkVersion(26)
targetSdkVersion(31)
minSdk = 26
targetSdk = 32
versionCode = 1
versionName = "1.0"
}
@ -22,5 +22,5 @@ android {
dependencies {
implementation(project(":common"))
implementation("androidx.activity:activity-compose:1.4.0")
implementation("androidx.activity:activity-compose:1.5.0")
}

2
examples/codeviewer/android/src/main/AndroidManifest.xml

@ -12,7 +12,7 @@
<activity
android:exported="true"
android:name="MainActivity"
android:label="@string/app_name">
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

8
examples/codeviewer/build.gradle.kts

@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
// this is necessary to avoid the plugins to be loaded multiple times
// in each subproject's classloader
@ -17,10 +15,4 @@ subprojects {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
plugins.withId("org.jetbrains.kotlin.multiplatform") {
tasks.withType<KotlinCompile> {
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
}
}

17
examples/codeviewer/common/build.gradle.kts

@ -1,5 +1,3 @@
import org.jetbrains.compose.compose
plugins {
id("com.android.library")
kotlin("multiplatform")
@ -22,8 +20,8 @@ kotlin {
named("androidMain") {
kotlin.srcDirs("src/jvmMain/kotlin")
dependencies {
api("androidx.appcompat:appcompat:1.4.1")
api("androidx.core:core-ktx:1.7.0")
api("androidx.appcompat:appcompat:1.5.1")
api("androidx.core:core-ktx:1.8.0")
}
}
named("desktopMain") {
@ -36,16 +34,11 @@ kotlin {
}
android {
compileSdkVersion(31)
compileSdk = 32
defaultConfig {
minSdkVersion(21)
targetSdkVersion(31)
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
minSdk = 26
targetSdk = 32
}
sourceSets {

6
examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt

@ -3,10 +3,4 @@ package org.jetbrains.codeviewer.platform
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
actual fun Modifier.pointerMoveFilter(
onEnter: () -> Boolean,
onExit: () -> Boolean,
onMove: (Offset) -> Boolean
): Modifier = this
actual fun Modifier.cursorForHorizontalResize() = this

4
examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt

@ -1,13 +1,15 @@
package org.jetbrains.codeviewer.platform
import android.annotation.SuppressLint
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
@SuppressLint("DiscouragedApi")
@Composable
actual fun Font(name: String, res: String, weight: FontWeight, style: FontStyle): Font {
actual fun font(name: String, res: String, weight: FontWeight, style: FontStyle): Font {
val context = LocalContext.current
val id = context.resources.getIdentifier(res, "font", context.packageName)
return Font(id, weight, style)

1
examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt

@ -4,7 +4,6 @@ import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
@Composable
actual fun VerticalScrollbar(

7
examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt

@ -1,12 +1,5 @@
package org.jetbrains.codeviewer.platform
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
expect fun Modifier.pointerMoveFilter(
onEnter: () -> Boolean = { true },
onExit: () -> Boolean = { true },
onMove: (Offset) -> Boolean = { true }
): Modifier
expect fun Modifier.cursorForHorizontalResize(): Modifier

2
examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt

@ -6,4 +6,4 @@ import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
@Composable
expect fun Font(name: String, res: String, weight: FontWeight, style: FontStyle): Font
expect fun font(name: String, res: String, weight: FontWeight, style: FontStyle): Font

18
examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Fonts.kt

@ -4,57 +4,57 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import org.jetbrains.codeviewer.platform.Font
import org.jetbrains.codeviewer.platform.font
object Fonts {
@Composable
fun jetbrainsMono() = FontFamily(
Font(
font(
"JetBrains Mono",
"jetbrainsmono_regular",
FontWeight.Normal,
FontStyle.Normal
),
Font(
font(
"JetBrains Mono",
"jetbrainsmono_italic",
FontWeight.Normal,
FontStyle.Italic
),
Font(
font(
"JetBrains Mono",
"jetbrainsmono_bold",
FontWeight.Bold,
FontStyle.Normal
),
Font(
font(
"JetBrains Mono",
"jetbrainsmono_bold_italic",
FontWeight.Bold,
FontStyle.Italic
),
Font(
font(
"JetBrains Mono",
"jetbrainsmono_extrabold",
FontWeight.ExtraBold,
FontStyle.Normal
),
Font(
font(
"JetBrains Mono",
"jetbrainsmono_extrabold_italic",
FontWeight.ExtraBold,
FontStyle.Italic
),
Font(
font(
"JetBrains Mono",
"jetbrainsmono_medium",
FontWeight.Medium,
FontStyle.Normal
),
Font(
font(
"JetBrains Mono",
"jetbrainsmono_medium_italic",
FontWeight.Medium,

21
examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTreeView.kt

@ -1,6 +1,9 @@
package org.jetbrains.codeviewer.ui.filetree
import androidx.compose.foundation.clickable
import androidx.compose.foundation.hoverable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsHoveredAsState
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
@ -11,6 +14,7 @@ import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
@ -24,7 +28,6 @@ import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import org.jetbrains.codeviewer.platform.VerticalScrollbar
import org.jetbrains.codeviewer.platform.pointerMoveFilter
import org.jetbrains.codeviewer.util.withoutWidthConstraints
@Composable
@ -76,25 +79,17 @@ private fun FileTreeItemView(fontSize: TextUnit, height: Dp, model: FileTree.Ite
.height(height)
.fillMaxWidth()
) {
val active = remember { mutableStateOf(false) }
val interactionSource = remember { MutableInteractionSource() }
val active by interactionSource.collectIsHoveredAsState()
FileItemIcon(Modifier.align(Alignment.CenterVertically), model)
Text(
text = model.name,
color = if (active.value) LocalContentColor.current.copy(alpha = 0.60f) else LocalContentColor.current,
color = if (active) LocalContentColor.current.copy(alpha = 0.60f) else LocalContentColor.current,
modifier = Modifier
.align(Alignment.CenterVertically)
.clipToBounds()
.pointerMoveFilter(
onEnter = {
active.value = true
true
},
onExit = {
active.value = false
true
}
),
.hoverable(interactionSource),
softWrap = true,
fontSize = fontSize,
overflow = TextOverflow.Ellipsis,

11
examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt

@ -2,20 +2,9 @@ package org.jetbrains.codeviewer.platform
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon
import androidx.compose.ui.input.pointer.pointerMoveFilter
import java.awt.Cursor
@OptIn(ExperimentalComposeUiApi::class)
actual fun Modifier.pointerMoveFilter(
onEnter: () -> Boolean,
onExit: () -> Boolean,
onMove: (Offset) -> Boolean
): Modifier = this.pointerMoveFilter(onEnter = onEnter, onExit = onExit, onMove = onMove)
@OptIn(ExperimentalComposeUiApi::class)
actual fun Modifier.cursorForHorizontalResize(): Modifier =
this.pointerHoverIcon(PointerIcon(Cursor(Cursor.E_RESIZE_CURSOR)))

2
examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt

@ -6,5 +6,5 @@ import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
@Composable
actual fun Font(name: String, res: String, weight: FontWeight, style: FontStyle): Font =
actual fun font(name: String, res: String, weight: FontWeight, style: FontStyle): Font =
androidx.compose.ui.text.platform.Font("font/$res.ttf", weight, style)

2
examples/codeviewer/gradle.properties

@ -20,5 +20,5 @@ android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
kotlin.version=1.7.10
agp.version=7.0.4
agp.version=7.1.3
compose.version=1.2.0-beta02

8
examples/imageviewer/android/build.gradle.kts

@ -5,11 +5,11 @@ plugins {
}
android {
compileSdk = 31
compileSdk = 32
defaultConfig {
minSdk = 21
targetSdk = 31
minSdk = 26
targetSdk = 32
versionCode = 1
versionName = "1.0"
}
@ -22,5 +22,5 @@ android {
dependencies {
implementation(project(":common"))
implementation("androidx.activity:activity-compose:1.3.1")
implementation("androidx.activity:activity-compose:1.5.0")
}

2
examples/imageviewer/android/src/main/AndroidManifest.xml

@ -17,7 +17,7 @@
<activity
android:exported="true"
android:name="example.imageviewer.MainActivity"
android:label="@string/app_name">
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

10
examples/imageviewer/common/build.gradle.kts

@ -20,8 +20,8 @@ kotlin {
}
named("androidMain") {
dependencies {
api("androidx.appcompat:appcompat:1.3.1")
api("androidx.core:core-ktx:1.3.1")
api("androidx.appcompat:appcompat:1.5.1")
api("androidx.core:core-ktx:1.8.0")
implementation("io.ktor:ktor-client-cio:1.4.1")
}
}
@ -35,11 +35,11 @@ kotlin {
}
android {
compileSdk = 31
compileSdk = 32
defaultConfig {
minSdk = 21
targetSdk = 31
minSdk = 26
targetSdk = 32
}
compileOptions {

10
examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/view/AndroidHover.kt

@ -1,10 +0,0 @@
package example.imageviewer.view
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
actual fun Modifier.hover(
onEnter: () -> Boolean,
onExit: () -> Boolean,
onMove: (Offset) -> Boolean
): Modifier = this

10
examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/PointerMoveFilter.kt

@ -1,10 +0,0 @@
package example.imageviewer.view
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
expect fun Modifier.hover(
onEnter: () -> Boolean = { true },
onExit: () -> Boolean = { true },
onMove: (Offset) -> Boolean = { true }
): Modifier

74
examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/FullscreenImage.kt

@ -1,8 +1,6 @@
package example.imageviewer.view
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
@ -12,22 +10,20 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsHoveredAsState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.key
@ -36,14 +32,12 @@ import androidx.compose.ui.input.key.KeyEventType
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.WindowSize
import example.imageviewer.core.FilterType
import example.imageviewer.model.AppState
import example.imageviewer.model.ContentState
import example.imageviewer.model.ScreenType
import example.imageviewer.ResString
import example.imageviewer.style.DarkGray
import example.imageviewer.style.DarkGreen
import example.imageviewer.style.Foreground
import example.imageviewer.style.MiniatureColor
import example.imageviewer.style.TranslucentBlack
@ -74,7 +68,8 @@ fun ToolBar(
text: String,
content: ContentState
) {
val backButtonHover = remember { mutableStateOf(false) }
val backButtonInteractionSource = remember { MutableInteractionSource() }
val backButtonHover by backButtonInteractionSource.collectIsHoveredAsState()
Surface(
color = MiniatureColor,
modifier = Modifier.height(44.dp)
@ -87,16 +82,9 @@ fun ToolBar(
) {
Tooltip(ResString.back) {
Clickable(
modifier = Modifier.hover(
onEnter = {
backButtonHover.value = true
false
},
onExit = {
backButtonHover.value = false
false
})
.background(color = if (backButtonHover.value) TranslucentBlack else Transparent),
modifier = Modifier
.hoverable(backButtonInteractionSource)
.background(color = if (backButtonHover) TranslucentBlack else Transparent),
onClick = {
if (content.isContentReady()) {
content.restoreMainImage()
@ -145,33 +133,27 @@ fun FilterButton(
type: FilterType,
modifier: Modifier = Modifier.size(38.dp)
) {
val filterButtonHover = remember { mutableStateOf(false) }
Box(
modifier = Modifier.background(color = Transparent).clip(CircleShape)
) {
Tooltip("$type") {
Clickable(
modifier = Modifier.hover(
onEnter = {
filterButtonHover.value = true
false
},
onExit = {
filterButtonHover.value = false
false
})
.background(color = if (filterButtonHover.value) TranslucentBlack else Transparent),
onClick = { content.toggleFilter(type)}
) {
Image(
getFilterImage(type = type, content = content),
contentDescription = null,
modifier
)
}
val interactionSource = remember { MutableInteractionSource() }
val filterButtonHover by interactionSource.collectIsHoveredAsState()
Box(
modifier = Modifier.background(color = Transparent).clip(CircleShape)
) {
Tooltip("$type") {
Clickable(
modifier = Modifier
.hoverable(interactionSource)
.background(color = if (filterButtonHover) TranslucentBlack else Transparent),
onClick = { content.toggleFilter(type)}
) {
Image(
getFilterImage(type = type, content = content),
contentDescription = null,
modifier
)
}
}
Spacer(Modifier.width(20.dp))
}
Spacer(Modifier.width(20.dp))
}
@Composable

61
examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MainScreen.kt

@ -1,9 +1,6 @@
package example.imageviewer.view
import androidx.compose.foundation.Image
import androidx.compose.foundation.VerticalScrollbar
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
@ -12,17 +9,12 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.rememberScrollbarAdapter
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsHoveredAsState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Card
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Divider
@ -31,6 +23,7 @@ import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
@ -81,7 +74,8 @@ fun TopContent(content: ContentState) {
@Composable
fun TitleBar(text: String, content: ContentState) {
val refreshButtonHover = remember { mutableStateOf(false) }
val interactionSource = remember { MutableInteractionSource() }
val refreshButtonHover by interactionSource.collectIsHoveredAsState()
TopAppBar(
backgroundColor = DarkGreen,
title = {
@ -98,17 +92,9 @@ fun TitleBar(text: String, content: ContentState) {
) {
Tooltip(ResString.refresh) {
Clickable(
modifier = Modifier.hover(
onEnter = {
refreshButtonHover.value = true
false
},
onExit = {
refreshButtonHover.value = false
false
}
)
.background(color = if (refreshButtonHover.value) TranslucentBlack else Transparent),
modifier = Modifier
.hoverable(interactionSource)
.background(color = if (refreshButtonHover) TranslucentBlack else Transparent),
onClick = {
if (content.isContentReady()) {
content.refresh()
@ -160,20 +146,15 @@ fun Miniature(
picture: Picture,
content: ContentState
) {
val cardHover = remember { mutableStateOf(false) }
val infoButtonHover = remember { mutableStateOf(false) }
val cardHoverInteractionSource = remember { MutableInteractionSource() }
val cardHover by cardHoverInteractionSource.collectIsHoveredAsState()
val infoButtonInteractionSource = remember { MutableInteractionSource() }
val infoButtonHover by infoButtonInteractionSource.collectIsHoveredAsState()
Card(
backgroundColor = if (cardHover.value) MiniatureHoverColor else MiniatureColor,
backgroundColor = if (cardHover) MiniatureHoverColor else MiniatureColor,
modifier = Modifier.padding(start = 10.dp, end = 18.dp).height(70.dp)
.fillMaxWidth()
.hover(onEnter = {
cardHover.value = true
false
},
onExit = {
cardHover.value = false
false
})
.hoverable(cardHoverInteractionSource)
.clickable {
content.setMainImage(picture)
},
@ -209,16 +190,8 @@ fun Miniature(
Clickable(
modifier = Modifier.height(70.dp)
.width(30.dp)
.hover(
onEnter = {
infoButtonHover.value = true
false
},
onExit = {
infoButtonHover.value = false
false
})
.background(color = if (infoButtonHover.value) TranslucentWhite else Transparent),
.hoverable(infoButtonInteractionSource)
.background(color = if (infoButtonHover) TranslucentWhite else Transparent),
onClick = {
showPopUpMessage(
"${ResString.picture} " +

13
examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MouseHover.kt

@ -1,13 +0,0 @@
package example.imageviewer.view
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.pointer.pointerMoveFilter
@OptIn(ExperimentalComposeUiApi::class)
actual fun Modifier.hover(
onEnter: () -> Boolean,
onExit: () -> Boolean,
onMove: (Offset) -> Boolean
): Modifier = this.pointerMoveFilter(onEnter = onEnter, onExit = onExit, onMove = onMove)

2
examples/imageviewer/gradle.properties

@ -20,5 +20,5 @@ android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
kotlin.version=1.7.10
agp.version=7.0.4
agp.version=7.1.3
compose.version=1.2.0-beta02

6
examples/issues/android/build.gradle.kts

@ -5,11 +5,11 @@ plugins {
}
android {
compileSdk = 31
compileSdk = 32
defaultConfig {
minSdk = 26
targetSdk = 31
targetSdk = 32
versionCode = 1
versionName = "1.0"
}
@ -22,5 +22,5 @@ android {
dependencies {
implementation(project(":common"))
implementation("androidx.activity:activity-compose:1.3.1")
implementation("androidx.activity:activity-compose:1.5.0")
}

2
examples/issues/android/src/main/AndroidManifest.xml

@ -12,7 +12,7 @@
<activity
android:exported="true"
android:name="androidx.ui.examples.jetissues.MainActivity"
android:label="@string/app_name">
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

8
examples/issues/common/build.gradle.kts

@ -24,8 +24,8 @@ kotlin {
named("androidMain") {
kotlin.srcDirs("src/jvmAndAndroidMain/kotlin")
dependencies {
api("androidx.appcompat:appcompat:1.3.1")
api("androidx.core:core-ktx:1.3.1")
api("androidx.appcompat:appcompat:1.5.1")
api("androidx.core:core-ktx:1.8.0")
}
}
named("desktopMain") {
@ -40,11 +40,11 @@ apollo {
}
android {
compileSdk = 31
compileSdk = 32
defaultConfig {
minSdk = 26
targetSdk = 31
targetSdk = 32
}
compileOptions {

13
examples/issues/common/src/jvmAndAndroidMain/kotlin/androidx/ui/examples/jetissues/view/JetIssuesView.kt

@ -19,6 +19,8 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@ -31,6 +33,7 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.ui.examples.jetissues.data.*
import androidx.ui.examples.jetissues.query.IssueQuery
import androidx.ui.examples.jetissues.query.IssuesQuery
@ -83,10 +86,12 @@ fun SingleColumnLayout(currentIssue: MutableState<IssuesQuery.Node?>) {
)
},
navigationIcon = {
Button(onClick = {
currentIssue.value = null
}) {
Text(text = "Back")
IconButton(
onClick = {
currentIssue.value = null
}
) {
Icon(Icons.Default.ArrowBack, contentDescription = "Back")
}
}
)

2
examples/issues/gradle.properties

@ -20,5 +20,5 @@ android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
kotlin.version=1.7.10
agp.version=7.0.4
agp.version=7.1.3
compose.version=1.2.0-beta02

10
examples/todoapp-lite/android/build.gradle.kts

@ -5,11 +5,11 @@ plugins {
}
android {
compileSdk = 31
compileSdk = 32
defaultConfig {
minSdk = 21
targetSdk = 31
minSdk = 26
targetSdk = 32
versionCode = 1
versionName = "1.0"
}
@ -23,7 +23,7 @@ android {
dependencies {
implementation(project(":common"))
implementation(compose.material)
implementation("androidx.appcompat:appcompat:1.3.0")
implementation("androidx.activity:activity-compose:1.3.0")
implementation("androidx.appcompat:appcompat:1.5.1")
implementation("androidx.activity:activity-compose:1.5.0")
}

2
examples/todoapp-lite/android/src/main/AndroidManifest.xml

@ -13,7 +13,7 @@
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name">
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>

6
examples/todoapp-lite/common/build.gradle.kts

@ -22,11 +22,11 @@ kotlin {
}
android {
compileSdk = 31
compileSdk = 32
defaultConfig {
minSdk = 21
targetSdk = 31
minSdk = 26
targetSdk = 32
}
compileOptions {

2
examples/todoapp-lite/gradle.properties

@ -20,5 +20,5 @@ android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
kotlin.version=1.7.10
agp.version=7.0.4
agp.version=7.1.3
compose.version=1.2.0-beta02

15
examples/visual-effects/.gitignore vendored

@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
build/
/captures
.externalNativeBuild
.cxx

6
examples/widgets-gallery/android/build.gradle.kts

@ -5,11 +5,11 @@ plugins {
}
android {
compileSdk = 31
compileSdk = 32
defaultConfig {
minSdk = 26
targetSdk = 30
targetSdk = 32
versionCode = 1
versionName = "1.0"
}
@ -22,5 +22,5 @@ android {
dependencies {
implementation(project(":common"))
implementation("androidx.activity:activity-compose:1.3.0")
implementation("androidx.activity:activity-compose:1.5.0")
}

3
examples/widgets-gallery/android/src/main/AndroidManifest.xml

@ -10,8 +10,9 @@
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity
android:exported="true"
android:name="MainActivity"
android:label="@string/app_name">
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

10
examples/widgets-gallery/common/build.gradle.kts

@ -21,8 +21,8 @@ kotlin {
}
named("androidMain") {
dependencies {
api("androidx.appcompat:appcompat:1.3.1")
api("androidx.core:core-ktx:1.3.1")
api("androidx.appcompat:appcompat:1.5.1")
api("androidx.core:core-ktx:1.8.0")
}
}
named("desktopMain") {
@ -34,11 +34,11 @@ kotlin {
}
android {
compileSdk = 30
compileSdk = 32
defaultConfig {
minSdk = 21
targetSdk = 30
minSdk = 26
targetSdk = 32
}
compileOptions {

6
examples/widgets-gallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt

@ -3,10 +3,4 @@ package org.jetbrains.compose.demo.widgets.platform
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
actual fun Modifier.pointerMoveFilter(
onEnter: () -> Boolean,
onExit: () -> Boolean,
onMove: (Offset) -> Boolean
): Modifier = this
actual fun Modifier.cursorForHorizontalResize() = this

6
examples/widgets-gallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Resources.kt

@ -1,10 +1,7 @@
package org.jetbrains.compose.demo.widgets.platform
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.graphics.vector.ImageVector
import org.jetbrains.compose.demo.widgets.platform.R
@Composable
actual fun painterResource(res: String): Painter {
@ -17,6 +14,5 @@ private fun drawableId(res: String): Int {
val imageName = res.substringAfterLast("/").substringBeforeLast(".")
val drawableClass = R.drawable::class.java
val field = drawableClass.getDeclaredField(imageName)
val idValue = field.get(drawableClass) as Integer
return idValue.toInt()
return field.get(drawableClass) as Int
}

6
examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt

@ -3,10 +3,4 @@ package org.jetbrains.compose.demo.widgets.platform
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
expect fun Modifier.pointerMoveFilter(
onEnter: () -> Boolean = { true },
onExit: () -> Boolean = { true },
onMove: (Offset) -> Boolean = { true }
): Modifier
expect fun Modifier.cursorForHorizontalResize(): Modifier

18
examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/MainView.kt

@ -4,6 +4,9 @@ import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.SpringSpec
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.clickable
import androidx.compose.foundation.hoverable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsHoveredAsState
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
@ -26,7 +29,6 @@ import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import org.jetbrains.compose.demo.widgets.platform.VerticalScrollbar
import org.jetbrains.compose.demo.widgets.platform.pointerMoveFilter
import org.jetbrains.compose.demo.widgets.theme.WidgetGalleryTheme
import org.jetbrains.compose.demo.widgets.ui.utils.PanelState
import org.jetbrains.compose.demo.widgets.ui.utils.ResizablePanel
@ -132,7 +134,8 @@ private fun WidgetsListItemViewImpl(
.height(height)
.padding(start = 16.dp)
) {
var inFocus by remember { mutableStateOf(false) }
val inFocusInteractionSource = remember { MutableInteractionSource() }
val inFocus by inFocusInteractionSource.collectIsHoveredAsState()
val textColor = LocalContentColor.current.let {
when {
isCurrent -> it
@ -147,16 +150,7 @@ private fun WidgetsListItemViewImpl(
modifier = Modifier
.align(Alignment.CenterVertically)
.clipToBounds()
.pointerMoveFilter(
onEnter = {
inFocus = true
true
},
onExit = {
inFocus = false
true
}
),
.hoverable(inFocusInteractionSource),
softWrap = true,
fontSize = fontSize,
overflow = TextOverflow.Ellipsis,

8
examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/WidgetsType.kt

@ -1,5 +1,7 @@
package org.jetbrains.compose.demo.widgets.ui
import java.util.Locale
enum class WidgetsType(private val customTitle: String? = null) {
APP_BARS,
BUTTONS,
@ -13,9 +15,11 @@ enum class WidgetsType(private val customTitle: String? = null) {
val readableName: String by lazy {
name.split("_")
.map { it.toLowerCase() }
.map { it.lowercase(Locale.getDefault()) }
.mapIndexed { i, it ->
if (i == 0) it.capitalize() else it
if (i == 0) it.replaceFirstChar {
if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString()
} else it
}.joinToString(" ")
}

2
examples/widgets-gallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/utils/Text.kt

@ -14,7 +14,7 @@ fun SubtitleText(subtitle: String, modifier: Modifier = Modifier) {
}
@Composable
fun TitleText(title: String, modifier: Modifier = Modifier) {
fun TitleText(title: String) {
Text(
text = title,
style = typography.h6.copy(fontSize = 14.sp),

8
examples/widgets-gallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt

@ -8,13 +8,5 @@ import androidx.compose.ui.input.pointer.pointerHoverIcon
import androidx.compose.ui.input.pointer.pointerMoveFilter
import java.awt.Cursor
@OptIn(ExperimentalComposeUiApi::class)
actual fun Modifier.pointerMoveFilter(
onEnter: () -> Boolean,
onExit: () -> Boolean,
onMove: (Offset) -> Boolean
): Modifier = this.pointerMoveFilter(onEnter = onEnter, onExit = onExit, onMove = onMove)
@OptIn(ExperimentalComposeUiApi::class)
actual fun Modifier.cursorForHorizontalResize(): Modifier =
this.pointerHoverIcon(PointerIcon(Cursor(Cursor.E_RESIZE_CURSOR)))

2
examples/widgets-gallery/gradle.properties

@ -21,4 +21,4 @@ android.enableJetifier=true
kotlin.code.style=official
kotlin.version=1.7.10
compose.version=1.2.0-beta02
agp.version=7.0.4
agp.version=7.1.3

Loading…
Cancel
Save