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.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.widget.Toast; 24 25 /** 26 * Asynchronous task for loading source photo screennail. 27 */ 28 public class LoadScreennailTask extends AsyncTask<Uri, Void, Bitmap> { 29 30 /** 31 * Callback for the completed asynchronous task. 32 */ 33 public interface Callback { 34 35 void onComplete(Bitmap bitmap); 36 } 37 38 // TODO: Support 1280x960 once OOM is fixed. 39 private static final int SCREENNAIL_WIDTH = 1024; 40 private static final int SCREENNAIL_HEIGHT = 768; 41 42 private final Context context; 43 private final Callback callback; 44 45 public LoadScreennailTask(Context context, Callback callback) { 46 this.context = context; 47 this.callback = callback; 48 } 49 50 /** 51 * The task should be executed with one given source photo uri. 52 */ 53 @Override 54 protected Bitmap doInBackground(Uri... params) { 55 if (params[0] == null) { 56 return null; 57 } 58 return new BitmapUtils(context).getBitmap(params[0], SCREENNAIL_WIDTH, SCREENNAIL_HEIGHT); 59 } 60 61 @Override 62 protected void onPostExecute(Bitmap bitmap) { 63 if (bitmap == null) { 64 Toast.makeText(context, R.string.loading_failure, Toast.LENGTH_SHORT).show(); 65 } 66 callback.onComplete(bitmap); 67 } 68 } 69