[go: nahoru, domu]

blob: 6d7d8b4a5681d95f4e8b458e7242eb391aaa1129 [file] [log] [blame]
Nate Fischer29bbb1e2018-10-01 19:23:43 -07001/*
2 * Copyright 2018 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
17package com.example.androidx.webkit;
18
19import android.app.Activity;
Nate Fischerc4988b52019-04-15 22:52:47 -070020import android.content.Context;
21import android.content.Intent;
Nate Fischer29bbb1e2018-10-01 19:23:43 -070022import android.os.Bundle;
Nate Fischerc4988b52019-04-15 22:52:47 -070023import android.webkit.ValueCallback;
Nate Fischer29bbb1e2018-10-01 19:23:43 -070024
Nate Fischerc4988b52019-04-15 22:52:47 -070025import androidx.annotation.NonNull;
Nate Fischer29bbb1e2018-10-01 19:23:43 -070026import androidx.annotation.Nullable;
27import androidx.appcompat.app.AppCompatActivity;
Nate Fischerc4988b52019-04-15 22:52:47 -070028import androidx.webkit.WebViewCompat;
29import androidx.webkit.WebViewFeature;
Nate Fischer29bbb1e2018-10-01 19:23:43 -070030
31/**
32 * An {@link Activity} to exercise Safe Browsing functionality.
33 */
34public class SafeBrowsingActivity extends AppCompatActivity {
35
36 @Override
37 protected void onCreate(@Nullable Bundle savedInstanceState) {
38 super.onCreate(savedInstanceState);
39
Nate Fischerc4988b52019-04-15 22:52:47 -070040 if (WebViewFeature.isFeatureSupported(WebViewFeature.START_SAFE_BROWSING)) {
41 WebViewCompat.startSafeBrowsing(this.getApplicationContext(),
42 new ValueCallback<Boolean>() {
43 @Override
44 public void onReceiveValue(@NonNull Boolean value) {
45 if (value) {
46 setupLayout();
47 } else {
48 WebkitHelpers.showMessageInActivity(SafeBrowsingActivity.this,
49 R.string.cannot_start_safe_browsing);
50 }
51 }
52 });
53 } else {
54 WebkitHelpers.showMessageInActivity(SafeBrowsingActivity.this,
55 R.string.webkit_api_not_available);
56 }
57 }
58
59 private void setupLayout() {
Nate Fischer29bbb1e2018-10-01 19:23:43 -070060 setContentView(R.layout.activity_safe_browsing);
61 setTitle(R.string.safebrowsing_activity_title);
62 WebkitHelpers.appendWebViewVersionToTitle(this);
Nate Fischerc4988b52019-04-15 22:52:47 -070063
64 final Context activityContext = this;
65 MenuListView listView = findViewById(R.id.safe_browsing_list);
66 MenuListView.MenuItem[] menuItems = new MenuListView.MenuItem[] {
67 new MenuListView.MenuItem(
68 getResources().getString(R.string.small_interstitial_activity_title),
69 new Intent(activityContext, SmallInterstitialActivity.class)),
Nate Fischer65108de2019-04-19 18:56:52 -070070 new MenuListView.MenuItem(
71 getResources().getString(R.string.medium_wide_interstitial_activity_title),
72 new Intent(activityContext, MediumInterstitialActivity.class)
73 .putExtra(MediumInterstitialActivity.LAYOUT_HORIZONTAL, false)),
74 new MenuListView.MenuItem(
75 getResources().getString(R.string.medium_tall_interstitial_activity_title),
76 new Intent(activityContext, MediumInterstitialActivity.class)
77 .putExtra(MediumInterstitialActivity.LAYOUT_HORIZONTAL, true)),
Nate Fischerc4988b52019-04-15 22:52:47 -070078 };
79 listView.setItems(menuItems);
Nate Fischer29bbb1e2018-10-01 19:23:43 -070080 }
81}