Merge "Fixing widget not laid-out properly in preview" into sc-v2-dev
This commit is contained in:
@@ -31,7 +31,7 @@ import android.view.ViewGroup;
|
|||||||
import com.android.launcher3.CellLayout.ContainerType;
|
import com.android.launcher3.CellLayout.ContainerType;
|
||||||
import com.android.launcher3.folder.FolderIcon;
|
import com.android.launcher3.folder.FolderIcon;
|
||||||
import com.android.launcher3.views.ActivityContext;
|
import com.android.launcher3.views.ActivityContext;
|
||||||
import com.android.launcher3.widget.LauncherAppWidgetHostView;
|
import com.android.launcher3.widget.NavigableAppWidgetHostView;
|
||||||
|
|
||||||
public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.FolderIconParent {
|
public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.FolderIconParent {
|
||||||
static final String TAG = "ShortcutAndWidgetContainer";
|
static final String TAG = "ShortcutAndWidgetContainer";
|
||||||
@@ -104,9 +104,9 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
|
|||||||
|
|
||||||
public void setupLp(View child) {
|
public void setupLp(View child) {
|
||||||
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
|
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
|
||||||
if (child instanceof LauncherAppWidgetHostView) {
|
if (child instanceof NavigableAppWidgetHostView) {
|
||||||
DeviceProfile profile = mActivity.getDeviceProfile();
|
DeviceProfile profile = mActivity.getDeviceProfile();
|
||||||
((LauncherAppWidgetHostView) child).getWidgetInset(profile, mTempRect);
|
((NavigableAppWidgetHostView) child).getWidgetInset(profile, mTempRect);
|
||||||
lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
|
lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
|
||||||
profile.appWidgetScale.x, profile.appWidgetScale.y, mBorderSpacing, mTempRect);
|
profile.appWidgetScale.x, profile.appWidgetScale.y, mBorderSpacing, mTempRect);
|
||||||
} else {
|
} else {
|
||||||
@@ -129,8 +129,8 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
|
|||||||
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
|
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
|
||||||
final DeviceProfile dp = mActivity.getDeviceProfile();
|
final DeviceProfile dp = mActivity.getDeviceProfile();
|
||||||
|
|
||||||
if (child instanceof LauncherAppWidgetHostView) {
|
if (child instanceof NavigableAppWidgetHostView) {
|
||||||
((LauncherAppWidgetHostView) child).getWidgetInset(dp, mTempRect);
|
((NavigableAppWidgetHostView) child).getWidgetInset(dp, mTempRect);
|
||||||
lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
|
lp.setup(mCellWidth, mCellHeight, invertLayoutHorizontally(), mCountX, mCountY,
|
||||||
dp.appWidgetScale.x, dp.appWidgetScale.y, mBorderSpacing, mTempRect);
|
dp.appWidgetScale.x, dp.appWidgetScale.y, mBorderSpacing, mTempRect);
|
||||||
} else {
|
} else {
|
||||||
@@ -176,16 +176,16 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon.
|
|||||||
*/
|
*/
|
||||||
public void layoutChild(View child) {
|
public void layoutChild(View child) {
|
||||||
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
|
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
|
||||||
if (child instanceof LauncherAppWidgetHostView) {
|
if (child instanceof NavigableAppWidgetHostView) {
|
||||||
LauncherAppWidgetHostView lahv = (LauncherAppWidgetHostView) child;
|
NavigableAppWidgetHostView nahv = (NavigableAppWidgetHostView) child;
|
||||||
|
|
||||||
// Scale and center the widget to fit within its cells.
|
// Scale and center the widget to fit within its cells.
|
||||||
DeviceProfile profile = mActivity.getDeviceProfile();
|
DeviceProfile profile = mActivity.getDeviceProfile();
|
||||||
float scaleX = profile.appWidgetScale.x;
|
float scaleX = profile.appWidgetScale.x;
|
||||||
float scaleY = profile.appWidgetScale.y;
|
float scaleY = profile.appWidgetScale.y;
|
||||||
|
|
||||||
lahv.setScaleToFit(Math.min(scaleX, scaleY));
|
nahv.setScaleToFit(Math.min(scaleX, scaleY));
|
||||||
lahv.setTranslationForCentering(-(lp.width - (lp.width * scaleX)) / 2.0f,
|
nahv.setTranslationForCentering(-(lp.width - (lp.width * scaleX)) / 2.0f,
|
||||||
-(lp.height - (lp.height * scaleY)) / 2.0f);
|
-(lp.height - (lp.height * scaleY)) / 2.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ import com.android.launcher3.util.MainThreadInitializedObject;
|
|||||||
import com.android.launcher3.views.ActivityContext;
|
import com.android.launcher3.views.ActivityContext;
|
||||||
import com.android.launcher3.views.BaseDragLayer;
|
import com.android.launcher3.views.BaseDragLayer;
|
||||||
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
|
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
|
||||||
|
import com.android.launcher3.widget.NavigableAppWidgetHostView;
|
||||||
import com.android.launcher3.widget.custom.CustomWidgetManager;
|
import com.android.launcher3.widget.custom.CustomWidgetManager;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -353,7 +354,12 @@ public class LauncherPreviewRenderer extends ContextWrapper
|
|||||||
|
|
||||||
private void inflateAndAddWidgets(
|
private void inflateAndAddWidgets(
|
||||||
LauncherAppWidgetInfo info, LauncherAppWidgetProviderInfo providerInfo) {
|
LauncherAppWidgetInfo info, LauncherAppWidgetProviderInfo providerInfo) {
|
||||||
AppWidgetHostView view = new AppWidgetHostView(mContext);
|
AppWidgetHostView view = new NavigableAppWidgetHostView(this) {
|
||||||
|
@Override
|
||||||
|
protected boolean shouldAllowDirectClick() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
view.setAppWidget(-1, providerInfo);
|
view.setAppWidget(-1, providerInfo);
|
||||||
view.updateAppWidget(null);
|
view.updateAppWidget(null);
|
||||||
view.setTag(info);
|
view.setTag(info);
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import android.view.View;
|
|||||||
import android.view.ViewDebug;
|
import android.view.ViewDebug;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import com.android.launcher3.BaseActivity;
|
|
||||||
import com.android.launcher3.DeviceProfile;
|
import com.android.launcher3.DeviceProfile;
|
||||||
import com.android.launcher3.Reorderable;
|
import com.android.launcher3.Reorderable;
|
||||||
import com.android.launcher3.dragndrop.DraggableView;
|
import com.android.launcher3.dragndrop.DraggableView;
|
||||||
@@ -59,7 +58,7 @@ public abstract class NavigableAppWidgetHostView extends AppWidgetHostView
|
|||||||
@ViewDebug.ExportedProperty(category = "launcher")
|
@ViewDebug.ExportedProperty(category = "launcher")
|
||||||
private boolean mChildrenFocused;
|
private boolean mChildrenFocused;
|
||||||
|
|
||||||
protected final BaseActivity mActivity;
|
protected final ActivityContext mActivity;
|
||||||
|
|
||||||
public NavigableAppWidgetHostView(Context context) {
|
public NavigableAppWidgetHostView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|||||||
Reference in New Issue
Block a user