From f5afcab9747e96ce2e83ccf7d2fa9789aa370623 Mon Sep 17 00:00:00 2001 From: Tsung-Mao Fang Date: Mon, 16 Nov 2020 18:25:58 +0800 Subject: [PATCH] Create a top intro preference widget Based on our ux spec, so we create this widget to let everyone can follow our spec easily. Test: Apply this widget in Settings and confirm it. Bug: 173087905 Change-Id: I481b350c417745cc3332b403877627e081cc0f73 --- packages/SettingsLib/Android.bp | 1 + .../SettingsLib/TopIntroPreference/Android.bp | 13 +++++ .../TopIntroPreference/AndroidManifest.xml | 23 ++++++++ .../res/layout/top_intro_preference.xml | 54 +++++++++++++++++++ .../widget/TopIntroPreference.java | 49 +++++++++++++++++ 5 files changed, 140 insertions(+) create mode 100644 packages/SettingsLib/TopIntroPreference/Android.bp create mode 100644 packages/SettingsLib/TopIntroPreference/AndroidManifest.xml create mode 100644 packages/SettingsLib/TopIntroPreference/res/layout/top_intro_preference.xml create mode 100644 packages/SettingsLib/TopIntroPreference/src/com/android/settingslib/widget/TopIntroPreference.java diff --git a/packages/SettingsLib/Android.bp b/packages/SettingsLib/Android.bp index 5afe2f3d2efc4..3af4b25fb40c0 100644 --- a/packages/SettingsLib/Android.bp +++ b/packages/SettingsLib/Android.bp @@ -51,6 +51,7 @@ java_defaults { "SettingsLibRadioButtonPreference", "SettingsLibDisplayDensityUtils", "SettingsLibUtils", + "SettingsLibTopIntroPreference", ], } diff --git a/packages/SettingsLib/TopIntroPreference/Android.bp b/packages/SettingsLib/TopIntroPreference/Android.bp new file mode 100644 index 0000000000000..03becbd23226f --- /dev/null +++ b/packages/SettingsLib/TopIntroPreference/Android.bp @@ -0,0 +1,13 @@ +android_library { + name: "SettingsLibTopIntroPreference", + + srcs: ["src/**/*.java"], + resource_dirs: ["res"], + + static_libs: [ + "androidx.annotation_annotation", + "androidx.preference_preference", + ], + sdk_version: "system_current", + min_sdk_version: "21", +} diff --git a/packages/SettingsLib/TopIntroPreference/AndroidManifest.xml b/packages/SettingsLib/TopIntroPreference/AndroidManifest.xml new file mode 100644 index 0000000000000..96d9e518663f9 --- /dev/null +++ b/packages/SettingsLib/TopIntroPreference/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + diff --git a/packages/SettingsLib/TopIntroPreference/res/layout/top_intro_preference.xml b/packages/SettingsLib/TopIntroPreference/res/layout/top_intro_preference.xml new file mode 100644 index 0000000000000..19fa91f72f0da --- /dev/null +++ b/packages/SettingsLib/TopIntroPreference/res/layout/top_intro_preference.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/packages/SettingsLib/TopIntroPreference/src/com/android/settingslib/widget/TopIntroPreference.java b/packages/SettingsLib/TopIntroPreference/src/com/android/settingslib/widget/TopIntroPreference.java new file mode 100644 index 0000000000000..9c82907da72a6 --- /dev/null +++ b/packages/SettingsLib/TopIntroPreference/src/com/android/settingslib/widget/TopIntroPreference.java @@ -0,0 +1,49 @@ +/* + * 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.settingslib.widget; + +import android.content.Context; +import android.util.AttributeSet; + +import androidx.preference.Preference; +import androidx.preference.PreferenceViewHolder; + +/** + * The TopIntroPreference shows a text which describe a feature. Gernerally, we expect this + * preference always shows on the top of screen. + */ +public class TopIntroPreference extends Preference { + + public TopIntroPreference(Context context) { + super(context); + setLayoutResource(R.layout.top_intro_preference); + setSelectable(false); + } + + public TopIntroPreference(Context context, AttributeSet attrs) { + super(context, attrs); + setLayoutResource(R.layout.top_intro_preference); + setSelectable(false); + } + + @Override + public void onBindViewHolder(PreferenceViewHolder holder) { + super.onBindViewHolder(holder); + holder.setDividerAllowedAbove(true); + holder.setDividerAllowedBelow(true); + } +}