Doris Ling | 9ed29a2 | 2017-11-02 16:42:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | package com.android.settings.location; |
| 15 | |
| 16 | import android.content.Context; |
| 17 | import android.os.UserManager; |
| 18 | |
Raff Tsai | 2229585 | 2019-11-22 11:35:40 +0800 | [diff] [blame] | 19 | import com.android.settings.core.BasePreferenceController; |
| 20 | import com.android.settings.dashboard.DashboardFragment; |
Doris Ling | 9ed29a2 | 2017-11-02 16:42:45 -0700 | [diff] [blame] | 21 | import com.android.settingslib.core.lifecycle.Lifecycle; |
| 22 | |
| 23 | /** |
| 24 | * A base controller for preferences that listens to location settings change and modifies location |
| 25 | * settings. |
| 26 | */ |
Raff Tsai | 2229585 | 2019-11-22 11:35:40 +0800 | [diff] [blame] | 27 | public abstract class LocationBasePreferenceController extends BasePreferenceController |
| 28 | implements LocationEnabler.LocationModeChangeListener { |
Doris Ling | 9ed29a2 | 2017-11-02 16:42:45 -0700 | [diff] [blame] | 29 | |
Raff Tsai | 2229585 | 2019-11-22 11:35:40 +0800 | [diff] [blame] | 30 | protected UserManager mUserManager; |
| 31 | protected LocationEnabler mLocationEnabler; |
| 32 | protected DashboardFragment mFragment; |
| 33 | protected Lifecycle mLifecycle; |
Doris Ling | 9ed29a2 | 2017-11-02 16:42:45 -0700 | [diff] [blame] | 34 | |
Raff Tsai | 2229585 | 2019-11-22 11:35:40 +0800 | [diff] [blame] | 35 | /** |
| 36 | * Constructor of LocationBasePreferenceController. {@link BasePreferenceController} uses |
| 37 | * reflection to create controller, all controllers extends {@link BasePreferenceController} |
| 38 | * should have this function. |
| 39 | */ |
| 40 | public LocationBasePreferenceController(Context context, String key) { |
| 41 | super(context, key); |
Raff Tsai | ed1b808 | 2019-11-28 10:13:11 +0800 | [diff] [blame] | 42 | mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); |
Raff Tsai | 2229585 | 2019-11-22 11:35:40 +0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Initialize {@link LocationEnabler} in this controller |
| 47 | * |
| 48 | * @param fragment The {@link DashboardFragment} uses the controller. |
| 49 | */ |
| 50 | public void init(DashboardFragment fragment) { |
| 51 | mFragment = fragment; |
Raff Tsai | 2229585 | 2019-11-22 11:35:40 +0800 | [diff] [blame] | 52 | mLifecycle = mFragment.getSettingsLifecycle(); |
| 53 | mLocationEnabler = new LocationEnabler(mContext, this /* listener */, mLifecycle); |
Doris Ling | 9ed29a2 | 2017-11-02 16:42:45 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | @Override |
Raff Tsai | 2229585 | 2019-11-22 11:35:40 +0800 | [diff] [blame] | 57 | public int getAvailabilityStatus() { |
| 58 | return AVAILABLE; |
Doris Ling | 9ed29a2 | 2017-11-02 16:42:45 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | } |