Hide "Changes made by your organization's admin" when empty
The admin of a manged device can take a number actions that will be listed in the "Changes made by your organization's admin" section of Settings. If the admin has not taken any such actions, the section will be empty and should be hidden. This is accomplished by having a PreferenceController for the section that observes the state of the PreferenceControllers inside it. Bug: 35912953 Test: m RunSettingsRoboTests Change-Id: Ia95754493ee6c5a19b4aa9731fd56fd558e61849
This commit is contained in:
@@ -29,6 +29,7 @@ public abstract class DynamicAvailabilityPreferenceController extends Preference
|
||||
|
||||
private Preference mPreference;
|
||||
private PreferenceScreen mScreen;
|
||||
private PreferenceAvailabilityObserver mAvailabilityObserver = null;
|
||||
|
||||
public DynamicAvailabilityPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context);
|
||||
@@ -37,6 +38,14 @@ public abstract class DynamicAvailabilityPreferenceController extends Preference
|
||||
}
|
||||
}
|
||||
|
||||
public void setAvailabilityObserver(PreferenceAvailabilityObserver observer) {
|
||||
mAvailabilityObserver = observer;
|
||||
}
|
||||
|
||||
public PreferenceAvailabilityObserver getAvailabilityObserver() {
|
||||
return mAvailabilityObserver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
mScreen = screen;
|
||||
@@ -56,4 +65,10 @@ public abstract class DynamicAvailabilityPreferenceController extends Preference
|
||||
mScreen.addPreference(mPreference);
|
||||
}
|
||||
}
|
||||
|
||||
protected void notifyOnAvailabilityUpdate(boolean available) {
|
||||
if (mAvailabilityObserver != null) {
|
||||
mAvailabilityObserver.onPreferenceAvailabilityUpdated(getPreferenceKey(), available);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.core;
|
||||
|
||||
/**
|
||||
* @deprecated This interface allows a {@link android.support.v7.preference.PreferenceGroup}'s
|
||||
* controller to observe the availability of the {@link android.support.v7.preference.Preference}s
|
||||
* inside it, hiding the group when all preferences become unavailable. In the future,
|
||||
* {@link android.support.v7.preference.PreferenceGroup} will have native support for that
|
||||
* functionality, removing the need for this interface.
|
||||
*/
|
||||
public interface PreferenceAvailabilityObserver {
|
||||
|
||||
/**
|
||||
* Notifies the observer that the availability of the preference identified by {@code key} has
|
||||
* been updated.
|
||||
*/
|
||||
void onPreferenceAvailabilityUpdated(String key, boolean available);
|
||||
}
|
Reference in New Issue
Block a user