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
This commit is contained in:
@@ -16,6 +16,7 @@ android_library {
|
||||
"SettingsLibRestrictedLockUtils",
|
||||
"SettingsLibAppPreference",
|
||||
"SettingsLibSearchWidget",
|
||||
"SettingsLibSettingsSpinner",
|
||||
],
|
||||
|
||||
// ANDROIDMK TRANSLATION ERROR: unsupported assignment to LOCAL_SHARED_JAVA_LIBRARIES
|
||||
|
||||
9
packages/SettingsLib/SettingsSpinner/Android.bp
Normal file
9
packages/SettingsLib/SettingsSpinner/Android.bp
Normal file
@@ -0,0 +1,9 @@
|
||||
android_library {
|
||||
name: "SettingsLibSettingsSpinner",
|
||||
|
||||
srcs: ["src/**/*.java"],
|
||||
resource_dirs: ["res"],
|
||||
|
||||
sdk_version: "system_current",
|
||||
min_sdk_version: "21",
|
||||
}
|
||||
23
packages/SettingsLib/SettingsSpinner/AndroidManifest.xml
Normal file
23
packages/SettingsLib/SettingsSpinner/AndroidManifest.xml
Normal file
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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"/>
|
||||
26
packages/SettingsLib/SettingsSpinner/res/values/styles.xml
Normal file
26
packages/SettingsLib/SettingsSpinner/res/values/styles.xml
Normal file
@@ -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>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user