1 /*
2  * Copyright (C) 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.accessibility;
18 
19 import android.content.ContentResolver;
20 import android.database.ContentObserver;
21 import android.net.Uri;
22 import android.os.Handler;
23 import android.provider.Settings;
24 
25 import java.util.ArrayList;
26 import java.util.List;
27 
28 abstract class SettingsContentObserver extends ContentObserver {
29     private final List<String> mKeysToObserve = new ArrayList<>(2);
30 
SettingsContentObserver(Handler handler)31     public SettingsContentObserver(Handler handler) {
32         super(handler);
33         mKeysToObserve.add(Settings.Secure.ACCESSIBILITY_ENABLED);
34         mKeysToObserve.add(Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
35     }
36 
SettingsContentObserver(Handler handler, List<String> keysToObserve)37     public SettingsContentObserver(Handler handler, List<String> keysToObserve) {
38         this(handler);
39         mKeysToObserve.addAll(keysToObserve);
40     }
41 
register(ContentResolver contentResolver)42     public void register(ContentResolver contentResolver) {
43         for (int i = 0; i < mKeysToObserve.size(); i++) {
44             contentResolver.registerContentObserver(
45                     Settings.Secure.getUriFor(mKeysToObserve.get(i)), false, this);
46         }
47     }
48 
unregister(ContentResolver contentResolver)49     public void unregister(ContentResolver contentResolver) {
50         contentResolver.unregisterContentObserver(this);
51     }
52 
53     @Override
onChange(boolean selfChange, Uri uri)54     public abstract void onChange(boolean selfChange, Uri uri);
55 }
56