diff options
| author | 2022-09-07 00:16:18 +0000 | |
|---|---|---|
| committer | 2022-09-07 00:16:18 +0000 | |
| commit | e4be54bdee582819f56c222a1f2536f8a014ca1c (patch) | |
| tree | fa1b6b1c6be3c52cc53af424a531d73df4b3bf7c | |
| parent | 1d404511dde8d1eae40cba9462f2af3b05b991d5 (diff) | |
| parent | 5456d9902b2ea96043d6bbd348b04f731a901536 (diff) | |
Merge "Create test app that mimics GMail" into tm-qpr-dev
13 files changed, 476 insertions, 0 deletions
diff --git a/tests/FlickerTests/test-apps/flickerapp/Android.bp b/tests/FlickerTests/test-apps/flickerapp/Android.bp index 78660c04d8d4..fffe33a019c1 100644 --- a/tests/FlickerTests/test-apps/flickerapp/Android.bp +++ b/tests/FlickerTests/test-apps/flickerapp/Android.bp @@ -24,6 +24,20 @@ package { android_test { name: "FlickerTestApp", srcs: ["**/*.java"], + static_libs: [ + "androidx.annotation_annotation", + "androidx.appcompat_appcompat", + "androidx-constraintlayout_constraintlayout", + "androidx.core_core", + "androidx.fragment_fragment", + "androidx.recyclerview_recyclerview", + "androidx.navigation_navigation-common-ktx", + "androidx.navigation_navigation-fragment-ktx", + "androidx.navigation_navigation-runtime-ktx", + "androidx.navigation_navigation-ui-ktx", + "kotlin-stdlib", + "kotlinx-coroutines-android", + ], sdk_version: "current", test_suites: ["device-tests"], } diff --git a/tests/FlickerTests/test-apps/flickerapp/AndroidManifest.xml b/tests/FlickerTests/test-apps/flickerapp/AndroidManifest.xml index 3e2130dc480f..25216a3176cb 100644 --- a/tests/FlickerTests/test-apps/flickerapp/AndroidManifest.xml +++ b/tests/FlickerTests/test-apps/flickerapp/AndroidManifest.xml @@ -163,5 +163,15 @@ <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> + <activity android:name=".MailActivity" + android:exported="true" + android:label="MailApp" + android:taskAffinity="com.android.server.wm.flicker.testapp.MailActivity" + android:theme="@style/Theme.AppCompat.Light"> + <intent-filter> + <action android:name="android.intent.action.MAIN"/> + <category android:name="android.intent.category.LAUNCHER"/> + </intent-filter> + </activity> </application> </manifest> diff --git a/tests/FlickerTests/test-apps/flickerapp/res/anim/slide_in_from_bottom.xml b/tests/FlickerTests/test-apps/flickerapp/res/anim/slide_in_from_bottom.xml new file mode 100644 index 000000000000..c0165e5c1086 --- /dev/null +++ b/tests/FlickerTests/test-apps/flickerapp/res/anim/slide_in_from_bottom.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2022 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. + --> +<set + xmlns:android="http://schemas.android.com/apk/res/android" + android:interpolator="@android:anim/linear_interpolator" + android:shareInterpolator="false"> + <translate + android:duration="500" + android:fromYDelta="100%p" + android:toYDelta="0%p" /> +</set> diff --git a/tests/FlickerTests/test-apps/flickerapp/res/layout/activity_mail.xml b/tests/FlickerTests/test-apps/flickerapp/res/layout/activity_mail.xml new file mode 100644 index 000000000000..8a97433ede04 --- /dev/null +++ b/tests/FlickerTests/test-apps/flickerapp/res/layout/activity_mail.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2022 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. + --> + +<androidx.constraintlayout.widget.ConstraintLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent"> + <fragment + android:id="@+id/main_fragment" + android:name="androidx.navigation.fragment.NavHostFragment" + android:layout_width="match_parent" + android:layout_height="match_parent" + app:defaultNavHost="true" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:navGraph="@navigation/mail_navigation"></fragment> +</androidx.constraintlayout.widget.ConstraintLayout> diff --git a/tests/FlickerTests/test-apps/flickerapp/res/layout/fragment_mail_content.xml b/tests/FlickerTests/test-apps/flickerapp/res/layout/fragment_mail_content.xml new file mode 100644 index 000000000000..fbbdc5b812ad --- /dev/null +++ b/tests/FlickerTests/test-apps/flickerapp/res/layout/fragment_mail_content.xml @@ -0,0 +1,21 @@ +<!-- + ~ Copyright (C) 2022 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"> +</LinearLayout> diff --git a/tests/FlickerTests/test-apps/flickerapp/res/layout/fragment_mail_list.xml b/tests/FlickerTests/test-apps/flickerapp/res/layout/fragment_mail_list.xml new file mode 100644 index 000000000000..0e30745bdfc9 --- /dev/null +++ b/tests/FlickerTests/test-apps/flickerapp/res/layout/fragment_mail_list.xml @@ -0,0 +1,25 @@ +<!-- + ~ Copyright (C) 2022 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"> + <androidx.recyclerview.widget.RecyclerView + android:id="@+id/mail_recycle_view" + android:layout_width="match_parent" + android:layout_height="match_parent"/> +</LinearLayout>
\ No newline at end of file diff --git a/tests/FlickerTests/test-apps/flickerapp/res/layout/mail_row_item.xml b/tests/FlickerTests/test-apps/flickerapp/res/layout/mail_row_item.xml new file mode 100644 index 000000000000..c39bfb35e9b0 --- /dev/null +++ b/tests/FlickerTests/test-apps/flickerapp/res/layout/mail_row_item.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2022 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="@dimen/list_item_height" + android:layout_marginLeft="@dimen/margin_medium" + android:layout_marginRight="@dimen/margin_medium"> + <ImageView + android:id="@+id/mail_row_item_icon" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:paddingBottom="@dimen/padding_small" + android:paddingEnd="@dimen/padding_small" + android:paddingStart="@dimen/padding_small" + android:paddingTop="@dimen/padding_small"/> + <TextView + android:id="@+id/mail_row_item_text" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="center_vertical" + android:paddingEnd="@dimen/padding_small" + android:textSize="@dimen/list_item_text_size" /> +</LinearLayout> diff --git a/tests/FlickerTests/test-apps/flickerapp/res/navigation/mail_navigation.xml b/tests/FlickerTests/test-apps/flickerapp/res/navigation/mail_navigation.xml new file mode 100644 index 000000000000..d12707a7a123 --- /dev/null +++ b/tests/FlickerTests/test-apps/flickerapp/res/navigation/mail_navigation.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2022 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. + --> + +<navigation xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:id="@+id/mail_navigation" + app:startDestination="@id/fragment_mail_list"> + <fragment + android:id="@+id/fragment_mail_list" + android:name=".MailListFragment" + android:label="Mail List"> + <action + android:id="@+id/action_mail_list_to_mail_content" + app:destination="@id/fragment_mail_content" + app:enterAnim="@anim/slide_in_from_bottom" /> + </fragment> + <fragment + android:id="@+id/fragment_mail_content" + android:name=".MailContentFragment" + android:label="Mail Content"> + </fragment> +</navigation> diff --git a/tests/FlickerTests/test-apps/flickerapp/res/values/dimens.xml b/tests/FlickerTests/test-apps/flickerapp/res/values/dimens.xml new file mode 100644 index 000000000000..0b0763d7071d --- /dev/null +++ b/tests/FlickerTests/test-apps/flickerapp/res/values/dimens.xml @@ -0,0 +1,24 @@ +<!-- + ~ Copyright (C) 2022 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. + --> + +<resources> + <dimen name="padding_small">8dp</dimen> + <dimen name="margin_medium">16dp</dimen> + <dimen name="list_item_height">72dp</dimen> + <dimen name="list_item_text_size">24dp</dimen> + <dimen name="icon_size">64dp</dimen> + <dimen name="icon_text_size">36dp</dimen> +</resources> diff --git a/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/MailActivity.java b/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/MailActivity.java new file mode 100644 index 000000000000..419d438baf69 --- /dev/null +++ b/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/MailActivity.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2022 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.android.server.wm.flicker.testapp; + +import android.os.Bundle; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +public class MailActivity extends AppCompatActivity { + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_mail); + } +} diff --git a/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/MailAdapter.java b/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/MailAdapter.java new file mode 100644 index 000000000000..984263acebac --- /dev/null +++ b/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/MailAdapter.java @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2022 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.android.server.wm.flicker.testapp; + +import static androidx.navigation.fragment.NavHostFragment.findNavController; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Typeface; +import android.graphics.drawable.ShapeDrawable; +import android.graphics.drawable.shapes.OvalShape; +import android.graphics.drawable.shapes.Shape; +import android.util.DisplayMetrics; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.navigation.NavController; +import androidx.recyclerview.widget.RecyclerView; + +public class MailAdapter extends RecyclerView.Adapter<MailAdapter.ViewHolder> { + + private final Fragment mFragment; + private final int mSize; + + static class BadgeShape extends OvalShape { + Context mContext; + String mLabel; + + BadgeShape(Context context, String label) { + mContext = context; + mLabel = label; + } + + @Override + public void draw(Canvas canvas, Paint paint) { + final Resources resources = mContext.getResources(); + int textSize = resources.getDimensionPixelSize(R.dimen.icon_text_size); + paint.setColor(Color.BLACK); + super.draw(canvas, paint); + paint.setColor(Color.WHITE); + paint.setTextSize(textSize); + paint.setTypeface(Typeface.DEFAULT_BOLD); + paint.setTextAlign(Paint.Align.CENTER); + Paint.FontMetrics fontMetrics = paint.getFontMetrics(); + float distance = (fontMetrics.bottom - fontMetrics.top) / 2 - fontMetrics.bottom; + canvas.drawText( + mLabel, + rect().centerX(), + rect().centerY() + distance, + paint); + } + } + + static class ViewHolder extends RecyclerView.ViewHolder { + + NavController mNavController; + ImageView mImageView; + TextView mTextView; + DisplayMetrics mDisplayMetrics; + + ViewHolder(@NonNull View itemView, NavController navController) { + super(itemView); + mNavController = navController; + itemView.setOnClickListener(this::onClick); + mImageView = itemView.findViewById(R.id.mail_row_item_icon); + mTextView = itemView.findViewById(R.id.mail_row_item_text); + mDisplayMetrics = itemView.getContext().getResources().getDisplayMetrics(); + } + + void onClick(View v) { + mNavController.navigate(R.id.action_mail_list_to_mail_content); + } + + public void setContent(int i) { + final Resources resources = mImageView.getContext().getResources(); + final int badgeSize = resources.getDimensionPixelSize(R.dimen.icon_size); + final char c = (char) ('A' + i % 26); + final Shape badge = new BadgeShape(mImageView.getContext(), String.valueOf(c)); + ShapeDrawable drawable = new ShapeDrawable(); + drawable.setIntrinsicHeight(badgeSize); + drawable.setIntrinsicWidth(badgeSize); + drawable.setShape(badge); + mImageView.setImageDrawable(drawable); + mTextView.setText(String.format("%s-%04d", c, i)); + } + } + + public MailAdapter(Fragment fragment, int size) { + super(); + mFragment = fragment; + mSize = size; + } + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { + View v = LayoutInflater + .from(viewGroup.getContext()) + .inflate(R.layout.mail_row_item, viewGroup, false); + return new ViewHolder(v, findNavController(mFragment)); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) { + viewHolder.setContent(i); + } + + @Override + public int getItemCount() { + return mSize; + } +} diff --git a/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/MailContentFragment.java b/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/MailContentFragment.java new file mode 100644 index 000000000000..278b92e4b353 --- /dev/null +++ b/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/MailContentFragment.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2022 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.android.server.wm.flicker.testapp; + +import android.graphics.Color; +import android.os.Bundle; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +public class MailContentFragment extends Fragment { + public MailContentFragment() { + super(R.layout.fragment_mail_content); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + view.setBackgroundColor(Color.LTGRAY); + } +} diff --git a/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/MailListFragment.java b/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/MailListFragment.java new file mode 100644 index 000000000000..551820c3322b --- /dev/null +++ b/tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/MailListFragment.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2022 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.android.server.wm.flicker.testapp; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +public class MailListFragment extends Fragment { + + protected RecyclerView mRecyclerView; + protected RecyclerView.LayoutManager mLayoutManager; + protected MailAdapter mAdapter; + + public MailListFragment() { + super(R.layout.fragment_mail_list); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_mail_list, container, false); + mRecyclerView = rootView.findViewById(R.id.mail_recycle_view); + mAdapter = new MailAdapter(this, 1000); + mRecyclerView.setAdapter(mAdapter); + mLayoutManager = new LinearLayoutManager(getActivity()); + mRecyclerView.setLayoutManager(mLayoutManager); + return rootView; + } +} |