Merge "ActivityView: set surface on a background thread." into cw-d-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d88e4d50d6
@@ -24,7 +24,10 @@ import android.content.IIntentSender;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentSender;
|
import android.content.IntentSender;
|
||||||
import android.graphics.SurfaceTexture;
|
import android.graphics.SurfaceTexture;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.HandlerThread;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.os.Message;
|
||||||
import android.os.OperationCanceledException;
|
import android.os.OperationCanceledException;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
@@ -48,7 +51,9 @@ public class ActivityView extends ViewGroup {
|
|||||||
private static final String TAG = "ActivityView";
|
private static final String TAG = "ActivityView";
|
||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
|
|
||||||
DisplayMetrics mMetrics;
|
private static final int MSG_SET_SURFACE = 1;
|
||||||
|
|
||||||
|
DisplayMetrics mMetrics = new DisplayMetrics();
|
||||||
private final TextureView mTextureView;
|
private final TextureView mTextureView;
|
||||||
private ActivityContainerWrapper mActivityContainer;
|
private ActivityContainerWrapper mActivityContainer;
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
@@ -58,6 +63,9 @@ public class ActivityView extends ViewGroup {
|
|||||||
private int mLastVisibility;
|
private int mLastVisibility;
|
||||||
private ActivityViewCallback mActivityViewCallback;
|
private ActivityViewCallback mActivityViewCallback;
|
||||||
|
|
||||||
|
private HandlerThread mThread = new HandlerThread("ActivityViewThread");
|
||||||
|
private Handler mHandler;
|
||||||
|
|
||||||
public ActivityView(Context context) {
|
public ActivityView(Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
}
|
}
|
||||||
@@ -89,12 +97,27 @@ public class ActivityView extends ViewGroup {
|
|||||||
+ e);
|
+ e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mThread.start();
|
||||||
|
mHandler = new Handler(mThread.getLooper()) {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
super.handleMessage(msg);
|
||||||
|
if (msg.what == MSG_SET_SURFACE) {
|
||||||
|
try {
|
||||||
|
mActivityContainer.setSurface((Surface) msg.obj, msg.arg1, msg.arg2,
|
||||||
|
mMetrics.densityDpi);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"ActivityView: Unable to set surface of ActivityContainer. " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
mTextureView = new TextureView(context);
|
mTextureView = new TextureView(context);
|
||||||
mTextureView.setSurfaceTextureListener(new ActivityViewSurfaceTextureListener());
|
mTextureView.setSurfaceTextureListener(new ActivityViewSurfaceTextureListener());
|
||||||
addView(mTextureView);
|
addView(mTextureView);
|
||||||
|
|
||||||
WindowManager wm = (WindowManager)mActivity.getSystemService(Context.WINDOW_SERVICE);
|
WindowManager wm = (WindowManager)mActivity.getSystemService(Context.WINDOW_SERVICE);
|
||||||
mMetrics = new DisplayMetrics();
|
|
||||||
wm.getDefaultDisplay().getMetrics(mMetrics);
|
wm.getDefaultDisplay().getMetrics(mMetrics);
|
||||||
|
|
||||||
mLastVisibility = getVisibility();
|
mLastVisibility = getVisibility();
|
||||||
@@ -111,18 +134,12 @@ public class ActivityView extends ViewGroup {
|
|||||||
protected void onVisibilityChanged(View changedView, int visibility) {
|
protected void onVisibilityChanged(View changedView, int visibility) {
|
||||||
super.onVisibilityChanged(changedView, visibility);
|
super.onVisibilityChanged(changedView, visibility);
|
||||||
|
|
||||||
if (mSurface != null) {
|
if (mSurface != null && (visibility == View.GONE || mLastVisibility == View.GONE)) {
|
||||||
try {
|
Message msg = Message.obtain(mHandler, MSG_SET_SURFACE);
|
||||||
if (visibility == View.GONE) {
|
msg.obj = (visibility == View.GONE) ? null : mSurface;
|
||||||
mActivityContainer.setSurface(null, mWidth, mHeight, mMetrics.densityDpi);
|
msg.arg1 = mWidth;
|
||||||
} else if (mLastVisibility == View.GONE) {
|
msg.arg2 = mHeight;
|
||||||
// Don't change surface when going between View.VISIBLE and View.INVISIBLE.
|
mHandler.sendMessage(msg);
|
||||||
mActivityContainer.setSurface(mSurface, mWidth, mHeight, mMetrics.densityDpi);
|
|
||||||
}
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
throw new RuntimeException(
|
|
||||||
"ActivityView: Unable to set surface of ActivityContainer. " + e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mLastVisibility = visibility;
|
mLastVisibility = visibility;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user