1/*
2 * Copyright (C) 2007 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.camera;
18
19import android.content.Intent;
20import android.net.Uri;
21import android.os.Bundle;
22
23/**
24 * Wallpaper picker for the camera application. This just redirects to the
25 * standard pick action.
26 */
27public class Wallpaper extends NoSearchActivity {
28    @SuppressWarnings("unused")
29    private static final String TAG = "Wallpaper";
30    private static final int PHOTO_PICKED = 1;
31    private static final int CROP_DONE = 2;
32
33    @Override
34    protected void onCreate(Bundle icicle) {
35        super.onCreate(icicle);
36
37        Uri imageToUse = getIntent().getData();
38        if (imageToUse != null) {
39            Intent intent = new Intent();
40            intent.setClass(this, CropImage.class);
41            intent.setData(imageToUse);
42            formatIntent(intent);
43            startActivityForResult(intent, CROP_DONE);
44        } else {
45            Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
46            intent.setType("image/*");
47            intent.putExtra("crop", "true");
48            formatIntent(intent);
49            startActivityForResult(intent, PHOTO_PICKED);
50        }
51    }
52
53    protected void formatIntent(Intent intent) {
54        int width = getWallpaperDesiredMinimumWidth();
55        int height = getWallpaperDesiredMinimumHeight();
56        intent.putExtra("outputX",         width);
57        intent.putExtra("outputY",         height);
58        intent.putExtra("aspectX",         width);
59        intent.putExtra("aspectY",         height);
60        intent.putExtra("scale",           true);
61        intent.putExtra("noFaceDetection", true);
62        intent.putExtra("setWallpaper",    true);
63    }
64
65    @Override
66    protected void onActivityResult(int requestCode, int resultCode,
67                                    Intent data) {
68        if ((requestCode == PHOTO_PICKED || requestCode == CROP_DONE)) {
69            setResult(resultCode);
70            finish();
71        }
72    }
73}
74