OLD | NEW |
---|---|
(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.browseraction; | |
6 | |
7 import android.app.PendingIntent; | |
8 import android.content.Intent; | |
9 import android.graphics.Bitmap; | |
10 import android.net.Uri; | |
11 import android.os.Bundle; | |
12 import android.support.customtabs.browseraction.BrowserActionIntent; | |
13 import android.support.customtabs.browseraction.BrowserActionItem; | |
14 | |
15 import org.chromium.chrome.browser.init.AsyncInitializationActivity; | |
16 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; | |
17 import org.chromium.chrome.browser.util.IntentUtils; | |
18 | |
19 import java.util.ArrayList; | |
20 | |
21 /** | |
22 * A transparent {@link AsyncInitializationActivity} that displays the browser a ction context menu. | |
23 */ | |
24 public class BrowserActionActivity extends AsyncInitializationActivity { | |
25 private int mType; | |
26 private Uri mUri; | |
27 private ArrayList<BrowserActionItem> mActions = new ArrayList<>(); | |
28 | |
29 /** Whether the native libraries have started loading */ | |
30 private boolean mIsNativeLoading; | |
31 | |
32 /** Wether the native libraries have already loaded */ | |
Yusuf
2017/03/31 23:43:12
Whether
ltian
2017/04/03 19:22:03
Done.
| |
33 private boolean mIsNativeReady; | |
34 | |
35 @Override | |
36 protected void setContentView() { | |
Yusuf
2017/03/31 23:43:12
if you are going to call beginLoadingLibrary, I am
ltian
2017/04/03 19:22:03
New plan is here it should try to open a dialog an
| |
37 if (getIntent() != null | |
38 && BrowserActionIntent.ACTION_BROWSER_ACTION_OPEN.equals(getInte nt().getAction())) { | |
39 parseIntent(getIntent()); | |
40 } | |
41 if (mUri == null) { | |
42 super.onDestroy(); | |
43 } | |
44 beginLoadingLibrary(); | |
45 } | |
46 | |
47 /** | |
48 * Opens a context menu based on the parsed data. | |
49 */ | |
50 public void openContextMenu() { | |
51 return; | |
52 } | |
53 | |
54 @Override | |
55 public void finishNativeInitialization() { | |
56 super.finishNativeInitialization(); | |
57 mIsNativeReady = true; | |
58 } | |
59 | |
60 private void beginLoadingLibrary() { | |
61 if (mIsNativeLoading || mIsNativeReady) return; | |
Yusuf
2017/03/31 23:43:12
not sure why we need these two booleans. setConten
ltian
2017/04/03 19:22:03
Done.
| |
62 mIsNativeLoading = true; | |
63 ChromeBrowserInitializer.getInstance(getApplicationContext()).handlePreN ativeStartup(this); | |
64 } | |
65 | |
66 @Override | |
67 protected boolean shouldDelayBrowserStartup() { | |
68 return true; | |
69 } | |
70 | |
71 /** | |
72 * Parses the data from {@link BrowserActionIntent}. | |
73 * @param intent The {@link BrowserActionIntent} need to be parsed. | |
74 */ | |
75 private void parseIntent(Intent intent) { | |
76 mUri = intent.getData(); | |
77 mType = IntentUtils.safeGetIntExtra( | |
78 intent, BrowserActionIntent.EXTRA_TYPE, BrowserActionIntent.MEDI A_TYPE_NONE); | |
79 ArrayList<Bundle> bundles = IntentUtils.getParcelableArrayListExtra( | |
80 intent, BrowserActionIntent.EXTRA_MENU_ITEMS); | |
81 if (bundles != null) { | |
82 parseBrowserActionItems(bundles); | |
83 } | |
84 } | |
85 | |
86 /** | |
87 * Gets custom item list for browser action menu. | |
88 * @param bundles Data for custom items from {@link BrowserActionIntent}. | |
89 */ | |
90 private void parseBrowserActionItems(ArrayList<Bundle> bundles) { | |
91 for (int i = 0; i < bundles.size(); i++) { | |
92 Bundle bundle = bundles.get(i); | |
93 String title = IntentUtils.safeGetString(bundle, BrowserActionIntent .KEY_TITLE); | |
94 PendingIntent action = | |
95 IntentUtils.safeGetParcelable(bundle, BrowserActionIntent.KE Y_ACTION); | |
96 Bitmap icon = IntentUtils.safeGetParcelable(bundle, BrowserActionInt ent.KEY_ICON); | |
97 if (title != null && action != null) { | |
98 BrowserActionItem item = new BrowserActionItem(title, action); | |
99 if (icon != null) { | |
100 item.setIcon(icon); | |
101 } | |
102 mActions.add(item); | |
103 } | |
104 } | |
105 } | |
106 } | |
OLD | NEW |