Create a custom drop-down filter spinner
Create a drop-down filter widget let other apps can use it.
UX goal is to use this widget on a bunch of page.
For example, Permissions, All apps, Sunshine, etc.
Change-Id: I0e939388d307deff9bad51e3ef415043814ec49e
Fixes: 112706966
Test: robotests
diff --git a/packages/SettingsLib/Android.bp b/packages/SettingsLib/Android.bp
index 89438e5..d60dbe7 100644
--- a/packages/SettingsLib/Android.bp
+++ b/packages/SettingsLib/Android.bp
@@ -16,6 +16,7 @@
"SettingsLibRestrictedLockUtils",
"SettingsLibAppPreference",
"SettingsLibSearchWidget",
+ "SettingsLibSettingsSpinner",
],
// ANDROIDMK TRANSLATION ERROR: unsupported assignment to LOCAL_SHARED_JAVA_LIBRARIES
diff --git a/packages/SettingsLib/SettingsSpinner/Android.bp b/packages/SettingsLib/SettingsSpinner/Android.bp
new file mode 100644
index 0000000..f18917c
--- /dev/null
+++ b/packages/SettingsLib/SettingsSpinner/Android.bp
@@ -0,0 +1,9 @@
+android_library {
+ name: "SettingsLibSettingsSpinner",
+
+ srcs: ["src/**/*.java"],
+ resource_dirs: ["res"],
+
+ sdk_version: "system_current",
+ min_sdk_version: "21",
+}
diff --git a/packages/SettingsLib/SettingsSpinner/AndroidManifest.xml b/packages/SettingsLib/SettingsSpinner/AndroidManifest.xml
new file mode 100644
index 0000000..5db9335
--- /dev/null
+++ b/packages/SettingsLib/SettingsSpinner/AndroidManifest.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2018 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.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.settingslib.widget.settingsspinner">
+
+ <uses-sdk android:minSdkVersion="21" />
+
+</manifest>
diff --git a/packages/SettingsLib/SettingsSpinner/res/drawable/arrow_drop_down_24dp.xml b/packages/SettingsLib/SettingsSpinner/res/drawable/arrow_drop_down_24dp.xml
new file mode 100644
index 0000000..827d0b5
--- /dev/null
+++ b/packages/SettingsLib/SettingsSpinner/res/drawable/arrow_drop_down_24dp.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2018 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.
+ -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:viewportWidth="24"
+ android:viewportHeight="24"
+ android:width="24dp"
+ android:height="24dp">
+ <path
+ android:pathData="M7 10l5 5 5 -5z"
+ android:fillColor="?android:attr/textColorPrimary"/>
+</vector>
\ No newline at end of file
diff --git a/packages/SettingsLib/SettingsSpinner/res/drawable/settings_spinner_background.xml b/packages/SettingsLib/SettingsSpinner/res/drawable/settings_spinner_background.xml
new file mode 100644
index 0000000..af30425
--- /dev/null
+++ b/packages/SettingsLib/SettingsSpinner/res/drawable/settings_spinner_background.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2018 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.
+ -->
+
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
+ android:paddingMode="stack">
+ <item>
+ <shape>
+ <corners
+ android:radius="20dp"/>
+ <stroke
+ android:color="?android:attr/textColorSecondary"
+ android:width="1dp"/>
+ <size
+ android:height="32dp"/>
+ </shape>
+ </item>
+
+ <item
+ android:gravity="center|end"
+ android:width="24dp"
+ android:height="24dp"
+ android:end="4dp"
+ android:drawable="@drawable/arrow_drop_down_24dp"/>
+</layer-list>
\ No newline at end of file
diff --git a/packages/SettingsLib/SettingsSpinner/res/layout/settings_spinner_view.xml b/packages/SettingsLib/SettingsSpinner/res/layout/settings_spinner_view.xml
new file mode 100644
index 0000000..bdd370f
--- /dev/null
+++ b/packages/SettingsLib/SettingsSpinner/res/layout/settings_spinner_view.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2018 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.
+-->
+
+<TextView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@android:id/text1"
+ style="@style/SettingsSpinnerTitleBar"
+ android:maxLines="1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:ellipsize="marquee"/>
diff --git a/packages/SettingsLib/SettingsSpinner/res/values/styles.xml b/packages/SettingsLib/SettingsSpinner/res/values/styles.xml
new file mode 100644
index 0000000..8447b08
--- /dev/null
+++ b/packages/SettingsLib/SettingsSpinner/res/values/styles.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2018 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.
+ -->
+
+<resources>
+ <style name="SettingsSpinnerTitleBar">
+ <item name="android:textAppearance">?android:attr/textAppearance</item>
+ <item name="android:paddingStart">16dp</item>
+ <item name="android:paddingEnd">36dp</item>
+ <item name="android:paddingTop">8dp</item>
+ <item name="android:paddingBottom">8dp</item>
+ </style>
+</resources>
\ No newline at end of file
diff --git a/packages/SettingsLib/SettingsSpinner/src/com/android/settingslib/widget/settingsspinner/SettingsSpinner.java b/packages/SettingsLib/SettingsSpinner/src/com/android/settingslib/widget/settingsspinner/SettingsSpinner.java
new file mode 100644
index 0000000..130cef2
--- /dev/null
+++ b/packages/SettingsLib/SettingsSpinner/src/com/android/settingslib/widget/settingsspinner/SettingsSpinner.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2018 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.settingslib.widget.settingsspinner;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.Spinner;
+
+/**
+ * A {@link Spinner} with settings style.
+ *
+ * The items in the SettingsSpinner come from the {@link SettingsSpinnerAdapter} associated with
+ * this view.
+ */
+public class SettingsSpinner extends Spinner {
+
+ /**
+ * Constructs a new SettingsSpinner with the given context's theme.
+ * And it also set a background resource with settings style.
+ *
+ * @param context The Context the view is running in, through which it can
+ * access the current theme, resources, etc.
+ */
+ public SettingsSpinner(Context context) {
+ super(context);
+ setBackgroundResource(R.drawable.settings_spinner_background);
+ }
+
+ /**
+ * Constructs a new SettingsSpinner with the given context's theme and the supplied
+ * mode of displaying choices. <code>mode</code> may be one of
+ * {@link Spinner#MODE_DIALOG} or {@link Spinner#MODE_DROPDOWN}.
+ * And it also set a background resource with settings style.
+ *
+ * @param context The Context the view is running in, through which it can
+ * access the current theme, resources, etc.
+ * @param mode Constant describing how the user will select choices from
+ * the spinner.
+ *
+ * @see Spinner#MODE_DIALOG
+ * @see Spinner#MODE_DROPDOWN
+ */
+ public SettingsSpinner(Context context, int mode) {
+ super(context, mode);
+ setBackgroundResource(R.drawable.settings_spinner_background);
+ }
+
+ /**
+ * Constructs a new SettingsSpinner with the given context's theme and the supplied
+ * attribute set.
+ * And it also set a background resource with settings style.
+ *
+ * @param context The Context the view is running in, through which it can
+ * access the current theme, resources, etc.
+ * @param attrs The attributes of the XML tag that is inflating the view.
+ */
+ public SettingsSpinner(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ setBackgroundResource(R.drawable.settings_spinner_background);
+ }
+
+ /**
+ * Constructs a new SettingsSpinner with the given context's theme, the supplied
+ * attribute set, and default style attribute.
+ * And it also set a background resource with settings style.
+ *
+ * @param context The Context the view is running in, through which it can
+ * access the current theme, resources, etc.
+ * @param attrs The attributes of the XML tag that is inflating the view.
+ * @param defStyleAttr An attribute in the current theme that contains a
+ * reference to a style resource that supplies default
+ * values for the view. Can be 0 to not look for
+ * defaults.
+ */
+ public SettingsSpinner(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ setBackgroundResource(R.drawable.settings_spinner_background);
+ }
+
+ /**
+ * Constructs a new SettingsSpinner with the given context's theme, the supplied
+ * attribute set, and default styles. <code>mode</code> may be one of
+ * {@link Spinner#MODE_DIALOG} or {@link Spinner#MODE_DROPDOWN} and determines how the
+ * user will select choices from the spinner.
+ * And it also set a background resource with settings style.
+ *
+ * @param context The Context the view is running in, through which it can
+ * access the current theme, resources, etc.
+ * @param attrs The attributes of the XML tag that is inflating the view.
+ * @param defStyleAttr An attribute in the current theme that contains a
+ * reference to a style resource that supplies default
+ * values for the view. Can be 0 to not look for
+ * defaults.
+ * @param defStyleRes A resource identifier of a style resource that
+ * supplies default values for the view, used only if
+ * defStyleAttr is 0 or can not be found in the theme.
+ * Can be 0 to not look for defaults.
+ * @param mode Constant describing how the user will select choices from
+ * the spinner.
+ *
+ * @see Spinner#MODE_DIALOG
+ * @see Spinner#MODE_DROPDOWN
+ */
+ public SettingsSpinner(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes,
+ int mode) {
+ super(context, attrs, defStyleAttr, defStyleRes, mode, null);
+ }
+}
\ No newline at end of file
diff --git a/packages/SettingsLib/SettingsSpinner/src/com/android/settingslib/widget/settingsspinner/SettingsSpinnerAdapter.java b/packages/SettingsLib/SettingsSpinner/src/com/android/settingslib/widget/settingsspinner/SettingsSpinnerAdapter.java
new file mode 100644
index 0000000..c26295c
--- /dev/null
+++ b/packages/SettingsLib/SettingsSpinner/src/com/android/settingslib/widget/settingsspinner/SettingsSpinnerAdapter.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2018 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.settingslib.widget.settingsspinner;
+
+import android.content.Context;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+
+/**
+ * An ArrayAdapter which was used by {@link SettingsSpinner} with settings style.
+ */
+public class SettingsSpinnerAdapter<CharSequence> extends ArrayAdapter {
+
+ /**
+ * Constructs a new SettingsSpinnerAdapter with the given context.
+ * And it customizes title bar with a settings style.
+ *
+ * @param context The Context the view is running in, through which it can
+ * access the current theme, resources, etc.
+ */
+ public SettingsSpinnerAdapter(Context context) {
+ super(context, R.layout.settings_spinner_view);
+ setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ }
+}