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