summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2012-09-26 11:37:23 -0700
committerJohn Reck <jreck@google.com>2012-09-26 13:21:37 -0700
commita6b46808bda90361903eda14fdb4624ff2a03af4 (patch)
treed1b67502ec0300e30d239b60ef470ca1b5247f17 /src/com
parentdc4107678f6ae7ff017c662e94a7cf628940a47e (diff)
downloadandroid_packages_apps_Snap-a6b46808bda90361903eda14fdb4624ff2a03af4.tar.gz
android_packages_apps_Snap-a6b46808bda90361903eda14fdb4624ff2a03af4.tar.bz2
android_packages_apps_Snap-a6b46808bda90361903eda14fdb4624ff2a03af4.zip
Avoid unnecessary allocation
Bug: 7238418 Change-Id: Ic0a1ef0368368526401a53f02f680ef9d42ea310
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/gallery3d/app/PhotoPage.java26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java
index ea7e83982..29211ffee 100644
--- a/src/com/android/gallery3d/app/PhotoPage.java
+++ b/src/com/android/gallery3d/app/PhotoPage.java
@@ -26,6 +26,8 @@ import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.net.Uri;
import android.nfc.NfcAdapter;
+import android.nfc.NfcAdapter.CreateBeamUrisCallback;
+import android.nfc.NfcEvent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -163,7 +165,7 @@ public class PhotoPage extends ActivityState implements
private Path mDeletePath;
private boolean mDeleteIsFocus; // whether the deleted item was in focus
- private NfcAdapter mNfcAdapter;
+ private Uri[] mNfcPushUris = new Uri[1];
private final MyMenuVisibilityListener mMenuVisibilityListener =
new MyMenuVisibilityListener();
@@ -292,7 +294,7 @@ public class PhotoPage extends ActivityState implements
mSetPathString = data.getString(KEY_MEDIA_SET_PATH);
mOriginalSetPathString = mSetPathString;
- mNfcAdapter = NfcAdapter.getDefaultAdapter(mActivity.getAndroidContext());
+ setupNfcBeamPush();
String itemPathString = data.getString(KEY_MEDIA_ITEM_PATH);
Path itemPath = itemPathString != null ?
Path.fromString(data.getString(KEY_MEDIA_ITEM_PATH)) :
@@ -461,12 +463,24 @@ public class PhotoPage extends ActivityState implements
}
@TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN)
- private void setNfcBeamPushUris(Uri[] uris) {
- if (mNfcAdapter != null && ApiHelper.HAS_SET_BEAM_PUSH_URIS) {
- mNfcAdapter.setBeamPushUris(uris, mActivity);
+ private void setupNfcBeamPush() {
+ if (!ApiHelper.HAS_SET_BEAM_PUSH_URIS) return;
+
+ NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mActivity);
+ if (adapter != null) {
+ adapter.setBeamPushUrisCallback(new CreateBeamUrisCallback() {
+ @Override
+ public Uri[] createBeamUris(NfcEvent event) {
+ return mNfcPushUris;
+ }
+ }, mActivity);
}
}
+ private void setNfcBeamPushUri(Uri uri) {
+ mNfcPushUris[0] = uri;
+ }
+
private Intent createShareIntent(Path path) {
DataManager manager = mActivity.getDataManager();
int type = manager.getMediaType(path);
@@ -499,7 +513,7 @@ public class PhotoPage extends ActivityState implements
DataManager manager = mActivity.getDataManager();
Uri uri = manager.getContentUri(path);
mActionBar.setShareIntent(createShareIntent(path));
- setNfcBeamPushUris(new Uri[]{uri});
+ setNfcBeamPushUri(uri);
}
private void updateCurrentPhoto(MediaItem photo) {