am 3be63c09: Infrastructure for supporting wallpaper previews.

Merge commit '3be63c09309b21c01b535271625d4c39045690e5'

* commit '3be63c09309b21c01b535271625d4c39045690e5':
  Infrastructure for supporting wallpaper previews.
This commit is contained in:
Dianne Hackborn
2009-08-20 20:39:32 -07:00
committed by Android Git Automerger
9 changed files with 313 additions and 89 deletions

View File

@@ -15944,6 +15944,17 @@
<parameter name="data" type="android.content.Intent">
</parameter>
</method>
<method name="onAttachedToWindow"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="onChildTitleChanged"
return="void"
abstract="false"
@@ -16147,6 +16158,17 @@
visibility="protected"
>
</method>
<method name="onDetachedFromWindow"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="onKeyDown"
return="boolean"
abstract="false"
@@ -19677,6 +19699,17 @@
visibility="public"
>
</method>
<method name="onAttachedToWindow"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="onContentChanged"
return="void"
abstract="false"
@@ -19785,6 +19818,17 @@
<parameter name="featureId" type="int">
</parameter>
</method>
<method name="onDetachedFromWindow"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="onKeyDown"
return="boolean"
abstract="false"
@@ -21731,6 +21775,30 @@
visibility="public"
>
</method>
<method name="onQueryPackageManager"
return="java.util.List&lt;android.content.pm.ResolveInfo&gt;"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="protected"
>
<parameter name="queryIntent" type="android.content.Intent">
</parameter>
</method>
<method name="onSetContentView"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="protected"
>
</method>
</class>
<class name="LauncherActivity.IconResizer"
extends="java.lang.Object"
@@ -154617,6 +154685,17 @@
<parameter name="event" type="android.view.MotionEvent">
</parameter>
</method>
<method name="onAttachedToWindow"
return="void"
abstract="true"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="onContentChanged"
return="void"
abstract="true"
@@ -154656,6 +154735,17 @@
<parameter name="featureId" type="int">
</parameter>
</method>
<method name="onDetachedFromWindow"
return="void"
abstract="true"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
</method>
<method name="onMenuItemSelected"
return="boolean"
abstract="true"

View File

