Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8746a478 authored by Craig Mautner's avatar Craig Mautner
Browse files

Create end of animation callback for Activity

Activities cannot draw while their entering animations are active.
This change introduces a callback, onEnterAnimationComplete() so
that activities can know when their draws will be effective.

Fixes bug 13658460.

Change-Id: Ic48540cd4c7e37538f10cb2dc0852aa3f55d11e1
parent cfec0fba
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -3392,6 +3392,7 @@ package android.app {
    method public android.view.View onCreateView(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet);
    method public android.view.View onCreateView(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet);
    method protected void onDestroy();
    method protected void onDestroy();
    method public void onDetachedFromWindow();
    method public void onDetachedFromWindow();
    method public void onEnterAnimationComplete();
    method public boolean onGenericMotionEvent(android.view.MotionEvent);
    method public boolean onGenericMotionEvent(android.view.MotionEvent);
    method public boolean onKeyDown(int, android.view.KeyEvent);
    method public boolean onKeyDown(int, android.view.KeyEvent);
    method public boolean onKeyLongPress(int, android.view.KeyEvent);
    method public boolean onKeyLongPress(int, android.view.KeyEvent);
+8 −0
Original line number Original line Diff line number Diff line
@@ -5500,6 +5500,14 @@ public class Activity extends ContextThemeWrapper
    public void onBackgroundMediaPlayingChanged(boolean playing) {
    public void onBackgroundMediaPlayingChanged(boolean playing) {
    }
    }


    /**
     * Activities cannot draw during the period that their windows are animating in. In order
     * to know when it is safe to begin drawing they can override this method which will be
     * called when the entering animation has completed.
     */
    public void onEnterAnimationComplete() {
    }

    /**
    /**
     * Adjust the current immersive mode setting.
     * Adjust the current immersive mode setting.
     *
     *
+21 −0
Original line number Original line Diff line number Diff line
@@ -2231,6 +2231,14 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            reply.writeNoException();
            reply.writeNoException();
            return true;
            return true;
        }
        }

        case NOTIFY_ENTER_ANIMATION_COMPLETE_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            IBinder token = data.readStrongBinder();
            notifyEnterAnimationComplete(token);
            reply.writeNoException();
            return true;
        }
        }
        }


        return super.onTransact(code, data, reply, flags);
        return super.onTransact(code, data, reply, flags);
@@ -5146,5 +5154,18 @@ class ActivityManagerProxy implements IActivityManager
        reply.recycle();
        reply.recycle();
    }
    }


    @Override
    public void notifyEnterAnimationComplete(IBinder token) throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeStrongBinder(token);
        mRemote.transact(NOTIFY_ENTER_ANIMATION_COMPLETE_TRANSACTION, data, reply,
                IBinder.FLAG_ONEWAY);
        reply.readException();
        data.recycle();
        reply.recycle();
    }

    private IBinder mRemote;
    private IBinder mRemote;
}
}
+16 −0
Original line number Original line Diff line number Diff line
@@ -1163,6 +1163,10 @@ public final class ActivityThread {
        public void scheduleBackgroundMediaPlayingChanged(IBinder token, boolean playing) {
        public void scheduleBackgroundMediaPlayingChanged(IBinder token, boolean playing) {
            sendMessage(H.BACKGROUND_MEDIA_PLAYING_CHANGED, token, playing ? 1 : 0);
            sendMessage(H.BACKGROUND_MEDIA_PLAYING_CHANGED, token, playing ? 1 : 0);
        }
        }

        public void scheduleEnterAnimationComplete(IBinder token) {
            sendMessage(H.ENTER_ANIMATION_COMPLETE, token);
        }
    }
    }


    private class H extends Handler {
    private class H extends Handler {
@@ -1215,6 +1219,7 @@ public final class ActivityThread {
        public static final int ON_NEW_ACTIVITY_OPTIONS = 146;
        public static final int ON_NEW_ACTIVITY_OPTIONS = 146;
        public static final int STOP_MEDIA_PLAYING = 147;
        public static final int STOP_MEDIA_PLAYING = 147;
        public static final int BACKGROUND_MEDIA_PLAYING_CHANGED = 148;
        public static final int BACKGROUND_MEDIA_PLAYING_CHANGED = 148;
        public static final int ENTER_ANIMATION_COMPLETE = 149;


        String codeToString(int code) {
        String codeToString(int code) {
            if (DEBUG_MESSAGES) {
            if (DEBUG_MESSAGES) {
@@ -1267,6 +1272,7 @@ public final class ActivityThread {
                    case ON_NEW_ACTIVITY_OPTIONS: return "ON_NEW_ACTIVITY_OPTIONS";
                    case ON_NEW_ACTIVITY_OPTIONS: return "ON_NEW_ACTIVITY_OPTIONS";
                    case STOP_MEDIA_PLAYING: return "STOP_MEDIA_PLAYING";
                    case STOP_MEDIA_PLAYING: return "STOP_MEDIA_PLAYING";
                    case BACKGROUND_MEDIA_PLAYING_CHANGED: return "BACKGROUND_MEDIA_PLAYING_CHANGED";
                    case BACKGROUND_MEDIA_PLAYING_CHANGED: return "BACKGROUND_MEDIA_PLAYING_CHANGED";
                    case ENTER_ANIMATION_COMPLETE: return "ENTER_ANIMATION_COMPLETE";
                }
                }
            }
            }
            return Integer.toString(code);
            return Integer.toString(code);
@@ -1491,6 +1497,9 @@ public final class ActivityThread {
                case BACKGROUND_MEDIA_PLAYING_CHANGED:
                case BACKGROUND_MEDIA_PLAYING_CHANGED:
                    handleOnBackgroundMediaPlayingChanged((IBinder) msg.obj, msg.arg1 > 0);
                    handleOnBackgroundMediaPlayingChanged((IBinder) msg.obj, msg.arg1 > 0);
                    break;
                    break;
                case ENTER_ANIMATION_COMPLETE:
                    handleEnterAnimationComplete((IBinder) msg.obj);
                    break;
            }
            }
            if (DEBUG_MESSAGES) Slog.v(TAG, "<<< done: " + codeToString(msg.what));
            if (DEBUG_MESSAGES) Slog.v(TAG, "<<< done: " + codeToString(msg.what));
        }
        }
@@ -2509,6 +2518,13 @@ public final class ActivityThread {
        installContentProviders(mInitialApplication, Lists.newArrayList(info));
        installContentProviders(mInitialApplication, Lists.newArrayList(info));
    }
    }


    private void handleEnterAnimationComplete(IBinder token) {
        ActivityClientRecord r = mActivities.get(token);
        if (r != null) {
            r.activity.onEnterAnimationComplete();
        }
    }

    private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>();
    private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>();


    /**
    /**
+18 −0
Original line number Original line Diff line number Diff line
@@ -666,6 +666,15 @@ public abstract class ApplicationThreadNative extends Binder
            reply.writeNoException();
            reply.writeNoException();
            return true;
            return true;
        }
        }

        case ENTER_ANIMATION_COMPLETE_TRANSACTION:
        {
            data.enforceInterface(IApplicationThread.descriptor);
            IBinder token = data.readStrongBinder();
            scheduleEnterAnimationComplete(token);
            reply.writeNoException();
            return true;
        }
        }
        }


        return super.onTransact(code, data, reply, flags);
        return super.onTransact(code, data, reply, flags);
@@ -1342,4 +1351,13 @@ class ApplicationThreadProxy implements IApplicationThread {
        mRemote.transact(BACKGROUND_MEDIA_PLAYING_CHANGED_TRANSACTION, data, null, IBinder.FLAG_ONEWAY);
        mRemote.transact(BACKGROUND_MEDIA_PLAYING_CHANGED_TRANSACTION, data, null, IBinder.FLAG_ONEWAY);
        data.recycle();
        data.recycle();
    }
    }

    @Override
    public void scheduleEnterAnimationComplete(IBinder token) throws RemoteException {
        Parcel data = Parcel.obtain();
        data.writeInterfaceToken(IApplicationThread.descriptor);
        data.writeStrongBinder(token);
        mRemote.transact(ENTER_ANIMATION_COMPLETE_TRANSACTION, data, null, IBinder.FLAG_ONEWAY);
        data.recycle();
    }
}
}
Loading