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