1 /* 2 * Copyright (C) 2022 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 */ 17 18 package com.android.customization.picker.quickaffordance.ui.fragment 19 20 import android.os.Bundle 21 import android.view.LayoutInflater 22 import android.view.View 23 import android.view.ViewGroup 24 import androidx.core.content.ContextCompat 25 import androidx.core.view.isVisible 26 import androidx.lifecycle.ViewModelProvider 27 import androidx.lifecycle.get 28 import androidx.transition.Transition 29 import androidx.transition.doOnStart 30 import com.android.customization.module.ThemePickerInjector 31 import com.android.customization.picker.quickaffordance.ui.binder.KeyguardQuickAffordancePickerBinder 32 import com.android.customization.picker.quickaffordance.ui.binder.KeyguardQuickAffordancePreviewBinder 33 import com.android.customization.picker.quickaffordance.ui.viewmodel.KeyguardQuickAffordancePickerViewModel 34 import com.android.themepicker.R 35 import com.android.wallpaper.module.InjectorProvider 36 import com.android.wallpaper.picker.AppbarFragment 37 38 class KeyguardQuickAffordancePickerFragment : AppbarFragment() { 39 companion object { 40 const val DESTINATION_ID = "quick_affordances" 41 @JvmStatic newInstancenull42 fun newInstance(): KeyguardQuickAffordancePickerFragment { 43 return KeyguardQuickAffordancePickerFragment() 44 } 45 } 46 onCreateViewnull47 override fun onCreateView( 48 inflater: LayoutInflater, 49 container: ViewGroup?, 50 savedInstanceState: Bundle? 51 ): View { 52 val view = 53 inflater.inflate( 54 R.layout.fragment_lock_screen_quick_affordances, 55 container, 56 false, 57 ) 58 setUpToolbar(view) 59 val injector = InjectorProvider.getInjector() as ThemePickerInjector 60 val viewModel: KeyguardQuickAffordancePickerViewModel = 61 ViewModelProvider( 62 requireActivity(), 63 injector.getKeyguardQuickAffordancePickerViewModelFactory(requireContext()), 64 ) 65 .get() 66 67 KeyguardQuickAffordancePreviewBinder.bind( 68 activity = requireActivity(), 69 previewView = view.requireViewById(R.id.preview), 70 viewModel = viewModel, 71 lifecycleOwner = this, 72 offsetToStart = 73 requireActivity().let { 74 injector.getDisplayUtils(it).isSingleDisplayOrUnfoldedHorizontalHinge(it) 75 } 76 ) 77 KeyguardQuickAffordancePickerBinder.bind( 78 view = view, 79 viewModel = viewModel, 80 lifecycleOwner = this, 81 ) 82 postponeEnterTransition() 83 view.post { startPostponedEnterTransition() } 84 (returnTransition as? Transition)?.doOnStart { 85 // Hide preview during exit transition animation 86 view?.findViewById<View>(R.id.preview)?.isVisible = false 87 } 88 return view 89 } 90 getDefaultTitlenull91 override fun getDefaultTitle(): CharSequence { 92 return requireContext().getString(R.string.keyguard_quick_affordance_title) 93 } 94 getToolbarTextColornull95 override fun getToolbarTextColor(): Int { 96 return ContextCompat.getColor( 97 requireContext(), 98 com.android.wallpaper.R.color.system_on_surface 99 ) 100 } 101 } 102