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 package com.example.adservices.samples.ui.consenttestapp; 17 18 import static com.google.common.util.concurrent.MoreExecutors.directExecutor; 19 20 import android.adservices.clients.customaudience.AdvertisingCustomAudienceClient; 21 import android.adservices.common.CommonFixture; 22 import android.adservices.customaudience.CustomAudienceFixture; 23 import android.os.Bundle; 24 25 import androidx.appcompat.app.AppCompatActivity; 26 27 import com.google.common.util.concurrent.FutureCallback; 28 import com.google.common.util.concurrent.Futures; 29 30 import java.util.concurrent.Executor; 31 import java.util.concurrent.Executors; 32 33 /** 34 * Android application activity for testing Topics API by providing a button in UI that initiate 35 * user's interaction with Topics Manager in the background. Response from Topics API will be shown 36 * in the app as text as well as toast message. In case anything goes wrong in this process, error 37 * message will also be shown in toast to suggest the Exception encountered. 38 */ 39 public class MainActivity extends AppCompatActivity { 40 41 private static final Executor CALLBACK_EXECUTOR = Executors.newCachedThreadPool(); 42 43 @Override onCreate(Bundle savedInstanceState)44 protected void onCreate(Bundle savedInstanceState) { 45 super.onCreate(savedInstanceState); 46 setContentView(R.layout.activity_main); 47 48 final AdvertisingCustomAudienceClient advertisingCustomAudienceClient = 49 new AdvertisingCustomAudienceClient.Builder() 50 .setContext(this) 51 .setExecutor(CALLBACK_EXECUTOR) 52 .build(); 53 Futures.addCallback( 54 advertisingCustomAudienceClient.joinCustomAudience( 55 CustomAudienceFixture.getValidBuilderForBuyer(CommonFixture.VALID_BUYER_1) 56 .build()), 57 new FutureCallback<Void>() { 58 @Override 59 public void onSuccess(Void result) {} 60 61 @Override 62 public void onFailure(Throwable t) {} 63 }, 64 directExecutor()); 65 } 66 } 67