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.accessibility; 18 19 import static com.android.settings.accessibility.AccessibilityUtil.State.OFF; 20 import static com.android.settings.accessibility.AccessibilityUtil.State.ON; 21 22 import android.content.Context; 23 import android.provider.Settings; 24 25 import com.android.settings.R; 26 import com.android.settings.core.TogglePreferenceController; 27 import com.android.settings.overlay.FeatureFactory; 28 29 /** 30 * Controller for Camera flash notification. 31 */ 32 public class CameraFlashNotificationPreferenceController extends TogglePreferenceController { 33 CameraFlashNotificationPreferenceController(Context context, String preferenceKey)34 public CameraFlashNotificationPreferenceController(Context context, String preferenceKey) { 35 super(context, preferenceKey); 36 } 37 38 @Override getAvailabilityStatus()39 public int getAvailabilityStatus() { 40 return FlashNotificationsUtil.isTorchAvailable(mContext) 41 ? AVAILABLE : UNSUPPORTED_ON_DEVICE; 42 } 43 44 @Override isChecked()45 public boolean isChecked() { 46 return Settings.System.getInt(mContext.getContentResolver(), 47 Settings.System.CAMERA_FLASH_NOTIFICATION, OFF) != OFF; 48 } 49 50 @Override setChecked(boolean isChecked)51 public boolean setChecked(boolean isChecked) { 52 FeatureFactory.getFeatureFactory().getMetricsFeatureProvider().changed( 53 getMetricsCategory(), getPreferenceKey(), isChecked ? 1 : 0); 54 return Settings.System.putInt(mContext.getContentResolver(), 55 Settings.System.CAMERA_FLASH_NOTIFICATION, (isChecked ? ON : OFF)); 56 } 57 58 @Override getSliceHighlightMenuRes()59 public int getSliceHighlightMenuRes() { 60 return R.string.menu_key_accessibility; 61 } 62 } 63