From b1b69f53a878ca45a2781bb0d713f3f97d594aa4 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Mon, 10 Aug 2009 15:10:15 -0700 Subject: [PATCH] Enable live wallpaper in Launcher2 --- res/layout-land/launcher.xml | 5 - res/layout-port/launcher.xml | 5 - res/values/styles.xml | 3 +- src/com/android/launcher2/Launcher.java | 99 ++------------ src/com/android/launcher2/WallpaperView.java | 136 ------------------- src/com/android/launcher2/Workspace.java | 12 -- 6 files changed, 10 insertions(+), 250 deletions(-) delete mode 100644 src/com/android/launcher2/WallpaperView.java diff --git a/res/layout-land/launcher.xml b/res/layout-land/launcher.xml index 6976112a5a..ef16231018 100644 --- a/res/layout-land/launcher.xml +++ b/res/layout-land/launcher.xml @@ -22,11 +22,6 @@ android:layout_width="fill_parent" android:layout_height="fill_parent"> - - - - - diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index 7a3d5731d4..5eead8b233 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -18,7 +18,6 @@ package com.android.launcher2; import android.app.Activity; import android.app.AlertDialog; -import android.app.Application; import android.app.Dialog; import android.app.ISearchManager; import android.app.SearchManager; @@ -40,7 +39,6 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.database.ContentObserver; import android.graphics.Bitmap; -import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.TransitionDrawable; import android.os.Bundle; @@ -64,6 +62,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.WindowManager; import android.view.View.OnLongClickListener; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; @@ -88,7 +87,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On static final boolean LOGD = false; private static final boolean PROFILE_STARTUP = false; - private static final boolean PROFILE_DRAWER = false; private static final boolean PROFILE_ROTATE = false; private static final boolean DEBUG_USER_INTERFACE = false; @@ -154,21 +152,15 @@ public final class Launcher extends Activity implements View.OnClickListener, On private static final LauncherModel sModel = new LauncherModel(); - private static Bitmap sWallpaper; - private static final Object sLock = new Object(); private static int sScreen = DEFAULT_SCREN; - private static WallpaperIntentReceiver sWallpaperReceiver; - private final BroadcastReceiver mApplicationsReceiver = new ApplicationsIntentReceiver(); private final ContentObserver mObserver = new FavoritesChangeObserver(); private LayoutInflater mInflater; private DragController mDragController; - private DragLayer mDragLayer; - private WallpaperView mWallpaperView; private Workspace mWorkspace; private AppWidgetManager mAppWidgetManager; @@ -182,7 +174,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On private FolderInfo mFolderInfo; private AllAppsDialog mAllAppsDialog; - private TransitionDrawable mHandleIcon; private HandleView mHandleView; private AllAppsView mAllAppsGrid; // TODO: put this into AllAppsDialog @@ -209,6 +200,8 @@ public final class Launcher extends Activity implements View.OnClickListener, On @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER); + mInflater = getLayoutInflater(); mAppWidgetManager = AppWidgetManager.getInstance(this); @@ -532,13 +525,9 @@ public final class Launcher extends Activity implements View.OnClickListener, On mDragController = new DragController(this); DragController dragController = mDragController; - mDragLayer = (DragLayer) findViewById(R.id.drag_layer); - final DragLayer dragLayer = mDragLayer; + DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer); dragLayer.setDragController(dragController); - mWallpaperView = (WallpaperView) findViewById(R.id.wallpaper); - final WallpaperView wallpaper = mWallpaperView; - mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace); final Workspace workspace = mWorkspace; @@ -547,16 +536,12 @@ public final class Launcher extends Activity implements View.OnClickListener, On mHandleView = (HandleView) findViewById(R.id.all_apps); mHandleView.setLauncher(this); mHandleView.setOnClickListener(this); - mHandleIcon = (TransitionDrawable) mHandleView.getDrawable(); - mHandleIcon.setCrossFadeEnabled(true); + TransitionDrawable handleIcon = (TransitionDrawable) mHandleView.getDrawable(); + handleIcon.setCrossFadeEnabled(true); workspace.setOnLongClickListener(this); workspace.setDragController(dragController); workspace.setLauncher(this); - workspace.setWallpaper(wallpaper); - - loadWallpaper(); - wallpaper.setScreenCount(workspace.getScreenCount()); deleteZone.setLauncher(this); deleteZone.setDragController(dragController); @@ -1275,17 +1260,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On * wallpaper. */ private void registerIntentReceivers() { - if (sWallpaperReceiver == null) { - final Application application = getApplication(); - - sWallpaperReceiver = new WallpaperIntentReceiver(application, this); - - IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED); - application.registerReceiver(sWallpaperReceiver, filter); - } else { - sWallpaperReceiver.setLauncher(this); - } - IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED); filter.addAction(Intent.ACTION_PACKAGE_REMOVED); filter.addAction(Intent.ACTION_PACKAGE_CHANGED); @@ -1614,25 +1588,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On } } - private void loadWallpaper() { - // The first time the application is started, we load the wallpaper from - // the ApplicationContext - if (sWallpaper == null) { - final Drawable drawable; - if (false) { - drawable = getWallpaper(); - } else { - drawable = getResources().getDrawable(R.drawable.wallpaper_path); - } - if (drawable instanceof BitmapDrawable) { - sWallpaper = ((BitmapDrawable) drawable).getBitmap(); - } else { - throw new IllegalStateException("The wallpaper must be a BitmapDrawable."); - } - } - mWallpaperView.loadWallpaper(sWallpaper); - } - /** * Opens the user fodler described by the specified tag. The opening of the folder * is animated relative to the specified View. If the View is null, no animation @@ -1885,7 +1840,7 @@ public final class Launcher extends Activity implements View.OnClickListener, On setOnShowListener(this); setContentView(R.layout.all_apps); - AllAppsView grid = mAllAppsGrid = (AllAppsView)findViewById(R.id.all_apps); + mAllAppsGrid = (AllAppsView) findViewById(R.id.all_apps); DragLayer dragLayer = (DragLayer)findViewById(R.id.drag_layer); dragLayer.setDragController(mDragController); @@ -1916,7 +1871,8 @@ public final class Launcher extends Activity implements View.OnClickListener, On // TODO } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: closeAllAppsDialog(true); @@ -2136,43 +2092,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On } } - /** - * Receives intents from other applications to change the wallpaper. - */ - private static class WallpaperIntentReceiver extends BroadcastReceiver { - private final Application mApplication; - private WeakReference mLauncher; - - WallpaperIntentReceiver(Application application, Launcher launcher) { - mApplication = application; - setLauncher(launcher); - } - - void setLauncher(Launcher launcher) { - mLauncher = new WeakReference(launcher); - } - - @Override - public void onReceive(Context context, Intent intent) { - // Load the wallpaper from the ApplicationContext and store it locally - // until the Launcher Activity is ready to use it - final Drawable drawable = mApplication.getWallpaper(); - if (drawable instanceof BitmapDrawable) { - sWallpaper = ((BitmapDrawable) drawable).getBitmap(); - } else { - throw new IllegalStateException("The wallpaper must be a BitmapDrawable."); - } - - // If Launcher is alive, notify we have a new wallpaper - if (mLauncher != null) { - final Launcher launcher = mLauncher.get(); - if (launcher != null) { - launcher.loadWallpaper(); - } - } - } - } - private static class DesktopBinder extends Handler implements MessageQueue.IdleHandler { static final int MESSAGE_BIND_ITEMS = 0x1; static final int MESSAGE_BIND_APPWIDGETS = 0x2; diff --git a/src/com/android/launcher2/WallpaperView.java b/src/com/android/launcher2/WallpaperView.java deleted file mode 100644 index d9fb66a62f..0000000000 --- a/src/com/android/launcher2/WallpaperView.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * 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 bb32e02992..1ff0c285fc 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -20,15 +20,11 @@ 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.util.Log; import android.view.MotionEvent; import android.view.VelocityTracker; import android.view.View; @@ -57,7 +53,6 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag private static final int SNAP_VELOCITY = 1000; private int mDefaultScreen; - private View mWallpaper; private boolean mFirstLayout = true; @@ -153,10 +148,6 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag mTween = new SymmetricalLinearTween(true, 250/*ms*/, this); } - void setWallpaper(View wallpaper) { - mWallpaper = wallpaper; - } - @Override public void addView(View child, int index, LayoutParams params) { if (!(child instanceof CellLayout)) { @@ -464,7 +455,6 @@ 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)); @@ -779,14 +769,12 @@ 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); } } }