Skip to content

Commit

Permalink
Apply Spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
riggaroo authored and github-actions[bot] committed Aug 18, 2023
1 parent e49e38f commit 2ffa59e
Showing 1 changed file with 38 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.example.compose.snippets.graphics

import android.R.attr.height
Expand All @@ -8,7 +24,6 @@ import android.content.Intent.createChooser
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Picture
import android.graphics.Rect
import android.graphics.drawable.PictureDrawable
import android.net.Uri
import androidx.compose.foundation.Image
Expand All @@ -26,21 +41,18 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.ContentDrawScope
import androidx.compose.ui.graphics.drawscope.draw
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
import androidx.compose.ui.graphics.nativeCanvas
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.node.DrawModifierNode
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.core.content.ContextCompat.startActivity
import androidx.core.content.FileProvider
import com.example.compose.snippets.R
import kotlinx.coroutines.launch
import java.io.File

import kotlinx.coroutines.launch

/*
* Copyright 2022 The Android Open Source Project
Expand All @@ -67,24 +79,26 @@ fun BitmapFromComposableSnippet() {

val coroutineScope = rememberCoroutineScope()
// [START android_compose_draw_into_bitmap]
Column(modifier = Modifier
.fillMaxSize()
.drawWithCache {
// Example that shows how to redirect rendering to an Android Picture and then
// draw the picture into the original destination
val width = this.size.width.toInt()
val height = this.size.height.toInt()
onDrawWithContent {
val pictureCanvas =
androidx.compose.ui.graphics.Canvas(picture.beginRecording(width, height))
draw(this, this.layoutDirection, pictureCanvas, this.size) {
this@onDrawWithContent.drawContent()
}
picture.endRecording()
Column(
modifier = Modifier
.fillMaxSize()
.drawWithCache {
// Example that shows how to redirect rendering to an Android Picture and then
// draw the picture into the original destination
val width = this.size.width.toInt()
val height = this.size.height.toInt()
onDrawWithContent {
val pictureCanvas =
androidx.compose.ui.graphics.Canvas(picture.beginRecording(width, height))
draw(this, this.layoutDirection, pictureCanvas, this.size) {
this@onDrawWithContent.drawContent()
}
picture.endRecording()

drawIntoCanvas { canvas -> canvas.nativeCanvas.drawPicture(picture) }
drawIntoCanvas { canvas -> canvas.nativeCanvas.drawPicture(picture) }
}
}
}) {
) {
// [START_EXCLUDE]
Image(
painterResource(id = R.drawable.dog),
Expand Down Expand Up @@ -116,7 +130,7 @@ suspend fun createBitmapFromPicture(picture: Picture): Bitmap {
Bitmap.Config.ARGB_8888
)
val canvas = Canvas(bitmap)
canvas.drawColor(android.graphics.Color.WHITE);
canvas.drawColor(android.graphics.Color.WHITE)
canvas.drawPicture(pictureDrawable.picture)
return bitmap
}
Expand Down Expand Up @@ -147,12 +161,10 @@ private fun shareBitmap(context: Context, uri: Uri) {
startActivity(context, createChooser(intent, "Share your image"), null)
}

class ScreenshotState {

}
class ScreenshotState

sealed class ImageResult {
object Initial : ImageResult()
data class Error(val exception: Exception) : ImageResult()
data class Success(val data: Bitmap) : ImageResult()
}
}

0 comments on commit 2ffa59e

Please sign in to comment.