The Android Open Source Project | b64d345 | 2009-03-03 19:32:20 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.camera; |
| 18 | |
The Android Open Source Project | b64d345 | 2009-03-03 19:32:20 -0800 | [diff] [blame] | 19 | import android.app.Activity; |
The Android Open Source Project | b64d345 | 2009-03-03 19:32:20 -0800 | [diff] [blame] | 20 | import android.content.Intent; |
The Android Open Source Project | b64d345 | 2009-03-03 19:32:20 -0800 | [diff] [blame] | 21 | import android.net.Uri; |
| 22 | import android.os.Bundle; |
The Android Open Source Project | b64d345 | 2009-03-03 19:32:20 -0800 | [diff] [blame] | 23 | |
| 24 | /** |
Chih-Chung Chang | 0435bac | 2009-04-01 00:11:56 -0700 | [diff] [blame] | 25 | * Wallpaper picker for the camera application. This just redirects to the |
| 26 | * standard pick action. |
The Android Open Source Project | b64d345 | 2009-03-03 19:32:20 -0800 | [diff] [blame] | 27 | */ |
| 28 | public class Wallpaper extends Activity { |
Owen Lin | 71d56e2 | 2009-09-23 22:27:04 +0800 | [diff] [blame] | 29 | @SuppressWarnings("unused") |
Chih-Chung Chang | c830ac2 | 2009-08-24 16:42:21 +0800 | [diff] [blame] | 30 | private static final String TAG = "Wallpaper"; |
| 31 | private static final int PHOTO_PICKED = 1; |
| 32 | private static final int CROP_DONE = 2; |
The Android Open Source Project | b64d345 | 2009-03-03 19:32:20 -0800 | [diff] [blame] | 33 | |
| 34 | @Override |
| 35 | protected void onCreate(Bundle icicle) { |
| 36 | super.onCreate(icicle); |
The Android Open Source Project | b64d345 | 2009-03-03 19:32:20 -0800 | [diff] [blame] | 37 | |
The Android Open Source Project | b64d345 | 2009-03-03 19:32:20 -0800 | [diff] [blame] | 38 | Uri imageToUse = getIntent().getData(); |
| 39 | if (imageToUse != null) { |
| 40 | Intent intent = new Intent(); |
Chih-Chung Chang | 0435bac | 2009-04-01 00:11:56 -0700 | [diff] [blame] | 41 | intent.setClassName("com.android.camera", |
| 42 | "com.android.camera.CropImage"); |
The Android Open Source Project | b64d345 | 2009-03-03 19:32:20 -0800 | [diff] [blame] | 43 | intent.setData(imageToUse); |
| 44 | formatIntent(intent); |
| 45 | startActivityForResult(intent, CROP_DONE); |
| 46 | } else { |
| 47 | Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null); |
| 48 | intent.setType("image/*"); |
| 49 | intent.putExtra("crop", "true"); |
| 50 | formatIntent(intent); |
| 51 | startActivityForResult(intent, PHOTO_PICKED); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | protected void formatIntent(Intent intent) { |
The Android Open Source Project | b64d345 | 2009-03-03 19:32:20 -0800 | [diff] [blame] | 56 | int width = getWallpaperDesiredMinimumWidth(); |
| 57 | int height = getWallpaperDesiredMinimumHeight(); |
| 58 | intent.putExtra("outputX", width); |
| 59 | intent.putExtra("outputY", height); |
| 60 | intent.putExtra("aspectX", width); |
| 61 | intent.putExtra("aspectY", height); |
| 62 | intent.putExtra("scale", true); |
| 63 | intent.putExtra("noFaceDetection", true); |
Chih-Chung Chang | c830ac2 | 2009-08-24 16:42:21 +0800 | [diff] [blame] | 64 | intent.putExtra("setWallpaper", true); |
The Android Open Source Project | b64d345 | 2009-03-03 19:32:20 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Override |
Chih-Chung Chang | 0435bac | 2009-04-01 00:11:56 -0700 | [diff] [blame] | 68 | protected void onActivityResult(int requestCode, int resultCode, |
| 69 | Intent data) { |
Chih-Chung Chang | c830ac2 | 2009-08-24 16:42:21 +0800 | [diff] [blame] | 70 | if ((requestCode == PHOTO_PICKED || requestCode == CROP_DONE)) { |
| 71 | setResult(resultCode); |
The Android Open Source Project | b64d345 | 2009-03-03 19:32:20 -0800 | [diff] [blame] | 72 | finish(); |
| 73 | } |
| 74 | } |
| 75 | } |