Loading src/com/android/launcher3/widget/BaseWidgetSheet.java +34 −1 Original line number Diff line number Diff line Loading @@ -24,11 +24,14 @@ import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; import android.widget.Toast; import androidx.annotation.GuardedBy; import androidx.annotation.Nullable; import androidx.core.view.ViewCompat; import com.android.launcher3.DeviceProfile; import com.android.launcher3.DragSource; import com.android.launcher3.DropTarget.DragObject; import com.android.launcher3.Insettable; import com.android.launcher3.Launcher; import com.android.launcher3.R; import com.android.launcher3.Utilities; Loading @@ -47,10 +50,11 @@ import com.android.launcher3.views.ArrowTipView; */ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher> implements OnClickListener, OnLongClickListener, DragSource, PopupDataProvider.PopupDataChangeListener { PopupDataProvider.PopupDataChangeListener, Insettable { protected static final String KEY_WIDGETS_EDUCATION_TIP_SEEN = "launcher.widgets_education_tip_seen"; protected final Rect mInsets = new Rect(); /* Touch handling related member variables. */ private Toast mWidgetInstructionToast; Loading Loading @@ -105,6 +109,35 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher> return true; } @Override public void setInsets(Rect insets) { mInsets.set(insets); } /** * Measures the dimension of this view and its children by taking system insets, navigation bar, * status bar, into account. */ @GuardedBy("MainThread") protected void doMeasure(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)); } private boolean beginDraggingWidget(WidgetCell v) { // Get the widget preview as the drag representation WidgetImageView image = v.getWidgetView(); Loading src/com/android/launcher3/widget/WidgetsBottomSheet.java +9 −47 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ import android.content.Context; import android.graphics.Rect; import android.util.AttributeSet; import android.util.IntProperty; import android.util.Log; import android.util.Pair; import android.view.Gravity; import android.view.LayoutInflater; Loading @@ -36,10 +35,7 @@ import android.widget.TableLayout; import android.widget.TableRow; import android.widget.TextView; import androidx.annotation.GuardedBy; import com.android.launcher3.DeviceProfile; import com.android.launcher3.Insettable; import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; import com.android.launcher3.anim.PendingAnimation; Loading @@ -53,7 +49,7 @@ import java.util.List; /** * Bottom sheet for the "Widgets" system shortcut in the long-press popup. */ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable { public class WidgetsBottomSheet extends BaseWidgetSheet { private static final String TAG = "WidgetsBottomSheet"; private static final IntProperty<View> PADDING_BOTTOM = Loading @@ -74,7 +70,6 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable { private static final long EDUCATION_TIP_DELAY_MS = 300; private ItemInfo mOriginalItemInfo; private final Rect mInsets; private final int mMaxTableHeight; private int mMaxHorizontalSpan = 4; Loading Loading @@ -114,7 +109,6 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable { public WidgetsBottomSheet(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setWillNotDraw(false); mInsets = new Rect(); DeviceProfile deviceProfile = mActivityContext.getDeviceProfile(); // 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. Loading @@ -132,53 +126,20 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (doMeasure(widthMeasureSpec, heightMeasureSpec)) { boolean hasUpdated = doMeasure(widthMeasureSpec, heightMeasureSpec); if (hasUpdated) { Log.w(TAG, "WidgetsBottomSheet dimension has been updated after a 2nd" + " measurement."); } } doMeasure(widthMeasureSpec, heightMeasureSpec); if (updateMaxSpansPerRow()) { doMeasure(widthMeasureSpec, heightMeasureSpec); } /** * Measures the dimension of this view and its children. * * <p>This function takes account of the following during measurement: * <ol> * <li>status bar and system navigation bar insets</li> * <li> * number of spans that can fit in a row. This affects the number of widgets that can * fit in a row. * </li> * </ol> * * @return {@code true} if the width or height of this view or its children have changed after * the measurement. Otherwise, returns {@code false}. */ @GuardedBy("MainThread") private boolean doMeasure(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)); /** Returns {@code true} if the max spans have been updated. */ private boolean updateMaxSpansPerRow() { if (getMeasuredWidth() == 0) return false; int paddingPx = 2 * getResources().getDimensionPixelOffset( R.dimen.widget_cell_horizontal_padding); int maxHorizontalSpan = findViewById(R.id.widgets_table).getMeasuredWidth() / (mActivityContext.getDeviceProfile().cellWidthPx + paddingPx); if (mMaxHorizontalSpan != maxHorizontalSpan) { // Ensure the table layout is showing widgets in the right column after measure. mMaxHorizontalSpan = maxHorizontalSpan; Loading Loading @@ -297,7 +258,8 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable { @Override public void setInsets(Rect insets) { mInsets.set(insets); super.setInsets(insets); mContent.setPadding(mContent.getPaddingStart(), mContent.getPaddingTop(), mContent.getPaddingEnd(), insets.bottom); if (insets.bottom > 0) { Loading src/com/android/launcher3/widget/picker/WidgetsFullSheet.java +2 −22 Original line number Diff line number Diff line Loading @@ -45,8 +45,6 @@ import androidx.annotation.VisibleForTesting; import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.RecyclerView; import com.android.launcher3.DeviceProfile; import com.android.launcher3.Insettable; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; Loading Loading @@ -76,7 +74,7 @@ import java.util.stream.IntStream; * Popup for showing the full list of available widgets */ public class WidgetsFullSheet extends BaseWidgetSheet implements Insettable, ProviderChangedListener, OnActivePageChangedListener, implements ProviderChangedListener, OnActivePageChangedListener, WidgetsRecyclerView.HeaderViewDimensionsProvider, SearchModeListener { private static final String TAG = WidgetsFullSheet.class.getSimpleName(); Loading Loading @@ -309,7 +307,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet @Override public void setInsets(Rect insets) { mInsets.set(insets); super.setInsets(insets); setBottomPadding(mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView, insets.bottom); setBottomPadding(mAdapters.get(AdapterHolder.SEARCH).mWidgetsRecyclerView, insets.bottom); Loading Loading @@ -351,24 +349,6 @@ public class WidgetsFullSheet extends BaseWidgetSheet } } private void doMeasure(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)); } /** Returns {@code true} if the max spans have been updated. */ private boolean updateMaxSpansPerRow() { if (getMeasuredWidth() == 0) return false; Loading Loading
src/com/android/launcher3/widget/BaseWidgetSheet.java +34 −1 Original line number Diff line number Diff line Loading @@ -24,11 +24,14 @@ import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; import android.widget.Toast; import androidx.annotation.GuardedBy; import androidx.annotation.Nullable; import androidx.core.view.ViewCompat; import com.android.launcher3.DeviceProfile; import com.android.launcher3.DragSource; import com.android.launcher3.DropTarget.DragObject; import com.android.launcher3.Insettable; import com.android.launcher3.Launcher; import com.android.launcher3.R; import com.android.launcher3.Utilities; Loading @@ -47,10 +50,11 @@ import com.android.launcher3.views.ArrowTipView; */ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher> implements OnClickListener, OnLongClickListener, DragSource, PopupDataProvider.PopupDataChangeListener { PopupDataProvider.PopupDataChangeListener, Insettable { protected static final String KEY_WIDGETS_EDUCATION_TIP_SEEN = "launcher.widgets_education_tip_seen"; protected final Rect mInsets = new Rect(); /* Touch handling related member variables. */ private Toast mWidgetInstructionToast; Loading Loading @@ -105,6 +109,35 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<Launcher> return true; } @Override public void setInsets(Rect insets) { mInsets.set(insets); } /** * Measures the dimension of this view and its children by taking system insets, navigation bar, * status bar, into account. */ @GuardedBy("MainThread") protected void doMeasure(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)); } private boolean beginDraggingWidget(WidgetCell v) { // Get the widget preview as the drag representation WidgetImageView image = v.getWidgetView(); Loading
src/com/android/launcher3/widget/WidgetsBottomSheet.java +9 −47 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ import android.content.Context; import android.graphics.Rect; import android.util.AttributeSet; import android.util.IntProperty; import android.util.Log; import android.util.Pair; import android.view.Gravity; import android.view.LayoutInflater; Loading @@ -36,10 +35,7 @@ import android.widget.TableLayout; import android.widget.TableRow; import android.widget.TextView; import androidx.annotation.GuardedBy; import com.android.launcher3.DeviceProfile; import com.android.launcher3.Insettable; import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; import com.android.launcher3.anim.PendingAnimation; Loading @@ -53,7 +49,7 @@ import java.util.List; /** * Bottom sheet for the "Widgets" system shortcut in the long-press popup. */ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable { public class WidgetsBottomSheet extends BaseWidgetSheet { private static final String TAG = "WidgetsBottomSheet"; private static final IntProperty<View> PADDING_BOTTOM = Loading @@ -74,7 +70,6 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable { private static final long EDUCATION_TIP_DELAY_MS = 300; private ItemInfo mOriginalItemInfo; private final Rect mInsets; private final int mMaxTableHeight; private int mMaxHorizontalSpan = 4; Loading Loading @@ -114,7 +109,6 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable { public WidgetsBottomSheet(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setWillNotDraw(false); mInsets = new Rect(); DeviceProfile deviceProfile = mActivityContext.getDeviceProfile(); // 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. Loading @@ -132,53 +126,20 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (doMeasure(widthMeasureSpec, heightMeasureSpec)) { boolean hasUpdated = doMeasure(widthMeasureSpec, heightMeasureSpec); if (hasUpdated) { Log.w(TAG, "WidgetsBottomSheet dimension has been updated after a 2nd" + " measurement."); } } doMeasure(widthMeasureSpec, heightMeasureSpec); if (updateMaxSpansPerRow()) { doMeasure(widthMeasureSpec, heightMeasureSpec); } /** * Measures the dimension of this view and its children. * * <p>This function takes account of the following during measurement: * <ol> * <li>status bar and system navigation bar insets</li> * <li> * number of spans that can fit in a row. This affects the number of widgets that can * fit in a row. * </li> * </ol> * * @return {@code true} if the width or height of this view or its children have changed after * the measurement. Otherwise, returns {@code false}. */ @GuardedBy("MainThread") private boolean doMeasure(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)); /** Returns {@code true} if the max spans have been updated. */ private boolean updateMaxSpansPerRow() { if (getMeasuredWidth() == 0) return false; int paddingPx = 2 * getResources().getDimensionPixelOffset( R.dimen.widget_cell_horizontal_padding); int maxHorizontalSpan = findViewById(R.id.widgets_table).getMeasuredWidth() / (mActivityContext.getDeviceProfile().cellWidthPx + paddingPx); if (mMaxHorizontalSpan != maxHorizontalSpan) { // Ensure the table layout is showing widgets in the right column after measure. mMaxHorizontalSpan = maxHorizontalSpan; Loading Loading @@ -297,7 +258,8 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable { @Override public void setInsets(Rect insets) { mInsets.set(insets); super.setInsets(insets); mContent.setPadding(mContent.getPaddingStart(), mContent.getPaddingTop(), mContent.getPaddingEnd(), insets.bottom); if (insets.bottom > 0) { Loading
src/com/android/launcher3/widget/picker/WidgetsFullSheet.java +2 −22 Original line number Diff line number Diff line Loading @@ -45,8 +45,6 @@ import androidx.annotation.VisibleForTesting; import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.RecyclerView; import com.android.launcher3.DeviceProfile; import com.android.launcher3.Insettable; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; Loading Loading @@ -76,7 +74,7 @@ import java.util.stream.IntStream; * Popup for showing the full list of available widgets */ public class WidgetsFullSheet extends BaseWidgetSheet implements Insettable, ProviderChangedListener, OnActivePageChangedListener, implements ProviderChangedListener, OnActivePageChangedListener, WidgetsRecyclerView.HeaderViewDimensionsProvider, SearchModeListener { private static final String TAG = WidgetsFullSheet.class.getSimpleName(); Loading Loading @@ -309,7 +307,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet @Override public void setInsets(Rect insets) { mInsets.set(insets); super.setInsets(insets); setBottomPadding(mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView, insets.bottom); setBottomPadding(mAdapters.get(AdapterHolder.SEARCH).mWidgetsRecyclerView, insets.bottom); Loading Loading @@ -351,24 +349,6 @@ public class WidgetsFullSheet extends BaseWidgetSheet } } private void doMeasure(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)); } /** Returns {@code true} if the max spans have been updated. */ private boolean updateMaxSpansPerRow() { if (getMeasuredWidth() == 0) return false; Loading