2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.development;
19 import android.content.Context;
20 import android.os.SystemProperties;
21 import android.support.v14.preference.SwitchPreference;
22 import android.support.v7.preference.Preference;
23 import android.support.v7.preference.PreferenceScreen;
24 import android.widget.Toast;
26 import com.android.internal.annotations.VisibleForTesting;
27 import com.android.settings.R;
28 import com.android.settings.core.PreferenceControllerMixin;
29 import com.android.settingslib.core.AbstractPreferenceController;
31 public class CameraHalHdrplusPreferenceController extends AbstractPreferenceController
32 implements PreferenceControllerMixin {
34 private static final String KEY_CAMERA_HAL_HDRPLUS_SWITCH = "camera_hal_hdrplus_switch";
36 static final String BUILD_TYPE = "ro.build.type";
38 static final String PROPERTY_CAMERA_HAL_HDRPLUS = "persist.camera.hdrplus.enable";
40 static final String ENABLED = "1";
42 static final String DISABLED = "0";
44 private SwitchPreference mPreference;
46 public CameraHalHdrplusPreferenceController(Context context) {
51 public void displayPreference(PreferenceScreen screen) {
52 super.displayPreference(screen);
54 mPreference = (SwitchPreference) screen.findPreference(KEY_CAMERA_HAL_HDRPLUS_SWITCH);
55 mPreference.setChecked(isHalHdrplusEnabled());
60 public String getPreferenceKey() {
61 return KEY_CAMERA_HAL_HDRPLUS_SWITCH;
65 public boolean isAvailable() {
66 return mContext.getResources().getBoolean(R.bool.config_show_camera_hal_hdrplus) &&
67 (SystemProperties.get(BUILD_TYPE).equals("userdebug") ||
68 SystemProperties.get(BUILD_TYPE).equals("eng"));
72 public void updateState(Preference preference) {
77 public boolean handlePreferenceTreeClick(Preference preference) {
78 if (KEY_CAMERA_HAL_HDRPLUS_SWITCH.equals(preference.getKey())) {
79 final SwitchPreference switchPreference = (SwitchPreference)preference;
80 SystemProperties.set(PROPERTY_CAMERA_HAL_HDRPLUS,
81 switchPreference.isChecked() ? ENABLED : DISABLED);
82 Toast.makeText(mContext, R.string.camera_hal_hdrplus_toast,
83 Toast.LENGTH_LONG).show();
89 public void enablePreference(boolean enabled) {
91 mPreference.setEnabled(enabled);
95 public boolean updatePreference() {
99 final boolean enabled = isHalHdrplusEnabled();
100 mPreference.setChecked(enabled);
104 private boolean isHalHdrplusEnabled() {
105 return SystemProperties.getBoolean(PROPERTY_CAMERA_HAL_HDRPLUS, false);