summaryrefslogtreecommitdiff
path: root/tests/ActivityViewTest/src
diff options
context:
space:
mode:
author Andrii Kulian <akulian@google.com> 2018-01-23 20:17:31 -0800
committer chaviw <chaviw@google.com> 2018-07-23 14:40:03 -0700
commit962e43401a919df729fc965b68be6ee09e138fb6 (patch)
tree87ec75eae1ef88402f99c0989e77389c72e8745d /tests/ActivityViewTest/src
parent78c1e790b3e3de3062897277d2af993b66be1502 (diff)
ActivityView demo app
Contains demos for - Launching activities into an ActivityView - Resizing ActivityView with activities inside - Changing position of ActivityView on screen This is a standalone APK and can be built with: mmma tests/ActivityViewTest Test: Manual Change-Id: I548a087ef42163b86be7607c5b1bfcf8119d54e5
Diffstat (limited to 'tests/ActivityViewTest/src')
-rw-r--r--tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewActivity.java51
-rw-r--r--tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewMainActivity.java39
-rw-r--r--tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewResizeActivity.java79
-rw-r--r--tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewScrollActivity.java44
-rw-r--r--tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewTestActivity.java115
5 files changed, 328 insertions, 0 deletions
diff --git a/tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewActivity.java b/tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewActivity.java
new file mode 100644
index 000000000000..1548d6ed8a03
--- /dev/null
+++ b/tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewActivity.java
@@ -0,0 +1,51 @@
+/**
+ * Copyright (c) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.android.test.activityview;
+
+import android.app.Activity;
+import android.app.ActivityView;
+import android.content.Intent;
+import android.os.Bundle;
+import android.widget.Button;
+
+public class ActivityViewActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_view_activity);
+
+ final ActivityView activityView = findViewById(R.id.activity_view);
+ final Button launchButton = findViewById(R.id.activity_launch_button);
+ launchButton.setOnClickListener(v -> {
+ final Intent intent = new Intent(this, ActivityViewTestActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
+ activityView.startActivity(intent);
+ });
+ final Button pickActivityLaunchButton = findViewById(R.id.activity_pick_launch_button);
+ pickActivityLaunchButton.setOnClickListener(v -> {
+ final Intent intent = Intent.makeMainActivity(null);
+ final Intent chooser = Intent.createChooser(intent,
+ "Pick an app to launch in ActivityView");
+ if (intent.resolveActivity(getPackageManager()) != null) {
+ chooser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+ | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
+ activityView.startActivity(chooser);
+ }
+ });
+ }
+}
diff --git a/tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewMainActivity.java b/tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewMainActivity.java
new file mode 100644
index 000000000000..66f0c6a56afd
--- /dev/null
+++ b/tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewMainActivity.java
@@ -0,0 +1,39 @@
+/**
+ * Copyright (c) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.android.test.activityview;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+
+public class ActivityViewMainActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_view_main_activity);
+
+ findViewById(R.id.activity_view_button).setOnClickListener(
+ v -> startActivity(new Intent(this, ActivityViewActivity.class)));
+
+ findViewById(R.id.scroll_activity_view_button).setOnClickListener(
+ v -> startActivity(new Intent(this, ActivityViewScrollActivity.class)));
+
+ findViewById(R.id.resize_activity_view_button).setOnClickListener(
+ v -> startActivity(new Intent(this, ActivityViewResizeActivity.class)));
+ }
+}
diff --git a/tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewResizeActivity.java b/tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewResizeActivity.java
new file mode 100644
index 000000000000..8860a771fd5a
--- /dev/null
+++ b/tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewResizeActivity.java
@@ -0,0 +1,79 @@
+/**
+ * Copyright (c) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.android.test.activityview;
+
+import android.app.Activity;
+import android.app.ActivityView;
+import android.content.Intent;
+import android.os.Bundle;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.SeekBar;
+
+public class ActivityViewResizeActivity extends Activity {
+ private static final int SMALL_SIZE = 600;
+ private static final int LARGE_SIZE = 1200;
+
+ private ActivityView mActivityView;
+
+ private boolean mFlipSize;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_view_resize_activity);
+
+ mActivityView = findViewById(R.id.activity_view);
+
+ final Button launchButton = findViewById(R.id.activity_launch_button);
+ launchButton.setOnClickListener(v -> {
+ final Intent intent = new Intent(this, ActivityViewTestActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
+ mActivityView.startActivity(intent);
+ });
+ final Button resizeButton = findViewById(R.id.activity_resize_button);
+ if (resizeButton != null) {
+ resizeButton.setOnClickListener(v -> {
+ LinearLayout.LayoutParams params =
+ (LinearLayout.LayoutParams) mActivityView.getLayoutParams();
+ params.height = mFlipSize ? SMALL_SIZE : LARGE_SIZE;
+ mFlipSize = !mFlipSize;
+ mActivityView.setLayoutParams(params);
+ });
+ }
+ final SeekBar seekBar = findViewById(R.id.activity_view_seek_bar);
+ if (seekBar != null) {
+ seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ final LinearLayout.LayoutParams params =
+ (LinearLayout.LayoutParams) mActivityView.getLayoutParams();
+ params.height = SMALL_SIZE + progress * 10;
+ mActivityView.setLayoutParams(params);
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ }
+ });
+ }
+ }
+}
diff --git a/tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewScrollActivity.java b/tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewScrollActivity.java
new file mode 100644
index 000000000000..56543662675c
--- /dev/null
+++ b/tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewScrollActivity.java
@@ -0,0 +1,44 @@
+/**
+ * Copyright (c) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.android.test.activityview;
+
+import android.app.Activity;
+import android.app.ActivityView;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+
+public class ActivityViewScrollActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_view_scroll_activity);
+
+ final ActivityView activityView = findViewById(R.id.activity_view);
+ final Button launchButton = findViewById(R.id.activity_launch_button);
+ launchButton.setOnClickListener(v -> {
+ final Intent intent = new Intent(this, ActivityViewTestActivity.class);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
+ activityView.startActivity(intent);
+ });
+ findViewById(R.id.activity_view_host_scroll_view).setOnScrollChangeListener(
+ (View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY)
+ -> activityView.onLocationChanged());
+ }
+}
diff --git a/tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewTestActivity.java b/tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewTestActivity.java
new file mode 100644
index 000000000000..0d62786f40b0
--- /dev/null
+++ b/tests/ActivityViewTest/src/com/google/android/test/activityview/ActivityViewTestActivity.java
@@ -0,0 +1,115 @@
+/**
+ * Copyright (c) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.android.test.activityview;
+
+import static android.view.MotionEvent.ACTION_CANCEL;
+import static android.view.MotionEvent.ACTION_DOWN;
+import static android.view.MotionEvent.ACTION_MOVE;
+import static android.view.MotionEvent.ACTION_UP;
+
+import android.app.Activity;
+import android.content.res.Configuration;
+import android.os.Bundle;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewTreeObserver;
+import android.widget.TextView;
+
+public class ActivityViewTestActivity extends Activity implements View.OnTouchListener {
+
+ private TextView mTextView;
+ private TextView mWidthTextView;
+ private TextView mHeightTextView;
+ private TextView mTouchStateTextView;
+ private View mTouchInterceptView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_view_test_activity);
+
+ mTextView = findViewById(R.id.test_activity_title);
+ mWidthTextView = findViewById(R.id.test_activity_width_text);
+ mHeightTextView = findViewById(R.id.test_activity_height_text);
+ mTouchStateTextView = findViewById(R.id.test_activity_touch_state);
+ mTouchInterceptView = findViewById(R.id.touch_intercept_view);
+ mTouchInterceptView.setOnTouchListener(this);
+ ViewTreeObserver viewTreeObserver = mTouchInterceptView.getViewTreeObserver();
+ if (viewTreeObserver.isAlive()) {
+ viewTreeObserver.addOnGlobalLayoutListener(this::updateDimensionTexts);
+ }
+ updateStateText("CREATED");
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ updateStateText("STARTED");
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ updateStateText("RESUMED");
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ updateStateText("PAUSED");
+ }
+
+ @Override
+ protected void onStop() {
+ super.onStop();
+ updateStateText("STOPPED");
+ }
+
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ updateDimensionTexts();
+ }
+
+ private void updateStateText(String state) {
+ mTextView.setText(state);
+ }
+
+ private void updateDimensionTexts() {
+ mWidthTextView.setText("" + mTouchInterceptView.getWidth());
+ mHeightTextView.setText("" + mTouchInterceptView.getHeight());
+ }
+
+ private void updateTouchState(MotionEvent event) {
+ switch (event.getAction()) {
+ case ACTION_DOWN:
+ case ACTION_MOVE:
+ mTouchStateTextView.setText("[" + event.getX() + "," + event.getY() + "]");
+ break;
+ case ACTION_UP:
+ case ACTION_CANCEL:
+ mTouchStateTextView.setText("");
+ break;
+ }
+ }
+
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ updateTouchState(event);
+ return true;
+ }
+}