Loading res/layout/widget_cell.xml +10 −15 Original line number Diff line number Diff line Loading @@ -39,16 +39,15 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="start" android:singleLine="true" android:ellipsize="end" android:fadingEdge="horizontal" android:textColor="@color/widgets_view_item_text_color" android:textSize="14sp" android:textAlignment="viewStart" android:fontFamily="sans-serif-condensed" android:gravity="start" android:shadowColor="#B0000000" android:shadowRadius="2.0" android:shadowColor="#B0000000" /> android:singleLine="true" android:textColor="@color/widgets_view_item_text_color" android:textSize="14sp" /> <!-- The original dimensions of the widget (can't be the same text as above due to different style. --> Loading @@ -58,22 +57,18 @@ android:layout_height="wrap_content" android:layout_marginStart="5dp" android:layout_marginLeft="5dp" android:layout_weight="0" android:gravity="start" android:textColor="@color/widgets_view_item_text_color" android:textSize="14sp" android:textAlignment="viewStart" android:fontFamily="sans-serif-condensed" android:shadowRadius="2.0" android:shadowColor="#B0000000" /> </LinearLayout> <!-- The image of the widget. --> <!-- The image of the widget. This view does not support padding. Any placement adjustment should be done using margins. --> <com.android.launcher3.widget.WidgetImageView android:id="@+id/widget_preview" style="@style/WidgetImageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:scaleType="matrix" /> android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /> </com.android.launcher3.widget.WidgetCell> No newline at end of file res/values-v17/styles.xmldeleted 100644 → 0 +0 −6 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <resources> <style name="WidgetImageView"> <item name="android:paddingStart">@dimen/widget_preview_horizontal_padding</item> </style> </resources> res/values/styles.xml +0 −5 Original line number Diff line number Diff line Loading @@ -86,9 +86,4 @@ <item name="ringOutset">4dp</item> </style> <!-- Overridden in device overlays --> <style name="WidgetImageView"> <item name="android:paddingLeft">@dimen/widget_preview_horizontal_padding</item> </style> </resources> src/com/android/launcher3/DragController.java +7 −8 Original line number Diff line number Diff line Loading @@ -174,19 +174,18 @@ public class DragController { * @param dragInfo The data associated with the object that is being dragged * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or * {@link #DRAG_ACTION_COPY} * @param viewImageBounds the position of the image inside the view * @param dragRegion Coordinates within the bitmap b for the position of item being dragged. * Makes dragging feel more precise, e.g. you can clip out a transparent border */ public void startDrag(View v, Bitmap bmp, DragSource source, Object dragInfo, int dragAction, Point extraPadding, float initialDragViewScale) { public void startDrag(View v, Bitmap bmp, DragSource source, Object dragInfo, Rect viewImageBounds, int dragAction, float initialDragViewScale) { int[] loc = mCoordinatesTemp; mLauncher.getDragLayer().getLocationInDragLayer(v, loc); int viewExtraPaddingLeft = extraPadding != null ? extraPadding.x : 0; int viewExtraPaddingTop = extraPadding != null ? extraPadding.y : 0; int dragLayerX = loc[0] + v.getPaddingLeft() + viewExtraPaddingLeft + (int) ((initialDragViewScale * bmp.getWidth() - bmp.getWidth()) / 2); int dragLayerY = loc[1] + v.getPaddingTop() + viewExtraPaddingTop + (int) ((initialDragViewScale * bmp.getHeight() - bmp.getHeight()) / 2); int dragLayerX = loc[0] + viewImageBounds.left + (int) ((initialDragViewScale * bmp.getWidth() - bmp.getWidth()) / 2); int dragLayerY = loc[1] + viewImageBounds.top + (int) ((initialDragViewScale * bmp.getHeight() - bmp.getHeight()) / 2); startDrag(bmp, dragLayerX, dragLayerY, source, dragInfo, dragAction, null, null, initialDragViewScale, false); Loading src/com/android/launcher3/widget/WidgetCell.java +13 −34 Original line number Diff line number Diff line Loading @@ -21,17 +21,14 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Rect; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.view.View.OnLayoutChangeListener; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.android.launcher3.DeviceProfile; import com.android.launcher3.FastBitmapDrawable; import com.android.launcher3.ItemInfo; import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherAppWidgetProviderInfo; Loading @@ -41,7 +38,13 @@ import com.android.launcher3.WidgetPreviewLoader.PreviewLoadRequest; import com.android.launcher3.compat.AppWidgetManagerCompat; /** * Represents the individual cell of the widget inside the widget tray. * Represents the individual cell of the widget inside the widget tray. The preview is drawn * horizontally centered, and scaled down if needed. * * This view does not support padding. Since the image is scaled down to fit the view, padding will * further decrease the scaling factor. Drag-n-drop uses the view bounds for showing a smooth * transition from the view to drag view, so when adding padding support, DnD would need to * consider the appropriate scaling factor. */ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { Loading @@ -59,13 +62,11 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { private int mPresetPreviewSize; int cellSize; private ImageView mWidgetImage; private WidgetImageView mWidgetImage; private TextView mWidgetName; private TextView mWidgetDims; private final Rect mOrigImgPadding = new Rect(); private String mDimensionsFormatString; private boolean mIsAppWidget; private Object mInfo; private WidgetPreviewLoader mWidgetPreviewLoader; Loading Loading @@ -101,12 +102,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { protected void onFinishInflate() { super.onFinishInflate(); mWidgetImage = (ImageView) findViewById(R.id.widget_preview); mOrigImgPadding.left = mWidgetImage.getPaddingLeft(); mOrigImgPadding.top = mWidgetImage.getPaddingTop(); mOrigImgPadding.right = mWidgetImage.getPaddingRight(); mOrigImgPadding.bottom = mWidgetImage.getPaddingBottom(); mWidgetImage = (WidgetImageView) findViewById(R.id.widget_preview); mWidgetName = ((TextView) findViewById(R.id.widget_name)); mWidgetDims = ((TextView) findViewById(R.id.widget_dims)); } Loading @@ -119,7 +115,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { Log.d(TAG, "reset called on:" + mWidgetName.getText()); } mWidgetImage.animate().cancel(); mWidgetImage.setImageDrawable(null); mWidgetImage.setBitmap(null); mWidgetName.setText(null); mWidgetDims.setText(null); Loading @@ -133,15 +129,11 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { * Apply the widget provider info to the view. */ public void applyFromAppWidgetProviderInfo(LauncherAppWidgetProviderInfo info, int maxWidth, WidgetPreviewLoader loader) { WidgetPreviewLoader loader) { LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); mIsAppWidget = true; mInfo = info; if (maxWidth > -1) { mWidgetImage.setMaxWidth(maxWidth); } // TODO(hyunyoungs): setup a cache for these labels. mWidgetName.setText(AppWidgetManagerCompat.getInstance(getContext()).loadLabel(info)); int hSpan = Math.min(info.spanX, grid.numColumns); Loading @@ -155,7 +147,6 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { */ public void applyFromResolveInfo( PackageManager pm, ResolveInfo info, WidgetPreviewLoader loader) { mIsAppWidget = false; mInfo = info; CharSequence label = info.loadLabel(pm); mWidgetName.setText(label); Loading @@ -172,20 +163,8 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { } public void applyPreview(Bitmap bitmap) { FastBitmapDrawable preview = new FastBitmapDrawable(bitmap); if (preview != null) { mWidgetImage.setImageDrawable(preview); if (mIsAppWidget) { // center horizontally int[] imageSize = getPreviewSize(); int centerAmount = (imageSize[0] - preview.getIntrinsicWidth()) / 2; mWidgetImage.setPadding(mOrigImgPadding.left + centerAmount, mOrigImgPadding.top, mOrigImgPadding.right, mOrigImgPadding.bottom); } if (bitmap != null) { mWidgetImage.setBitmap(bitmap); mWidgetImage.setAlpha(0f); mWidgetImage.animate().alpha(1.0f).setDuration(FADE_IN_DURATION_MS); } Loading Loading
res/layout/widget_cell.xml +10 −15 Original line number Diff line number Diff line Loading @@ -39,16 +39,15 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="start" android:singleLine="true" android:ellipsize="end" android:fadingEdge="horizontal" android:textColor="@color/widgets_view_item_text_color" android:textSize="14sp" android:textAlignment="viewStart" android:fontFamily="sans-serif-condensed" android:gravity="start" android:shadowColor="#B0000000" android:shadowRadius="2.0" android:shadowColor="#B0000000" /> android:singleLine="true" android:textColor="@color/widgets_view_item_text_color" android:textSize="14sp" /> <!-- The original dimensions of the widget (can't be the same text as above due to different style. --> Loading @@ -58,22 +57,18 @@ android:layout_height="wrap_content" android:layout_marginStart="5dp" android:layout_marginLeft="5dp" android:layout_weight="0" android:gravity="start" android:textColor="@color/widgets_view_item_text_color" android:textSize="14sp" android:textAlignment="viewStart" android:fontFamily="sans-serif-condensed" android:shadowRadius="2.0" android:shadowColor="#B0000000" /> </LinearLayout> <!-- The image of the widget. --> <!-- The image of the widget. This view does not support padding. Any placement adjustment should be done using margins. --> <com.android.launcher3.widget.WidgetImageView android:id="@+id/widget_preview" style="@style/WidgetImageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:scaleType="matrix" /> android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /> </com.android.launcher3.widget.WidgetCell> No newline at end of file
res/values-v17/styles.xmldeleted 100644 → 0 +0 −6 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <resources> <style name="WidgetImageView"> <item name="android:paddingStart">@dimen/widget_preview_horizontal_padding</item> </style> </resources>
res/values/styles.xml +0 −5 Original line number Diff line number Diff line Loading @@ -86,9 +86,4 @@ <item name="ringOutset">4dp</item> </style> <!-- Overridden in device overlays --> <style name="WidgetImageView"> <item name="android:paddingLeft">@dimen/widget_preview_horizontal_padding</item> </style> </resources>
src/com/android/launcher3/DragController.java +7 −8 Original line number Diff line number Diff line Loading @@ -174,19 +174,18 @@ public class DragController { * @param dragInfo The data associated with the object that is being dragged * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or * {@link #DRAG_ACTION_COPY} * @param viewImageBounds the position of the image inside the view * @param dragRegion Coordinates within the bitmap b for the position of item being dragged. * Makes dragging feel more precise, e.g. you can clip out a transparent border */ public void startDrag(View v, Bitmap bmp, DragSource source, Object dragInfo, int dragAction, Point extraPadding, float initialDragViewScale) { public void startDrag(View v, Bitmap bmp, DragSource source, Object dragInfo, Rect viewImageBounds, int dragAction, float initialDragViewScale) { int[] loc = mCoordinatesTemp; mLauncher.getDragLayer().getLocationInDragLayer(v, loc); int viewExtraPaddingLeft = extraPadding != null ? extraPadding.x : 0; int viewExtraPaddingTop = extraPadding != null ? extraPadding.y : 0; int dragLayerX = loc[0] + v.getPaddingLeft() + viewExtraPaddingLeft + (int) ((initialDragViewScale * bmp.getWidth() - bmp.getWidth()) / 2); int dragLayerY = loc[1] + v.getPaddingTop() + viewExtraPaddingTop + (int) ((initialDragViewScale * bmp.getHeight() - bmp.getHeight()) / 2); int dragLayerX = loc[0] + viewImageBounds.left + (int) ((initialDragViewScale * bmp.getWidth() - bmp.getWidth()) / 2); int dragLayerY = loc[1] + viewImageBounds.top + (int) ((initialDragViewScale * bmp.getHeight() - bmp.getHeight()) / 2); startDrag(bmp, dragLayerX, dragLayerY, source, dragInfo, dragAction, null, null, initialDragViewScale, false); Loading
src/com/android/launcher3/widget/WidgetCell.java +13 −34 Original line number Diff line number Diff line Loading @@ -21,17 +21,14 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Rect; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.view.View.OnLayoutChangeListener; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.android.launcher3.DeviceProfile; import com.android.launcher3.FastBitmapDrawable; import com.android.launcher3.ItemInfo; import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherAppWidgetProviderInfo; Loading @@ -41,7 +38,13 @@ import com.android.launcher3.WidgetPreviewLoader.PreviewLoadRequest; import com.android.launcher3.compat.AppWidgetManagerCompat; /** * Represents the individual cell of the widget inside the widget tray. * Represents the individual cell of the widget inside the widget tray. The preview is drawn * horizontally centered, and scaled down if needed. * * This view does not support padding. Since the image is scaled down to fit the view, padding will * further decrease the scaling factor. Drag-n-drop uses the view bounds for showing a smooth * transition from the view to drag view, so when adding padding support, DnD would need to * consider the appropriate scaling factor. */ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { Loading @@ -59,13 +62,11 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { private int mPresetPreviewSize; int cellSize; private ImageView mWidgetImage; private WidgetImageView mWidgetImage; private TextView mWidgetName; private TextView mWidgetDims; private final Rect mOrigImgPadding = new Rect(); private String mDimensionsFormatString; private boolean mIsAppWidget; private Object mInfo; private WidgetPreviewLoader mWidgetPreviewLoader; Loading Loading @@ -101,12 +102,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { protected void onFinishInflate() { super.onFinishInflate(); mWidgetImage = (ImageView) findViewById(R.id.widget_preview); mOrigImgPadding.left = mWidgetImage.getPaddingLeft(); mOrigImgPadding.top = mWidgetImage.getPaddingTop(); mOrigImgPadding.right = mWidgetImage.getPaddingRight(); mOrigImgPadding.bottom = mWidgetImage.getPaddingBottom(); mWidgetImage = (WidgetImageView) findViewById(R.id.widget_preview); mWidgetName = ((TextView) findViewById(R.id.widget_name)); mWidgetDims = ((TextView) findViewById(R.id.widget_dims)); } Loading @@ -119,7 +115,7 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { Log.d(TAG, "reset called on:" + mWidgetName.getText()); } mWidgetImage.animate().cancel(); mWidgetImage.setImageDrawable(null); mWidgetImage.setBitmap(null); mWidgetName.setText(null); mWidgetDims.setText(null); Loading @@ -133,15 +129,11 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { * Apply the widget provider info to the view. */ public void applyFromAppWidgetProviderInfo(LauncherAppWidgetProviderInfo info, int maxWidth, WidgetPreviewLoader loader) { WidgetPreviewLoader loader) { LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); mIsAppWidget = true; mInfo = info; if (maxWidth > -1) { mWidgetImage.setMaxWidth(maxWidth); } // TODO(hyunyoungs): setup a cache for these labels. mWidgetName.setText(AppWidgetManagerCompat.getInstance(getContext()).loadLabel(info)); int hSpan = Math.min(info.spanX, grid.numColumns); Loading @@ -155,7 +147,6 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { */ public void applyFromResolveInfo( PackageManager pm, ResolveInfo info, WidgetPreviewLoader loader) { mIsAppWidget = false; mInfo = info; CharSequence label = info.loadLabel(pm); mWidgetName.setText(label); Loading @@ -172,20 +163,8 @@ public class WidgetCell extends LinearLayout implements OnLayoutChangeListener { } public void applyPreview(Bitmap bitmap) { FastBitmapDrawable preview = new FastBitmapDrawable(bitmap); if (preview != null) { mWidgetImage.setImageDrawable(preview); if (mIsAppWidget) { // center horizontally int[] imageSize = getPreviewSize(); int centerAmount = (imageSize[0] - preview.getIntrinsicWidth()) / 2; mWidgetImage.setPadding(mOrigImgPadding.left + centerAmount, mOrigImgPadding.top, mOrigImgPadding.right, mOrigImgPadding.bottom); } if (bitmap != null) { mWidgetImage.setBitmap(bitmap); mWidgetImage.setAlpha(0f); mWidgetImage.animate().alpha(1.0f).setDuration(FADE_IN_DURATION_MS); } Loading