summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Sandler <dsandler@android.com>2012-08-16 10:57:52 -0400
committerDaniel Sandler <dsandler@android.com>2012-08-16 22:57:24 -0400
commit5c9c1573621e52ce54b172d3a8bc47ae481c06d6 (patch)
treee83114fb989e8284ba7b1f974e188f85894d53eb
parent33363f476c511240240b0249ed0151752980f930 (diff)
downloadandroid_packages_screensavers_WebView-5c9c1573621e52ce54b172d3a8bc47ae481c06d6.tar.gz
android_packages_screensavers_WebView-5c9c1573621e52ce54b172d3a8bc47ae481c06d6.tar.bz2
android_packages_screensavers_WebView-5c9c1573621e52ce54b172d3a8bc47ae481c06d6.zip
Sample screensaver: load a webpage full-screen.
Configuration is currently accomplished by ACTION_SENDing a URL. At some point we'll have a configuration UI. :/ Change-Id: I0d410e6fd99e44c0aab005bd5c5fc177fe1c7bdb
-rw-r--r--Android.mk17
-rw-r--r--AndroidManifest.xml43
-rw-r--r--assets/default.html23
-rw-r--r--res/layout/main.xml8
-rw-r--r--src/com/android/dreams/web/Screensaver.java89
-rw-r--r--src/com/android/dreams/web/SetURL.java57
-rw-r--r--src/com/android/dreams/web/SetURLInteractive.java57
7 files changed, 294 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..5c86b55
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,17 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+# Only compile source java files in this apk.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := WebViewDream
+
+# need tasty bits
+# LOCAL_CERTIFICATE := platform
+
+include $(BUILD_PACKAGE)
+
+# Use the following include to make our test apk.
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
new file mode 100644
index 0000000..fb23252
--- /dev/null
+++ b/AndroidManifest.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.dreams.web"
+ >
+ <!-- uses-permission android:name="android.permission.WRITE_SETTINGS" -->
+ <uses-permission android:name="android.permission.INTERNET" />
+ <application android:label="WebViewDream">
+ <service
+ android:name="Screensaver"
+ android:exported="true"
+ android:label="WebView">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.DREAM" />
+ </intent-filter>
+ </service>
+
+ <activity
+ android:name="SetURL"
+ android:label="Dream URL"
+ android:theme="@android:style/Theme.Translucent.NoTitleBar">
+
+ <intent-filter>
+ <action android:name="android.intent.action.SEND" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <data android:mimeType="text/plain" />
+ </intent-filter>
+ </activity>
+
+ <activity
+ android:name="SetURLInteractive"
+ android:label="Dream URL (Interactive)"
+ android:theme="@android:style/Theme.Translucent.NoTitleBar">
+
+ <intent-filter>
+ <action android:name="android.intent.action.SEND" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <data android:mimeType="text/plain" />
+ </intent-filter>
+ </activity>
+ </application>
+</manifest>
diff --git a/assets/default.html b/assets/default.html
new file mode 100644
index 0000000..c0abd75
--- /dev/null
+++ b/assets/default.html
@@ -0,0 +1,23 @@
+<html>
+ <head>
+ <style>
+ body {
+ background-color: black;
+ color: gray;
+ font-size: 16pt;
+ font-family: "Roboto-Light", Roboto, sans-serif;
+ text-align: center;
+ }
+ #text {
+ margin-left: auto;
+ margin-right: auto;
+ margin-top: 96pt;
+ }
+ </style>
+ </head>
+ <body>
+ <div id="text">
+ Use the &ldquo;Share&rdquo; menu option in your browser to choose a URL for this dream.
+ </div>
+ </body>
+</html> \ No newline at end of file
diff --git a/res/layout/main.xml b/res/layout/main.xml
new file mode 100644
index 0000000..5f2b65a
--- /dev/null
+++ b/res/layout/main.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<WebView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/webview"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ >
+</WebView>
diff --git a/src/com/android/dreams/web/Screensaver.java b/src/com/android/dreams/web/Screensaver.java
new file mode 100644
index 0000000..39a4146
--- /dev/null
+++ b/src/com/android/dreams/web/Screensaver.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.dreams.web;
+
+import android.animation.Animator;
+import android.animation.AnimatorSet;
+import android.animation.ObjectAnimator;
+import android.animation.TimeInterpolator;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.res.Configuration;
+import android.graphics.drawable.Drawable;
+import android.graphics.PorterDuff;
+import android.net.Uri;
+import android.os.BatteryManager;
+import android.os.Handler;
+import android.provider.Settings;
+import android.service.dreams.Dream;
+import android.util.Log;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.WindowManager;
+import android.view.animation.AccelerateInterpolator;
+import android.view.animation.DecelerateInterpolator;
+import android.webkit.WebSettings;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
+import android.widget.TextView;
+
+public class Screensaver extends Dream {
+ @Override
+ public void onStart() {
+ super.onStart();
+ }
+
+ private class LinkLauncher extends WebViewClient {
+ @Override
+ public boolean shouldOverrideUrlLoading(WebView view, String url) {
+ Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(intent);
+ finish();
+ return true;
+ }
+ }
+
+ @Override
+ public void onAttachedToWindow() {
+ super.onAttachedToWindow();
+
+ setContentView(R.layout.main);
+
+ lightsOut(); // lights out, fullscreen
+
+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
+ final String url = prefs.getString("url", "file:///android_asset/default.html");
+
+ final boolean interactive = prefs.getBoolean("interactive", false);
+ Log.v("WebViewDream", String.format("loading %s in %s mode",
+ url, interactive ? "interactive" : "noninteractive"));
+ setInteractive(interactive);
+
+ WebView webview = (WebView) findViewById(R.id.webview);
+ webview.setWebViewClient(new LinkLauncher());
+
+ WebSettings webSettings = webview.getSettings();
+ webSettings.setJavaScriptEnabled(true);
+
+ webview.loadUrl(url);
+ }
+}
diff --git a/src/com/android/dreams/web/SetURL.java b/src/com/android/dreams/web/SetURL.java
new file mode 100644
index 0000000..564518a
--- /dev/null
+++ b/src/com/android/dreams/web/SetURL.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.dreams.web;
+
+import android.service.dreams.Dream;
+import android.util.Log;
+import android.content.SharedPreferences.Editor;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
+import android.widget.Toast;
+import android.os.Bundle;
+import android.app.Activity;
+import android.content.Intent;
+import android.widget.Toast;
+
+public class SetURL extends Activity {
+ @Override
+ public void onCreate(Bundle stuff) {
+ super.onCreate(stuff);
+
+ final Intent intent = getIntent();
+
+ final String action = intent.getAction();
+ String url = intent.getStringExtra(Intent.EXTRA_TEXT);
+
+ if (url == null) {
+ finish();
+ } else if (Intent.ACTION_SEND.equals(action)) {
+ set(url);
+ finish();
+ }
+ }
+
+ protected void set(String url) {
+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
+ final Editor editor = prefs.edit();
+ editor.putString("url", url);
+ editor.putBoolean("interactive", false);
+ editor.commit();
+
+ Toast.makeText(this, "WebView dream URL set to: " + url, Toast.LENGTH_SHORT).show();
+ }
+}
diff --git a/src/com/android/dreams/web/SetURLInteractive.java b/src/com/android/dreams/web/SetURLInteractive.java
new file mode 100644
index 0000000..dfe15a4
--- /dev/null
+++ b/src/com/android/dreams/web/SetURLInteractive.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.dreams.web;
+
+import android.service.dreams.Dream;
+import android.util.Log;
+import android.content.SharedPreferences.Editor;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
+import android.widget.Toast;
+import android.os.Bundle;
+import android.app.Activity;
+import android.content.Intent;
+import android.widget.Toast;
+
+public class SetURLInteractive extends Activity {
+ @Override
+ public void onCreate(Bundle stuff) {
+ super.onCreate(stuff);
+
+ final Intent intent = getIntent();
+
+ final String action = intent.getAction();
+ String url = intent.getStringExtra(Intent.EXTRA_TEXT);
+
+ if (url == null) {
+ finish();
+ } else if (Intent.ACTION_SEND.equals(action)) {
+ set(url);
+ finish();
+ }
+ }
+
+ protected void set(String url) {
+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
+ final Editor editor = prefs.edit();
+ editor.putString("url", url);
+ editor.putBoolean("interactive", true);
+ editor.commit();
+
+ Toast.makeText(this, "WebView dream URL set to: " + url, Toast.LENGTH_SHORT).show();
+ }
+}