Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d85cd117 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove DynamicAvailabilityPreferenceController."

parents 07e63ea2 b5f5ffbe
Loading
Loading
Loading
Loading
+0 −75
Original line number Diff line number Diff line
/*
 * 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;

import android.content.Context;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;

import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnResume;

public abstract class DynamicAvailabilityPreferenceController extends AbstractPreferenceController
        implements PreferenceControllerMixin, LifecycleObserver, OnResume {

    private Preference mPreference;
    private PreferenceScreen mScreen;
    private PreferenceAvailabilityObserver mAvailabilityObserver = null;

    public DynamicAvailabilityPreferenceController(Context context, Lifecycle lifecycle) {
        super(context);
        if (lifecycle != null) {
            lifecycle.addObserver(this);
        }
    }

    public void setAvailabilityObserver(PreferenceAvailabilityObserver observer) {
        mAvailabilityObserver = observer;
    }

    public PreferenceAvailabilityObserver getAvailabilityObserver() {
        return mAvailabilityObserver;
    }

    @Override
    public void displayPreference(PreferenceScreen screen) {
        mScreen = screen;
        mPreference = screen.findPreference(getPreferenceKey());
        super.displayPreference(screen);
    }

    @Override
    public void onResume() {
        if (!isAvailable()) {
            removePreference(mScreen, getPreferenceKey());
            return;
        }

        updateState(mPreference);
        if (mScreen.findPreference(getPreferenceKey()) == null) {
            mScreen.addPreference(mPreference);
        }
    }

    protected void notifyOnAvailabilityUpdate(boolean available) {
        if (mAvailabilityObserver != null) {
            mAvailabilityObserver.onPreferenceAvailabilityUpdated(getPreferenceKey(), available);
        }
    }
}
+0 −33
Original line number Diff line number Diff line
/*
 * 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);
}
+2 −6
Original line number Diff line number Diff line
@@ -17,18 +17,14 @@ package com.android.settings.enterprise;
import android.Manifest;
import android.content.Context;

import com.android.settingslib.core.lifecycle.Lifecycle;

public class AdminGrantedCameraPermissionPreferenceController extends
        AdminGrantedPermissionsPreferenceControllerBase {

    private static final String KEY_ENTERPRISE_PRIVACY_NUMBER_CAMERA_ACCESS_PACKAGES
            = "enterprise_privacy_number_camera_access_packages";

    public AdminGrantedCameraPermissionPreferenceController(Context context, Lifecycle lifecycle,
            boolean async) {
        super(context, lifecycle, async, new String[] {Manifest.permission.CAMERA},
                Manifest.permission_group.CAMERA);
    public AdminGrantedCameraPermissionPreferenceController(Context context, boolean async) {
        super(context, async, new String[] {Manifest.permission.CAMERA});
    }

    @Override
+3 −6
Original line number Diff line number Diff line
@@ -17,18 +17,15 @@ package com.android.settings.enterprise;
import android.Manifest;
import android.content.Context;

import com.android.settingslib.core.lifecycle.Lifecycle;

public class AdminGrantedLocationPermissionsPreferenceController extends
        AdminGrantedPermissionsPreferenceControllerBase {

    private static final String KEY_ENTERPRISE_PRIVACY_NUMBER_LOCATION_ACCESS_PACKAGES
            = "enterprise_privacy_number_location_access_packages";

    public AdminGrantedLocationPermissionsPreferenceController(Context context, Lifecycle lifecycle,
            boolean async) {
        super(context, lifecycle, async, new String[] {Manifest.permission.ACCESS_COARSE_LOCATION,
                Manifest.permission.ACCESS_FINE_LOCATION}, Manifest.permission_group.LOCATION);
    public AdminGrantedLocationPermissionsPreferenceController(Context context, boolean async) {
        super(context, async, new String[] {Manifest.permission.ACCESS_COARSE_LOCATION,
                Manifest.permission.ACCESS_FINE_LOCATION});
    }

    @Override
+2 −6
Original line number Diff line number Diff line
@@ -17,18 +17,14 @@ package com.android.settings.enterprise;
import android.Manifest;
import android.content.Context;

import com.android.settingslib.core.lifecycle.Lifecycle;

public class AdminGrantedMicrophonePermissionPreferenceController extends
        AdminGrantedPermissionsPreferenceControllerBase {

    private static final String KEY_ENTERPRISE_PRIVACY_NUMBER_MICROPHONE_ACCESS_PACKAGES
            = "enterprise_privacy_number_microphone_access_packages";

    public AdminGrantedMicrophonePermissionPreferenceController(Context context,
            Lifecycle lifecycle, boolean async) {
        super(context, lifecycle, async, new String[] {Manifest.permission.RECORD_AUDIO},
                Manifest.permission_group.MICROPHONE);
    public AdminGrantedMicrophonePermissionPreferenceController(Context context, boolean async) {
        super(context, async, new String[] {Manifest.permission.RECORD_AUDIO});
    }

    @Override
Loading