blob: 9ac85af93da45e83a19fb8076f97bfeb114969e4 [file] [log] [blame]
Yuli Huang6a12ad72011-09-12 22:25:30 +08001/*
2 * Copyright (C) 2010 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.gallery3d.photoeditor;
18
19import android.content.Context;
20import android.graphics.Bitmap;
21import android.net.Uri;
22import android.os.AsyncTask;
23import android.view.Gravity;
24import android.widget.Toast;
25
26import com.android.gallery3d.R;
27
28/**
29 * Asynchronous task for loading source photo screennail.
30 */
31public class LoadScreennailTask extends AsyncTask<Uri, Void, Bitmap> {
32
33 /**
34 * Callback for the completed asynchronous task.
35 */
36 public interface Callback {
37
Yuli Huangae70ae42011-10-01 02:05:06 +080038 void onComplete(Bitmap result);
Yuli Huang6a12ad72011-09-12 22:25:30 +080039 }
40
41 private static final int SCREENNAIL_WIDTH = 1280;
42 private static final int SCREENNAIL_HEIGHT = 960;
43
44 private final Context context;
45 private final Callback callback;
46
47 public LoadScreennailTask(Context context, Callback callback) {
48 this.context = context;
49 this.callback = callback;
50 }
51
52 /**
53 * The task should be executed with one given source photo uri.
54 */
55 @Override
56 protected Bitmap doInBackground(Uri... params) {
57 if (params[0] == null) {
58 return null;
59 }
60 return new BitmapUtils(context).getBitmap(params[0], SCREENNAIL_WIDTH, SCREENNAIL_HEIGHT);
61 }
62
63 @Override
Yuli Huangae70ae42011-10-01 02:05:06 +080064 protected void onPostExecute(Bitmap result) {
65 if (result == null) {
Yuli Huang6a12ad72011-09-12 22:25:30 +080066 Toast toast = Toast.makeText(context, R.string.loading_failure, Toast.LENGTH_SHORT);
67 toast.setGravity(Gravity.CENTER, 0, 0);
68 toast.show();
69 }
Yuli Huangae70ae42011-10-01 02:05:06 +080070 callback.onComplete(result);
Yuli Huang6a12ad72011-09-12 22:25:30 +080071 }
72}