1 /* 2 * Copyright (C) 2017 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.android.autofill.app; 17 18 import android.content.Context; 19 import android.content.Intent; 20 import android.os.Bundle; 21 import android.support.v7.app.AppCompatActivity; 22 import android.util.Log; 23 import android.webkit.WebSettings; 24 import android.webkit.WebView; 25 import android.webkit.WebViewClient; 26 27 import static com.example.android.autofill.app.CommonUtil.DEBUG; 28 import static com.example.android.autofill.app.CommonUtil.TAG; 29 30 public class WebViewSignInActivity extends AppCompatActivity { 31 32 public static Intent getStartActivityIntent(Context context) { 33 Intent intent = new Intent(context, WebViewSignInActivity.class); 34 return intent; 35 } 36 37 @Override 38 protected void onCreate(Bundle savedInstanceState) { 39 super.onCreate(savedInstanceState); 40 41 setContentView(R.layout.login_webview_activity); 42 43 WebView webView = findViewById(R.id.webview); 44 WebSettings webSettings = webView.getSettings(); 45 webView.setWebViewClient(new WebViewClient()); 46 webSettings.setJavaScriptEnabled(true); 47 48 String url = getIntent().getStringExtra("url"); 49 if (url == null) { 50 url = "file:///android_res/raw/sample_form.html"; 51 } 52 if (DEBUG) Log.d(TAG, "Clearing WebView data"); 53 webView.clearHistory(); 54 webView.clearFormData(); 55 webView.clearCache(true); 56 Log.i(TAG, "Loading URL " + url); 57 webView.loadUrl(url); 58 } 59 }