fix: 首次提交
This commit is contained in:
31
SettingsLib/LayoutPreference/Android.bp
Normal file
31
SettingsLib/LayoutPreference/Android.bp
Normal file
@@ -0,0 +1,31 @@
|
||||
package {
|
||||
// See: http://go/android-license-faq
|
||||
// A large-scale-change added 'default_applicable_licenses' to import
|
||||
// all of the 'license_kinds' from "frameworks_base_license"
|
||||
// to get the below license kinds:
|
||||
// SPDX-license-identifier-Apache-2.0
|
||||
default_applicable_licenses: ["frameworks_base_license"],
|
||||
}
|
||||
|
||||
android_library {
|
||||
name: "SettingsLibLayoutPreference",
|
||||
use_resource_processor: true,
|
||||
defaults: [
|
||||
"SettingsLintDefaults",
|
||||
],
|
||||
|
||||
srcs: ["src/**/*.java"],
|
||||
resource_dirs: ["res"],
|
||||
|
||||
static_libs: [
|
||||
"androidx.preference_preference",
|
||||
"SettingsLibSettingsTheme",
|
||||
],
|
||||
|
||||
sdk_version: "system_current",
|
||||
min_sdk_version: "21",
|
||||
apex_available: [
|
||||
"//apex_available:platform",
|
||||
"com.android.permission",
|
||||
],
|
||||
}
|
||||
23
SettingsLib/LayoutPreference/AndroidManifest.xml
Normal file
23
SettingsLib/LayoutPreference/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.preference.layout">
|
||||
|
||||
<uses-sdk android:minSdkVersion="21" />
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,26 @@
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?android:attr/colorAccent">
|
||||
<path
|
||||
android:pathData="M6.99,11L3,15l3.99,4v-3H14v-2H6.99v-3zM21,9l-3.99,-4v3H10v2h7.01v3L21,9z"
|
||||
android:fillColor="@android:color/white"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,25 @@
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M6.99,11L3,15l3.99,4v-3H14v-2H6.99v-3zM21,9l-3.99,-4v3H10v2h7.01v3L21,9z"
|
||||
android:fillColor="#757575"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/entity_header"
|
||||
style="@style/EntityHeader">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/entity_header_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="32dp"
|
||||
android:paddingBottom="32dp"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/entity_header_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/entity_header_icon_personal"
|
||||
style="@style/CrossProfileEntityHeaderIcon" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/entity_header_swap_horiz"
|
||||
style="@style/CrossProfileSwapHorizIcon "/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/entity_header_icon_work"
|
||||
style="@style/CrossProfileEntityHeaderIcon" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/entity_header_title"
|
||||
style="@style/CrossProfileEntityHeaderTitle" />
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:importantForAccessibility="no"/>
|
||||
@@ -0,0 +1,112 @@
|
||||
<?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.
|
||||
-->
|
||||
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/entity_header"
|
||||
style="@style/EntityHeader"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/entity_header_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/entity_header_icon"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:antialias="true"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/entity_header_title"
|
||||
style="@style/TextAppearance.EntityHeaderTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="false"
|
||||
android:gravity="center"
|
||||
android:ellipsize="marquee"
|
||||
android:textDirection="locale"
|
||||
android:layout_marginTop="8dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/install_type"
|
||||
style="@style/TextAppearance.EntityHeaderSummary"
|
||||
android:visibility="gone"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/entity_header_summary"
|
||||
style="@style/TextAppearance.EntityHeaderSummary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dp"
|
||||
android:singleLine="false"
|
||||
android:textAlignment="center"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/entity_header_second_summary"
|
||||
style="@style/TextAppearance.EntityHeaderSummary"
|
||||
android:singleLine="false"
|
||||
android:maxLines="4"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageButton
|
||||
android:id="@android:id/button1"
|
||||
style="?android:attr/actionOverflowButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="0dp"
|
||||
android:visibility="gone"
|
||||
android:minWidth="24dp"
|
||||
android:src="@null"
|
||||
android:tint="?android:attr/colorAccent"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@android:id/button2"
|
||||
style="?android:attr/actionOverflowButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="0dp"
|
||||
android:visibility="gone"
|
||||
android:minWidth="24dp"
|
||||
android:src="@null"
|
||||
android:tint="?android:attr/colorAccent"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
55
SettingsLib/LayoutPreference/res/values/styles.xml
Normal file
55
SettingsLib/LayoutPreference/res/values/styles.xml
Normal file
@@ -0,0 +1,55 @@
|
||||
<?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="EntityHeader">
|
||||
<item name="android:paddingTop">24dp</item>
|
||||
<item name="android:paddingBottom">16dp</item>
|
||||
<item name="android:paddingEnd">16dp</item>
|
||||
</style>
|
||||
|
||||
<style name="CrossProfileEntityHeaderIcon">
|
||||
<item name="android:layout_width">48dp</item>
|
||||
<item name="android:layout_height">48dp</item>
|
||||
<item name="android:layout_gravity">center</item>
|
||||
<item name="android:gravity">center</item>
|
||||
<item name="android:scaleType">fitCenter</item>
|
||||
<item name="android:antialias">true</item>
|
||||
</style>
|
||||
|
||||
<style name="CrossProfileSwapHorizIcon">
|
||||
<item name="android:layout_width">24dp</item>
|
||||
<item name="android:layout_height">24dp</item>
|
||||
<item name="android:layout_gravity">center</item>
|
||||
<item name="android:gravity">center</item>
|
||||
<item name="android:scaleType">fitCenter</item>
|
||||
<item name="android:layout_marginStart">10dp</item>
|
||||
<item name="android:layout_marginEnd">10dp</item>
|
||||
<item name="android:src">@drawable/ic_swap_horiz_grey</item>
|
||||
<item name="android:antialias">true</item>
|
||||
</style>
|
||||
|
||||
<style name="CrossProfileEntityHeaderTitle">
|
||||
<item name="android:layout_width">wrap_content</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:layout_gravity">center</item>
|
||||
<item name="android:textSize">18sp</item>
|
||||
<item name="android:textColor">?android:attr/textColorPrimary</item>
|
||||
<item name="android:fontFamily">google-sans-medium</item>
|
||||
<item name="android:layout_marginTop">8dp</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import androidx.core.content.res.TypedArrayUtils;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
/**
|
||||
* A preference can be simply customized a view by adding layout attribute in xml.
|
||||
* User also can decide whether or not LayoutPreference allows above divider or below divider.
|
||||
*
|
||||
* For instances,
|
||||
*
|
||||
* <com.android.settingslib.widget.LayoutPreference
|
||||
* ...
|
||||
* android:layout="@layout/settings_entity_header"
|
||||
* xxxxxxx:allowDividerAbove="true"
|
||||
* xxxxxxx:allowDividerBelow="true"
|
||||
*
|
||||
*/
|
||||
public class LayoutPreference extends Preference {
|
||||
|
||||
private final View.OnClickListener mClickListener = v -> performClick(v);
|
||||
private boolean mAllowDividerAbove;
|
||||
private boolean mAllowDividerBelow;
|
||||
private View mRootView;
|
||||
|
||||
/**
|
||||
* Constructs a new LayoutPreference with the given context's theme and the supplied
|
||||
* attribute set.
|
||||
*
|
||||
* @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 LayoutPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs, 0 /* defStyleAttr */);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new LayoutPreference with the given context's theme, the supplied
|
||||
* attribute set, and default style attribute.
|
||||
*
|
||||
* @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 LayoutPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new LayoutPreference with the given context's theme and a customized view id.
|
||||
*
|
||||
* @param context The Context the view is running in, through which it can
|
||||
* access the current theme, resources, etc.
|
||||
* @param resource The view id which you expected to be inflated and show in preference.
|
||||
*/
|
||||
public LayoutPreference(Context context, int resource) {
|
||||
this(context, LayoutInflater.from(context).inflate(resource, null, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new LayoutPreference with the given context's theme and a customized view.
|
||||
*
|
||||
* @param context The Context the view is running in, through which it can
|
||||
* access the current theme, resources, etc.
|
||||
* @param view The view which you expected show in preference.
|
||||
*/
|
||||
public LayoutPreference(Context context, View view) {
|
||||
super(context);
|
||||
setView(view);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, androidx.preference.R.styleable.Preference);
|
||||
mAllowDividerAbove = TypedArrayUtils.getBoolean(a, androidx.preference.R.styleable.Preference_allowDividerAbove,
|
||||
androidx.preference.R.styleable.Preference_allowDividerAbove, false);
|
||||
mAllowDividerBelow = TypedArrayUtils.getBoolean(a, androidx.preference.R.styleable.Preference_allowDividerBelow,
|
||||
androidx.preference.R.styleable.Preference_allowDividerBelow, false);
|
||||
a.recycle();
|
||||
|
||||
a = context.obtainStyledAttributes(
|
||||
attrs, androidx.preference.R.styleable.Preference, defStyleAttr, 0);
|
||||
int layoutResource = a.getResourceId(androidx.preference.R.styleable.Preference_android_layout, 0);
|
||||
if (layoutResource == 0) {
|
||||
throw new IllegalArgumentException("LayoutPreference requires a layout to be defined");
|
||||
}
|
||||
a.recycle();
|
||||
|
||||
// Need to create view now so that findViewById can be called immediately.
|
||||
final View view = LayoutInflater.from(getContext())
|
||||
.inflate(layoutResource, null, false);
|
||||
setView(view);
|
||||
}
|
||||
|
||||
private void setView(View view) {
|
||||
setLayoutResource(com.android.settingslib.widget.preference.layout.R.layout.layout_preference_frame);
|
||||
mRootView = view;
|
||||
setShouldDisableView(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
holder.itemView.setOnClickListener(mClickListener);
|
||||
|
||||
final boolean selectable = isSelectable();
|
||||
holder.itemView.setFocusable(selectable);
|
||||
holder.itemView.setClickable(selectable);
|
||||
holder.setDividerAllowedAbove(mAllowDividerAbove);
|
||||
holder.setDividerAllowedBelow(mAllowDividerBelow);
|
||||
|
||||
FrameLayout layout = (FrameLayout) holder.itemView;
|
||||
layout.removeAllViews();
|
||||
ViewGroup parent = (ViewGroup) mRootView.getParent();
|
||||
if (parent != null) {
|
||||
parent.removeView(mRootView);
|
||||
}
|
||||
layout.addView(mRootView);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the view with the given ID.
|
||||
*
|
||||
* @param id the ID to search for
|
||||
* @return a view with given ID if found, or {@code null} otherwise
|
||||
*/
|
||||
public <T extends View> T findViewById(int id) {
|
||||
return mRootView.findViewById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* LayoutPreference whether or not allows to set a below divider.
|
||||
*/
|
||||
public void setAllowDividerBelow(boolean allowed) {
|
||||
mAllowDividerBelow = allowed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a value whether or not LayoutPreference allows to set a below divider.
|
||||
*/
|
||||
public boolean isAllowDividerBelow() {
|
||||
return mAllowDividerBelow;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user