1764f45db9168b4f19623b72db8429016d1226cbeJason Monk/*
2764f45db9168b4f19623b72db8429016d1226cbeJason Monk * Copyright (C) 2016 The Android Open Source Project
3764f45db9168b4f19623b72db8429016d1226cbeJason Monk *
4764f45db9168b4f19623b72db8429016d1226cbeJason Monk * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5764f45db9168b4f19623b72db8429016d1226cbeJason Monk * except in compliance with the License. You may obtain a copy of the License at
6764f45db9168b4f19623b72db8429016d1226cbeJason Monk *
7764f45db9168b4f19623b72db8429016d1226cbeJason Monk *      http://www.apache.org/licenses/LICENSE-2.0
8764f45db9168b4f19623b72db8429016d1226cbeJason Monk *
9764f45db9168b4f19623b72db8429016d1226cbeJason Monk * Unless required by applicable law or agreed to in writing, software distributed under the
10764f45db9168b4f19623b72db8429016d1226cbeJason Monk * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11764f45db9168b4f19623b72db8429016d1226cbeJason Monk * KIND, either express or implied. See the License for the specific language governing
12764f45db9168b4f19623b72db8429016d1226cbeJason Monk * permissions and limitations under the License.
13764f45db9168b4f19623b72db8429016d1226cbeJason Monk */
14764f45db9168b4f19623b72db8429016d1226cbeJason Monk
15764f45db9168b4f19623b72db8429016d1226cbeJason Monkpackage com.android.settings.datausage;
16764f45db9168b4f19623b72db8429016d1226cbeJason Monk
17764f45db9168b4f19623b72db8429016d1226cbeJason Monkimport android.content.Context;
18764f45db9168b4f19623b72db8429016d1226cbeJason Monkimport android.support.v7.preference.Preference;
19764f45db9168b4f19623b72db8429016d1226cbeJason Monkimport android.util.AttributeSet;
20764f45db9168b4f19623b72db8429016d1226cbeJason Monkimport com.android.settings.R;
21764f45db9168b4f19623b72db8429016d1226cbeJason Monk
22764f45db9168b4f19623b72db8429016d1226cbeJason Monkpublic class DataSaverPreference extends Preference implements DataSaverBackend.Listener {
23764f45db9168b4f19623b72db8429016d1226cbeJason Monk
24764f45db9168b4f19623b72db8429016d1226cbeJason Monk    private final DataSaverBackend mDataSaverBackend;
25764f45db9168b4f19623b72db8429016d1226cbeJason Monk
26764f45db9168b4f19623b72db8429016d1226cbeJason Monk    public DataSaverPreference(Context context, AttributeSet attrs) {
27764f45db9168b4f19623b72db8429016d1226cbeJason Monk        super(context, attrs);
28764f45db9168b4f19623b72db8429016d1226cbeJason Monk        mDataSaverBackend = new DataSaverBackend(context);
29764f45db9168b4f19623b72db8429016d1226cbeJason Monk    }
30764f45db9168b4f19623b72db8429016d1226cbeJason Monk
31764f45db9168b4f19623b72db8429016d1226cbeJason Monk    @Override
32764f45db9168b4f19623b72db8429016d1226cbeJason Monk    public void onAttached() {
33764f45db9168b4f19623b72db8429016d1226cbeJason Monk        super.onAttached();
34764f45db9168b4f19623b72db8429016d1226cbeJason Monk        mDataSaverBackend.addListener(this);
35764f45db9168b4f19623b72db8429016d1226cbeJason Monk    }
36764f45db9168b4f19623b72db8429016d1226cbeJason Monk
37764f45db9168b4f19623b72db8429016d1226cbeJason Monk    @Override
38764f45db9168b4f19623b72db8429016d1226cbeJason Monk    public void onDetached() {
39764f45db9168b4f19623b72db8429016d1226cbeJason Monk        super.onDetached();
40484087c181cedb5a6418c8c10f81a36eaa49420fJin Dong        mDataSaverBackend.remListener(this);
41764f45db9168b4f19623b72db8429016d1226cbeJason Monk    }
42764f45db9168b4f19623b72db8429016d1226cbeJason Monk
43764f45db9168b4f19623b72db8429016d1226cbeJason Monk    @Override
44764f45db9168b4f19623b72db8429016d1226cbeJason Monk    public void onDataSaverChanged(boolean isDataSaving) {
45764f45db9168b4f19623b72db8429016d1226cbeJason Monk        setSummary(isDataSaving ? R.string.data_saver_on : R.string.data_saver_off);
46764f45db9168b4f19623b72db8429016d1226cbeJason Monk    }
4785c63f348f7bdccd47266ec9bbd083d49105af53Felipe Leme
4885c63f348f7bdccd47266ec9bbd083d49105af53Felipe Leme    @Override
4985c63f348f7bdccd47266ec9bbd083d49105af53Felipe Leme    public void onWhitelistStatusChanged(int uid, boolean isWhitelisted) {
5085c63f348f7bdccd47266ec9bbd083d49105af53Felipe Leme    }
5185c63f348f7bdccd47266ec9bbd083d49105af53Felipe Leme
5285c63f348f7bdccd47266ec9bbd083d49105af53Felipe Leme    @Override
5385c63f348f7bdccd47266ec9bbd083d49105af53Felipe Leme    public void onBlacklistStatusChanged(int uid, boolean isBlacklisted) {
5485c63f348f7bdccd47266ec9bbd083d49105af53Felipe Leme    }
55764f45db9168b4f19623b72db8429016d1226cbeJason Monk}
56