1 /* 2 * Copyright (C) 2021 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 com.android.cts.verifier.notifications; 18 19 import android.os.Build; 20 import android.os.Bundle; 21 import android.view.View; 22 import android.widget.Toast; 23 24 import com.android.cts.verifier.PassFailButtons; 25 import com.android.cts.verifier.R; 26 27 /** 28 * Tests visual requirements for toasts. 29 * - max 2 lines 30 * - show app icon 31 */ 32 public class ToastVerifierActivity extends PassFailButtons.Activity { 33 34 @Override onCreate(Bundle savedState)35 protected void onCreate(Bundle savedState) { 36 super.onCreate(savedState); 37 setContentView(getLayoutInflater().inflate(R.layout.toast_main, null)); 38 setPassFailButtonClickListeners(); 39 40 // Sets the text in the dialog 41 setInfoResources(R.string.toast_title, 42 R.string.toast_info, -1); 43 44 if (getApplicationContext().getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.S) { 45 // don't run the test, auto-pass 46 findViewById(R.id.toast_description_s).setVisibility(View.GONE); 47 findViewById(R.id.toast_post_button).setVisibility(View.GONE); 48 getPassButton().callOnClick(); 49 } else { 50 // only enable pass after tester has pressed button to post a toast 51 getPassButton().setEnabled(false); 52 findViewById(R.id.toast_description_pre_s).setVisibility(View.GONE); 53 } 54 55 // Post toast 56 findViewById(R.id.toast_post_button).setOnClickListener(v -> { 57 postToast(); 58 getPassButton().setEnabled(true); 59 }); 60 } 61 postToast()62 private void postToast() { 63 Toast.makeText(getApplicationContext(), R.string.toast_long_text, Toast.LENGTH_LONG) 64 .show(); 65 } 66 } 67