If 3 screens are good 5 will be better

This commit is contained in:
Mike Cleron committed 2009-11-05 17:17:50 -08:00
1 parent 2d80476997
commit 3a2b3f2be5
6 files changed
+73 -24

No files matched your search

+5 -2
View File
@@ -39,12 +39,15 @@
android:id="@+id/workspace" android:id="@+id/workspace"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:scrollbars="horizontal"
launcher:defaultScreen="1"> android:fadeScrollbars="true"
launcher:defaultScreen="2">
<include android:id="@+id/cell1" layout="@layout/workspace_screen" /> <include android:id="@+id/cell1" layout="@layout/workspace_screen" />
<include android:id="@+id/cell2" layout="@layout/workspace_screen" /> <include android:id="@+id/cell2" layout="@layout/workspace_screen" />
<include android:id="@+id/cell3" layout="@layout/workspace_screen" /> <include android:id="@+id/cell3" layout="@layout/workspace_screen" />
<include android:id="@+id/cell4" layout="@layout/workspace_screen" />
<include android:id="@+id/cell5" layout="@layout/workspace_screen" />
</com.android.launcher2.Workspace> </com.android.launcher2.Workspace>
+5 -2
View File
@@ -40,12 +40,15 @@
android:id="@+id/workspace" android:id="@+id/workspace"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:scrollbars="horizontal"
launcher:defaultScreen="1"> android:fadeScrollbars="true"
launcher:defaultScreen="2">
<include android:id="@+id/cell1" layout="@layout/workspace_screen" /> <include android:id="@+id/cell1" layout="@layout/workspace_screen" />
<include android:id="@+id/cell2" layout="@layout/workspace_screen" /> <include android:id="@+id/cell2" layout="@layout/workspace_screen" />
<include android:id="@+id/cell3" layout="@layout/workspace_screen" /> <include android:id="@+id/cell3" layout="@layout/workspace_screen" />
<include android:id="@+id/cell4" layout="@layout/workspace_screen" />
<include android:id="@+id/cell5" layout="@layout/workspace_screen" />
</com.android.launcher2.Workspace> </com.android.launcher2.Workspace>
+7 -7
View File
@@ -17,49 +17,49 @@
<favorites xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher2"> <favorites xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher2">
<search <search
launcher:screen="1" launcher:screen="2"
launcher:x="0" launcher:x="0"
launcher:y="0" /> launcher:y="0" />
<favorite <favorite
launcher:packageName="com.android.contacts" launcher:packageName="com.android.contacts"
launcher:className="com.android.contacts.DialtactsActivity" launcher:className="com.android.contacts.DialtactsActivity"
launcher:screen="1" launcher:screen="2"
launcher:x="0" launcher:x="0"
launcher:y="3" /> launcher:y="3" />
<favorite <favorite
launcher:packageName="com.android.contacts" launcher:packageName="com.android.contacts"
launcher:className="com.android.contacts.DialtactsContactsEntryActivity" launcher:className="com.android.contacts.DialtactsContactsEntryActivity"
launcher:screen="1" launcher:screen="2"
launcher:x="1" launcher:x="1"
launcher:y="3" /> launcher:y="3" />
<favorite <favorite
launcher:packageName="com.android.browser" launcher:packageName="com.android.browser"
launcher:className="com.android.browser.BrowserActivity" launcher:className="com.android.browser.BrowserActivity"
launcher:screen="1" launcher:screen="2"
launcher:x="2" launcher:x="2"
launcher:y="3" /> launcher:y="3" />
<favorite <favorite
launcher:packageName="com.google.android.apps.maps" launcher:packageName="com.google.android.apps.maps"
launcher:className="com.google.android.maps.MapsActivity" launcher:className="com.google.android.maps.MapsActivity"
launcher:screen="1" launcher:screen="2"
launcher:x="3" launcher:x="3"
launcher:y="3" /> launcher:y="3" />
<favorite <favorite
launcher:packageName="com.android.mms" launcher:packageName="com.android.mms"
launcher:className="com.android.mms.ui.ConversationList" launcher:className="com.android.mms.ui.ConversationList"
launcher:screen="1" launcher:screen="2"
launcher:x="0" launcher:x="0"
launcher:y="2" /> launcher:y="2" />
<favorite <favorite
launcher:packageName="com.android.vending" launcher:packageName="com.android.vending"
launcher:className="com.android.vending.AssetBrowserActivity" launcher:className="com.android.vending.AssetBrowserActivity"
launcher:screen="1" launcher:screen="2"
launcher:x="3" launcher:x="3"
launcher:y="2" /> launcher:y="2" />
+3 -3
View File
@@ -108,8 +108,8 @@ public final class Launcher extends Activity
static final String EXTRA_CUSTOM_WIDGET = "custom_widget"; static final String EXTRA_CUSTOM_WIDGET = "custom_widget";
static final String SEARCH_WIDGET = "search_widget"; static final String SEARCH_WIDGET = "search_widget";
static final int SCREEN_COUNT = 3; static final int SCREEN_COUNT = 5;
static final int DEFAULT_SCREN = 1; static final int DEFAULT_SCREEN = 2;
static final int NUMBER_CELLS_X = 4; static final int NUMBER_CELLS_X = 4;
static final int NUMBER_CELLS_Y = 4; static final int NUMBER_CELLS_Y = 4;
@@ -148,7 +148,7 @@ public final class Launcher extends Activity
static final int APPWIDGET_HOST_ID = 1024; static final int APPWIDGET_HOST_ID = 1024;
private static final Object sLock = new Object(); private static final Object sLock = new Object();
private static int sScreen = DEFAULT_SCREN; private static int sScreen = DEFAULT_SCREEN;
private LayoutInflater mInflater; private LayoutInflater mInflater;
@@ -58,7 +58,7 @@ public class LauncherProvider extends ContentProvider {
private static final String DATABASE_NAME = "launcher.db"; private static final String DATABASE_NAME = "launcher.db";
private static final int DATABASE_VERSION = 4; private static final int DATABASE_VERSION = 5;
static final String AUTHORITY = "com.android.launcher2.settings"; static final String AUTHORITY = "com.android.launcher2.settings";
@@ -393,6 +393,21 @@ public class LauncherProvider extends ContentProvider {
} }
} }
if (version < 5) {
// We went from 3 to 5 screens. Move everything 1 to the right
db.beginTransaction();
try {
db.execSQL("UPDATE favorites SET screen=(screen + 1);");
db.setTransactionSuccessful();
version = 5;
} catch (SQLException ex) {
// Old version remains, which means we wipe old data
Log.e(LOG_TAG, ex.getMessage(), ex);
} finally {
db.endTransaction();
}
}
if (version != DATABASE_VERSION) { if (version != DATABASE_VERSION) {
Log.w(LOG_TAG, "Destroying all old data."); Log.w(LOG_TAG, "Destroying all old data.");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_FAVORITES); db.execSQL("DROP TABLE IF EXISTS " + TABLE_FAVORITES);
+37 -9
View File
@@ -543,6 +543,14 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
if (restore) { if (restore) {
canvas.restoreToCount(restoreCount); canvas.restoreToCount(restoreCount);
} }
onDrawScrollBars(canvas);
}
@Override
protected int computeHorizontalScrollRange() {
final int count = getChildCount();
return count == 0 ? getWidth() : (getChildAt(count - 1)).getRight();
} }
private float mScale = 1.0f; private float mScale = 1.0f;
@@ -577,8 +585,11 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec); getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec);
} }
if (mFirstLayout) { if (mFirstLayout) {
setHorizontalScrollBarEnabled(false);
scrollTo(mCurrentScreen * width, 0); scrollTo(mCurrentScreen * width, 0);
setHorizontalScrollBarEnabled(true);
updateWallpaperOffset(width * (getChildCount() - 1)); updateWallpaperOffset(width * (getChildCount() - 1));
mFirstLayout = false; mFirstLayout = false;
} }
@@ -725,7 +736,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
if (xMoved) { if (xMoved) {
// Scroll if the user moved far enough along the X axis // Scroll if the user moved far enough along the X axis
mTouchState = TOUCH_STATE_SCROLLING; mTouchState = TOUCH_STATE_SCROLLING;
enableChildrenCache(); enableChildrenCache(mCurrentScreen - 1, mCurrentScreen + 1);
} }
// Either way, cancel any pending longpress // Either way, cancel any pending longpress
if (mAllowLongPress) { if (mAllowLongPress) {
@@ -781,9 +792,20 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
return mTouchState != TOUCH_STATE_REST; return mTouchState != TOUCH_STATE_REST;
} }
void enableChildrenCache() { void enableChildrenCache(int fromScreen, int toScreen) {
if (fromScreen > toScreen) {
int temp = fromScreen;
fromScreen = toScreen;
toScreen = fromScreen;
}
final int count = getChildCount(); final int count = getChildCount();
for (int i = 0; i < count; i++) {
fromScreen = Math.max(fromScreen, 0);
toScreen = Math.min(toScreen, count - 1);
for (int i = fromScreen; i <= toScreen; i++) {
// Log.d("TAG", "enablingChildrenCache: " + i);
final CellLayout layout = (CellLayout) getChildAt(i); final CellLayout layout = (CellLayout) getChildAt(i);
layout.setChildrenDrawnWithCacheEnabled(true); layout.setChildrenDrawnWithCacheEnabled(true);
layout.setChildrenDrawingCacheEnabled(true); layout.setChildrenDrawingCacheEnabled(true);
@@ -852,6 +874,8 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
scrollBy(Math.min(availableToScroll, deltaX), 0); scrollBy(Math.min(availableToScroll, deltaX), 0);
updateWallpaperOffset(); updateWallpaperOffset();
} }
} else {
awakenScrollBars();
} }
} }
break; break;
@@ -895,22 +919,26 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
void snapToScreen(int whichScreen) { void snapToScreen(int whichScreen) {
if (!mScroller.isFinished()) return; if (!mScroller.isFinished()) return;
clearVacantCache();
enableChildrenCache();
whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1)); whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1));
boolean changingScreens = whichScreen != mCurrentScreen;
clearVacantCache();
enableChildrenCache(mCurrentScreen, whichScreen);
final int screenDelta = Math.abs(whichScreen - mCurrentScreen);
mNextScreen = whichScreen; mNextScreen = whichScreen;
View focusedChild = getFocusedChild(); View focusedChild = getFocusedChild();
if (focusedChild != null && changingScreens && focusedChild == getChildAt(mCurrentScreen)) { if (focusedChild != null && screenDelta != 0 && focusedChild == getChildAt(mCurrentScreen)) {
focusedChild.clearFocus(); focusedChild.clearFocus();
} }
final int newX = whichScreen * getWidth(); final int newX = whichScreen * getWidth();
final int delta = newX - mScrollX; final int delta = newX - mScrollX;
mScroller.startScroll(mScrollX, 0, delta, 0, Math.abs(delta) * 2); final int duration = screenDelta * 300;
awakenScrollBars(duration);
mScroller.startScroll(mScrollX, 0, delta, 0, duration);
invalidate(); invalidate();
} }