1 package com.cooliris.media;
4 * Copyright (C) 2009 The Android Open Source Project
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import com.cooliris.media.PhotoAppWidgetProvider.PhotoDatabaseHelper;
21 import android.app.Activity;
22 import android.appwidget.AppWidgetManager;
23 import android.content.Intent;
24 import android.graphics.Bitmap;
25 import android.os.Bundle;
26 import android.widget.RemoteViews;
28 public class PhotoAppWidgetConfigure extends Activity {
30 @SuppressWarnings("unused")
31 private static final String TAG = "PhotoAppWidgetConfigure";
32 static final int REQUEST_GET_PHOTO = 2;
34 int mAppWidgetId = -1;
37 protected void onCreate(Bundle icicle) {
38 super.onCreate(icicle);
40 // Someone is requesting that we configure the given mAppWidgetId, which
41 // means we prompt the user to pick and crop a photo.
43 mAppWidgetId = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
44 if (mAppWidgetId == -1) {
45 setResult(Activity.RESULT_CANCELED);
49 // TODO: get these values from constants somewhere
50 // TODO: Adjust the PhotoFrame's image size to avoid on the fly scaling
51 Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
52 intent.setType("image/*");
53 intent.putExtra("crop", "true");
54 intent.putExtra("aspectX", 1);
55 intent.putExtra("aspectY", 1);
56 intent.putExtra("outputX", 192);
57 intent.putExtra("outputY", 192);
58 intent.putExtra("noFaceDetection", true);
59 intent.putExtra("return-data", true);
61 startActivityForResult(intent, REQUEST_GET_PHOTO);
65 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
66 if (resultCode == RESULT_OK && mAppWidgetId != -1) {
67 // Store the cropped photo in our database
68 Bitmap bitmap = (Bitmap) data.getParcelableExtra("data");
70 PhotoDatabaseHelper helper = new PhotoDatabaseHelper(this);
71 if (helper.setPhoto(mAppWidgetId, bitmap)) {
72 resultCode = Activity.RESULT_OK;
74 // Push newly updated widget to surface
75 RemoteViews views = PhotoAppWidgetProvider.buildUpdate(this, mAppWidgetId, helper);
76 AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
77 appWidgetManager.updateAppWidget(new int[] { mAppWidgetId }, views);
81 resultCode = Activity.RESULT_CANCELED;
84 // Make sure we pass back the original mAppWidgetId
85 Intent resultValue = new Intent();
86 resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
87 setResult(resultCode, resultValue);