Implement all of the infrastructure for configuring wallpapers.

Actually being able to configure a wallpaper relies on additional
work in the launcher and wallpapers that will be in another change.
Also note that this breaks all existing wallpapers, since they now
need to include a meta-data item about themselves.  This also
will be fixed in another change.

Change-Id: I97d2c2bd07237abc32f92b9147c32530a2f73c71
This commit is contained in:
Dianne Hackborn
2009-09-07 00:49:58 -07:00
parent 9c93007bcd
commit eb034652c2
21 changed files with 880 additions and 44 deletions

View File

@@ -684,6 +684,11 @@ public class ActivityManager {
*/
public int pid;
/**
* The user id of this process.
*/
public int uid;
public String pkgList[];
/**
@@ -797,6 +802,7 @@ public class ActivityManager {
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(processName);
dest.writeInt(pid);
dest.writeInt(uid);
dest.writeStringArray(pkgList);
dest.writeInt(importance);
dest.writeInt(lru);
@@ -808,6 +814,7 @@ public class ActivityManager {
public void readFromParcel(Parcel source) {
processName = source.readString();
pid = source.readInt();
uid = source.readInt();
pkgList = source.readStringArray();
importance = source.readInt();
lru = source.readInt();

View File

@@ -19,6 +19,7 @@ package android.app;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.app.IWallpaperManagerCallback;
import android.app.WallpaperInfo;
import android.content.ComponentName;
/** @hide */
@@ -40,6 +41,11 @@ interface IWallpaperManager {
ParcelFileDescriptor getWallpaper(IWallpaperManagerCallback cb,
out Bundle outParams);
/**
* Get information about a live wallpaper.
*/
WallpaperInfo getWallpaperInfo();
/**
* Clear the wallpaper.
*/

View File

@@ -53,9 +53,9 @@ import java.util.List;
*
*/
public abstract class LauncherActivity extends ListActivity {
Intent mIntent;
PackageManager mPackageManager;
IconResizer mIconResizer;
/**
* An item in the list
@@ -77,7 +77,9 @@ public abstract class LauncherActivity extends ListActivity {
label = resolveInfo.activityInfo.name;
}
icon = resizer.createIconThumbnail(resolveInfo.loadIcon(pm));
if (resizer != null) {
icon = resizer.createIconThumbnail(resolveInfo.loadIcon(pm));
}
packageName = ci.applicationInfo.packageName;
className = ci.name;
}
@@ -93,13 +95,15 @@ public abstract class LauncherActivity extends ListActivity {
private final Object lock = new Object();
private ArrayList<ListItem> mOriginalValues;
protected final IconResizer mIconResizer;
protected final LayoutInflater mInflater;
protected List<ListItem> mActivitiesList;
private Filter mFilter;
public ActivityAdapter() {
public ActivityAdapter(IconResizer resizer) {
mIconResizer = resizer;
mInflater = (LayoutInflater) LauncherActivity.this.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
mActivitiesList = makeListItems();
@@ -154,6 +158,10 @@ public abstract class LauncherActivity extends ListActivity {
private void bindView(View view, ListItem item) {
TextView text = (TextView) view;
text.setText(item.label);
if (item.icon == null) {
item.icon = mIconResizer.createIconThumbnail(
item.resolveInfo.loadIcon(getPackageManager()));
}
text.setCompoundDrawablesWithIntrinsicBounds(item.icon, null, null, null);
}
@@ -330,9 +338,11 @@ public abstract class LauncherActivity extends ListActivity {
setProgressBarIndeterminateVisibility(true);
onSetContentView();
mIconResizer = new IconResizer();
mIntent = new Intent(getTargetIntent());
mIntent.setComponent(null);
mAdapter = new ActivityAdapter();
mAdapter = new ActivityAdapter(mIconResizer);
setListAdapter(mAdapter);
getListView().setTextFilterEnabled(true);
@@ -398,13 +408,11 @@ public abstract class LauncherActivity extends ListActivity {
List<ResolveInfo> list = onQueryPackageManager(mIntent);
Collections.sort(list, new ResolveInfo.DisplayNameComparator(mPackageManager));
IconResizer resizer = new IconResizer();
ArrayList<ListItem> result = new ArrayList<ListItem>(list.size());
int listSize = list.size();
for (int i = 0; i < listSize; i++) {
ResolveInfo resolveInfo = list.get(i);
result.add(new ListItem(mPackageManager, resolveInfo, resizer));
result.add(new ListItem(mPackageManager, resolveInfo, null));
}
return result;

View File

@@ -0,0 +1,19 @@
/*
** Copyright 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 android.app;
parcelable WallpaperInfo;

View File

@@ -0,0 +1,200 @@
package android.app;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.service.wallpaper.WallpaperService;
import android.util.AttributeSet;
import android.util.Printer;
import android.util.Xml;
import java.io.IOException;
/**
* This class is used to specify meta information of a wallpaper service.
* @hide Live Wallpaper
*/
public final class WallpaperInfo implements Parcelable {
static final String TAG = "WallpaperInfo";
/**
* The Service that implements this wallpaper component.
*/
final ResolveInfo mService;
/**
* The wallpaper setting activity's name, to
* launch the setting activity of this wallpaper.
*/
final String mSettingsActivityName;
/**
* Constructor.
*
* @param context The Context in which we are parsing the wallpaper.
* @param service The ResolveInfo returned from the package manager about
* this wallpaper's component.
*/
public WallpaperInfo(Context context, ResolveInfo service)
throws XmlPullParserException, IOException {
mService = service;
ServiceInfo si = service.serviceInfo;
PackageManager pm = context.getPackageManager();
String settingsActivityComponent = null;
XmlResourceParser parser = null;
try {
parser = si.loadXmlMetaData(pm, WallpaperService.SERVICE_META_DATA);
if (parser == null) {
throw new XmlPullParserException("No "
+ WallpaperService.SERVICE_META_DATA + " meta-data");
}
AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
&& type != XmlPullParser.START_TAG) {
}
String nodeName = parser.getName();
if (!"wallpaper".equals(nodeName)) {
throw new XmlPullParserException(
"Meta-data does not start with wallpaper tag");
}
TypedArray sa = context.getResources().obtainAttributes(attrs,
com.android.internal.R.styleable.Wallpaper);
settingsActivityComponent = sa.getString(
com.android.internal.R.styleable.Wallpaper_settingsActivity);
sa.recycle();
} finally {
if (parser != null) parser.close();
}
mSettingsActivityName = settingsActivityComponent;
}
WallpaperInfo(Parcel source) {
mSettingsActivityName = source.readString();
mService = ResolveInfo.CREATOR.createFromParcel(source);
}
/**
* Return the .apk package that implements this wallpaper.
*/
public String getPackageName() {
return mService.serviceInfo.packageName;
}
/**
* Return the class name of the service component that implements
* this wallpaper.
*/
public String getServiceName() {
return mService.serviceInfo.name;
}
/**
* Return the raw information about the Service implementing this
* wallpaper. Do not modify the returned object.
*/
public ServiceInfo getServiceInfo() {
return mService.serviceInfo;
}
/**
* Return the component of the service that implements this wallpaper.
*/
public ComponentName getComponent() {
return new ComponentName(mService.serviceInfo.packageName,
mService.serviceInfo.name);
}
/**
* Load the user-displayed label for this wallpaper.
*
* @param pm Supply a PackageManager used to load the wallpaper's
* resources.
*/
public CharSequence loadLabel(PackageManager pm) {
return mService.loadLabel(pm);
}
/**
* Load the user-displayed icon for this wallpaper.
*
* @param pm Supply a PackageManager used to load the wallpaper's
* resources.
*/
public Drawable loadIcon(PackageManager pm) {
return mService.loadIcon(pm);
}
/**
* Return the class name of an activity that provides a settings UI for
* the wallpaper. You can launch this activity be starting it with
* an {@link android.content.Intent} whose action is MAIN and with an
* explicit {@link android.content.ComponentName}
* composed of {@link #getPackageName} and the class name returned here.
*
* <p>A null will be returned if there is no settings activity associated
* with the wallpaper.
*/
public String getSettingsActivity() {
return mSettingsActivityName;
}
public void dump(Printer pw, String prefix) {
pw.println(prefix + "Service:");
mService.dump(pw, prefix + " ");
pw.println(prefix + "mSettingsActivityName=" + mSettingsActivityName);
}
@Override
public String toString() {
return "WallpaperInfo{" + mService.serviceInfo.name
+ ", settings: "
+ mSettingsActivityName + "}";
}
/**
* Used to package this object into a {@link Parcel}.
*
* @param dest The {@link Parcel} to be written.
* @param flags The flags used for parceling.
*/
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mSettingsActivityName);
mService.writeToParcel(dest, flags);
}
/**
* Used to make this class parcelable.
*/
public static final Parcelable.Creator<WallpaperInfo> CREATOR = new Parcelable.Creator<WallpaperInfo>() {
public WallpaperInfo createFromParcel(Parcel source) {
return new WallpaperInfo(source);
}
public WallpaperInfo[] newArray(int size) {
return new WallpaperInfo[size];
}
};
public int describeContents() {
return 0;
}
}

View File

@@ -49,7 +49,7 @@ public class WallpaperManager {
/**
* Launch an activity for the user to pick the current global live
* wallpaper.
* @hide
* @hide Live Wallpaper
*/
public static final String ACTION_LIVE_WALLPAPER_CHOOSER
= "android.service.wallpaper.LIVE_WALLPAPER_CHOOSER";
@@ -238,6 +238,20 @@ public class WallpaperManager {
return bm != null ? new BitmapDrawable(mContext.getResources(), bm) : null;
}
/**
* If the current wallpaper is a live wallpaper component, return the
* information about that wallpaper. Otherwise, if it is a static image,
* simply return null.
* @hide Live Wallpaper
*/
public WallpaperInfo getWallpaperInfo() {
try {
return sGlobals.mService.getWallpaperInfo();
} catch (RemoteException e) {
return null;
}
}
/**
* Change the current system wallpaper to the bitmap in the given resource.
* The resource is opened as a raw data stream and copied into the