1 /*
2  * Copyright 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.example.androidx.webkit;
18 
19 import android.app.Activity;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.os.Bundle;
23 
24 import androidx.appcompat.app.AppCompatActivity;
25 
26 import org.jspecify.annotations.Nullable;
27 
28 /**
29  * An {@link Activity} to exercise Restricted Content blocking functionality.
30  */
31 public class RestrictedContentActivity extends AppCompatActivity {
32     @Override
onCreate(@ullable Bundle savedInstanceState)33     protected void onCreate(@Nullable Bundle savedInstanceState) {
34         super.onCreate(savedInstanceState);
35         setupLayout();
36     }
37 
setupLayout()38     private void setupLayout() {
39         setContentView(R.layout.activity_restricted_content);
40         setTitle(R.string.restricted_content_activity_title);
41         WebkitHelpers.appendWebViewVersionToTitle(this);
42 
43         final Context activityContext = this;
44         MenuListView listView = findViewById(R.id.restricted_content_list);
45         MenuListView.MenuItem[] menuItems = new MenuListView.MenuItem[] {
46                 new MenuListView.MenuItem(
47                         getResources().getString(R.string.tiny_interstitial_activity_title),
48                         new Intent(activityContext, TinyInterstitialActivity.class)),
49                 new MenuListView.MenuItem(
50                         getResources().getString(R.string.small_interstitial_activity_title),
51                         new Intent(activityContext, SmallInterstitialActivity.class)
52                                 .putExtra(SmallInterstitialActivity.CONTENT_TYPE,
53                                         ContentType.RESTRICTED_CONTENT)),
54                 new MenuListView.MenuItem(
55                         getResources().getString(R.string.full_page_interstitial_activity_title),
56                         new Intent(activityContext, FullPageInterstitialActivity.class)
57                                 .putExtra(FullPageInterstitialActivity.CONTENT_TYPE,
58                                         ContentType.RESTRICTED_CONTENT)),
59         };
60         listView.setItems(menuItems);
61     }
62 }
63