Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit acff6f40 authored by Cameron Yee's avatar Cameron Yee Committed by Android (Google) Code Review
Browse files

Merge "Cloudy weather v1.0" into main

parents 072ec7cd 644927b9
Loading
Loading
Loading
Loading
+2.34 MiB
Loading image diff...
+321 KiB
Loading image diff...
+11 −1
Original line number Diff line number Diff line
@@ -50,11 +50,21 @@
            android:text="@string/button_rain"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toTopOf="@id/fog"
            app:layout_constraintBottom_toTopOf="@id/clouds"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginBottom="10dp"
            android:layout_marginEnd="20dp" />

        <Button
            android:id="@+id/clouds"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="20dp"
            android:layout_marginBottom="10dp"
            android:text="@string/button_clouds"
            app:layout_constraintBottom_toTopOf="@id/fog"
            app:layout_constraintEnd_toEndOf="parent" />

        <Button
            android:id="@+id/fog"
            android:text="@string/button_fog"
+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
    <string name="set_wallpaper" translatable="false">Set Wallpaper</string>
    <string name="button_rain" translatable="false">Rain</string>
    <string name="button_fog" translatable="false">Fog</string>
    <string name="button_clouds" translatable="false">Clouds</string>
    <string name="button_snow" translatable="false">Snow</string>
    <string name="button_sunny" translatable="false">Sun</string>
    <string name="button_clear" translatable="false">Clear Weather</string>
+80 −74
Original line number Diff line number Diff line
@@ -41,24 +41,18 @@ import com.google.android.wallpaper.weathereffects.data.repository.WallpaperFile
import com.google.android.wallpaper.weathereffects.domain.WeatherEffectsInteractor
import com.google.android.wallpaper.weathereffects.provider.WallpaperInfoContract
import com.google.android.wallpaper.weathereffects.shared.model.WallpaperFileModel
import java.io.File
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.io.File
import javax.inject.Inject

class WallpaperEffectsDebugActivity : TorusViewerActivity() {

    @Inject
    @MainScope
    lateinit var mainScope: CoroutineScope
    @Inject
    @BackgroundScope
    lateinit var bgScope: CoroutineScope
    @Inject
    lateinit var context: Context
    @Inject
    lateinit var interactor: WeatherEffectsInteractor
    @Inject @MainScope lateinit var mainScope: CoroutineScope
    @Inject @BackgroundScope lateinit var bgScope: CoroutineScope
    @Inject lateinit var context: Context
    @Inject lateinit var interactor: WeatherEffectsInteractor

