Added demo for ActiviyView visibility
Allows user to control the ActivityView's visibility at runtime to test the behavior. Test: mmma tests/ActivityViewTest, install apk, and run app Change-Id: Ia01ffa825c2a96a35760574a205c41196c9b1976
This commit is contained in:
@@ -57,5 +57,10 @@
|
||||
android:exported="true"
|
||||
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|colorMode|density">
|
||||
</activity>
|
||||
|
||||
<activity android:name=".ActivityViewVisibilityActivity"
|
||||
android:label="AV Visibility"
|
||||
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|colorMode|density">
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -41,4 +41,10 @@
|
||||
android:text="Test Resize ActivityView"
|
||||
android:textAllCaps="false"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/visibility_activity_view_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Test ActivityView Visibility"
|
||||
android:textAllCaps="false"/>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2019 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" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/visibility_spinner"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ActivityView
|
||||
android:id="@+id/activity_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -35,5 +35,8 @@ public class ActivityViewMainActivity extends Activity {
|
||||
|
||||
findViewById(R.id.resize_activity_view_button).setOnClickListener(
|
||||
v -> startActivity(new Intent(this, ActivityViewResizeActivity.class)));
|
||||
|
||||
findViewById(R.id.visibility_activity_view_button).setOnClickListener(
|
||||
v -> startActivity(new Intent(this, ActivityViewVisibilityActivity.class)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,12 +24,14 @@ import static android.view.MotionEvent.ACTION_UP;
|
||||
import android.app.Activity;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class ActivityViewTestActivity extends Activity {
|
||||
private static final String TAG = "ActivityViewTestActivity";
|
||||
|
||||
private View mRoot;
|
||||
private TextView mTextView;
|
||||
@@ -84,6 +86,7 @@ public class ActivityViewTestActivity extends Activity {
|
||||
}
|
||||
|
||||
private void updateStateText(String state) {
|
||||
Log.d(TAG, state);
|
||||
mTextView.setText(state);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Copyright (c) 2019 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.View.GONE;
|
||||
import static android.view.View.INVISIBLE;
|
||||
import static android.view.View.VISIBLE;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityView;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.Spinner;
|
||||
|
||||
public class ActivityViewVisibilityActivity extends Activity {
|
||||
private static final String[] sVisibilityOptions = {"VISIBLE", "INVISIBLE", "GONE"};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_view_visibility_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 Spinner visibilitySpinner = findViewById(R.id.visibility_spinner);
|
||||
final ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
|
||||
android.R.layout.simple_spinner_item, sVisibilityOptions);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
visibilitySpinner.setAdapter(adapter);
|
||||
visibilitySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
activityView.setVisibility(VISIBLE);
|
||||
break;
|
||||
case 1:
|
||||
activityView.setVisibility(INVISIBLE);
|
||||
break;
|
||||
case 2:
|
||||
activityView.setVisibility(GONE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user