1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.wear.widget;
18 
19 import android.os.Bundle;
20 import android.view.Gravity;
21 import android.view.View;
22 import android.view.ViewGroup;
23 import android.widget.TextView;
24 
25 import androidx.recyclerview.widget.LinearLayoutManager;
26 import androidx.recyclerview.widget.RecyclerView;
27 import androidx.wear.test.R;
28 
29 public class SwipeDismissFrameLayoutTestActivity extends LayoutTestActivity {
30 
31     public static final String EXTRA_LAYOUT_HORIZONTAL = "layout_horizontal";
32 
33     @Override
onCreate(Bundle savedInstanceState)34     protected void onCreate(Bundle savedInstanceState) {
35         super.onCreate(savedInstanceState);
36         int layoutId = getIntent().getIntExtra(EXTRA_LAYOUT_RESOURCE_ID, -1);
37         boolean horizontal = getIntent().getBooleanExtra(EXTRA_LAYOUT_HORIZONTAL, false);
38 
39         if (layoutId == R.layout.swipe_dismiss_layout_testcase_2) {
40             createScrollableContent(horizontal);
41         }
42     }
43 
createScrollableContent(boolean horizontal)44     private void createScrollableContent(boolean horizontal) {
45         RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_container);
46         if (recyclerView == null) {
47             throw new NullPointerException("There has to be a relevant container defined");
48         }
49         recyclerView.setLayoutManager(
50                 new LinearLayoutManager(
51                         this,
52                         horizontal ? LinearLayoutManager.HORIZONTAL : LinearLayoutManager.VERTICAL,
53                         false));
54         recyclerView.setAdapter(new MyRecyclerViewAdapter());
55     }
56 
57     private static class MyRecyclerViewAdapter
58             extends RecyclerView.Adapter<MyRecyclerViewAdapter.CustomViewHolder> {
59         @Override
onCreateViewHolder(ViewGroup parent, int viewType)60         public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
61             TextView textView = new TextView(parent.getContext());
62             textView.setText("A LOT OF TEXT VIEW");
63             textView.setGravity(Gravity.CENTER_VERTICAL);
64             return new CustomViewHolder(textView);
65         }
66 
67         @Override
onBindViewHolder(CustomViewHolder holder, int position)68         public void onBindViewHolder(CustomViewHolder holder, int position) {
69         }
70 
71         @Override
getItemCount()72         public int getItemCount() {
73             return 100;
74         }
75 
76         static class CustomViewHolder extends RecyclerView.ViewHolder {
77 
CustomViewHolder(View view)78             CustomViewHolder(View view) {
79                 super(view);
80             }
81         }
82     }
83 }
84