Add a button for reconfiguring widgets.

Test: manual
Bug: 183316993
Change-Id: I17bec121e3d07d65979c2b92c285e487a7d64d65
This commit is contained in:
Yogisha Dixit
2021-03-21 20:10:06 +00:00
parent 59230c3cdd
commit 73c8a366a8
6 changed files with 89 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M20.41,4.94l-1.35,-1.35c-0.78,-0.78 -2.05,-0.78 -2.83,0L3,16.82L3,21h4.18L20.41,7.77c0.79,-0.78 0.79,-2.05 0,-2.83zM6.41,19.06L5,19v-1.36l9.82,-9.82 1.41,1.41 -9.82,9.83z"/>
</vector>

View File

@@ -0,0 +1,32 @@
<?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.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="@dimen/widget_reconfigure_button_size"
android:height="@dimen/widget_reconfigure_button_size">
<shape
android:shape="rectangle">
<solid android:color="?android:attr/colorAccent" />
<corners android:radius="@dimen/widget_reconfigure_button_corner_radius" />
</shape>
</item>
<item
android:gravity="center"
android:padding="@dimen/widget_reconfigure_button_padding"
android:drawable="@drawable/gm_edit_24"
android:color="?android:attr/colorPrimary" />
</layer-list>

View File

@@ -73,5 +73,17 @@
android:src="@drawable/ic_widget_resize_handle"
android:tint="?android:attr/colorAccent" />
<ImageButton
android:id="@+id/widget_reconfigure_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/widget_reconfigure_button_padding"
android:layout_gravity="bottom|end"
android:layout_marginBottom="@dimen/widget_reconfigure_button_margin"
android:layout_marginEnd="@dimen/widget_reconfigure_button_margin"
android:src="@drawable/widget_reconfigure_button_frame"
android:background="?android:attr/selectableItemBackground"
android:visibility="gone" />
</FrameLayout>
</com.android.launcher3.AppWidgetResizeFrame>

View File

@@ -56,6 +56,12 @@
<dimen name="resize_frame_background_padding">24dp</dimen>
<dimen name="resize_frame_margin">22dp</dimen>
<!-- App widget reconfigure button -->
<dimen name="widget_reconfigure_button_corner_radius">14dp</dimen>
<dimen name="widget_reconfigure_button_padding">6dp</dimen>
<dimen name="widget_reconfigure_button_margin">32dp</dimen>
<dimen name="widget_reconfigure_button_size">36dp</dimen>
<!-- Fast scroll -->
<dimen name="fastscroll_track_min_width">6dp</dimen>
<dimen name="fastscroll_track_max_width">8dp</dimen>

View File

@@ -22,6 +22,7 @@ import android.util.SizeF;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import androidx.annotation.Nullable;
@@ -74,6 +75,7 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
private LauncherAppWidgetHostView mWidgetView;
private CellLayout mCellLayout;
private DragLayer mDragLayer;
private ImageButton mReconfigureButton;
private Rect mWidgetPadding;
@@ -211,6 +213,17 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
mDragHandles[INDEX_RIGHT].setVisibility(GONE);
}
mReconfigureButton = (ImageButton) findViewById(R.id.widget_reconfigure_button);
if (info.isReconfigurable()) {
mReconfigureButton.setVisibility(VISIBLE);
mReconfigureButton.setOnClickListener(view -> mLauncher
.getAppWidgetHost()
.startConfigActivity(
mLauncher,
mWidgetView.getAppWidgetId(),
Launcher.REQUEST_RECONFIGURE_APPWIDGET));
}
// When we create the resize frame, we first mark all cells as unoccupied. The appropriate
// cells (same if not resized, or different) will be marked as occupied when the resize
// frame is dismissed.
@@ -582,6 +595,13 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
return false;
}
private boolean isTouchOnReconfigureButton(MotionEvent ev) {
int xFrame = (int) ev.getX() - getLeft();
int yFrame = (int) ev.getY() - getTop();
mReconfigureButton.getHitRect(sTmpRect);
return sTmpRect.contains(xFrame, yFrame);
}
@Override
public boolean onControllerTouchEvent(MotionEvent ev) {
int action = ev.getAction();
@@ -609,6 +629,11 @@ public class AppWidgetResizeFrame extends AbstractFloatingView implements View.O
if (ev.getAction() == MotionEvent.ACTION_DOWN && handleTouchDown(ev)) {
return true;
}
// Keep the resize frame open but let a click on the reconfigure button fall through to the
// button's OnClickListener.
if (isTouchOnReconfigureButton(ev)) {
return false;
}
close(false);
return false;
}

View File

@@ -139,6 +139,10 @@ public class LauncherAppWidgetProviderInfo extends AppWidgetProviderInfo
}
}
public boolean isReconfigurable() {
return configure != null && (getWidgetFeatures() & WIDGET_FEATURE_RECONFIGURABLE) != 0;
}
@Override
public final ComponentName getComponent() {
return provider;