Merge "Refactoring common methods" into ub-launcher3-burnaby
This commit is contained in:
@@ -21,11 +21,6 @@
|
||||
<dimen name="toolbar_button_vertical_padding">8dip</dimen>
|
||||
<dimen name="toolbar_button_horizontal_padding">8dip</dimen>
|
||||
|
||||
<!-- When dragging items on the workspace, the number of dps by which the position of
|
||||
the drag view should be offset from the position of the original view. -->
|
||||
<dimen name="dragViewOffsetX">0dp</dimen>
|
||||
<dimen name="dragViewOffsetY">0dp</dimen>
|
||||
|
||||
<!-- Cling -->
|
||||
<dimen name="cling_migration_content_margin">96dp</dimen>
|
||||
<dimen name="cling_migration_content_width">320dp</dimen>
|
||||
|
||||
@@ -68,10 +68,6 @@
|
||||
or right while you're dragging. -->
|
||||
<dimen name="scroll_zone">20dp</dimen>
|
||||
|
||||
<!-- When dragging items on the workspace, the number of dps by which the position of
|
||||
the drag view should be offset from the position of the original view. -->
|
||||
<dimen name="dragViewOffsetX">0dp</dimen>
|
||||
<dimen name="dragViewOffsetY">0dp</dimen>
|
||||
<!-- When dragging an item, how much bigger (fixed dps) the dragged view
|
||||
should be. If 0, it will not be scaled at all. -->
|
||||
<dimen name="dragViewScale">12dp</dimen>
|
||||
|
||||
@@ -613,11 +613,7 @@ public class CellLayout extends ViewGroup {
|
||||
if (lp.cellVSpan < 0) lp.cellVSpan = mCountY;
|
||||
|
||||
child.setId(childId);
|
||||
if (inLayout) {
|
||||
mShortcutsAndWidgets.addView(child, index, lp, true);
|
||||
} else {
|
||||
mShortcutsAndWidgets.addView(child, index, lp, false);
|
||||
}
|
||||
mShortcutsAndWidgets.addView(child, index, lp, inLayout);
|
||||
|
||||
if (markCells) markCellsAsOccupiedForView(child);
|
||||
|
||||
|
||||
@@ -65,6 +65,29 @@ public interface DropTarget {
|
||||
|
||||
public DragObject() {
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used to compute the visual center of the dragView. This point is then
|
||||
* used to visualize drop locations and determine where to drop an item. The idea is that
|
||||
* the visual center represents the user's interpretation of where the item is, and hence
|
||||
* is the appropriate point to use when determining drop location.
|
||||
*/
|
||||
public final float[] getVisualCenter(float[] recycle) {
|
||||
final float res[] = (recycle == null) ? new float[2] : recycle;
|
||||
|
||||
// These represent the visual top and left of drag view if a dragRect was provided.
|
||||
// If a dragRect was not provided, then they correspond to the actual view left and
|
||||
// top, as the dragRect is in that case taken to be the entire dragView.
|
||||
// R.dimen.dragViewOffsetY.
|
||||
int left = x - xOffset;
|
||||
int top = y - yOffset;
|
||||
|
||||
// In order to find the visual center, we shift by half the dragRect
|
||||
res[0] = left + dragView.getDragRegion().width() / 2;
|
||||
res[1] = top + dragView.getDragRegion().height() / 2;
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DragEnforcer implements DragController.DragListener {
|
||||
|
||||
@@ -27,7 +27,6 @@ import android.content.res.Resources;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.os.SystemClock;
|
||||
import android.text.InputType;
|
||||
import android.text.Selection;
|
||||
import android.text.Spannable;
|
||||
@@ -53,7 +52,6 @@ import com.android.launcher3.FolderInfo.FolderListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Represents a set of icons chosen by the user or generated by the system.
|
||||
@@ -704,17 +702,11 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
|
||||
}
|
||||
|
||||
public void onDragOver(DragObject d) {
|
||||
final DragView dragView = d.dragView;
|
||||
final int scrollOffset = mScrollView.getScrollY();
|
||||
final float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, dragView, null);
|
||||
final float[] r = d.getVisualCenter(null);
|
||||
r[0] -= getPaddingLeft();
|
||||
r[1] -= getPaddingTop();
|
||||
|
||||
final long downTime = SystemClock.uptimeMillis();
|
||||
final MotionEvent translatedEv = MotionEvent.obtain(
|
||||
downTime, downTime, MotionEvent.ACTION_MOVE, d.x, d.y, 0);
|
||||
|
||||
translatedEv.recycle();
|
||||
mTargetCell = mContent.findNearestArea(
|
||||
(int) r[0], (int) r[1] + scrollOffset, 1, 1, mTargetCell);
|
||||
if (isLayoutRtl()) {
|
||||
@@ -730,32 +722,6 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
|
||||
}
|
||||
}
|
||||
|
||||
// This is used to compute the visual center of the dragView. The idea is that
|
||||
// the visual center represents the user's interpretation of where the item is, and hence
|
||||
// is the appropriate point to use when determining drop location.
|
||||
private float[] getDragViewVisualCenter(int x, int y, int xOffset, int yOffset,
|
||||
DragView dragView, float[] recycle) {
|
||||
float res[];
|
||||
if (recycle == null) {
|
||||
res = new float[2];
|
||||
} else {
|
||||
res = recycle;
|
||||
}
|
||||
|
||||
// These represent the visual top and left of drag view if a dragRect was provided.
|
||||
// If a dragRect was not provided, then they correspond to the actual view left and
|
||||
// top, as the dragRect is in that case taken to be the entire dragView.
|
||||
// R.dimen.dragViewOffsetY.
|
||||
int left = x - xOffset;
|
||||
int top = y - yOffset;
|
||||
|
||||
// In order to find the visual center, we shift by half the dragRect
|
||||
res[0] = left + dragView.getDragRegion().width() / 2;
|
||||
res[1] = top + dragView.getDragRegion().height() / 2;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() {
|
||||
public void onAlarm(Alarm alarm) {
|
||||
completeDragExit();
|
||||
|
||||
@@ -2831,8 +2831,7 @@ public class Workspace extends SmoothPagedView
|
||||
}
|
||||
if (!transitionStateShouldAllowDrop()) return false;
|
||||
|
||||
mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset,
|
||||
d.dragView, mDragViewVisualCenter);
|
||||
mDragViewVisualCenter = d.getVisualCenter(mDragViewVisualCenter);
|
||||
|
||||
// We want the point to be mapped to the dragTarget.
|
||||
if (mLauncher.isHotseatLayout(dropTargetLayout)) {
|
||||
@@ -3034,9 +3033,7 @@ public class Workspace extends SmoothPagedView
|
||||
}
|
||||
|
||||
public void onDrop(final DragObject d) {
|
||||
mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView,
|
||||
mDragViewVisualCenter);
|
||||
|
||||
mDragViewVisualCenter = d.getVisualCenter(mDragViewVisualCenter);
|
||||
CellLayout dropTargetLayout = mDropToLayout;
|
||||
|
||||
// We want the point to be mapped to the dragTarget.
|
||||
@@ -3542,38 +3539,6 @@ public class Workspace extends SmoothPagedView
|
||||
return bestMatchingScreen;
|
||||
}
|
||||
|
||||
// This is used to compute the visual center of the dragView. This point is then
|
||||
// used to visualize drop locations and determine where to drop an item. The idea is that
|
||||
// the visual center represents the user's interpretation of where the item is, and hence
|
||||
// is the appropriate point to use when determining drop location.
|
||||
private float[] getDragViewVisualCenter(int x, int y, int xOffset, int yOffset,
|
||||
DragView dragView, float[] recycle) {
|
||||
float res[];
|
||||
if (recycle == null) {
|
||||
res = new float[2];
|
||||
} else {
|
||||
res = recycle;
|
||||
}
|
||||
|
||||
// First off, the drag view has been shifted in a way that is not represented in the
|
||||
// x and y values or the x/yOffsets. Here we account for that shift.
|
||||
x += getResources().getDimensionPixelSize(R.dimen.dragViewOffsetX);
|
||||
y += getResources().getDimensionPixelSize(R.dimen.dragViewOffsetY);
|
||||
|
||||
// These represent the visual top and left of drag view if a dragRect was provided.
|
||||
// If a dragRect was not provided, then they correspond to the actual view left and
|
||||
// top, as the dragRect is in that case taken to be the entire dragView.
|
||||
// R.dimen.dragViewOffsetY.
|
||||
int left = x - xOffset;
|
||||
int top = y - yOffset;
|
||||
|
||||
// In order to find the visual center, we shift by half the dragRect
|
||||
res[0] = left + dragView.getDragRegion().width() / 2;
|
||||
res[1] = top + dragView.getDragRegion().height() / 2;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
private boolean isDragWidget(DragObject d) {
|
||||
return (d.dragInfo instanceof LauncherAppWidgetInfo ||
|
||||
d.dragInfo instanceof PendingAddWidgetInfo);
|
||||
@@ -3598,8 +3563,7 @@ public class Workspace extends SmoothPagedView
|
||||
|
||||
// Ensure that we have proper spans for the item that we are dropping
|
||||
if (item.spanX < 0 || item.spanY < 0) throw new RuntimeException("Improper spans found");
|
||||
mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset,
|
||||
d.dragView, mDragViewVisualCenter);
|
||||
mDragViewVisualCenter = d.getVisualCenter(mDragViewVisualCenter);
|
||||
|
||||
final View child = (mDragInfo == null) ? null : mDragInfo.cell;
|
||||
// Identify whether we have dragged over a side page
|
||||
|
||||
Reference in New Issue
Block a user