Implement Flash Notifications UI for Settings app.
Bug: 237628564 Test: make RunSettingsRoboTests ROBOTEST_FILTER=CameraFlashNotificationPreferenceControllerTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=ColorSelectorLayoutTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=FlashNotificationsPreferenceControllerTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=FlashNotificationsPreferenceFragmentTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=FlashNotificationsPreviewPreferenceControllerTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=FlashNotificationsPreviewPreferenceTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=FlashNotificationsUtilTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=ScreenFlashNotificationColorDialogFragmentTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=ScreenFlashNotificationColorTest Change-Id: I0987590ddfcfd0873ec419db263f6a7eade81844 Signed-off-by: yw.bae <yw.bae@samsung.corp-partner.google.com> Signed-off-by: Angela Wang <angelala@google.com>
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
|
||||
import static com.android.settings.accessibility.FlashNotificationsUtil.ACTION_FLASH_NOTIFICATION_START_PREVIEW;
|
||||
import static com.android.settings.accessibility.FlashNotificationsUtil.EXTRA_FLASH_NOTIFICATION_PREVIEW_TYPE;
|
||||
import static com.android.settings.accessibility.FlashNotificationsUtil.SETTING_KEY_CAMERA_FLASH_NOTIFICATION;
|
||||
import static com.android.settings.accessibility.FlashNotificationsUtil.SETTING_KEY_SCREEN_FLASH_NOTIFICATION;
|
||||
import static com.android.settings.accessibility.FlashNotificationsUtil.TYPE_SHORT_PREVIEW;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleEventObserver;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
/**
|
||||
* Controller for flash notifications preview.
|
||||
*/
|
||||
public class FlashNotificationsPreviewPreferenceController extends
|
||||
BasePreferenceController implements LifecycleEventObserver {
|
||||
|
||||
private Preference mPreference;
|
||||
private final ContentResolver mContentResolver;
|
||||
|
||||
@VisibleForTesting
|
||||
final ContentObserver mContentObserver = new ContentObserver(
|
||||
new Handler(Looper.getMainLooper())) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange, @Nullable Uri uri) {
|
||||
onSettingChanged();
|
||||
}
|
||||
};
|
||||
|
||||
public FlashNotificationsPreviewPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mContentResolver = context.getContentResolver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
onSettingChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (getPreferenceKey().equals(preference.getKey())) {
|
||||
Intent intent = new Intent(ACTION_FLASH_NOTIFICATION_START_PREVIEW);
|
||||
intent.putExtra(EXTRA_FLASH_NOTIFICATION_PREVIEW_TYPE, TYPE_SHORT_PREVIEW);
|
||||
mContext.sendBroadcast(intent);
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.handlePreferenceTreeClick(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateChanged(@NonNull LifecycleOwner lifecycleOwner,
|
||||
@NonNull Lifecycle.Event event) {
|
||||
if (event == Lifecycle.Event.ON_RESUME) {
|
||||
mContentResolver.registerContentObserver(
|
||||
Settings.System.getUriFor(SETTING_KEY_CAMERA_FLASH_NOTIFICATION),
|
||||
/* notifyForDescendants= */ false, mContentObserver);
|
||||
mContentResolver.registerContentObserver(
|
||||
Settings.System.getUriFor(SETTING_KEY_SCREEN_FLASH_NOTIFICATION),
|
||||
/* notifyForDescendants= */ false, mContentObserver);
|
||||
} else if (event == Lifecycle.Event.ON_PAUSE) {
|
||||
mContentResolver.unregisterContentObserver(mContentObserver);
|
||||
}
|
||||
}
|
||||
|
||||
private void onSettingChanged() {
|
||||
if (mPreference == null) return;
|
||||
|
||||
mPreference.setEnabled(FlashNotificationsUtil.getFlashNotificationsState(mContext)
|
||||
!= FlashNotificationsUtil.State.OFF);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user