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
This commit is contained in:
12
tests/ActivityViewTest/Android.mk
Normal file
12
tests/ActivityViewTest/Android.mk
Normal file
@@ -0,0 +1,12 @@
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-subdir-java-files)
|
||||
|
||||
LOCAL_PACKAGE_NAME := ActivityViewTest
|
||||
LOCAL_PRIVATE_PLATFORM_APIS := true
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
LOCAL_CERTIFICATE := platform
|
||||
|
||||
include $(BUILD_PACKAGE)
|
||||
58
tests/ActivityViewTest/AndroidManifest.xml
Normal file
58
tests/ActivityViewTest/AndroidManifest.xml
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.google.android.test.activityview">
|
||||
<uses-permission android:name="android.permission.INJECT_EVENTS"/>
|
||||
<uses-permission android:name="android.permission.MANAGE_ACTIVITY_STACKS"/>
|
||||
<uses-permission android:name="android.permission.ACTIVITY_EMBEDDING"/>
|
||||
<uses-permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW"/>
|
||||
|
||||
<uses-sdk android:targetSdkVersion="27"/>
|
||||
<application android:label="ActivityViewTest">
|
||||
<activity android:name=".ActivityViewMainActivity"
|
||||
android:label="AV Main"
|
||||
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|colorMode|density">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ActivityViewActivity"
|
||||
android:label="AV"
|
||||
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|colorMode|density">
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ActivityViewResizeActivity"
|
||||
android:label="AV Resize"
|
||||
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|colorMode|density">
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ActivityViewScrollActivity"
|
||||
android:label="AV Scroll"
|
||||
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|colorMode|density">
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ActivityViewTestActivity"
|
||||
android:resizeableActivity="true"
|
||||
android:theme="@*android:style/Theme.NoTitleBar"
|
||||
android:exported="true"
|
||||
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|colorMode|density">
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
47
tests/ActivityViewTest/res/layout/activity_view_activity.xml
Normal file
47
tests/ActivityViewTest/res/layout/activity_view_activity.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#cfd8dc">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/activity_launch_button"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Launch test activity" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/activity_pick_launch_button"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Launch from picker" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ActivityView
|
||||
android:id="@+id/activity_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/activity_view_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Test ActivityView"
|
||||
android:textAllCaps="false"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/scroll_activity_view_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Test Scroll ActivityView"
|
||||
android:textAllCaps="false"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/resize_activity_view_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Test Resize ActivityView"
|
||||
android:textAllCaps="false"/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#cfd8dc">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/activity_launch_button"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Launch" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/activity_resize_button"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Resize" />
|
||||
</LinearLayout>
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/activity_view_seek_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<ActivityView
|
||||
android:id="@+id/activity_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="600dp" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<Button
|
||||
android:id="@+id/activity_launch_button"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Launch" />
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/activity_view_host_scroll_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:color="#cfd8dc">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="300dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:background="#eeeeee" />
|
||||
|
||||
<ActivityView
|
||||
android:id="@+id/activity_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="300dp"
|
||||
android:background="#fce4ec" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="300dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:background="#eeeeee" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#ffe0b2">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:orientation="vertical"
|
||||
android:background="#00000000" >
|
||||
<TextView
|
||||
android:id="@+id/test_activity_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@android:color/black"
|
||||
android:background="#00000000"
|
||||
android:gravity="center" />
|
||||
<TextView
|
||||
android:id="@+id/test_activity_touch_state"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@android:color/black"
|
||||
android:background="#00000000"
|
||||
android:gravity="center" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/test_activity_width_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@android:color/black"
|
||||
android:background="#00000000"
|
||||
android:gravity="center" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/test_activity_height_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:textColor="@android:color/black"
|
||||
android:background="#00000000"
|
||||
android:gravity="center" />
|
||||
|
||||
<View
|
||||
android:id="@+id/touch_intercept_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#00000000"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user