Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.physicalweb; | 5 package org.chromium.chrome.browser.physicalweb; |
| 6 | 6 |
| 7 import android.content.Intent; | 7 import android.content.Intent; |
| 8 import android.os.Build; | 8 import android.os.Build; |
| 9 import android.os.Bundle; | |
| 10 import android.support.v7.app.AppCompatActivity; | |
| 11 | 9 |
| 12 import org.chromium.chrome.browser.share.ShareHelper; | 10 import org.chromium.chrome.browser.ChromeActivity; |
| 13 import org.chromium.chrome.browser.tab.Tab; | 11 import org.chromium.chrome.browser.share.ShareActivity; |
| 14 import org.chromium.chrome.browser.util.IntentUtils; | |
| 15 | 12 |
| 16 /** | 13 /** |
| 17 * A simple activity that allows Chrome to start the physical web sharing servic e. | 14 * A simple activity that allows Chrome to start the physical web sharing servic e. |
| 18 */ | 15 */ |
| 19 public class PhysicalWebShareActivity extends AppCompatActivity { | 16 public class PhysicalWebShareActivity extends ShareActivity { |
| 20 private static final String TAG = "PhysicalWebShareActivity"; | 17 @Override |
| 18 protected void handleShareAction(ChromeActivity triggeringActivity) { | |
| 19 String url = triggeringActivity.getActivityTab().getUrl(); | |
| 21 | 20 |
| 22 @Override | 21 Intent intent = new Intent(this, PhysicalWebBroadcastService.class); |
| 23 protected void onCreate(Bundle savedInstanceState) { | 22 intent.putExtra(PhysicalWebBroadcastService.DISPLAY_URL_KEY, url); |
| 24 super.onCreate(savedInstanceState); | 23 startService(intent); |
| 25 | |
| 26 try { | |
| 27 Intent intent = getIntent(); | |
| 28 if (intent == null) return; | |
| 29 if (!Intent.ACTION_SEND.equals(intent.getAction())) return; | |
| 30 if (!IntentUtils.safeHasExtra(getIntent(), ShareHelper.EXTRA_TASK_ID )) return; | |
| 31 handleShareAction(); | |
| 32 } finally { | |
| 33 finish(); | |
| 34 } | |
| 35 } | 24 } |
| 36 | 25 |
| 37 private void handleShareAction() { | 26 /** |
| 38 // TODO(iankc): implement sharing | 27 * Pre-conditions for Physical Web Sharing to be enabled: |
|
cco3
2017/03/02 23:46:07
It be good to have a summary line before this:
"Re
iankc
2017/03/02 23:51:05
Done.
| |
| 39 } | 28 * Device is Marshmallow or above. |
| 40 | 29 * Device has sharing feature enabled. |
| 41 public static boolean sharingIsEnabled(Tab currentTab) { | 30 */ |
| 31 public static boolean featureIsAvailable() { | |
| 42 return PhysicalWeb.sharingIsEnabled() && Build.VERSION.SDK_INT >= Build. VERSION_CODES.M; | 32 return PhysicalWeb.sharingIsEnabled() && Build.VERSION.SDK_INT >= Build. VERSION_CODES.M; |
| 43 } | 33 } |
| 44 } | 34 } |
| OLD | NEW |