Browse Source

Migrate to 0.3.0-build146 (imageviewer)

pull/328/head
Igor Demin 4 years ago
parent
commit
e00beacfbd
  1. 4
      examples/imageviewer/build.gradle.kts
  2. 41
      examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/view/FullImageScreen.kt
  3. 4
      examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/view/MainScreen.kt
  4. 6
      examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/Draggable.kt
  5. 28
      examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/Scalable.kt
  6. 6
      examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/utils/Application.kt
  7. 45
      examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/FullImageScreen.kt
  8. 4
      examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/MainScreen.kt
  9. 23
      examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/Toast.kt

4
examples/imageviewer/build.gradle.kts

@ -11,10 +11,10 @@ buildscript {
dependencies {
// __LATEST_COMPOSE_RELEASE_VERSION__
classpath("org.jetbrains.compose:compose-gradle-plugin:0.3.0-build141")
classpath("org.jetbrains.compose:compose-gradle-plugin:0.3.0-build146")
classpath("com.android.tools.build:gradle:4.0.1")
// __KOTLIN_COMPOSE_VERSION__
classpath(kotlin("gradle-plugin", version = "1.4.21"))
classpath(kotlin("gradle-plugin", version = "1.4.21-2"))
}
}

41
examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/view/FullImageScreen.kt

@ -2,29 +2,29 @@ package example.imageviewer.view
import android.graphics.Bitmap
import android.graphics.Rect
import androidx.compose.foundation.background
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.draw.clip
import androidx.compose.ui.Modifier
import androidx.compose.foundation.ScrollableRow
import androidx.compose.foundation.Image
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.MaterialTheme
import androidx.compose.foundation.ScrollableRow
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
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.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.unit.dp
import example.imageviewer.core.FilterType
@ -37,17 +37,15 @@ import example.imageviewer.style.Foreground
import example.imageviewer.style.MiniatureColor
import example.imageviewer.style.Transparent
import example.imageviewer.style.icBack
import example.imageviewer.style.icFilterGrayscaleOn
import example.imageviewer.style.icFilterBlurOff
import example.imageviewer.style.icFilterBlurOn
import example.imageviewer.style.icFilterGrayscaleOff
import example.imageviewer.style.icFilterPixelOn
import example.imageviewer.style.icFilterGrayscaleOn
import example.imageviewer.style.icFilterPixelOff
import example.imageviewer.style.icFilterBlurOn
import example.imageviewer.style.icFilterBlurOff
import example.imageviewer.style.icFilterUnknown
import example.imageviewer.utils.displayHeight
import example.imageviewer.style.icFilterPixelOn
import example.imageviewer.utils.adjustImageScale
import example.imageviewer.utils.displayWidth
import example.imageviewer.utils.getDisplayBounds
import example.imageviewer.utils.adjustImageScale
import kotlin.math.abs
import kotlin.math.pow
import kotlin.math.roundToInt
@ -104,6 +102,7 @@ fun setToolBar(
}) {
Image(
icBack(),
contentDescription = null,
modifier = Modifier.preferredSize(38.dp)
)
}
@ -149,6 +148,7 @@ fun FilterButton(
) {
Image(
getFilterImage(type = type, content = content),
contentDescription = null,
modifier
)
}
@ -182,6 +182,7 @@ fun setImage(content: ContentState) {
val bitmap = imageByGesture(content, scale, drag)
Image(
bitmap = bitmap.asImageBitmap(),
contentDescription = null,
contentScale = adjustImageScale(bitmap)
)
}

4
examples/imageviewer/common/src/androidMain/kotlin/example/imageviewer/view/MainScreen.kt

