From d78f2de0d5feb9e62a6eb087725b1f655a5590ec Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Tue, 13 Jun 2023 17:06:25 +0800 Subject: [PATCH] New onViewCreated in AbstractPreferenceController To let fragment's view lifecycle owner passed in to controllers. For UI usage, view lifecycle owner is the best choice, controller could use this lifecycle owner to observe events and do UI related works. Bug: 287005021 Test: presubmit Change-Id: Ibbfaae1ce350e2721a095783f930928f695e1470 --- .../core/AbstractPreferenceController.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/SettingsLib/src/com/android/settingslib/core/AbstractPreferenceController.java b/packages/SettingsLib/src/com/android/settingslib/core/AbstractPreferenceController.java index 9567a3b38896e..ea65adecd7634 100644 --- a/packages/SettingsLib/src/com/android/settingslib/core/AbstractPreferenceController.java +++ b/packages/SettingsLib/src/com/android/settingslib/core/AbstractPreferenceController.java @@ -1,3 +1,19 @@ +/* + * 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.settingslib.core; import android.app.admin.DevicePolicyManager; @@ -6,8 +22,11 @@ import android.os.Build; import android.text.TextUtils; import android.util.Log; +import androidx.annotation.EmptySuper; +import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; import androidx.core.os.BuildCompat; +import androidx.lifecycle.LifecycleOwner; import androidx.preference.Preference; import androidx.preference.PreferenceGroup; import androidx.preference.PreferenceScreen; @@ -51,6 +70,13 @@ public abstract class AbstractPreferenceController { } } + /** + * Called on view created. + */ + @EmptySuper + public void onViewCreated(@NonNull LifecycleOwner viewLifecycleOwner) { + } + /** * Updates the current status of preference (summary, switch state, etc) */