1 /* 2 * Copyright (C) 2014 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.example.android.musicservicedemo.browser; 18 19 import android.os.AsyncTask; 20 import android.util.Log; 21 22 import org.json.JSONException; 23 24 /** 25 * Asynchronous task to retrieve the music data using MusicProvider. 26 */ 27 public class MusicProviderTask extends AsyncTask<Void, Void, Void> { 28 29 private static final String TAG = "MusicProviderTask"; 30 31 MusicProvider mMusicProvider; 32 MusicProviderTaskListener mMusicProviderTaskListener; 33 34 /** 35 * Initialize the task with the provider to download the music data and the 36 * listener to be informed when the task is done. 37 * 38 * @param musicProvider 39 * @param listener 40 */ 41 public MusicProviderTask(MusicProvider musicProvider, 42 MusicProviderTaskListener listener) { 43 mMusicProvider = musicProvider; 44 mMusicProviderTaskListener = listener; 45 } 46 47 /* 48 * (non-Javadoc) 49 * @see android.os.AsyncTask#doInBackground(java.lang.Object[]) 50 */ 51 @Override 52 protected Void doInBackground(Void... arg0) { 53 try { 54 mMusicProvider.retreiveMedia(); 55 } catch (JSONException e) { 56 Log.e(TAG, "::doInBackground:", e); 57 } 58 return null; 59 } 60 61 /* 62 * (non-Javadoc) 63 * @see android.os.AsyncTask#onPostExecute(java.lang.Object) 64 */ 65 @Override 66 protected void onPostExecute(Void result) { 67 mMusicProviderTaskListener.onMusicProviderTaskCompleted(); 68 } 69 70 } 71