Extract common measurement in widgets pickers to its base class

Bug: 191644950
Test: 1. Open the full widget picker. Observe the clock widgets'
         previews are shown properly. Then, rotate the screen and
         observe the clock widgets' previews are shown properly.
      2. Open the bottom widgets picker for clock. Observe the
         clock widgets' previews are shown properly. Then, rotate
         the screen and observe the clock widgets' previews are shown
         properly.
      3. Repeat 1, 2 after changing the system navigation from button
         to gesture.
Change-Id: I564fc2ce0baf3103ae77499380ad69ec38ac6930
This commit is contained in:
Steven Ng
2021-06-28 12:29:35 +01:00
parent bf60673bbb
commit fbe1836627
3 changed files with 45 additions and 70 deletions

View File

@@ -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;
@@ -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;
@@ -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();