Enable live wallpaper in Launcher2

This commit is contained in:
Romain Guy 2009-08-10 15:10:15 -07:00
parent 0bed662a2e
commit b1b69f53a8
6 changed files with 10 additions and 250 deletions

View File

@ -22,11 +22,6 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="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 --> <!-- The workspace contains 3 screens of cells -->
<com.android.launcher2.Workspace <com.android.launcher2.Workspace
android:id="@+id/workspace" android:id="@+id/workspace"

View File

@ -21,11 +21,6 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="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" />
<com.android.launcher2.DragLayer <com.android.launcher2.DragLayer
android:id="@+id/drag_layer" android:id="@+id/drag_layer"
android:layout_width="fill_parent" android:layout_width="fill_parent"

View File

@ -18,8 +18,7 @@
--> -->
<resources> <resources>
<style name="Theme" parent="android:Theme"> <style name="Theme" parent="android:Theme.Wallpaper">
<item name="android:windowBackground">@null</item>
<item name="android:windowNoTitle">true</item> <item name="android:windowNoTitle">true</item>
</style> </style>

View File

@ -18,7 +18,6 @@ package com.android.launcher2;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Application;
import android.app.Dialog; import android.app.Dialog;
import android.app.ISearchManager; import android.app.ISearchManager;
import android.app.SearchManager; import android.app.SearchManager;
@ -40,7 +39,6 @@ import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.ContentObserver; import android.database.ContentObserver;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable; import android.graphics.drawable.TransitionDrawable;
import android.os.Bundle; import android.os.Bundle;
@ -64,6 +62,7 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.View.OnLongClickListener; import android.view.View.OnLongClickListener;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; import android.widget.EditText;
@ -88,7 +87,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
static final boolean LOGD = false; static final boolean LOGD = false;
private static final boolean PROFILE_STARTUP = 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 PROFILE_ROTATE = false;
private static final boolean DEBUG_USER_INTERFACE = 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 final LauncherModel sModel = new LauncherModel();
private static Bitmap sWallpaper;
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_SCREN;
private static WallpaperIntentReceiver sWallpaperReceiver;
private final BroadcastReceiver mApplicationsReceiver = new ApplicationsIntentReceiver(); private final BroadcastReceiver mApplicationsReceiver = new ApplicationsIntentReceiver();
private final ContentObserver mObserver = new FavoritesChangeObserver(); private final ContentObserver mObserver = new FavoritesChangeObserver();
private LayoutInflater mInflater; private LayoutInflater mInflater;
private DragController mDragController; private DragController mDragController;
private DragLayer mDragLayer;
private WallpaperView mWallpaperView;
private Workspace mWorkspace; private Workspace mWorkspace;
private AppWidgetManager mAppWidgetManager; private AppWidgetManager mAppWidgetManager;
@ -182,7 +174,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
private FolderInfo mFolderInfo; private FolderInfo mFolderInfo;
private AllAppsDialog mAllAppsDialog; private AllAppsDialog mAllAppsDialog;
private TransitionDrawable mHandleIcon;
private HandleView mHandleView; private HandleView mHandleView;
private AllAppsView mAllAppsGrid; // TODO: put this into AllAppsDialog private AllAppsView mAllAppsGrid; // TODO: put this into AllAppsDialog
@ -209,6 +200,8 @@ public final class Launcher extends Activity implements View.OnClickListener, On
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
mInflater = getLayoutInflater(); mInflater = getLayoutInflater();
mAppWidgetManager = AppWidgetManager.getInstance(this); mAppWidgetManager = AppWidgetManager.getInstance(this);
@ -532,13 +525,9 @@ public final class Launcher extends Activity implements View.OnClickListener, On
mDragController = new DragController(this); mDragController = new DragController(this);
DragController dragController = mDragController; DragController dragController = mDragController;
mDragLayer = (DragLayer) findViewById(R.id.drag_layer); DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
final DragLayer dragLayer = mDragLayer;
dragLayer.setDragController(dragController); dragLayer.setDragController(dragController);
mWallpaperView = (WallpaperView) findViewById(R.id.wallpaper);
final WallpaperView wallpaper = mWallpaperView;
mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace); mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
final Workspace workspace = mWorkspace; 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 = (HandleView) findViewById(R.id.all_apps);
mHandleView.setLauncher(this); mHandleView.setLauncher(this);
mHandleView.setOnClickListener(this); mHandleView.setOnClickListener(this);
mHandleIcon = (TransitionDrawable) mHandleView.getDrawable(); TransitionDrawable handleIcon = (TransitionDrawable) mHandleView.getDrawable();
mHandleIcon.setCrossFadeEnabled(true); handleIcon.setCrossFadeEnabled(true);
workspace.setOnLongClickListener(this); workspace.setOnLongClickListener(this);
workspace.setDragController(dragController); workspace.setDragController(dragController);
workspace.setLauncher(this); workspace.setLauncher(this);
workspace.setWallpaper(wallpaper);
loadWallpaper();
wallpaper.setScreenCount(workspace.getScreenCount());
deleteZone.setLauncher(this); deleteZone.setLauncher(this);
deleteZone.setDragController(dragController); deleteZone.setDragController(dragController);
@ -1275,17 +1260,6 @@ public final class Launcher extends Activity implements View.OnClickListener, On
* wallpaper. * wallpaper.
*/ */
private void registerIntentReceivers() { 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); IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED); filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addAction(Intent.ACTION_PACKAGE_CHANGED); 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 * 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 * 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); setOnShowListener(this);
setContentView(R.layout.all_apps); 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 dragLayer = (DragLayer)findViewById(R.id.drag_layer);
dragLayer.setDragController(mDragController); dragLayer.setDragController(mDragController);
@ -1916,7 +1871,8 @@ public final class Launcher extends Activity implements View.OnClickListener, On
// TODO // TODO
} }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) { switch (keyCode) {
case KeyEvent.KEYCODE_BACK: case KeyEvent.KEYCODE_BACK:
closeAllAppsDialog(true); 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<Launcher> mLauncher;
WallpaperIntentReceiver(Application application, Launcher launcher) {
mApplication = application;
setLauncher(launcher);
}
void setLauncher(Launcher launcher) {
mLauncher = new WeakReference<Launcher>(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 { private static class DesktopBinder extends Handler implements MessageQueue.IdleHandler {
static final int MESSAGE_BIND_ITEMS = 0x1; static final int MESSAGE_BIND_ITEMS = 0x1;
static final int MESSAGE_BIND_APPWIDGETS = 0x2; static final int MESSAGE_BIND_APPWIDGETS = 0x2;

View File

@ -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;
}
}

View File

@ -20,15 +20,11 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF; import android.graphics.RectF;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.VelocityTracker; import android.view.VelocityTracker;
import android.view.View; 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 static final int SNAP_VELOCITY = 1000;
private int mDefaultScreen; private int mDefaultScreen;
private View mWallpaper;
private boolean mFirstLayout = true; private boolean mFirstLayout = true;
@ -153,10 +148,6 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
mTween = new SymmetricalLinearTween(true, 250/*ms*/, this); mTween = new SymmetricalLinearTween(true, 250/*ms*/, this);
} }
void setWallpaper(View wallpaper) {
mWallpaper = wallpaper;
}
@Override @Override
public void addView(View child, int index, LayoutParams params) { public void addView(View child, int index, LayoutParams params) {
if (!(child instanceof CellLayout)) { if (!(child instanceof CellLayout)) {
@ -464,7 +455,6 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
if (mScroller.computeScrollOffset()) { if (mScroller.computeScrollOffset()) {
mScrollX = mScroller.getCurrX(); mScrollX = mScroller.getCurrX();
mScrollY = mScroller.getCurrY(); mScrollY = mScroller.getCurrY();
mWallpaper.scrollTo(mScrollX, mScrollY);
postInvalidate(); postInvalidate();
} else if (mNextScreen != INVALID_SCREEN) { } else if (mNextScreen != INVALID_SCREEN) {
mCurrentScreen = Math.max(0, Math.min(mNextScreen, getChildCount() - 1)); 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 (deltaX < 0) {
if (mScrollX > 0) { if (mScrollX > 0) {
scrollBy(Math.max(-mScrollX, deltaX), 0); scrollBy(Math.max(-mScrollX, deltaX), 0);
mWallpaper.scrollTo(mScrollX, mScrollY);
} }
} else if (deltaX > 0) { } else if (deltaX > 0) {
final int availableToScroll = getChildAt(getChildCount() - 1).getRight() - final int availableToScroll = getChildAt(getChildCount() - 1).getRight() -
mScrollX - getWidth(); mScrollX - getWidth();
if (availableToScroll > 0) { if (availableToScroll > 0) {
scrollBy(Math.min(availableToScroll, deltaX), 0); scrollBy(Math.min(availableToScroll, deltaX), 0);
mWallpaper.scrollTo(mScrollX, mScrollY);
} }
} }
} }