    private lateinit var rootView: FrameLayout
    private lateinit var surfaceView: SurfaceView
@@ -73,12 +67,13 @@ class WallpaperEffectsDebugActivity : TorusViewerActivity() {

    override fun getWallpaperEngine(context: Context, surfaceView: SurfaceView): TorusEngine {
        this.surfaceView = surfaceView
        val engine = WeatherEngine(
        val engine =
            WeatherEngine(
                surfaceView.holder,
                mainScope,
                interactor,
                context,
            isDebugActivity = true
                isDebugActivity = true,
            )
        this.engine = engine
        return engine
@@ -107,6 +102,11 @@ class WallpaperEffectsDebugActivity : TorusViewerActivity() {
            updateWallpaper()
            setDebugText(context.getString(R.string.generating))
        }
        rootView.requireViewById<Button>(R.id.clouds).setOnClickListener {
            weatherEffect = WallpaperInfoContract.WeatherEffect.CLOUDS
            updateWallpaper()
            setDebugText(context.getString(R.string.generating))
        }
        rootView.requireViewById<Button>(R.id.snow).setOnClickListener {
            weatherEffect = WallpaperInfoContract.WeatherEffect.SNOW
            updateWallpaper()
@@ -133,18 +133,21 @@ class WallpaperEffectsDebugActivity : TorusViewerActivity() {
            i.action = WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER
            i.putExtra(
                WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
                ComponentName(this, WeatherWallpaperService::class.java)
                ComponentName(this, WeatherWallpaperService::class.java),
            )
            this.startActivityForResult(i, SET_WALLPAPER_REQUEST_CODE)
            saveWallpaper()
        }

        rootView.requireViewById<FrameLayout>(R.id.wallpaper_layout)
            .setOnTouchListener { view, event ->
        rootView.requireViewById<FrameLayout>(R.id.wallpaper_layout).setOnTouchListener {
            view,
            event ->
            when (event?.action) {
                MotionEvent.ACTION_DOWN -> {
                        if (rootView.requireViewById<ConstraintLayout>(R.id.buttons).visibility
                            == View.GONE) {
                    if (
                        rootView.requireViewById<ConstraintLayout>(R.id.buttons).visibility ==
                            View.GONE
                    ) {
                        showButtons()
                    } else {
                        hideButtons()
@@ -157,8 +160,13 @@ class WallpaperEffectsDebugActivity : TorusViewerActivity() {

        setDebugText()
        val seekBar = rootView.requireViewById<SeekBar>(R.id.seekBar)
        seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
            override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
        seekBar.setOnSeekBarChangeListener(
            object : SeekBar.OnSeekBarChangeListener {
                override fun onProgressChanged(
                    seekBar: SeekBar?,
                    progress: Int,
                    fromUser: Boolean,
                ) {
                    // Convert progress to a value between 0 and 1
                    val value = progress.toFloat() / 100f
                    engine?.setTargetIntensity(value)
@@ -172,7 +180,8 @@ class WallpaperEffectsDebugActivity : TorusViewerActivity() {
                override fun onStopTrackingTouch(seekBar: SeekBar?) {
                    showButtons()
                }
        })
            }
        )
        intensity = seekBar.progress.toFloat() / 100f

        // This avoids that the initial state after installing is showing a black screen.
@@ -190,7 +199,9 @@ class WallpaperEffectsDebugActivity : TorusViewerActivity() {
                        FOREGROUND_IMAGE_1,
                        FOREGROUND_IMAGE_2,
                        FOREGROUND_IMAGE_3,
                ).map { getFileFromAssets(it).absolutePath })
                    )
                    .map { getFileFromAssets(it).absolutePath }
            )
        }
        bgCachedAssetPaths.apply {
            clear()
@@ -200,7 +211,9 @@ class WallpaperEffectsDebugActivity : TorusViewerActivity() {
                        BACKGROUND_IMAGE_1,
                        BACKGROUND_IMAGE_2,
                        BACKGROUND_IMAGE_3,
                ).map { getFileFromAssets(it).absolutePath })
                    )
                    .map { getFileFromAssets(it).absolutePath }
            )
        }
    }

@@ -208,9 +221,7 @@ class WallpaperEffectsDebugActivity : TorusViewerActivity() {
        return File(context.cacheDir, fileName).also {
            if (!it.exists()) {
                it.outputStream().use { cache ->
                    context.assets.open(fileName).use { inputStream ->
                        inputStream.copyTo(cache)
                    }
                    context.assets.open(fileName).use { inputStream -> inputStream.copyTo(cache) }
                }
            }
        }
@@ -220,13 +231,7 @@ class WallpaperEffectsDebugActivity : TorusViewerActivity() {
        mainScope.launch {
            val fgPath = fgCachedAssetPaths[assetIndex]
            val bgPath = bgCachedAssetPaths[assetIndex]
            interactor.updateWallpaper(
                WallpaperFileModel(
                    fgPath,
                    bgPath,
                    weatherEffect,
                )
            )
            interactor.updateWallpaper(WallpaperFileModel(fgPath, bgPath, weatherEffect))
            engine?.setTargetIntensity(intensity)
            setDebugText(
                "Wallpaper updated successfully.\n* Weather: " +
@@ -236,9 +241,7 @@ class WallpaperEffectsDebugActivity : TorusViewerActivity() {
    }

    private fun saveWallpaper() {
        bgScope.launch {
            interactor.saveWallpaper()
        }
        bgScope.launch { interactor.saveWallpaper() }
    }

    private fun setDebugText(text: String? = null) {
@@ -265,14 +268,17 @@ class WallpaperEffectsDebugActivity : TorusViewerActivity() {

    private fun hideButtons() {
        val buttons = rootView.requireViewById<ConstraintLayout>(R.id.buttons)
        buttons.animate()
        buttons
            .animate()
            .alpha(0f)
            .setDuration(400)
            .setListener(object : AnimatorListenerAdapter() {
            .setListener(
                object : AnimatorListenerAdapter() {
                    override fun onAnimationEnd(animation: Animator) {
                        buttons.visibility = View.GONE
                    }
            })
                }
            )
    }

    private companion object {
Loading