ShortcutAndWidgetContainer.java revision 7066003b2032a49ae5e59dab9b706259bdeb7e6e
18c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka/*
28c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka * Copyright (C) 2008 The Android Open Source Project
38c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka *
48c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka * Licensed under the Apache License, Version 2.0 (the "License");
58c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka * you may not use this file except in compliance with the License.
68c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka * You may obtain a copy of the License at
78c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka *
88c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka *      http://www.apache.org/licenses/LICENSE-2.0
98c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka *
108c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka * Unless required by applicable law or agreed to in writing, software
118c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka * distributed under the License is distributed on an "AS IS" BASIS,
128c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka * See the License for the specific language governing permissions and
148c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka * limitations under the License.
158c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka */
168c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka
17325dc23624160689e59fbac708cf6f222b20d025Daniel Sandlerpackage com.android.launcher3;
188c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka
198c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurkaimport android.app.WallpaperManager;
208c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurkaimport android.content.Context;
21eecf02da58adef5486bf0c9ff7127ea891f457a4Winson Chungimport android.graphics.Canvas;
22eecf02da58adef5486bf0c9ff7127ea891f457a4Winson Chungimport android.graphics.Paint;
238c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurkaimport android.graphics.Rect;
248c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurkaimport android.view.View;
25cf6125c2d30ce02d8ab6cbe8e37a20f6a831e216Michael Jurkaimport android.view.ViewGroup;
265940042d39b576553c2499bcf3d0641281e6ad52Adam Cohenimport android.view.ViewGroup.LayoutParams;
278c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka
28a52570f8f9ad65b85e33a2f2e87722f9edd6c6f4Michael Jurkapublic class ShortcutAndWidgetContainer extends ViewGroup {
298c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    static final String TAG = "CellLayoutChildren";
308c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka
318c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    // These are temporary variables to prevent having to allocate a new object just to
328c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    // return an (x, y) value from helper functions. Do NOT use them to maintain other state.
338c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    private final int[] mTmpCellXY = new int[2];
348c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka
358c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    private final WallpaperManager mWallpaperManager;
368c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka
375f8afe6280eae34620067696173e71943e1a30a3Winson Chung    private boolean mIsHotseatLayout;
385f8afe6280eae34620067696173e71943e1a30a3Winson Chung
39d4844c3e731b00547a31f23a00f8bd4a271e2b62Adam Cohen    private int mCellWidth;
40d4844c3e731b00547a31f23a00f8bd4a271e2b62Adam Cohen    private int mCellHeight;
41d4844c3e731b00547a31f23a00f8bd4a271e2b62Adam Cohen
428c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    private int mWidthGap;
438c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    private int mHeightGap;
448c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka
452374abfda3e53f84e005df8923170308e4df8c03Adam Cohen    private int mCountX;
465f8afe6280eae34620067696173e71943e1a30a3Winson Chung    private int mCountY;
472374abfda3e53f84e005df8923170308e4df8c03Adam Cohen
482374abfda3e53f84e005df8923170308e4df8c03Adam Cohen    private boolean mInvertIfRtl = false;
492374abfda3e53f84e005df8923170308e4df8c03Adam Cohen
50a52570f8f9ad65b85e33a2f2e87722f9edd6c6f4Michael Jurka    public ShortcutAndWidgetContainer(Context context) {
518c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        super(context);
528c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        mWallpaperManager = WallpaperManager.getInstance(context);
532801cafe62653131fdc9da402e5c44e5ffd0bf47Adam Cohen    }
542801cafe62653131fdc9da402e5c44e5ffd0bf47Adam Cohen
552374abfda3e53f84e005df8923170308e4df8c03Adam Cohen    public void setCellDimensions(int cellWidth, int cellHeight, int widthGap, int heightGap,
565f8afe6280eae34620067696173e71943e1a30a3Winson Chung            int countX, int countY) {
578c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        mCellWidth = cellWidth;
588c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        mCellHeight = cellHeight;
598c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        mWidthGap = widthGap;
608c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        mHeightGap = heightGap;
612374abfda3e53f84e005df8923170308e4df8c03Adam Cohen        mCountX = countX;
625f8afe6280eae34620067696173e71943e1a30a3Winson Chung        mCountY = countY;
638c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    }
648c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka
658c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    public View getChildAt(int x, int y) {
668c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        final int count = getChildCount();
678c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        for (int i = 0; i < count; i++) {
688c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka            View child = getChildAt(i);
698c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka            CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
708c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka
718c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka            if ((lp.cellX <= x) && (x < lp.cellX + lp.cellHSpan) &&
72f579b5041afe8272c79f9f13001120d37eeeee7bAdam Cohen                    (lp.cellY <= y) && (y < lp.cellY + lp.cellVSpan)) {
738c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka                return child;
748c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka            }
758c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        }
768c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        return null;
778c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    }
788c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka
798c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    @Override
80eecf02da58adef5486bf0c9ff7127ea891f457a4Winson Chung    protected void dispatchDraw(Canvas canvas) {
813a9fcedbcd235372cd2ab64f825a0b5b3937f59eMichael Jurka        @SuppressWarnings("all") // suppress dead code warning
823a9fcedbcd235372cd2ab64f825a0b5b3937f59eMichael Jurka        final boolean debug = false;
833a9fcedbcd235372cd2ab64f825a0b5b3937f59eMichael Jurka        if (debug) {
843a9fcedbcd235372cd2ab64f825a0b5b3937f59eMichael Jurka            // Debug drawing for hit space
85eecf02da58adef5486bf0c9ff7127ea891f457a4Winson Chung            Paint p = new Paint();
86eecf02da58adef5486bf0c9ff7127ea891f457a4Winson Chung            p.setColor(0x6600FF00);
87eecf02da58adef5486bf0c9ff7127ea891f457a4Winson Chung            for (int i = getChildCount() - 1; i >= 0; i--) {
88eecf02da58adef5486bf0c9ff7127ea891f457a4Winson Chung                final View child = getChildAt(i);
89eecf02da58adef5486bf0c9ff7127ea891f457a4Winson Chung                final CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
90eecf02da58adef5486bf0c9ff7127ea891f457a4Winson Chung
91eecf02da58adef5486bf0c9ff7127ea891f457a4Winson Chung                canvas.drawRect(lp.x, lp.y, lp.x + lp.width, lp.y + lp.height, p);
92eecf02da58adef5486bf0c9ff7127ea891f457a4Winson Chung            }
93eecf02da58adef5486bf0c9ff7127ea891f457a4Winson Chung        }
94eecf02da58adef5486bf0c9ff7127ea891f457a4Winson Chung        super.dispatchDraw(canvas);
95eecf02da58adef5486bf0c9ff7127ea891f457a4Winson Chung    }
96eecf02da58adef5486bf0c9ff7127ea891f457a4Winson Chung
97eecf02da58adef5486bf0c9ff7127ea891f457a4Winson Chung    @Override
988c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
998c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        int count = getChildCount();
100ec40b2b90c649be3b513af2ba174db56b54b64f6Adam Cohen
101ec40b2b90c649be3b513af2ba174db56b54b64f6Adam Cohen        int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
102ec40b2b90c649be3b513af2ba174db56b54b64f6Adam Cohen        int heightSpecSize =  MeasureSpec.getSize(heightMeasureSpec);
103ec40b2b90c649be3b513af2ba174db56b54b64f6Adam Cohen        setMeasuredDimension(widthSpecSize, heightSpecSize);
104ec40b2b90c649be3b513af2ba174db56b54b64f6Adam Cohen
1058c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        for (int i = 0; i < count; i++) {
1068c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka            View child = getChildAt(i);
1072824b0750e978e5a63f804a42e9eedba53e8d21dVladimir Marko            if (child.getVisibility() != GONE) {
1082824b0750e978e5a63f804a42e9eedba53e8d21dVladimir Marko                measureChild(child);
1092824b0750e978e5a63f804a42e9eedba53e8d21dVladimir Marko            }
1108c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        }
1118c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    }
1128c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka
113bfbfd26c627a18f8e1e3e6d0e53e78feab360203Adam Cohen    public void setupLp(CellLayout.LayoutParams lp) {
1142374abfda3e53f84e005df8923170308e4df8c03Adam Cohen        lp.setup(mCellWidth, mCellHeight, mWidthGap, mHeightGap, invertLayoutHorizontally(),
1152374abfda3e53f84e005df8923170308e4df8c03Adam Cohen                mCountX);
1162374abfda3e53f84e005df8923170308e4df8c03Adam Cohen    }
1172374abfda3e53f84e005df8923170308e4df8c03Adam Cohen
1182374abfda3e53f84e005df8923170308e4df8c03Adam Cohen    // Set whether or not to invert the layout horizontally if the layout is in RTL mode.
1192374abfda3e53f84e005df8923170308e4df8c03Adam Cohen    public void setInvertIfRtl(boolean invert) {
1202374abfda3e53f84e005df8923170308e4df8c03Adam Cohen        mInvertIfRtl = invert;
121bfbfd26c627a18f8e1e3e6d0e53e78feab360203Adam Cohen    }
122bfbfd26c627a18f8e1e3e6d0e53e78feab360203Adam Cohen
1235f8afe6280eae34620067696173e71943e1a30a3Winson Chung    public void setIsHotseat(boolean isHotseat) {
1245f8afe6280eae34620067696173e71943e1a30a3Winson Chung        mIsHotseatLayout = isHotseat;
1255f8afe6280eae34620067696173e71943e1a30a3Winson Chung    }
1265f8afe6280eae34620067696173e71943e1a30a3Winson Chung
1273a6e7f330e680ef718ca7c0921d842efb4d8bbaeWinson Chung    int getCellContentWidth() {
1283a6e7f330e680ef718ca7c0921d842efb4d8bbaeWinson Chung        final LauncherAppState app = LauncherAppState.getInstance();
1293a6e7f330e680ef718ca7c0921d842efb4d8bbaeWinson Chung        final DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
1303a6e7f330e680ef718ca7c0921d842efb4d8bbaeWinson Chung        return Math.min(getMeasuredHeight(), mIsHotseatLayout ?
1313a6e7f330e680ef718ca7c0921d842efb4d8bbaeWinson Chung                grid.hotseatCellWidthPx: grid.cellWidthPx);
1323a6e7f330e680ef718ca7c0921d842efb4d8bbaeWinson Chung    }
1333a6e7f330e680ef718ca7c0921d842efb4d8bbaeWinson Chung
13469737c3e49ff3edc42899609fdbc96e356f8638eWinson Chung    int getCellContentHeight() {
13569737c3e49ff3edc42899609fdbc96e356f8638eWinson Chung        final LauncherAppState app = LauncherAppState.getInstance();
13669737c3e49ff3edc42899609fdbc96e356f8638eWinson Chung        final DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
13769737c3e49ff3edc42899609fdbc96e356f8638eWinson Chung        return Math.min(getMeasuredHeight(), mIsHotseatLayout ?
13869737c3e49ff3edc42899609fdbc96e356f8638eWinson Chung                grid.hotseatCellHeightPx : grid.cellHeightPx);
13969737c3e49ff3edc42899609fdbc96e356f8638eWinson Chung    }
14069737c3e49ff3edc42899609fdbc96e356f8638eWinson Chung
141d5e42733799817d11d739b0a882da8dda721126dAdam Cohen    public void measureChild(View child) {
1425f8afe6280eae34620067696173e71943e1a30a3Winson Chung        final LauncherAppState app = LauncherAppState.getInstance();
1435f8afe6280eae34620067696173e71943e1a30a3Winson Chung        final DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
144d5e42733799817d11d739b0a882da8dda721126dAdam Cohen        final int cellWidth = mCellWidth;
145d5e42733799817d11d739b0a882da8dda721126dAdam Cohen        final int cellHeight = mCellHeight;
146d5e42733799817d11d739b0a882da8dda721126dAdam Cohen        CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
147ec40b2b90c649be3b513af2ba174db56b54b64f6Adam Cohen        if (!lp.isFullscreen) {
148ec40b2b90c649be3b513af2ba174db56b54b64f6Adam Cohen            lp.setup(cellWidth, cellHeight, mWidthGap, mHeightGap, invertLayoutHorizontally(),
149ec40b2b90c649be3b513af2ba174db56b54b64f6Adam Cohen                    mCountX);
1505f8afe6280eae34620067696173e71943e1a30a3Winson Chung
1515f8afe6280eae34620067696173e71943e1a30a3Winson Chung            if (child instanceof LauncherAppWidgetHostView) {
1525f8afe6280eae34620067696173e71943e1a30a3Winson Chung                // Widgets have their own padding, so skip
1535f8afe6280eae34620067696173e71943e1a30a3Winson Chung            } else {
1545f8afe6280eae34620067696173e71943e1a30a3Winson Chung                // Otherwise, center the icon
15569737c3e49ff3edc42899609fdbc96e356f8638eWinson Chung                int cHeight = getCellContentHeight();
1565f8afe6280eae34620067696173e71943e1a30a3Winson Chung                int cellPaddingY = (int) Math.max(0, ((lp.height - cHeight) / 2f));
157cdef04403695872db8be6342b8dacd437ee02d52Winson Chung                int cellPaddingX = (int) (grid.edgeMarginPx / 2f);
158cdef04403695872db8be6342b8dacd437ee02d52Winson Chung                child.setPadding(cellPaddingX, cellPaddingY, cellPaddingX, 0);
1595f8afe6280eae34620067696173e71943e1a30a3Winson Chung            }
160ec40b2b90c649be3b513af2ba174db56b54b64f6Adam Cohen        } else {
161ec40b2b90c649be3b513af2ba174db56b54b64f6Adam Cohen            lp.x = 0;
162ec40b2b90c649be3b513af2ba174db56b54b64f6Adam Cohen            lp.y = 0;
163ec40b2b90c649be3b513af2ba174db56b54b64f6Adam Cohen            lp.width = getMeasuredWidth();
164ec40b2b90c649be3b513af2ba174db56b54b64f6Adam Cohen            lp.height = getMeasuredHeight();
165ec40b2b90c649be3b513af2ba174db56b54b64f6Adam Cohen        }
166d5e42733799817d11d739b0a882da8dda721126dAdam Cohen        int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
167d5e42733799817d11d739b0a882da8dda721126dAdam Cohen        int childheightMeasureSpec = MeasureSpec.makeMeasureSpec(lp.height,
168d5e42733799817d11d739b0a882da8dda721126dAdam Cohen                MeasureSpec.EXACTLY);
169d5e42733799817d11d739b0a882da8dda721126dAdam Cohen        child.measure(childWidthMeasureSpec, childheightMeasureSpec);
170d5e42733799817d11d739b0a882da8dda721126dAdam Cohen    }
171d5e42733799817d11d739b0a882da8dda721126dAdam Cohen
172fc3c1edf7bbc3f7cb23e79520731d13ccc2da046Sunny Goyal    public boolean invertLayoutHorizontally() {
1737066003b2032a49ae5e59dab9b706259bdeb7e6eSunny Goyal        return mInvertIfRtl && Utilities.isRtl(getResources());
1742374abfda3e53f84e005df8923170308e4df8c03Adam Cohen    }
1752374abfda3e53f84e005df8923170308e4df8c03Adam Cohen
1768c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    @Override
1778c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    protected void onLayout(boolean changed, int l, int t, int r, int b) {
1788c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        int count = getChildCount();
1798c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        for (int i = 0; i < count; i++) {
1808c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka            final View child = getChildAt(i);
1818c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka            if (child.getVisibility() != GONE) {
1828c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka                CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
1838c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka                int childLeft = lp.x;
1848c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka                int childTop = lp.y;
1858c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka                child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);
1868c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka
1878c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka                if (lp.dropped) {
1888c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka                    lp.dropped = false;
1898c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka
1908c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka                    final int[] cellXY = mTmpCellXY;
1918c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka                    getLocationOnScreen(cellXY);
1928c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka                    mWallpaperManager.sendWallpaperCommand(getWindowToken(),
1938c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka                            WallpaperManager.COMMAND_DROP,
1948c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka                            cellXY[0] + childLeft + lp.width / 2,
1958c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka                            cellXY[1] + childTop + lp.height / 2, 0, null);
1968c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka                }
1978c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka            }
1988c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        }
1998c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    }
2008c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka
2018c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    @Override
202e6235dd225404239b55c459245543f3302326112Michael Jurka    public boolean shouldDelayChildPressedState() {
203e6235dd225404239b55c459245543f3302326112Michael Jurka        return false;
204e6235dd225404239b55c459245543f3302326112Michael Jurka    }
205e6235dd225404239b55c459245543f3302326112Michael Jurka
206e6235dd225404239b55c459245543f3302326112Michael Jurka    @Override
2078c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    public void requestChildFocus(View child, View focused) {
2088c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        super.requestChildFocus(child, focused);
2098c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        if (child != null) {
2108c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka            Rect r = new Rect();
2118c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka            child.getDrawingRect(r);
2128c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka            requestRectangleOnScreen(r);
2138c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        }
2148c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    }
2158c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka
2168c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    @Override
2178c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    public void cancelLongPress() {
2188c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        super.cancelLongPress();
2198c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka
2208c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        // Cancel long press for all children
2218c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        final int count = getChildCount();
2228c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        for (int i = 0; i < count; i++) {
2238c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka            final View child = getChildAt(i);
2248c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka            child.cancelLongPress();
2258c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        }
2268c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    }
2278c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka
2288c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    @Override
2298c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    protected void setChildrenDrawingCacheEnabled(boolean enabled) {
2308c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        final int count = getChildCount();
2318c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        for (int i = 0; i < count; i++) {
2328c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka            final View view = getChildAt(i);
2338c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka            view.setDrawingCacheEnabled(enabled);
2348c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka            // Update the drawing caches
2358182e5bc3c2d1a0140df345599b89369d457bb4aAdam Cohen            if (!view.isHardwareAccelerated() && enabled) {
2368c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka                view.buildDrawingCache(true);
2378c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka            }
2388c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        }
2398c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    }
2408c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka
2418c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    @Override
2428c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    protected void setChildrenDrawnWithCacheEnabled(boolean enabled) {
2438c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka        super.setChildrenDrawnWithCacheEnabled(enabled);
2448c920dd3683d752aa4c43e964831ce53f9b72887Michael Jurka    }
245d4844c3e731b00547a31f23a00f8bd4a271e2b62Adam Cohen}
246