Add PrefController in XML support
Add the ability to define a Preference Controller in xml using the 'controller' tag. This is useful for two reasons: - It allows the controllers to be instantiated via reflection for Slices and Dashboard fragment - Removes the requirement that controllers be defined manually in Fragments In order to be instantiable, they must have a unified construction following either: ClassName(Context) ClassName(Context, String) Also added a robotest that verifies that all controllers defined in XML follow the constructor schema, and extend BasePreferenceController. Test: robotests Bug: 67996923 Change-Id: I304b35dc666daebecf0c9e286696f3f2a510704a
This commit is contained in:
@@ -23,27 +23,26 @@ import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GesturesSettingPreferenceController extends AbstractPreferenceController
|
||||
implements PreferenceControllerMixin {
|
||||
|
||||
private static final String KEY_GESTURES_SETTINGS = "gesture_settings";
|
||||
|
||||
public class GesturesSettingPreferenceController extends BasePreferenceController {
|
||||
private final AssistGestureFeatureProvider mFeatureProvider;
|
||||
private List<AbstractPreferenceController> mGestureControllers;
|
||||
|
||||
private static final String KEY_GESTURES_SETTINGS = "gesture_settings";
|
||||
|
||||
public GesturesSettingPreferenceController(Context context) {
|
||||
super(context);
|
||||
super(context, KEY_GESTURES_SETTINGS);
|
||||
mFeatureProvider = FeatureFactory.getFactory(context).getAssistGestureFeatureProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
public int getAvailabilityStatus() {
|
||||
if (mGestureControllers == null) {
|
||||
mGestureControllers = GestureSettings.buildPreferenceControllers(mContext,
|
||||
null /* lifecycle */, new AmbientDisplayConfiguration(mContext));
|
||||
@@ -52,12 +51,9 @@ public class GesturesSettingPreferenceController extends AbstractPreferenceContr
|
||||
for (AbstractPreferenceController controller : mGestureControllers) {
|
||||
isAvailable = isAvailable || controller.isAvailable();
|
||||
}
|
||||
return isAvailable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_GESTURES_SETTINGS;
|
||||
return isAvailable
|
||||
? AVAILABLE
|
||||
: DISABLED_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,5 +79,4 @@ public class GesturesSettingPreferenceController extends AbstractPreferenceContr
|
||||
}
|
||||
preference.setSummary(summary);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user