Search in sources :

Example 6 with TabDelegate

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;
}
Also used : BookmarkId(org.chromium.components.bookmarks.BookmarkId) List(java.util.List) TabDelegate(org.chromium.chrome.browser.tabmodel.document.TabDelegate) BookmarkItem(org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem)

Example 7 with TabDelegate

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;
}
Also used : Context(android.content.Context) ChromeTabbedActivity(org.chromium.chrome.browser.ChromeTabbedActivity) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams) TabDelegate(org.chromium.chrome.browser.tabmodel.document.TabDelegate)

Example 8 with TabDelegate

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);
}
Also used : HashMap(java.util.HashMap) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams) AsyncTabCreationParams(org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams) TabDelegate(org.chromium.chrome.browser.tabmodel.document.TabDelegate)

Aggregations

TabDelegate (org.chromium.chrome.browser.tabmodel.document.TabDelegate)8 LoadUrlParams (org.chromium.content_public.browser.LoadUrlParams)4 Intent (android.content.Intent)2 AsyncTabCreationParams (org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams)2 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)1 AlertDialog (android.support.v7.app.AlertDialog)1 SpannableString (android.text.SpannableString)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 TextView (android.widget.TextView)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CalledByNative (org.chromium.base.annotations.CalledByNative)1 SuppressFBWarnings (org.chromium.base.annotations.SuppressFBWarnings)1 ChromeTabbedActivity (org.chromium.chrome.browser.ChromeTabbedActivity)1 BookmarkItem (org.chromium.chrome.browser.bookmarks.BookmarkBridge.BookmarkItem)1 ButtonPreference (org.chromium.chrome.browser.preferences.ButtonPreference)1 ClearBrowsingDataCheckBoxPreference (org.chromium.chrome.browser.preferences.ClearBrowsingDataCheckBoxPreference)1