1792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project/* 2792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * Copyright (C) 2008 The Android Open Source Project 3792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * 4792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 5792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * you may not use this file except in compliance with the License. 6792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * You may obtain a copy of the License at 7792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * 8792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 9792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * 10792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * Unless required by applicable law or agreed to in writing, software 11792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 12792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * See the License for the specific language governing permissions and 14792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project * limitations under the License. 15792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project */ 16792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project 17792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectpackage com.android.music; 18792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project 19792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectimport android.app.Activity; 20792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectimport android.database.Cursor; 21792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectimport android.media.AudioManager; 22792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectimport android.os.Bundle; 23792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectimport android.os.Environment; 24792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectimport android.os.Handler; 25792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectimport android.os.Message; 26792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectimport android.provider.MediaStore; 27792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectimport android.view.Window; 28792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectimport android.view.WindowManager; 29792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project 30792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Projectpublic class ScanningProgress extends Activity 31792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project{ 32792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project private final static int CHECK = 0; 33792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project private Handler mHandler = new Handler() { 34792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project @Override 35792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project public void handleMessage(Message msg) 36792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project { 37792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project if (msg.what == CHECK) { 38792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project String status = Environment.getExternalStorageState(); 39792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project if (!status.equals(Environment.MEDIA_MOUNTED)) { 40792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project // If the card suddenly got unmounted again, there's 41792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project // really no need to keep waiting for the media scanner. 42792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project finish(); 43792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project return; 44792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project } 45792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project Cursor c = MusicUtils.query(ScanningProgress.this, 46792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, 47792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project null, null, null, null); 48792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project if (c != null) { 49792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project // The external media database is now ready for querying 50792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project // (though it may still be in the process of being filled). 51792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project c.close(); 52792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project setResult(RESULT_OK); 53792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project finish(); 54792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project return; 55792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project } 56792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project Message next = obtainMessage(CHECK); 57792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project sendMessageDelayed(next, 3000); 58792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project } 59792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project } 60792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project }; 61792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project 62792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project @Override 63792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project public void onCreate(Bundle icicle) { 64792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project super.onCreate(icicle); 65792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project setVolumeControlStream(AudioManager.STREAM_MUSIC); 66792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project 67792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project requestWindowFeature(Window.FEATURE_NO_TITLE); 68792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project setContentView(R.layout.scanning); 69792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project getWindow().setLayout(WindowManager.LayoutParams.WRAP_CONTENT, 70792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project WindowManager.LayoutParams.WRAP_CONTENT); 71792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project setResult(RESULT_CANCELED); 72792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project 73792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project Message msg = mHandler.obtainMessage(CHECK); 74792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project mHandler.sendMessageDelayed(msg, 1000); 75792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project } 76792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project 77792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project @Override 78792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project public void onDestroy() { 79792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project mHandler.removeMessages(CHECK); 80792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project super.onDestroy(); 81792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project } 82792a2206a4f05f6bd13fce902d3663892d2947afThe Android Open Source Project} 83