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

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

Issue 2716293003: Abstract ShareActivity Class (Closed)
Patch Set: rebasing Created 3 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.share;
6
7 import android.app.Activity;
8 import android.content.Intent;
9 import android.os.Bundle;
10 import android.support.v7.app.AppCompatActivity;
11
12 import org.chromium.base.ApplicationStatus;
13 import org.chromium.chrome.browser.ChromeActivity;
14 import org.chromium.chrome.browser.util.IntentUtils;
15
16 import java.lang.ref.WeakReference;
17 import java.util.List;
18
19 /**
20 * {@code ShareActivity} is the base class for share options, which
21 * are activities that are shown in the share chooser. Activities subclassing
22 * ShareActivity override featureIsEnabled, and handleShareAction.
23 */
24 public abstract class ShareActivity extends AppCompatActivity {
25 @Override
26 protected void onCreate(Bundle savedInstanceState) {
27 super.onCreate(savedInstanceState);
28
29 try {
30 Intent intent = getIntent();
31 if (intent == null) return;
32 if (!Intent.ACTION_SEND.equals(intent.getAction())) return;
33 if (!IntentUtils.safeHasExtra(intent, ShareHelper.EXTRA_TASK_ID)) re turn;
34
35 ChromeActivity triggeringActivity = getTriggeringActivity();
36 if (triggeringActivity == null) return;
37
38 handleShareAction(triggeringActivity);
39 } finally {
40 finish();
41 }
42 }
43
44 /**
45 * Returns the ChromeActivity that called the share intent picker.
46 */
47 private ChromeActivity getTriggeringActivity() {
48 int triggeringTaskId =
49 IntentUtils.safeGetIntExtra(getIntent(), ShareHelper.EXTRA_TASK_ ID, 0);
50 List<WeakReference<Activity>> activities = ApplicationStatus.getRunningA ctivities();
51 ChromeActivity triggeringActivity = null;
52 for (int i = 0; i < activities.size(); i++) {
53 Activity activity = activities.get(i).get();
54 if (activity == null) continue;
55
56 if (activity.getTaskId() == triggeringTaskId && activity instanceof ChromeActivity) {
57 return (ChromeActivity) activity;
58 }
59 }
60 return null;
61 }
62
63 /**
64 * Completes the share action.
65 * Override this activity to implement desired share functionality. The act ivity
66 * will be destroyed immediately after this method is called.
67 */
68 protected abstract void handleShareAction(ChromeActivity triggeringActivity) ;
69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698