Fields Summary |
---|
private static final String | TAG |
private static final File | WALLPAPER_DIR |
private static final String | WALLPAPER |
private static final File | WALLPAPER_FILE |
private static final String | PREFERENCES |
private static final String | HINT_WIDTH |
private static final String | HINT_HEIGHT |
private final android.os.RemoteCallbackList | mCallbacksList of callbacks registered they should each be notified
when the wallpaper is changed. |
private final android.os.FileObserver | mWallpaperObserverObserves the wallpaper for changes and notifies all IWallpaperServiceCallbacks
that the wallpaper has changed. The CREATE is triggered when there is no
wallpaper set and is created for the first time. The CLOSE_WRITE is triggered
everytime the wallpaper is changed. |
private final android.content.Context | mContext |
private int | mWidth |
private int | mHeight |
Methods Summary |
---|
private void | checkPermission(java.lang.String permission)
if (PackageManager.PERMISSION_GRANTED != mContext.checkCallingOrSelfPermission(permission)) {
throw new SecurityException("Access denied to process: " + Binder.getCallingPid()
+ ", must have permission " + permission);
}
|
public void | clearWallpaper()
File f = WALLPAPER_FILE;
if (f.exists()) {
f.delete();
}
|
private void | createFilesDir()
if (!WALLPAPER_DIR.exists()) {
WALLPAPER_DIR.mkdirs();
}
|
protected void | finalize()
super.finalize();
mWallpaperObserver.stopWatching();
|
public int | getHeightHint()
return mHeight;
|
public android.os.ParcelFileDescriptor | getWallpaper(android.app.IWallpaperServiceCallback cb)
try {
mCallbacks.register(cb);
File f = WALLPAPER_FILE;
if (!f.exists()) {
return null;
}
return ParcelFileDescriptor.open(f, MODE_READ_ONLY);
} catch (FileNotFoundException e) {
/* Shouldn't happen as we check to see if the file exists */
if (Config.LOGD) Log.d(TAG, "Error getting wallpaper", e);
}
return null;
|
public int | getWidthHint()
return mWidth;
|
private void | notifyCallbacks()
final int n = mCallbacks.beginBroadcast();
for (int i = 0; i < n; i++) {
try {
mCallbacks.getBroadcastItem(i).onWallpaperChanged();
} catch (RemoteException e) {
// The RemoteCallbackList will take care of removing
// the dead object for us.
}
}
mCallbacks.finishBroadcast();
final Intent intent = new Intent(Intent.ACTION_WALLPAPER_CHANGED);
mContext.sendBroadcast(intent);
|
public void | setDimensionHints(int width, int height)
checkPermission(android.Manifest.permission.SET_WALLPAPER_HINTS);
if (width <= 0 || height <= 0) {
throw new IllegalArgumentException("width and height must be > 0");
}
if (width != mWidth || height != mHeight) {
mWidth = width;
mHeight = height;
SharedPreferences preferences = mContext.getSharedPreferences(PREFERENCES,
Context.MODE_PRIVATE);
final SharedPreferences.Editor editor = preferences.edit();
editor.putInt(HINT_WIDTH, width);
editor.putInt(HINT_HEIGHT, height);
editor.commit();
}
|
public android.os.ParcelFileDescriptor | setWallpaper()
checkPermission(android.Manifest.permission.SET_WALLPAPER);
try {
return ParcelFileDescriptor.open(WALLPAPER_FILE, MODE_CREATE|MODE_READ_WRITE);
} catch (FileNotFoundException e) {
if (Config.LOGD) Log.d(TAG, "Error setting wallpaper", e);
}
return null;
|