Wallpaper.java revision af7f98026f1564d7a4f9c8084bba763ec1698e04
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.app.Activity; 20import android.content.Intent; 21import android.net.Uri; 22import android.os.Bundle; 23 24/** 25 * Wallpaper picker for the camera application. This just redirects to the 26 * standard pick action. 27 */ 28public class Wallpaper extends Activity { 29 @SuppressWarnings("unused") 30 private static final String TAG = "Wallpaper"; 31 private static final int PHOTO_PICKED = 1; 32 private static final int CROP_DONE = 2; 33 34 @Override 35 protected void onCreate(Bundle icicle) { 36 super.onCreate(icicle); 37 38 Uri imageToUse = getIntent().getData(); 39 if (imageToUse != null) { 40 Intent intent = new Intent(); 41 intent.setClassName("com.android.camera", 42 "com.android.camera.CropImage"); 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) { 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); 64 intent.putExtra("setWallpaper", true); 65 } 66 67 @Override 68 protected void onActivityResult(int requestCode, int resultCode, 69 Intent data) { 70 if ((requestCode == PHOTO_PICKED || requestCode == CROP_DONE)) { 71 setResult(resultCode); 72 finish(); 73 } 74 } 75} 76