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.android.adservices.ui.settings.activities; 17 18 import static com.android.adservices.ui.UxUtil.isUxStatesReady; 19 20 import android.os.Build; 21 import android.os.Bundle; 22 23 import androidx.annotation.RequiresApi; 24 import androidx.lifecycle.ViewModelProvider; 25 26 import com.android.adservices.api.R; 27 import com.android.adservices.ui.settings.activitydelegates.MeasurementActivityActionDelegate; 28 import com.android.adservices.ui.settings.delegates.MeasurementActionDelegate; 29 import com.android.adservices.ui.settings.fragments.AdServicesSettingsMeasurementFragment; 30 import com.android.adservices.ui.settings.viewmodels.MeasurementViewModel; 31 32 /** Android application activity provides functionality to control measurement data and consent. */ 33 // TODO(b/269798827): Enable for R. 34 @RequiresApi(Build.VERSION_CODES.S) 35 public class MeasurementActivity extends AdServicesBaseActivity { 36 private MeasurementActionDelegate mActionDelegate; 37 38 /** @return the action delegate for the activity. */ getActionDelegate()39 public MeasurementActionDelegate getActionDelegate() { 40 return mActionDelegate; 41 } 42 43 @Override onCreate(Bundle savedInstanceState)44 protected void onCreate(Bundle savedInstanceState) { 45 super.onCreate(savedInstanceState); 46 if (!isUxStatesReady(this)) { 47 initFragment(); 48 } 49 } 50 51 @Override initGA()52 public void initGA() { 53 initActivity(); 54 } 55 56 @Override initU18()57 public void initU18() { 58 initActivity(); 59 } 60 61 @Override initRvc()62 public void initRvc() { 63 setContentView(R.layout.measurement_activity_v30); 64 new MeasurementActivityActionDelegate( 65 this, new ViewModelProvider(this).get(MeasurementViewModel.class)); 66 } 67 initFragment()68 private void initFragment() { 69 setContentView(R.layout.adservices_settings_main_activity); 70 getSupportFragmentManager() 71 .beginTransaction() 72 .replace( 73 R.id.fragment_container_view, 74 AdServicesSettingsMeasurementFragment.class, 75 null) 76 .setReorderingAllowed(true) 77 .commit(); 78 mActionDelegate = 79 new MeasurementActionDelegate( 80 this, new ViewModelProvider(this).get(MeasurementViewModel.class)); 81 } 82 initActivity()83 private void initActivity() { 84 setContentView(R.layout.measurement_activity); 85 // no need to store since not using 86 new MeasurementActivityActionDelegate( 87 this, new ViewModelProvider(this).get(MeasurementViewModel.class)); 88 } 89 } 90