summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/layout-land/launcher.xml5
-rw-r--r--res/layout-port/launcher.xml5
-rw-r--r--src/com/android/launcher2/DragLayer.java1
-rw-r--r--src/com/android/launcher2/Launcher.java17
-rw-r--r--src/com/android/launcher2/WallpaperView.java136
-rw-r--r--src/com/android/launcher2/Workspace.java79
6 files changed, 170 insertions, 73 deletions
diff --git a/res/layout-land/launcher.xml b/res/layout-land/launcher.xml
index ef1623101..6976112a5 100644
--- a/res/layout-land/launcher.xml
+++ b/res/layout-land/launcher.xml
@@ -22,6 +22,11 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent">
+ <com.android.launcher2.WallpaperView
+ android:id="@+id/wallpaper"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" />
+
<!-- The workspace contains 3 screens of cells -->
<com.android.launcher2.Workspace
android:id="@+id/workspace"
diff --git a/res/layout-port/launcher.xml b/res/layout-port/launcher.xml
index e77a01e98..462fe5296 100644
--- a/res/layout-port/launcher.xml
+++ b/res/layout-port/launcher.xml
@@ -22,6 +22,11 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent">
+ <com.android.launcher2.WallpaperView
+ android:id="@+id/wallpaper"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" />
+
<!-- The workspace contains 3 screens of cells -->
<com.android.launcher2.Workspace
android:id="@+id/workspace"
diff --git a/src/com/android/launcher2/DragLayer.java b/src/com/android/launcher2/DragLayer.java
index 3439de091..fee86326c 100644
--- a/src/com/android/launcher2/DragLayer.java
+++ b/src/com/android/launcher2/DragLayer.java
@@ -28,6 +28,7 @@ import android.graphics.PorterDuff;
import android.os.Vibrator;
import android.os.SystemClock;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index ef21c61ba..7e42b8d98 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -171,6 +171,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
private LayoutInflater mInflater;
private DragLayer mDragLayer;
+ private WallpaperView mWallpaperView;
private Workspace mWorkspace;
private AppWidgetManager mAppWidgetManager;
@@ -539,6 +540,9 @@ public final class Launcher extends Activity implements View.OnClickListener, On
mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
final DragLayer dragLayer = mDragLayer;
+ mWallpaperView = (WallpaperView) dragLayer.findViewById(R.id.wallpaper);
+ final WallpaperView wallpaper = mWallpaperView;
+
mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
final Workspace workspace = mWorkspace;
@@ -553,7 +557,10 @@ public final class Launcher extends Activity implements View.OnClickListener, On
workspace.setOnLongClickListener(this);
workspace.setDragger(dragLayer);
workspace.setLauncher(this);
+ workspace.setWallpaper(wallpaper);
+
loadWallpaper();
+ wallpaper.setScreenCount(workspace.getScreenCount());
deleteZone.setLauncher(this);
deleteZone.setDragController(dragLayer);
@@ -1645,7 +1652,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On
throw new IllegalStateException("The wallpaper must be a BitmapDrawable.");
}
}
- mWorkspace.loadWallpaper(sWallpaper);
+ mWallpaperView.loadWallpaper(sWallpaper);
}
/**
@@ -1736,14 +1743,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
return /* TODO !mDrawer.isMoving() && */ !mAllAppsDialog.isOpen;
}
- boolean isDrawerUp() {
- return mAllAppsDialog.isOpen; /* TODO && !mDrawer.isMoving();*/
- }
-
- boolean isDrawerMoving() {
- return false; // TODO mDrawer.isMoving();
- }
-
Workspace getWorkspace() {
return mWorkspace;
}
diff --git a/src/com/android/launcher2/WallpaperView.java b/src/com/android/launcher2/WallpaperView.java
new file mode 100644
index 000000000..d9fb66a62
--- /dev/null
+++ b/src/com/android/launcher2/WallpaperView.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher2;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.ComponentName;
+import android.content.res.TypedArray;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.RectF;
+import android.graphics.Rect;
+import android.graphics.Region;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.VelocityTracker;
+import android.view.View;
+import android.view.ViewConfiguration;
+import android.view.ViewGroup;
+import android.view.ViewParent;
+import android.widget.Scroller;
+import android.widget.TextView;
+import android.os.Parcelable;
+import android.os.Parcel;
+
+import java.util.ArrayList;
+
+/**
+ * Wallpaper view shows the wallpaper bitmap, which is far layer in the parallax.
+ */
+public class WallpaperView extends View {
+
+ private int mScreenCount;
+
+ private Paint mPaint;
+ private Bitmap mWallpaper;
+
+ private int mWallpaperWidth;
+ private int mWallpaperHeight;
+ private float mWallpaperOffset;
+ private boolean mWallpaperLoaded;
+
+ /**
+ * Used to inflate the Workspace from XML.
+ *
+ * @param context The application's context.
+ * @param attrs The attribtues set containing the Workspace's customization values.
+ */
+ public WallpaperView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ /**
+ * Used to inflate the Workspace from XML.
+ *
+ * @param context The application's context.
+ * @param attrs The attribtues set containing the Workspace's customization values.
+ * @param defStyle Unused.
+ */
+ public WallpaperView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+
+ initWorkspace();
+ }
+
+ /**
+ * Initializes various states for this workspace.
+ */
+ private void initWorkspace() {
+ mPaint = new Paint();
+ mPaint.setDither(false);
+ }
+
+ /**
+ * Set the background's wallpaper.
+ */
+ void loadWallpaper(Bitmap bitmap) {
+ mWallpaper = bitmap;
+ mWallpaperLoaded = true;
+ requestLayout();
+ invalidate();
+ }
+
+ void setScreenCount(int count) {
+ mScreenCount = count;
+ }
+
+ @Override
+ public boolean isOpaque() {
+ return !mWallpaper.hasAlpha();
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ boolean restore = false;
+
+ float x = mScrollX * mWallpaperOffset;
+ if (x + mWallpaperWidth < mRight - mLeft) {
+ x = mRight - mLeft - mWallpaperWidth;
+ }
+
+ canvas.drawBitmap(mWallpaper, x, (mBottom - mTop - mWallpaperHeight) / 2, mPaint);
+ }
+
+ @Override
+ protected void onSizeChanged(int width, int height, int oldw, int oldh) {
+
+ if (mWallpaperLoaded) {
+ mWallpaperLoaded = false;
+ mWallpaper = Utilities.centerToFit(mWallpaper, width, height, getContext());
+ mWallpaperWidth = mWallpaper.getWidth();
+ mWallpaperHeight = mWallpaper.getHeight();
+ }
+
+ final int wallpaperWidth = mWallpaperWidth;
+ mWallpaperOffset = wallpaperWidth > width ? (mScreenCount * width - wallpaperWidth) /
+ ((mScreenCount - 1) * (float) width) : 1.0f;
+ }
+}
+
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index df3f25b7e..cdb841157 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -28,6 +28,7 @@ import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
+import android.util.Log;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
@@ -55,14 +56,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
private static final int SNAP_VELOCITY = 1000;
private int mDefaultScreen;
-
- private Paint mPaint;
- private Bitmap mWallpaper;
-
- private int mWallpaperWidth;
- private int mWallpaperHeight;
- private float mWallpaperOffset;
- private boolean mWallpaperLoaded;
+ private View mWallpaper;
private boolean mFirstLayout = true;
@@ -148,22 +142,13 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
mCurrentScreen = mDefaultScreen;
Launcher.setScreen(mCurrentScreen);
- mPaint = new Paint();
- mPaint.setDither(false);
-
final ViewConfiguration configuration = ViewConfiguration.get(getContext());
mTouchSlop = configuration.getScaledTouchSlop();
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}
- /**
- * Set the background's wallpaper.
- */
- void loadWallpaper(Bitmap bitmap) {
- mWallpaper = bitmap;
- mWallpaperLoaded = true;
- requestLayout();
- invalidate();
+ void setWallpaper(View wallpaper) {
+ mWallpaper = wallpaper;
}
@Override
@@ -256,6 +241,13 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
}
/**
+ * Returns how many screens there are.
+ */
+ int getScreenCount() {
+ return getChildCount();
+ }
+
+ /**
* Computes a bounding rectangle for a range of cells
*
* @param cellX X coordinate of upper left corner expressed as a cell position
@@ -460,6 +452,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
if (mScroller.computeScrollOffset()) {
mScrollX = mScroller.getCurrX();
mScrollY = mScroller.getCurrY();
+ mWallpaper.scrollTo(mScrollX, mScrollY);
postInvalidate();
} else if (mNextScreen != INVALID_SCREEN) {
mCurrentScreen = Math.max(0, Math.min(mNextScreen, getChildCount() - 1));
@@ -470,42 +463,9 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
}
@Override
- public boolean isOpaque() {
- return !mWallpaper.hasAlpha();
- }
-
- @Override
protected void dispatchDraw(Canvas canvas) {
boolean restore = false;
- // If the all apps drawer is open and the drawing region for the workspace
- // is contained within the drawer's bounds, we skip the drawing. This requires
- // the drawer to be fully opaque.
- if (mLauncher.isDrawerUp()) {
- final Rect clipBounds = mClipBounds;
- canvas.getClipBounds(clipBounds);
- clipBounds.offset(-mScrollX, -mScrollY);
- if (mDrawerBounds.contains(clipBounds)) {
- return;
- }
- } else if (mLauncher.isDrawerMoving()) {
- restore = true;
- canvas.save(Canvas.CLIP_SAVE_FLAG);
-
- final View view = mLauncher.getDrawerHandle();
- final int top = view.getTop() + view.getHeight();
-
- canvas.clipRect(mScrollX, top, mScrollX + mDrawerContentWidth,
- top + mDrawerContentHeight, Region.Op.DIFFERENCE);
- }
-
- float x = mScrollX * mWallpaperOffset;
- if (x + mWallpaperWidth < mRight - mLeft) {
- x = mRight - mLeft - mWallpaperWidth;
- }
-
- canvas.drawBitmap(mWallpaper, x, (mBottom - mTop - mWallpaperHeight) / 2, mPaint);
-
// ViewGroup.dispatchDraw() supports many features we don't need:
// clip to padding, layout animation, animation listener, disappearing
// children, etc. The following implementation attempts to fast-track
@@ -557,18 +517,6 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec);
}
- if (mWallpaperLoaded) {
- mWallpaperLoaded = false;
- mWallpaper = Utilities.centerToFit(mWallpaper, width,
- MeasureSpec.getSize(heightMeasureSpec), getContext());
- mWallpaperWidth = mWallpaper.getWidth();
- mWallpaperHeight = mWallpaper.getHeight();
- }
-
- final int wallpaperWidth = mWallpaperWidth;
- mWallpaperOffset = wallpaperWidth > width ? (count * width - wallpaperWidth) /
- ((count - 1) * (float) width) : 1.0f;
-
if (mFirstLayout) {
scrollTo(mCurrentScreen * width, 0);
mFirstLayout = false;
@@ -769,6 +717,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
@Override
public boolean onTouchEvent(MotionEvent ev) {
+
if (mLocked || !mLauncher.isDrawerDown()) {
return true;
}
@@ -803,12 +752,14 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
if (deltaX < 0) {
if (mScrollX > 0) {
scrollBy(Math.max(-mScrollX, deltaX), 0);
+ mWallpaper.scrollTo(mScrollX, mScrollY);
}
} else if (deltaX > 0) {
final int availableToScroll = getChildAt(getChildCount() - 1).getRight() -
mScrollX - getWidth();
if (availableToScroll > 0) {
scrollBy(Math.min(availableToScroll, deltaX), 0);
+ mWallpaper.scrollTo(mScrollX, mScrollY);
}
}
}