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
17package com.android.wallpaper.livepicker;
18
19import android.app.ListActivity;
20import android.app.WallpaperInfo;
21import android.content.Intent;
22import android.os.Bundle;
23import android.view.View;
24import android.widget.ListView;
25
26public class LiveWallpaperActivity extends ListActivity {
27    private static final int REQUEST_PREVIEW = 100;
28
29    private LiveWallpaperListAdapter mAdapter;
30
31    @Override
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
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
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