org.chromium.chrome.browser.share.ShareHelper Java Examples
The following examples show how to use
org.chromium.chrome.browser.share.ShareHelper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContextMenuHelper.java From 365browser with Apache License 2.0 | 6 votes |
/** * Share image triggered with the current context menu directly with a specific app. * @param name The {@link ComponentName} of the app to share the image directly with. */ public void shareImageDirectly(@Nullable final ComponentName name) { if (mNativeContextMenuHelper == 0) return; Callback<byte[]> callback = new Callback<byte[]>() { @Override public void onResult(byte[] result) { WebContents webContents = nativeGetJavaWebContents(mNativeContextMenuHelper); WindowAndroid windowAndroid = webContents.getTopLevelNativeWindow(); Activity activity = windowAndroid.getActivity().get(); if (activity == null) return; ShareHelper.shareImage(activity, result, name); } }; nativeRetrieveImage(mNativeContextMenuHelper, callback, MAX_SHARE_DIMEN_PX); }
Example #2
Source File: ChromeApplication.java From delion with Apache License 2.0 | 5 votes |
/** * Called after onForegroundSessionEnd() indicating that the activity whose onStop() ended the * last foreground session was destroyed. */ private void onForegroundActivityDestroyed() { if (ApplicationStatus.isEveryActivityDestroyed()) { mBackgroundProcessing.onDestroy(); if (mDevToolsServer != null) { mDevToolsServer.destroy(); mDevToolsServer = null; } stopApplicationActivityTracker(); PartnerBrowserCustomizations.destroy(); ShareHelper.clearSharedImages(this); CombinedPolicyProvider.get().destroy(); } }
Example #3
Source File: ChromeActivitySessionTracker.java From 365browser with Apache License 2.0 | 5 votes |
private void onForegroundActivityDestroyed() { if (ApplicationStatus.isEveryActivityDestroyed()) { // These will all be re-initialized when a new Activity starts / upon next use. PartnerBrowserCustomizations.destroy(); ShareHelper.clearSharedImages(); } }
Example #4
Source File: OfflinePageUtils.java From 365browser with Apache License 2.0 | 5 votes |
/** * Callback for receiving the OfflinePageItem and use it to call prepareForSharing. * @param shareDirectly Whether it should share directly with the activity that was most * recently used to share. * @param mainActivity Activity that is used to access package manager * @param title Title of the page. * @param onlineUrl Online URL associated with the offline page that is used to access the * offline page file path. * @param screenshotUri Screenshot of the page to be shared. * @param mContext The application context. * @return a callback of OfflinePageItem */ private static Callback<OfflinePageItem> onGotOfflinePageItemToShare( final boolean shareDirectly, final boolean saveLastUsed, final Activity mainActivity, final String title, final String text, final String onlineUrl, final Uri screenshotUri, final ShareHelper.TargetChosenCallback callback) { return new Callback<OfflinePageItem>() { @Override public void onResult(OfflinePageItem item) { String offlineFilePath = (item == null) ? null : item.getFilePath(); prepareFileAndShare(shareDirectly, saveLastUsed, mainActivity, title, text, onlineUrl, screenshotUri, callback, offlineFilePath); } }; }
Example #5
Source File: OfflinePageUtils.java From 365browser with Apache License 2.0 | 5 votes |
/** * Share an offline copy of the current page. * @param shareDirectly Whether it should share directly with the activity that was most * recently used to share. * @param saveLastUsed Whether to save the chosen activity for future direct sharing. * @param mainActivity Activity that is used to access package manager. * @param text Text to be shared. If both |text| and |url| are supplied, they are concatenated * with a space. * @param screenshotUri Screenshot of the page to be shared. * @param callback Optional callback to be called when user makes a choice. Will not be called * if receiving a response when the user makes a choice is not supported (see * TargetChosenReceiver#isSupported()). * @param currentTab The current tab for which sharing is being done. */ public static void shareOfflinePage(final boolean shareDirectly, final boolean saveLastUsed, final Activity mainActivity, final String text, final Uri screenshotUri, final ShareHelper.TargetChosenCallback callback, final Tab currentTab) { final String url = currentTab.getUrl(); final String title = currentTab.getTitle(); final OfflinePageBridge offlinePageBridge = OfflinePageBridge.getForProfile(currentTab.getProfile()); if (offlinePageBridge == null) { Log.e(TAG, "Unable to perform sharing on current tab."); return; } OfflinePageItem offlinePage = offlinePageBridge.getOfflinePage(currentTab.getWebContents()); if (offlinePage != null) { // If we're currently on offline page get the saved file directly. prepareFileAndShare(shareDirectly, saveLastUsed, mainActivity, title, text, url, screenshotUri, callback, offlinePage.getFilePath()); return; } // If this is an online page, share the offline copy of it. Callback<OfflinePageItem> prepareForSharing = onGotOfflinePageItemToShare(shareDirectly, saveLastUsed, mainActivity, title, text, url, screenshotUri, callback); offlinePageBridge.selectPageForOnlineUrl(url, currentTab.getId(), selectPageForOnlineUrlCallback(currentTab.getWebContents(), offlinePageBridge, prepareForSharing)); }
Example #6
Source File: ShareServiceImpl.java From 365browser with Apache License 2.0 | 5 votes |
@Override public void share(String title, String text, Url url, final ShareResponse callback) { RecordHistogram.recordEnumeratedHistogram("WebShare.ApiCount", WEBSHARE_METHOD_SHARE, WEBSHARE_METHOD_COUNT); if (mActivity == null) { RecordHistogram.recordEnumeratedHistogram("WebShare.ShareOutcome", WEBSHARE_OUTCOME_UNKNOWN_FAILURE, WEBSHARE_OUTCOME_COUNT); callback.call(ShareError.INTERNAL_ERROR); return; } ShareHelper.TargetChosenCallback innerCallback = new ShareHelper.TargetChosenCallback() { @Override public void onTargetChosen(ComponentName chosenComponent) { RecordHistogram.recordEnumeratedHistogram("WebShare.ShareOutcome", WEBSHARE_OUTCOME_SUCCESS, WEBSHARE_OUTCOME_COUNT); callback.call(ShareError.OK); } @Override public void onCancel() { RecordHistogram.recordEnumeratedHistogram("WebShare.ShareOutcome", WEBSHARE_OUTCOME_CANCELED, WEBSHARE_OUTCOME_COUNT); callback.call(ShareError.CANCELED); } }; ShareHelper.share(false, false, mActivity, title, text, url.url, null, null, innerCallback); }
Example #7
Source File: ChromeActivitySessionTracker.java From AndroidChromium with Apache License 2.0 | 5 votes |
private void onForegroundActivityDestroyed() { if (ApplicationStatus.isEveryActivityDestroyed()) { // These will all be re-initialized when a new Activity starts / upon next use. PartnerBrowserCustomizations.destroy(); ShareHelper.clearSharedImages(); } }
Example #8
Source File: OfflinePageUtils.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Callback for receiving the OfflinePageItem and use it to call prepareForSharing. * @param shareDirectly Whether it should share directly with the activity that was most * recently used to share. * @param mainActivity Activity that is used to access package manager * @param title Title of the page. * @param onlineUrl Online URL associated with the offline page that is used to access the * offline page file path. * @param screenshotUri Screenshot of the page to be shared. * @param mContext The application context. * @return a callback of OfflinePageItem */ private static Callback<OfflinePageItem> onGotOfflinePageItemToShare( final boolean shareDirectly, final boolean saveLastUsed, final Activity mainActivity, final String title, final String text, final String onlineUrl, final Uri screenshotUri, final ShareHelper.TargetChosenCallback callback) { return new Callback<OfflinePageItem>() { @Override public void onResult(OfflinePageItem item) { String offlineFilePath = (item == null) ? null : item.getFilePath(); prepareFileAndShare(shareDirectly, saveLastUsed, mainActivity, title, text, onlineUrl, screenshotUri, callback, offlineFilePath); } }; }
Example #9
Source File: OfflinePageUtils.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Share an offline copy of the current page. * @param shareDirectly Whether it should share directly with the activity that was most * recently used to share. * @param saveLastUsed Whether to save the chosen activity for future direct sharing. * @param mainActivity Activity that is used to access package manager. * @param text Text to be shared. If both |text| and |url| are supplied, they are concatenated * with a space. * @param screenshotUri Screenshot of the page to be shared. * @param callback Optional callback to be called when user makes a choice. Will not be called * if receiving a response when the user makes a choice is not supported (see * TargetChosenReceiver#isSupported()). * @param currentTab The current tab for which sharing is being done. */ public static void shareOfflinePage(final boolean shareDirectly, final boolean saveLastUsed, final Activity mainActivity, final String text, final Uri screenshotUri, final ShareHelper.TargetChosenCallback callback, final Tab currentTab) { final String url = currentTab.getUrl(); final String title = currentTab.getTitle(); final OfflinePageBridge offlinePageBridge = OfflinePageBridge.getForProfile(currentTab.getProfile()); if (offlinePageBridge == null) { Log.e(TAG, "Unable to perform sharing on current tab."); return; } OfflinePageItem offlinePage = currentTab.getOfflinePage(); if (offlinePage != null) { // If we're currently on offline page get the saved file directly. prepareFileAndShare(shareDirectly, saveLastUsed, mainActivity, title, text, url, screenshotUri, callback, offlinePage.getFilePath()); return; } // If this is an online page, share the offline copy of it. Callback<OfflinePageItem> prepareForSharing = onGotOfflinePageItemToShare(shareDirectly, saveLastUsed, mainActivity, title, text, url, screenshotUri, callback); offlinePageBridge.selectPageForOnlineUrl(url, currentTab.getId(), selectPageForOnlineUrlCallback(currentTab.getWebContents(), offlinePageBridge, prepareForSharing)); }
Example #10
Source File: ShareServiceImpl.java From AndroidChromium with Apache License 2.0 | 5 votes |
@Override public void share(String title, String text, Url url, final ShareResponse callback) { RecordHistogram.recordEnumeratedHistogram("WebShare.ApiCount", WEBSHARE_METHOD_SHARE, WEBSHARE_METHOD_COUNT); if (mActivity == null) { RecordHistogram.recordEnumeratedHistogram("WebShare.ShareOutcome", WEBSHARE_OUTCOME_UNKNOWN_FAILURE, WEBSHARE_OUTCOME_COUNT); callback.call("Share failed"); return; } ShareHelper.TargetChosenCallback innerCallback = new ShareHelper.TargetChosenCallback() { public void onTargetChosen(ComponentName chosenComponent) { RecordHistogram.recordEnumeratedHistogram("WebShare.ShareOutcome", WEBSHARE_OUTCOME_SUCCESS, WEBSHARE_OUTCOME_COUNT); callback.call(null); } public void onCancel() { RecordHistogram.recordEnumeratedHistogram("WebShare.ShareOutcome", WEBSHARE_OUTCOME_CANCELED, WEBSHARE_OUTCOME_COUNT); callback.call("Share canceled"); } }; ShareHelper.share(false, false, mActivity, title, text, url.url, null, null, innerCallback); }
Example #11
Source File: PrintShareActivity.java From AndroidChromium with Apache License 2.0 | 5 votes |
@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(getIntent(), ShareHelper.EXTRA_TASK_ID)) return; handlePrintAction(); } finally { finish(); } }
Example #12
Source File: ContextMenuHelper.java From AndroidChromium with Apache License 2.0 | 5 votes |
@CalledByNative private void onShareImageReceived( WindowAndroid windowAndroid, byte[] jpegImageData) { Activity activity = windowAndroid.getActivity().get(); if (activity == null) return; ShareHelper.shareImage(activity, jpegImageData); }
Example #13
Source File: ChromeActivity.java From delion with Apache License 2.0 | 5 votes |
/** * Triggered when the share menu item is selected. * This creates and shows a share intent picker dialog or starts a share intent directly. * @param shareDirectly Whether it should share directly with the activity that was most * recently used to share. * @param isIncognito Whether currentTab is incognito. */ public void onShareMenuItemSelected(final boolean shareDirectly, boolean isIncognito) { final Tab currentTab = getActivityTab(); if (currentTab == null) return; final Activity mainActivity = this; ContentBitmapCallback callback = new ContentBitmapCallback() { @Override public void onFinishGetBitmap(Bitmap bitmap, int response) { // Check whether this page is an offline page, and use its online URL if so. String url = currentTab.getOfflinePageOriginalUrl(); RecordHistogram.recordBooleanHistogram( "OfflinePages.SharedPageWasOffline", url != null); // If there is no entry in the offline pages DB for this tab, use the tab's // URL directly. if (url == null) url = currentTab.getUrl(); ShareHelper.share( shareDirectly, mainActivity, currentTab.getTitle(), url, bitmap); if (shareDirectly) { RecordUserAction.record("MobileMenuDirectShare"); } else { RecordUserAction.record("MobileMenuShare"); } } }; if (isIncognito || currentTab.getWebContents() == null) { callback.onFinishGetBitmap(null, ReadbackResponse.SURFACE_UNAVAILABLE); } else { currentTab.getWebContents().getContentBitmapAsync( Bitmap.Config.ARGB_8888, 1.f, EMPTY_RECT, callback); } }
Example #14
Source File: ContextMenuHelper.java From delion with Apache License 2.0 | 5 votes |
@CalledByNative private void onShareImageReceived( WindowAndroid windowAndroid, byte[] jpegImageData) { Activity activity = windowAndroid.getActivity().get(); if (activity == null) return; ShareHelper.shareImage(activity, jpegImageData); }
Example #15
Source File: DeferredStartupHandler.java From AndroidChromium with Apache License 2.0 | 4 votes |
/** * Handle application level deferred startup tasks that can be lazily done after all * the necessary initialization has been completed. Any calls requiring network access should * probably go here. * * Keep these tasks short and break up long tasks into multiple smaller tasks, as they run on * the UI thread and are blocking. Remember to follow RAIL guidelines, as much as possible, and * that most devices are quite slow, so leave enough buffer. */ @UiThread public void initDeferredStartupForApp() { if (mDeferredStartupInitializedForApp) return; mDeferredStartupInitializedForApp = true; ThreadUtils.assertOnUiThread(); RecordHistogram.recordLongTimesHistogram( "UMA.Debug.EnableCrashUpload.DeferredStartUptime2", SystemClock.uptimeMillis() - UmaUtils.getForegroundStartTime(), TimeUnit.MILLISECONDS); mDeferredTasks.add(new Runnable() { @Override public void run() { // Punt all tasks that may block on disk off onto a background thread. initAsyncDiskTask(); AfterStartupTaskUtils.setStartupComplete(); PartnerBrowserCustomizations.setOnInitializeAsyncFinished(new Runnable() { @Override public void run() { String homepageUrl = HomepageManager.getHomepageUri(mAppContext); LaunchMetrics.recordHomePageLaunchMetrics( HomepageManager.isHomepageEnabled(mAppContext), NewTabPage.isNTPUrl(homepageUrl), homepageUrl); } }); PartnerBookmarksShim.kickOffReading(mAppContext); PowerMonitor.create(mAppContext); ShareHelper.clearSharedImages(); OfflinePageUtils.clearSharedOfflineFiles(mAppContext); } }); mDeferredTasks.add(new Runnable() { @Override public void run() { // Clear any media notifications that existed when Chrome was last killed. MediaCaptureNotificationService.clearMediaNotifications(mAppContext); startModerateBindingManagementIfNeeded(); recordKeyboardLocaleUma(); } }); mDeferredTasks.add(new Runnable() { @Override public void run() { // Start or stop Physical Web PhysicalWeb.onChromeStart(); } }); final ChromeApplication application = (ChromeApplication) mAppContext; mDeferredTasks.add(new Runnable() { @Override public void run() { // Starts syncing with GSA. application.createGsaHelper().startSync(); } }); ProcessInitializationHandler.getInstance().initializeDeferredStartupTasks(); }
Example #16
Source File: CustomTabAppMenuPropertiesDelegate.java From AndroidChromium with Apache License 2.0 | 4 votes |
@Override public void prepareMenu(Menu menu) { Tab currentTab = mActivity.getActivityTab(); if (currentTab != null) { MenuItem forwardMenuItem = menu.findItem(R.id.forward_menu_id); forwardMenuItem.setEnabled(currentTab.canGoForward()); mReloadMenuItem = menu.findItem(R.id.reload_menu_id); mReloadMenuItem.setIcon(R.drawable.btn_reload_stop); loadingStateChanged(currentTab.isLoading()); MenuItem shareItem = menu.findItem(R.id.share_row_menu_id); shareItem.setVisible(mShowShare); shareItem.setEnabled(mShowShare); if (mShowShare) { ShareHelper.configureDirectShareMenuItem( mActivity, menu.findItem(R.id.direct_share_menu_id)); } MenuItem iconRow = menu.findItem(R.id.icon_row_menu_id); MenuItem openInChromeItem = menu.findItem(R.id.open_in_browser_id); if (mIsMediaViewer) { // Most of the menu items don't make sense when viewing media. iconRow.setVisible(false); openInChromeItem.setVisible(false); } else { try { openInChromeItem.setTitle(mDefaultBrowserFetcher.get()); } catch (InterruptedException | ExecutionException e) { openInChromeItem.setTitle( mActivity.getString(R.string.menu_open_in_product_default)); } } // Add custom menu items. Make sure they are only added once. if (!mIsCustomEntryAdded) { mIsCustomEntryAdded = true; for (int i = 0; i < mMenuEntries.size(); i++) { MenuItem item = menu.add(0, 0, 1, mMenuEntries.get(i)); mItemToIndexMap.put(item, i); } } } }
Example #17
Source File: ChromeActivity.java From AndroidChromium with Apache License 2.0 | 4 votes |
private void triggerShare( final Tab currentTab, final boolean shareDirectly, boolean isIncognito) { final Activity mainActivity = this; WebContents webContents = currentTab.getWebContents(); RecordHistogram.recordBooleanHistogram( "OfflinePages.SharedPageWasOffline", currentTab.isOfflinePage()); boolean canShareOfflinePage = OfflinePageBridge.isPageSharingEnabled(); // Share an empty blockingUri in place of screenshot file. The file ready notification is // sent by onScreenshotReady call below when the file is written. final Uri blockingUri = (isIncognito || webContents == null) ? null : ChromeFileProvider.generateUriAndBlockAccess(mainActivity); if (canShareOfflinePage) { OfflinePageUtils.shareOfflinePage(shareDirectly, true, mainActivity, null, blockingUri, null, currentTab); } else { ShareHelper.share(shareDirectly, true, mainActivity, currentTab.getTitle(), null, currentTab.getUrl(), null, blockingUri, null); if (shareDirectly) { RecordUserAction.record("MobileMenuDirectShare"); } else { RecordUserAction.record("MobileMenuShare"); } } if (blockingUri == null) return; // Start screenshot capture and notify the provider when it is ready. ContentBitmapCallback callback = new ContentBitmapCallback() { @Override public void onFinishGetBitmap(Bitmap bitmap, int response) { ShareHelper.saveScreenshotToDisk(bitmap, mainActivity, new Callback<Uri>() { @Override public void onResult(Uri result) { // Unblock the file once it is saved to disk. ChromeFileProvider.notifyFileReady(blockingUri, result); } }); } }; if (!mScreenshotCaptureSkippedForTesting) { webContents.getContentBitmapAsync(Bitmap.Config.ARGB_8888, 1.f, EMPTY_RECT, callback); } else { callback.onFinishGetBitmap(null, ReadbackResponse.SURFACE_UNAVAILABLE); } }
Example #18
Source File: TabularContextMenuListAdapter.java From 365browser with Apache License 2.0 | 4 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { ContextMenuItem menuItem = mMenuItems.get(position); ViewHolderItem viewHolder; if (convertView == null) { LayoutInflater inflater = LayoutInflater.from(mActivity); convertView = inflater.inflate(R.layout.tabular_context_menu_row, null); viewHolder = new ViewHolderItem(); viewHolder.mIcon = (ImageView) convertView.findViewById(R.id.context_menu_icon); viewHolder.mText = (TextView) convertView.findViewById(R.id.context_text); viewHolder.mShareIcon = (ImageView) convertView.findViewById(R.id.context_menu_share_icon); viewHolder.mRightPadding = (Space) convertView.findViewById(R.id.context_menu_right_padding); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolderItem) convertView.getTag(); } viewHolder.mText.setText(menuItem.getTitle(mActivity)); Drawable icon = menuItem.getDrawable(mActivity); viewHolder.mIcon.setImageDrawable(icon); viewHolder.mIcon.setVisibility(icon != null ? View.VISIBLE : View.INVISIBLE); if (menuItem == ChromeContextMenuItem.SHARE_IMAGE) { Intent shareIntent = ShareHelper.getShareImageIntent(null); final Pair<Drawable, CharSequence> shareInfo = ShareHelper.getShareableIconAndName(mActivity, shareIntent); if (shareInfo.first != null) { viewHolder.mShareIcon.setImageDrawable(shareInfo.first); viewHolder.mShareIcon.setVisibility(View.VISIBLE); viewHolder.mShareIcon.setContentDescription(mActivity.getString( R.string.accessibility_menu_share_via, shareInfo.second)); viewHolder.mShareIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mOnDirectShare.run(); } }); viewHolder.mRightPadding.setVisibility(View.GONE); } } else { viewHolder.mShareIcon.setVisibility(View.GONE); viewHolder.mRightPadding.setVisibility(View.VISIBLE); } return convertView; }
Example #19
Source File: ContextMenuHelper.java From 365browser with Apache License 2.0 | 4 votes |
/** * Starts showing a context menu for {@code view} based on {@code params}. * @param contentViewCore The {@link ContentViewCore} to show the menu to. * @param params The {@link ContextMenuParams} that indicate what menu items to show. */ @CalledByNative private void showContextMenu(final ContentViewCore contentViewCore, ContextMenuParams params) { if (params.isFile()) return; View view = contentViewCore.getContainerView(); final WindowAndroid windowAndroid = contentViewCore.getWindowAndroid(); if (view == null || view.getVisibility() != View.VISIBLE || view.getParent() == null || windowAndroid == null || windowAndroid.getActivity().get() == null || mPopulator == null) { return; } mCurrentContextMenuParams = params; mActivity = windowAndroid.getActivity().get(); mCallback = new Callback<Integer>() { @Override public void onResult(Integer result) { mPopulator.onItemSelected( ContextMenuHelper.this, mCurrentContextMenuParams, result); } }; mOnMenuShown = new Runnable() { @Override public void run() { WebContents webContents = contentViewCore.getWebContents(); RecordHistogram.recordBooleanHistogram("ContextMenu.Shown", webContents != null); } }; mOnMenuClosed = new Runnable() { @Override public void run() { if (mNativeContextMenuHelper == 0) return; nativeOnContextMenuClosed(mNativeContextMenuHelper); } }; if (ChromeFeatureList.isEnabled(ChromeFeatureList.CUSTOM_CONTEXT_MENU)) { List<Pair<Integer, List<ContextMenuItem>>> items = mPopulator.buildContextMenu(null, mActivity, mCurrentContextMenuParams); if (items.isEmpty()) { ThreadUtils.postOnUiThread(mOnMenuClosed); return; } final ContextMenuUi menuUi = new TabularContextMenuUi(new Runnable() { @Override public void run() { shareImageDirectly(ShareHelper.getLastShareComponentName()); } }); menuUi.displayMenu(mActivity, mCurrentContextMenuParams, items, mCallback, mOnMenuShown, mOnMenuClosed); if (mCurrentContextMenuParams.isImage()) { getThumbnail(new Callback<Bitmap>() { @Override public void onResult(Bitmap result) { ((TabularContextMenuUi) menuUi).onImageThumbnailRetrieved(result); } }); } return; } // The Platform Context Menu requires the listener within this hepler since this helper and // provides context menu for us to show. view.setOnCreateContextMenuListener(this); if (view.showContextMenu()) { mOnMenuShown.run(); windowAndroid.addContextMenuCloseListener(new OnCloseContextMenuListener() { @Override public void onContextMenuClosed() { mOnMenuClosed.run(); windowAndroid.removeContextMenuCloseListener(this); } }); } }
Example #20
Source File: CustomTabAppMenuPropertiesDelegate.java From delion with Apache License 2.0 | 4 votes |
@Override public void prepareMenu(Menu menu) { Tab currentTab = mActivity.getActivityTab(); if (currentTab != null) { MenuItem forwardMenuItem = menu.findItem(R.id.forward_menu_id); forwardMenuItem.setEnabled(currentTab.canGoForward()); mReloadMenuItem = menu.findItem(R.id.reload_menu_id); mReloadMenuItem.setIcon(R.drawable.btn_reload_stop); loadingStateChanged(currentTab.isLoading()); MenuItem shareItem = menu.findItem(R.id.share_row_menu_id); shareItem.setVisible(mShowShare); shareItem.setEnabled(mShowShare); if (mShowShare) { ShareHelper.configureDirectShareMenuItem( mActivity, menu.findItem(R.id.direct_share_menu_id)); } if (mShowBookmark) { MenuItem bookmarkItem = menu.findItem(R.id.bookmark_this_page_id); updateBookmarkMenuItem(bookmarkItem, currentTab); } else { // Because we have custom logic for laying out the icon row, the bookmark icon must // be explicitly removed instead of just made invisible. menu.findItem(R.id.icon_row_menu_id).getSubMenu().removeItem( R.id.bookmark_this_page_id); } MenuItem openInChromeItem = menu.findItem(R.id.open_in_browser_id); MenuItem readItLaterItem = menu.findItem(R.id.read_it_later_id); if (ChromeFeatureList.isEnabled("ReadItLaterInMenu")) { // In the read-it-later experiment, Chrome will be the only browser to open the link openInChromeItem.setTitle(R.string.menu_open_in_chrome); } else { readItLaterItem.setVisible(false); try { openInChromeItem.setTitle(mDefaultBrowserFetcher.get()); } catch (InterruptedException | ExecutionException e) { openInChromeItem.setTitle( mActivity.getString(R.string.menu_open_in_product_default)); } } // Add custom menu items. Make sure they are only added once. if (!mIsCustomEntryAdded) { mIsCustomEntryAdded = true; for (int i = 0; i < mMenuEntries.size(); i++) { MenuItem item = menu.add(0, 0, 1, mMenuEntries.get(i)); mItemToIndexMap.put(item, i); } } } }
Example #21
Source File: CustomTabAppMenuPropertiesDelegate.java From 365browser with Apache License 2.0 | 4 votes |
@Override public void prepareMenu(Menu menu) { Tab currentTab = mActivity.getActivityTab(); if (currentTab != null) { MenuItem forwardMenuItem = menu.findItem(R.id.forward_menu_id); forwardMenuItem.setEnabled(currentTab.canGoForward()); mReloadMenuItem = menu.findItem(R.id.reload_menu_id); mReloadMenuItem.setIcon(R.drawable.btn_reload_stop); loadingStateChanged(currentTab.isLoading()); MenuItem shareItem = menu.findItem(R.id.share_row_menu_id); shareItem.setVisible(mShowShare); shareItem.setEnabled(mShowShare); if (mShowShare) { ShareHelper.configureDirectShareMenuItem( mActivity, menu.findItem(R.id.direct_share_menu_id)); } MenuItem iconRow = menu.findItem(R.id.icon_row_menu_id); MenuItem openInChromeItem = menu.findItem(R.id.open_in_browser_id); MenuItem bookmarkItem = menu.findItem(R.id.bookmark_this_page_id); MenuItem downloadItem = menu.findItem(R.id.offline_page_id); boolean addToHomeScreenVisible = true; // Hide request desktop site on all chrome:// pages except for the NTP. Check request // desktop site if it's activated on this page. MenuItem requestItem = menu.findItem(R.id.request_desktop_site_id); updateRequestDesktopSiteMenuItem(requestItem, currentTab); if (mIsMediaViewer) { // Most of the menu items don't make sense when viewing media. iconRow.setVisible(false); openInChromeItem.setVisible(false); menu.findItem(R.id.find_in_page_id).setVisible(false); menu.findItem(R.id.request_desktop_site_id).setVisible(false); addToHomeScreenVisible = false; } else { openInChromeItem.setTitle( DefaultBrowserInfo.getTitleOpenInDefaultBrowser(mIsOpenedByChrome)); updateBookmarkMenuItem(bookmarkItem, currentTab); } bookmarkItem.setVisible(mShowStar); downloadItem.setVisible(mShowDownload); if (!FirstRunStatus.getFirstRunFlowComplete()) { openInChromeItem.setVisible(false); bookmarkItem.setVisible(false); downloadItem.setVisible(false); addToHomeScreenVisible = false; } downloadItem.setEnabled(DownloadUtils.isAllowedToDownloadPage(currentTab)); String url = currentTab.getUrl(); boolean isChromeScheme = url.startsWith(UrlConstants.CHROME_URL_PREFIX) || url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX); if (isChromeScheme) { addToHomeScreenVisible = false; } // Add custom menu items. Make sure they are only added once. if (!mIsCustomEntryAdded) { mIsCustomEntryAdded = true; for (int i = 0; i < mMenuEntries.size(); i++) { MenuItem item = menu.add(0, 0, 1, mMenuEntries.get(i)); mItemToIndexMap.put(item, i); } } prepareAddToHomescreenMenuItem(menu, currentTab, addToHomeScreenVisible); } }
Example #22
Source File: ChromeActivity.java From 365browser with Apache License 2.0 | 4 votes |
private void triggerShare( final Tab currentTab, final boolean shareDirectly, boolean isIncognito) { final Activity mainActivity = this; WebContents webContents = currentTab.getWebContents(); RecordHistogram.recordBooleanHistogram( "OfflinePages.SharedPageWasOffline", OfflinePageUtils.isOfflinePage(currentTab)); boolean canShareOfflinePage = OfflinePageBridge.isPageSharingEnabled(); // Share an empty blockingUri in place of screenshot file. The file ready notification is // sent by onScreenshotReady call below when the file is written. final Uri blockingUri = (isIncognito || webContents == null) ? null : ChromeFileProvider.generateUriAndBlockAccess(mainActivity); if (canShareOfflinePage) { OfflinePageUtils.shareOfflinePage(shareDirectly, true, mainActivity, null, blockingUri, null, currentTab); } else { ShareHelper.share(shareDirectly, true, mainActivity, currentTab.getTitle(), null, currentTab.getUrl(), null, blockingUri, null); if (shareDirectly) { RecordUserAction.record("MobileMenuDirectShare"); } else { RecordUserAction.record("MobileMenuShare"); } } if (blockingUri == null) return; // Start screenshot capture and notify the provider when it is ready. ContentBitmapCallback callback = new ContentBitmapCallback() { @Override public void onFinishGetBitmap(Bitmap bitmap, int response) { ShareHelper.saveScreenshotToDisk(bitmap, mainActivity, new Callback<Uri>() { @Override public void onResult(Uri result) { // Unblock the file once it is saved to disk. ChromeFileProvider.notifyFileReady(blockingUri, result); } }); } }; if (mScreenshotCaptureSkippedForTesting) { callback.onFinishGetBitmap(null, ReadbackResponse.SURFACE_UNAVAILABLE); } else { webContents.getContentBitmapAsync(0, 0, callback); } }