Add data saver to settings
Bug: 22817899 Change-Id: Ic3055aa6a5baae1653db350313366f180c049cc7
This commit is contained in:
83
src/com/android/settings/datausage/DataSaverSummary.java
Normal file
83
src/com/android/settings/datausage/DataSaverSummary.java
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.datausage;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.util.Log;
|
||||
import android.widget.Switch;
|
||||
import com.android.settings.InstrumentedFragment;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
|
||||
public class DataSaverSummary extends SettingsPreferenceFragment
|
||||
implements SwitchBar.OnSwitchChangeListener, DataSaverBackend.Listener {
|
||||
|
||||
private static final String KEY_UNRESTRICTED_ACCESS = "unrestricted_access";
|
||||
|
||||
private SwitchBar mSwitchBar;
|
||||
private DataSaverBackend mDataSaverBackend;
|
||||
private Preference mUnrestrictedAccess;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
addPreferencesFromResource(R.xml.data_saver);
|
||||
mUnrestrictedAccess = findPreference(KEY_UNRESTRICTED_ACCESS);
|
||||
mDataSaverBackend = new DataSaverBackend(getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mSwitchBar = ((SettingsActivity) getActivity()).getSwitchBar();
|
||||
mSwitchBar.show();
|
||||
mSwitchBar.addOnSwitchChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mDataSaverBackend.addListener(this);
|
||||
mDataSaverBackend.refreshWhitelist();
|
||||
int count = mDataSaverBackend.getWhitelistedCount();
|
||||
mUnrestrictedAccess.setSummary(getResources().getQuantityString(
|
||||
R.plurals.data_saver_unrestricted_summary, count, count));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mDataSaverBackend.remListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchChanged(Switch switchView, boolean isChecked) {
|
||||
mDataSaverBackend.setDataSaverEnabled(isChecked);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMetricsCategory() {
|
||||
return InstrumentedFragment.DATA_SAVER_SUMMARY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataSaverChanged(boolean isDataSaving) {
|
||||
mSwitchBar.setChecked(isDataSaving);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user