@ -120,6 +120,7 @@ fun setTitleBar(text: String, content: ContentState) {
) {
Image(
icRefresh(),
contentDescription = null,
modifier = Modifier.preferredSize(35.dp)
)
}
@ -146,6 +147,7 @@ fun setPreviewImageUI(content: ContentState) {
} else {
content.getSelectedImage().asImageBitmap()
},
contentDescription = null,
modifier = Modifier
.fillMaxWidth().padding(start = 1.dp, top = 1.dp, end = 1.dp, bottom = 5.dp),
contentScale = ContentScale.Fit
@ -178,6 +180,7 @@ fun setMiniatureUI(
) {
Image(
picture.image.asImageBitmap(),
contentDescription = null,
modifier = Modifier.preferredHeight(70.dp)
.preferredWidth(90.dp)
.padding(start = 1.dp, top = 1.dp, end = 1.dp, bottom = 1.dp),
@ -207,6 +210,7 @@ fun setMiniatureUI(
) {
Image(
icDots(),
contentDescription = null,
modifier = Modifier.preferredHeight(70.dp)
.preferredWidth(30.dp)
.padding(start = 1.dp, top = 25.dp, end = 1.dp, bottom = 25.dp),

6
examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/Draggable.kt

@ -2,15 +2,11 @@ package example.imageviewer.view
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.onDispose
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Modifier
import androidx.compose.foundation.Interaction
import androidx.compose.foundation.InteractionState
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.gesture.DragObserver
import androidx.compose.ui.gesture.rawDragGestureFilter
import androidx.compose.runtime.mutableStateOf
import example.imageviewer.core.EventLocker
import example.imageviewer.style.Transparent

28
examples/imageviewer/common/src/commonMain/kotlin/example/imageviewer/view/Scalable.kt

@ -1,16 +1,15 @@
package example.imageviewer.view
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.gestures.detectTransformGestures
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.gesture.RawScaleObserver
import androidx.compose.ui.gesture.doubleTapGestureFilter
import androidx.compose.ui.gesture.rawScaleGestureFilter
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Modifier
import androidx.compose.foundation.Interaction
import androidx.compose.foundation.InteractionState
import androidx.compose.material.Surface
import androidx.compose.ui.input.pointer.pointerInput
import example.imageviewer.style.Transparent
import androidx.compose.runtime.mutableStateOf
// TODO fix, it doesn't work
@Composable
fun Scalable(
onScale: ScaleHandler,
@ -19,17 +18,18 @@ fun Scalable(
) {
Surface(
color = Transparent,
modifier = modifier.rawScaleGestureFilter(
scaleObserver = onScale,
canStartScaling = { true }
).doubleTapGestureFilter(onDoubleTap = { onScale.resetFactor() }),
modifier = modifier.pointerInput {
detectTapGestures(onDoubleTap = { onScale.resetFactor() })
detectTransformGestures { _, _, zoom, _ ->
onScale.onScale(zoom)
}
},
) {
children()
}
}
class ScaleHandler(private val maxFactor: Float = 5f, private val minFactor: Float = 1f) :
RawScaleObserver {
class ScaleHandler(private val maxFactor: Float = 5f, private val minFactor: Float = 1f) {
val factor = mutableStateOf(1f)
fun resetFactor() {
@ -37,7 +37,7 @@ class ScaleHandler(private val maxFactor: Float = 5f, private val minFactor: Flo
factor.value = minFactor
}
override fun onScale(scaleFactor: Float): Float {
fun onScale(scaleFactor: Float): Float {
factor.value += scaleFactor - 1f
if (maxFactor < factor.value) factor.value = maxFactor

6
examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/utils/Application.kt

@ -5,12 +5,12 @@ import androidx.compose.desktop.AppWindow
import androidx.compose.desktop.WindowEvents
import androidx.compose.runtime.Applier
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Composition
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.ExperimentalComposeApi
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MonotonicFrameClock
import androidx.compose.runtime.Recomposer
import androidx.compose.runtime.compositionFor
import androidx.compose.runtime.dispatch.MonotonicFrameClock
import androidx.compose.runtime.emptyContent
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@ -46,7 +46,7 @@ class ApplicationScope(
private val scope = CoroutineScope(context)
private val recomposer = Recomposer(context)
private val composition = compositionFor(Unit, EmptyApplier(), recomposer)
private val composition = Composition(Unit, EmptyApplier(), recomposer)
private val windows = mutableSetOf<AppWindow>()
private var windowsVersion by mutableStateOf(Any())

45
examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/FullImageScreen.kt

@ -1,33 +1,34 @@
package example.imageviewer.view
import java.awt.image.BufferedImage
import androidx.compose.foundation.background
import androidx.compose.foundation.ScrollableRow
import androidx.compose.foundation.Image
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.MaterialTheme
import androidx.compose.foundation.ScrollableRow
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredHeight
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
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.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.shortcuts
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import example.imageviewer.core.FilterType
import example.imageviewer.model.AppState
@ -37,29 +38,24 @@ import example.imageviewer.style.DarkGray
import example.imageviewer.style.DarkGreen
import example.imageviewer.style.Foreground
import example.imageviewer.style.MiniatureColor
import example.imageviewer.style.Transparent
import example.imageviewer.style.TranslucentBlack
import example.imageviewer.style.TranslucentWhite
import example.imageviewer.style.Transparent
import example.imageviewer.style.icBack
import example.imageviewer.style.icFilterGrayscaleOn
import example.imageviewer.style.icFilterBlurOff
import example.imageviewer.style.icFilterBlurOn
import example.imageviewer.style.icFilterGrayscaleOff
import example.imageviewer.style.icFilterPixelOn
import example.imageviewer.style.icFilterGrayscaleOn
import example.imageviewer.style.icFilterPixelOff
import example.imageviewer.style.icFilterBlurOn
import example.imageviewer.style.icFilterBlurOff
import example.imageviewer.style.icFilterUnknown
import example.imageviewer.utils.displayHeight
import example.imageviewer.style.icFilterPixelOn
import example.imageviewer.utils.cropImage
import example.imageviewer.utils.displayWidth
import example.imageviewer.utils.getDisplayBounds
import example.imageviewer.utils.toByteArray
import example.imageviewer.utils.cropImage
import kotlin.math.abs
import java.awt.Rectangle
import java.awt.event.KeyEvent
import java.awt.image.BufferedImage
import kotlin.math.pow
import kotlin.math.roundToInt
import org.jetbrains.skija.IRect
import java.awt.event.KeyEvent
import java.awt.Rectangle
import androidx.compose.ui.input.key.*
@Composable
fun setImageFullScreen(
@ -126,6 +122,7 @@ fun setToolBar(
}) {
Image(
icBack(),
contentDescription = null,
modifier = Modifier.preferredSize(38.dp)
)
}
@ -182,6 +179,7 @@ fun FilterButton(
) {
Image(
getFilterImage(type = type, content = content),
contentDescription = null,
modifier
)
}
@ -225,6 +223,7 @@ fun setImage(content: ContentState) {
val bitmap = imageByGesture(content, scale, drag)
Image(
bitmap = bitmap,
contentDescription = null,
contentScale = ContentScale.Fit
)
}

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

@ -137,6 +137,7 @@ fun setTitleBar(text: String, content: ContentState) {
) {
Image(
icRefresh(),
contentDescription = null,
modifier = Modifier.preferredSize(35.dp)
)
}
@ -165,6 +166,7 @@ fun setPreviewImageUI(content: ContentState) {
else org.jetbrains.skija.Image.makeFromEncoded(
toByteArray(content.getSelectedImage())
).asImageBitmap(),
contentDescription = null,
modifier = Modifier
.fillMaxWidth().padding(start = 1.dp, top = 1.dp, end = 1.dp, bottom = 5.dp),
contentScale = ContentScale.Fit
@ -207,6 +209,7 @@ fun setMiniatureUI(
org.jetbrains.skija.Image.makeFromEncoded(
toByteArray(picture.image)
).asImageBitmap(),
contentDescription = null,
modifier = Modifier.preferredHeight(70.dp)
.preferredWidth(90.dp)
.padding(start = 1.dp, top = 1.dp, end = 1.dp, bottom = 1.dp),
@ -248,6 +251,7 @@ fun setMiniatureUI(
) {
Image(
icDots(),
contentDescription = null,
modifier = Modifier.preferredHeight(70.dp)
.preferredWidth(30.dp)
.padding(start = 1.dp, top = 25.dp, end = 1.dp, bottom = 25.dp),

23
examples/imageviewer/common/src/desktopMain/kotlin/example/imageviewer/view/Toast.kt

@ -1,26 +1,24 @@
package example.imageviewer.view
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.onActive
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.draw.clip
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.launch
import kotlinx.coroutines.delay
import kotlinx.coroutines.GlobalScope
import example.imageviewer.style.ToastBackground
import example.imageviewer.style.Foreground
import androidx.compose.material.Surface
import androidx.compose.material.Text
import example.imageviewer.style.ToastBackground
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
enum class ToastDuration(val value: Int) {
Short(1000), Long(3000)
@ -55,12 +53,13 @@ fun Toast(
color = Foreground
)
}
onActive {
DisposableEffect(Unit) {
GlobalScope.launch {
delay(duration.value.toLong())
isShown = false
visibility.value = false
}
onDispose { }
}
}
}

Loading…
Cancel
Save