1 /* 2 * Copyright (C) 2012 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.android.dreams.web; 18 19 import android.animation.Animator; 20 import android.animation.AnimatorSet; 21 import android.animation.ObjectAnimator; 22 import android.animation.TimeInterpolator; 23 import android.content.BroadcastReceiver; 24 import android.content.Context; 25 import android.content.Intent; 26 import android.content.IntentFilter; 27 import android.content.res.Configuration; 28 import android.graphics.drawable.Drawable; 29 import android.graphics.PorterDuff; 30 import android.net.Uri; 31 import android.os.BatteryManager; 32 import android.os.Handler; 33 import android.provider.Settings; 34 import android.service.dreams.DreamService; 35 import android.util.Log; 36 import android.view.MotionEvent; 37 import android.view.View; 38 import android.view.WindowManager; 39 import android.view.animation.AccelerateInterpolator; 40 import android.view.animation.DecelerateInterpolator; 41 import android.webkit.WebSettings; 42 import android.webkit.WebView; 43 import android.webkit.WebViewClient; 44 import android.content.SharedPreferences; 45 import android.preference.PreferenceManager; 46 import android.widget.TextView; 47 48 public class Screensaver extends DreamService { 49 private class LinkLauncher extends WebViewClient { 50 @Override 51 public boolean shouldOverrideUrlLoading(WebView view, String url) { 52 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 53 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 54 startActivity(intent); 55 finish(); 56 return true; 57 } 58 } 59 60 @Override 61 public void onAttachedToWindow() { 62 super.onAttachedToWindow(); 63 64 setContentView(R.layout.main); 65 66 setFullscreen(true); 67 68 final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); 69 final String url = prefs.getString("url", "file:///android_asset/default.html"); 70 71 final boolean interactive = prefs.getBoolean("interactive", false); 72 Log.v("WebViewDream", String.format("loading %s in %s mode", 73 url, interactive ? "interactive" : "noninteractive")); 74 setInteractive(interactive); 75 76 WebView webview = (WebView) findViewById(R.id.webview); 77 webview.setWebViewClient(new LinkLauncher()); 78 79 WebSettings webSettings = webview.getSettings(); 80 webSettings.setJavaScriptEnabled(true); 81 82 webview.loadUrl(url); 83 } 84 } 85