|
| 1 | +// Copyright 2022 Samsung Electronics Co., Ltd. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +#include "accessibility_settings.h" |
| 6 | + |
| 7 | +#ifdef TV_PROFILE |
| 8 | +#include <system/system_settings.h> |
| 9 | +#endif |
| 10 | + |
| 11 | +#include "flutter/shell/platform/tizen/flutter_tizen_engine.h" |
| 12 | +#include "flutter/shell/platform/tizen/logger.h" |
| 13 | + |
| 14 | +// SYSTEM_SETTINGS_KEY_MENU_SYSTEM_ACCESSIBILITY_HIGHCONTRAST = 10059 has been |
| 15 | +// defined in system_settings_keys.h only for TV profile. |
| 16 | +#define SYSTEM_SETTINGS_KEY_MENU_SYSTEM_ACCESSIBILITY_HIGHCONTRAST 10059 |
| 17 | + |
| 18 | +namespace flutter { |
| 19 | + |
| 20 | +AccessibilitySettings::AccessibilitySettings(FlutterTizenEngine* engine) |
| 21 | + : engine_(engine) { |
| 22 | +#ifdef TV_PROFILE |
| 23 | + // Add listener for accessibility high contrast. |
| 24 | + system_settings_set_changed_cb( |
| 25 | + system_settings_key_e( |
| 26 | + SYSTEM_SETTINGS_KEY_MENU_SYSTEM_ACCESSIBILITY_HIGHCONTRAST), |
| 27 | + [](system_settings_key_e key, void* user_data) -> void { |
| 28 | + auto* self = reinterpret_cast<AccessibilitySettings*>(user_data); |
| 29 | + self->OnHighContrastStateChanged(); |
| 30 | + }, |
| 31 | + this); |
| 32 | + |
| 33 | + // Set initialized value of accessibility high contrast. |
| 34 | + if (engine_ != nullptr) { |
| 35 | + engine_->EnableAccessibilityFeature(GetHighContrastValue()); |
| 36 | + } |
| 37 | +#endif |
| 38 | +} |
| 39 | + |
| 40 | +AccessibilitySettings::~AccessibilitySettings() { |
| 41 | +#ifdef TV_PROFILE |
| 42 | + system_settings_unset_changed_cb(system_settings_key_e( |
| 43 | + SYSTEM_SETTINGS_KEY_MENU_SYSTEM_ACCESSIBILITY_HIGHCONTRAST)); |
| 44 | +#endif |
| 45 | +} |
| 46 | + |
| 47 | +void AccessibilitySettings::OnHighContrastStateChanged() { |
| 48 | + if (engine_ != nullptr) { |
| 49 | + engine_->EnableAccessibilityFeature(GetHighContrastValue()); |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +bool AccessibilitySettings::GetHighContrastValue() { |
| 54 | + int enabled = 0; |
| 55 | +#ifdef TV_PROFILE |
| 56 | + int ret = system_settings_get_value_int( |
| 57 | + system_settings_key_e( |
| 58 | + SYSTEM_SETTINGS_KEY_MENU_SYSTEM_ACCESSIBILITY_HIGHCONTRAST), |
| 59 | + &enabled); |
| 60 | + if (ret != SYSTEM_SETTINGS_ERROR_NONE) { |
| 61 | + FT_LOG(Error) |
| 62 | + << "Failed to get value of accessibility high contrast. ERROR CODE = " |
| 63 | + << ret; |
| 64 | + } |
| 65 | +#endif |
| 66 | + return enabled; |
| 67 | +} |
| 68 | + |
| 69 | +} // namespace flutter |
0 commit comments