Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 18 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 19 | import android.appwidget.AppWidgetHostView; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 20 | import android.appwidget.AppWidgetManager; |
| 21 | import android.appwidget.AppWidgetProviderInfo; |
| 22 | import android.content.ComponentName; |
| 23 | import android.content.Context; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 24 | import android.content.pm.PackageManager; |
| 25 | import android.content.pm.ResolveInfo; |
| 26 | import android.content.res.Resources; |
| 27 | import android.content.res.TypedArray; |
| 28 | import android.graphics.Bitmap; |
Michael Jurka | 05713af | 2013-01-23 12:39:24 +0100 | [diff] [blame] | 29 | import android.graphics.Point; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 30 | import android.graphics.Rect; |
| 31 | import android.graphics.drawable.Drawable; |
Adam Cohen | 9e05a5e | 2012-09-10 15:53:09 -0700 | [diff] [blame] | 32 | import android.os.Build; |
| 33 | import android.os.Bundle; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 34 | import android.util.AttributeSet; |
| 35 | import android.util.Log; |
Winson Chung | 72d8b39 | 2011-07-29 13:56:44 -0700 | [diff] [blame] | 36 | import android.view.Gravity; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 37 | import android.view.LayoutInflater; |
| 38 | import android.view.View; |
Winson Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 39 | import android.widget.GridLayout; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 40 | import android.widget.ImageView; |
Winson Chung | 55b6550 | 2011-05-26 12:03:43 -0700 | [diff] [blame] | 41 | import android.widget.Toast; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 42 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 43 | import com.android.launcher3.DropTarget.DragObject; |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 44 | import com.android.launcher3.FocusHelper.PagedViewKeyListener; |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 45 | import com.android.launcher3.compat.AppWidgetManagerCompat; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 46 | import com.android.launcher3.util.Thunk; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 47 | |
| 48 | import java.util.ArrayList; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * The Apps/Customize page that displays all the applications, widgets, and shortcuts. |
| 52 | */ |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 53 | public class AppsCustomizePagedView extends PagedViewWithDraggableItems implements |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 54 | View.OnClickListener, DragSource, |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 55 | PagedViewWidget.ShortPressListener, LauncherTransitionable { |
Adam Cohen | 0e56cc9 | 2012-05-11 15:57:05 -0700 | [diff] [blame] | 56 | static final String TAG = "AppsCustomizePagedView"; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 57 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 58 | private static Rect sTmpRect = new Rect(); |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 59 | private static final int[] sTempPosArray = new int[2]; |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 60 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 61 | /** |
| 62 | * The different content types that this paged view can show. |
| 63 | */ |
| 64 | public enum ContentType { |
Winson Chung | 6a26e5b | 2011-05-26 14:36:06 -0700 | [diff] [blame] | 65 | Widgets |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 66 | } |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 67 | private ContentType mContentType = ContentType.Widgets; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 68 | |
| 69 | // Refs |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 70 | @Thunk Launcher mLauncher; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 71 | private DragController mDragController; |
| 72 | private final LayoutInflater mLayoutInflater; |
| 73 | private final PackageManager mPackageManager; |
| 74 | |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 75 | // Save and Restore |
| 76 | private int mSaveInstanceStateItemIndex = -1; |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 77 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 78 | // Content |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 79 | private ArrayList<Object> mWidgets; |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 80 | |
| 81 | // Caching |
Winson Chung | 4dbea79 | 2011-05-05 14:21:32 -0700 | [diff] [blame] | 82 | private IconCache mIconCache; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 83 | |
| 84 | // Dimens |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 85 | private int mContentWidth, mContentHeight; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 86 | @Thunk int mWidgetCountX, mWidgetCountY; |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 87 | private int mNumWidgetPages; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 88 | |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 89 | private final PagedViewKeyListener mKeyListener = new PagedViewKeyListener(); |
| 90 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 91 | private Runnable mInflateWidgetRunnable = null; |
| 92 | private Runnable mBindWidgetRunnable = null; |
| 93 | static final int WIDGET_NO_CLEANUP_REQUIRED = -1; |
Adam Cohen | 21a170b | 2012-05-30 15:17:06 -0700 | [diff] [blame] | 94 | static final int WIDGET_PRELOAD_PENDING = 0; |
| 95 | static final int WIDGET_BOUND = 1; |
| 96 | static final int WIDGET_INFLATED = 2; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 97 | int mWidgetCleanupState = WIDGET_NO_CLEANUP_REQUIRED; |
| 98 | int mWidgetLoadingId = -1; |
Adam Cohen | 1b36dc3 | 2012-02-13 19:27:37 -0800 | [diff] [blame] | 99 | PendingAddWidgetInfo mCreateWidgetInfo = null; |
Adam Cohen | 7a32664 | 2012-02-22 12:03:22 -0800 | [diff] [blame] | 100 | private boolean mDraggingWidget = false; |
Adam Cohen | a00673c | 2014-08-14 12:57:28 -0700 | [diff] [blame] | 101 | boolean mPageBackgroundsVisible = true; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 102 | |
Winson Chung | cb9ab4f | 2012-07-02 11:47:27 -0700 | [diff] [blame] | 103 | private Toast mWidgetInstructionToast; |
| 104 | |
Michael Jurka | 39e5d17 | 2012-03-12 18:36:12 -0700 | [diff] [blame] | 105 | // Deferral of loading widget previews during launcher transitions |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 106 | private boolean mInTransition; |
Michael Jurka | 39e5d17 | 2012-03-12 18:36:12 -0700 | [diff] [blame] | 107 | |
Michael Jurka | 05713af | 2013-01-23 12:39:24 +0100 | [diff] [blame] | 108 | WidgetPreviewLoader mWidgetPreviewLoader; |
| 109 | |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 110 | private boolean mInBulkBind; |
| 111 | private boolean mNeedToUpdatePageCountsAndInvalidateData; |
| 112 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 113 | public AppsCustomizePagedView(Context context, AttributeSet attrs) { |
| 114 | super(context, attrs); |
| 115 | mLayoutInflater = LayoutInflater.from(context); |
| 116 | mPackageManager = context.getPackageManager(); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 117 | mWidgets = new ArrayList<>(); |
Daniel Sandler | cc8befa | 2013-06-11 14:45:48 -0400 | [diff] [blame] | 118 | mIconCache = (LauncherAppState.getInstance()).getIconCache(); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 119 | |
| 120 | // Save the default widget preview background |
Winson Chung | 6032e7e | 2011-11-08 15:47:17 -0800 | [diff] [blame] | 121 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AppsCustomizePagedView, 0, 0); |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 122 | mWidgetCountX = a.getInt(R.styleable.AppsCustomizePagedView_widgetCountX, 2); |
| 123 | mWidgetCountY = a.getInt(R.styleable.AppsCustomizePagedView_widgetCountY, 2); |
| 124 | a.recycle(); |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 125 | |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 126 | // The padding on the non-matched dimension for the default widget preview icons |
| 127 | // (top + bottom) |
Adam Cohen | 2591f6a | 2011-10-25 14:36:40 -0700 | [diff] [blame] | 128 | mFadeInAdjacentScreens = false; |
Svetoslav Ganov | 08055f6 | 2012-05-15 11:06:36 -0700 | [diff] [blame] | 129 | |
| 130 | // Unless otherwise specified this view is important for accessibility. |
| 131 | if (getImportantForAccessibility() == View.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { |
| 132 | setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); |
| 133 | } |
Adam Cohen | 1d3d4f1 | 2014-08-14 19:14:52 -0700 | [diff] [blame] | 134 | setSinglePageInViewport(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | @Override |
| 138 | protected void init() { |
| 139 | super.init(); |
Winson Chung | 6a87740 | 2011-10-26 14:51:44 -0700 | [diff] [blame] | 140 | mCenterPagesVertically = false; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 141 | |
| 142 | Context context = getContext(); |
| 143 | Resources r = context.getResources(); |
| 144 | setDragSlopeThreshold(r.getInteger(R.integer.config_appsCustomizeDragSlopeThreshold)/100f); |
| 145 | } |
| 146 | |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 147 | public void onFinishInflate() { |
| 148 | super.onFinishInflate(); |
| 149 | |
| 150 | LauncherAppState app = LauncherAppState.getInstance(); |
| 151 | DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); |
| 152 | setPadding(grid.edgeMarginPx, 2 * grid.edgeMarginPx, |
| 153 | grid.edgeMarginPx, 2 * grid.edgeMarginPx); |
| 154 | } |
| 155 | |
Winson Chung | 67ca7e4 | 2013-10-31 16:53:19 -0700 | [diff] [blame] | 156 | void setWidgetsPageIndicatorPadding(int pageIndicatorHeight) { |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 157 | setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), pageIndicatorHeight); |
Winson Chung | 67ca7e4 | 2013-10-31 16:53:19 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Michael Jurka | 9c5cc5a | 2014-01-09 14:59:22 +0100 | [diff] [blame] | 160 | WidgetPreviewLoader getWidgetPreviewLoader() { |
| 161 | if (mWidgetPreviewLoader == null) { |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 162 | mWidgetPreviewLoader = LauncherAppState.getInstance().getWidgetCache(); |
Michael Jurka | 9c5cc5a | 2014-01-09 14:59:22 +0100 | [diff] [blame] | 163 | } |
| 164 | return mWidgetPreviewLoader; |
| 165 | } |
| 166 | |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 167 | /** Returns the item index of the center item on this page so that we can restore to this |
| 168 | * item index when we rotate. */ |
| 169 | private int getMiddleComponentIndexOnCurrentPage() { |
| 170 | int i = -1; |
| 171 | if (getPageCount() > 0) { |
| 172 | int currentPage = getCurrentPage(); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 173 | if (mContentType == ContentType.Widgets) { |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 174 | PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(currentPage); |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 175 | int numItemsPerPage = mWidgetCountX * mWidgetCountY; |
| 176 | int childCount = layout.getChildCount(); |
| 177 | if (childCount > 0) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 178 | i = (currentPage * numItemsPerPage) + (childCount / 2); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 179 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 180 | } else { |
| 181 | throw new RuntimeException("Invalid ContentType"); |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | return i; |
| 185 | } |
| 186 | |
| 187 | /** Get the index of the item to restore to if we need to restore the current page. */ |
| 188 | int getSaveInstanceStateIndex() { |
| 189 | if (mSaveInstanceStateItemIndex == -1) { |
| 190 | mSaveInstanceStateItemIndex = getMiddleComponentIndexOnCurrentPage(); |
| 191 | } |
| 192 | return mSaveInstanceStateItemIndex; |
| 193 | } |
| 194 | |
| 195 | /** Returns the page in the current orientation which is expected to contain the specified |
| 196 | * item index. */ |
| 197 | int getPageForComponent(int index) { |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 198 | if (index < 0) return 0; |
| 199 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 200 | int numItemsPerPage = mWidgetCountX * mWidgetCountY; |
| 201 | return index / numItemsPerPage; |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 204 | /** Restores the page for an item at the specified index */ |
| 205 | void restorePageForIndex(int index) { |
| 206 | if (index < 0) return; |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 207 | mSaveInstanceStateItemIndex = index; |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Winson Chung | 4b0ed8c | 2011-10-19 15:24:49 -0700 | [diff] [blame] | 210 | private void updatePageCounts() { |
| 211 | mNumWidgetPages = (int) Math.ceil(mWidgets.size() / |
| 212 | (float) (mWidgetCountX * mWidgetCountY)); |
Winson Chung | 4b0ed8c | 2011-10-19 15:24:49 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 215 | protected void onDataReady(int width, int height) { |
Winson Chung | 4b0ed8c | 2011-10-19 15:24:49 -0700 | [diff] [blame] | 216 | updatePageCounts(); |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 217 | |
Winson Chung | db1138b | 2011-06-30 14:39:35 -0700 | [diff] [blame] | 218 | // Force a measure to update recalculate the gaps |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 219 | mContentWidth = getMeasuredWidth() - getPaddingLeft() - getPaddingRight(); |
| 220 | mContentHeight = getMeasuredHeight() - getPaddingTop() - getPaddingBottom(); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 221 | |
Adam Cohen | 6c5891a | 2014-07-09 23:53:15 -0700 | [diff] [blame] | 222 | final boolean hostIsTransitioning = getTabHost().isInTransition(); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 223 | int page = getPageForComponent(mSaveInstanceStateItemIndex); |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 224 | invalidatePageData(Math.max(0, page), hostIsTransitioning); |
Winson Chung | 3f4e142 | 2011-11-17 14:58:51 -0800 | [diff] [blame] | 225 | } |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 226 | |
Adam Cohen | a00673c | 2014-08-14 12:57:28 -0700 | [diff] [blame] | 227 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
| 228 | super.onLayout(changed, l, t, r, b); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 229 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 230 | if (!isDataReady()) { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 231 | if (!mWidgets.isEmpty()) { |
Adam Cohen | 69ed200 | 2014-08-27 21:27:01 -0700 | [diff] [blame] | 232 | post(new Runnable() { |
| 233 | // This code triggers requestLayout so must be posted outside of the |
| 234 | // layout pass. |
| 235 | public void run() { |
Sunny Goyal | fafca52 | 2014-11-03 11:30:01 -0800 | [diff] [blame] | 236 | if (Utilities.isViewAttachedToWindow(AppsCustomizePagedView.this)) { |
Adam Cohen | 0d2adfb | 2014-09-04 01:27:53 +0200 | [diff] [blame] | 237 | setDataIsReady(); |
| 238 | onDataReady(getMeasuredWidth(), getMeasuredHeight()); |
| 239 | } |
Adam Cohen | 69ed200 | 2014-08-27 21:27:01 -0700 | [diff] [blame] | 240 | } |
| 241 | }); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 242 | } |
| 243 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 246 | public void onPackagesUpdated(ArrayList<Object> widgetsAndShortcuts) { |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 247 | LauncherAppState app = LauncherAppState.getInstance(); |
| 248 | DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); |
| 249 | |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 250 | // Get the list of widgets and shortcuts |
| 251 | mWidgets.clear(); |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 252 | for (Object o : widgetsAndShortcuts) { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 253 | if (o instanceof LauncherAppWidgetProviderInfo) { |
| 254 | LauncherAppWidgetProviderInfo widget = (LauncherAppWidgetProviderInfo) o; |
| 255 | if (!app.shouldShowAppOrWidgetProvider(widget.provider) && !widget.isCustomWidget) { |
Bjorn Bringert | 1307f63 | 2013-10-03 22:31:03 +0100 | [diff] [blame] | 256 | continue; |
| 257 | } |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 258 | |
| 259 | if (widget.minSpanX > 0 && widget.minSpanY > 0) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 260 | // Ensure that all widgets we show can be added on a workspace of this size |
| 261 | int[] spanXY = Launcher.getSpanForWidget(mLauncher, widget); |
| 262 | int[] minSpanXY = Launcher.getMinSpanForWidget(mLauncher, widget); |
| 263 | int minSpanX = Math.min(spanXY[0], minSpanXY[0]); |
| 264 | int minSpanY = Math.min(spanXY[1], minSpanXY[1]); |
Winson Chung | 892c74d | 2013-08-22 16:15:50 -0700 | [diff] [blame] | 265 | if (minSpanX <= (int) grid.numColumns && |
| 266 | minSpanY <= (int) grid.numRows) { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 267 | mWidgets.add(widget); |
| 268 | } else { |
| 269 | Log.e(TAG, "Widget " + widget.provider + " can not fit on this device (" + |
| 270 | widget.minWidth + ", " + widget.minHeight + ")"); |
| 271 | } |
Winson Chung | fd39d8e | 2012-06-05 10:12:48 -0700 | [diff] [blame] | 272 | } else { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 273 | Log.e(TAG, "Widget " + widget.provider + " has invalid dimensions (" + |
| 274 | widget.minWidth + ", " + widget.minHeight + ")"); |
Winson Chung | a5c9636 | 2012-04-12 14:04:41 -0700 | [diff] [blame] | 275 | } |
Michael Jurka | dbc1f65 | 2011-11-10 17:02:56 -0800 | [diff] [blame] | 276 | } else { |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 277 | // just add shortcuts |
| 278 | mWidgets.add(o); |
Michael Jurka | dbc1f65 | 2011-11-10 17:02:56 -0800 | [diff] [blame] | 279 | } |
| 280 | } |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 281 | |
Michael Jurka | c402cd9 | 2013-05-20 15:49:32 +0200 | [diff] [blame] | 282 | updatePageCountsAndInvalidateData(); |
| 283 | } |
| 284 | |
| 285 | public void setBulkBind(boolean bulkBind) { |
| 286 | if (bulkBind) { |
| 287 | mInBulkBind = true; |
| 288 | } else { |
| 289 | mInBulkBind = false; |
| 290 | if (mNeedToUpdatePageCountsAndInvalidateData) { |
| 291 | updatePageCountsAndInvalidateData(); |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | private void updatePageCountsAndInvalidateData() { |
| 297 | if (mInBulkBind) { |
| 298 | mNeedToUpdatePageCountsAndInvalidateData = true; |
| 299 | } else { |
| 300 | updatePageCounts(); |
| 301 | invalidateOnDataChange(); |
| 302 | mNeedToUpdatePageCountsAndInvalidateData = false; |
| 303 | } |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | @Override |
| 307 | public void onClick(View v) { |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 308 | // When we have exited all apps or are in transition, disregard clicks |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 309 | if (!mLauncher.isWidgetsViewVisible() |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 310 | || mLauncher.getWorkspace().isSwitchingState() |
| 311 | || !(v instanceof PagedViewWidget)) return; |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 312 | |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 313 | // Let the user know that they have to long press to add a widget |
| 314 | if (mWidgetInstructionToast != null) { |
| 315 | mWidgetInstructionToast.cancel(); |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 316 | } |
Sunny Goyal | 508da15 | 2014-08-14 10:53:27 -0700 | [diff] [blame] | 317 | mWidgetInstructionToast = Toast.makeText(getContext(),R.string.long_press_widget_to_add, |
| 318 | Toast.LENGTH_SHORT); |
| 319 | mWidgetInstructionToast.show(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | /* |
| 323 | * PagedViewWithDraggableItems implementation |
| 324 | */ |
| 325 | @Override |
| 326 | protected void determineDraggingStart(android.view.MotionEvent ev) { |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 327 | } |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 328 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 329 | static Bundle getDefaultOptionsForWidget(Launcher launcher, PendingAddWidgetInfo info) { |
Adam Cohen | 9e05a5e | 2012-09-10 15:53:09 -0700 | [diff] [blame] | 330 | Bundle options = null; |
| 331 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 332 | AppWidgetResizeFrame.getWidgetSizeRanges(launcher, info.spanX, info.spanY, sTmpRect); |
| 333 | Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(launcher, |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 334 | info.componentName, null); |
| 335 | |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 336 | float density = launcher.getResources().getDisplayMetrics().density; |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 337 | int xPaddingDips = (int) ((padding.left + padding.right) / density); |
| 338 | int yPaddingDips = (int) ((padding.top + padding.bottom) / density); |
| 339 | |
Adam Cohen | 9e05a5e | 2012-09-10 15:53:09 -0700 | [diff] [blame] | 340 | options = new Bundle(); |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 341 | options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 342 | sTmpRect.left - xPaddingDips); |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 343 | options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 344 | sTmpRect.top - yPaddingDips); |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 345 | options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 346 | sTmpRect.right - xPaddingDips); |
Adam Cohen | aaa5c21 | 2012-10-05 18:14:31 -0700 | [diff] [blame] | 347 | options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, |
Sunny Goyal | ff57227 | 2014-07-23 13:58:07 -0700 | [diff] [blame] | 348 | sTmpRect.bottom - yPaddingDips); |
Adam Cohen | 9e05a5e | 2012-09-10 15:53:09 -0700 | [diff] [blame] | 349 | } |
| 350 | return options; |
| 351 | } |
| 352 | |
Adam Cohen | f1dcdf6 | 2012-05-10 16:51:52 -0700 | [diff] [blame] | 353 | private void preloadWidget(final PendingAddWidgetInfo info) { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 354 | final LauncherAppWidgetProviderInfo pInfo = info.info; |
| 355 | final Bundle options = pInfo.isCustomWidget ? null : |
| 356 | getDefaultOptionsForWidget(mLauncher, info); |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 357 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 358 | if (pInfo.configure != null) { |
Adam Cohen | dd70d66 | 2012-10-04 16:53:44 -0700 | [diff] [blame] | 359 | info.bindOptions = options; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 360 | return; |
| 361 | } |
| 362 | |
Adam Cohen | 21a170b | 2012-05-30 15:17:06 -0700 | [diff] [blame] | 363 | mWidgetCleanupState = WIDGET_PRELOAD_PENDING; |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 364 | mBindWidgetRunnable = new Runnable() { |
| 365 | @Override |
| 366 | public void run() { |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 367 | if (pInfo.isCustomWidget) { |
| 368 | mWidgetCleanupState = WIDGET_BOUND; |
| 369 | return; |
| 370 | } |
| 371 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 372 | mWidgetLoadingId = mLauncher.getAppWidgetHost().allocateAppWidgetId(); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 373 | if(AppWidgetManagerCompat.getInstance(mLauncher).bindAppWidgetIdIfAllowed( |
| 374 | mWidgetLoadingId, pInfo, options)) { |
| 375 | mWidgetCleanupState = WIDGET_BOUND; |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 376 | } |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 377 | |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 378 | } |
| 379 | }; |
| 380 | post(mBindWidgetRunnable); |
| 381 | |
| 382 | mInflateWidgetRunnable = new Runnable() { |
| 383 | @Override |
| 384 | public void run() { |
Michael Jurka | 1637d6d | 2012-08-03 13:35:01 -0700 | [diff] [blame] | 385 | if (mWidgetCleanupState != WIDGET_BOUND) { |
| 386 | return; |
| 387 | } |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 388 | AppWidgetHostView hostView = mLauncher.getAppWidgetHost().createView( |
| 389 | getContext(), mWidgetLoadingId, pInfo); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 390 | info.boundWidget = hostView; |
| 391 | mWidgetCleanupState = WIDGET_INFLATED; |
Adam Cohen | ef3dd6e | 2012-02-14 20:54:05 -0800 | [diff] [blame] | 392 | hostView.setVisibility(INVISIBLE); |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 393 | int[] unScaledSize = mLauncher.getWorkspace().estimateItemSize(info, false); |
Adam Cohen | 1f36270 | 2012-04-04 14:58:12 -0700 | [diff] [blame] | 394 | |
| 395 | // We want the first widget layout to be the correct size. This will be important |
| 396 | // for width size reporting to the AppWidgetManager. |
| 397 | DragLayer.LayoutParams lp = new DragLayer.LayoutParams(unScaledSize[0], |
| 398 | unScaledSize[1]); |
| 399 | lp.x = lp.y = 0; |
| 400 | lp.customPosition = true; |
| 401 | hostView.setLayoutParams(lp); |
Adam Cohen | ef3dd6e | 2012-02-14 20:54:05 -0800 | [diff] [blame] | 402 | mLauncher.getDragLayer().addView(hostView); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 403 | } |
| 404 | }; |
| 405 | post(mInflateWidgetRunnable); |
| 406 | } |
| 407 | |
| 408 | @Override |
| 409 | public void onShortPress(View v) { |
| 410 | // We are anticipating a long press, and we use this time to load bind and instantiate |
| 411 | // the widget. This will need to be cleaned up if it turns out no long press occurs. |
Adam Cohen | 0e56cc9 | 2012-05-11 15:57:05 -0700 | [diff] [blame] | 412 | if (mCreateWidgetInfo != null) { |
| 413 | // Just in case the cleanup process wasn't properly executed. This shouldn't happen. |
| 414 | cleanupWidgetPreloading(false); |
| 415 | } |
Adam Cohen | 1b36dc3 | 2012-02-13 19:27:37 -0800 | [diff] [blame] | 416 | mCreateWidgetInfo = new PendingAddWidgetInfo((PendingAddWidgetInfo) v.getTag()); |
Adam Cohen | f1dcdf6 | 2012-05-10 16:51:52 -0700 | [diff] [blame] | 417 | preloadWidget(mCreateWidgetInfo); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 418 | } |
| 419 | |
Adam Cohen | 0e56cc9 | 2012-05-11 15:57:05 -0700 | [diff] [blame] | 420 | private void cleanupWidgetPreloading(boolean widgetWasAdded) { |
| 421 | if (!widgetWasAdded) { |
| 422 | // If the widget was not added, we may need to do further cleanup. |
| 423 | PendingAddWidgetInfo info = mCreateWidgetInfo; |
| 424 | mCreateWidgetInfo = null; |
Adam Cohen | 21a170b | 2012-05-30 15:17:06 -0700 | [diff] [blame] | 425 | |
| 426 | if (mWidgetCleanupState == WIDGET_PRELOAD_PENDING) { |
Adam Cohen | 21a170b | 2012-05-30 15:17:06 -0700 | [diff] [blame] | 427 | // We never did any preloading, so just remove pending callbacks to do so |
| 428 | removeCallbacks(mBindWidgetRunnable); |
| 429 | removeCallbacks(mInflateWidgetRunnable); |
| 430 | } else if (mWidgetCleanupState == WIDGET_BOUND) { |
| 431 | // Delete the widget id which was allocated |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 432 | if (mWidgetLoadingId != -1 && !info.isCustomWidget()) { |
Adam Cohen | 21a170b | 2012-05-30 15:17:06 -0700 | [diff] [blame] | 433 | mLauncher.getAppWidgetHost().deleteAppWidgetId(mWidgetLoadingId); |
| 434 | } |
| 435 | |
| 436 | // We never got around to inflating the widget, so remove the callback to do so. |
Adam Cohen | 0e56cc9 | 2012-05-11 15:57:05 -0700 | [diff] [blame] | 437 | removeCallbacks(mInflateWidgetRunnable); |
| 438 | } else if (mWidgetCleanupState == WIDGET_INFLATED) { |
Adam Cohen | 21a170b | 2012-05-30 15:17:06 -0700 | [diff] [blame] | 439 | // Delete the widget id which was allocated |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 440 | if (mWidgetLoadingId != -1 && !info.isCustomWidget()) { |
Adam Cohen | 21a170b | 2012-05-30 15:17:06 -0700 | [diff] [blame] | 441 | mLauncher.getAppWidgetHost().deleteAppWidgetId(mWidgetLoadingId); |
| 442 | } |
| 443 | |
Adam Cohen | 0e56cc9 | 2012-05-11 15:57:05 -0700 | [diff] [blame] | 444 | // The widget was inflated and added to the DragLayer -- remove it. |
| 445 | AppWidgetHostView widget = info.boundWidget; |
| 446 | mLauncher.getDragLayer().removeView(widget); |
| 447 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 448 | } |
| 449 | mWidgetCleanupState = WIDGET_NO_CLEANUP_REQUIRED; |
| 450 | mWidgetLoadingId = -1; |
Adam Cohen | 0e56cc9 | 2012-05-11 15:57:05 -0700 | [diff] [blame] | 451 | mCreateWidgetInfo = null; |
| 452 | PagedViewWidget.resetShortPressTarget(); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 453 | } |
| 454 | |
Adam Cohen | 7a32664 | 2012-02-22 12:03:22 -0800 | [diff] [blame] | 455 | @Override |
| 456 | public void cleanUpShortPress(View v) { |
| 457 | if (!mDraggingWidget) { |
Adam Cohen | 0e56cc9 | 2012-05-11 15:57:05 -0700 | [diff] [blame] | 458 | cleanupWidgetPreloading(false); |
Adam Cohen | 7a32664 | 2012-02-22 12:03:22 -0800 | [diff] [blame] | 459 | } |
| 460 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 461 | |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 462 | private boolean beginDraggingWidget(PagedViewWidget v) { |
Adam Cohen | 7a32664 | 2012-02-22 12:03:22 -0800 | [diff] [blame] | 463 | mDraggingWidget = true; |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 464 | // Get the widget preview as the drag representation |
| 465 | ImageView image = (ImageView) v.findViewById(R.id.widget_preview); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 466 | PendingAddItemInfo createItemInfo = (PendingAddItemInfo) v.getTag(); |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 467 | |
Adam Cohen | 88c5d2d | 2012-05-09 21:34:33 -0700 | [diff] [blame] | 468 | // If the ImageView doesn't have a drawable yet, the widget preview hasn't been loaded and |
| 469 | // we abort the drag. |
| 470 | if (image.getDrawable() == null) { |
| 471 | mDraggingWidget = false; |
| 472 | return false; |
| 473 | } |
| 474 | |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 475 | // Compose the drag image |
Winson Chung | 1120e03 | 2011-11-22 16:11:31 -0800 | [diff] [blame] | 476 | Bitmap preview; |
| 477 | Bitmap outline; |
Winson Chung | 72d5984 | 2012-02-22 13:51:36 -0800 | [diff] [blame] | 478 | float scale = 1f; |
Michael Jurka | 05713af | 2013-01-23 12:39:24 +0100 | [diff] [blame] | 479 | Point previewPadding = null; |
| 480 | |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 481 | if (createItemInfo instanceof PendingAddWidgetInfo) { |
Adam Cohen | 9247892 | 2012-05-17 13:43:29 -0700 | [diff] [blame] | 482 | // This can happen in some weird cases involving multi-touch. We can't start dragging |
| 483 | // the widget if this is null, so we break out. |
| 484 | if (mCreateWidgetInfo == null) { |
| 485 | return false; |
| 486 | } |
| 487 | |
Adam Cohen | 1b36dc3 | 2012-02-13 19:27:37 -0800 | [diff] [blame] | 488 | PendingAddWidgetInfo createWidgetInfo = mCreateWidgetInfo; |
| 489 | createItemInfo = createWidgetInfo; |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 490 | int[] size = mLauncher.getWorkspace().estimateItemSize(createWidgetInfo, true); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 491 | |
Winson Chung | 72d5984 | 2012-02-22 13:51:36 -0800 | [diff] [blame] | 492 | FastBitmapDrawable previewDrawable = (FastBitmapDrawable) image.getDrawable(); |
| 493 | float minScale = 1.25f; |
Sunny Goyal | 4cad753 | 2015-03-18 15:56:30 -0700 | [diff] [blame] | 494 | int maxWidth = Math.min((int) (previewDrawable.getIntrinsicWidth() * minScale), size[0]); |
Winson Chung | 72d5984 | 2012-02-22 13:51:36 -0800 | [diff] [blame] | 495 | |
Michael Jurka | 05713af | 2013-01-23 12:39:24 +0100 | [diff] [blame] | 496 | int[] previewSizeBeforeScale = new int[1]; |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 497 | preview = getWidgetPreviewLoader().generateWidgetPreview(createWidgetInfo.info, |
Sunny Goyal | 4cad753 | 2015-03-18 15:56:30 -0700 | [diff] [blame] | 498 | maxWidth, null, previewSizeBeforeScale); |
Michael Jurka | 05713af | 2013-01-23 12:39:24 +0100 | [diff] [blame] | 499 | // Compare the size of the drag preview to the preview in the AppsCustomize tray |
| 500 | int previewWidthInAppsCustomize = Math.min(previewSizeBeforeScale[0], |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 501 | v.getActualItemWidth()); |
Michael Jurka | 05713af | 2013-01-23 12:39:24 +0100 | [diff] [blame] | 502 | scale = previewWidthInAppsCustomize / (float) preview.getWidth(); |
| 503 | |
| 504 | // The bitmap in the AppsCustomize tray is always the the same size, so there |
| 505 | // might be extra pixels around the preview itself - this accounts for that |
| 506 | if (previewWidthInAppsCustomize < previewDrawable.getIntrinsicWidth()) { |
| 507 | int padding = |
| 508 | (previewDrawable.getIntrinsicWidth() - previewWidthInAppsCustomize) / 2; |
| 509 | previewPadding = new Point(padding, 0); |
| 510 | } |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 511 | } else { |
Michael Jurka | dac8591 | 2012-05-18 15:04:49 -0700 | [diff] [blame] | 512 | PendingAddShortcutInfo createShortcutInfo = (PendingAddShortcutInfo) v.getTag(); |
| 513 | Drawable icon = mIconCache.getFullResIcon(createShortcutInfo.shortcutActivityInfo); |
Sunny Goyal | ffe83f1 | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 514 | preview = Utilities.createIconBitmap(icon, mLauncher); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 515 | createItemInfo.spanX = createItemInfo.spanY = 1; |
| 516 | } |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 517 | |
Michael Jurka | 8c3339b | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 518 | // Don't clip alpha values for the drag outline if we're using the default widget preview |
| 519 | boolean clipAlpha = !(createItemInfo instanceof PendingAddWidgetInfo && |
| 520 | (((PendingAddWidgetInfo) createItemInfo).previewImage == 0)); |
Peter Ng | 8db7000 | 2011-10-25 15:40:08 -0700 | [diff] [blame] | 521 | |
Winson Chung | 1120e03 | 2011-11-22 16:11:31 -0800 | [diff] [blame] | 522 | // Save the preview for the outline generation, then dim the preview |
| 523 | outline = Bitmap.createScaledBitmap(preview, preview.getWidth(), preview.getHeight(), |
| 524 | false); |
Winson Chung | 1120e03 | 2011-11-22 16:11:31 -0800 | [diff] [blame] | 525 | |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 526 | // Start the drag |
Winson Chung | 641d71d | 2012-04-26 15:58:01 -0700 | [diff] [blame] | 527 | mLauncher.lockScreenOrientation(); |
Michael Jurka | 8c3339b | 2012-06-14 16:18:21 -0700 | [diff] [blame] | 528 | mLauncher.getWorkspace().onDragStartedWithItem(createItemInfo, outline, clipAlpha); |
Winson Chung | 1120e03 | 2011-11-22 16:11:31 -0800 | [diff] [blame] | 529 | mDragController.startDrag(image, preview, this, createItemInfo, |
Michael Jurka | 05713af | 2013-01-23 12:39:24 +0100 | [diff] [blame] | 530 | DragController.DRAG_ACTION_COPY, previewPadding, scale); |
Winson Chung | 1120e03 | 2011-11-22 16:11:31 -0800 | [diff] [blame] | 531 | outline.recycle(); |
| 532 | preview.recycle(); |
Adam Cohen | 88c5d2d | 2012-05-09 21:34:33 -0700 | [diff] [blame] | 533 | return true; |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 534 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 535 | |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 536 | @Override |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 537 | protected boolean beginDragging(final View v) { |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 538 | if (!super.beginDragging(v)) return false; |
| 539 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 540 | if (v instanceof PagedViewWidget) { |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 541 | if (!beginDraggingWidget((PagedViewWidget) v)) { |
Adam Cohen | 88c5d2d | 2012-05-09 21:34:33 -0700 | [diff] [blame] | 542 | return false; |
| 543 | } |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 544 | } else { |
| 545 | Log.e(TAG, "Unexpected dragging view: " + v); |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 546 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 547 | |
| 548 | // We delay entering spring-loaded mode slightly to make sure the UI |
| 549 | // thready is free of any work. |
| 550 | postDelayed(new Runnable() { |
| 551 | @Override |
| 552 | public void run() { |
Adam Cohen | 1b36dc3 | 2012-02-13 19:27:37 -0800 | [diff] [blame] | 553 | // We don't enter spring-loaded mode if the drag has been cancelled |
| 554 | if (mLauncher.getDragController().isDragging()) { |
Adam Cohen | 1b36dc3 | 2012-02-13 19:27:37 -0800 | [diff] [blame] | 555 | // Go into spring loaded mode (must happen before we startDrag()) |
| 556 | mLauncher.enterSpringLoadedDragMode(); |
| 557 | } |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 558 | } |
Winson Chung | 72d5984 | 2012-02-22 13:51:36 -0800 | [diff] [blame] | 559 | }, 150); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 560 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 561 | return true; |
| 562 | } |
Adam Cohen | 1b36dc3 | 2012-02-13 19:27:37 -0800 | [diff] [blame] | 563 | |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 564 | /** |
| 565 | * Clean up after dragging. |
| 566 | * |
| 567 | * @param target where the item was dragged to (can be null if the item was flung) |
| 568 | */ |
| 569 | private void endDragging(View target, boolean isFlingToDelete, boolean success) { |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 570 | if (isFlingToDelete || !success || (target != mLauncher.getWorkspace() && |
Jorim Jaggi | 55bd972 | 2014-01-16 15:30:42 -0800 | [diff] [blame] | 571 | !(target instanceof DeleteDropTarget) && !(target instanceof Folder))) { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 572 | // Exit spring loaded mode if we have not successfully dropped or have not handled the |
| 573 | // drop in Workspace |
Sunny Goyal | 8498eb4 | 2014-10-16 12:08:41 -0700 | [diff] [blame] | 574 | mLauncher.exitSpringLoadedDragModeDelayed(true, |
| 575 | Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); |
Adam Cohen | 689ff16 | 2014-05-08 17:27:56 -0700 | [diff] [blame] | 576 | mLauncher.unlockScreenOrientation(false); |
Adam Cohen | e97a3b3 | 2013-10-23 16:11:50 -0700 | [diff] [blame] | 577 | } else { |
| 578 | mLauncher.unlockScreenOrientation(false); |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 579 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 582 | @Override |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 583 | public View getContent() { |
Winson Chung | 7bb3752 | 2013-10-28 11:07:57 -0700 | [diff] [blame] | 584 | if (getChildCount() > 0) { |
| 585 | return getChildAt(0); |
| 586 | } |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 587 | return null; |
| 588 | } |
| 589 | |
| 590 | @Override |
| 591 | public void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace) { |
Michael Jurka | 39e5d17 | 2012-03-12 18:36:12 -0700 | [diff] [blame] | 592 | mInTransition = true; |
| 593 | if (toWorkspace) { |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 594 | cancelAllTasks(false); |
Michael Jurka | 39e5d17 | 2012-03-12 18:36:12 -0700 | [diff] [blame] | 595 | } |
| 596 | } |
| 597 | |
| 598 | @Override |
Michael Jurka | a35e35a | 2012-04-26 15:04:28 -0700 | [diff] [blame] | 599 | public void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace) { |
Michael Jurka | 39e5d17 | 2012-03-12 18:36:12 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | @Override |
| 603 | public void onLauncherTransitionStep(Launcher l, float t) { |
| 604 | } |
| 605 | |
| 606 | @Override |
| 607 | public void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace) { |
| 608 | mInTransition = false; |
Michael Jurka | 5e368ff | 2012-05-14 23:13:15 -0700 | [diff] [blame] | 609 | mForceDrawAllChildrenNextFrame = !toWorkspace; |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 610 | if (!toWorkspace) { |
| 611 | loadPreviewsForPage(getNextPage()); |
| 612 | } |
Michael Jurka | 39e5d17 | 2012-03-12 18:36:12 -0700 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | @Override |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 616 | public void onDropCompleted(View target, DragObject d, boolean isFlingToDelete, |
| 617 | boolean success) { |
| 618 | // Return early and wait for onFlingToDeleteCompleted if this was the result of a fling |
| 619 | if (isFlingToDelete) return; |
| 620 | |
| 621 | endDragging(target, false, success); |
Winson Chung | fc79c80 | 2011-05-02 13:35:34 -0700 | [diff] [blame] | 622 | |
| 623 | // Display an error message if the drag failed due to there not being enough space on the |
| 624 | // target layout we were dropping on. |
| 625 | if (!success) { |
| 626 | boolean showOutOfSpaceMessage = false; |
| 627 | if (target instanceof Workspace) { |
| 628 | int currentScreen = mLauncher.getCurrentWorkspaceScreen(); |
| 629 | Workspace workspace = (Workspace) target; |
| 630 | CellLayout layout = (CellLayout) workspace.getChildAt(currentScreen); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 631 | ItemInfo itemInfo = (ItemInfo) d.dragInfo; |
Winson Chung | fc79c80 | 2011-05-02 13:35:34 -0700 | [diff] [blame] | 632 | if (layout != null) { |
| 633 | layout.calculateSpans(itemInfo); |
| 634 | showOutOfSpaceMessage = |
| 635 | !layout.findCellForSpan(null, itemInfo.spanX, itemInfo.spanY); |
| 636 | } |
| 637 | } |
Winson Chung | fc79c80 | 2011-05-02 13:35:34 -0700 | [diff] [blame] | 638 | if (showOutOfSpaceMessage) { |
Winson Chung | 93eef08 | 2012-03-23 15:59:27 -0700 | [diff] [blame] | 639 | mLauncher.showOutOfSpaceMessage(false); |
Winson Chung | fc79c80 | 2011-05-02 13:35:34 -0700 | [diff] [blame] | 640 | } |
Adam Cohen | 7a32664 | 2012-02-22 12:03:22 -0800 | [diff] [blame] | 641 | |
Winson Chung | 7bd1bbb | 2012-02-13 18:29:29 -0800 | [diff] [blame] | 642 | d.deferDragViewCleanupPostAnimation = false; |
Winson Chung | fc79c80 | 2011-05-02 13:35:34 -0700 | [diff] [blame] | 643 | } |
Adam Cohen | 0e56cc9 | 2012-05-11 15:57:05 -0700 | [diff] [blame] | 644 | cleanupWidgetPreloading(success); |
Adam Cohen | 7a32664 | 2012-02-22 12:03:22 -0800 | [diff] [blame] | 645 | mDraggingWidget = false; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 648 | @Override |
| 649 | public void onFlingToDeleteCompleted() { |
| 650 | // We just dismiss the drag when we fling, so cleanup here |
| 651 | endDragging(null, true, true); |
Adam Cohen | 0e56cc9 | 2012-05-11 15:57:05 -0700 | [diff] [blame] | 652 | cleanupWidgetPreloading(false); |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 653 | mDraggingWidget = false; |
| 654 | } |
| 655 | |
| 656 | @Override |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 657 | public boolean supportsFlingToDelete() { |
Winson Chung | a48487a | 2012-03-20 16:19:37 -0700 | [diff] [blame] | 658 | return true; |
Winson Chung | 043f2af | 2012-03-01 16:09:54 -0800 | [diff] [blame] | 659 | } |
| 660 | |
Winson Chung | 7f0acdd | 2011-09-19 18:34:19 -0700 | [diff] [blame] | 661 | @Override |
Mathew Inwood | 1eeb3fc | 2013-11-25 17:01:34 +0000 | [diff] [blame] | 662 | public boolean supportsAppInfoDropTarget() { |
| 663 | return true; |
| 664 | } |
| 665 | |
| 666 | @Override |
| 667 | public boolean supportsDeleteDropTarget() { |
| 668 | return false; |
| 669 | } |
| 670 | |
| 671 | @Override |
Winson Chung | eeb5bbc | 2013-11-13 15:47:05 -0800 | [diff] [blame] | 672 | public float getIntrinsicIconScaleFactor() { |
| 673 | LauncherAppState app = LauncherAppState.getInstance(); |
| 674 | DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); |
| 675 | return (float) grid.allAppsIconSizePx / grid.iconSizePx; |
| 676 | } |
| 677 | |
| 678 | @Override |
Winson Chung | 7f0acdd | 2011-09-19 18:34:19 -0700 | [diff] [blame] | 679 | protected void onDetachedFromWindow() { |
| 680 | super.onDetachedFromWindow(); |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 681 | cancelAllTasks(true); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 682 | } |
Winson Chung | 7f0acdd | 2011-09-19 18:34:19 -0700 | [diff] [blame] | 683 | |
Adam Cohen | c8f4e1b | 2014-11-19 16:03:20 -0800 | [diff] [blame] | 684 | @Override |
| 685 | public void trimMemory() { |
| 686 | super.trimMemory(); |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 687 | cancelAllTasks(true); |
Adam Cohen | c8f4e1b | 2014-11-19 16:03:20 -0800 | [diff] [blame] | 688 | } |
| 689 | |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 690 | private void cancelAllTasks(boolean clearCompletedTasks) { |
| 691 | for (int page = getPageCount() - 1; page >= 0; page--) { |
| 692 | final PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page); |
| 693 | if (layout != null) { |
| 694 | for (int i = 0; i < layout.getChildCount(); i++) { |
| 695 | ((PagedViewWidget) layout.getChildAt(i)).deletePreview(clearCompletedTasks); |
| 696 | } |
Michael Jurka | e326f18 | 2011-11-21 14:05:46 -0800 | [diff] [blame] | 697 | } |
| 698 | } |
| 699 | } |
| 700 | |
Winson Chung | 7f0acdd | 2011-09-19 18:34:19 -0700 | [diff] [blame] | 701 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 702 | public void setContentType(ContentType type) { |
Michael Jurka | d9546fc | 2013-10-23 15:38:48 +0200 | [diff] [blame] | 703 | // Widgets appear to be cleared every time you leave, always force invalidate for them |
| 704 | if (mContentType != type || type == ContentType.Widgets) { |
| 705 | int page = (mContentType != type) ? 0 : getCurrentPage(); |
| 706 | mContentType = type; |
| 707 | invalidatePageData(page, true); |
Winson Chung | 7819a56 | 2013-09-19 15:55:45 -0700 | [diff] [blame] | 708 | } |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | public ContentType getContentType() { |
| 712 | return mContentType; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 713 | } |
| 714 | |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 715 | public void setPageBackgroundsVisible(boolean visible) { |
| 716 | mPageBackgroundsVisible = visible; |
| 717 | int childCount = getChildCount(); |
| 718 | for (int i = 0; i < childCount; ++i) { |
| 719 | Drawable bg = getChildAt(i).getBackground(); |
| 720 | if (bg != null) { |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 721 | bg.setAlpha(visible ? 255 : 0); |
Adam Cohen | 9bfdb76 | 2014-07-21 17:44:06 -0700 | [diff] [blame] | 722 | } |
| 723 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 724 | } |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 725 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 726 | /* |
| 727 | * Widgets PagedView implementation |
| 728 | */ |
Winson Chung | 4e6a976 | 2011-05-09 11:56:34 -0700 | [diff] [blame] | 729 | private void setupPage(PagedViewGridLayout layout) { |
Winson Chung | 63257c1 | 2011-05-05 17:06:13 -0700 | [diff] [blame] | 730 | // Note: We force a measure here to get around the fact that when we do layout calculations |
Winson Chung | d52f3d8 | 2011-07-12 14:29:11 -0700 | [diff] [blame] | 731 | // immediately after syncing, we don't have a proper width. |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 732 | int widthSpec = MeasureSpec.makeMeasureSpec(mContentWidth, MeasureSpec.AT_MOST); |
| 733 | int heightSpec = MeasureSpec.makeMeasureSpec(mContentHeight, MeasureSpec.AT_MOST); |
Adam Cohen | 63f1ec0 | 2014-08-12 09:23:13 -0700 | [diff] [blame] | 734 | |
| 735 | Drawable bg = getContext().getResources().getDrawable(R.drawable.quantum_panel_dark); |
| 736 | if (bg != null) { |
| 737 | bg.setAlpha(mPageBackgroundsVisible ? 255 : 0); |
| 738 | layout.setBackground(bg); |
| 739 | } |
Winson Chung | 63257c1 | 2011-05-05 17:06:13 -0700 | [diff] [blame] | 740 | layout.measure(widthSpec, heightSpec); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 741 | } |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 742 | |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 743 | public void syncWidgetPageItems(final int page, final boolean immediate) { |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 744 | int numItemsPerPage = mWidgetCountX * mWidgetCountY; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 745 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 746 | final PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page); |
| 747 | |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 748 | // Calculate the dimensions of each cell we are giving to each widget |
Michael Jurka | 038f9d8 | 2011-11-03 13:50:45 -0700 | [diff] [blame] | 749 | final ArrayList<Object> items = new ArrayList<Object>(); |
Adam Cohen | a00673c | 2014-08-14 12:57:28 -0700 | [diff] [blame] | 750 | int contentWidth = mContentWidth - layout.getPaddingLeft() - layout.getPaddingRight(); |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 751 | final int cellWidth = contentWidth / mWidgetCountX; |
Adam Cohen | a00673c | 2014-08-14 12:57:28 -0700 | [diff] [blame] | 752 | int contentHeight = mContentHeight - layout.getPaddingTop() - layout.getPaddingBottom(); |
| 753 | |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 754 | final int cellHeight = contentHeight / mWidgetCountY; |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 755 | |
Winson Chung | e4a647f | 2011-09-30 14:41:25 -0700 | [diff] [blame] | 756 | // Prepare the set of widgets to load previews for in the background |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 757 | int offset = page * numItemsPerPage; |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 758 | for (int i = offset; i < Math.min(offset + numItemsPerPage, mWidgets.size()); ++i) { |
| 759 | items.add(mWidgets.get(i)); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Winson Chung | e4a647f | 2011-09-30 14:41:25 -0700 | [diff] [blame] | 762 | // Prepopulate the pages with the other widget info, and fill in the previews later |
Winson Chung | e4a647f | 2011-09-30 14:41:25 -0700 | [diff] [blame] | 763 | layout.setColumnCount(layout.getCellCountX()); |
| 764 | for (int i = 0; i < items.size(); ++i) { |
| 765 | Object rawInfo = items.get(i); |
| 766 | PendingAddItemInfo createItemInfo = null; |
| 767 | PagedViewWidget widget = (PagedViewWidget) mLayoutInflater.inflate( |
| 768 | R.layout.apps_customize_widget, layout, false); |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 769 | |
| 770 | if (rawInfo instanceof LauncherAppWidgetProviderInfo) { |
Winson Chung | e4a647f | 2011-09-30 14:41:25 -0700 | [diff] [blame] | 771 | // Fill in the widget information |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 772 | LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) rawInfo; |
| 773 | createItemInfo = new PendingAddWidgetInfo(info, null); |
Adam Cohen | 1f36270 | 2012-04-04 14:58:12 -0700 | [diff] [blame] | 774 | |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 775 | widget.applyFromAppWidgetProviderInfo(info, -1, getWidgetPreviewLoader()); |
Winson Chung | e4a647f | 2011-09-30 14:41:25 -0700 | [diff] [blame] | 776 | widget.setTag(createItemInfo); |
Adam Cohen | ed66b2b | 2012-01-23 17:28:51 -0800 | [diff] [blame] | 777 | widget.setShortPressListener(this); |
Winson Chung | e4a647f | 2011-09-30 14:41:25 -0700 | [diff] [blame] | 778 | } else if (rawInfo instanceof ResolveInfo) { |
| 779 | // Fill in the shortcuts information |
| 780 | ResolveInfo info = (ResolveInfo) rawInfo; |
Michael Jurka | dac8591 | 2012-05-18 15:04:49 -0700 | [diff] [blame] | 781 | createItemInfo = new PendingAddShortcutInfo(info.activityInfo); |
Winson Chung | e4a647f | 2011-09-30 14:41:25 -0700 | [diff] [blame] | 782 | createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; |
| 783 | createItemInfo.componentName = new ComponentName(info.activityInfo.packageName, |
| 784 | info.activityInfo.name); |
Michael Jurka | 9c5cc5a | 2014-01-09 14:59:22 +0100 | [diff] [blame] | 785 | widget.applyFromResolveInfo(mPackageManager, info, getWidgetPreviewLoader()); |
Winson Chung | e4a647f | 2011-09-30 14:41:25 -0700 | [diff] [blame] | 786 | widget.setTag(createItemInfo); |
| 787 | } |
Adam Cohen | 5940042 | 2014-03-05 18:07:04 -0800 | [diff] [blame] | 788 | |
Winson Chung | e4a647f | 2011-09-30 14:41:25 -0700 | [diff] [blame] | 789 | widget.setOnClickListener(this); |
| 790 | widget.setOnLongClickListener(this); |
| 791 | widget.setOnTouchListener(this); |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 792 | widget.setOnKeyListener(mKeyListener); |
Winson Chung | e4a647f | 2011-09-30 14:41:25 -0700 | [diff] [blame] | 793 | |
| 794 | // Layout each widget |
| 795 | int ix = i % mWidgetCountX; |
| 796 | int iy = i / mWidgetCountX; |
Adam Cohen | 4e243a2 | 2014-08-10 18:30:55 -0700 | [diff] [blame] | 797 | |
| 798 | if (ix > 0) { |
| 799 | View border = widget.findViewById(R.id.left_border); |
| 800 | border.setVisibility(View.VISIBLE); |
| 801 | } |
| 802 | if (ix < mWidgetCountX - 1) { |
| 803 | View border = widget.findViewById(R.id.right_border); |
| 804 | border.setVisibility(View.VISIBLE); |
| 805 | } |
| 806 | |
Winson Chung | e4a647f | 2011-09-30 14:41:25 -0700 | [diff] [blame] | 807 | GridLayout.LayoutParams lp = new GridLayout.LayoutParams( |
Fabrice Di Meglio | cc11f74 | 2012-12-18 16:25:49 -0800 | [diff] [blame] | 808 | GridLayout.spec(iy, GridLayout.START), |
Winson Chung | e4a647f | 2011-09-30 14:41:25 -0700 | [diff] [blame] | 809 | GridLayout.spec(ix, GridLayout.TOP)); |
| 810 | lp.width = cellWidth; |
| 811 | lp.height = cellHeight; |
Fabrice Di Meglio | cc11f74 | 2012-12-18 16:25:49 -0800 | [diff] [blame] | 812 | lp.setGravity(Gravity.TOP | Gravity.START); |
Winson Chung | e4a647f | 2011-09-30 14:41:25 -0700 | [diff] [blame] | 813 | layout.addView(widget, lp); |
| 814 | } |
| 815 | |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 816 | if (immediate && !mInTransition) { |
| 817 | loadPreviewsForPage(page); |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 818 | } |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 819 | } |
Michael Jurka | 39e5d17 | 2012-03-12 18:36:12 -0700 | [diff] [blame] | 820 | |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 821 | private void loadPreviewsForPage(int page) { |
| 822 | final PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 823 | |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 824 | if (layout != null) { |
| 825 | for (int i = 0; i < layout.getChildCount(); i++) { |
| 826 | ((PagedViewWidget) layout.getChildAt(i)).ensurePreview(); |
Michael Jurka | 39e5d17 | 2012-03-12 18:36:12 -0700 | [diff] [blame] | 827 | } |
Winson Chung | 68e4c64 | 2011-11-10 15:48:25 -0800 | [diff] [blame] | 828 | } |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 829 | } |
Winson Chung | 46af2e8 | 2011-05-09 16:00:53 -0700 | [diff] [blame] | 830 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 831 | @Override |
| 832 | public void syncPages() { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 833 | disablePagedViewAnimations(); |
| 834 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 835 | removeAllViews(); |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 836 | cancelAllTasks(true); |
Winson Chung | 875de7e | 2011-06-28 14:25:17 -0700 | [diff] [blame] | 837 | |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 838 | Context context = getContext(); |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 839 | if (mContentType == ContentType.Widgets) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 840 | for (int j = 0; j < mNumWidgetPages; ++j) { |
| 841 | PagedViewGridLayout layout = new PagedViewGridLayout(context, mWidgetCountX, |
| 842 | mWidgetCountY); |
| 843 | setupPage(layout); |
| 844 | addView(layout, new PagedView.LayoutParams(LayoutParams.MATCH_PARENT, |
| 845 | LayoutParams.MATCH_PARENT)); |
| 846 | } |
| 847 | } else { |
| 848 | throw new RuntimeException("Invalid ContentType"); |
Winson Chung | 875de7e | 2011-06-28 14:25:17 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 851 | enablePagedViewAnimations(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 852 | } |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 853 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 854 | @Override |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 855 | public void syncPageItems(int page, boolean immediate) { |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 856 | if (mContentType == ContentType.Widgets) { |
Michael Jurka | 39e5d17 | 2012-03-12 18:36:12 -0700 | [diff] [blame] | 857 | syncWidgetPageItems(page, immediate); |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 858 | } else { |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 859 | Log.e(TAG, "Unexpected ContentType"); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 860 | } |
| 861 | } |
| 862 | |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 863 | // We want our pages to be z-ordered such that the further a page is to the left, the higher |
| 864 | // it is in the z-order. This is important to insure touch events are handled correctly. |
| 865 | View getPageAt(int index) { |
Michael Jurka | 39e5d17 | 2012-03-12 18:36:12 -0700 | [diff] [blame] | 866 | return getChildAt(indexToPage(index)); |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Adam Cohen | ae4f155 | 2011-10-20 00:15:42 -0700 | [diff] [blame] | 869 | @Override |
| 870 | protected int indexToPage(int index) { |
| 871 | return getChildCount() - index - 1; |
| 872 | } |
| 873 | |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 874 | // In apps customize, we have a scrolling effect which emulates pulling cards off of a stack. |
| 875 | @Override |
| 876 | protected void screenScrolled(int screenCenter) { |
| 877 | super.screenScrolled(screenCenter); |
Michael Jurka | 47639b9 | 2013-01-14 12:42:27 +0100 | [diff] [blame] | 878 | enableHwLayersOnVisiblePages(); |
| 879 | } |
| 880 | |
| 881 | private void enableHwLayersOnVisiblePages() { |
| 882 | final int screenCount = getChildCount(); |
| 883 | |
| 884 | getVisiblePages(mTempVisiblePagesRange); |
| 885 | int leftScreen = mTempVisiblePagesRange[0]; |
| 886 | int rightScreen = mTempVisiblePagesRange[1]; |
| 887 | int forceDrawScreen = -1; |
| 888 | if (leftScreen == rightScreen) { |
| 889 | // make sure we're caching at least two pages always |
| 890 | if (rightScreen < screenCount - 1) { |
| 891 | rightScreen++; |
| 892 | forceDrawScreen = rightScreen; |
| 893 | } else if (leftScreen > 0) { |
| 894 | leftScreen--; |
| 895 | forceDrawScreen = leftScreen; |
| 896 | } |
| 897 | } else { |
| 898 | forceDrawScreen = leftScreen + 1; |
| 899 | } |
| 900 | |
| 901 | for (int i = 0; i < screenCount; i++) { |
| 902 | final View layout = (View) getPageAt(i); |
| 903 | if (!(leftScreen <= i && i <= rightScreen && |
| 904 | (i == forceDrawScreen || shouldDrawChild(layout)))) { |
| 905 | layout.setLayerType(LAYER_TYPE_NONE, null); |
| 906 | } |
| 907 | } |
| 908 | |
Michael Jurka | 47639b9 | 2013-01-14 12:42:27 +0100 | [diff] [blame] | 909 | for (int i = 0; i < screenCount; i++) { |
| 910 | final View layout = (View) getPageAt(i); |
| 911 | |
| 912 | if (leftScreen <= i && i <= rightScreen && |
| 913 | (i == forceDrawScreen || shouldDrawChild(layout))) { |
| 914 | if (layout.getLayerType() != LAYER_TYPE_HARDWARE) { |
| 915 | layout.setLayerType(LAYER_TYPE_HARDWARE, null); |
| 916 | } |
| 917 | } |
| 918 | } |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | protected void overScroll(float amount) { |
Adam Cohen | 1e4359c | 2014-08-18 13:12:16 -0700 | [diff] [blame] | 922 | dampedOverScroll(amount); |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 923 | } |
| 924 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 925 | /** |
| 926 | * Used by the parent to get the content width to set the tab bar to |
| 927 | * @return |
| 928 | */ |
| 929 | public int getPageContentWidth() { |
| 930 | return mContentWidth; |
| 931 | } |
| 932 | |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 933 | @Override |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 934 | protected void onPageEndMoving() { |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 935 | super.onPageEndMoving(); |
Michael Jurka | 5e368ff | 2012-05-14 23:13:15 -0700 | [diff] [blame] | 936 | mForceDrawAllChildrenNextFrame = true; |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 937 | // We reset the save index when we change pages so that it will be recalculated on next |
| 938 | // rotation |
| 939 | mSaveInstanceStateItemIndex = -1; |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 940 | } |
| 941 | |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 942 | @Override |
| 943 | protected void onPageBeginMoving() { |
| 944 | super.onPageBeginMoving(); |
| 945 | if (!mInTransition) { |
| 946 | getVisiblePages(sTempPosArray); |
| 947 | for (int i = sTempPosArray[0]; i <= sTempPosArray[1]; i++) { |
| 948 | loadPreviewsForPage(i); |
| 949 | } |
| 950 | } |
| 951 | } |
| 952 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 953 | /* |
| 954 | * AllAppsView implementation |
| 955 | */ |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 956 | public void setup(Launcher launcher, DragController dragController) { |
| 957 | mLauncher = launcher; |
| 958 | mDragController = dragController; |
| 959 | } |
Winson Chung | 9802ac9 | 2012-06-08 16:01:58 -0700 | [diff] [blame] | 960 | |
| 961 | /** |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 962 | * We should call thise method whenever the core data changes (mWidgets) so that we can |
Winson Chung | 9802ac9 | 2012-06-08 16:01:58 -0700 | [diff] [blame] | 963 | * appropriately determine when to invalidate the PagedView page data. In cases where the data |
| 964 | * has yet to be set, we can requestLayout() and wait for onDataReady() to be called in the |
| 965 | * next onMeasure() pass, which will trigger an invalidatePageData() itself. |
| 966 | */ |
| 967 | private void invalidateOnDataChange() { |
| 968 | if (!isDataReady()) { |
| 969 | // The next layout pass will trigger data-ready if both widgets and apps are set, so |
| 970 | // request a layout to trigger the page data when ready. |
| 971 | requestLayout(); |
| 972 | } else { |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 973 | cancelAllTasks(false); |
Winson Chung | 9802ac9 | 2012-06-08 16:01:58 -0700 | [diff] [blame] | 974 | invalidatePageData(); |
| 975 | } |
| 976 | } |
| 977 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 978 | public void reset() { |
Winson Chung | 649668f | 2012-01-10 13:07:16 -0800 | [diff] [blame] | 979 | // If we have reset, then we should not continue to restore the previous state |
| 980 | mSaveInstanceStateItemIndex = -1; |
| 981 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 982 | if (mContentType != ContentType.Widgets) { |
| 983 | setContentType(ContentType.Widgets); |
Adam Cohen | b64d36e | 2011-10-17 21:48:02 -0700 | [diff] [blame] | 984 | } |
Winson Chung | 649668f | 2012-01-10 13:07:16 -0800 | [diff] [blame] | 985 | |
Adam Cohen | b64d36e | 2011-10-17 21:48:02 -0700 | [diff] [blame] | 986 | if (mCurrentPage != 0) { |
| 987 | invalidatePageData(0); |
| 988 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 989 | } |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 990 | |
| 991 | private AppsCustomizeTabHost getTabHost() { |
| 992 | return (AppsCustomizeTabHost) mLauncher.findViewById(R.id.apps_customize_pane); |
| 993 | } |
| 994 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 995 | public void dumpState() { |
| 996 | // TODO: Dump information related to current list of Applications, Widgets, etc. |
Adam Cohen | 0e56cc9 | 2012-05-11 15:57:05 -0700 | [diff] [blame] | 997 | dumpAppWidgetProviderInfoList(TAG, "mWidgets", mWidgets); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 998 | } |
Adam Cohen | 4e84401 | 2011-11-09 13:48:04 -0800 | [diff] [blame] | 999 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1000 | private void dumpAppWidgetProviderInfoList(String tag, String label, |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 1001 | ArrayList<Object> list) { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1002 | Log.d(tag, label + " size=" + list.size()); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 1003 | for (Object i: list) { |
| 1004 | if (i instanceof AppWidgetProviderInfo) { |
| 1005 | AppWidgetProviderInfo info = (AppWidgetProviderInfo) i; |
| 1006 | Log.d(tag, " label=\"" + info.label + "\" previewImage=" + info.previewImage |
| 1007 | + " resizeMode=" + info.resizeMode + " configure=" + info.configure |
| 1008 | + " initialLayout=" + info.initialLayout |
| 1009 | + " minWidth=" + info.minWidth + " minHeight=" + info.minHeight); |
| 1010 | } else if (i instanceof ResolveInfo) { |
| 1011 | ResolveInfo info = (ResolveInfo) i; |
| 1012 | Log.d(tag, " label=\"" + info.loadLabel(mPackageManager) + "\" icon=" |
| 1013 | + info.icon); |
| 1014 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1015 | } |
| 1016 | } |
Adam Cohen | 4e84401 | 2011-11-09 13:48:04 -0800 | [diff] [blame] | 1017 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1018 | public void surrender() { |
| 1019 | // TODO: If we are in the middle of any process (ie. for holographic outlines, etc) we |
| 1020 | // should stop this now. |
Winson Chung | 4b0ed8c | 2011-10-19 15:24:49 -0700 | [diff] [blame] | 1021 | |
| 1022 | // Stop all background tasks |
Sunny Goyal | 5b0e669 | 2015-03-19 14:31:19 -0700 | [diff] [blame] | 1023 | cancelAllTasks(true); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1024 | } |
Winson Chung | 007c698 | 2011-06-14 13:27:53 -0700 | [diff] [blame] | 1025 | |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 1026 | /* |
| 1027 | * We load an extra page on each side to prevent flashes from scrolling and loading of the |
| 1028 | * widget previews in the background with the AsyncTasks. |
| 1029 | */ |
Winson Chung | 68e4c64 | 2011-11-10 15:48:25 -0800 | [diff] [blame] | 1030 | final static int sLookBehindPageCount = 2; |
| 1031 | final static int sLookAheadPageCount = 2; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 1032 | protected int getAssociatedLowerPageBound(int page) { |
Winson Chung | 68e4c64 | 2011-11-10 15:48:25 -0800 | [diff] [blame] | 1033 | final int count = getChildCount(); |
| 1034 | int windowSize = Math.min(count, sLookBehindPageCount + sLookAheadPageCount + 1); |
| 1035 | int windowMinIndex = Math.max(Math.min(page - sLookBehindPageCount, count - windowSize), 0); |
| 1036 | return windowMinIndex; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 1037 | } |
| 1038 | protected int getAssociatedUpperPageBound(int page) { |
| 1039 | final int count = getChildCount(); |
Winson Chung | 68e4c64 | 2011-11-10 15:48:25 -0800 | [diff] [blame] | 1040 | int windowSize = Math.min(count, sLookBehindPageCount + sLookAheadPageCount + 1); |
| 1041 | int windowMaxIndex = Math.min(Math.max(page + sLookAheadPageCount, windowSize - 1), |
| 1042 | count - 1); |
| 1043 | return windowMaxIndex; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 1044 | } |
Winson Chung | 6a0f57d | 2011-06-29 20:10:49 -0700 | [diff] [blame] | 1045 | |
Winson Chung | 6a0f57d | 2011-06-29 20:10:49 -0700 | [diff] [blame] | 1046 | protected String getCurrentPageDescription() { |
| 1047 | int page = (mNextPage != INVALID_PAGE) ? mNextPage : mCurrentPage; |
| 1048 | int stringId = R.string.default_scroll_format; |
Adam Cohen | d3357b1 | 2011-10-18 14:58:11 -0700 | [diff] [blame] | 1049 | int count = 0; |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 1050 | |
Winson Chung | b745afb | 2015-03-02 11:51:23 -0800 | [diff] [blame] | 1051 | if (mContentType == ContentType.Widgets) { |
Winson Chung | 6a0f57d | 2011-06-29 20:10:49 -0700 | [diff] [blame] | 1052 | stringId = R.string.apps_customize_widgets_scroll_format; |
Adam Cohen | d3357b1 | 2011-10-18 14:58:11 -0700 | [diff] [blame] | 1053 | count = mNumWidgetPages; |
Winson Chung | c58497e | 2013-09-03 17:48:37 -0700 | [diff] [blame] | 1054 | } else { |
| 1055 | throw new RuntimeException("Invalid ContentType"); |
Winson Chung | 6a0f57d | 2011-06-29 20:10:49 -0700 | [diff] [blame] | 1056 | } |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 1057 | |
Michael Jurka | 8b805b1 | 2012-04-18 14:23:14 -0700 | [diff] [blame] | 1058 | return String.format(getContext().getString(stringId), page + 1, count); |
Winson Chung | 6a0f57d | 2011-06-29 20:10:49 -0700 | [diff] [blame] | 1059 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1060 | } |