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

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

Issue 2716293003: Abstract ShareActivity Class (Closed)
Patch Set: Removed Availability Created 3 years, 10 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
Index: chrome/android/java/src/org/chromium/chrome/browser/share/ShareActivity.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/share/ShareActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/share/ShareActivity.java
new file mode 100644
index 0000000000000000000000000000000000000000..782a81eed95032089f03db3279d0b30e5ed8c119
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/share/ShareActivity.java
@@ -0,0 +1,67 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.share;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+
+import org.chromium.base.ApplicationStatus;
+import org.chromium.chrome.browser.ChromeActivity;
+import org.chromium.chrome.browser.util.IntentUtils;
+
+import java.lang.ref.WeakReference;
+import java.util.List;
+
+/**
+ * {@code ShareActivity} is the base class for share options, which
+ * are activities that are shown in the share chooser. Activities subclassing
+ * ShareActivity override featureIsEnabled, and handleShareAction.
+ */
+public abstract class ShareActivity extends AppCompatActivity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ try {
+ Intent intent = getIntent();
+ if (intent == null) return;
+ if (!Intent.ACTION_SEND.equals(intent.getAction())) return;
+ if (!IntentUtils.safeHasExtra(intent, ShareHelper.EXTRA_TASK_ID)) return;
+ handleShareAction();
+ } finally {
+ finish();
+ }
+ }
+
+ /**
+ * Returns the ChromeActivity that called the share intent picker.
+ */
+ protected ChromeActivity getTriggeringActivity() {
+ int triggeringTaskId =
+ IntentUtils.safeGetIntExtra(getIntent(), ShareHelper.EXTRA_TASK_ID, 0);
+ List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities();
+ ChromeActivity triggeringActivity = null;
+ for (int i = 0; i < activities.size(); i++) {
+ Activity activity = activities.get(i).get();
+ if (activity == null) continue;
+
+ // Since the share intent is triggered without NEW_TASK or NEW_DOCUMENT, the task ID
Ted C 2017/03/02 21:21:26 I made this comment invalid in one of my earlier p
iankc 2017/03/02 21:33:26 Done.
+ // of this activity will match that of the triggering activity.
+ if (activity.getTaskId() == triggeringTaskId && activity instanceof ChromeActivity) {
+ return (ChromeActivity) activity;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Completes the share action.
+ * Override this activity to implement desired share functionality. The activity
+ * will be destroyed immediately after this method is called.
+ */
+ protected abstract void handleShareAction();
Ted C 2017/03/02 21:21:26 Should we pass the triggering activity here? That
iankc 2017/03/02 21:33:26 Done.
+}

Powered by Google App Engine
This is Rietveld 408576698