1 /* 2 * Copyright (C) 2024 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.sharesheet; 18 19 import android.content.Intent; 20 import android.os.Bundle; 21 import android.service.chooser.Flags; 22 import android.view.View; 23 import android.widget.Button; 24 import android.widget.TextView; 25 import android.widget.Toast; 26 27 import com.android.cts.verifier.PassFailButtons; 28 import com.android.cts.verifier.R; 29 30 /** 31 * Test the album subtype hint (must be honored for sharesheets that show a headline like 32 * "Sharing text"). 33 * 34 * The flow is broken up into three steps: 35 * 1. Ask the user to invoke the sharesheet and see if there is a headline text. 36 * 2. After the sharesheet has been invoked, confirm whether there was a headline. 37 * 3. If there was a headline, ask the user to invoke again, this time using the API to indicate 38 * that an album is being shared, and let the user pass or fail the test based upon whether the 39 * album designation is honored. 40 */ 41 public class SharesheetAlbumActivity extends PassFailButtons.Activity { 42 // True iff the operator has confirmed that the sharesheet displayed a headline (meaning we are 43 // in step 3 described above). 44 private boolean mHeadlineConfirmed = false; 45 46 @Override onCreate(Bundle savedInstanceState)47 protected void onCreate(Bundle savedInstanceState) { 48 super.onCreate(savedInstanceState); 49 50 if (!Flags.chooserAlbumText()) { 51 // If the API isn't enabled, immediately let the test pass. 52 Toast.makeText(this, R.string.sharesheet_skipping_for_flag, Toast.LENGTH_LONG).show(); 53 setTestResultAndFinish(true); 54 return; 55 } 56 57 setContentView(R.layout.sharesheet_album_activity); 58 setPassFailButtonClickListeners(); 59 setInfoResources(R.string.sharesheet_album_test, R.string.sharesheet_album_test_info, -1); 60 61 Button shareBtn = (Button) findViewById(R.id.share); 62 TextView instructionText = (TextView) findViewById(R.id.instructions); 63 64 // Can't pass until steps are completed. 65 getPassButton().setVisibility(View.GONE); 66 67 shareBtn.setOnClickListener(new View.OnClickListener() { 68 @Override 69 public void onClick(View v) { 70 if (!mHeadlineConfirmed) { 71 // Show the UI for step two and open the sharesheet. 72 instructionText.setText(R.string.sharesheet_album_test_step_2); 73 findViewById(R.id.step_two_buttons).setVisibility(View.VISIBLE); 74 shareText(false); 75 } else { 76 // Show the sharesheet with the album hint, let the user pass the test after 77 // it's shown. 78 getPassButton().setVisibility(View.VISIBLE); 79 shareText(true); 80 } 81 } 82 }); 83 84 findViewById(R.id.title_yes).setOnClickListener(v -> { 85 // There is a title, so move to the next step to see if the album subtype is honored. 86 instructionText.setText(R.string.sharesheet_album_test_step_3); 87 findViewById(R.id.step_two_buttons).setVisibility(View.GONE); 88 mHeadlineConfirmed = true; 89 }); 90 91 // If there's no title, then the test is passed. 92 findViewById(R.id.title_no).setOnClickListener(v -> { 93 Toast.makeText(this, R.string.sharesheet_no_title_message, Toast.LENGTH_LONG).show(); 94 setTestResultAndFinish(true); 95 }); 96 } 97 shareText(boolean album)98 private void shareText(boolean album) { 99 Intent sendIntent = new Intent(); 100 sendIntent.setAction(Intent.ACTION_SEND); 101 sendIntent.putExtra(Intent.EXTRA_TEXT, "Testing"); 102 sendIntent.setType("text/plain"); 103 104 Intent shareIntent = Intent.createChooser(sendIntent, null); 105 if (album) { 106 shareIntent.putExtra(Intent.EXTRA_CHOOSER_CONTENT_TYPE_HINT, 107 Intent.CHOOSER_CONTENT_TYPE_ALBUM); 108 } 109 startActivity(shareIntent); 110 } 111 } 112