Merge "Update all apps & widget pickers personal / work tabs" into sc-dev

This commit is contained in:
Steven Ng 2021-06-22 10:37:00 +00:00 committed by Android (Google) Code Review
commit cec6edf78e
11 changed files with 56 additions and 135 deletions

View File

@ -1,18 +0,0 @@
<?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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/system_neutral2_100"/>
</selector>

View File

@ -1,18 +0,0 @@
<?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.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#E2E2E2"/>
</selector>

View File

@ -13,13 +13,27 @@
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">
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:enterFadeDuration="500">
<item
android:top="@dimen/all_apps_tabs_vertical_padding"
android:bottom="@dimen/all_apps_tabs_vertical_padding">
android:id="@+id/unselected"
android:state_selected="false">
<ripple android:color="@color/all_apps_tab_background_selected">
<item>
<shape android:shape="rectangle">
<corners android:radius="@dimen/all_apps_header_pill_corner_radius" />
<solid android:color="@color/all_apps_tabs_background" />
</shape>
</item>
</ripple>
</item>
<item
android:id="@+id/selected"
android:state_selected="true">
<shape android:shape="rectangle">
<solid android:color="@color/all_apps_tabs_background" />
<corners android:radius="@dimen/all_apps_header_pill_corner_radius" />
<solid android:color="@color/all_apps_tab_background_selected" />
</shape>
</item>
</layer-list>
</selector>

View File

@ -14,12 +14,12 @@
~ limitations under the License.
-->
<com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip xmlns:android="http://schemas.android.com/apk/res/android"
<com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabs"
android:layout_width="@dimen/all_apps_header_pills_width"
android:layout_width="match_parent"
android:layout_height="@dimen/all_apps_header_pill_height"
android:layout_gravity="center_horizontal"
android:background="@drawable/all_apps_tabs_background"
android:orientation="horizontal"
style="@style/TextHeadline">
@ -27,19 +27,25 @@
android:id="@+id/tab_personal"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="@dimen/all_apps_tabs_button_horizontal_padding"
android:layout_marginVertical="@dimen/all_apps_tabs_vertical_padding"
android:layout_weight="1"
android:background="@drawable/personal_work_tabs_ripple"
android:background="@drawable/all_apps_tabs_background"
android:text="@string/all_apps_personal_tab"
android:textColor="@color/all_apps_tab_text"
android:textSize="14sp" />
android:textSize="14sp"
style="?android:attr/borderlessButtonStyle" />
<Button
android:id="@+id/tab_work"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/all_apps_tabs_button_horizontal_padding"
android:layout_marginVertical="@dimen/all_apps_tabs_vertical_padding"
android:layout_weight="1"
android:background="@drawable/personal_work_tabs_ripple"
android:background="@drawable/all_apps_tabs_background"
android:text="@string/all_apps_work_tab"
android:textColor="@color/all_apps_tab_text"
android:textSize="14sp" />
android:textSize="14sp"
style="?android:attr/borderlessButtonStyle" />
</com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip>

View File

@ -53,7 +53,7 @@
android:id="@+id/recommended_widget_table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginHorizontal="@dimen/widget_list_horizontal_margin"
android:layout_marginTop="8dp"
android:background="@drawable/widgets_recommendation_background"
android:paddingVertical="@dimen/recommended_widgets_table_vertical_padding"

View File

@ -19,7 +19,7 @@
android:id="@+id/widgets_list_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginHorizontal="@dimen/widget_list_horizontal_margin"
android:paddingVertical="@dimen/widget_list_header_view_vertical_padding"
android:orientation="horizontal"
launcher:appIconSize="48dp">

View File

@ -20,28 +20,34 @@
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="@dimen/all_apps_header_pill_height"
android:layout_marginHorizontal="32dp"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:background="@drawable/all_apps_tabs_background"
android:layout_marginHorizontal="@dimen/widget_tabs_horizontal_margin"
style="@style/TextHeadline">
<Button
android:id="@+id/tab_personal"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="@dimen/widget_tabs_button_horizontal_padding"
android:layout_marginVertical="@dimen/widget_apps_tabs_vertical_padding"
android:layout_weight="1"
android:background="@drawable/personal_work_tabs_ripple"
android:background="@drawable/all_apps_tabs_background"
android:text="@string/widgets_full_sheet_personal_tab"
android:textColor="@color/all_apps_tab_text"
android:textSize="14sp" />
android:textSize="14sp"
style="?android:attr/borderlessButtonStyle" />
<Button
android:id="@+id/tab_work"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="@dimen/widget_tabs_button_horizontal_padding"
android:layout_marginVertical="@dimen/widget_apps_tabs_vertical_padding"
android:layout_weight="1"
android:background="@drawable/personal_work_tabs_ripple"
android:background="@drawable/all_apps_tabs_background"
android:text="@string/widgets_full_sheet_work_tab"
android:textColor="@color/all_apps_tab_text"
android:textSize="14sp" />
android:textSize="14sp"
style="?android:attr/borderlessButtonStyle" />
</com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip>

View File

@ -6,7 +6,7 @@
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="24dp"
android:layout_marginHorizontal="16dp"
android:layout_marginHorizontal="@dimen/widget_list_horizontal_margin"
android:background="@drawable/bg_widgets_searchbox">
<com.android.launcher3.ExtendedEditText

View File

@ -18,4 +18,4 @@
android:id="@+id/widgets_table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"/>
android:layout_marginHorizontal="@dimen/widget_list_horizontal_margin" />

