summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinux Build Service Account <lnxbuild@localhost>2016-04-21 20:05:51 -0700
committerLinux Build Service Account <lnxbuild@localhost>2016-04-21 20:05:51 -0700
commitd916b9d2a556e522b14b74592c3d9cb57a515259 (patch)
tree9b977a6ce90a5a33e540107e048a68c868c60bef
parent9fb4a9fa866b9711990a89cb39916caeeb65910c (diff)
parentab423589e334f3bbc99020f2ede83383479aa16e (diff)
downloadandroid_packages_apps_Gallery2-d916b9d2a556e522b14b74592c3d9cb57a515259.tar.gz
android_packages_apps_Gallery2-d916b9d2a556e522b14b74592c3d9cb57a515259.tar.bz2
android_packages_apps_Gallery2-d916b9d2a556e522b14b74592c3d9cb57a515259.zip
Promotion of android_ui.lnx.1.2.c1-00011.
CRs Change ID Subject -------------------------------------------------------------------------------------------------------------- 980372 I7ce509aec6859c8117aebc01c7a3c828221aafa3 Gallery: fix error when license expires 981663 I11f0632ed96958a74b6aa2cdd9c2f1d88c99e94e Gallery2: fix photo widget has not sync after delete the 991985 I1eaa74fb62c5f4d205b82854bc75d442bf59fee0 Gallery: fix crash after deletion Change-Id: Ia965d926c93f0baf0925e994ebd9a41d7ab00958 CRs-Fixed: 980372, 991985, 981663
-rwxr-xr-xres/layout/photo_frame.xml22
-rw-r--r--src/com/android/gallery3d/filtershow/cache/ImageLoader.java3
-rw-r--r--src/com/android/gallery3d/gadget/PhotoAppWidgetProvider.java67
-rw-r--r--src/com/android/gallery3d/ui/MenuExecutor.java37
-rw-r--r--src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java2
5 files changed, 113 insertions, 18 deletions
diff --git a/res/layout/photo_frame.xml b/res/layout/photo_frame.xml
index 63faf539d..ede942f6b 100755
--- a/res/layout/photo_frame.xml
+++ b/res/layout/photo_frame.xml
@@ -21,6 +21,28 @@
android:paddingBottom="23dp"
android:paddingStart="12dp"
android:paddingEnd="12dp">
+
+ <RelativeLayout
+ android:id="@+id/appwidget_empty_photo"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:visibility="gone">
+
+ <FrameLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerInParent="true"
+ android:background="@drawable/appwidget_photo_border">
+
+ <TextView
+ android:id="@id/appwidget_photo_item"
+ android:layout_width="@dimen/stack_photo_width"
+ android:layout_height="@dimen/stack_photo_height"
+ android:gravity="center"
+ android:text="@string/appwidget_empty_text"
+ android:textColor="@android:color/black" />
+ </FrameLayout>
+ </RelativeLayout>
<ImageView android:id="@+id/photo"
android:layout_gravity="center"
android:layout_width="wrap_content"
diff --git a/src/com/android/gallery3d/filtershow/cache/ImageLoader.java b/src/com/android/gallery3d/filtershow/cache/ImageLoader.java
index ea559e569..d8560312c 100644
--- a/src/com/android/gallery3d/filtershow/cache/ImageLoader.java
+++ b/src/com/android/gallery3d/filtershow/cache/ImageLoader.java
@@ -88,8 +88,7 @@ public final class ImageLoader {
return null;
}
int index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
- cursor.moveToFirst();
- return cursor.getString(index);
+ return cursor.moveToFirst() ? cursor.getString(index) : null;
}
/**
diff --git a/src/com/android/gallery3d/gadget/PhotoAppWidgetProvider.java b/src/com/android/gallery3d/gadget/PhotoAppWidgetProvider.java
index 58466bf01..91e5cbeb6 100644
--- a/src/com/android/gallery3d/gadget/PhotoAppWidgetProvider.java
+++ b/src/com/android/gallery3d/gadget/PhotoAppWidgetProvider.java
@@ -22,10 +22,14 @@ import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
+import android.database.ContentObserver;
+import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
+import android.os.Handler;
import android.util.Log;
+import android.view.View;
import android.widget.RemoteViews;
import com.android.gallery3d.R;
@@ -33,9 +37,14 @@ import com.android.gallery3d.common.ApiHelper;
import com.android.gallery3d.gadget.WidgetDatabaseHelper.Entry;
import com.android.gallery3d.onetimeinitializer.GalleryWidgetMigrator;
+import java.util.ArrayList;
+import java.util.List;
+
public class PhotoAppWidgetProvider extends AppWidgetProvider {
private static final String TAG = "WidgetProvider";
+ private static List<PhotoUriContentObserver> mPhotoUriObservers = new ArrayList<>();
+ private static Handler mContentObserverHandler = new Handler();
static RemoteViews buildWidget(Context context, int id, Entry entry) {
@@ -44,6 +53,12 @@ public class PhotoAppWidgetProvider extends AppWidgetProvider {
case WidgetDatabaseHelper.TYPE_SHUFFLE:
return buildStackWidget(context, id, entry);
case WidgetDatabaseHelper.TYPE_SINGLE_PHOTO:
+ PhotoUriContentObserver photoUriObserver =
+ new PhotoUriContentObserver(context, mContentObserverHandler, entry, id);
+ photoUriObserver.setTag(id);
+ mPhotoUriObservers.add(photoUriObserver);
+ context.getContentResolver().registerContentObserver(Uri.parse(entry.imageUri),
+ false, photoUriObserver);
return buildFrameWidget(context, id, entry);
}
throw new RuntimeException("invalid type - " + entry.type);
@@ -132,8 +147,60 @@ public class PhotoAppWidgetProvider extends AppWidgetProvider {
// Clean deleted photos out of our database
WidgetDatabaseHelper helper = new WidgetDatabaseHelper(context);
for (int appWidgetId : appWidgetIds) {
+ PhotoUriContentObserver contentObserver = getContentObserver(appWidgetId);
+ if (contentObserver != null) {
+ context.getContentResolver().unregisterContentObserver(contentObserver);
+ mPhotoUriObservers.remove(contentObserver);
+ }
helper.deleteEntry(appWidgetId);
}
helper.close();
}
+
+ private PhotoUriContentObserver getContentObserver(int appWidgetId) {
+ for (PhotoUriContentObserver contentObserver : mPhotoUriObservers) {
+ if (appWidgetId == contentObserver.getTag()) {
+ return contentObserver;
+ }
+ }
+ return null;
+ }
+
+ private static class PhotoUriContentObserver extends ContentObserver {
+ private int mId;
+ private int mTag;
+ private Context mContext;
+ private Entry mEntry;
+
+ public void setTag(int tag) {
+ this.mTag = tag;
+ }
+
+ public int getTag() {
+ return mTag;
+ }
+
+ public PhotoUriContentObserver(Context context, Handler handler, Entry entry, int id) {
+ super(handler);
+ mContext = context;
+ mEntry = entry;
+ mId = id;
+ }
+
+ public void onChange(boolean selfChange) {
+ super.onChange(selfChange);
+ Uri uri = Uri.parse(mEntry.imageUri);
+ Cursor cursor = mContext.getContentResolver().query(uri, null, null,
+ null, "_id ASC LIMIT 1");
+ if (cursor != null) {
+ if (cursor.getCount() == 0) {
+ RemoteViews views = buildFrameWidget(mContext, mId, mEntry);
+ views.setViewVisibility(R.id.appwidget_empty_photo, View.VISIBLE);
+ views.setViewVisibility(R.id.photo, View.GONE);
+ AppWidgetManager.getInstance(mContext).updateAppWidget(mId, views);
+ }
+ cursor.close();
+ }
+ }
+ }
}
diff --git a/src/com/android/gallery3d/ui/MenuExecutor.java b/src/com/android/gallery3d/ui/MenuExecutor.java
index c4636cb38..e65649bcf 100644
--- a/src/com/android/gallery3d/ui/MenuExecutor.java
+++ b/src/com/android/gallery3d/ui/MenuExecutor.java
@@ -216,13 +216,16 @@ public class MenuExecutor {
private Path getSingleSelectedPath() {
ArrayList<Path> ids = mSelectionManager.getSelected(true);
- Utils.assertTrue(ids.size() == 1);
- return ids.get(0);
+ if (ids.size() != 1)
+ return null;
+ return ids.get(0);
}
private Intent getIntentBySingleSelectedPath(String action) {
DataManager manager = mActivity.getDataManager();
Path path = getSingleSelectedPath();
+ if (path == null)
+ return null;
String mimeType = getMimeType(manager.getMediaType(path));
return new Intent(action).setDataAndType(manager.getContentUri(path), mimeType);
}
@@ -248,26 +251,30 @@ public class MenuExecutor {
return;
}*/
case R.id.action_edit: {
- Intent intent = getIntentBySingleSelectedPath(Intent.ACTION_EDIT)
- .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- ((Activity) mActivity).startActivity(Intent.createChooser(intent, null));
+ Intent intent = getIntentBySingleSelectedPath(Intent.ACTION_EDIT);
+ if (intent != null) {
+ intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ ((Activity) mActivity).startActivity(Intent.createChooser(intent, null));
+ }
return;
}
case R.id.action_setas: {
- Intent intent = getIntentBySingleSelectedPath(Intent.ACTION_ATTACH_DATA)
- .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- intent.putExtra("mimeType", intent.getType());
-
- // DRM files can be set as wallpaper only. Don't show other options
- // to set as.
- Uri uri = intent.getData();
+ Intent intent = getIntentBySingleSelectedPath(Intent.ACTION_ATTACH_DATA);
+ if (intent != null) {
+ intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ intent.putExtra("mimeType", intent.getType());
+
+ // DRM files can be set as wallpaper only. Don't show other options
+ // to set as.
+ Uri uri = intent.getData();
// if (DrmHelper.isDrmFile(DrmHelper.getFilePath(mActivity, uri))) {
// intent.setPackage("com.android.gallery3d");
// }
- Activity activity = mActivity;
- activity.startActivity(Intent.createChooser(
- intent, activity.getString(R.string.set_as)));
+ Activity activity = mActivity;
+ activity.startActivity(Intent.createChooser(
+ intent, activity.getString(R.string.set_as)));
+ }
return;
}
case R.id.action_delete:
diff --git a/src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java b/src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java
index aae691d55..1dd429d5a 100644
--- a/src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java
+++ b/src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java
@@ -461,7 +461,7 @@ public class CodeauroraVideoView extends SurfaceView implements MediaPlayerContr
private void openVideo() {
clearVideoInfo();
- if (mUri == null || mSurfaceHolder == null) {
+ if (mUri == null || mSurfaceHolder == null || mTargetState == STATE_ERROR) {
// not ready for playback just yet, will try again later
return;
}