1 /* 2 * Copyright (C) 2008 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.music; 18 19 import android.app.Activity; 20 import android.database.Cursor; 21 import android.media.AudioManager; 22 import android.os.Bundle; 23 import android.os.Environment; 24 import android.os.Handler; 25 import android.os.Message; 26 import android.provider.MediaStore; 27 import android.view.Window; 28 import android.view.WindowManager; 29 30 public class ScanningProgress extends Activity 31 { 32 private final static int CHECK = 0; 33 private Handler mHandler = new Handler() { 34 @Override 35 public void handleMessage(Message msg) 36 { 37 if (msg.what == CHECK) { 38 String status = Environment.getExternalStorageState(); 39 if (!status.equals(Environment.MEDIA_MOUNTED)) { 40 // If the card suddenly got unmounted again, there's 41 // really no need to keep waiting for the media scanner. 42 finish(); 43 return; 44 } 45 Cursor c = MusicUtils.query(ScanningProgress.this, 46 MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, 47 null, null, null, null); 48 if (c != null) { 49 // The external media database is now ready for querying 50 // (though it may still be in the process of being filled). 51 c.close(); 52 setResult(RESULT_OK); 53 finish(); 54 return; 55 } 56 Message next = obtainMessage(CHECK); 57 sendMessageDelayed(next, 3000); 58 } 59 } 60 }; 61 62 @Override onCreate(Bundle icicle)63 public void onCreate(Bundle icicle) { 64 super.onCreate(icicle); 65 setVolumeControlStream(AudioManager.STREAM_MUSIC); 66 67 requestWindowFeature(Window.FEATURE_NO_TITLE); 68 if (android.os.Environment.isExternalStorageRemovable()) { 69 setContentView(R.layout.scanning); 70 } else { 71 setContentView(R.layout.scanning_nosdcard); 72 } 73 getWindow().setLayout(WindowManager.LayoutParams.WRAP_CONTENT, 74 WindowManager.LayoutParams.WRAP_CONTENT); 75 setResult(RESULT_CANCELED); 76 77 Message msg = mHandler.obtainMessage(CHECK); 78 mHandler.sendMessageDelayed(msg, 1000); 79 } 80 81 @Override onDestroy()82 public void onDestroy() { 83 mHandler.removeMessages(CHECK); 84 super.onDestroy(); 85 } 86 } 87