blob: bd65d02a39fefa60a2854a1848a542a2370450c7 [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;
Daniel Sandler6e0a80f2012-10-05 00:17:58 -040034import android.service.dreams.DreamService;
Daniel Sandler5c9c1572012-08-16 10:57:52 -040035import 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
Daniel Sandler6e0a80f2012-10-05 00:17:58 -040048public class Screensaver extends DreamService {
Daniel Sandler5c9c1572012-08-16 10:57:52 -040049 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
John Spurlock39f9b3d2012-09-21 17:03:00 -040066 setFullscreen(true);
Daniel Sandler5c9c1572012-08-16 10:57:52 -040067
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}