View File

@ -93,14 +93,14 @@
<dimen name="all_apps_background_canvas_width">700dp</dimen>
<dimen name="all_apps_background_canvas_height">475dp</dimen>
<dimen name="all_apps_header_pill_height">48dp</dimen>
<dimen name="all_apps_header_pill_corner_radius">18dp</dimen>
<dimen name="all_apps_header_pills_width">348dp</dimen>
<dimen name="all_apps_header_pill_corner_radius">12dp</dimen>
<dimen name="all_apps_header_tab_height">48dp</dimen>
<dimen name="all_apps_tabs_indicator_height">2dp</dimen>
<dimen name="all_apps_header_top_padding">36dp</dimen>
<dimen name="all_apps_header_bottom_padding">6dp</dimen>
<dimen name="all_apps_work_profile_tab_footer_top_padding">16dp</dimen>
<dimen name="all_apps_work_profile_tab_footer_bottom_padding">20dp</dimen>
<dimen name="all_apps_tabs_button_horizontal_padding">4dp</dimen>
<dimen name="all_apps_tabs_vertical_padding">6dp</dimen>
<dimen name="all_apps_divider_height">2dp</dimen>
<dimen name="all_apps_divider_width">128dp</dimen>
@ -136,6 +136,11 @@
<dimen name="widget_cell_horizontal_padding">16dp</dimen>
<dimen name="widget_cell_font_size">14sp</dimen>
<dimen name="widget_tabs_button_horizontal_padding">4dp</dimen>
<dimen name="widget_tabs_horizontal_margin">32dp</dimen>
<dimen name="widget_apps_header_pill_height">48dp</dimen>
<dimen name="widget_apps_tabs_vertical_padding">6dp</dimen>
<dimen name="recommended_widgets_table_vertical_padding">8dp</dimen>
<!-- Bottom margin for the search and recommended widgets container without work profile -->
@ -148,6 +153,7 @@
<dimen name="widget_list_header_view_vertical_padding">20dp</dimen>
<dimen name="widget_list_entry_spacing">2dp</dimen>
<dimen name="widget_list_horizontal_margin">16dp</dimen>
<dimen name="widget_preview_shadow_blur">0.5dp</dimen>
<dimen name="widget_preview_key_shadow_distance">1dp</dimen>

View File

@ -16,118 +16,43 @@
package com.android.launcher3.workprofile;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.pageindicators.PageIndicator;
/**
* Supports two indicator colors, dedicated for personal and work tabs.
*/
public class PersonalWorkSlidingTabStrip extends LinearLayout implements PageIndicator {
private final Paint mSelectedIndicatorPaint;
private int mTabVerticalPadding;
private final int mSelectedIndicatorRadius;
private int mIndicatorLeft = -1;
private int mIndicatorRight = -1;
private float mScrollOffset;
private int mSelectedPosition = 0;
private OnActivePageChangedListener mOnActivePageChangedListener;
private int mLastActivePage = 0;
private boolean mIsRtl;
public PersonalWorkSlidingTabStrip(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
setWillNotDraw(false);
mTabVerticalPadding =
getResources().getDimensionPixelSize(R.dimen.all_apps_tabs_vertical_padding);
mSelectedIndicatorRadius = getResources().getDimensionPixelSize(
R.dimen.all_apps_header_pill_corner_radius);
mSelectedIndicatorPaint = new Paint();
mSelectedIndicatorPaint.setColor(
context.getColor(R.color.all_apps_tab_background_selected));
mIsRtl = Utilities.isRtl(getResources());
}
/**
* Highlights tab with index pos
*/
public void updateTabTextColor(int pos) {
mSelectedPosition = pos;
for (int i = 0; i < getChildCount(); i++) {
Button tab = (Button) getChildAt(i);
tab.setSelected(i == pos);
}
}
private void updateIndicatorPosition(float scrollOffset) {
mScrollOffset = scrollOffset;
updateIndicatorPosition();
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
updateTabTextColor(mSelectedPosition);
updateIndicatorPosition(mScrollOffset);
}
private void updateIndicatorPosition() {
int left = -1, right = -1;
final View leftTab = getLeftTab();
if (leftTab != null) {
left = (int) (leftTab.getLeft() + leftTab.getWidth() * mScrollOffset);
right = left + leftTab.getWidth();
}
setIndicatorPosition(left, right);
}
private View getLeftTab() {
return mIsRtl ? getChildAt(1) : getChildAt(0);
}
private void setIndicatorPosition(int left, int right) {
if (left != mIndicatorLeft || right != mIndicatorRight) {
mIndicatorLeft = left;
mIndicatorRight = right;
invalidate();
}
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawRoundRect(mIndicatorLeft, mTabVerticalPadding, mIndicatorRight,
getHeight() - mTabVerticalPadding, mSelectedIndicatorRadius,
mSelectedIndicatorRadius, mSelectedIndicatorPaint);
}
@Override
public void setScroll(int currentScroll, int totalScroll) {
float scrollOffset = ((float) currentScroll) / totalScroll;
updateIndicatorPosition(scrollOffset);
}
@Override
public void setActiveMarker(int activePage) {
updateTabTextColor(activePage);
updateIndicatorPosition(mIsRtl ? 1 - activePage : activePage);
if (mOnActivePageChangedListener != null && mLastActivePage != activePage) {
mOnActivePageChangedListener.onActivePageChanged(activePage);
}