FileDocCategorySizeDatePackage
ActivityView.javaAPI DocAndroid 5.1 API16484Thu Mar 12 22:22:10 GMT 2015android.app

ActivityView

public class ActivityView extends android.view.ViewGroup
hide

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
android.util.DisplayMetrics
mMetrics
private final android.view.TextureView
mTextureView
private ActivityContainerWrapper
mActivityContainer
private Activity
mActivity
private int
mWidth
private int
mHeight
private android.view.Surface
mSurface
private int
mLastVisibility
private ActivityViewCallback
mActivityViewCallback
android.content.IIntentSender
mQueuedPendingIntent
android.content.Intent
mQueuedIntent
Constructors Summary
public ActivityView(android.content.Context context)


       
        this(context, null);
    
public ActivityView(android.content.Context context, android.util.AttributeSet attrs)

        this(context, attrs, 0);
    
public ActivityView(android.content.Context context, android.util.AttributeSet attrs, int defStyle)

        super(context, attrs, defStyle);

        while (context instanceof ContextWrapper) {
            if (context instanceof Activity) {
                mActivity = (Activity)context;
                break;
            }
            context = ((ContextWrapper)context).getBaseContext();
        }
        if (mActivity == null) {
            throw new IllegalStateException("The ActivityView's Context is not an Activity.");
        }

        try {
            mActivityContainer = new ActivityContainerWrapper(
                    ActivityManagerNative.getDefault().createActivityContainer(
                            mActivity.getActivityToken(), new ActivityContainerCallback(this)));
        } catch (RemoteException e) {
            throw new RuntimeException("ActivityView: Unable to create ActivityContainer. "
                    + e);
        }

        mTextureView = new TextureView(context);
        mTextureView.setSurfaceTextureListener(new ActivityViewSurfaceTextureListener());
        addView(mTextureView);

        WindowManager wm = (WindowManager)mActivity.getSystemService(Context.WINDOW_SERVICE);
        mMetrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(mMetrics);

        mLastVisibility = getVisibility();

        if (DEBUG) Log.v(TAG, "ctor()");
    
Methods Summary
private voidattachToSurfaceWhenReady()

        final SurfaceTexture surfaceTexture = mTextureView.getSurfaceTexture();
        if (surfaceTexture == null || mSurface != null) {
            // Either not ready to attach, or already attached.
            return;
        }

        mSurface = new Surface(surfaceTexture);
        try {
            mActivityContainer.setSurface(mSurface, mWidth, mHeight, mMetrics.densityDpi);
        } catch (RemoteException e) {
            mSurface.release();
            mSurface = null;
            throw new RuntimeException("ActivityView: Unable to create ActivityContainer. " + e);
        }

        if (DEBUG) Log.v(TAG, "attachToSurfaceWhenReady: " + (mQueuedIntent != null ||
                mQueuedPendingIntent != null ? "" : "no") + " queued intent");
        if (mQueuedIntent != null) {
            mActivityContainer.startActivity(mQueuedIntent);
            mQueuedIntent = null;
        } else if (mQueuedPendingIntent != null) {
            mActivityContainer.startActivityIntentSender(mQueuedPendingIntent);
            mQueuedPendingIntent = null;
        }
    
private booleaninjectInputEvent(android.view.InputEvent event)

        return mActivityContainer != null && mActivityContainer.injectEvent(event);
    
public booleanisAttachedToDisplay()

        return mSurface != null;
    
public voidonAttachedToWindow()

        if (DEBUG) Log.v(TAG, "onAttachedToWindow(): mActivityContainer=" + mActivityContainer +
                " mSurface=" + mSurface);
    
public voidonDetachedFromWindow()

        if (DEBUG) Log.v(TAG, "onDetachedFromWindow(): mActivityContainer=" + mActivityContainer +
                " mSurface=" + mSurface);
    
