use of org.chromium.chrome.browser.tabmodel.document.TabDelegate in project AndroidChromium by JackyAndroid.
the class BookmarkActionBar method onMenuItemClick.
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
SelectionDelegate<BookmarkId> selectionDelegate = mDelegate.getSelectionDelegate();
if (menuItem.getItemId() == R.id.edit_menu_id) {
BookmarkAddEditFolderActivity.startEditFolderActivity(getContext(), mCurrentFolder.getId());
return true;
} else if (menuItem.getItemId() == R.id.close_menu_id) {
BookmarkUtils.finishActivityOnPhone(getContext());
return true;
} else if (menuItem.getItemId() == R.id.search_menu_id) {
mDelegate.openSearchUI();
return true;
} else if (menuItem.getItemId() == R.id.selection_mode_edit_menu_id) {
List<BookmarkId> list = selectionDelegate.getSelectedItems();
assert list.size() == 1;
BookmarkItem item = mDelegate.getModel().getBookmarkById(list.get(0));
if (item.isFolder()) {
BookmarkAddEditFolderActivity.startEditFolderActivity(getContext(), item.getId());
} else {
BookmarkUtils.startEditActivity(getContext(), item.getId());
}
return true;
} else if (menuItem.getItemId() == R.id.selection_mode_move_menu_id) {
List<BookmarkId> list = selectionDelegate.getSelectedItems();
if (list.size() >= 1) {
BookmarkFolderSelectActivity.startFolderSelectActivity(getContext(), list.toArray(new BookmarkId[list.size()]));
}
return true;
} else if (menuItem.getItemId() == R.id.selection_mode_delete_menu_id) {
mDelegate.getModel().deleteBookmarks(selectionDelegate.getSelectedItems().toArray(new BookmarkId[0]));
return true;
} else if (menuItem.getItemId() == R.id.selection_open_in_new_tab_id) {
openBookmarksInNewTabs(selectionDelegate.getSelectedItems(), new TabDelegate(false), mDelegate.getModel());
selectionDelegate.clearSelection();
return true;
} else if (menuItem.getItemId() == R.id.selection_open_in_incognito_tab_id) {
openBookmarksInNewTabs(selectionDelegate.getSelectedItems(), new TabDelegate(true), mDelegate.getModel());
selectionDelegate.clearSelection();
return true;
}
assert false : "Unhandled menu click.";
return false;
}
use of org.chromium.chrome.browser.tabmodel.document.TabDelegate in project AndroidChromium by JackyAndroid.
the class DownloadUtils method showDownloadManager.
/**
* Displays the download manager UI. Note the UI is different on tablets and on phones.
* @return Whether the UI was shown.
*/
public static boolean showDownloadManager(@Nullable Activity activity, @Nullable Tab tab) {
if (!isDownloadHomeEnabled())
return false;
// Figure out what tab was last being viewed by the user.
if (activity == null)
activity = ApplicationStatus.getLastTrackedFocusedActivity();
if (tab == null && activity instanceof ChromeTabbedActivity) {
tab = ((ChromeTabbedActivity) activity).getActivityTab();
}
Context appContext = ContextUtils.getApplicationContext();
if (DeviceFormFactor.isTablet(appContext)) {
// Download Home shows up as a tab on tablets.
LoadUrlParams params = new LoadUrlParams(UrlConstants.DOWNLOADS_URL);
if (tab == null || !tab.isInitialized()) {
// Open a new tab, which pops Chrome into the foreground.
TabDelegate delegate = new TabDelegate(false);
delegate.createNewTab(params, TabLaunchType.FROM_CHROME_UI, null);
} else {
// Download Home shows up inside an existing tab, but only if the last Activity was
// the ChromeTabbedActivity.
tab.loadUrl(params);
// Bring Chrome to the foreground, if possible.
Intent intent = Tab.createBringTabToFrontIntent(tab.getId());
if (intent != null) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
IntentUtils.safeStartActivity(appContext, intent);
}
}
} else {
// Download Home shows up as a new Activity on phones.
Intent intent = new Intent();
intent.setClass(appContext, DownloadActivity.class);
if (tab != null)
intent.putExtra(EXTRA_IS_OFF_THE_RECORD, tab.isIncognito());
if (activity == null) {
// Stands alone in its own task.
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
appContext.startActivity(intent);
} else {
// Sits on top of another Activity.
intent.putExtra(IntentHandler.EXTRA_PARENT_COMPONENT, activity.getComponentName());
activity.startActivity(intent);
}
}
return true;
}
use of org.chromium.chrome.browser.tabmodel.document.TabDelegate in project AndroidChromium by JackyAndroid.
the class OfflinePageDownloadBridge method openItem.
/**
* 'Opens' the offline page identified by the GUID.
* This is done by creating a new tab and navigating it to the saved local snapshot.
* No automatic redirection is happening based on the connection status.
* If the item with specified GUID is not found or can't be opened, nothing happens.
* @param guid GUID of the item to open.
* @param componentName If specified, targets a specific Activity to open the offline page in.
*/
@Override
public void openItem(String guid, @Nullable ComponentName componentName) {
OfflinePageDownloadItem item = getItem(guid);
if (item == null)
return;
LoadUrlParams params = new LoadUrlParams(item.getUrl());
Map<String, String> headers = new HashMap<String, String>();
headers.put("X-Chrome-offline", "persist=1 reason=download id=" + Long.toString(nativeGetOfflineIdByGuid(mNativeOfflinePageDownloadBridge, guid)));
params.setExtraHeaders(headers);
AsyncTabCreationParams asyncParams = componentName == null ? new AsyncTabCreationParams(params) : new AsyncTabCreationParams(params, componentName);
final TabDelegate tabDelegate = new TabDelegate(false);
tabDelegate.createNewTab(asyncParams, TabLaunchType.FROM_CHROME_UI, Tab.INVALID_TAB_ID);
}
Aggregations