OSDN Git Service

android-2.1_r1 snapshot
[android-x86/packages-apps-Gallery2.git] / src / com / cooliris / media / PhotoAppWidgetConfigure.java
1 package com.cooliris.media;
2
3 /*
4  * Copyright (C) 2009 The Android Open Source Project
5  *
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19 import com.cooliris.media.PhotoAppWidgetProvider.PhotoDatabaseHelper;
20
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;
27
28 public class PhotoAppWidgetConfigure extends Activity {
29
30     @SuppressWarnings("unused")
31     private static final String TAG = "PhotoAppWidgetConfigure";
32     static final int REQUEST_GET_PHOTO = 2;
33
34     int mAppWidgetId = -1;
35
36     @Override
37     protected void onCreate(Bundle icicle) {
38         super.onCreate(icicle);
39
40         // Someone is requesting that we configure the given mAppWidgetId, which
41         // means we prompt the user to pick and crop a photo.
42
43         mAppWidgetId = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
44         if (mAppWidgetId == -1) {
45             setResult(Activity.RESULT_CANCELED);
46             finish();
47         }
48
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);
60
61         startActivityForResult(intent, REQUEST_GET_PHOTO);
62     }
63
64     @Override
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");
69
70             PhotoDatabaseHelper helper = new PhotoDatabaseHelper(this);
71             if (helper.setPhoto(mAppWidgetId, bitmap)) {
72                 resultCode = Activity.RESULT_OK;
73
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);
78             }
79             helper.close();
80         } else {
81             resultCode = Activity.RESULT_CANCELED;
82         }
83
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);
88         finish();
89     }
90
91 }