Merge "Fix corner radius for expanded widget picker list items" into sc-dev
This commit is contained in:
commit
6f3081affa
|
@ -1,42 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
**
|
||||
** Copyright 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.
|
||||
*/
|
||||
-->
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?android:attr/colorControlHighlight">
|
||||
<item android:id="@android:id/mask">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/surface" />
|
||||
<corners
|
||||
android:topLeftRadius="@dimen/widget_list_content_corner_radius"
|
||||
android:topRightRadius="@dimen/widget_list_content_corner_radius"
|
||||
android:bottomLeftRadius="@dimen/widget_list_top_bottom_corner_radius"
|
||||
android:bottomRightRadius="@dimen/widget_list_top_bottom_corner_radius" />
|
||||
</shape>
|
||||
</item>
|
||||
<item android:id="@android:id/background">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/surface" />
|
||||
<corners
|
||||
android:topLeftRadius="@dimen/widget_list_content_corner_radius"
|
||||
android:topRightRadius="@dimen/widget_list_content_corner_radius"
|
||||
android:bottomLeftRadius="@dimen/widget_list_top_bottom_corner_radius"
|
||||
android:bottomRightRadius="@dimen/widget_list_top_bottom_corner_radius" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
|
@ -1,43 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
**
|
||||
** Copyright 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.
|
||||
*/
|
||||
-->
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?android:attr/colorControlHighlight">
|
||||
<item android:id="@android:id/mask">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/surface" />
|
||||
<corners
|
||||
android:topLeftRadius="@dimen/widget_list_content_corner_radius"
|
||||
android:topRightRadius="@dimen/widget_list_content_corner_radius"
|
||||
android:bottomLeftRadius="@dimen/widget_list_content_corner_radius"
|
||||
android:bottomRightRadius="@dimen/widget_list_content_corner_radius" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<item android:id="@android:id/background">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/surface" />
|
||||
<corners
|
||||
android:topLeftRadius="@dimen/widget_list_content_corner_radius"
|
||||
android:topRightRadius="@dimen/widget_list_content_corner_radius"
|
||||
android:bottomLeftRadius="@dimen/widget_list_content_corner_radius"
|
||||
android:bottomRightRadius="@dimen/widget_list_content_corner_radius" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
|
@ -1,42 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
**
|
||||
** Copyright 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.
|
||||
*/
|
||||
-->
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?android:attr/colorControlHighlight">
|
||||
<item android:id="@android:id/mask">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/surface" />
|
||||
<corners
|
||||
android:topLeftRadius="@dimen/widget_list_top_bottom_corner_radius"
|
||||
android:topRightRadius="@dimen/widget_list_top_bottom_corner_radius"
|
||||
android:bottomLeftRadius="@dimen/widget_list_top_bottom_corner_radius"
|
||||
android:bottomRightRadius="@dimen/widget_list_top_bottom_corner_radius" />
|
||||
</shape>
|
||||
</item>
|
||||
<item android:id="@android:id/background">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/surface" />
|
||||
<corners
|
||||
android:topLeftRadius="@dimen/widget_list_top_bottom_corner_radius"
|
||||
android:topRightRadius="@dimen/widget_list_top_bottom_corner_radius"
|
||||
android:bottomLeftRadius="@dimen/widget_list_top_bottom_corner_radius"
|
||||
android:bottomRightRadius="@dimen/widget_list_top_bottom_corner_radius" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
|
@ -1,43 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
/*
|
||||
**
|
||||
** Copyright 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.
|
||||
*/
|
||||
-->
|
||||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?android:attr/colorControlHighlight">
|
||||
<item android:id="@android:id/mask">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/surface" />
|
||||
<corners
|
||||
android:topLeftRadius="@dimen/widget_list_top_bottom_corner_radius"
|
||||
android:topRightRadius="@dimen/widget_list_top_bottom_corner_radius"
|
||||
android:bottomLeftRadius="@dimen/widget_list_content_corner_radius"
|
||||
android:bottomRightRadius="@dimen/widget_list_content_corner_radius" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<item android:id="@android:id/background">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@color/surface" />
|
||||
<corners
|
||||
android:topLeftRadius="@dimen/widget_list_top_bottom_corner_radius"
|
||||
android:topRightRadius="@dimen/widget_list_top_bottom_corner_radius"
|
||||
android:bottomLeftRadius="@dimen/widget_list_content_corner_radius"
|
||||
android:bottomRightRadius="@dimen/widget_list_content_corner_radius" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
|
@ -20,7 +20,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:background="@drawable/widgets_list_middle_ripple"
|
||||
android:layout_marginBottom="@dimen/widget_list_entry_bottom_margin"
|
||||
android:paddingVertical="@dimen/widget_list_header_view_vertical_padding"
|
||||
android:orientation="horizontal"
|
||||
|
|
|
@ -19,5 +19,4 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:background="@drawable/widgets_list_middle_ripple"
|
||||
android:layout_marginBottom="@dimen/widget_list_entry_bottom_margin"/>
|
||||
|
|
|
@ -131,6 +131,7 @@
|
|||
|
||||
<dimen name="widget_list_top_bottom_corner_radius">28dp</dimen>
|
||||
<dimen name="widget_list_content_corner_radius">4dp</dimen>
|
||||
<dimen name="widget_list_content_joined_corner_radius">0dp</dimen>
|
||||
|
||||
<dimen name="widget_list_header_view_vertical_padding">20dp</dimen>
|
||||
<dimen name="widget_list_entry_bottom_margin">2dp</dimen>
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
package com.android.launcher3.widget.picker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.graphics.drawable.RippleDrawable;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.util.Themes;
|
||||
|
||||
/** Helper class for creating drawables to use as background for list elements. */
|
||||
final class WidgetsListDrawables {
|
||||
|
||||
private WidgetsListDrawables() {}
|
||||
|
||||
/** Creates a list background drawable with the specified radii. */
|
||||
static Drawable createListBackgroundDrawable(
|
||||
Context context,
|
||||
float topRadius,
|
||||
float bottomRadius) {
|
||||
GradientDrawable backgroundMask = new GradientDrawable();
|
||||
backgroundMask.setColor(context.getColorStateList(R.color.surface));
|
||||
backgroundMask.setShape(GradientDrawable.RECTANGLE);
|
||||
|
||||
backgroundMask.setCornerRadii(
|
||||
new float[]{
|
||||
topRadius,
|
||||
topRadius,
|
||||
topRadius,
|
||||
topRadius,
|
||||
bottomRadius,
|
||||
bottomRadius,
|
||||
bottomRadius,
|
||||
bottomRadius
|
||||
});
|
||||
|
||||
return new RippleDrawable(
|
||||
/* color= */ ColorStateList.valueOf(
|
||||
Themes.getAttrColor(context, android.R.attr.colorControlHighlight)),
|
||||
/* content= */ backgroundMask,
|
||||
/* mask= */ backgroundMask);
|
||||
}
|
||||
|
||||
}
|
|
@ -60,6 +60,9 @@ public final class WidgetsListHeader extends LinearLayout implements ItemInfoUpd
|
|||
@Nullable private Drawable mIconDrawable;
|
||||
private final int mIconSize;
|
||||
private final int mBottomMarginSize;
|
||||
private final float mTopBottomCornerRadius;
|
||||
private final float mMiddleCornerRadius;
|
||||
private final float mJoinedCornerRadius;
|
||||
|
||||
private ImageView mAppIcon;
|
||||
private TextView mTitle;
|
||||
|
@ -87,6 +90,12 @@ public final class WidgetsListHeader extends LinearLayout implements ItemInfoUpd
|
|||
grid.iconSizePx);
|
||||
mBottomMarginSize =
|
||||
getResources().getDimensionPixelSize(R.dimen.widget_list_entry_bottom_margin);
|
||||
mTopBottomCornerRadius =
|
||||
getResources().getDimension(R.dimen.widget_list_top_bottom_corner_radius);
|
||||
mMiddleCornerRadius =
|
||||
getResources().getDimension(R.dimen.widget_list_content_corner_radius);
|
||||
mJoinedCornerRadius =
|
||||
getResources().getDimension(R.dimen.widget_list_content_joined_corner_radius);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -254,6 +263,20 @@ public final class WidgetsListHeader extends LinearLayout implements ItemInfoUpd
|
|||
verifyHighRes();
|
||||
}
|
||||
|
||||
/** Updates the list to have a background drawable with the appropriate corner radii. */
|
||||
@UiThread
|
||||
public void updateListBackground(boolean isFirst, boolean isLast, boolean isExpanded) {
|
||||
float topRadius = isFirst ? mTopBottomCornerRadius : mMiddleCornerRadius;
|
||||
float bottomRadius = isLast
|
||||
? mTopBottomCornerRadius
|
||||
: isExpanded
|
||||
? mJoinedCornerRadius
|
||||
: mMiddleCornerRadius;
|
||||
setBackground(
|
||||
WidgetsListDrawables.createListBackgroundDrawable(
|
||||
getContext(), topRadius, bottomRadius));
|
||||
}
|
||||
|
||||
private void setTitles(WidgetsListSearchHeaderEntry entry) {
|
||||
mTitle.setText(entry.mPkgItem.title);
|
||||
|
||||
|
|
|
@ -52,15 +52,10 @@ public final class WidgetsListHeaderViewHolderBinder implements
|
|||
public void bindViewHolder(WidgetsListHeaderHolder viewHolder, WidgetsListHeaderEntry data,
|
||||
int position) {
|
||||
WidgetsListHeader widgetsListHeader = viewHolder.mWidgetsListHeader;
|
||||
if (mWidgetsListAdapter.getItemCount() == 1) {
|
||||
widgetsListHeader.setBackgroundResource(R.drawable.widgets_list_single_item_ripple);
|
||||
} else if (position == 0) {
|
||||
widgetsListHeader.setBackgroundResource(R.drawable.widgets_list_top_ripple);
|
||||
} else if (position == mWidgetsListAdapter.getItemCount() - 1) {
|
||||
widgetsListHeader.setBackgroundResource(R.drawable.widgets_list_bottom_ripple);
|
||||
} else {
|
||||
widgetsListHeader.setBackgroundResource(R.drawable.widgets_list_middle_ripple);
|
||||
}
|
||||
widgetsListHeader.updateListBackground(
|
||||
/* isFirst= */ position == 0,
|
||||
/* isLast= */ position == mWidgetsListAdapter.getItemCount() - 1,
|
||||
/* isExpanded= */ data.isWidgetListShown());
|
||||
widgetsListHeader.applyFromItemInfoWithIcon(data);
|
||||
widgetsListHeader.setExpanded(data.isWidgetListShown());
|
||||
widgetsListHeader.setOnExpandChangeListener(isExpanded ->
|
||||
|
|
|
@ -53,15 +53,10 @@ public final class WidgetsListSearchHeaderViewHolderBinder implements
|
|||
public void bindViewHolder(WidgetsListSearchHeaderHolder viewHolder,
|
||||
WidgetsListSearchHeaderEntry data, int position) {
|
||||
WidgetsListHeader widgetsListHeader = viewHolder.mWidgetsListHeader;
|
||||
if (mWidgetsListAdapter.getItemCount() == 1) {
|
||||
widgetsListHeader.setBackgroundResource(R.drawable.widgets_list_single_item_ripple);
|
||||
} else if (position == 0) {
|
||||
widgetsListHeader.setBackgroundResource(R.drawable.widgets_list_top_ripple);
|
||||
} else if (position == mWidgetsListAdapter.getItemCount() - 1) {
|
||||
widgetsListHeader.setBackgroundResource(R.drawable.widgets_list_bottom_ripple);
|
||||
} else {
|
||||
widgetsListHeader.setBackgroundResource(R.drawable.widgets_list_middle_ripple);
|
||||
}
|
||||
widgetsListHeader.updateListBackground(
|
||||
/* isFirst= */ position == 0,
|
||||
/* isLast= */ position == mWidgetsListAdapter.getItemCount() - 1,
|
||||
/* isExpanded= */ data.isWidgetListShown());
|
||||
widgetsListHeader.applyFromItemInfoWithIcon(data);
|
||||
widgetsListHeader.setExpanded(data.isWidgetListShown());
|
||||
widgetsListHeader.setOnExpandChangeListener(isExpanded ->
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
package com.android.launcher3.widget.picker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -51,6 +52,9 @@ public final class WidgetsListTableViewHolderBinder
|
|||
private final OnLongClickListener mIconLongClickListener;
|
||||
private final WidgetPreviewLoader mWidgetPreviewLoader;
|
||||
private final WidgetsListAdapter mWidgetsListAdapter;
|
||||
private final float mTopBottomCornerRadius;
|
||||
private final float mMiddleCornerRadius;
|
||||
private final float mJoinedCornerRadius;
|
||||
private boolean mApplyBitmapDeferred = false;
|
||||
|
||||
public WidgetsListTableViewHolderBinder(
|
||||
|
@ -65,6 +69,13 @@ public final class WidgetsListTableViewHolderBinder
|
|||
mIconLongClickListener = iconLongClickListener;
|
||||
mWidgetPreviewLoader = widgetPreviewLoader;
|
||||
mWidgetsListAdapter = listAdapter;
|
||||
Resources resources = context.getResources();
|
||||
mTopBottomCornerRadius =
|
||||
resources.getDimension(R.dimen.widget_list_top_bottom_corner_radius);
|
||||
mMiddleCornerRadius =
|
||||
resources.getDimension(R.dimen.widget_list_content_corner_radius);
|
||||
mJoinedCornerRadius =
|
||||
resources.getDimension(R.dimen.widget_list_content_joined_corner_radius);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,13 +111,14 @@ public final class WidgetsListTableViewHolderBinder
|
|||
entry.mWidgets.size(), table.getChildCount()));
|
||||
}
|
||||
|
||||
if (position == mWidgetsListAdapter.getItemCount() - 1) {
|
||||
table.setBackgroundResource(R.drawable.widgets_list_bottom_ripple);
|
||||
} else {
|
||||
// WidgetsListContentEntry is never shown in position 0. There must be a header above
|
||||
// it.
|
||||
table.setBackgroundResource(R.drawable.widgets_list_middle_ripple);
|
||||
}
|
||||
// The content is always joined to an expanded header above.
|
||||
float topRadius = mJoinedCornerRadius;
|
||||
float bottomRadius = position == mWidgetsListAdapter.getItemCount() - 1
|
||||
? mTopBottomCornerRadius
|
||||
: mMiddleCornerRadius;
|
||||
table.setBackgroundDrawable(
|
||||
WidgetsListDrawables.createListBackgroundDrawable(
|
||||
holder.itemView.getContext(), topRadius, bottomRadius));
|
||||
|
||||
List<ArrayList<WidgetItem>> widgetItemsTable =
|
||||
WidgetsTableUtils.groupWidgetItemsIntoTable(entry.mWidgets, mMaxSpansPerRow);
|
||||
|
|
Loading…
Reference in New Issue