• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.gallery3d.photoeditor;
18 
19 import android.content.Context;
20 import android.graphics.Bitmap;
21 import android.net.Uri;
22 import android.os.AsyncTask;
23 import android.view.Gravity;
24 import android.widget.Toast;
25 
26 import com.android.gallery3d.R;
27 
28 /**
29  * Asynchronous task for loading source photo screennail.
30  */
31 public class LoadScreennailTask extends AsyncTask<Uri, Void, Bitmap> {
32 
33     /**
34      * Callback for the completed asynchronous task.
35      */
36     public interface Callback {
37 
onComplete(Bitmap result)38         void onComplete(Bitmap result);
39     }
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 
LoadScreennailTask(Context context, Callback callback)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
doInBackground(Uri... params)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
onPostExecute(Bitmap result)64     protected void onPostExecute(Bitmap result) {
65         if (result == null) {
66             Toast toast = Toast.makeText(context, R.string.loading_failure, Toast.LENGTH_SHORT);
67             toast.setGravity(Gravity.CENTER, 0, 0);
68             toast.show();
69         }
70         callback.onComplete(result);
71     }
72 }
73