Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1298)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java

Issue 2338683002: ShareHelper: Call onCancel when dismissed, in Kit Kat and earlier. (Closed)
Patch Set: Rebase. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java
index 13f97ae8dd5db30f0aa66bf4b0bac2d93636a37f..9dd90b7329e5838a6ddabac7b42e421877dac7ea 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/share/ShareHelper.java
@@ -11,6 +11,8 @@ import android.content.BroadcastReceiver;
import android.content.ClipData;
import android.content.ComponentName;
import android.content.Context;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
@@ -401,6 +403,9 @@ public class ShareHelper {
builder.setTitle(activity.getString(R.string.share_link_chooser_title));
builder.setAdapter(adapter, null);
+ // Need a mutable object to record whether the callback has been fired.
+ final boolean[] callbackCalled = new boolean[1];
+
final AlertDialog dialog = builder.create();
dialog.show();
dialog.getListView().setOnItemClickListener(new OnItemClickListener() {
@@ -410,13 +415,28 @@ public class ShareHelper {
ActivityInfo ai = info.activityInfo;
ComponentName component =
new ComponentName(ai.applicationInfo.packageName, ai.name);
- if (callback != null) callback.onTargetChosen(component);
+ if (callback != null && !callbackCalled[0]) {
+ callback.onTargetChosen(component);
+ callbackCalled[0] = true;
+ }
if (saveLastUsed) setLastShareComponentName(component);
makeIntentAndShare(false, activity, title, text, url, offlineUri, screenshotUri,
component, null);
dialog.dismiss();
}
});
+
+ if (callback == null) return;
+
+ dialog.setOnDismissListener(new OnDismissListener() {
+ @Override
+ public void onDismiss(DialogInterface dialog) {
+ if (!callbackCalled[0]) {
+ callback.onCancel();
+ callbackCalled[0] = true;
+ }
+ }
+ });
}
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698