Java Code Examples for org.chromium.chrome.browser.tab.Tab#getTitle()

The following examples show how to use org.chromium.chrome.browser.tab.Tab#getTitle() . 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: CustomTabToolbar.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void setTitleToPageTitle() {
    Tab currentTab = getToolbarDataProvider().getTab();
    if (currentTab == null || TextUtils.isEmpty(currentTab.getTitle())) {
        mTitleBar.setText("");
        return;
    }
    String title = currentTab.getTitle();

    // It takes some time to parse the title of the webcontent, and before that Tab#getTitle
    // always return the url. We postpone the title animation until the title is authentic.
    if ((mState == STATE_DOMAIN_AND_TITLE || mState == STATE_TITLE_ONLY)
            && !title.equals(currentTab.getUrl())
            && !title.equals(UrlConstants.ABOUT_BLANK)) {
        // Delay the title animation until security icon animation finishes.
        ThreadUtils.postOnUiThreadDelayed(mTitleAnimationStarter, TITLE_ANIM_DELAY_MS);
    }

    mTitleBar.setText(title);
}
 
Example 2
Source File: CustomTabToolbar.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void setTitleToPageTitle() {
    Tab currentTab = getToolbarDataProvider().getTab();
    if (currentTab == null || TextUtils.isEmpty(currentTab.getTitle())) {
        mTitleBar.setText("");
        return;
    }
    String title = currentTab.getTitle();

    // It takes some time to parse the title of the webcontent, and before that Tab#getTitle
    // always return the url. We postpone the title animation until the title is authentic.
    if ((mState == STATE_DOMAIN_AND_TITLE || mState == STATE_TITLE_ONLY)
            && !title.equals(currentTab.getUrl())
            && !title.equals(UrlConstants.ABOUT_BLANK)) {
        // Delay the title animation until security icon animation finishes.
        ThreadUtils.postOnUiThreadDelayed(mTitleAnimationStarter, TITLE_ANIM_DELAY_MS);
    }

    mTitleBar.setText(title);
}
 
Example 3
Source File: CustomTabToolbar.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void setTitleToPageTitle() {
    Tab currentTab = getToolbarDataProvider().getTab();
    if (currentTab == null || TextUtils.isEmpty(currentTab.getTitle())) {
        mTitleBar.setText("");
        return;
    }
    String title = currentTab.getTitle();

    // It takes some time to parse the title of the webcontent, and before that Tab#getTitle
    // always return the url. We postpone the title animation until the title is authentic.
    if ((mState == STATE_DOMAIN_AND_TITLE || mState == STATE_TITLE_ONLY)
            && !title.equals(currentTab.getUrl())
            && !title.equals(ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL)) {
        // Delay the title animation until security icon animation finishes.
        ThreadUtils.postOnUiThreadDelayed(mTitleAnimationStarter, TITLE_ANIM_DELAY_MS);
    }

    mTitleBar.setText(title);
}
 
Example 4
Source File: TabPrinter.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public String getTitle() {
    Tab tab = mTab.get();
    if (tab == null) return sDefaultTitle;

    String title = tab.getTitle();
    if (!TextUtils.isEmpty(title)) return title;

    String url = tab.getUrl();
    if (!TextUtils.isEmpty(url)) return url;

    return sDefaultTitle;
}
 
Example 5
Source File: LayerTitleCache.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Comes up with a valid title to return for a tab.
 * @param tab The {@link Tab} to build a title for.
 * @return    The title to use.
 */
private String getTitleForTab(Tab tab, String defaultTitle) {
    String title = tab.getTitle();
    if (TextUtils.isEmpty(title)) {
        title = tab.getUrl();
        if (TextUtils.isEmpty(title)) {
            title = defaultTitle;
            if (TextUtils.isEmpty(title)) {
                title = "";
            }
        }
    }
    return title;
}
 
Example 6
Source File: TabPrinter.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public String getTitle() {
    Tab tab = mTab.get();
    if (tab == null) return mDefaultTitle;

    String title = tab.getTitle();
    if (!TextUtils.isEmpty(title)) return title;

    String url = tab.getUrl();
    if (!TextUtils.isEmpty(url)) return url;

    return mDefaultTitle;
}
 
Example 7
Source File: LayerTitleCache.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Comes up with a valid title to return for a tab.
 * @param tab The {@link Tab} to build a title for.
 * @return    The title to use.
 */
private String getTitleForTab(Tab tab, String defaultTitle) {
    String title = tab.getTitle();
    if (TextUtils.isEmpty(title)) {
        title = tab.getUrl();
        if (TextUtils.isEmpty(title)) {
            title = defaultTitle;
            if (TextUtils.isEmpty(title)) {
                title = "";
            }
        }
    }
    return title;
}
 
Example 8
Source File: OfflinePageUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * 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 9
Source File: TabPrinter.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public String getTitle() {
    Tab tab = mTab.get();
    if (tab == null) return mDefaultTitle;

    String title = tab.getTitle();
    if (!TextUtils.isEmpty(title)) return title;

    String url = tab.getUrl();
    if (!TextUtils.isEmpty(url)) return url;

    return mDefaultTitle;
}
 
Example 10
Source File: LayerTitleCache.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Comes up with a valid title to return for a tab.
 * @param tab The {@link Tab} to build a title for.
 * @return    The title to use.
 */
private String getTitleForTab(Tab tab, String defaultTitle) {
    String title = tab.getTitle();
    if (TextUtils.isEmpty(title)) {
        title = tab.getUrl();
        if (TextUtils.isEmpty(title)) {
            title = defaultTitle;
            if (TextUtils.isEmpty(title)) {
                title = "";
            }
        }
    }
    return title;
}
 
Example 11
Source File: OfflinePageUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
}