@@ -1930,10 +1930,31 @@ public class Activity extends ContextThemeWrapper
*
* @see #hasWindowFocus()
* @see #onResume
* @see View#onWindowFocusChanged(boolean)
*/
public void onWindowFocusChanged(boolean hasFocus) {
}
/**
* Called when the main window associated with the activity has been
* attached to the window manager.
* See {@link View#onAttachedToWindow() View.onAttachedToWindow()}
* for more information.
* @see View#onAttachedToWindow
*/
public void onAttachedToWindow() {
}
/**
* Called when the main window associated with the activity has been
* detached from the window manager.
* See {@link View#onDetachedFromWindow() View.onDetachedFromWindow()}
* for more information.
* @see View#onDetachedFromWindow
*/
public void onDetachedFromWindow() {
}
/**
* Returns true if this activity's <em>main</em> window currently has window focus.
* Note that this is not the same as the view itself having focus.

View File

@@ -576,6 +576,12 @@ public class Dialog implements DialogInterface, Window.Callback,
public void onWindowFocusChanged(boolean hasFocus) {
}
public void onAttachedToWindow() {
}
public void onDetachedFromWindow() {
}
/**
* Called to process key events. You can override this to intercept all
* key events before they are dispatched to the window. Be sure to call

View File

@@ -18,6 +18,7 @@ package android.app;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ComponentInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
@@ -70,13 +71,15 @@ public abstract class LauncherActivity extends ListActivity {
ListItem(PackageManager pm, ResolveInfo resolveInfo, IconResizer resizer) {
this.resolveInfo = resolveInfo;
label = resolveInfo.loadLabel(pm);
if (label == null && resolveInfo.activityInfo != null) {
ComponentInfo ci = resolveInfo.activityInfo;
if (ci == null) ci = resolveInfo.serviceInfo;
if (label == null && ci != null) {
label = resolveInfo.activityInfo.name;
}
icon = resizer.createIconThumbnail(resolveInfo.loadIcon(pm));
packageName = resolveInfo.activityInfo.applicationInfo.packageName;
className = resolveInfo.activityInfo.name;
packageName = ci.applicationInfo.packageName;
className = ci.name;
}
public ListItem() {
@@ -325,8 +328,7 @@ public abstract class LauncherActivity extends ListActivity {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setProgressBarIndeterminateVisibility(true);
setContentView(com.android.internal.R.layout.activity_list);
onSetContentView();
mIntent = new Intent(getTargetIntent());
mIntent.setComponent(null);
@@ -338,10 +340,17 @@ public abstract class LauncherActivity extends ListActivity {
setProgressBarIndeterminateVisibility(false);
}
/**
* Override to call setContentView() with your own content view to
* customize the list layout.
*/
protected void onSetContentView() {
setContentView(com.android.internal.R.layout.activity_list);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent intent = ((ActivityAdapter)mAdapter).intentForPosition(position);
Intent intent = intentForPosition(position);
startActivity(intent);
}
@@ -373,13 +382,20 @@ public abstract class LauncherActivity extends ListActivity {
return new Intent();
}
/**
* Perform query on package manager for list items. The default
* implementation queries for activities.
*/
protected List<ResolveInfo> onQueryPackageManager(Intent queryIntent) {
return mPackageManager.queryIntentActivities(queryIntent, /* no flags */ 0);
}
/**
* Perform the query to determine which results to show and return a list of them.
*/
public List<ListItem> makeListItems() {
// Load all matching activities and sort correctly
List<ResolveInfo> list = mPackageManager.queryIntentActivities(mIntent,
/* no flags */ 0);
List<ResolveInfo> list = onQueryPackageManager(mIntent);
Collections.sort(list, new ResolveInfo.DisplayNameComparator(mPackageManager));
IconResizer resizer = new IconResizer();

View File

@@ -23,5 +23,6 @@ import android.service.wallpaper.IWallpaperConnection;
*/
oneway interface IWallpaperService {
void attach(IWallpaperConnection connection,
IBinder windowToken, int reqWidth, int reqHeight);
IBinder windowToken, int windowType, boolean isPreview,
int reqWidth, int reqHeight);
}

View File

