diff options
Diffstat (limited to 'src/com/android/gallery3d/app/PhotoPage.java')
-rwxr-xr-x | src/com/android/gallery3d/app/PhotoPage.java | 179 |
1 files changed, 175 insertions, 4 deletions
diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index dd27f2689..b5a4d5640 100755 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -1,4 +1,4 @@ -/* +/** * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,10 +20,18 @@ import android.annotation.TargetApi; import android.app.ActionBar.OnMenuVisibilityListener; import android.app.Activity; import android.content.ActivityNotFoundException; +import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.content.res.Configuration; +import android.database.Cursor; +import android.drm.DrmManagerClient; +import android.drm.DrmStore.Action; +import android.drm.DrmStore.DrmDeliveryType; +import android.drm.DrmStore.RightsStatus; +import android.graphics.BitmapFactory; +import android.graphics.BitmapFactory.Options; import android.graphics.Rect; import android.media.MediaFile; import android.net.Uri; @@ -34,6 +42,8 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.SystemClock; +import android.provider.MediaStore; +import android.provider.MediaStore.Video.VideoColumns; import android.text.TextUtils; import android.view.Menu; import android.view.MenuItem; @@ -44,6 +54,7 @@ import android.widget.Toast; import com.android.gallery3d.R; import com.android.gallery3d.common.ApiHelper; +import com.android.gallery3d.common.Utils; import com.android.gallery3d.data.ComboAlbum; import com.android.gallery3d.data.DataManager; import com.android.gallery3d.data.FilterDeleteSet; @@ -76,6 +87,11 @@ import com.android.gallery3d.util.GalleryUtils; import com.android.gallery3d.util.UsageStatistics; import com.android.gallery3d.util.ViewGifImage; +import java.io.File; +import java.io.FileDescriptor; +import java.io.FileInputStream; +import java.io.IOException; + import java.util.ArrayList; import java.util.Locale; @@ -84,6 +100,8 @@ public abstract class PhotoPage extends ActivityState implements PhotoPageBottomControls.Delegate, GalleryActionBar.OnAlbumModeSelectedListener { private static final String TAG = "PhotoPage"; + public static final String BUY_LICENSE = "android.drmservice.intent.action.BUY_LICENSE"; + private static final int MSG_HIDE_BARS = 1; private static final int MSG_ON_FULL_SCREEN_CHANGED = 4; private static final int MSG_UPDATE_ACTION_BAR = 5; @@ -377,8 +395,9 @@ public abstract class PhotoPage extends ActivityState implements panoramaIntent = createSharePanoramaIntent(contentUri); } Intent shareIntent = createShareIntent(mCurrentPhoto); - - mActionBar.setShareIntents(panoramaIntent, shareIntent, PhotoPage.this); + if (shareIntent != null) { + mActionBar.setShareIntents(panoramaIntent, shareIntent, PhotoPage.this); + } setNfcBeamPushUri(contentUri); } break; @@ -571,6 +590,16 @@ public abstract class PhotoPage extends ActivityState implements PhotoPage.this); } } + MediaItem item = mModel.getMediaItem(0); + if (item != null + && item.getMediaType() == MediaObject.MEDIA_TYPE_IMAGE + && item.getConsumeRights() == true) { + Log.d(TAG, "onDestroy,consume rights = true"); + item.setConsumeRights(false); + Uri uri = item.getContentUri(); + Log.d(TAG, "onDestroy:uri=" + uri); + consumeRights(uri); + } } @Override @@ -610,6 +639,40 @@ public abstract class PhotoPage extends ActivityState implements }); } + private void consumeRights(Uri uri) { + Log.d(TAG, "consumeRights:uri=" + uri); + String filepath = null; + String scheme = uri.getScheme(); + if ("file".equals(scheme)) { + filepath = uri.getPath(); + } else { + Cursor cursor = null; + try { + cursor = mActivity.getContentResolver().query(uri, + new String[] {VideoColumns.DATA}, null, null, null); + if (cursor != null && cursor.moveToNext()) { + filepath = cursor.getString(0); + } + } catch (Throwable t) { + Log.w(TAG, "cannot get path from: " + uri); + } finally { + if (cursor != null) cursor.close(); + } + } + Options options = new Options(); + FileInputStream fis = null; + try { + fis = new FileInputStream(new File(filepath)); + FileDescriptor fd = fis.getFD(); + Log.d(TAG, "onLoadingFinished:calling decodeFileDescriptor with true"); + BitmapFactory.decodeFileDescriptor(fd, new Rect(), options, true); + } catch(IOException e) { + Log.w(TAG, "IOException"); + } finally { + Utils.closeSilently(fis); + } + } + @Override public void onPictureCenter(boolean isCamera) { isCamera = isCamera || (mHasCameraScreennailOrPlaceholder && mAppBridge == null); @@ -683,8 +746,42 @@ public abstract class PhotoPage extends ActivityState implements mNfcPushUris[0] = uri; } - private static Intent createShareIntent(MediaObject mediaObject) { + private Intent createShareIntent(MediaObject mediaObject) { int type = mediaObject.getMediaType(); + Uri uri = mediaObject.getContentUri(); + Log.d(TAG, "updateShareURI:uri:" + uri); + String filepath = null; + String scheme = uri.getScheme(); + if ("file".equals(scheme)) { + filepath = uri.getPath(); + } else { + Cursor cursor = null; + try { + cursor = mApplication.getContentResolver().query(uri, + new String[] {VideoColumns.DATA}, null, null, null); + if (cursor != null && cursor.moveToNext()) { + filepath = cursor.getString(0); + } + } catch (Throwable t) { + Log.w(TAG, "cannot get path from: " + uri); + } finally { + if (cursor != null) cursor.close(); + } + } + + if (filepath != null && filepath.endsWith(".dcf")) { + DrmManagerClient drmClient = new DrmManagerClient(mActivity.getAndroidContext()); + filepath = filepath.replace("/storage/emulated/0", "/storage/emulated/legacy"); + ContentValues values = drmClient.getMetadata(filepath); + int drmType = values.getAsInteger("DRM-TYPE"); + Log.d(TAG, "updateShareURI:drmType returned= " + Integer.toString(drmType) + + " for path= " + filepath); + if (drmType != DrmDeliveryType.SEPARATE_DELIVERY) { + return null; + } + if (drmClient != null) drmClient.release(); + } + return new Intent(Intent.ACTION_SEND) .setType(MenuExecutor.getMimeType(type)) .putExtra(Intent.EXTRA_STREAM, mediaObject.getContentUri()) @@ -1157,6 +1254,34 @@ public abstract class PhotoPage extends ActivityState implements mSelectionManager.toggle(path); mMenuExecutor.onMenuClicked(item, confirmMsg, mConfirmDialogListener); return true; + case R.id.action_drm_info: + Uri uri = manager.getContentUri(path); + Log.d(TAG, "executeuri:" + uri); + String filepath = null; + String scheme = uri.getScheme(); + if ("file".equals(scheme)) { + filepath = uri.getPath(); + } else { + Cursor cursor = null; + try { + cursor = mActivity.getAndroidContext().getContentResolver().query(uri, + new String[] {VideoColumns.DATA}, null, null, null); + if (cursor != null && cursor.moveToNext()) { + filepath = cursor.getString(0); + } + } catch (Throwable t) { + Log.w(TAG, "cannot get path from: " + uri); + } finally { + if (cursor != null) cursor.close(); + } + } + filepath = filepath.replace("/storage/emulated/0", "/storage/emulated/legacy"); + Intent drmintent = new Intent("android.drmservice.intent.action.SHOW_PROPERTIES"); + drmintent.putExtra("DRM_FILE_PATH", filepath); + drmintent.putExtra("DRM_TYPE", "OMAV1"); + Log.d(TAG,"-----filepath===" + path); + mActivity.getAndroidContext().sendBroadcast(drmintent); + return true; default : return false; } @@ -1292,6 +1417,41 @@ public abstract class PhotoPage extends ActivityState implements public void playVideo(Activity activity, Uri uri, String title) { try { + String scheme = uri.getScheme(); + Log.d(TAG, "playVideo:uri= " + uri); + String path = null; + if (scheme.equals("content")) { + Cursor c = activity.getContentResolver().query(uri, + new String[] { MediaStore.Images.ImageColumns.DATA }, null, null, null); + if (c != null && c.getCount() > 0) { + c.moveToFirst(); + path = c.getString(c.getColumnIndex(MediaStore.Images.ImageColumns.DATA)); + Log.d(TAG, "playVideo:path= " + path); + } + if (c != null) c.close(); + } else { + path = uri.getPath(); + } + if (path.endsWith(".dcf")) { + DrmManagerClient drmClient = new DrmManagerClient(activity); + path = path.replace("/storage/emulated/0", "/storage/emulated/legacy"); + + // This hack is added to work FL. It will remove after the sdcard permission issue solved + int status = drmClient.checkRightsStatus(path, Action.PLAY); + status = RightsStatus.RIGHTS_VALID; + + if (RightsStatus.RIGHTS_VALID != status) { + ContentValues values = drmClient.getMetadata(path); + String address = values.getAsString("Rights-Issuer"); + Log.d(TAG, "playVideo, address= " + address); + Intent intent = new Intent(BUY_LICENSE); + intent.putExtra("DRM_FILE_PATH", address); + activity.sendBroadcast(intent); + return; + } + if (drmClient != null) drmClient.release(); + } + Intent intent = new Intent(Intent.ACTION_VIEW) .setDataAndType(uri, "video/*") .putExtra(Intent.EXTRA_TITLE, title) @@ -1396,6 +1556,17 @@ public abstract class PhotoPage extends ActivityState implements @Override public void onCurrentImageUpdated() { + if (mSetPathString == null) { + MediaItem item = mModel.getMediaItem(0); + if (item.getMediaType() == MediaObject.MEDIA_TYPE_IMAGE + && item.getConsumeRights() == true) { + Log.d(TAG, "onCurrentImageUpdated,consume rights = true"); + item.setConsumeRights(false); + Uri uri = item.getContentUri(); + Log.d(TAG, "onCurrentImageUpdated:uri=" + uri); + consumeRights(uri); + } + } mActivity.getGLRoot().unfreeze(); } |