Show progress on device when Android render test is running (#4119)
This commit is contained in:
@@ -16,7 +16,7 @@ import org.junit.runner.RunWith;
|
||||
public class NativeActivityTest {
|
||||
|
||||
@Rule
|
||||
public ActivityTestRule<NativeActivity> mActivityTestRule = new ActivityTestRule<>(NativeActivity.class, false, false);
|
||||
public ActivityTestRule<RenderTestActivity> mActivityTestRule = new ActivityTestRule<>(RenderTestActivity.class, false, false);
|
||||
|
||||
@Test(timeout = 600000L)
|
||||
public void runRenderTests() throws Exception {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
android:debuggable="true"
|
||||
tools:ignore="HardcodedDebugMode">
|
||||
|
||||
<activity android:name="android.app.NativeActivity"
|
||||
<activity android:name="android.app.RenderTestActivity"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="portrait"
|
||||
android:exported="true">
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package android.app;
|
||||
|
||||
import android.graphics.PixelFormat;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class RenderTestActivity extends NativeActivity {
|
||||
|
||||
private TextView progressTextView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
progressTextView = new TextView(this);
|
||||
progressTextView.setText("Starting tests...");
|
||||
progressTextView.setTextSize(18f);
|
||||
progressTextView.setTextColor(0xFFFFFFFF);
|
||||
progressTextView.setShadowLayer(2f, 1f, 1f, 0xFF000000);
|
||||
progressTextView.setPadding(24, 24, 24, 24);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
|
||||
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
|
||||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
WindowManager.LayoutParams.TYPE_APPLICATION_PANEL,
|
||||
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
|
||||
PixelFormat.TRANSLUCENT
|
||||
);
|
||||
params.gravity = Gravity.TOP | Gravity.START;
|
||||
params.token = getWindow().getDecorView().getWindowToken();
|
||||
|
||||
getWindowManager().addView(progressTextView, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromWindow() {
|
||||
if (progressTextView != null) {
|
||||
getWindowManager().removeView(progressTextView);
|
||||
}
|
||||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from C++ via JNI to update the progress display.
|
||||
*/
|
||||
public void updateProgress(final int completed, final int total) {
|
||||
runOnUiThread(() -> {
|
||||
if (progressTextView != null) {
|
||||
progressTextView.setText(completed + " / " + total + " tests complete");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user