Merge "Fix 2797185: Re-enable thumbnail generation in framework" into gingerbread

This commit is contained in:
Jim Miller
2010-07-14 16:59:52 -07:00
committed by Android (Google) Code Review
5 changed files with 94 additions and 22 deletions

View File

@@ -67,6 +67,8 @@ import android.view.View.OnCreateContextMenuListener;
import android.view.ViewGroup.LayoutParams;
import android.view.accessibility.AccessibilityEvent;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import java.util.ArrayList;
import java.util.HashMap;
@@ -1204,19 +1206,37 @@ public class Activity extends ContextThemeWrapper
* @see #onPause
*/
public boolean onCreateThumbnail(Bitmap outBitmap, Canvas canvas) {
final View view = mDecor;
if (view == null) {
if (mDecor == null) {
return false;
}
final int vw = view.getWidth();
final int vh = view.getHeight();
final int dw = outBitmap.getWidth();
final int dh = outBitmap.getHeight();
int paddingLeft = 0;
int paddingRight = 0;
int paddingTop = 0;
int paddingBottom = 0;
// Find System window and use padding so we ignore space reserved for decorations
// like the status bar and such.
final FrameLayout top = (FrameLayout) mDecor;
for (int i = 0; i < top.getChildCount(); i++) {
View child = top.getChildAt(i);
if (child.isFitsSystemWindowsFlagSet()) {
paddingLeft = child.getPaddingLeft();
paddingRight = child.getPaddingRight();
paddingTop = child.getPaddingTop();
paddingBottom = child.getPaddingBottom();
break;
}
}
final int visibleWidth = mDecor.getWidth() - paddingLeft - paddingRight;
final int visibleHeight = mDecor.getHeight() - paddingTop - paddingBottom;
canvas.save();
canvas.scale(((float)dw)/vw, ((float)dh)/vh);
view.draw(canvas);
canvas.scale( (float) outBitmap.getWidth() / visibleWidth,
(float) outBitmap.getHeight() / visibleHeight);
canvas.translate(-paddingLeft, -paddingTop);
mDecor.draw(canvas);
canvas.restore();
return true;

View File

@@ -285,24 +285,54 @@ public class ActivityManager {
* @param maxNum The maximum number of entries to return in the list. The
* actual number returned may be smaller, depending on how many tasks the
* user has started.
*
*
* @param flags Optional flags
* @param receiver Optional receiver for delayed thumbnails
*
* @return Returns a list of RunningTaskInfo records describing each of
* the running tasks.
*
* Some thumbnails may not be available at the time of this call. The optional
* receiver may be used to receive those thumbnails.
*
* @throws SecurityException Throws SecurityException if the caller does
* not hold the {@link android.Manifest.permission#GET_TASKS} permission.
*
* @hide
*/
public List<RunningTaskInfo> getRunningTasks(int maxNum)
public List<RunningTaskInfo> getRunningTasks(int maxNum, int flags, IThumbnailReceiver receiver)
throws SecurityException {
try {
return (List<RunningTaskInfo>)ActivityManagerNative.getDefault()
.getTasks(maxNum, 0, null);
return ActivityManagerNative.getDefault().getTasks(maxNum, flags, receiver);
} catch (RemoteException e) {
// System dead, we will be dead too soon!
return null;
}
}
/**
* Return a list of the tasks that are currently running, with
* the most recent being first and older ones after in order. Note that
* "running" does not mean any of the task's code is currently loaded or
* activity -- the task may have been frozen by the system, so that it
* can be restarted in its previous state when next brought to the
* foreground.
*
* @param maxNum The maximum number of entries to return in the list. The
* actual number returned may be smaller, depending on how many tasks the
* user has started.
*
* @return Returns a list of RunningTaskInfo records describing each of
* the running tasks.
*
* @throws SecurityException Throws SecurityException if the caller does
* not hold the {@link android.Manifest.permission#GET_TASKS} permission.
*/
public List<RunningTaskInfo> getRunningTasks(int maxNum)
throws SecurityException {
return getRunningTasks(maxNum, 0, null);
}
/**
* Information you can retrieve about a particular Service that is
* currently running in the system.

View File

@@ -115,6 +115,7 @@ final class RemoteServiceException extends AndroidRuntimeException {
*/
public final class ActivityThread {
static final String TAG = "ActivityThread";
private static final android.graphics.Bitmap.Config THUMBNAIL_FORMAT = Bitmap.Config.RGB_565;
private static final boolean DEBUG = false;
static final boolean localLOGV = DEBUG ? Config.LOGD : Config.LOGV;
static final boolean DEBUG_BROADCAST = false;
@@ -2210,13 +2211,24 @@ public final class ActivityThread {
h = mThumbnailHeight;
}
// XXX Only set hasAlpha if needed?
thumbnail = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
thumbnail.eraseColor(0);
Canvas cv = new Canvas(thumbnail);
if (!r.activity.onCreateThumbnail(thumbnail, cv)) {
thumbnail = null;
// On platforms where we don't want thumbnails, set dims to (0,0)
if ((w > 0) && (h > 0)) {
View topView = r.activity.getWindow().getDecorView();
// Maximize bitmap by capturing in native aspect.
if (topView.getWidth() >= topView.getHeight()) {
thumbnail = Bitmap.createBitmap(w, h, THUMBNAIL_FORMAT);
} else {
thumbnail = Bitmap.createBitmap(h, w, THUMBNAIL_FORMAT);
}
thumbnail.eraseColor(0);
Canvas cv = new Canvas(thumbnail);
if (!r.activity.onCreateThumbnail(thumbnail, cv)) {
thumbnail = null;
}
}
} catch (Exception e) {
if (!mInstrumentation.onException(r.activity, e)) {
throw new RuntimeException(
@@ -2347,7 +2359,7 @@ public final class ActivityThread {
if (info != null) {
try {
// First create a thumbnail for the activity...
//info.thumbnail = createThumbnailBitmap(r);
info.thumbnail = createThumbnailBitmap(r);
info.description = r.activity.onCreateDescription();
} catch (Exception e) {
if (!mInstrumentation.onException(r.activity, e)) {

View File

@@ -3004,6 +3004,16 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
return false;
}
/**
* Determine if this view has the FITS_SYSTEM_WINDOWS flag set.
* @return True if window has FITS_SYSTEM_WINDOWS set
*
* @hide
*/
public boolean isFitsSystemWindowsFlagSet() {
return (mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS;
}
/**
* Returns the visibility status for this view.
*

View File

@@ -19,9 +19,9 @@
-->
<resources>
<!-- The width that is used when creating thumbnails of applications. -->
<dimen name="thumbnail_width">84dp</dimen>
<dimen name="thumbnail_width">0dp</dimen>
<!-- The height that is used when creating thumbnails of applications. -->
<dimen name="thumbnail_height">63dp</dimen>
<dimen name="thumbnail_height">0dp</dimen>
<!-- The standard size (both width and height) of an application icon that
will be displayed in the app launcher and elsewhere. -->
<dimen name="app_icon_size">48dip</dimen>