/* * Copyright 2024 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.sharetest import android.app.Activity import android.app.PendingIntent import android.content.BroadcastReceiver import android.content.ClipData import android.content.Context import android.content.Intent import android.content.IntentFilter import android.graphics.Color import android.graphics.Typeface import android.os.Bundle import android.text.Spannable import android.text.SpannableStringBuilder import android.text.style.BackgroundColorSpan import android.text.style.BulletSpan import android.text.style.ForegroundColorSpan import android.text.style.StyleSpan import android.text.style.UnderlineSpan import android.view.View import android.view.ViewGroup.MarginLayoutParams import android.widget.ArrayAdapter import android.widget.Button import android.widget.CheckBox import android.widget.EditText import android.widget.RadioButton import android.widget.RadioGroup import android.widget.Spinner import android.widget.Toast import androidx.annotation.RequiresApi import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat import androidx.core.view.updateLayoutParams import com.android.sharetest.ImageContentProvider.Companion.IMAGE_COUNT import com.android.sharetest.ImageContentProvider.Companion.makeItemUri import kotlin.random.Random private const val TYPE_IMAGE = "Image" private const val TYPE_VIDEO = "Video" private const val TYPE_PDF = "PDF Doc" private const val TYPE_IMG_VIDEO = "Image / Video Mix" private const val TYPE_IMG_PDF = "Image / PDF Mix" private const val TYPE_VIDEO_PDF = "Video / PDF Mix" private const val TYPE_ALL = "All Type Mix" private const val ADDITIONAL_ITEM_COUNT = 1_000 @RequiresApi(34) class ShareTestActivity : Activity() { private lateinit var customActionReceiver: BroadcastReceiver private lateinit var refinementReceiver: BroadcastReceiver private lateinit var mediaSelection: RadioGroup private lateinit var textSelection: RadioGroup private lateinit var mediaTypeSelection: Spinner private lateinit var mediaTypeHeader: View private lateinit var richText: CheckBox private lateinit var albumCheck: CheckBox private lateinit var metadata: EditText private lateinit var shareouselCheck: CheckBox private lateinit var altIntentCheck: CheckBox private lateinit var callerTargetCheck: CheckBox private lateinit var selectionLatencyGroup: RadioGroup private lateinit var imageSizeMetadataCheck: CheckBox private val customActionFactory = CustomActionFactory(this) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val container = requireViewById(R.id.container) ViewCompat.setOnApplyWindowInsetsListener(container) { v, windowInsets -> val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) v.updateLayoutParams { leftMargin = insets.left topMargin = insets.top rightMargin = insets.right bottomMargin = insets.bottom } WindowInsetsCompat.CONSUMED } customActionReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent) { Toast.makeText( this@ShareTestActivity, "Custom action invoked, isModified: ${!intent.isInitial}", Toast.LENGTH_LONG ) .show() } } refinementReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent) { // Need to show refinement in another activity because this one is beneath the // sharesheet. val activityIntent = Intent(this@ShareTestActivity, RefinementActivity::class.java) activityIntent.putExtras(intent) startActivity(activityIntent) } } registerReceiver( customActionReceiver, IntentFilter(CustomActionFactory.BROADCAST_ACTION), Context.RECEIVER_EXPORTED ) registerReceiver( refinementReceiver, IntentFilter(REFINEMENT_ACTION), Context.RECEIVER_EXPORTED ) richText = requireViewById(R.id.use_rich_text) albumCheck = requireViewById(R.id.album_text) shareouselCheck = requireViewById(R.id.shareousel) altIntentCheck = requireViewById(R.id.alt_intent) callerTargetCheck = requireViewById(R.id.caller_direct_target) mediaTypeSelection = requireViewById(R.id.media_type_selection) mediaTypeHeader = requireViewById(R.id.media_type_header) selectionLatencyGroup = requireViewById(R.id.selection_latency) imageSizeMetadataCheck = requireViewById(R.id.image_size_metadata) mediaSelection = requireViewById(R.id.media_selection).apply { setOnCheckedChangeListener { _, id -> updateMediaTypesList(id) } check(R.id.no_media) } metadata = requireViewById(R.id.metadata) textSelection = requireViewById(R.id.text_selection).apply { check(R.id.short_text) } requireViewById(R.id.action_selection).check(R.id.no_actions) requireViewById