From 0be025d64c1f84138fe430a58875886e66aae767 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Mon, 23 May 2011 17:45:09 -0700 Subject: Fixing long-press issue due to child hit-rect offset. - Removing some unused code Change-Id: I875e3b27372c4c507e4bbc2d36b16eba077e2121 --- src/com/android/launcher2/AllAppsBackground.java | 4 +- src/com/android/launcher2/CellLayout.java | 14 ++++-- src/com/android/launcher2/PagedViewIcon.java | 1 - src/com/android/launcher2/ShortcutsAdapter.java | 58 ------------------------ src/com/android/launcher2/Utilities.java | 22 --------- 5 files changed, 13 insertions(+), 86 deletions(-) delete mode 100644 src/com/android/launcher2/ShortcutsAdapter.java diff --git a/src/com/android/launcher2/AllAppsBackground.java b/src/com/android/launcher2/AllAppsBackground.java index 5292d0ad3..51e1ee472 100644 --- a/src/com/android/launcher2/AllAppsBackground.java +++ b/src/com/android/launcher2/AllAppsBackground.java @@ -25,8 +25,8 @@ import android.util.AttributeSet; import android.view.View; /** - * An implementation of PagedView that populates the pages of the workspace - * with all of the user's applications. + * The background for AllApps which moves independently of the AllApps tray (for example, when we + * transition between AllApps and the Workspace while in spring-loaded mode). */ public class AllAppsBackground extends View { private Drawable mBackground; diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java index 5f848a8fa..f189cd58e 100644 --- a/src/com/android/launcher2/CellLayout.java +++ b/src/com/android/launcher2/CellLayout.java @@ -71,7 +71,7 @@ public class CellLayout extends ViewGroup { // These are temporary variables to prevent having to allocate a new object just to // return an (x, y) value from helper functions. Do NOT use them to maintain other state. - private final int[] mTmpCellXY = new int[2]; + private final int[] mTmpXY = new int[2]; private final int[] mTmpPoint = new int[2]; private final PointF mTmpPointF = new PointF(); @@ -694,6 +694,14 @@ public class CellLayout extends ViewGroup { if ((child.getVisibility() == VISIBLE || child.getAnimation() != null) && lp.isLockedToGrid) { child.getHitRect(frame); + + // The child hit rect is relative to the CellLayoutChildren parent, so we need to + // offset that by this CellLayout's padding to test an (x,y) point that is relative + // to this view. + final int tmpXY[] = mTmpXY; + child.getLocationOnScreen(tmpXY); + frame.offset(mLeftPadding, mTopPadding); + if (frame.contains(x, y)) { cellInfo.cell = child; cellInfo.cellX = lp.cellX; @@ -708,7 +716,7 @@ public class CellLayout extends ViewGroup { } if (!found) { - final int cellXY[] = mTmpCellXY; + final int cellXY[] = mTmpXY; pointToCellExact(x, y, cellXY); cellInfo.cell = null; @@ -1161,7 +1169,7 @@ public class CellLayout extends ViewGroup { } } } - final int[] cellXY = mTmpCellXY; + final int[] cellXY = mTmpXY; cellToCenterPoint(x, y, cellXY); double distance = Math.sqrt(Math.pow(cellXY[0] - pixelX, 2) diff --git a/src/com/android/launcher2/PagedViewIcon.java b/src/com/android/launcher2/PagedViewIcon.java index 306ff9e7b..30f0b1db2 100644 --- a/src/com/android/launcher2/PagedViewIcon.java +++ b/src/com/android/launcher2/PagedViewIcon.java @@ -31,7 +31,6 @@ import android.os.HandlerThread; import android.os.Message; import android.util.AttributeSet; import android.view.KeyEvent; -import android.view.View; import android.widget.Checkable; import com.android.launcher.R; diff --git a/src/com/android/launcher2/ShortcutsAdapter.java b/src/com/android/launcher2/ShortcutsAdapter.java deleted file mode 100644 index de73c3e3a..000000000 --- a/src/com/android/launcher2/ShortcutsAdapter.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2008 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. - */ - -package com.android.launcher2; - -import java.util.ArrayList; - -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.TextView; - -import com.android.launcher.R; - -/** - * GridView adapter to show the list of applications and shortcuts - */ -public class ShortcutsAdapter extends ArrayAdapter { - private final LayoutInflater mInflater; - private final IconCache mIconCache; - - public ShortcutsAdapter(Context context, ArrayList apps) { - super(context, 0, apps); - mInflater = LayoutInflater.from(context); - mIconCache = ((LauncherApplication)context.getApplicationContext()).getIconCache(); - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - final ShortcutInfo info = getItem(position); - - if (convertView == null) { - convertView = mInflater.inflate(R.layout.application_boxed, parent, false); - } - - final TextView textView = (TextView) convertView; - textView.setCompoundDrawablesWithIntrinsicBounds(null, - new FastBitmapDrawable(info.getIcon(mIconCache)), null, null); - textView.setText(info.title); - - return convertView; - } -} diff --git a/src/com/android/launcher2/Utilities.java b/src/com/android/launcher2/Utilities.java index ba258939c..04abd77aa 100644 --- a/src/com/android/launcher2/Utilities.java +++ b/src/com/android/launcher2/Utilities.java @@ -68,28 +68,6 @@ final class Utilities { sCanvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, Paint.FILTER_BITMAP_FLAG)); } - - static Bitmap centerToFit(Bitmap bitmap, int width, int height, Context context) { - final int bitmapWidth = bitmap.getWidth(); - final int bitmapHeight = bitmap.getHeight(); - - if (bitmapWidth < width || bitmapHeight < height) { - int color = context.getResources().getColor(R.color.window_background); - - Bitmap centered = Bitmap.createBitmap(bitmapWidth < width ? width : bitmapWidth, - bitmapHeight < height ? height : bitmapHeight, Bitmap.Config.RGB_565); - centered.setDensity(bitmap.getDensity()); - Canvas canvas = new Canvas(centered); - canvas.drawColor(color); - canvas.drawBitmap(bitmap, (width - bitmapWidth) / 2.0f, (height - bitmapHeight) / 2.0f, - null); - - bitmap = centered; - } - - return bitmap; - } - static int sColors[] = { 0xffff0000, 0xff00ff00, 0xff0000ff }; static int sColorIndex = 0; -- cgit v1.2.3