Add support for device state based auto-rotation preferences in Settings.
- Creates new preferences that are shown when device-state rotation is supported. - Hides standard preferences when device-state rotation is supported. - Controllers/Preferences for individual folded/unfolded rotation settings are created and added programatically based on the settable device states available. Test: Manually + Unit tests Bug: 195757480 Change-Id: If254220ca3018bc6ec1c4e3947375733f6816f92
This commit is contained in:
@@ -34,10 +34,14 @@ import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.widget.SettingsMainSwitchBar;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.search.Indexable;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
import com.android.settingslib.search.SearchIndexableRaw;
|
||||
import com.android.settingslib.widget.FooterPreference;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Preference fragment used for auto rotation
|
||||
*/
|
||||
@@ -60,6 +64,15 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
use(SmartAutoRotateController.class).init(getLifecycle());
|
||||
DeviceStateAutoRotationHelper.initControllers(
|
||||
getLifecycle(),
|
||||
useAll(DeviceStateAutoRotateSettingController.class)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
return DeviceStateAutoRotationHelper.createPreferenceControllers(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,7 +92,9 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
|
||||
|
||||
@VisibleForTesting
|
||||
void createHeader(SettingsActivity activity) {
|
||||
if (isRotationResolverServiceAvailable(activity)) {
|
||||
boolean deviceStateRotationEnabled =
|
||||
DeviceStateAutoRotationHelper.isDeviceStateRotationEnabled(activity);
|
||||
if (isRotationResolverServiceAvailable(activity) && !deviceStateRotationEnabled) {
|
||||
final SettingsMainSwitchBar switchBar = activity.getSwitchBar();
|
||||
switchBar.setTitle(
|
||||
getContext().getString(R.string.auto_rotate_settings_primary_switch_title));
|
||||
@@ -127,5 +142,12 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
|
||||
}
|
||||
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.auto_rotate_settings);
|
||||
new BaseSearchIndexProvider(R.xml.auto_rotate_settings) {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableRaw> getRawDataToIndex(
|
||||
Context context, boolean enabled) {
|
||||
return DeviceStateAutoRotationHelper.getRawDataToIndex(context, enabled);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user