Gallery2 : Drm lock icon added on Photo widget for drm content

CRs-fixed : 804180

Change-Id: I11c969f0156dba6db75c924a568eaa0733395208
diff --git a/res/layout/appwidget_drm_empty_item.xml b/res/layout/appwidget_drm_empty_item.xml
new file mode 100644
index 0000000..8261dbe
--- /dev/null
+++ b/res/layout/appwidget_drm_empty_item.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (c) 2015, The Linux Foundation. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+    * Neither the name of The Linux Foundation nor the names of its
+      contributors may be used to endorse or promote products derived
+      from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+-->
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:background="@drawable/appwidget_photo_border" >
+
+    <RelativeLayout
+        android:layout_width="@dimen/stack_photo_width"
+        android:layout_height="@dimen/stack_photo_height"
+        android:background="@android:color/darker_gray" >
+
+        <ImageView
+            android:id="@+id/drm_icon"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_centerInParent="true"
+            android:background="@drawable/drm_image" />
+    </RelativeLayout>
+s
+</FrameLayout>
\ No newline at end of file
diff --git a/src/com/android/gallery3d/gadget/PhotoAppWidgetProvider.java b/src/com/android/gallery3d/gadget/PhotoAppWidgetProvider.java
index 1dfbe3f..58466bf 100644
--- a/src/com/android/gallery3d/gadget/PhotoAppWidgetProvider.java
+++ b/src/com/android/gallery3d/gadget/PhotoAppWidgetProvider.java
@@ -106,7 +106,7 @@
                 context.getPackageName(), R.layout.photo_frame);
         try {
             byte[] data = entry.imageData;
-            Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, false);
+            Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
             views.setImageViewBitmap(R.id.photo, bitmap);
         } catch (Throwable t) {
             Log.w(TAG, "cannot load widget image: " + appWidgetId, t);
diff --git a/src/com/android/gallery3d/gadget/WidgetClickHandler.java b/src/com/android/gallery3d/gadget/WidgetClickHandler.java
index 642f3d6..e5b0a37 100644
--- a/src/com/android/gallery3d/gadget/WidgetClickHandler.java
+++ b/src/com/android/gallery3d/gadget/WidgetClickHandler.java
@@ -57,8 +57,6 @@
         Intent intent;
         if (isValidDataUri(uri)) {
             intent = new Intent(Intent.ACTION_VIEW, uri);
-            intent.putExtra("WidgetClick", true);
-
             // Used for checking whether it is from widget
             intent.putExtra(PhotoPage.KEY_IS_FROM_WIDGET, true);
             if (tediousBack) {
diff --git a/src/com/android/gallery3d/gadget/WidgetService.java b/src/com/android/gallery3d/gadget/WidgetService.java
index 8544337..7b16f8b 100644
--- a/src/com/android/gallery3d/gadget/WidgetService.java
+++ b/src/com/android/gallery3d/gadget/WidgetService.java
@@ -19,8 +19,10 @@
 import android.annotation.TargetApi;
 import android.appwidget.AppWidgetManager;
 import android.content.Intent;
+import android.drm.DrmHelper;
 import android.graphics.Bitmap;
 import android.net.Uri;
+import android.view.View;
 import android.widget.RemoteViews;
 import android.widget.RemoteViewsService;
 
@@ -121,7 +123,31 @@
                 return null;
             }
             Bitmap bitmap = mSource.getImage(position);
-            if (bitmap == null) return getLoadingView();
+
+            boolean isDrm = false;
+            if (DrmHelper.isDrmFile(DrmHelper.getFilePath(
+                    mApp.getAndroidContext(), mSource.getContentUri(position)))) {
+                isDrm = true;
+            }
+
+            if (isDrm) {
+                if (bitmap == null) {
+                    RemoteViews rv = new RemoteViews(mApp.getAndroidContext()
+                            .getPackageName(),
+                            R.layout.appwidget_drm_empty_item);
+                    rv.setOnClickFillInIntent(
+                            R.id.appwidget_photo_item,
+                            new Intent().setFlags(
+                                    Intent.FLAG_ACTIVITY_CLEAR_TOP).setData(
+                                    mSource.getContentUri(position)));
+                    return rv;
+                }
+            } else {
+                if (bitmap == null) {
+                    return getLoadingView();
+                }
+            }
+
             RemoteViews views = new RemoteViews(
                     mApp.getAndroidContext().getPackageName(),
                     R.layout.appwidget_photo_item);
@@ -129,6 +155,13 @@
             views.setOnClickFillInIntent(R.id.appwidget_photo_item, new Intent()
                     .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
                     .setData(mSource.getContentUri(position)));
+
+            if (isDrm) {
+                views.setViewVisibility(R.id.drm_icon, View.VISIBLE);
+            } else {
+                views.setViewVisibility(R.id.drm_icon, View.GONE);
+            }
+
             return views;
         }