@@ -211,6 +211,15 @@ public abstract class WallpaperService extends Service {
return mIWallpaperEngine.mReqHeight;
}
/**
* Returns true if this engine is running in preview mode -- that is,
* it is being shown to the user before they select it as the actual
* wallpaper.
*/
public boolean isPreview() {
return mIWallpaperEngine.mIsPreview;
}
/**
* Control whether this wallpaper will receive raw touch events
* from the window manager as the user interacts with the window
@@ -332,7 +341,7 @@ public abstract class WallpaperService extends Service {
mLayout.token = mWindowToken;
if (!mCreated) {
mLayout.type = WindowManager.LayoutParams.TYPE_WALLPAPER;
mLayout.type = mIWallpaperEngine.mWindowType;
mLayout.gravity = Gravity.LEFT|Gravity.TOP;
mSession.add(mWindow, mLayout, View.VISIBLE, mContentInsets);
}
@@ -465,6 +474,8 @@ public abstract class WallpaperService extends Service {
final IWallpaperConnection mConnection;
final IBinder mWindowToken;
final int mWindowType;
final boolean mIsPreview;
int mReqWidth;
int mReqHeight;
@@ -472,10 +483,12 @@ public abstract class WallpaperService extends Service {
IWallpaperEngineWrapper(WallpaperService context,
IWallpaperConnection conn, IBinder windowToken,
int reqWidth, int reqHeight) {
int windowType, boolean isPreview, int reqWidth, int reqHeight) {
mCaller = new HandlerCaller(context, this);
mConnection = conn;
mWindowToken = windowToken;
mWindowType = windowType;
mIsPreview = isPreview;
mReqWidth = reqWidth;
mReqHeight = reqHeight;
@@ -567,10 +580,10 @@ public abstract class WallpaperService extends Service {
mTarget = context;
}
public void attach(IWallpaperConnection conn,
IBinder windowToken, int reqWidth, int reqHeight) {
new IWallpaperEngineWrapper(
mTarget, conn, windowToken, reqWidth, reqHeight);
public void attach(IWallpaperConnection conn, IBinder windowToken,
int windowType, boolean isPreview, int reqWidth, int reqHeight) {
new IWallpaperEngineWrapper(mTarget, conn, windowToken,
windowType, isPreview, reqWidth, reqHeight);
}
}

View File

@@ -237,7 +237,6 @@ public abstract class Window {
/**
* This is called whenever the current window attributes change.
*
*/
public void onWindowAttributesChanged(WindowManager.LayoutParams attrs);
@@ -252,12 +251,28 @@ public abstract class Window {
public void onContentChanged();
/**
* This hook is called whenever the window focus changes.
* This hook is called whenever the window focus changes. See
* {@link View#onWindowFocusChanged(boolean)
* View.onWindowFocusChanged(boolean)} for more information.
*
* @param hasFocus Whether the window now has focus.
*/
public void onWindowFocusChanged(boolean hasFocus);
/**
* Called when the window has been attached to the window manager.
* See {@link View#onAttachedToWindow() View.onAttachedToWindow()}
* for more information.
*/
public void onAttachedToWindow();
/**
* Called when the window has been attached to the window manager.
* See {@link View#onDetachedFromWindow() View.onDetachedFromWindow()}
* for more information.
*/
public void onDetachedFromWindow();
/**
* Called when a panel is being closed. If another logical subsequent
* panel is being opened (and this panel is being closed to make room for the subsequent

View File

@@ -404,7 +404,9 @@ class WallpaperManagerService extends IWallpaperManager.Stub {
void attachServiceLocked(WallpaperConnection conn) {
try {
conn.mService.attach(conn, conn.mToken, mWidth, mHeight);
conn.mService.attach(conn, conn.mToken,
WindowManager.LayoutParams.TYPE_WALLPAPER, false,
mWidth, mHeight);
} catch (RemoteException e) {
Log.w(TAG, "Failed attaching wallpaper; clearing", e);
bindWallpaperComponentLocked(null);

View File

@@ -405,7 +405,12 @@ public class WindowManagerService extends IWindowManager.Stub
// If non-null, this is the currently visible window that is associated
// with the wallpaper.
WindowState mWallpaperTarget = null;
WindowState mUpcomingWallpaperTarget = null;
// If non-null, we are in the middle of animating from one wallpaper target
// to another, and this is the lower one in Z-order.
WindowState mLowerWallpaperTarget = null;
// If non-null, we are in the middle of animating from one wallpaper target
// to another, and this is the higher one in Z-order.
WindowState mUpperWallpaperTarget = null;
int mWallpaperAnimLayerAdjustment;
AppWindowToken mFocusedApp = null;
@@ -1179,7 +1184,8 @@ public class WindowManagerService extends IWindowManager.Stub
boolean adjustWallpaperWindowsLocked() {
boolean changed = false;
mUpcomingWallpaperTarget = null;
final int dw = mDisplay.getWidth();
final int dh = mDisplay.getHeight();
// First find top-most window that has asked to be on top of the
// wallpaper; all wallpapers go behind it.
@@ -1188,60 +1194,41 @@ public class WindowManagerService extends IWindowManager.Stub
WindowState w = null;
WindowState foundW = null;
int foundI = 0;
AppWindowToken topToken = null;
AppWindowToken behindToken = null;
int i = N;
while (i > 0) {
i--;
w = (WindowState)localmWindows.get(i);
if (topToken != null) {
if (w.mAppToken == topToken) {
if (w.mAppToken != null) {
// If this window's app token is hidden and not animating,
// it is of no interest to us.
if (w.mAppToken.hidden && w.mAppToken.animation == null) {
if (DEBUG_WALLPAPER) Log.v(TAG,
"Skipping hidden or animating token: " + w);
continue;
}
if (w.mAppToken != null) {
if (behindToken == null) {
// We need to look through for what is behind the
// potential new wallpaper target... skip all tokens
// that are hidden and not animating, since they can't
// be involved with the transition.
if (w.mAppToken.hidden && w.mAppToken.animation == null) {
continue;
}
behindToken = w.mAppToken;
}
if (w.mAppToken != behindToken) {
break;
}
// If this window's app token is ot fullscreen, also irrelevant.
if (!w.mAppToken.appFullscreen) {
if (DEBUG_WALLPAPER) Log.v(TAG,
"Skipping non-fullscreen token: " + w);
continue;
}
}
if (DEBUG_WALLPAPER) Log.v(TAG, "Win " + w + ": readyfordisplay="
+ w.isReadyForDisplay() + " drawpending=" + w.mDrawPending
+ " commitdrawpending=" + w.mCommitDrawPending);
if ((w.mAttrs.flags&FLAG_SHOW_WALLPAPER) != 0 && w.isReadyForDisplay()
&& !w.mDrawPending && !w.mCommitDrawPending) {
if (behindToken != null && w.mAppToken == behindToken) {
// We had previously found a wallpaper window that was
// animating, and now we found one behind it. We could
// be doing an animation between two windows on top of
// the wallpaper!
if (mWallpaperTarget == w || mWallpaperTarget == foundW) {
// Retain the current wallpaper target (don't move
// the wallpaper yet), but note the window that is
// going to become the wallpaper target so that
// others know about this special state.
if (DEBUG_WALLPAPER) Log.v(TAG,
"Switching wallpaper activities: cur#" + i + "="
+ w + " upcoming#" + foundI + "=" + foundW);
mUpcomingWallpaperTarget = foundW;
foundW = w;
foundI = i;
break;
}
}
if (DEBUG_WALLPAPER) Log.v(TAG,
"Found wallpaper activity: #" + i + "=" + w);
foundW = w;
foundI = i;
if (w.mAppToken != null && w.mAppToken.animation != null) {
// If this app token is animating, we want to keep the
// wallpaper below it if it is animating on top of another
// app with a wallpaper.
topToken = w.mAppToken;
if (w == mWallpaperTarget && w.mAppToken != null
&& w.mAppToken.animation != null) {
// The current wallpaper target is animating, so we'll
// look behind it for another possible target and figure
// out what is going on below.
if (DEBUG_WALLPAPER) Log.v(TAG, "Win " + w
+ ": token animating, looking behind.");
continue;
}
break;
@@ -1258,20 +1245,93 @@ public class WindowManagerService extends IWindowManager.Stub
// enough (we'll just wait until whatever transition is pending
// executes).
if (mWallpaperTarget != null && mWallpaperTarget.mAppToken != null) {
if (DEBUG_WALLPAPER) Log.v(TAG,
"Wallpaper not changing: waiting for app anim in current target");
return false;
}
if (foundW != null && foundW.mAppToken != null) {
return false;
}
if (mUpcomingWallpaperTarget != null && mUpcomingWallpaperTarget.mAppToken != null) {
if (DEBUG_WALLPAPER) Log.v(TAG,
"Wallpaper not changing: waiting for app anim in found target");
return false;
}
}
if (mWallpaperTarget != foundW) {
mWallpaperTarget = foundW;
if (DEBUG_WALLPAPER) {
Log.v(TAG, "New wallpaper target: " + foundW);
Log.v(TAG, "New wallpaper target: " + foundW
+ " oldTarget: " + mWallpaperTarget);
}
mLowerWallpaperTarget = null;
mUpperWallpaperTarget = null;
WindowState oldW = mWallpaperTarget;
mWallpaperTarget = foundW;
// Now what is happening... if the current and new targets are
// animating, then we are in our super special mode!
if (foundW != null && foundW.mAppToken != null && oldW != null
&& oldW.mAppToken != null) {
if (DEBUG_WALLPAPER) {
Log.v(TAG, "New animation: " + foundW.mAppToken.animation
+ " old animation: " + oldW.mAppToken.animation);
}
if (foundW.mAppToken.animation != null
&& oldW.mAppToken.animation != null) {
int oldI = localmWindows.indexOf(oldW);
if (DEBUG_WALLPAPER) {
Log.v(TAG, "New i: " + foundI + " old i: " + oldI);
}
if (oldI >= 0) {
if (DEBUG_WALLPAPER) {
Log.v(TAG, "Animating wallpapers: old#" + oldI
+ "=" + oldW + "; new#" + foundI
+ "=" + foundW);
}
// Set the new target correctly.
if (foundW.mAppToken.hiddenRequested) {
if (DEBUG_WALLPAPER) {
Log.v(TAG, "Old wallpaper still the target.");
}
mWallpaperTarget = oldW;
}
// Now set the upper and lower wallpaper targets
// correctly, and make sure that we are positioning
// the wallpaper below the lower.
if (foundI > oldI) {
// The new target is on top of the old one.
if (DEBUG_WALLPAPER) {
Log.v(TAG, "Found target above old target.");
}
mUpperWallpaperTarget = foundW;
mLowerWallpaperTarget = oldW;
foundW = oldW;
foundI = oldI;
} else {
// The new target is below the old one.
if (DEBUG_WALLPAPER) {
Log.v(TAG, "Found target below old target.");
}
mUpperWallpaperTarget = oldW;
mLowerWallpaperTarget = foundW;
}
}
}
}
} else {
// Is it time to stop animating?
if (mLowerWallpaperTarget == null
|| mLowerWallpaperTarget.mAppToken.animation == null
|| mUpperWallpaperTarget == null
|| mUpperWallpaperTarget.mAppToken.animation == null) {
if (DEBUG_WALLPAPER) {
Log.v(TAG, "No longer animating wallpaper targets!");
}
mLowerWallpaperTarget = null;
mUpperWallpaperTarget = null;
}
}
@@ -1286,7 +1346,7 @@ public class WindowManagerService extends IWindowManager.Stub
// its layer adjustment. Only do this if we are not transfering
// between two wallpaper targets.
mWallpaperAnimLayerAdjustment =
(mUpcomingWallpaperTarget == null && foundW.mAppToken != null)
(mLowerWallpaperTarget == null && foundW.mAppToken != null)
? foundW.mAppToken.animLayerAdjustment : 0;
// Now w is the window we are supposed to be behind... but we
@@ -1310,9 +1370,6 @@ public class WindowManagerService extends IWindowManager.Stub
// what is below it for later.
foundW = foundI > 0 ? (WindowState)localmWindows.get(foundI-1) : null;
final int dw = mDisplay.getWidth();
final int dh = mDisplay.getHeight();
// Start stepping backwards from here, ensuring that our wallpaper windows
// are correctly placed.
int curTokenIndex = mWallpaperTokens.size();
@@ -6676,11 +6733,14 @@ public class WindowManagerService extends IWindowManager.Stub
mAppToken.startingDisplayed = false;
}
if (localLOGV) Log.v(
TAG, "Window " + this
+ " destroying surface " + mSurface + ", session " + mSession);
if (mSurface != null) {
try {
if (DEBUG_VISIBILITY) {
RuntimeException e = new RuntimeException();
e.fillInStackTrace();
Log.w(TAG, "Window " + this + " destroying surface "
+ mSurface + ", session " + mSession, e);
}
if (SHOW_TRANSACTIONS) {
RuntimeException ex = new RuntimeException();
ex.fillInStackTrace();
@@ -6829,7 +6889,7 @@ public class WindowManagerService extends IWindowManager.Stub
}
mHasLocalTransformation = false;
if ((!mLocalAnimating || mAnimationIsEntrance) && mAppToken != null
&& mAppToken.hasTransformation) {
&& mAppToken.animation != null) {
// When our app token is animating, we kind-of pretend like
// we are as well. Note the mLocalAnimating mAnimationIsEntrance
// part of this check means that we will only do this if
@@ -6962,7 +7022,7 @@ public class WindowManagerService extends IWindowManager.Stub
// Wallpapers are animated based on the "real" window they
// are currently targeting.
if (mAttrs.type == TYPE_WALLPAPER && mUpcomingWallpaperTarget == null
if (mAttrs.type == TYPE_WALLPAPER && mLowerWallpaperTarget == null
&& mWallpaperTarget != null) {
if (mWallpaperTarget.mHasLocalTransformation) {
attachedTransformation = mWallpaperTarget.mTransformation;
@@ -7600,7 +7660,7 @@ public class WindowManagerService extends IWindowManager.Stub
if (w == mInputMethodTarget) {
setInputMethodAnimLayerAdjustment(adj);
}
if (w == mWallpaperTarget && mUpcomingWallpaperTarget == null) {
if (w == mWallpaperTarget && mLowerWallpaperTarget == null) {
setWallpaperAnimLayerAdjustmentLocked(adj);
}
}
@@ -7640,7 +7700,7 @@ public class WindowManagerService extends IWindowManager.Stub
if (animation == sDummyAnimation) {
// This guy is going to animate, but not yet. For now count
// it is not animating for purposes of scheduling transactions;
// it as not animating for purposes of scheduling transactions;
// when it is really time to animate, this will be set to
// a real animation and the next call will execute normally.
return false;
@@ -7780,6 +7840,7 @@ public class WindowManagerService extends IWindowManager.Stub
pw.print(prefix); pw.print("allAppWindows="); pw.println(allAppWindows);
}
pw.print(prefix); pw.print("groupId="); pw.print(groupId);
pw.print(" appFullscreen="); pw.println(appFullscreen);
pw.print(" requestedOrientation="); pw.println(requestedOrientation);
pw.print(prefix); pw.print("hiddenRequested="); pw.print(hiddenRequested);
pw.print(" clientHidden="); pw.print(clientHidden);
@@ -8725,13 +8786,12 @@ public class WindowManagerService extends IWindowManager.Stub
mH.removeMessages(H.APP_TRANSITION_TIMEOUT);
boolean wallpaperMoved = adjustWallpaperWindowsLocked();
adjustWallpaperWindowsLocked();
if (DEBUG_APP_TRANSITIONS) Log.v(TAG,
"Old wallpaper target=" + mWallpaperTarget
+ ", upcoming target=" + mUpcomingWallpaperTarget);
if (mUpcomingWallpaperTarget != mWallpaperTarget &&
mUpcomingWallpaperTarget != null &&
mWallpaperTarget != null) {
"New wallpaper target=" + mWallpaperTarget
+ ", lower target=" + mLowerWallpaperTarget
+ ", upper target=" + mUpperWallpaperTarget);
if (mLowerWallpaperTarget != null) {
// Need to determine if both the closing and
// opening app token sets are wallpaper targets,
// in which case special animations are needed
@@ -8741,20 +8801,20 @@ public class WindowManagerService extends IWindowManager.Stub
NN = mOpeningApps.size();
for (i=0; i<NN; i++) {
AppWindowToken wtoken = mOpeningApps.get(i);
if (mUpcomingWallpaperTarget.mAppToken == wtoken) {
if (mLowerWallpaperTarget.mAppToken == wtoken) {
found |= 1;
}
if (mWallpaperTarget.mAppToken == wtoken) {
if (mUpperWallpaperTarget.mAppToken == wtoken) {
found |= 1;
}
}
NN = mClosingApps.size();
for (i=0; i<NN; i++) {
AppWindowToken wtoken = mClosingApps.get(i);
if (mUpcomingWallpaperTarget.mAppToken == wtoken) {
if (mLowerWallpaperTarget.mAppToken == wtoken) {
found |= 2;
}
if (mWallpaperTarget.mAppToken == wtoken) {
if (mUpperWallpaperTarget.mAppToken == wtoken) {
found |= 2;
}
}