OSDN Git Service

Updates to 3D gallery. Build 1203.
[android-x86/packages-apps-Gallery2.git] / src / com / cooliris / cache / BootReceiver.java
1 package com.cooliris.cache;
2
3 import com.cooliris.media.LocalDataSource;
4 import com.cooliris.media.SingleDataSource;
5
6 import android.content.BroadcastReceiver;
7 import android.content.ContentResolver;
8 import android.content.Context;
9 import android.content.Intent;
10 import android.database.ContentObserver;
11 import android.net.Uri;
12 import android.os.Handler;
13 import android.provider.MediaStore.Images;
14 import android.provider.MediaStore.Video;
15 import android.util.Log;
16
17 public class BootReceiver extends BroadcastReceiver {
18     private static final String TAG = "BootReceiver";
19     private final Handler mHandler = new Handler();
20
21     @Override
22     public void onReceive(final Context context, Intent intent) {
23         final String action = intent.getAction();
24         Log.i(TAG, "Got intent with action " + action);
25         if (Intent.ACTION_MEDIA_SCANNER_FINISHED.equals(action)) {
26             CacheService.markDirty(context);
27             CacheService.startCache(context, true);
28         } else if (Intent.ACTION_MEDIA_MOUNTED.equals(action)) {
29             // Do nothing, wait for the mediascanner to be done after mounting.
30             ;
31         } else if (action.equals(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE)) {
32             final Uri fileUri = intent.getData();
33             final long bucketId = SingleDataSource.parseBucketIdFromFileUri(fileUri.toString());
34             if (!CacheService.isPresentInCache(bucketId)) {
35                 CacheService.markDirty(context);
36             }
37         } else if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
38             // We add special listeners for the MediaProvider
39             final Handler handler = mHandler;
40             final ContentObserver localObserver = new ContentObserver(handler) {
41                 public void onChange(boolean selfChange) {
42                     if (!LocalDataSource.sObserverActive) {
43                         CacheService.senseDirty(context, null);
44                     }
45                 }
46             };
47             // Start listening perpetually.
48             Uri uriImages = Images.Media.EXTERNAL_CONTENT_URI;
49             Uri uriVideos = Video.Media.EXTERNAL_CONTENT_URI;
50             ContentResolver cr = context.getContentResolver();
51             cr.registerContentObserver(uriImages, false, localObserver);
52             cr.registerContentObserver(uriVideos, false, localObserver);
53         }
54     }
55 }