Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | |
| 17 | package com.android.launcher2; |
| 18 | |
Dianne Hackborn | 83a5d38 | 2009-09-15 18:50:10 -0700 | [diff] [blame] | 19 | import org.xmlpull.v1.XmlPullParserException; |
| 20 | |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 21 | import android.app.Activity; |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 22 | import android.app.ListActivity; |
Dianne Hackborn | 83a5d38 | 2009-09-15 18:50:10 -0700 | [diff] [blame] | 23 | import android.app.WallpaperInfo; |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 24 | import android.app.WallpaperManager; |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 25 | import android.content.ComponentName; |
| 26 | import android.content.Context; |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 27 | import android.content.DialogInterface; |
| 28 | import android.content.Intent; |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 29 | import android.content.ServiceConnection; |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 30 | import android.content.pm.ComponentInfo; |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 31 | import android.content.pm.PackageManager; |
| 32 | import android.content.pm.ResolveInfo; |
| 33 | import android.content.pm.ServiceInfo; |
| 34 | import android.graphics.drawable.Drawable; |
Daniel Sandler | 8f141b4 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 35 | import android.graphics.drawable.BitmapDrawable; |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 36 | import android.graphics.Bitmap; |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 37 | import android.os.Binder; |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 38 | import android.os.Bundle; |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 39 | import android.os.IBinder; |
| 40 | import android.os.ParcelFileDescriptor; |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 41 | import android.os.RemoteException; |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 42 | import android.os.SystemClock; |
| 43 | import android.service.wallpaper.IWallpaperConnection; |
| 44 | import android.service.wallpaper.IWallpaperEngine; |
| 45 | import android.service.wallpaper.IWallpaperService; |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 46 | import android.service.wallpaper.WallpaperService; |
Dianne Hackborn | 83a5d38 | 2009-09-15 18:50:10 -0700 | [diff] [blame] | 47 | import android.service.wallpaper.WallpaperSettingsActivity; |
Daniel Sandler | 8f141b4 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 48 | import android.util.DisplayMetrics; |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 49 | import android.util.Log; |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 50 | import android.view.LayoutInflater; |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 51 | import android.view.View; |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 52 | import android.view.ViewGroup; |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 53 | import android.view.WindowManager; |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 54 | import android.widget.AdapterView; |
| 55 | import android.widget.BaseAdapter; |
Dianne Hackborn | 83a5d38 | 2009-09-15 18:50:10 -0700 | [diff] [blame] | 56 | import android.widget.Button; |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 57 | import android.widget.Gallery; |
| 58 | import android.widget.ImageView; |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 59 | import android.widget.ListView; |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 60 | |
Dianne Hackborn | 83a5d38 | 2009-09-15 18:50:10 -0700 | [diff] [blame] | 61 | import java.io.IOException; |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 62 | import java.text.Collator; |
| 63 | import java.util.List; |
| 64 | import java.util.ArrayList; |
| 65 | import java.util.Collections; |
| 66 | import java.util.Comparator; |
| 67 | |
| 68 | /** |
| 69 | * Displays a list of live wallpapers, allowing the user to select one |
| 70 | * and make it the system global wallpaper. |
| 71 | */ |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 72 | public class LiveWallpaperPickActivity |
| 73 | extends Activity |
| 74 | implements AdapterView.OnItemSelectedListener, |
| 75 | View.OnClickListener |
| 76 | { |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 77 | private static final String TAG = "LiveWallpaperPickActivity"; |
| 78 | |
| 79 | private PackageManager mPackageManager; |
| 80 | private WallpaperManager mWallpaperManager; |
| 81 | |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 82 | Intent mSelectedIntent; |
Dianne Hackborn | 83a5d38 | 2009-09-15 18:50:10 -0700 | [diff] [blame] | 83 | WallpaperInfo mSelectedInfo; |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 84 | WallpaperConnection mWallpaperConnection; |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 85 | |
| 86 | private Gallery mGallery; |
Dianne Hackborn | 83a5d38 | 2009-09-15 18:50:10 -0700 | [diff] [blame] | 87 | private Button mConfigureButton; |
| 88 | |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 89 | private ArrayList<Intent> mWallpaperIntents; |
Dianne Hackborn | 83a5d38 | 2009-09-15 18:50:10 -0700 | [diff] [blame] | 90 | private ArrayList<WallpaperInfo> mWallpaperInfos; |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 91 | |
Daniel Sandler | 8f141b4 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 92 | private ArrayList<Drawable> mThumbnails; |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 93 | |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 94 | class WallpaperConnection extends IWallpaperConnection.Stub |
| 95 | implements ServiceConnection { |
| 96 | final Intent mIntent; |
| 97 | IWallpaperService mService; |
| 98 | IWallpaperEngine mEngine; |
| 99 | boolean mConnected; |
| 100 | |
| 101 | public WallpaperConnection(Intent intent) { |
| 102 | mIntent = intent; |
| 103 | } |
| 104 | |
| 105 | public boolean connect() { |
| 106 | synchronized (this) { |
| 107 | if (!bindService(mIntent, this, Context.BIND_AUTO_CREATE)) { |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | mConnected = true; |
| 112 | return true; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | public void disconnect() { |
| 117 | synchronized (this) { |
| 118 | mConnected = false; |
| 119 | if (mEngine != null) { |
| 120 | try { |
| 121 | mEngine.destroy(); |
| 122 | } catch (RemoteException e) { |
| 123 | } |
| 124 | mEngine = null; |
| 125 | } |
| 126 | unbindService(this); |
| 127 | mService = null; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 132 | if (mWallpaperConnection == this) { |
| 133 | mService = IWallpaperService.Stub.asInterface(service); |
| 134 | try { |
| 135 | View button = findViewById(R.id.set); |
| 136 | mService.attach(this, button.getWindowToken(), |
| 137 | WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA, |
| 138 | true, |
| 139 | button.getRootView().getWidth(), |
| 140 | button.getRootView().getHeight()); |
| 141 | } catch (RemoteException e) { |
| 142 | Log.w(TAG, "Failed attaching wallpaper; clearing", e); |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | public void onServiceDisconnected(ComponentName name) { |
| 148 | mService = null; |
| 149 | mEngine = null; |
| 150 | if (mWallpaperConnection == this) { |
| 151 | Log.w(TAG, "Wallpaper service gone: " + name); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | public void attachEngine(IWallpaperEngine engine) { |
| 156 | synchronized (this) { |
| 157 | if (mConnected) { |
| 158 | mEngine = engine; |
Dianne Hackborn | 5237ccb | 2009-08-29 19:17:48 -0700 | [diff] [blame] | 159 | try { |
| 160 | engine.setVisibility(true); |
| 161 | } catch (RemoteException e) { |
| 162 | } |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 163 | } else { |
| 164 | try { |
| 165 | engine.destroy(); |
| 166 | } catch (RemoteException e) { |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | public ParcelFileDescriptor setWallpaper(String name) { |
| 173 | return null; |
| 174 | } |
| 175 | } |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 176 | |
| 177 | private class ImageAdapter extends BaseAdapter { |
| 178 | private LayoutInflater mLayoutInflater; |
| 179 | |
| 180 | ImageAdapter(LiveWallpaperPickActivity context) { |
| 181 | mLayoutInflater = context.getLayoutInflater(); |
| 182 | } |
| 183 | |
| 184 | public int getCount() { |
Daniel Sandler | 8f141b4 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 185 | return mThumbnails.size(); |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | public Object getItem(int position) { |
| 189 | return position; |
| 190 | } |
| 191 | |
| 192 | public long getItemId(int position) { |
| 193 | return position; |
| 194 | } |
| 195 | |
| 196 | public View getView(int position, View convertView, ViewGroup parent) { |
| 197 | ImageView image; |
| 198 | |
| 199 | if (convertView == null) { |
| 200 | image = (ImageView) mLayoutInflater.inflate(R.layout.wallpaper_item, parent, false); |
| 201 | } else { |
| 202 | image = (ImageView) convertView; |
| 203 | } |
| 204 | |
Daniel Sandler | 8f141b4 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 205 | image.setImageDrawable(mThumbnails.get(position)); |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 206 | image.getDrawable().setDither(true); |
Daniel Sandler | 8f141b4 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 207 | |
| 208 | image.setAdjustViewBounds(true); |
| 209 | image.setScaleType(ImageView.ScaleType.FIT_CENTER); |
| 210 | image.setLayoutParams(new Gallery.LayoutParams( |
| 211 | ViewGroup.LayoutParams.WRAP_CONTENT, |
| 212 | ViewGroup.LayoutParams.FILL_PARENT)); |
| 213 | |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 214 | return image; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | |
| 219 | private void findLiveWallpapers() { |
Daniel Sandler | 8f141b4 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 220 | mThumbnails = new ArrayList<Drawable>(24); |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 221 | List<ResolveInfo> list = |
Dianne Hackborn | 83a5d38 | 2009-09-15 18:50:10 -0700 | [diff] [blame] | 222 | mPackageManager.queryIntentServices(getTargetIntent(), |
| 223 | PackageManager.GET_META_DATA); |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 224 | |
| 225 | mWallpaperIntents = new ArrayList<Intent>(list.size()); |
Dianne Hackborn | 83a5d38 | 2009-09-15 18:50:10 -0700 | [diff] [blame] | 226 | mWallpaperInfos = new ArrayList<WallpaperInfo>(list.size()); |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 227 | |
| 228 | int listSize = list.size(); |
Daniel Sandler | 8f141b4 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 229 | DisplayMetrics metrics = new DisplayMetrics(); |
| 230 | getWindowManager().getDefaultDisplay().getMetrics(metrics); |
| 231 | |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 232 | for (int i = 0; i < listSize; i++) { |
| 233 | ResolveInfo resolveInfo = list.get(i); |
| 234 | ComponentInfo ci = resolveInfo.serviceInfo; |
Dianne Hackborn | 83a5d38 | 2009-09-15 18:50:10 -0700 | [diff] [blame] | 235 | WallpaperInfo winfo; |
| 236 | try { |
| 237 | winfo = new WallpaperInfo(this, resolveInfo); |
| 238 | } catch (XmlPullParserException e) { |
| 239 | Log.w(TAG, "Skipping wallpaper " + ci, e); |
| 240 | continue; |
| 241 | } catch (IOException e) { |
| 242 | Log.w(TAG, "Skipping wallpaper " + ci, e); |
| 243 | continue; |
| 244 | } |
Daniel Sandler | 8f141b4 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 245 | |
| 246 | String packageName = winfo.getPackageName(); |
| 247 | String className = winfo.getServiceName(); |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 248 | Intent intent = new Intent(getTargetIntent()); |
| 249 | intent.setClassName(packageName, className); |
| 250 | mWallpaperIntents.add(intent); |
Dianne Hackborn | 83a5d38 | 2009-09-15 18:50:10 -0700 | [diff] [blame] | 251 | mWallpaperInfos.add(winfo); |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 252 | |
Daniel Sandler | 8f141b4 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 253 | Drawable thumb = winfo.loadThumbnail(mPackageManager); |
| 254 | if (null == thumb) { |
| 255 | // TODO dsandler: replace with pretty placeholder |
| 256 | Bitmap thumbBit = Bitmap.createBitmap( |
| 257 | (int)(240 * metrics.density), |
| 258 | (int)(240 * metrics.density), |
| 259 | Bitmap.Config.ARGB_8888); |
| 260 | android.graphics.Canvas can = new android.graphics.Canvas(thumbBit); |
| 261 | android.graphics.Paint pt = new android.graphics.Paint(android.graphics.Paint.ANTI_ALIAS_FLAG|android.graphics.Paint.DITHER_FLAG); |
| 262 | pt.setARGB(255, 0, 0, 255); |
| 263 | can.drawPaint(pt); |
| 264 | pt.setARGB(255, 255, 255, 255); |
| 265 | pt.setTextSize(12 * metrics.density); |
| 266 | can.drawText(className, |
| 267 | (int)(12 * metrics.density), |
| 268 | (int)(thumbBit.getHeight()-12 * metrics.density), |
| 269 | pt); |
| 270 | pt.setTextSize(100 * metrics.density); |
| 271 | can.drawText(String.format("#%d", i), |
| 272 | (int)(thumbBit.getWidth()*0.3), |
| 273 | (int)(thumbBit.getHeight()*0.5), |
| 274 | pt); |
| 275 | thumb = new BitmapDrawable(thumbBit); |
| 276 | } |
| 277 | mThumbnails.add(thumb); |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | |
| 281 | } |
| 282 | |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 283 | |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 284 | @Override |
| 285 | public void onCreate(Bundle icicle) { |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 286 | super.onCreate(icicle); |
| 287 | |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 288 | mPackageManager = getPackageManager(); |
| 289 | mWallpaperManager = WallpaperManager.getInstance(this); |
| 290 | |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 291 | findLiveWallpapers(); |
| 292 | |
| 293 | setContentView(R.layout.live_wallpaper_content); |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 294 | |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 295 | mGallery = (Gallery) findViewById(R.id.gallery); |
| 296 | mGallery.setAdapter(new ImageAdapter(this)); |
| 297 | mGallery.setOnItemSelectedListener(this); |
| 298 | mGallery.setCallbackDuringFling(false); |
| 299 | |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 300 | View button = findViewById(R.id.set); |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 301 | button.setOnClickListener(this); |
| 302 | |
Dianne Hackborn | 83a5d38 | 2009-09-15 18:50:10 -0700 | [diff] [blame] | 303 | mConfigureButton = (Button)findViewById(R.id.configure); |
| 304 | mConfigureButton.setEnabled(false); |
| 305 | mConfigureButton.setOnClickListener(this); |
| 306 | |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 307 | // Set default return data |
| 308 | setResult(RESULT_CANCELED); |
| 309 | } |
| 310 | |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 311 | @Override |
Dianne Hackborn | 5237ccb | 2009-08-29 19:17:48 -0700 | [diff] [blame] | 312 | public void onResume() { |
| 313 | super.onResume(); |
| 314 | if (mWallpaperConnection != null && mWallpaperConnection.mEngine != null) { |
| 315 | try { |
| 316 | mWallpaperConnection.mEngine.setVisibility(true); |
| 317 | } catch (RemoteException e) { |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | @Override |
| 323 | public void onPause() { |
| 324 | super.onPause(); |
| 325 | if (mWallpaperConnection != null && mWallpaperConnection.mEngine != null) { |
| 326 | try { |
| 327 | mWallpaperConnection.mEngine.setVisibility(false); |
| 328 | } catch (RemoteException e) { |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | @Override |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 334 | public void onDetachedFromWindow() { |
| 335 | super.onDetachedFromWindow(); |
| 336 | if (mWallpaperConnection != null) { |
| 337 | mWallpaperConnection.disconnect(); |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 338 | } |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 339 | mWallpaperConnection = null; |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 342 | protected Intent getTargetIntent() { |
| 343 | return new Intent(WallpaperService.SERVICE_INTERFACE); |
| 344 | } |
| 345 | |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 346 | public void onItemSelected(AdapterView parent, View v, int position, long id) { |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 347 | mSelectedIntent = mWallpaperIntents.get(position); |
Dianne Hackborn | 83a5d38 | 2009-09-15 18:50:10 -0700 | [diff] [blame] | 348 | mSelectedInfo = mWallpaperInfos.get(position); |
| 349 | mConfigureButton.setEnabled(mSelectedInfo != null |
| 350 | && mSelectedInfo.getSettingsActivity() != null); |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 351 | findViewById(R.id.set).setEnabled(true); |
| 352 | |
| 353 | WallpaperConnection conn = new WallpaperConnection(mSelectedIntent); |
| 354 | if (conn.connect()) { |
| 355 | if (mWallpaperConnection != null) { |
| 356 | mWallpaperConnection.disconnect(); |
| 357 | } |
| 358 | mWallpaperConnection = conn; |
| 359 | } |
| 360 | } |
| 361 | |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 362 | public void onClick(View v) { // "Set" button |
Dianne Hackborn | 83a5d38 | 2009-09-15 18:50:10 -0700 | [diff] [blame] | 363 | if (v.getId() == R.id.set) { |
| 364 | if (mSelectedIntent != null) { |
| 365 | try { |
| 366 | mWallpaperManager.getIWallpaperManager().setWallpaperComponent( |
| 367 | mSelectedIntent.getComponent()); |
| 368 | this.setResult(RESULT_OK); |
| 369 | } catch (RemoteException e) { |
| 370 | // do nothing |
| 371 | } catch (RuntimeException e) { |
| 372 | Log.w(TAG, "Failure setting wallpaper", e); |
| 373 | } |
| 374 | finish(); |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 375 | } |
Dianne Hackborn | 83a5d38 | 2009-09-15 18:50:10 -0700 | [diff] [blame] | 376 | } else if (v.getId() == R.id.configure) { |
| 377 | if (mSelectedInfo != null && mSelectedInfo.getSettingsActivity() != null) { |
| 378 | Intent intent = new Intent(); |
| 379 | intent.setComponent(new ComponentName(mSelectedInfo.getPackageName(), |
| 380 | mSelectedInfo.getSettingsActivity())); |
| 381 | intent.putExtra(WallpaperSettingsActivity.EXTRA_PREVIEW_MODE, true); |
| 382 | startActivity(intent); |
| 383 | } |
Dianne Hackborn | 02e638e | 2009-08-20 19:33:42 -0700 | [diff] [blame] | 384 | } |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 385 | } |
Daniel Sandler | 86aea35 | 2009-09-11 15:59:22 -0400 | [diff] [blame] | 386 | |
| 387 | public void onNothingSelected(AdapterView parent) { |
| 388 | } |
| 389 | |
Romain Guy | 41669fc | 2009-08-13 12:53:24 -0700 | [diff] [blame] | 390 | } |