Merge "TaskOrganizer: Add BLASTSyncEngine example"

This commit is contained in:
Rob Carr
2020-02-12 22:09:23 +00:00
committed by Android (Google) Code Review
3 changed files with 149 additions and 16 deletions

View File

@@ -19,41 +19,135 @@ package com.android.test.taskembed;
import static android.app.WindowConfiguration.WINDOWING_MODE_MULTI_WINDOW;
import android.app.ActivityManager;
import android.app.ActivityTaskManager;
import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.RemoteException;
import android.view.Gravity;
import android.view.ITaskOrganizer;
import android.view.IWindowContainer;
import android.view.MotionEvent;
import android.view.SurfaceControl;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowContainerTransaction;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
public class TaskOrganizerMultiWindowTest extends Activity {
class TaskLaunchingView extends TaskView {
TaskLaunchingView(Context c, ITaskOrganizer o, int windowingMode) {
class SplitLayout extends LinearLayout implements View.OnTouchListener {
View mView1;
View mView2;
View mDividerView;
public boolean onTouch(View v, MotionEvent e) {
if (e.getAction() != MotionEvent.ACTION_UP) {
return true;
}
float x = e.getX(0);
float ratio = (float) x / (float) getWidth() ;
LinearLayout.LayoutParams lp1 =
new LinearLayout.LayoutParams(0,
ViewGroup.LayoutParams.WRAP_CONTENT, ratio-0.02f);
LinearLayout.LayoutParams lp2 =
new LinearLayout.LayoutParams(0,
ViewGroup.LayoutParams.WRAP_CONTENT, 1-ratio-0.02f);
updateViewLayout(mView1, lp2);
updateViewLayout(mView2, lp1);
return true;
}
SplitLayout(Context c, View v1, View v2) {
super(c);
LinearLayout.LayoutParams lp1 =
new LinearLayout.LayoutParams(0,
ViewGroup.LayoutParams.WRAP_CONTENT, 0.48f);
LinearLayout.LayoutParams lp3 =
new LinearLayout.LayoutParams(0,
ViewGroup.LayoutParams.WRAP_CONTENT, 0.48f);
LinearLayout.LayoutParams lp2 =
new LinearLayout.LayoutParams(0,
ViewGroup.LayoutParams.FILL_PARENT, 0.04f);
lp2.gravity = Gravity.CENTER;
setWeightSum(1);
mView1 = v1;
mView2 = v2;
addView(mView1, lp1);
mDividerView = new View(getContext());
mDividerView.setBackgroundColor(Color.BLACK);
addView(mDividerView, lp2);
mDividerView.setOnTouchListener(this);
addView(mView2, lp3);
}
}
class ResizingTaskView extends TaskView {
final Intent mIntent;
boolean launched = false;
ResizingTaskView(Context c, ITaskOrganizer o, int windowingMode, Intent i) {
super(c, o, windowingMode);
mIntent = i;
}
@Override
public void surfaceChanged(SurfaceHolder h, int format, int width, int height) {
startCalculatorActivity(width, height);
if (!launched) {
launchOrganizedActivity(mIntent, width, height);
launched = true;
} else {
resizeTask(width, height);
}
}
void resizeTask(int width, int height) {
final WindowContainerTransaction wct = new WindowContainerTransaction();
wct.setBounds(mWc, new Rect(0, 0, width, height));
try {
ActivityTaskManager.getTaskOrganizerController().applyContainerTransaction(wct,
mOrganizer);
} catch (Exception e) {
// Oh well
}
}
}
TaskView mView;
TaskView mTaskView1;
TaskView mTaskView2;
boolean gotFirstTask = false;
class Organizer extends ITaskOrganizer.Stub {
private int receivedTransactions = 0;
SurfaceControl.Transaction mergedTransaction = new SurfaceControl.Transaction();
@Override
public void taskAppeared(ActivityManager.RunningTaskInfo ti) {
mView.reparentTask(ti.token);
if (!gotFirstTask) {
mTaskView1.reparentTask(ti.token);
gotFirstTask = true;
} else {
mTaskView2.reparentTask(ti.token);
}
}
public void taskVanished(IWindowContainer wc) {
}
public void transactionReady(int id, SurfaceControl.Transaction t) {
mergedTransaction.merge(t);
receivedTransactions++;
if (receivedTransactions == 2) {
mergedTransaction.apply();
receivedTransactions = 0;
}
}
@Override
public void onTaskInfoChanged(ActivityManager.RunningTaskInfo info) {
@@ -66,14 +160,33 @@ public class TaskOrganizerMultiWindowTest extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mView = new TaskLaunchingView(this, mOrganizer, WINDOWING_MODE_MULTI_WINDOW);
setContentView(mView);
try {
ActivityTaskManager.getTaskOrganizerController().registerTaskOrganizer(mOrganizer,
WINDOWING_MODE_MULTI_WINDOW);
} catch (Exception e) {
}
mTaskView1 = new ResizingTaskView(this, mOrganizer, WINDOWING_MODE_MULTI_WINDOW,
makeSettingsIntent());
mTaskView2 = new ResizingTaskView(this, mOrganizer, WINDOWING_MODE_MULTI_WINDOW,
makeContactsIntent());
View splitView = new SplitLayout(this, mTaskView1, mTaskView2);
setContentView(splitView);
}
Intent makeCalculatorIntent() {
Intent makeSettingsIntent() {
Intent intent = new Intent();
intent.setAction(android.provider.Settings.ACTION_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return intent;
}
Intent makeContactsIntent() {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_APP_CALCULATOR);
intent.addCategory(Intent.CATEGORY_APP_CONTACTS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return intent;
}
@@ -85,7 +198,7 @@ public class TaskOrganizerMultiWindowTest extends Activity {
return o.toBundle();
}
void startCalculatorActivity(int width, int height) {
startActivity(makeCalculatorIntent(), makeLaunchOptions(width, height));
void launchOrganizedActivity(Intent i, int width, int height) {
startActivity(i, makeLaunchOptions(width, height));
}
}

View File

@@ -68,6 +68,13 @@ public class TaskOrganizerPipTest extends Service {
public void onCreate() {
super.onCreate();
try {
ActivityTaskManager.getTaskOrganizerController().registerTaskOrganizer(mOrganizer,
WINDOWING_MODE_PINNED);
} catch (Exception e) {
}
final WindowManager.LayoutParams wlp = new WindowManager.LayoutParams();
wlp.setTitle("TaskOrganizerPipTest");
wlp.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;

View File

@@ -31,6 +31,10 @@ import android.view.SurfaceView;
class TaskView extends SurfaceView implements SurfaceHolder.Callback {
final ITaskOrganizer mTaskOrganizer;
final int mWindowingMode;
IWindowContainer mWc;
boolean mSurfaceCreated = false;
boolean mNeedsReparent;
TaskView(Context c, ITaskOrganizer o, int windowingMode) {
super(c);
@@ -43,10 +47,10 @@ class TaskView extends SurfaceView implements SurfaceHolder.Callback {
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
ActivityTaskManager.getTaskOrganizerController().registerTaskOrganizer(mTaskOrganizer,
mWindowingMode);
} catch (Exception e) {
mSurfaceCreated = true;
if (mNeedsReparent) {
mNeedsReparent = false;
reparentLeash();
}
}
@@ -59,10 +63,19 @@ class TaskView extends SurfaceView implements SurfaceHolder.Callback {
}
void reparentTask(IWindowContainer wc) {
mWc = wc;
if (mSurfaceCreated == false) {
mNeedsReparent = true;
} else {
reparentLeash();
}
}
void reparentLeash() {
SurfaceControl.Transaction t = new SurfaceControl.Transaction();
SurfaceControl leash = null;
try {
leash = wc.getLeash();
leash = mWc.getLeash();
} catch (Exception e) {
// System server died.. oh well
}