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 17 package com.android.settings.biometrics2.ui.viewmodel; 18 19 import android.content.res.Configuration; 20 import android.util.Log; 21 22 import androidx.annotation.NonNull; 23 import androidx.lifecycle.LiveData; 24 import androidx.lifecycle.MutableLiveData; 25 import androidx.lifecycle.ViewModel; 26 27 import com.android.systemui.unfold.compat.ScreenSizeFoldProvider; 28 import com.android.systemui.unfold.updates.FoldProvider; 29 30 import java.util.concurrent.Executor; 31 32 /** 33 * ViewModel explaining the fingerprint sensor location for fingerprint enrollment. 34 */ 35 public class DeviceFoldedViewModel extends ViewModel { 36 37 private static final String TAG = "DeviceFoldedViewModel"; 38 39 @NonNull private final MutableLiveData<Boolean> mLiveData = 40 new MutableLiveData<>(null); 41 42 private final ScreenSizeFoldProvider mScreenSizeFoldProvider; 43 private final FoldProvider.FoldCallback mIsFoldedCallback = isFolded -> { 44 Log.d(TAG, "onFoldUpdated= " + isFolded); 45 mLiveData.postValue(isFolded); 46 }; 47 DeviceFoldedViewModel(@onNull ScreenSizeFoldProvider screenSizeFoldProvider, @NonNull Executor executor)48 public DeviceFoldedViewModel(@NonNull ScreenSizeFoldProvider screenSizeFoldProvider, 49 @NonNull Executor executor) { 50 super(); 51 mScreenSizeFoldProvider = screenSizeFoldProvider; 52 mScreenSizeFoldProvider.registerCallback(mIsFoldedCallback, executor); 53 } 54 55 /** 56 * Calls this method when activity gets configuration change 57 */ onConfigurationChanged(@onNull Configuration newConfig)58 public void onConfigurationChanged(@NonNull Configuration newConfig) { 59 mScreenSizeFoldProvider.onConfigurationChange(newConfig); 60 } 61 62 /** 63 * Returns FoldedLiveData 64 */ getLiveData()65 public LiveData<Boolean> getLiveData() { 66 return mLiveData; 67 } 68 69 @Override onCleared()70 protected void onCleared() { 71 mScreenSizeFoldProvider.unregisterCallback(mIsFoldedCallback); 72 super.onCleared(); 73 } 74 } 75