Merge "Update bottom widget picker and pin widget dialog layout in landscape mode." into sc-dev am: b5459c9ba5
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/14817823 Change-Id: Ide581f63a52c03c9fbf948ff77d12bdb98add096
This commit is contained in:
commit
cbb8df3ec3
8 files changed
+196
-134
No files matched your search
@@ -26,79 +26,82 @@
|
|||||||
android:importantForAccessibility="no">
|
android:importantForAccessibility="no">
|
||||||
|
|
||||||
<com.android.launcher3.widget.AddItemWidgetsBottomSheet
|
<com.android.launcher3.widget.AddItemWidgetsBottomSheet
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:id="@+id/add_item_bottom_sheet"
|
android:id="@+id/add_item_bottom_sheet"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@drawable/add_item_dialog_background"
|
|
||||||
android:paddingTop="24dp"
|
|
||||||
android:theme="?attr/widgetsTheme"
|
android:theme="?attr/widgetsTheme"
|
||||||
android:layout_gravity="bottom"
|
android:layout_gravity="bottom"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
|
||||||
style="@style/TextHeadline"
|
|
||||||
android:id="@+id/widget_appName"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:paddingHorizontal="24dp"
|
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
|
||||||
android:textSize="24sp"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:fadingEdge="horizontal"
|
|
||||||
android:singleLine="true"
|
|
||||||
android:maxLines="1" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:paddingHorizontal="24dp"
|
|
||||||
android:paddingTop="8dp"
|
|
||||||
android:text="@string/add_item_request_drag_hint"
|
|
||||||
android:textSize="14sp"
|
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
|
||||||
android:alpha="0.7"
|
|
||||||
android:importantForAccessibility="no"/>
|
|
||||||
|
|
||||||
<include layout="@layout/widget_cell"
|
|
||||||
android:id="@+id/widget_cell"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_marginVertical="16dp" />
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/add_item_bottom_sheet_content"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center_vertical|end"
|
android:padding="24dp"
|
||||||
android:paddingHorizontal="24dp"
|
android:background="@drawable/add_item_dialog_background"
|
||||||
android:paddingVertical="8dp"
|
android:orientation="vertical" >
|
||||||
android:orientation="horizontal">
|
|
||||||
<Button
|
|
||||||
style="@style/Button.FullRounded.Colored"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="36dp"
|
|
||||||
android:paddingHorizontal="16dp"
|
|
||||||
android:textSize="14sp"
|
|
||||||
android:textColor="@color/button_text"
|
|
||||||
android:text="@android:string/cancel"
|
|
||||||
android:onClick="onCancelClick"/>
|
|
||||||
|
|
||||||
<Space
|
<TextView
|
||||||
android:layout_width="8dp"
|
style="@style/TextHeadline"
|
||||||
android:layout_height="wrap_content" />
|
android:id="@+id/widget_appName"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:textSize="24sp"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:fadingEdge="horizontal"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:maxLines="1" />
|
||||||
|
|
||||||
<Button
|
<TextView
|
||||||
style="@style/Button.FullRounded.Colored"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_height="36dp"
|
android:gravity="center_horizontal"
|
||||||
android:paddingHorizontal="16dp"
|
android:paddingTop="8dp"
|
||||||
|
android:text="@string/add_item_request_drag_hint"
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
android:textColor="@color/button_text"
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
android:text="@string/add_to_home_screen"
|
android:alpha="0.7"
|
||||||
android:onClick="onPlaceAutomaticallyClick"/>
|
android:importantForAccessibility="no"/>
|
||||||
|
|
||||||
|
<include layout="@layout/widget_cell"
|
||||||
|
android:id="@+id/widget_cell"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_marginVertical="16dp" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_vertical|end"
|
||||||
|
android:paddingVertical="8dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
<Button
|
||||||
|
style="@style/Button.FullRounded.Colored"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="36dp"
|
||||||
|
android:paddingHorizontal="16dp"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:textColor="@color/button_text"
|
||||||
|
android:text="@android:string/cancel"
|
||||||
|
android:onClick="onCancelClick"/>
|
||||||
|
|
||||||
|
<Space
|
||||||
|
android:layout_width="8dp"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
style="@style/Button.FullRounded.Colored"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="36dp"
|
||||||
|
android:paddingHorizontal="16dp"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:textColor="@color/button_text"
|
||||||
|
android:text="@string/add_to_home_screen"
|
||||||
|
android:onClick="onPlaceAutomaticallyClick"/>
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</com.android.launcher3.widget.AddItemWidgetsBottomSheet>
|
</com.android.launcher3.widget.AddItemWidgetsBottomSheet>
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,6 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingTop="16dp"
|
|
||||||
android:background="@drawable/widgets_bottom_sheet_background"
|
|
||||||
android:layout_gravity="bottom"
|
android:layout_gravity="bottom"
|
||||||
android:theme="?attr/widgetsTheme">
|
android:theme="?attr/widgetsTheme">
|
||||||
|
|
||||||
|
|||||||
@@ -14,32 +14,40 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
<merge xmlns:android="http://schemas.android.com/apk/res/android">
|
<merge xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<View
|
<LinearLayout
|
||||||
android:id="@+id/collapse_handle"
|
android:id="@+id/widgets_bottom_sheet"
|
||||||
android:layout_width="48dp"
|
|
||||||
android:layout_height="2dp"
|
|
||||||
android:layout_gravity="center_horizontal"
|
|
||||||
android:layout_marginBottom="16dp"
|
|
||||||
android:visibility="gone"
|
|
||||||
android:background="?android:attr/textColorSecondary"/>
|
|
||||||
<TextView
|
|
||||||
style="@style/TextHeadline"
|
|
||||||
android:id="@+id/title"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center_horizontal"
|
android:background="@drawable/widgets_bottom_sheet_background"
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
android:paddingTop="16dp"
|
||||||
android:textSize="24sp"/>
|
android:orientation="vertical">
|
||||||
|
<View
|
||||||
<ScrollView
|
android:id="@+id/collapse_handle"
|
||||||
android:id="@+id/widgets_table_scroll_view"
|
android:layout_width="48dp"
|
||||||
android:layout_width="match_parent"
|
android:layout_height="2dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_gravity="center_horizontal"
|
||||||
android:fadeScrollbars="false"
|
android:layout_marginBottom="16dp"
|
||||||
android:layout_marginVertical="16dp">
|
android:visibility="gone"
|
||||||
<include layout="@layout/widgets_table_container"
|
android:background="?android:attr/textColorSecondary"/>
|
||||||
|
<TextView
|
||||||
|
style="@style/TextHeadline"
|
||||||
|
android:id="@+id/title"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_horizontal" />
|
android:gravity="center_horizontal"
|
||||||
</ScrollView>
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:textSize="24sp"/>
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:id="@+id/widgets_table_scroll_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:fadeScrollbars="false"
|
||||||
|
android:layout_marginVertical="16dp">
|
||||||
|
<include layout="@layout/widgets_table_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal" />
|
||||||
|
</ScrollView>
|
||||||
|
</LinearLayout>
|
||||||
</merge>
|
</merge>
|
||||||
@@ -20,5 +20,6 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<style name="AddItemActivityTheme" parent="@android:style/Theme.Translucent.NoTitleBar">
|
<style name="AddItemActivityTheme" parent="@android:style/Theme.Translucent.NoTitleBar">
|
||||||
<item name="widgetsTheme">@style/WidgetContainerTheme.Dark</item>
|
<item name="widgetsTheme">@style/WidgetContainerTheme.Dark</item>
|
||||||
|
<item name="android:windowTranslucentStatus">true</item>
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -316,5 +316,6 @@
|
|||||||
<style name="AddItemActivityTheme" parent="@android:style/Theme.Translucent.NoTitleBar">
|
<style name="AddItemActivityTheme" parent="@android:style/Theme.Translucent.NoTitleBar">
|
||||||
<item name="widgetsTheme">@style/WidgetContainerTheme</item>
|
<item name="widgetsTheme">@style/WidgetContainerTheme</item>
|
||||||
<item name="android:windowLightStatusBar">true</item>
|
<item name="android:windowLightStatusBar">true</item>
|
||||||
|
<item name="android:windowTranslucentStatus">true</item>
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -125,7 +125,6 @@ public class AddItemActivity extends BaseActivity
|
|||||||
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
|
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
|
||||||
mDragLayer = findViewById(R.id.add_item_drag_layer);
|
mDragLayer = findViewById(R.id.add_item_drag_layer);
|
||||||
mDragLayer.recreateControllers();
|
mDragLayer.recreateControllers();
|
||||||
mDragLayer.setInsets(mDeviceProfile.getInsets());
|
|
||||||
mWidgetCell = findViewById(R.id.widget_cell);
|
mWidgetCell = findViewById(R.id.widget_cell);
|
||||||
|
|
||||||
if (mRequest.getRequestType() == PinItemRequest.REQUEST_TYPE_SHORTCUT) {
|
if (mRequest.getRequestType() == PinItemRequest.REQUEST_TYPE_SHORTCUT) {
|
||||||
@@ -322,7 +321,7 @@ public class AddItemActivity extends BaseActivity
|
|||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
logCommand(LAUNCHER_ADD_EXTERNAL_ITEM_BACK);
|
logCommand(LAUNCHER_ADD_EXTERNAL_ITEM_BACK);
|
||||||
super.onBackPressed();
|
mSlideInView.close(/* animate= */ true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,17 +16,21 @@
|
|||||||
|
|
||||||
package com.android.launcher3.widget;
|
package com.android.launcher3.widget;
|
||||||
|
|
||||||
|
import static com.android.launcher3.Utilities.ATLEAST_R;
|
||||||
import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN;
|
import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN;
|
||||||
|
|
||||||
import android.animation.PropertyValuesHolder;
|
import android.animation.PropertyValuesHolder;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
import android.graphics.Insets;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewParent;
|
import android.view.ViewParent;
|
||||||
|
import android.view.WindowInsets;
|
||||||
|
|
||||||
import com.android.launcher3.Insettable;
|
import com.android.launcher3.DeviceProfile;
|
||||||
import com.android.launcher3.R;
|
import com.android.launcher3.R;
|
||||||
import com.android.launcher3.dragndrop.AddItemActivity;
|
import com.android.launcher3.dragndrop.AddItemActivity;
|
||||||
import com.android.launcher3.views.AbstractSlideInView;
|
import com.android.launcher3.views.AbstractSlideInView;
|
||||||
@@ -34,13 +38,12 @@ import com.android.launcher3.views.AbstractSlideInView;
|
|||||||
/**
|
/**
|
||||||
* Bottom sheet for the pin widget.
|
* Bottom sheet for the pin widget.
|
||||||
*/
|
*/
|
||||||
public class AddItemWidgetsBottomSheet extends AbstractSlideInView<AddItemActivity>
|
public class AddItemWidgetsBottomSheet extends AbstractSlideInView<AddItemActivity> implements
|
||||||
implements Insettable {
|
View.OnApplyWindowInsetsListener {
|
||||||
|
|
||||||
private static final int DEFAULT_CLOSE_DURATION = 200;
|
private static final int DEFAULT_CLOSE_DURATION = 200;
|
||||||
|
|
||||||
private Rect mInsets;
|
private final Rect mInsets;
|
||||||
private Configuration mCurrentConfiguration;
|
|
||||||
|
|
||||||
public AddItemWidgetsBottomSheet(Context context, AttributeSet attrs) {
|
public AddItemWidgetsBottomSheet(Context context, AttributeSet attrs) {
|
||||||
this(context, attrs, 0);
|
this(context, attrs, 0);
|
||||||
@@ -48,9 +51,7 @@ public class AddItemWidgetsBottomSheet extends AbstractSlideInView<AddItemActivi
|
|||||||
|
|
||||||
public AddItemWidgetsBottomSheet(Context context, AttributeSet attrs, int defStyleAttr) {
|
public AddItemWidgetsBottomSheet(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
mContent = this;
|
|
||||||
mInsets = new Rect();
|
mInsets = new Rect();
|
||||||
mCurrentConfiguration = new Configuration(getResources().getConfiguration());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,15 +63,49 @@ public class AddItemWidgetsBottomSheet extends AbstractSlideInView<AddItemActivi
|
|||||||
((ViewGroup) parent).removeView(this);
|
((ViewGroup) parent).removeView(this);
|
||||||
}
|
}
|
||||||
attachToContainer();
|
attachToContainer();
|
||||||
|
setOnApplyWindowInsetsListener(this);
|
||||||
animateOpen();
|
animateOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||||
super.onLayout(changed, l, t, r, b);
|
int width = r - l;
|
||||||
|
int height = b - t;
|
||||||
|
|
||||||
|
// Lay out content as center bottom aligned.
|
||||||
|
int contentWidth = mContent.getMeasuredWidth();
|
||||||
|
int contentLeft = (width - contentWidth - mInsets.left - mInsets.right) / 2 + mInsets.left;
|
||||||
|
mContent.layout(contentLeft, height - mContent.getMeasuredHeight(),
|
||||||
|
contentLeft + contentWidth, height);
|
||||||
|
|
||||||
setTranslationShift(mTranslationShift);
|
setTranslationShift(mTranslationShift);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
|
||||||
|
int widthUsed;
|
||||||
|
if (mInsets.bottom > 0) {
|
||||||
|
widthUsed = mInsets.left + mInsets.right;
|
||||||
|
} else {
|
||||||
|
Rect padding = deviceProfile.workspacePadding;
|
||||||
|
widthUsed = Math.max(padding.left + padding.right,
|
||||||
|
2 * (mInsets.left + mInsets.right));
|
||||||
|
}
|
||||||
|
|
||||||
|
int heightUsed = mInsets.top + deviceProfile.edgeMarginPx;
|
||||||
|
measureChildWithMargins(mContent, widthMeasureSpec,
|
||||||
|
widthUsed, heightMeasureSpec, heightUsed);
|
||||||
|
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
|
||||||
|
MeasureSpec.getSize(heightMeasureSpec));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onFinishInflate() {
|
||||||
|
super.onFinishInflate();
|
||||||
|
mContent = findViewById(R.id.add_item_bottom_sheet_content);
|
||||||
|
}
|
||||||
|
|
||||||
private void animateOpen() {
|
private void animateOpen() {
|
||||||
if (mIsOpen || mOpenCloseAnimator.isRunning()) {
|
if (mIsOpen || mOpenCloseAnimator.isRunning()) {
|
||||||
return;
|
return;
|
||||||
@@ -92,26 +127,25 @@ public class AddItemWidgetsBottomSheet extends AbstractSlideInView<AddItemActivi
|
|||||||
return (type & TYPE_PIN_WIDGET_FROM_EXTERNAL_POPUP) != 0;
|
return (type & TYPE_PIN_WIDGET_FROM_EXTERNAL_POPUP) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setInsets(Rect insets) {
|
|
||||||
// Extend behind left, right, and bottom insets.
|
|
||||||
int leftInset = insets.left - mInsets.left;
|
|
||||||
int rightInset = insets.right - mInsets.right;
|
|
||||||
int bottomInset = insets.bottom - mInsets.bottom;
|
|
||||||
mInsets.set(insets);
|
|
||||||
setPadding(leftInset, getPaddingTop(), rightInset, bottomInset);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onConfigurationChanged(Configuration newConfig) {
|
|
||||||
if (mCurrentConfiguration.orientation != newConfig.orientation) {
|
|
||||||
mInsets.setEmpty();
|
|
||||||
}
|
|
||||||
mCurrentConfiguration.updateFrom(newConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getScrimColor(Context context) {
|
protected int getScrimColor(Context context) {
|
||||||
return context.getResources().getColor(R.color.widgets_picker_scrim);
|
return context.getResources().getColor(R.color.widgets_picker_scrim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("NewApi") // Already added API check.
|
||||||
|
@Override
|
||||||
|
public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
|
||||||
|
if (ATLEAST_R) {
|
||||||
|
Insets insets = windowInsets.getInsets(WindowInsets.Type.systemBars());
|
||||||
|
mInsets.set(insets.left, insets.top, insets.right, insets.bottom);
|
||||||
|
} else {
|
||||||
|
mInsets.set(windowInsets.getSystemWindowInsetLeft(),
|
||||||
|
windowInsets.getSystemWindowInsetTop(),
|
||||||
|
windowInsets.getSystemWindowInsetRight(),
|
||||||
|
windowInsets.getSystemWindowInsetBottom());
|
||||||
|
}
|
||||||
|
mContent.setPadding(mContent.getPaddingStart(),
|
||||||
|
mContent.getPaddingTop(), mContent.getPaddingEnd(), mInsets.bottom);
|
||||||
|
return windowInsets;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,6 @@ import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN;
|
|||||||
|
|
||||||
import android.animation.PropertyValuesHolder;
|
import android.animation.PropertyValuesHolder;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.IntProperty;
|
import android.util.IntProperty;
|
||||||
@@ -71,10 +70,9 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable {
|
|||||||
private static final long EDUCATION_TIP_DELAY_MS = 300;
|
private static final long EDUCATION_TIP_DELAY_MS = 300;
|
||||||
|
|
||||||
private ItemInfo mOriginalItemInfo;
|
private ItemInfo mOriginalItemInfo;
|
||||||
private Rect mInsets;
|
private final Rect mInsets;
|
||||||
private final int mMaxTableHeight;
|
private final int mMaxTableHeight;
|
||||||
private int mMaxHorizontalSpan = 4;
|
private int mMaxHorizontalSpan = 4;
|
||||||
private Configuration mCurrentConfiguration;
|
|
||||||
|
|
||||||
private final OnLayoutChangeListener mLayoutChangeListenerToShowTips =
|
private final OnLayoutChangeListener mLayoutChangeListenerToShowTips =
|
||||||
new OnLayoutChangeListener() {
|
new OnLayoutChangeListener() {
|
||||||
@@ -113,20 +111,38 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable {
|
|||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
setWillNotDraw(false);
|
setWillNotDraw(false);
|
||||||
mInsets = new Rect();
|
mInsets = new Rect();
|
||||||
mContent = this;
|
|
||||||
DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
|
DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
|
||||||
// Set the max table height to 2 / 3 of the grid height so that the bottom picker won't
|
// Set the max table height to 2 / 3 of the grid height so that the bottom picker won't
|
||||||
// take over the entire view vertically.
|
// take over the entire view vertically.
|
||||||
mMaxTableHeight = deviceProfile.inv.numRows * 2 / 3 * deviceProfile.cellHeightPx;
|
mMaxTableHeight = deviceProfile.inv.numRows * 2 / 3 * deviceProfile.cellHeightPx;
|
||||||
mCurrentConfiguration = new Configuration(getResources().getConfiguration());
|
|
||||||
if (!hasSeenEducationTip()) {
|
if (!hasSeenEducationTip()) {
|
||||||
addOnLayoutChangeListener(mLayoutChangeListenerToShowTips);
|
addOnLayoutChangeListener(mLayoutChangeListenerToShowTips);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onFinishInflate() {
|
||||||
|
super.onFinishInflate();
|
||||||
|
mContent = findViewById(R.id.widgets_bottom_sheet);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
|
||||||
|
int widthUsed;
|
||||||
|
if (mInsets.bottom > 0) {
|
||||||
|
widthUsed = mInsets.left + mInsets.right;
|
||||||
|
} else {
|
||||||
|
Rect padding = deviceProfile.workspacePadding;
|
||||||
|
widthUsed = Math.max(padding.left + padding.right,
|
||||||
|
2 * (mInsets.left + mInsets.right));
|
||||||
|
}
|
||||||
|
|
||||||
|
int heightUsed = mInsets.top + deviceProfile.edgeMarginPx;
|
||||||
|
measureChildWithMargins(mContent, widthMeasureSpec,
|
||||||
|
widthUsed, heightMeasureSpec, heightUsed);
|
||||||
|
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
|
||||||
|
MeasureSpec.getSize(heightMeasureSpec));
|
||||||
|
|
||||||
int paddingPx = 2 * getResources().getDimensionPixelOffset(
|
int paddingPx = 2 * getResources().getDimensionPixelOffset(
|
||||||
R.dimen.widget_cell_horizontal_padding);
|
R.dimen.widget_cell_horizontal_padding);
|
||||||
@@ -142,7 +158,15 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||||
super.onLayout(changed, l, t, r, b);
|
int width = r - l;
|
||||||
|
int height = b - t;
|
||||||
|
|
||||||
|
// Content is laid out as center bottom aligned.
|
||||||
|
int contentWidth = mContent.getMeasuredWidth();
|
||||||
|
int contentLeft = (width - contentWidth - mInsets.left - mInsets.right) / 2 + mInsets.left;
|
||||||
|
mContent.layout(contentLeft, height - mContent.getMeasuredHeight(),
|
||||||
|
contentLeft + contentWidth, height);
|
||||||
|
|
||||||
setTranslationShift(mTranslationShift);
|
setTranslationShift(mTranslationShift);
|
||||||
|
|
||||||
// Ensure the scroll view height is not larger than mMaxTableHeight, which is a value
|
// Ensure the scroll view height is not larger than mMaxTableHeight, which is a value
|
||||||
@@ -241,20 +265,14 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInsets(Rect insets) {
|
public void setInsets(Rect insets) {
|
||||||
// Extend behind left, right, and bottom insets.
|
|
||||||
int leftInset = insets.left - mInsets.left;
|
|
||||||
int rightInset = insets.right - mInsets.right;
|
|
||||||
int bottomInset = insets.bottom - mInsets.bottom;
|
|
||||||
mInsets.set(insets);
|
mInsets.set(insets);
|
||||||
setPadding(leftInset, getPaddingTop(), rightInset, bottomInset);
|
mContent.setPadding(mContent.getPaddingStart(),
|
||||||
}
|
mContent.getPaddingTop(), mContent.getPaddingEnd(), insets.bottom);
|
||||||
|
if (insets.bottom > 0) {
|
||||||
@Override
|
setupNavBarColor();
|
||||||
protected void onConfigurationChanged(Configuration newConfig) {
|
} else {
|
||||||
if (mCurrentConfiguration.orientation != newConfig.orientation) {
|
clearNavBarColor();
|
||||||
mInsets.setEmpty();
|
|
||||||
}
|
}
|
||||||
mCurrentConfiguration.updateFrom(newConfig);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in new issue
Block a user