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 package com.android.systemui.accessibility.floatingmenu; 18 19 import android.content.Context; 20 import android.view.accessibility.AccessibilityManager; 21 22 import androidx.lifecycle.LiveData; 23 import androidx.lifecycle.MutableLiveData; 24 25 import com.android.internal.accessibility.dialog.AccessibilityTarget; 26 import com.android.systemui.util.settings.SecureSettings; 27 28 import java.util.List; 29 30 /** 31 * The view model provides the menu information from the repository{@link MenuInfoRepository} for 32 * the menu view{@link MenuView}. 33 */ 34 class MenuViewModel implements MenuInfoRepository.OnSettingsContentsChanged { 35 private final MutableLiveData<List<AccessibilityTarget>> mTargetFeaturesData = 36 new MutableLiveData<>(); 37 private final MutableLiveData<Integer> mSizeTypeData = new MutableLiveData<>(); 38 private final MutableLiveData<MenuFadeEffectInfo> mFadeEffectInfoData = 39 new MutableLiveData<>(); 40 private final MutableLiveData<Boolean> mMoveToTuckedData = new MutableLiveData<>(); 41 private final MutableLiveData<Boolean> mDockTooltipData = new MutableLiveData<>(); 42 private final MutableLiveData<Boolean> mMigrationTooltipData = new MutableLiveData<>(); 43 private final MutableLiveData<Position> mPercentagePositionData = new MutableLiveData<>(); 44 private final MenuInfoRepository mInfoRepository; 45 MenuViewModel(Context context, AccessibilityManager accessibilityManager, SecureSettings secureSettings)46 MenuViewModel(Context context, AccessibilityManager accessibilityManager, 47 SecureSettings secureSettings) { 48 mInfoRepository = new MenuInfoRepository(context, 49 accessibilityManager, /* settingsContentsChanged= */ this, secureSettings); 50 } 51 52 @Override onTargetFeaturesChanged(List<AccessibilityTarget> newTargetFeatures)53 public void onTargetFeaturesChanged(List<AccessibilityTarget> newTargetFeatures) { 54 mTargetFeaturesData.setValue(newTargetFeatures); 55 } 56 57 @Override onSizeTypeChanged(int newSizeType)58 public void onSizeTypeChanged(int newSizeType) { 59 mSizeTypeData.setValue(newSizeType); 60 } 61 62 @Override onFadeEffectInfoChanged(MenuFadeEffectInfo fadeEffectInfo)63 public void onFadeEffectInfoChanged(MenuFadeEffectInfo fadeEffectInfo) { 64 mFadeEffectInfoData.setValue(fadeEffectInfo); 65 } 66 updateMenuMoveToTucked(boolean isMoveToTucked)67 void updateMenuMoveToTucked(boolean isMoveToTucked) { 68 mInfoRepository.updateMoveToTucked(isMoveToTucked); 69 } 70 updateMenuSavingPosition(Position percentagePosition)71 void updateMenuSavingPosition(Position percentagePosition) { 72 mInfoRepository.updateMenuSavingPosition(percentagePosition); 73 } 74 updateDockTooltipVisibility(boolean hasSeen)75 void updateDockTooltipVisibility(boolean hasSeen) { 76 mInfoRepository.updateDockTooltipVisibility(hasSeen); 77 } 78 updateMigrationTooltipVisibility(boolean visible)79 void updateMigrationTooltipVisibility(boolean visible) { 80 mInfoRepository.updateMigrationTooltipVisibility(visible); 81 } 82 getMoveToTuckedData()83 LiveData<Boolean> getMoveToTuckedData() { 84 mInfoRepository.loadMenuMoveToTucked(mMoveToTuckedData::setValue); 85 return mMoveToTuckedData; 86 } 87 getDockTooltipVisibilityData()88 LiveData<Boolean> getDockTooltipVisibilityData() { 89 mInfoRepository.loadDockTooltipVisibility(mDockTooltipData::setValue); 90 return mDockTooltipData; 91 } 92 getMigrationTooltipVisibilityData()93 LiveData<Boolean> getMigrationTooltipVisibilityData() { 94 mInfoRepository.loadMigrationTooltipVisibility(mMigrationTooltipData::setValue); 95 return mMigrationTooltipData; 96 } 97 getPercentagePositionData()98 LiveData<Position> getPercentagePositionData() { 99 mInfoRepository.loadMenuPosition(mPercentagePositionData::setValue); 100 return mPercentagePositionData; 101 } 102 getSizeTypeData()103 LiveData<Integer> getSizeTypeData() { 104 mInfoRepository.loadMenuSizeType(mSizeTypeData::setValue); 105 return mSizeTypeData; 106 } 107 getFadeEffectInfoData()108 LiveData<MenuFadeEffectInfo> getFadeEffectInfoData() { 109 mInfoRepository.loadMenuFadeEffectInfo(mFadeEffectInfoData::setValue); 110 return mFadeEffectInfoData; 111 } 112 getTargetFeaturesData()113 LiveData<List<AccessibilityTarget>> getTargetFeaturesData() { 114 mInfoRepository.loadMenuTargetFeatures(mTargetFeaturesData::setValue); 115 return mTargetFeaturesData; 116 } 117 registerObserversAndCallbacks()118 void registerObserversAndCallbacks() { 119 mInfoRepository.registerObserversAndCallbacks(); 120 } 121 unregisterObserversAndCallbacks()122 void unregisterObserversAndCallbacks() { 123 mInfoRepository.unregisterObserversAndCallbacks(); 124 } 125 }