From 9ca9c3705c2176f1da98c573a9d765fc65b840ce Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Tue, 17 Apr 2012 16:21:12 +0800 Subject: Fix NPE in onContentDirty. onContentDirty is suppose to be called in Main thread. Change-Id: Ic6a0fba8abd8a3e17d400bcfc5b82d272b07bc41 --- src/com/android/gallery3d/data/LocalAlbumSet.java | 11 ++++++++++- src/com/android/gallery3d/data/MtpDeviceSet.java | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/com/android/gallery3d/data/LocalAlbumSet.java b/src/com/android/gallery3d/data/LocalAlbumSet.java index 47e3bd431..dbb518985 100644 --- a/src/com/android/gallery3d/data/LocalAlbumSet.java +++ b/src/com/android/gallery3d/data/LocalAlbumSet.java @@ -19,6 +19,7 @@ package com.android.gallery3d.data; import android.content.ContentResolver; import android.database.Cursor; import android.net.Uri; +import android.os.Handler; import android.provider.MediaStore.Files; import android.provider.MediaStore.Files.FileColumns; import android.provider.MediaStore.Images; @@ -98,12 +99,15 @@ public class LocalAlbumSet extends MediaSet private final ChangeNotifier mNotifierImage; private final ChangeNotifier mNotifierVideo; private final String mName; + private final Handler mHandler; + private Future> mLoadTask; private ArrayList mLoadBuffer; public LocalAlbumSet(Path path, GalleryApp application) { super(path, nextVersionNumber()); mApplication = application; + mHandler = new Handler(application.getMainLooper()); mType = getTypeFromPath(path); mNotifierImage = new ChangeNotifier(this, mWatchUriImage, application); mNotifierVideo = new ChangeNotifier(this, mWatchUriVideo, application); @@ -282,7 +286,12 @@ public class LocalAlbumSet extends MediaSet if (mLoadTask != future) return; // ignore, wait for the latest task mLoadBuffer = future.get(); if (mLoadBuffer == null) mLoadBuffer = new ArrayList(); - notifyContentChanged(); + mHandler.post(new Runnable() { + @Override + public void run() { + notifyContentChanged(); + } + }); } // For debug only. Fake there is a ContentObserver.onChange() event. diff --git a/src/com/android/gallery3d/data/MtpDeviceSet.java b/src/com/android/gallery3d/data/MtpDeviceSet.java index 46cc0fc68..6dcb0d2e6 100644 --- a/src/com/android/gallery3d/data/MtpDeviceSet.java +++ b/src/com/android/gallery3d/data/MtpDeviceSet.java @@ -18,6 +18,7 @@ package com.android.gallery3d.data; import android.mtp.MtpDeviceInfo; import android.net.Uri; +import android.os.Handler; import android.util.Log; import com.android.gallery3d.R; @@ -41,6 +42,7 @@ public class MtpDeviceSet extends MediaSet private final ChangeNotifier mNotifier; private final MtpContext mMtpContext; private final String mName; + private final Handler mHandler; private Future> mLoadTask; private ArrayList mDeviceSet = new ArrayList(); @@ -52,6 +54,7 @@ public class MtpDeviceSet extends MediaSet mNotifier = new ChangeNotifier(this, Uri.parse("mtp://"), application); mMtpContext = mtpContext; mName = application.getResources().getString(R.string.set_label_mtp_devices); + mHandler = new Handler(mApplication.getMainLooper()); } private class DevicesLoader implements Job> { @@ -131,6 +134,12 @@ public class MtpDeviceSet extends MediaSet if (future != mLoadTask) return; mLoadBuffer = future.get(); if (mLoadBuffer == null) mLoadBuffer = new ArrayList(); - notifyContentChanged(); + + mHandler.post(new Runnable() { + @Override + public void run() { + notifyContentChanged(); + } + }); } } -- cgit v1.2.3