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.wallpaper.livepicker;
18 
19 import android.app.ListActivity;
20 import android.app.WallpaperInfo;
21 import android.content.Intent;
22 import android.os.Bundle;
23 import android.view.View;
24 import android.widget.ListView;
25 
26 public class LiveWallpaperActivity extends ListActivity {
27     private static final int REQUEST_PREVIEW = 100;
28 
29     private LiveWallpaperListAdapter mAdapter;
30 
31     @Override
onCreate(Bundle savedInstanceState)32     protected void onCreate(Bundle savedInstanceState) {
33         super.onCreate(savedInstanceState);
34         setContentView(R.layout.live_wallpaper_base);
35 
36         mAdapter = new LiveWallpaperListAdapter(this);
37         setListAdapter(mAdapter);
38     }
39 
40     @Override
onActivityResult(int requestCode, int resultCode, Intent data)41     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
42         super.onActivityResult(requestCode, resultCode, data);
43 
44         if (requestCode == REQUEST_PREVIEW) {
45             if (resultCode == RESULT_OK) finish();
46         }
47     }
48 
49     @Override
onListItemClick(ListView l, View v, int position, long id)50     protected void onListItemClick(ListView l, View v, int position, long id) {
51         LiveWallpaperListAdapter.LiveWallpaperInfo wallpaperInfo =
52                 (LiveWallpaperListAdapter.LiveWallpaperInfo) mAdapter.getItem(position);
53         final WallpaperInfo info = wallpaperInfo.info;
54         if (info != null) {
55             Intent preview = new Intent(this, LiveWallpaperPreview.class);
56             preview.putExtra(LiveWallpaperPreview.EXTRA_LIVE_WALLPAPER_INFO, info);
57             startActivityForResult(preview, REQUEST_PREVIEW);
58         }
59     }
60 
61 }
62