• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.wallpaper.picker.preview.ui
17 
18 import android.content.Context
19 import android.content.Intent
20 import android.content.pm.ActivityInfo
21 import android.graphics.Color
22 import android.os.Bundle
23 import android.widget.Toast
24 import androidx.activity.viewModels
25 import com.android.wallpaper.R
26 import com.android.wallpaper.model.WallpaperInfo
27 import com.android.wallpaper.picker.AppbarFragment
28 import com.android.wallpaper.picker.BasePreviewActivity
29 import com.android.wallpaper.picker.preview.ui.viewmodel.WallpaperPreviewViewModel
30 import com.android.wallpaper.util.ActivityUtils
31 import com.android.wallpaper.util.DisplayUtils
32 import dagger.hilt.android.AndroidEntryPoint
33 import javax.inject.Inject
34 
35 /** This activity holds the flow for the preview screen. */
36 @AndroidEntryPoint(BasePreviewActivity::class)
37 class WallpaperPreviewActivity :
38     Hilt_WallpaperPreviewActivity(), AppbarFragment.AppbarFragmentHost {
39     private val viewModel: WallpaperPreviewViewModel by viewModels()
40     @Inject lateinit var displayUtils: DisplayUtils
41 
onCreatenull42     override fun onCreate(savedInstanceState: Bundle?) {
43         super.onCreate(savedInstanceState)
44         window.navigationBarColor = Color.TRANSPARENT
45         window.statusBarColor = Color.TRANSPARENT
46         setContentView(R.layout.activity_wallpaper_preview)
47         viewModel.editingWallpaper =
48             intent.getParcelableExtra(EXTRA_WALLPAPER_INFO, WallpaperInfo::class.java)
49     }
50 
onUpArrowPressednull51     override fun onUpArrowPressed() {
52         onBackPressedDispatcher.onBackPressed()
53     }
54 
isUpArrowSupportednull55     override fun isUpArrowSupported(): Boolean {
56         return !ActivityUtils.isSUWMode(baseContext)
57     }
58 
onResumenull59     override fun onResume() {
60         super.onResume()
61         requestedOrientation =
62             if (displayUtils.isOnWallpaperDisplay(this)) ActivityInfo.SCREEN_ORIENTATION_USER
63             else ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
64         if (isInMultiWindowMode) {
65             Toast.makeText(this, R.string.wallpaper_exit_split_screen, Toast.LENGTH_SHORT).show()
66             onBackPressedDispatcher.onBackPressed()
67         }
68     }
69 
70     companion object {
71         /**
72          * Returns a new [Intent] that can be used to start [WallpaperPreviewActivity].
73          *
74          * @param context application context.
75          * @param wallpaperInfo selected by user for editing preview.
76          * @param isNewTask true to launch at a new task.
77          *
78          * TODO(b/291761856): Use wallpaper model to replace wallpaper info.
79          */
newIntentnull80         fun newIntent(
81             context: Context,
82             wallpaperInfo: WallpaperInfo,
83             isNewTask: Boolean = false,
84         ): Intent {
85             val intent = Intent(context.applicationContext, WallpaperPreviewActivity::class.java)
86             if (isNewTask) {
87                 // TODO(b/291761856): When going back to main screen, use startActivity instead of
88                 //                    onActivityResult, which won't work.
89                 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
90             }
91             intent.putExtra(EXTRA_WALLPAPER_INFO, wallpaperInfo)
92             return intent
93         }
94     }
95 }
96