summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Guy <romainguy@android.com>2009-11-08 13:51:50 -0800
committerRomain Guy <romainguy@android.com>2009-11-08 15:30:12 -0800
commit2f26cced2d4257c4fb106939447d901ae971b4d1 (patch)
treeb78f744b31f42fc53274593d2a5883a2258d50b8
parent7e2a10d904ce52bde6e887b9c257709729f39613 (diff)
downloadandroid_packages_wallpapers_LivePicker-2f26cced2d4257c4fb106939447d901ae971b4d1.zip
android_packages_wallpapers_LivePicker-2f26cced2d4257c4fb106939447d901ae971b4d1.tar.gz
android_packages_wallpapers_LivePicker-2f26cced2d4257c4fb106939447d901ae971b4d1.tar.bz2
New, safer, live wallpaper picker.
-rw-r--r--AndroidManifest.xml15
-rw-r--r--res/layout/live_wallpaper_content.xml103
-rw-r--r--res/layout/live_wallpaper_entry.xml66
-rw-r--r--res/layout/live_wallpaper_list.xml38
-rw-r--r--res/layout/live_wallpaper_preview.xml45
-rw-r--r--res/layout/wallpaper_item.xml22
-rw-r--r--res/values/colors.xml3
-rw-r--r--res/values/dimensions.xml25
-rw-r--r--res/values/strings.xml8
-rw-r--r--src/com/android/wallpaper/livepicker/LiveWallpaperListActivity.java214
-rw-r--r--src/com/android/wallpaper/livepicker/LiveWallpaperPickActivity.java411
-rw-r--r--src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java224
12 files changed, 631 insertions, 543 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 9fd1077..c5d8528 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -30,10 +30,11 @@
android:label="@string/application_name"
android:icon="@drawable/ic_launcher_appwidget">
- <activity android:name="LiveWallpaperPickActivity"
- android:icon="@drawable/ic_launcher_appwidget"
- android:label="@string/live_wallpaper_picker_title"
- android:theme="@android:style/Theme.Wallpaper.NoTitleBar">
+ <activity android:name="LiveWallpaperListActivity"
+ android:icon="@drawable/ic_launcher_appwidget"
+ android:label="@string/live_wallpaper_picker_title"
+ android:theme="@android:style/Theme.NoTitleBar"
+ android:screenOrientation="nosensor">
<intent-filter>
<action android:name="android.service.wallpaper.LIVE_WALLPAPER_CHOOSER" />
<action android:name="android.intent.action.SET_WALLPAPER" />
@@ -41,6 +42,12 @@
</intent-filter>
</activity>
+ <activity android:name="LiveWallpaperPreview"
+ android:icon="@drawable/ic_launcher_appwidget"
+ android:label="@string/live_wallpaper_preview_title"
+ android:theme="@android:style/Theme.Wallpaper.NoTitleBar"
+ android:screenOrientation="nosensor" />
+
</application>
</manifest>
diff --git a/res/layout/live_wallpaper_content.xml b/res/layout/live_wallpaper_content.xml
deleted file mode 100644
index 3809a35..0000000
--- a/res/layout/live_wallpaper_content.xml
+++ /dev/null
@@ -1,103 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2009 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.
--->
-
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
-
- <RelativeLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="8dip"
- android:layout_marginLeft="6dip"
- >
- <TextView android:id="@+id/title"
- style="@style/WallpaperTitle"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
- <TextView android:id="@+id/author"
- style="@style/WallpaperTitle"
- android:layout_below="@id/title"
- android:textSize="14dip"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="10dip"
- />
- <TextView android:id="@+id/synopsis"
- style="@style/WallpaperTitle"
- android:layout_below="@id/author"
- android:textSize="14dip"
- android:ems="15"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="10dip"
- />
- </RelativeLayout>
-
- <FrameLayout
- android:layout_width="fill_parent"
- android:layout_height="0px"
- android:layout_weight="1"
- >
- <!--
- <ListView
- android:id="@android:id/list"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- />
- -->
- <TextView
- android:id="@android:id/empty"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:gravity="center"
- android:text="@string/live_wallpaper_empty"
- android:visibility="gone"
- android:textAppearance="?android:attr/textAppearanceMedium"
- />
- </FrameLayout>
-
- <Gallery android:id="@+id/gallery"
- android:gravity="fill"
- android:layout_width="fill_parent"
- android:layout_height="120dip" />
-
- <LinearLayout
- android:orientation="horizontal"
- android:layout_gravity="center"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
-
- <Button android:id="@+id/set"
- android:layout_width="160dip"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="@string/wallpaper_instructions"
- android:layout_gravity="center" />
-
- <Button android:id="@+id/configure"
- android:layout_width="160dip"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:text="@string/configure_wallpaper"
- android:layout_gravity="center" />
-
- </LinearLayout>
-
-</LinearLayout>
diff --git a/res/layout/live_wallpaper_entry.xml b/res/layout/live_wallpaper_entry.xml
new file mode 100644
index 0000000..29be991
--- /dev/null
+++ b/res/layout/live_wallpaper_entry.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+
+ android:paddingLeft="4dip"
+ android:minHeight="?android:attr/listPreferredItemHeight">
+
+ <ImageView
+ android:id="@+id/thumbnail"
+
+ android:layout_width="@dimen/live_wallpaper_thumbnail_width"
+ android:layout_height="@dimen/live_wallpaper_thumbnail_width"
+
+ android:layout_gravity="center_vertical"
+
+ android:scaleType="fitCenter" />
+
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+
+ android:layout_marginLeft="8dip"
+ android:layout_gravity="center_vertical"
+
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/title_author"
+
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+
+ android:textAppearance="?android:attr/textAppearanceMedium"
+
+ android:singleLine="true"
+ android:ellipsize="marquee" />
+
+ <TextView
+ android:id="@+id/description"
+
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+
+ android:textAppearance="?android:attr/textAppearanceSmall"
+
+ android:maxLines="3" />
+
+ </LinearLayout>
+
+</LinearLayout>
diff --git a/res/layout/live_wallpaper_list.xml b/res/layout/live_wallpaper_list.xml
new file mode 100644
index 0000000..bab79ff
--- /dev/null
+++ b/res/layout/live_wallpaper_list.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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.
+-->
+
+<merge xmlns:android="http://schemas.android.com/apk/res/android" >
+
+ <ListView
+ android:id="@android:id/list"
+
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+
+ android:drawSelectorOnTop="false" />
+
+ <TextView
+ android:id="@android:id/empty"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+
+ android:gravity="center"
+ android:visibility="gone"
+
+ android:text="@string/live_wallpaper_empty"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+</merge> \ No newline at end of file
diff --git a/res/layout/live_wallpaper_preview.xml b/res/layout/live_wallpaper_preview.xml
new file mode 100644
index 0000000..d5da853
--- /dev/null
+++ b/res/layout/live_wallpaper_preview.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+
+ android:layout_gravity="center_horizontal|bottom"
+
+ android:paddingBottom="4dip">
+
+ <Button
+ android:layout_width="160dip"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+
+ android:text="@string/wallpaper_instructions"
+
+ android:onClick="setLiveWallpaper" />
+
+ <Button
+ android:id="@+id/configure"
+
+ android:layout_width="160dip"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+
+ android:text="@string/configure_wallpaper"
+
+ android:onClick="configureLiveWallpaper" />
+
+</LinearLayout>
diff --git a/res/layout/wallpaper_item.xml b/res/layout/wallpaper_item.xml
deleted file mode 100644
index 6727483..0000000
--- a/res/layout/wallpaper_item.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2008 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.
--->
-
-<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
- android:background="?android:attr/galleryItemBackground"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:scaleType="fitXY"
- android:focusable="true" />
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 90d633a..d49e104 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -18,6 +18,7 @@
-->
<resources>
- <color name="bubble_dark_background">#B2191919</color>
+ <color name="live_wallpaper_thumbnail_background">#CC666666</color>
+ <color name="live_wallpaper_thumbnail_text_color">#FFFFFFFF</color>
</resources>
diff --git a/res/values/dimensions.xml b/res/values/dimensions.xml
new file mode 100644
index 0000000..080a55a
--- /dev/null
+++ b/res/values/dimensions.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+* copyright (c) 2008 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.
+*/
+-->
+
+<resources>
+ <dimen name="live_wallpaper_thumbnail_text_size">14dip</dimen>
+ <dimen name="live_wallpaper_thumbnail_text_offset">12dip</dimen>
+ <dimen name="live_wallpaper_thumbnail_width">100dip</dimen>
+ <dimen name="live_wallpaper_thumbnail_height">79dip</dimen>
+</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 190bb19..3df82f1 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -24,7 +24,9 @@
<string name="application_name">Live Wallpaper Picker</string>
<!-- Title for the screen that lets the user choose a live wallpaper to use
for the system. -->
- <string name="live_wallpaper_picker_title">Live wallpaper</string>
+ <string name="live_wallpaper_picker_title">Live wallpaper</string>
+ <!-- Title for the screen that lets the user preview a live wallpaper. -->
+ <string name="live_wallpaper_preview_title">Live wallpaper preview</string>
<!-- List item for configuring the current wallpaper -->
<string name="configure_wallpaper">Settingsā€¦</string>
<!-- Button label on Wallpaper Gallery screen; user selects this button to set a specific wallpaper -->
@@ -33,5 +35,7 @@
<string name="live_wallpaper_empty">No live wallpapers.</string>
<!-- Button label, action, sets the currently selected wallpaper. -->
<string name="set_live_wallpaper">Set wallpaper</string>
-
+ <!-- Label, title and author of the live wallpaper -->
+ <string name="wallpaper_title_and_author"><xliff:g id="title" example="Galaxy">%1$s</xliff:g> by <xliff:g id="author" example="Google">%2$s</xliff:g></string>
+
</resources>
diff --git a/src/com/android/wallpaper/livepicker/LiveWallpaperListActivity.java b/src/com/android/wallpaper/livepicker/LiveWallpaperListActivity.java
new file mode 100644
index 0000000..44493ee
--- /dev/null
+++ b/src/com/android/wallpaper/livepicker/LiveWallpaperListActivity.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2009 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.wallpaper.livepicker;
+
+import android.app.ListActivity;
+import android.app.WallpaperInfo;
+import android.os.Bundle;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ComponentInfo;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.Paint;
+import android.graphics.Canvas;
+import android.graphics.Bitmap;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.LayoutInflater;
+import android.service.wallpaper.WallpaperService;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+import android.widget.ImageView;
+import android.widget.AdapterView;
+import android.text.Html;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.io.IOException;
+
+import org.xmlpull.v1.XmlPullParserException;
+
+public class LiveWallpaperListActivity extends ListActivity implements AdapterView.OnItemClickListener {
+ private static final String LOG_TAG = "LiveWallpapersPicker";
+
+ private static final int REQUEST_PREVIEW = 100;
+
+ private PackageManager mPackageManager;
+
+ private ArrayList<Drawable> mThumbnails;
+ private ArrayList<WallpaperInfo> mWallpaperInfos;
+ private ArrayList<Intent> mWallpaperIntents;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.live_wallpaper_list);
+
+ mPackageManager = getPackageManager();
+
+ findLiveWallpapers();
+
+ setListAdapter(new LiveWallpapersAdapter());
+ getListView().setOnItemClickListener(this);
+ }
+
+ private void findLiveWallpapers() {
+ List<ResolveInfo> list = mPackageManager.queryIntentServices(
+ new Intent(WallpaperService.SERVICE_INTERFACE),
+ PackageManager.GET_META_DATA);
+
+ int listSize = list.size();
+
+ mThumbnails = new ArrayList<Drawable>(listSize);
+ mWallpaperIntents = new ArrayList<Intent>(listSize);
+ mWallpaperInfos = new ArrayList<WallpaperInfo>(listSize);
+
+ Resources res = getResources();
+ Drawable galleryIcon = res.getDrawable(R.drawable.livewallpaper_placeholder);
+
+ Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
+ paint.setTextAlign(Paint.Align.CENTER);
+
+ Canvas canvas = new Canvas();
+
+ for (int i = 0; i < listSize; i++) {
+ ResolveInfo resolveInfo = list.get(i);
+ ComponentInfo ci = resolveInfo.serviceInfo;
+ WallpaperInfo info;
+ try {
+ info = new WallpaperInfo(this, resolveInfo);
+ } catch (XmlPullParserException e) {
+ Log.w(LOG_TAG, "Skipping wallpaper " + ci, e);
+ continue;
+ } catch (IOException e) {
+ Log.w(LOG_TAG, "Skipping wallpaper " + ci, e);
+ continue;
+ }
+
+ String packageName = info.getPackageName();
+ String className = info.getServiceName();
+
+ Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
+ intent.setClassName(packageName, className);
+
+ mWallpaperIntents.add(intent);
+ mWallpaperInfos.add(info);
+
+ Drawable thumb = info.loadThumbnail(mPackageManager);
+ if (thumb == null) {
+ int thumbWidth = res.getDimensionPixelSize(R.dimen.live_wallpaper_thumbnail_width);
+ int thumbHeight = res.getDimensionPixelSize(R.dimen.live_wallpaper_thumbnail_height);
+
+ Bitmap thumbnail = Bitmap.createBitmap(thumbWidth, thumbHeight,
+ Bitmap.Config.ARGB_8888);
+
+ paint.setColor(res.getColor(R.color.live_wallpaper_thumbnail_background));
+ canvas.setBitmap(thumbnail);
+ canvas.drawPaint(paint);
+
+ galleryIcon.setBounds(0, 0, thumbWidth, thumbHeight);
+ ((BitmapDrawable) galleryIcon).setGravity(Gravity.CENTER);
+ galleryIcon.draw(canvas);
+
+ String title = info.loadLabel(mPackageManager).toString();
+
+ paint.setColor(res.getColor(R.color.live_wallpaper_thumbnail_text_color));
+ paint.setTextSize(
+ res.getDimensionPixelSize(R.dimen.live_wallpaper_thumbnail_text_size));
+
+ canvas.drawText(title, (int) (thumbWidth * 0.5),
+ thumbHeight - res.getDimensionPixelSize(
+ R.dimen.live_wallpaper_thumbnail_text_offset), paint);
+
+ thumb = new BitmapDrawable(res, thumbnail);
+ }
+
+ thumb.setDither(true);
+ mThumbnails.add(thumb);
+ }
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+
+ if (requestCode == REQUEST_PREVIEW) {
+ if (resultCode == RESULT_OK) finish();
+ }
+ }
+
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ final Intent intent = mWallpaperIntents.get(position);
+ final WallpaperInfo info = mWallpaperInfos.get(position);
+ LiveWallpaperPreview.showPreview(this, REQUEST_PREVIEW, intent, info);
+ }
+
+ static class ViewHolder {
+ TextView titleAuthor;
+ TextView description;
+ ImageView thumbnail;
+ }
+
+ private class LiveWallpapersAdapter extends BaseAdapter {
+ private final LayoutInflater mInflater;
+
+ LiveWallpapersAdapter() {
+ mInflater = LayoutInflater.from(LiveWallpaperListActivity.this);
+ }
+
+ public int getCount() {
+ return mWallpaperInfos.size();
+ }
+
+ public Object getItem(int position) {
+ return mWallpaperInfos.get(position);
+ }
+
+ public long getItemId(int position) {
+ return position;
+ }
+
+ public View getView(int position, View convertView, ViewGroup parent) {
+ ViewHolder holder;
+ if (convertView == null) {
+ convertView = mInflater.inflate(R.layout.live_wallpaper_entry, parent, false);
+
+ holder = new ViewHolder();
+ holder.titleAuthor = (TextView) convertView.findViewById(R.id.title_author);
+ holder.description = (TextView) convertView.findViewById(R.id.description);
+ holder.thumbnail = (ImageView) convertView.findViewById(R.id.thumbnail);
+ convertView.setTag(holder);
+ } else {
+ holder = (ViewHolder) convertView.getTag();
+ }
+
+ WallpaperInfo info = mWallpaperInfos.get(position);
+ holder.thumbnail.setImageDrawable(mThumbnails.get(position));
+ holder.titleAuthor.setText(getString(R.string.wallpaper_title_and_author,
+ info.loadLabel(mPackageManager), info.loadAuthor(mPackageManager)));
+ holder.description.setText(Html.fromHtml(
+ info.loadDescription(mPackageManager).toString()));
+
+ return convertView;
+ }
+ }
+}
diff --git a/src/com/android/wallpaper/livepicker/LiveWallpaperPickActivity.java b/src/com/android/wallpaper/livepicker/LiveWallpaperPickActivity.java
deleted file mode 100644
index b93b01c..0000000
--- a/src/com/android/wallpaper/livepicker/LiveWallpaperPickActivity.java
+++ /dev/null
@@ -1,411 +0,0 @@
-/*
- * Copyright (C) 2009 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.wallpaper.livepicker;
-
-import org.xmlpull.v1.XmlPullParserException;
-
-import android.app.Activity;
-import android.app.WallpaperInfo;
-import android.app.WallpaperManager;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.ServiceConnection;
-import android.content.pm.ComponentInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.res.Resources.NotFoundException;
-import android.graphics.drawable.Drawable;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.os.ParcelFileDescriptor;
-import android.os.RemoteException;
-import android.service.wallpaper.IWallpaperConnection;
-import android.service.wallpaper.IWallpaperEngine;
-import android.service.wallpaper.IWallpaperService;
-import android.service.wallpaper.WallpaperService;
-import android.service.wallpaper.WallpaperSettingsActivity;
-import android.text.Html;
-import android.util.DisplayMetrics;
-import android.util.Log;
-import android.view.Gravity;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.WindowManager;
-import android.widget.AdapterView;
-import android.widget.BaseAdapter;
-import android.widget.Button;
-import android.widget.Gallery;
-import android.widget.ImageView;
-import android.widget.TextView;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.ArrayList;
-
-/**
- * Displays a list of live wallpapers, allowing the user to select one
- * and make it the system global wallpaper.
- */
-public class LiveWallpaperPickActivity extends Activity implements
- AdapterView.OnItemSelectedListener, View.OnClickListener {
-
- private static final String TAG = "LiveWallpaperPickActivity";
-
- private PackageManager mPackageManager;
- private WallpaperManager mWallpaperManager;
-
- Intent mSelectedIntent;
- WallpaperInfo mSelectedInfo;
- WallpaperConnection mWallpaperConnection;
-
- private Button mConfigureButton;
- private TextView mWallpaperTitle;
- private TextView mWallpaperAuthor;
- private TextView mWallpaperSynopsis;
-
- private ArrayList<Intent> mWallpaperIntents;
- private ArrayList<WallpaperInfo> mWallpaperInfos;
-
- private ArrayList<Drawable> mThumbnails;
-
- class WallpaperConnection extends IWallpaperConnection.Stub implements ServiceConnection {
- final Intent mIntent;
- IWallpaperService mService;
- IWallpaperEngine mEngine;
- boolean mConnected;
-
- WallpaperConnection(Intent intent) {
- mIntent = intent;
- }
-
- public boolean connect() {
- synchronized (this) {
- if (!bindService(mIntent, this, Context.BIND_AUTO_CREATE)) {
- return false;
- }
-
- mConnected = true;
- return true;
- }
- }
-
- public void disconnect() {
- synchronized (this) {
- mConnected = false;
- if (mEngine != null) {
- try {
- mEngine.destroy();
- } catch (RemoteException e) {
- // Ignore
- }
- mEngine = null;
- }
- unbindService(this);
- mService = null;
- }
- }
-
- public void onServiceConnected(ComponentName name, IBinder service) {
- if (mWallpaperConnection == this) {
- mService = IWallpaperService.Stub.asInterface(service);
- try {
- View button = findViewById(R.id.set);
- mService.attach(this, button.getWindowToken(),
- WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA,
- true,
- button.getRootView().getWidth(),
- button.getRootView().getHeight());
- } catch (RemoteException e) {
- Log.w(TAG, "Failed attaching wallpaper; clearing", e);
- }
- }
- }
-
- public void onServiceDisconnected(ComponentName name) {
- mService = null;
- mEngine = null;
- if (mWallpaperConnection == this) {
- Log.w(TAG, "Wallpaper service gone: " + name);
- }
- }
-
- public void attachEngine(IWallpaperEngine engine) {
- synchronized (this) {
- if (mConnected) {
- mEngine = engine;
- try {
- engine.setVisibility(true);
- } catch (RemoteException e) {
- // Ignore
- }
- } else {
- try {
- engine.destroy();
- } catch (RemoteException e) {
- // Ignore
- }
- }
- }
- }
-
- public ParcelFileDescriptor setWallpaper(String name) {
- return null;
- }
- }
-
- private class ImageAdapter extends BaseAdapter {
- private LayoutInflater mLayoutInflater;
-
- ImageAdapter(LiveWallpaperPickActivity context) {
- mLayoutInflater = context.getLayoutInflater();
- }
-
- public int getCount() {
- return mThumbnails.size();
- }
-
- public Object getItem(int position) {
- return position;
- }
-
- public long getItemId(int position) {
- return position;
- }
-
- public View getView(int position, View convertView, ViewGroup parent) {
- ImageView image;
-
- if (convertView == null) {
- image = (ImageView) mLayoutInflater.inflate(R.layout.wallpaper_item, parent, false);
- image.setLayoutParams(new Gallery.LayoutParams(
- ViewGroup.LayoutParams.WRAP_CONTENT,
- ViewGroup.LayoutParams.FILL_PARENT));
- image.setAdjustViewBounds(true);
- image.setScaleType(ImageView.ScaleType.FIT_CENTER);
- } else {
- image = (ImageView) convertView;
- }
-
- image.setImageDrawable(mThumbnails.get(position));
-
- return image;
- }
- }
-
-
- private void findLiveWallpapers() {
- mThumbnails = new ArrayList<Drawable>(24);
- List<ResolveInfo> list = mPackageManager.queryIntentServices(getTargetIntent(),
- PackageManager.GET_META_DATA);
-
- mWallpaperIntents = new ArrayList<Intent>(list.size());
- mWallpaperInfos = new ArrayList<WallpaperInfo>(list.size());
-
- int listSize = list.size();
- DisplayMetrics metrics = new DisplayMetrics();
- getWindowManager().getDefaultDisplay().getMetrics(metrics);
-
- Drawable galleryIcon = getResources().getDrawable(R.drawable.livewallpaper_placeholder);
-
- Paint pt = new Paint(Paint.ANTI_ALIAS_FLAG|Paint.DITHER_FLAG);
- pt.setTextAlign(Paint.Align.CENTER);
-
- Canvas canvas = new Canvas();
-
- for (int i = 0; i < listSize; i++) {
- ResolveInfo resolveInfo = list.get(i);
- ComponentInfo ci = resolveInfo.serviceInfo;
- WallpaperInfo winfo;
- try {
- winfo = new WallpaperInfo(this, resolveInfo);
- } catch (XmlPullParserException e) {
- Log.w(TAG, "Skipping wallpaper " + ci, e);
- continue;
- } catch (IOException e) {
- Log.w(TAG, "Skipping wallpaper " + ci, e);
- continue;
- }
-
- String packageName = winfo.getPackageName();
- String className = winfo.getServiceName();
- Intent intent = new Intent(getTargetIntent());
- intent.setClassName(packageName, className);
- mWallpaperIntents.add(intent);
- mWallpaperInfos.add(winfo);
-
- Drawable thumb = winfo.loadThumbnail(mPackageManager);
- if (thumb == null) {
- final int thumbWidth = (int) (180 * metrics.density);
- final int thumbHeight = (int) (160 * metrics.density);
- Bitmap thumbBit = Bitmap.createBitmap(thumbWidth, thumbHeight,
- Bitmap.Config.ARGB_8888);
- pt.setARGB(204,102,102,102);
- canvas.setBitmap(thumbBit);
- canvas.drawPaint(pt);
-
- galleryIcon.setBounds(0, 0, thumbWidth, thumbHeight);
- ((BitmapDrawable) galleryIcon).setGravity(Gravity.CENTER);
- galleryIcon.draw(canvas);
-
- pt.setARGB(255, 255, 255, 255);
- pt.setTextSize(20 * metrics.density);
- canvas.drawText(className.substring(className.lastIndexOf('.') + 1),
- (int) (thumbWidth * 0.5), (int) (thumbHeight - 22 * metrics.density), pt);
- thumb = new BitmapDrawable(getResources(), thumbBit);
- }
-
- thumb.setDither(true);
- mThumbnails.add(thumb);
- }
- }
-
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
-
- mPackageManager = getPackageManager();
- mWallpaperManager = WallpaperManager.getInstance(this);
-
- findLiveWallpapers();
-
- setContentView(R.layout.live_wallpaper_content);
-
- Gallery gallery = (Gallery) findViewById(R.id.gallery);
- gallery.setAdapter(new ImageAdapter(this));
- gallery.setOnItemSelectedListener(this);
- gallery.setCallbackDuringFling(false);
-
- View button = findViewById(R.id.set);
- button.setOnClickListener(this);
-
- mConfigureButton = (Button)findViewById(R.id.configure);
- mConfigureButton.setVisibility(View.GONE);
- mConfigureButton.setOnClickListener(this);
-
- mWallpaperTitle = (TextView)findViewById(R.id.title);
- mWallpaperAuthor = (TextView)findViewById(R.id.author);
- mWallpaperSynopsis = (TextView)findViewById(R.id.synopsis);
-
- // Set default return data
- setResult(RESULT_CANCELED);
- }
-
- @Override
- public void onResume() {
- super.onResume();
- if (mWallpaperConnection != null && mWallpaperConnection.mEngine != null) {
- try {
- mWallpaperConnection.mEngine.setVisibility(true);
- } catch (RemoteException e) {
- // Ignore
- }
- }
- }
-
- @Override
- public void onPause() {
- super.onPause();
- if (mWallpaperConnection != null && mWallpaperConnection.mEngine != null) {
- try {
- mWallpaperConnection.mEngine.setVisibility(false);
- } catch (RemoteException e) {
- // Ignore
- }
- }
- }
-
- @Override
- public void onDetachedFromWindow() {
- super.onDetachedFromWindow();
- if (mWallpaperConnection != null) {
- mWallpaperConnection.disconnect();
- }
- mWallpaperConnection = null;
- }
-
- protected Intent getTargetIntent() {
- return new Intent(WallpaperService.SERVICE_INTERFACE);
- }
-
- public void onItemSelected(AdapterView parent, View v, int position, long id) {
- mSelectedIntent = mWallpaperIntents.get(position);
- mSelectedInfo = mWallpaperInfos.get(position);
- mConfigureButton.setVisibility(
- (mSelectedInfo != null &&
- mSelectedInfo.getSettingsActivity() != null)
- ? View.VISIBLE
- : View.GONE);
- findViewById(R.id.set).setEnabled(true);
-
- mWallpaperTitle.setText(mSelectedInfo.loadLabel(mPackageManager).toString());
- try {
- mWallpaperAuthor.setText(mSelectedInfo.loadAuthor(mPackageManager).toString());
- } catch (NotFoundException e) {
- mWallpaperAuthor.setText("");
- }
- try {
- String htmlText = mSelectedInfo.loadDescription(mPackageManager).toString();
- mWallpaperSynopsis.setText(Html.fromHtml(htmlText));
- } catch (NotFoundException e) {
- mWallpaperSynopsis.setText("");
- }
-
- WallpaperConnection conn = new WallpaperConnection(mSelectedIntent);
- if (conn.connect()) {
- if (mWallpaperConnection != null) {
- mWallpaperConnection.disconnect();
- }
- mWallpaperConnection = conn;
- }
- }
-
- public void onClick(View v) { // "Set" button
- if (v.getId() == R.id.set) {
- if (mSelectedIntent != null) {
- try {
- mWallpaperManager.getIWallpaperManager().setWallpaperComponent(
- mSelectedIntent.getComponent());
- mWallpaperManager.setWallpaperOffsets(
- v.getRootView().getWindowToken(), 0.5f, 0.0f);
- this.setResult(RESULT_OK);
- } catch (RemoteException e) {
- // do nothing
- } catch (RuntimeException e) {
- Log.w(TAG, "Failure setting wallpaper", e);
- }
- finish();
- }
- } else if (v.getId() == R.id.configure) {
- if (mSelectedInfo != null && mSelectedInfo.getSettingsActivity() != null) {
- Intent intent = new Intent();
- intent.setComponent(new ComponentName(mSelectedInfo.getPackageName(),
- mSelectedInfo.getSettingsActivity()));
- intent.putExtra(WallpaperSettingsActivity.EXTRA_PREVIEW_MODE, true);
- startActivity(intent);
- }
- }
- }
-
- public void onNothingSelected(AdapterView parent) {
- }
-}
diff --git a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java
new file mode 100644
index 0000000..374f5ec
--- /dev/null
+++ b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java
@@ -0,0 +1,224 @@
+/*
+ * Copyright (C) 2009 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.wallpaper.livepicker;
+
+import android.app.Activity;
+import android.app.WallpaperManager;
+import android.app.WallpaperInfo;
+import android.service.wallpaper.IWallpaperConnection;
+import android.service.wallpaper.IWallpaperService;
+import android.service.wallpaper.IWallpaperEngine;
+import android.service.wallpaper.WallpaperSettingsActivity;
+import android.content.ServiceConnection;
+import android.content.Intent;
+import android.content.Context;
+import android.content.ComponentName;
+import android.os.RemoteException;
+import android.os.IBinder;
+import android.os.ParcelFileDescriptor;
+import android.os.Bundle;
+import android.view.View;
+import android.view.WindowManager;
+import android.util.Log;
+
+public class LiveWallpaperPreview extends Activity {
+ static final String EXTRA_LIVE_WALLPAPER_INTENT = "android.live_wallpaper.intent";
+ static final String EXTRA_LIVE_WALLPAPER_SETTINGS = "android.live_wallpaper.settings";
+ static final String EXTRA_LIVE_WALLPAPER_PACKAGE = "android.live_wallpaper.package";
+
+ private static final String LOG_TAG = "LiveWallpaperPreview";
+
+ private WallpaperManager mWallpaperManager;
+ private WallpaperConnection mWallpaperConnection;
+
+ private String mSettings;
+ private String mPackageName;
+ private Intent mWallpaperIntent;
+
+ static void showPreview(Activity activity, int code, Intent intent, WallpaperInfo info) {
+ Intent preview = new Intent(activity, LiveWallpaperPreview.class);
+ preview.putExtra(EXTRA_LIVE_WALLPAPER_INTENT, intent);
+ preview.putExtra(EXTRA_LIVE_WALLPAPER_SETTINGS, info.getSettingsActivity());
+ preview.putExtra(EXTRA_LIVE_WALLPAPER_PACKAGE, info.getPackageName());
+ activity.startActivityForResult(preview, code);
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ Bundle extras = getIntent().getExtras();
+ mWallpaperIntent = (Intent) extras.get(EXTRA_LIVE_WALLPAPER_INTENT);
+ if (mWallpaperIntent == null) {
+ setResult(RESULT_CANCELED);
+ finish();
+ }
+
+ setContentView(R.layout.live_wallpaper_preview);
+
+ mSettings = extras.getString(EXTRA_LIVE_WALLPAPER_SETTINGS);
+ mPackageName = extras.getString(EXTRA_LIVE_WALLPAPER_PACKAGE);
+ if (mSettings == null) {
+ findViewById(R.id.configure).setVisibility(View.GONE);
+ }
+
+ mWallpaperManager = WallpaperManager.getInstance(this);
+
+ WallpaperConnection connection = new WallpaperConnection(mWallpaperIntent);
+ if (connection.connect()) {
+ mWallpaperConnection = connection;
+ }
+ }
+
+ public void setLiveWallpaper(View v) {
+ try {
+ mWallpaperManager.getIWallpaperManager().setWallpaperComponent(
+ mWallpaperIntent.getComponent());
+ mWallpaperManager.setWallpaperOffsets(v.getRootView().getWindowToken(), 0.5f, 0.0f);
+ setResult(RESULT_OK);
+ } catch (RemoteException e) {
+ // do nothing
+ } catch (RuntimeException e) {
+ Log.w(LOG_TAG, "Failure setting wallpaper", e);
+ }
+ finish();
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void configureLiveWallpaper(View v) {
+ Intent intent = new Intent();
+ intent.setComponent(new ComponentName(mPackageName, mSettings));
+ intent.putExtra(WallpaperSettingsActivity.EXTRA_PREVIEW_MODE, true);
+ startActivity(intent);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ if (mWallpaperConnection != null && mWallpaperConnection.mEngine != null) {
+ try {
+ mWallpaperConnection.mEngine.setVisibility(true);
+ } catch (RemoteException e) {
+ // Ignore
+ }
+ }
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ if (mWallpaperConnection != null && mWallpaperConnection.mEngine != null) {
+ try {
+ mWallpaperConnection.mEngine.setVisibility(false);
+ } catch (RemoteException e) {
+ // Ignore
+ }
+ }
+ }
+
+ @Override
+ public void onDetachedFromWindow() {
+ super.onDetachedFromWindow();
+ if (mWallpaperConnection != null) {
+ mWallpaperConnection.disconnect();
+ }
+ mWallpaperConnection = null;
+ }
+
+ class WallpaperConnection extends IWallpaperConnection.Stub implements ServiceConnection {
+ final Intent mIntent;
+ IWallpaperService mService;
+ IWallpaperEngine mEngine;
+ boolean mConnected;
+
+ WallpaperConnection(Intent intent) {
+ mIntent = intent;
+ }
+
+ public boolean connect() {
+ synchronized (this) {
+ if (!bindService(mIntent, this, Context.BIND_AUTO_CREATE)) {
+ return false;
+ }
+
+ mConnected = true;
+ return true;
+ }
+ }
+
+ public void disconnect() {
+ synchronized (this) {
+ mConnected = false;
+ if (mEngine != null) {
+ try {
+ mEngine.destroy();
+ } catch (RemoteException e) {
+ // Ignore
+ }
+ mEngine = null;
+ }
+ unbindService(this);
+ mService = null;
+ }
+ }
+
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ if (mWallpaperConnection == this) {
+ mService = IWallpaperService.Stub.asInterface(service);
+ try {
+ final View view = getWindow().getDecorView().getRootView();
+ mService.attach(this, view.getWindowToken(),
+ WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA,
+ true, view.getWidth(), view.getHeight());
+ } catch (RemoteException e) {
+ Log.w(LOG_TAG, "Failed attaching wallpaper; clearing", e);
+ }
+ }
+ }
+
+ public void onServiceDisconnected(ComponentName name) {
+ mService = null;
+ mEngine = null;
+ if (mWallpaperConnection == this) {
+ Log.w(LOG_TAG, "Wallpaper service gone: " + name);
+ }
+ }
+
+ public void attachEngine(IWallpaperEngine engine) {
+ synchronized (this) {
+ if (mConnected) {
+ mEngine = engine;
+ try {
+ engine.setVisibility(true);
+ } catch (RemoteException e) {
+ // Ignore
+ }
+ } else {
+ try {
+ engine.destroy();
+ } catch (RemoteException e) {
+ // Ignore
+ }
+ }
+ }
+ }
+
+ public ParcelFileDescriptor setWallpaper(String name) {
+ return null;
+ }
+ }
+}