am 7fe4f8ba: Merge "Add ability to swipe from apps to widgets in AllAppsCustomize (issue 5453016)" into ics-mr0
* commit '7fe4f8ba0a3c065773f3166940f6b34e42194389': Add ability to swipe from apps to widgets in AllAppsCustomize (issue 5453016)
This commit is contained in:
commit
72040e89ea
3 files changed
+157
-186
No files matched your search
@@ -130,9 +130,8 @@ class AsyncTaskPageData {
|
|||||||
* A generic template for an async task used in AppsCustomize.
|
* A generic template for an async task used in AppsCustomize.
|
||||||
*/
|
*/
|
||||||
class AppsCustomizeAsyncTask extends AsyncTask<AsyncTaskPageData, Void, AsyncTaskPageData> {
|
class AppsCustomizeAsyncTask extends AsyncTask<AsyncTaskPageData, Void, AsyncTaskPageData> {
|
||||||
AppsCustomizeAsyncTask(int p, AppsCustomizePagedView.ContentType t, AsyncTaskPageData.Type ty) {
|
AppsCustomizeAsyncTask(int p, AsyncTaskPageData.Type ty) {
|
||||||
page = p;
|
page = p;
|
||||||
pageContentType = t;
|
|
||||||
threadPriority = Process.THREAD_PRIORITY_DEFAULT;
|
threadPriority = Process.THREAD_PRIORITY_DEFAULT;
|
||||||
dataType = ty;
|
dataType = ty;
|
||||||
}
|
}
|
||||||
@@ -159,7 +158,6 @@ class AppsCustomizeAsyncTask extends AsyncTask<AsyncTaskPageData, Void, AsyncTas
|
|||||||
// The page that this async task is associated with
|
// The page that this async task is associated with
|
||||||
AsyncTaskPageData.Type dataType;
|
AsyncTaskPageData.Type dataType;
|
||||||
int page;
|
int page;
|
||||||
AppsCustomizePagedView.ContentType pageContentType;
|
|
||||||
int threadPriority;
|
int threadPriority;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,10 +184,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
|
|
||||||
// Save and Restore
|
// Save and Restore
|
||||||
private int mSaveInstanceStateItemIndex = -1;
|
private int mSaveInstanceStateItemIndex = -1;
|
||||||
private int mRestorePage = -1;
|
|
||||||
|
|
||||||
// Content
|
// Content
|
||||||
private ContentType mContentType;
|
|
||||||
private ArrayList<ApplicationInfo> mApps;
|
private ArrayList<ApplicationInfo> mApps;
|
||||||
private ArrayList<Object> mWidgets;
|
private ArrayList<Object> mWidgets;
|
||||||
|
|
||||||
@@ -212,6 +208,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
private final int mWidgetPreviewIconPaddedDimension;
|
private final int mWidgetPreviewIconPaddedDimension;
|
||||||
private final float sWidgetPreviewIconPaddingPercentage = 0.25f;
|
private final float sWidgetPreviewIconPaddingPercentage = 0.25f;
|
||||||
private PagedViewCellLayout mWidgetSpacingLayout;
|
private PagedViewCellLayout mWidgetSpacingLayout;
|
||||||
|
private int mNumAppsPages;
|
||||||
|
private int mNumWidgetPages;
|
||||||
|
|
||||||
// Relating to the scroll and overscroll effects
|
// Relating to the scroll and overscroll effects
|
||||||
Workspace.ZInterpolator mZInterpolator = new Workspace.ZInterpolator(0.5f);
|
Workspace.ZInterpolator mZInterpolator = new Workspace.ZInterpolator(0.5f);
|
||||||
@@ -231,7 +229,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
mLayoutInflater = LayoutInflater.from(context);
|
mLayoutInflater = LayoutInflater.from(context);
|
||||||
mPackageManager = context.getPackageManager();
|
mPackageManager = context.getPackageManager();
|
||||||
mContentType = ContentType.Applications;
|
|
||||||
mApps = new ArrayList<ApplicationInfo>();
|
mApps = new ArrayList<ApplicationInfo>();
|
||||||
mWidgets = new ArrayList<Object>();
|
mWidgets = new ArrayList<Object>();
|
||||||
mIconCache = ((LauncherApplication) context.getApplicationContext()).getIconCache();
|
mIconCache = ((LauncherApplication) context.getApplicationContext()).getIconCache();
|
||||||
@@ -298,24 +295,23 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
int i = -1;
|
int i = -1;
|
||||||
if (getPageCount() > 0) {
|
if (getPageCount() > 0) {
|
||||||
int currentPage = getCurrentPage();
|
int currentPage = getCurrentPage();
|
||||||
switch (mContentType) {
|
if (currentPage < mNumAppsPages) {
|
||||||
case Applications: {
|
|
||||||
PagedViewCellLayout layout = (PagedViewCellLayout) getPageAt(currentPage);
|
PagedViewCellLayout layout = (PagedViewCellLayout) getPageAt(currentPage);
|
||||||
PagedViewCellLayoutChildren childrenLayout = layout.getChildrenLayout();
|
PagedViewCellLayoutChildren childrenLayout = layout.getChildrenLayout();
|
||||||
int numItemsPerPage = mCellCountX * mCellCountY;
|
int numItemsPerPage = mCellCountX * mCellCountY;
|
||||||
int childCount = childrenLayout.getChildCount();
|
int childCount = childrenLayout.getChildCount();
|
||||||
if (childCount > 0) {
|
if (childCount > 0) {
|
||||||
i = (currentPage * numItemsPerPage) + (childCount / 2);
|
i = (currentPage * numItemsPerPage) + (childCount / 2);
|
||||||
}}
|
}
|
||||||
break;
|
} else {
|
||||||
case Widgets: {
|
int numApps = mApps.size();
|
||||||
PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(currentPage);
|
PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(currentPage);
|
||||||
int numItemsPerPage = mWidgetCountX * mWidgetCountY;
|
int numItemsPerPage = mWidgetCountX * mWidgetCountY;
|
||||||
int childCount = layout.getChildCount();
|
int childCount = layout.getChildCount();
|
||||||
if (childCount > 0) {
|
if (childCount > 0) {
|
||||||
i = (currentPage * numItemsPerPage) + (childCount / 2);
|
i = numApps +
|
||||||
}}
|
((currentPage - mNumAppsPages) * numItemsPerPage) + (childCount / 2);
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
@@ -332,16 +328,15 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
/** Returns the page in the current orientation which is expected to contain the specified
|
/** Returns the page in the current orientation which is expected to contain the specified
|
||||||
* item index. */
|
* item index. */
|
||||||
int getPageForComponent(int index) {
|
int getPageForComponent(int index) {
|
||||||
switch (mContentType) {
|
if (index < 0) return 0;
|
||||||
case Applications: {
|
|
||||||
|
if (index < mApps.size()) {
|
||||||
int numItemsPerPage = mCellCountX * mCellCountY;
|
int numItemsPerPage = mCellCountX * mCellCountY;
|
||||||
return (index / numItemsPerPage);
|
return (index / numItemsPerPage);
|
||||||
}
|
} else {
|
||||||
case Widgets: {
|
|
||||||
int numItemsPerPage = mWidgetCountX * mWidgetCountY;
|
int numItemsPerPage = mWidgetCountX * mWidgetCountY;
|
||||||
return (index / numItemsPerPage);
|
return mNumAppsPages + ((index - mApps.size()) / numItemsPerPage);
|
||||||
}}
|
}
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -350,25 +345,14 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
private boolean testDataReady() {
|
private boolean testDataReady() {
|
||||||
// We only do this test once, and we default to the Applications page, so we only really
|
// We only do this test once, and we default to the Applications page, so we only really
|
||||||
// have to wait for there to be apps.
|
// have to wait for there to be apps.
|
||||||
if (mContentType == AppsCustomizePagedView.ContentType.Widgets) {
|
// TODO: What if one of them is validly empty
|
||||||
return !mApps.isEmpty() && !mWidgets.isEmpty();
|
return !mApps.isEmpty() && !mWidgets.isEmpty();
|
||||||
} else {
|
|
||||||
return !mApps.isEmpty();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Restores the page for an item at the specified index */
|
/** Restores the page for an item at the specified index */
|
||||||
void restorePageForIndex(int index) {
|
void restorePageForIndex(int index) {
|
||||||
if (index < 0) return;
|
if (index < 0) return;
|
||||||
|
mSaveInstanceStateItemIndex = index;
|
||||||
int page = getPageForComponent(index);
|
|
||||||
if (page > -1) {
|
|
||||||
if (getChildCount() > 0) {
|
|
||||||
invalidatePageData(page);
|
|
||||||
} else {
|
|
||||||
mRestorePage = page;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onDataReady(int width, int height) {
|
protected void onDataReady(int width, int height) {
|
||||||
@@ -392,14 +376,19 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
mWidgetSpacingLayout.calculateCellCount(width, height, maxCellCountX, maxCellCountY);
|
mWidgetSpacingLayout.calculateCellCount(width, height, maxCellCountX, maxCellCountY);
|
||||||
mCellCountX = mWidgetSpacingLayout.getCellCountX();
|
mCellCountX = mWidgetSpacingLayout.getCellCountX();
|
||||||
mCellCountY = mWidgetSpacingLayout.getCellCountY();
|
mCellCountY = mWidgetSpacingLayout.getCellCountY();
|
||||||
|
mNumWidgetPages = (int) Math.ceil(mWidgets.size() /
|
||||||
|
(float) (mWidgetCountX * mWidgetCountY));
|
||||||
|
mNumAppsPages = (int) Math.ceil((float) mApps.size() / (mCellCountX * mCellCountY));
|
||||||
|
|
||||||
// Force a measure to update recalculate the gaps
|
// Force a measure to update recalculate the gaps
|
||||||
int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST);
|
int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST);
|
||||||
int heightSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST);
|
int heightSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST);
|
||||||
mWidgetSpacingLayout.measure(widthSpec, heightSpec);
|
mWidgetSpacingLayout.measure(widthSpec, heightSpec);
|
||||||
mContentWidth = mWidgetSpacingLayout.getContentWidth();
|
mContentWidth = mWidgetSpacingLayout.getContentWidth();
|
||||||
invalidatePageData(Math.max(0, mRestorePage));
|
|
||||||
mRestorePage = -1;
|
// Restore the page
|
||||||
|
int page = getPageForComponent(mSaveInstanceStateItemIndex);
|
||||||
|
invalidatePageData(Math.max(0, page));
|
||||||
|
|
||||||
int[] offset = new int[2];
|
int[] offset = new int[2];
|
||||||
int[] pos = mWidgetSpacingLayout.estimateCellPosition(mClingFocusedX, mClingFocusedY);
|
int[] pos = mWidgetSpacingLayout.estimateCellPosition(mClingFocusedX, mClingFocusedY);
|
||||||
@@ -472,6 +461,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
// a layout to do this test and invalidate the page data when ready.
|
// a layout to do this test and invalidate the page data when ready.
|
||||||
if (testDataReady()) requestLayout();
|
if (testDataReady()) requestLayout();
|
||||||
} else {
|
} else {
|
||||||
|
cancelAllTasks();
|
||||||
invalidatePageData();
|
invalidatePageData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -625,7 +615,10 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
@Override
|
@Override
|
||||||
protected void onDetachedFromWindow() {
|
protected void onDetachedFromWindow() {
|
||||||
super.onDetachedFromWindow();
|
super.onDetachedFromWindow();
|
||||||
|
cancelAllTasks();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cancelAllTasks() {
|
||||||
// Clean up all the async tasks
|
// Clean up all the async tasks
|
||||||
Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator();
|
Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
@@ -636,18 +629,34 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setContentType(ContentType type) {
|
public void setContentType(ContentType type) {
|
||||||
mContentType = type;
|
if (type == ContentType.Widgets) {
|
||||||
invalidatePageData(0, (type != ContentType.Applications));
|
invalidatePageData(mNumAppsPages, true);
|
||||||
}
|
} else if (type == ContentType.Applications) {
|
||||||
|
invalidatePageData(0, true);
|
||||||
public boolean isContentType(ContentType type) {
|
}
|
||||||
return (mContentType == type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCurrentPageToWidgets() {
|
public void setCurrentPageToWidgets() {
|
||||||
invalidatePageData(0);
|
invalidatePageData(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void snapToPage(int whichPage, int delta, int duration) {
|
||||||
|
super.snapToPage(whichPage, delta, duration);
|
||||||
|
updateCurrentTab(whichPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateCurrentTab(int currentPage) {
|
||||||
|
AppsCustomizeTabHost tabHost = getTabHost();
|
||||||
|
String tag = tabHost.getCurrentTabTag();
|
||||||
|
if (currentPage >= mNumAppsPages &&
|
||||||
|
!tag.equals(tabHost.getTabTagForContentType(ContentType.Widgets))) {
|
||||||
|
tabHost.setCurrentTabFromContent(ContentType.Widgets);
|
||||||
|
} else if (currentPage < mNumAppsPages &&
|
||||||
|
!tag.equals(tabHost.getTabTagForContentType(ContentType.Applications))) {
|
||||||
|
tabHost.setCurrentTabFromContent(ContentType.Applications);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Apps PagedView implementation
|
* Apps PagedView implementation
|
||||||
*/
|
*/
|
||||||
@@ -674,16 +683,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
layout.measure(widthSpec, heightSpec);
|
layout.measure(widthSpec, heightSpec);
|
||||||
setVisibilityOnChildren(layout, View.VISIBLE);
|
setVisibilityOnChildren(layout, View.VISIBLE);
|
||||||
}
|
}
|
||||||
public void syncAppsPages() {
|
|
||||||
// Ensure that we have the right number of pages
|
|
||||||
Context context = getContext();
|
|
||||||
int numPages = (int) Math.ceil((float) mApps.size() / (mCellCountX * mCellCountY));
|
|
||||||
for (int i = 0; i < numPages; ++i) {
|
|
||||||
PagedViewCellLayout layout = new PagedViewCellLayout(context);
|
|
||||||
setupPage(layout);
|
|
||||||
addView(layout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void syncAppsPageItems(int page, boolean immediate) {
|
public void syncAppsPageItems(int page, boolean immediate) {
|
||||||
// ensure that we have the right number of items on the pages
|
// ensure that we have the right number of items on the pages
|
||||||
int numCells = mCellCountX * mCellCountY;
|
int numCells = mCellCountX * mCellCountY;
|
||||||
@@ -754,17 +754,17 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next();
|
AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next();
|
||||||
int taskPage = task.page;
|
int taskPage = task.page;
|
||||||
if ((taskPage == page) ||
|
if ((taskPage == page) ||
|
||||||
taskPage < getAssociatedLowerPageBound(mCurrentPage) ||
|
taskPage < getAssociatedLowerPageBound(mCurrentPage - mNumAppsPages) ||
|
||||||
taskPage > getAssociatedUpperPageBound(mCurrentPage)) {
|
taskPage > getAssociatedUpperPageBound(mCurrentPage - mNumAppsPages)) {
|
||||||
task.cancel(false);
|
task.cancel(false);
|
||||||
iter.remove();
|
iter.remove();
|
||||||
} else {
|
} else {
|
||||||
task.setThreadPriority(getThreadPriorityForPage(taskPage));
|
task.setThreadPriority(getThreadPriorityForPage(taskPage + mNumAppsPages));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We introduce a slight delay to order the loading of side pages so that we don't thrash
|
// We introduce a slight delay to order the loading of side pages so that we don't thrash
|
||||||
final int sleepMs = getSleepForPage(page);
|
final int sleepMs = getSleepForPage(page + mNumAppsPages);
|
||||||
AsyncTaskPageData pageData = new AsyncTaskPageData(page, widgets, cellWidth, cellHeight,
|
AsyncTaskPageData pageData = new AsyncTaskPageData(page, widgets, cellWidth, cellHeight,
|
||||||
cellCountX, new AsyncTaskCallback() {
|
cellCountX, new AsyncTaskCallback() {
|
||||||
@Override
|
@Override
|
||||||
@@ -787,8 +787,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
try {
|
try {
|
||||||
mRunningTasks.remove(task);
|
mRunningTasks.remove(task);
|
||||||
if (task.isCancelled()) return;
|
if (task.isCancelled()) return;
|
||||||
if (task.page > getPageCount()) return;
|
|
||||||
if (task.pageContentType != mContentType) return;
|
|
||||||
onSyncWidgetPageItems(data);
|
onSyncWidgetPageItems(data);
|
||||||
} finally {
|
} finally {
|
||||||
data.cleanup(task.isCancelled());
|
data.cleanup(task.isCancelled());
|
||||||
@@ -797,7 +795,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Ensure that the task is appropriately prioritized and runs in parallel
|
// Ensure that the task is appropriately prioritized and runs in parallel
|
||||||
AppsCustomizeAsyncTask t = new AppsCustomizeAsyncTask(page, mContentType,
|
AppsCustomizeAsyncTask t = new AppsCustomizeAsyncTask(page,
|
||||||
AsyncTaskPageData.Type.LoadWidgetPreviewData);
|
AsyncTaskPageData.Type.LoadWidgetPreviewData);
|
||||||
t.setThreadPriority(getThreadPriorityForPage(page));
|
t.setThreadPriority(getThreadPriorityForPage(page));
|
||||||
t.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, pageData);
|
t.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, pageData);
|
||||||
@@ -862,8 +860,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
try {
|
try {
|
||||||
mRunningTasks.remove(task);
|
mRunningTasks.remove(task);
|
||||||
if (task.isCancelled()) return;
|
if (task.isCancelled()) return;
|
||||||
if (task.page > getPageCount()) return;
|
|
||||||
if (task.pageContentType != mContentType) return;
|
|
||||||
onHolographicPageItemsLoaded(data);
|
onHolographicPageItemsLoaded(data);
|
||||||
} finally {
|
} finally {
|
||||||
data.cleanup(task.isCancelled());
|
data.cleanup(task.isCancelled());
|
||||||
@@ -873,8 +869,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
|
|
||||||
// Ensure that the outline task always runs in the background, serially
|
// Ensure that the outline task always runs in the background, serially
|
||||||
AppsCustomizeAsyncTask t =
|
AppsCustomizeAsyncTask t =
|
||||||
new AppsCustomizeAsyncTask(page, mContentType,
|
new AppsCustomizeAsyncTask(page, AsyncTaskPageData.Type.LoadHolographicIconsData);
|
||||||
AsyncTaskPageData.Type.LoadHolographicIconsData);
|
|
||||||
t.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
t.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
|
||||||
t.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, pageData);
|
t.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, pageData);
|
||||||
mRunningTasks.add(t);
|
mRunningTasks.add(t);
|
||||||
@@ -894,6 +889,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
layout.setMinimumWidth(getPageContentWidth());
|
layout.setMinimumWidth(getPageContentWidth());
|
||||||
layout.measure(widthSpec, heightSpec);
|
layout.measure(widthSpec, heightSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h) {
|
private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h) {
|
||||||
renderDrawableToBitmap(d, bitmap, x, y, w, h, 1f, 0xFFFFFFFF);
|
renderDrawableToBitmap(d, bitmap, x, y, w, h, 1f, 0xFFFFFFFF);
|
||||||
}
|
}
|
||||||
@@ -1008,19 +1004,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
}
|
}
|
||||||
return preview;
|
return preview;
|
||||||
}
|
}
|
||||||
public void syncWidgetPages() {
|
|
||||||
// Ensure that we have the right number of pages
|
|
||||||
Context context = getContext();
|
|
||||||
int numPages = (int) Math.ceil(mWidgets.size() /
|
|
||||||
(float) (mWidgetCountX * mWidgetCountY));
|
|
||||||
for (int j = 0; j < numPages; ++j) {
|
|
||||||
PagedViewGridLayout layout = new PagedViewGridLayout(context, mWidgetCountX,
|
|
||||||
mWidgetCountY);
|
|
||||||
setupPage(layout);
|
|
||||||
addView(layout, new PagedViewGridLayout.LayoutParams(LayoutParams.MATCH_PARENT,
|
|
||||||
LayoutParams.MATCH_PARENT));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void syncWidgetPageItems(int page, boolean immediate) {
|
public void syncWidgetPageItems(int page, boolean immediate) {
|
||||||
int numItemsPerPage = mWidgetCountX * mWidgetCountY;
|
int numItemsPerPage = mWidgetCountX * mWidgetCountY;
|
||||||
int contentWidth = mWidgetSpacingLayout.getContentWidth();
|
int contentWidth = mWidgetSpacingLayout.getContentWidth();
|
||||||
@@ -1040,7 +1024,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prepopulate the pages with the other widget info, and fill in the previews later
|
// Prepopulate the pages with the other widget info, and fill in the previews later
|
||||||
PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page);
|
PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page + mNumAppsPages);
|
||||||
layout.setColumnCount(layout.getCellCountX());
|
layout.setColumnCount(layout.getCellCountX());
|
||||||
for (int i = 0; i < items.size(); ++i) {
|
for (int i = 0; i < items.size(); ++i) {
|
||||||
Object rawInfo = items.get(i);
|
Object rawInfo = items.get(i);
|
||||||
@@ -1130,7 +1114,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
}
|
}
|
||||||
private void onSyncWidgetPageItems(AsyncTaskPageData data) {
|
private void onSyncWidgetPageItems(AsyncTaskPageData data) {
|
||||||
int page = data.page;
|
int page = data.page;
|
||||||
PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page);
|
PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page + mNumAppsPages);
|
||||||
|
|
||||||
ArrayList<Object> items = data.items;
|
ArrayList<Object> items = data.items;
|
||||||
int count = items.size();
|
int count = items.size();
|
||||||
@@ -1183,33 +1167,30 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
@Override
|
@Override
|
||||||
public void syncPages() {
|
public void syncPages() {
|
||||||
removeAllViews();
|
removeAllViews();
|
||||||
|
cancelAllTasks();
|
||||||
|
|
||||||
// Remove all background asyc tasks if we are loading content anew
|
Context context = getContext();
|
||||||
Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator();
|
for (int j = 0; j < mNumWidgetPages; ++j) {
|
||||||
while (iter.hasNext()) {
|
PagedViewGridLayout layout = new PagedViewGridLayout(context, mWidgetCountX,
|
||||||
AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next();
|
mWidgetCountY);
|
||||||
task.cancel(false);
|
setupPage(layout);
|
||||||
iter.remove();
|
addView(layout, new PagedViewGridLayout.LayoutParams(LayoutParams.MATCH_PARENT,
|
||||||
|
LayoutParams.MATCH_PARENT));
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (mContentType) {
|
for (int i = 0; i < mNumAppsPages; ++i) {
|
||||||
case Applications:
|
PagedViewCellLayout layout = new PagedViewCellLayout(context);
|
||||||
syncAppsPages();
|
setupPage(layout);
|
||||||
break;
|
addView(layout);
|
||||||
case Widgets:
|
|
||||||
syncWidgetPages();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void syncPageItems(int page, boolean immediate) {
|
public void syncPageItems(int page, boolean immediate) {
|
||||||
switch (mContentType) {
|
if (page < mNumAppsPages) {
|
||||||
case Applications:
|
|
||||||
syncAppsPageItems(page, immediate);
|
syncAppsPageItems(page, immediate);
|
||||||
break;
|
} else {
|
||||||
case Widgets:
|
syncWidgetPageItems(page - mNumAppsPages, immediate);
|
||||||
syncWidgetPageItems(page, immediate);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1286,31 +1267,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
return mContentWidth;
|
return mContentWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPageBeginMoving() {
|
|
||||||
/* TO BE ENABLED LATER
|
|
||||||
setChildrenDrawnWithCacheEnabled(true);
|
|
||||||
for (int i = 0; i < getChildCount(); ++i) {
|
|
||||||
View v = getChildAt(i);
|
|
||||||
if (v instanceof PagedViewCellLayout) {
|
|
||||||
((PagedViewCellLayout) v).setChildrenDrawingCacheEnabled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
super.onPageBeginMoving();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPageEndMoving() {
|
protected void onPageEndMoving() {
|
||||||
/* TO BE ENABLED LATER
|
|
||||||
for (int i = 0; i < getChildCount(); ++i) {
|
|
||||||
View v = getChildAt(i);
|
|
||||||
if (v instanceof PagedViewCellLayout) {
|
|
||||||
((PagedViewCellLayout) v).setChildrenDrawingCacheEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setChildrenDrawnWithCacheEnabled(false);
|
|
||||||
*/
|
|
||||||
super.onPageEndMoving();
|
super.onPageEndMoving();
|
||||||
|
|
||||||
// We reset the save index when we change pages so that it will be recalculated on next
|
// We reset the save index when we change pages so that it will be recalculated on next
|
||||||
@@ -1402,15 +1360,14 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset() {
|
public void reset() {
|
||||||
if (mContentType != ContentType.Applications) {
|
updateCurrentTab(0);
|
||||||
// Reset to the first page of the Apps pane
|
invalidatePageData(0);
|
||||||
AppsCustomizeTabHost tabs = (AppsCustomizeTabHost)
|
|
||||||
mLauncher.findViewById(R.id.apps_customize_pane);
|
|
||||||
tabs.selectAppsTab();
|
|
||||||
} else if (getCurrentPage() != 0) {
|
|
||||||
invalidatePageData(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AppsCustomizeTabHost getTabHost() {
|
||||||
|
return (AppsCustomizeTabHost) mLauncher.findViewById(R.id.apps_customize_pane);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dumpState() {
|
public void dumpState() {
|
||||||
// TODO: Dump information related to current list of Applications, Widgets, etc.
|
// TODO: Dump information related to current list of Applications, Widgets, etc.
|
||||||
@@ -1456,14 +1413,14 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
|
|||||||
protected String getCurrentPageDescription() {
|
protected String getCurrentPageDescription() {
|
||||||
int page = (mNextPage != INVALID_PAGE) ? mNextPage : mCurrentPage;
|
int page = (mNextPage != INVALID_PAGE) ? mNextPage : mCurrentPage;
|
||||||
int stringId = R.string.default_scroll_format;
|
int stringId = R.string.default_scroll_format;
|
||||||
switch (mContentType) {
|
|
||||||
case Applications:
|
if (page < mNumAppsPages) {
|
||||||
stringId = R.string.apps_customize_apps_scroll_format;
|
stringId = R.string.apps_customize_apps_scroll_format;
|
||||||
break;
|
} else {
|
||||||
case Widgets:
|
page -= mNumAppsPages;
|
||||||
stringId = R.string.apps_customize_widgets_scroll_format;
|
stringId = R.string.apps_customize_widgets_scroll_format;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return String.format(mContext.getString(stringId), page + 1, getChildCount());
|
return String.format(mContext.getString(stringId), page + 1, getChildCount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,6 +48,7 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona
|
|||||||
private ViewGroup mTabs;
|
private ViewGroup mTabs;
|
||||||
private ViewGroup mTabsContainer;
|
private ViewGroup mTabsContainer;
|
||||||
private AppsCustomizePagedView mAppsCustomizePane;
|
private AppsCustomizePagedView mAppsCustomizePane;
|
||||||
|
private boolean mSuppressContentCallback = false;
|
||||||
private ImageView mAnimationBuffer;
|
private ImageView mAnimationBuffer;
|
||||||
|
|
||||||
private boolean mInTransition;
|
private boolean mInTransition;
|
||||||
@@ -167,6 +168,7 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona
|
|||||||
private void onTabChangedStart() {
|
private void onTabChangedStart() {
|
||||||
mAppsCustomizePane.hideScrollingIndicator(false);
|
mAppsCustomizePane.hideScrollingIndicator(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onTabChangedEnd(AppsCustomizePagedView.ContentType type) {
|
private void onTabChangedEnd(AppsCustomizePagedView.ContentType type) {
|
||||||
mAppsCustomizePane.setContentType(type);
|
mAppsCustomizePane.setContentType(type);
|
||||||
}
|
}
|
||||||
@@ -174,59 +176,67 @@ public class AppsCustomizeTabHost extends TabHost implements LauncherTransitiona
|
|||||||
@Override
|
@Override
|
||||||
public void onTabChanged(String tabId) {
|
public void onTabChanged(String tabId) {
|
||||||
final AppsCustomizePagedView.ContentType type = getContentTypeForTabTag(tabId);
|
final AppsCustomizePagedView.ContentType type = getContentTypeForTabTag(tabId);
|
||||||
if (!mAppsCustomizePane.isContentType(type)) {
|
if (mSuppressContentCallback) {
|
||||||
// Animate the changing of the tab content by fading pages in and out
|
mSuppressContentCallback = false;
|
||||||
final Resources res = getResources();
|
return;
|
||||||
final int duration = res.getInteger(R.integer.config_tabTransitionDuration);
|
|
||||||
|
|
||||||
// We post a runnable here because there is a delay while the first page is loading and
|
|
||||||
// the feedback from having changed the tab almost feels better than having it stick
|
|
||||||
post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
// Setup the animation buffer
|
|
||||||
Bitmap b = Bitmap.createBitmap(mAppsCustomizePane.getMeasuredWidth(),
|
|
||||||
mAppsCustomizePane.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
|
|
||||||
Canvas c = new Canvas(b);
|
|
||||||
mAppsCustomizePane.draw(c);
|
|
||||||
mAppsCustomizePane.setAlpha(0f);
|
|
||||||
mAnimationBuffer.setImageBitmap(b);
|
|
||||||
mAnimationBuffer.setAlpha(1f);
|
|
||||||
mAnimationBuffer.setVisibility(View.VISIBLE);
|
|
||||||
c.setBitmap(null);
|
|
||||||
b = null;
|
|
||||||
|
|
||||||
// Toggle the new content
|
|
||||||
onTabChangedStart();
|
|
||||||
onTabChangedEnd(type);
|
|
||||||
|
|
||||||
// Animate the transition
|
|
||||||
ObjectAnimator outAnim = ObjectAnimator.ofFloat(mAnimationBuffer, "alpha", 0f);
|
|
||||||
outAnim.addListener(new AnimatorListenerAdapter() {
|
|
||||||
@Override
|
|
||||||
public void onAnimationEnd(Animator animation) {
|
|
||||||
mAnimationBuffer.setVisibility(View.GONE);
|
|
||||||
mAnimationBuffer.setImageBitmap(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ObjectAnimator inAnim = ObjectAnimator.ofFloat(mAppsCustomizePane, "alpha", 1f);
|
|
||||||
inAnim.addListener(new AnimatorListenerAdapter() {
|
|
||||||
@Override
|
|
||||||
public void onAnimationEnd(Animator animation) {
|
|
||||||
if (!LauncherApplication.isScreenLarge()) {
|
|
||||||
mAppsCustomizePane.flashScrollingIndicator();
|
|
||||||
}
|
|
||||||
mAppsCustomizePane.loadAssociatedPages(
|
|
||||||
mAppsCustomizePane.getCurrentPage());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
AnimatorSet animSet = new AnimatorSet();
|
|
||||||
animSet.playTogether(outAnim, inAnim);
|
|
||||||
animSet.setDuration(duration);
|
|
||||||
animSet.start();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Animate the changing of the tab content by fading pages in and out
|
||||||
|
final Resources res = getResources();
|
||||||
|
final int duration = res.getInteger(R.integer.config_tabTransitionDuration);
|
||||||
|
|
||||||
|
// We post a runnable here because there is a delay while the first page is loading and
|
||||||
|
// the feedback from having changed the tab almost feels better than having it stick
|
||||||
|
post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// Setup the animation buffer
|
||||||
|
Bitmap b = Bitmap.createBitmap(mAppsCustomizePane.getMeasuredWidth(),
|
||||||
|
mAppsCustomizePane.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
|
||||||
|
Canvas c = new Canvas(b);
|
||||||
|
mAppsCustomizePane.draw(c);
|
||||||
|
mAppsCustomizePane.setAlpha(0f);
|
||||||
|
mAnimationBuffer.setImageBitmap(b);
|
||||||
|
mAnimationBuffer.setAlpha(1f);
|
||||||
|
mAnimationBuffer.setVisibility(View.VISIBLE);
|
||||||
|
c.setBitmap(null);
|
||||||
|
b = null;
|
||||||
|
|
||||||
|
// Toggle the new content
|
||||||
|
onTabChangedStart();
|
||||||
|
onTabChangedEnd(type);
|
||||||
|
|
||||||
|
// Animate the transition
|
||||||
|
ObjectAnimator outAnim = ObjectAnimator.ofFloat(mAnimationBuffer, "alpha", 0f);
|
||||||
|
outAnim.addListener(new AnimatorListenerAdapter() {
|
||||||
|
@Override
|
||||||
|
public void onAnimationEnd(Animator animation) {
|
||||||
|
mAnimationBuffer.setVisibility(View.GONE);
|
||||||
|
mAnimationBuffer.setImageBitmap(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ObjectAnimator inAnim = ObjectAnimator.ofFloat(mAppsCustomizePane, "alpha", 1f);
|
||||||
|
inAnim.addListener(new AnimatorListenerAdapter() {
|
||||||
|
@Override
|
||||||
|
public void onAnimationEnd(Animator animation) {
|
||||||
|
if (!LauncherApplication.isScreenLarge()) {
|
||||||
|
mAppsCustomizePane.flashScrollingIndicator();
|
||||||
|
}
|
||||||
|
mAppsCustomizePane.loadAssociatedPages(
|
||||||
|
mAppsCustomizePane.getCurrentPage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
AnimatorSet animSet = new AnimatorSet();
|
||||||
|
animSet.playTogether(outAnim, inAnim);
|
||||||
|
animSet.setDuration(duration);
|
||||||
|
animSet.start();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentTabFromContent(AppsCustomizePagedView.ContentType type) {
|
||||||
|
mSuppressContentCallback = true;
|
||||||
|
setCurrentTabByTag(getTabTagForContentType(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1685,6 +1685,10 @@ public abstract class PagedView extends ViewGroup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mContentIsRefreshable) {
|
if (mContentIsRefreshable) {
|
||||||
|
// Force all scrolling-related behavior to end
|
||||||
|
mScroller.forceFinished(true);
|
||||||
|
mNextPage = INVALID_PAGE;
|
||||||
|
|
||||||
// Update all the pages
|
// Update all the pages
|
||||||
syncPages();
|
syncPages();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user