public booleanonGenericMotionEvent(android.view.MotionEvent event)

        if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) {
            if (injectInputEvent(event)) {
                return true;
            }
        }
        return super.onGenericMotionEvent(event);
    
protected voidonLayout(boolean changed, int l, int t, int r, int b)

        mTextureView.layout(0, 0, r - l, b - t);
    
public booleanonTouchEvent(android.view.MotionEvent event)

        return injectInputEvent(event) || super.onTouchEvent(event);
    
protected voidonVisibilityChanged(android.view.View changedView, int visibility)

        super.onVisibilityChanged(changedView, visibility);

        if (mSurface != null) {
            try {
                if (visibility == View.GONE) {
                    mActivityContainer.setSurface(null, mWidth, mHeight, mMetrics.densityDpi);
                } else if (mLastVisibility == View.GONE) {
                    // Don't change surface when going between View.VISIBLE and View.INVISIBLE.
                    mActivityContainer.setSurface(mSurface, mWidth, mHeight, mMetrics.densityDpi);
                }
            } catch (RemoteException e) {
                throw new RuntimeException(
                        "ActivityView: Unable to set surface of ActivityContainer. " + e);
            }
        }
        mLastVisibility = visibility;
    
public voidrelease()

        if (DEBUG) Log.v(TAG, "release() mActivityContainer=" + mActivityContainer +
                " mSurface=" + mSurface);
        if (mActivityContainer == null) {
            Log.e(TAG, "Duplicate call to release");
            return;
        }
        mActivityContainer.release();
        mActivityContainer = null;

        if (mSurface != null) {
            mSurface.release();
            mSurface = null;
        }

        mTextureView.setSurfaceTextureListener(null);
    
public voidsetCallback(android.app.ActivityView$ActivityViewCallback callback)
Set the callback to use to report certain state changes.

param
callback The callback to report events to.
see
ActivityViewCallback

        mActivityViewCallback = callback;
    
public voidstartActivity(android.content.Intent intent)

        if (mActivityContainer == null) {
            throw new IllegalStateException("Attempt to call startActivity after release");
        }
        if (DEBUG) Log.v(TAG, "startActivity(): intent=" + intent + " " +
                (isAttachedToDisplay() ? "" : "not") + " attached");
        if (mSurface != null) {
            mActivityContainer.startActivity(intent);
        } else {
            mActivityContainer.checkEmbeddedAllowed(intent);
            mQueuedIntent = intent;
            mQueuedPendingIntent = null;
        }
    
public voidstartActivity(android.content.IntentSender intentSender)

        if (mActivityContainer == null) {
            throw new IllegalStateException("Attempt to call startActivity after release");
        }
        if (DEBUG) Log.v(TAG, "startActivityIntentSender(): intentSender=" + intentSender + " " +
                (isAttachedToDisplay() ? "" : "not") + " attached");
        final IIntentSender iIntentSender = intentSender.getTarget();
        if (mSurface != null) {
            mActivityContainer.startActivityIntentSender(iIntentSender);
        } else {
            mActivityContainer.checkEmbeddedAllowedIntentSender(iIntentSender);
            mQueuedPendingIntent = iIntentSender;
            mQueuedIntent = null;
        }
    
public voidstartActivity(PendingIntent pendingIntent)

        if (mActivityContainer == null) {
            throw new IllegalStateException("Attempt to call startActivity after release");
        }
        if (DEBUG) Log.v(TAG, "startActivityPendingIntent(): PendingIntent=" + pendingIntent + " "
                + (isAttachedToDisplay() ? "" : "not") + " attached");
        final IIntentSender iIntentSender = pendingIntent.getTarget();
        if (mSurface != null) {
            mActivityContainer.startActivityIntentSender(iIntentSender);
        } else {
            mActivityContainer.checkEmbeddedAllowedIntentSender(iIntentSender);
            mQueuedPendingIntent = iIntentSender;
            mQueuedIntent = null;
        }