1 /*
2  * Copyright (C) 2022 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.test.uiautomator.testapp;
18 
19 import android.app.Activity;
20 import android.os.Bundle;
21 import android.view.View;
22 import android.view.View.OnLongClickListener;
23 import android.widget.Button;
24 
25 import org.jspecify.annotations.NonNull;
26 import org.jspecify.annotations.Nullable;
27 
28 public class ClickTestActivity extends Activity {
29 
30     @Override
onCreate(@ullable Bundle savedInstanceState)31     public void onCreate(@Nullable Bundle savedInstanceState) {
32         super.onCreate(savedInstanceState);
33 
34         setContentView(R.layout.click_test_activity);
35 
36         // Set up the long-clickable buttons.
37         Button button4 = findViewById(R.id.button4);
38         Button button5 = findViewById(R.id.button5);
39         Button button6 = findViewById(R.id.button6);
40         Button button7 = findViewById(R.id.button7);
41 
42         button4.setOnLongClickListener(new OnButtonLongClick());
43         button5.setOnLongClickListener(new OnButtonLongClick());
44         button6.setOnLongClickListener(new OnButtonLongClick());
45         button7.setOnLongClickListener(new OnButtonLongClick());
46     }
47 
onButtonClick(@onNull View v)48     public void onButtonClick(@NonNull View v) {
49         ((Button) v).append("_clicked");
50     }
51 
52     static class OnButtonLongClick implements OnLongClickListener {
53         @Override
onLongClick(View v)54         public boolean onLongClick(View v) {
55             ((Button) v).append("_long_clicked");
56             return true;
57         }
58     }
59 }
60