Create SettingsLibTwoTargetPreference

Bug: 180156703
Test: robotest
Change-Id: I4a9958efa47ac24f88e06c8fdb1c9d0a5542e360
This commit is contained in:
Edgar Wang
2021-02-13 12:28:26 +08:00
parent 242cc497ab
commit 506c0cfab4
10 changed files with 81 additions and 16 deletions

View File

@@ -17,8 +17,8 @@ android_library {
// TODO(b/149540986): revert this change.
static_libs: [
// All other dependent components should be put in
// "SettingsLibDependenciesWithoutWifiTracker".
// All other dependent components should be put in
// "SettingsLibDependenciesWithoutWifiTracker".
"WifiTrackerLib",
],
@@ -27,7 +27,10 @@ android_library {
resource_dirs: ["res"],
srcs: ["src/**/*.java", "src/**/*.kt"],
srcs: [
"src/**/*.java",
"src/**/*.kt",
],
min_sdk_version: "21",
@@ -67,6 +70,7 @@ java_defaults {
"SettingsLibFooterPreference",
"SettingsLibUsageProgressBarPreference",
"SettingsLibCollapsingToolbarBaseActivity",
"SettingsLibTwoTargetPreference",
],
}

View File

@@ -0,0 +1,13 @@
android_library {
name: "SettingsLibTwoTargetPreference",
srcs: ["src/**/*.java"],
resource_dirs: ["res"],
static_libs: [
"androidx.annotation_annotation",
"androidx.preference_preference",
],
sdk_version: "system_current",
min_sdk_version: "21",
}

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2021 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">
<uses-sdk android:minSdkVersion="21" />
</manifest>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2017 The Android Open Source Project
Copyright (C) 2021 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.

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2017 The Android Open Source Project
Copyright (C) 2021 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.

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2021 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>
<dimen name="two_target_pref_small_icon_size">24dp</dimen>
<dimen name="two_target_pref_medium_icon_size">32dp</dimen>
</resources>

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 The Android Open Source Project
* Copyright (C) 2021 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.
@@ -14,21 +14,24 @@
* limitations under the License.
*/
package com.android.settingslib;
package com.android.settingslib.widget;
import android.annotation.IntDef;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.annotation.IntDef;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* The Base preference with two target areas divided by a vertical divider
*/
public class TwoTargetPreference extends Preference {
@IntDef({ICON_SIZE_DEFAULT, ICON_SIZE_MEDIUM, ICON_SIZE_SMALL})

View File

@@ -32,9 +32,6 @@
<dimen name="user_spinner_padding_sides">20dp</dimen>
<dimen name="user_spinner_item_height">56dp</dimen>
<dimen name="two_target_pref_small_icon_size">24dp</dimen>
<dimen name="two_target_pref_medium_icon_size">32dp</dimen>
<!-- Lock icon for preferences locked by admin -->
<dimen name="restricted_icon_padding">4dp</dimen>

View File

@@ -27,6 +27,8 @@ import androidx.core.content.res.TypedArrayUtils;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceViewHolder;
import com.android.settingslib.widget.TwoTargetPreference;
/**
* Preference class that supports being disabled by a user restriction
* set by a device admin.

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 The Android Open Source Project
* Copyright (C) 2021 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.
@@ -14,11 +14,11 @@
* limitations under the License.
*/
package com.android.settingslib;
package com.android.settingslib.widget;
import static com.android.settingslib.TwoTargetPreference.ICON_SIZE_DEFAULT;
import static com.android.settingslib.TwoTargetPreference.ICON_SIZE_MEDIUM;
import static com.android.settingslib.TwoTargetPreference.ICON_SIZE_SMALL;
import static com.android.settingslib.widget.TwoTargetPreference.ICON_SIZE_DEFAULT;
import static com.android.settingslib.widget.TwoTargetPreference.ICON_SIZE_MEDIUM;
import static com.android.settingslib.widget.TwoTargetPreference.ICON_SIZE_SMALL;
import static com.google.common.truth.Truth.assertThat;
@@ -32,6 +32,8 @@ import android.widget.LinearLayout;
import androidx.preference.PreferenceViewHolder;
import com.android.settingslib.R;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;