Merge "Move GeoTZ toggle to Date&Time settings screen." into sc-dev

This commit is contained in:
Almaz Mingaleev
2021-03-11 14:04:01 +00:00
committed by Android (Google) Code Review
9 changed files with 76 additions and 342 deletions

View File

@@ -31,7 +31,7 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.TogglePreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
@@ -43,7 +43,7 @@ import java.util.concurrent.Executor;
* screen.
*/
public class LocationTimeZoneDetectionPreferenceController
extends BasePreferenceController
extends TogglePreferenceController
implements LifecycleObserver, OnStart, OnStop, TimeManager.TimeZoneDetectorListener {
private final TimeManager mTimeManager;
@@ -57,6 +57,22 @@ public class LocationTimeZoneDetectionPreferenceController
mLocationManager = context.getSystemService(LocationManager.class);
}
@Override
public boolean isChecked() {
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
mTimeManager.getTimeZoneCapabilitiesAndConfig();
TimeZoneConfiguration configuration = capabilitiesAndConfig.getConfiguration();
return configuration.isGeoDetectionEnabled();
}
@Override
public boolean setChecked(boolean isChecked) {
TimeZoneConfiguration configuration = new TimeZoneConfiguration.Builder()
.setGeoDetectionEnabled(isChecked)
.build();
return mTimeManager.updateTimeZoneConfiguration(configuration);
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
@@ -126,10 +142,10 @@ public class LocationTimeZoneDetectionPreferenceController
summaryResId = R.string.location_time_zone_detection_not_applicable;
}
} else if (configureGeoDetectionEnabledCapability == CAPABILITY_POSSESSED) {
boolean isGeoDetectionEnabled = configuration.isGeoDetectionEnabled();
summaryResId = isGeoDetectionEnabled
? R.string.location_time_zone_detection_on
: R.string.location_time_zone_detection_off;
// If capability is possessed, toggle status already tells all the information needed.
// Returning null will make previous text stick on toggling.
// See AbstractPreferenceController#refreshSummary.
return "";
} else {
// This is unexpected: getAvailabilityStatus() should ensure that the UI element isn't
// even shown for known cases, or the capability is unknown.

View File

@@ -1,52 +0,0 @@
/*
* Copyright (C) 2020 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.datetime.locationtimezone;
import android.app.settings.SettingsEnums;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
/**
* The controller for the "location time zone detection" screen.
*/
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class TimeZoneDetectionSettings extends DashboardFragment {
private static final String TAG = "LTZDetectionSettings";
@Override
public int getMetricsCategory() {
return SettingsEnums.LOCATION_TIME_ZONE_DETECTION;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.location_time_zone_detection;
}
@Override
protected String getLogTag() {
return TAG;
}
/**
* For Search.
*/
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.location_time_zone_detection);
}

View File

@@ -1,59 +0,0 @@
/*
* Copyright (C) 2020 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.datetime.locationtimezone;
import android.app.time.TimeManager;
import android.app.time.TimeZoneCapabilitiesAndConfig;
import android.app.time.TimeZoneConfiguration;
import android.content.Context;
import com.android.settings.core.TogglePreferenceController;
/**
* The controller for the "location time zone detection" switch on the location time zone detection
* screen.
*/
public class TimeZoneDetectionTogglePreferenceController extends TogglePreferenceController {
private final TimeManager mTimeManager;
public TimeZoneDetectionTogglePreferenceController(Context context, String key) {
super(context, key);
mTimeManager = context.getSystemService(TimeManager.class);
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public boolean isChecked() {
TimeZoneCapabilitiesAndConfig capabilitiesAndConfig =
mTimeManager.getTimeZoneCapabilitiesAndConfig();
TimeZoneConfiguration configuration = capabilitiesAndConfig.getConfiguration();
return configuration.isGeoDetectionEnabled();
}
@Override
public boolean setChecked(boolean isChecked) {
TimeZoneConfiguration configuration = new TimeZoneConfiguration.Builder()
.setGeoDetectionEnabled(isChecked)
.build();
return mTimeManager.updateTimeZoneConfiguration(configuration);
}
}