org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController Java Examples

The following examples show how to use org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController. 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: OfflinePageTabObserver.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a snackbar controller that we can use to show our snackbar.
 * @param tabModelSelector used to retrieve a tab by ID
 */
private static SnackbarController createReloadSnackbarController(
        final TabModelSelector tabModelSelector) {
    Log.d(TAG, "building snackbar controller");

    return new SnackbarController() {
        @Override
        public void onAction(Object actionData) {
            assert actionData != null;
            int tabId = (int) actionData;
            RecordUserAction.record("OfflinePages.ReloadButtonClicked");
            Tab foundTab = tabModelSelector.getTabById(tabId);
            if (foundTab == null) return;
            // Delegates to Tab to reload the page. Tab will send the correct header in order to
            // load the right page.
            foundTab.reload();
        }

        @Override
        public void onDismissNoAction(Object actionData) {
            RecordUserAction.record("OfflinePages.ReloadButtonNotClicked");
        }
    };
}
 
Example #2
Source File: OfflinePageTabObserver.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Builds a new OfflinePageTabObserver.
 * @param tabModelSelector Tab model selector for the activity.
 * @param snackbarManager The snackbar manager to show and dismiss snackbars.
 * @param snackbarController Controller to use to build the snackbar.
 */
OfflinePageTabObserver(TabModelSelector tabModelSelector, SnackbarManager snackbarManager,
        SnackbarController snackbarController) {
    mSnackbarManager = snackbarManager;
    mSnackbarController = snackbarController;
    mTabModelSelector = tabModelSelector;
    mTabModelObserver = new TabModelSelectorTabModelObserver(tabModelSelector) {
        @Override
        public void tabRemoved(Tab tab) {
            Log.d(TAG, "tabRemoved");
            stopObservingTab(tab);
            mSnackbarManager.dismissSnackbars(mSnackbarController);
        }
    };
    // The first time observer is created snackbar has net yet been shown.
    mIsObservingNetworkChanges = false;
}
 
Example #3
Source File: OfflinePageUtils.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a snackbar controller that we can use to show our snackbar.
 * @param tabModelSelector used to retrieve a tab by ID
 */
private static SnackbarController createReloadSnackbarController(
        final TabModelSelector tabModelSelector) {
    Log.d(TAG, "building snackbar controller");

    return new SnackbarController() {
        @Override
        public void onAction(Object actionData) {
            assert actionData != null;
            int tabId = (int) actionData;
            RecordUserAction.record("OfflinePages.ReloadButtonClicked");
            Tab foundTab = tabModelSelector.getTabById(tabId);
            if (foundTab == null) return;
            // Delegates to Tab to reload the page. Tab will send the correct header in order to
            // load the right page.
            foundTab.reload();
        }

        @Override
        public void onDismissNoAction(Object actionData) {
            RecordUserAction.record("OfflinePages.ReloadButtonNotClicked");
        }
    };
}
 
Example #4
Source File: OfflinePageUtils.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a snackbar controller that we can use to show our snackbar.
 * @param tabModelSelector used to retrieve a tab by ID
 */
private static SnackbarController createReloadSnackbarController(
        final TabModelSelector tabModelSelector) {
    Log.d(TAG, "building snackbar controller");

    return new SnackbarController() {
        @Override
        public void onAction(Object actionData) {
            assert actionData != null;
            int tabId = (int) actionData;
            RecordUserAction.record("OfflinePages.ReloadButtonClicked");
            Tab foundTab = tabModelSelector.getTabById(tabId);
            if (foundTab == null) return;

            LoadUrlParams params = new LoadUrlParams(
                    foundTab.getOfflinePageOriginalUrl(), PageTransition.RELOAD);
            foundTab.loadUrl(params);
        }

        @Override
        public void onDismissNoAction(Object actionData) {
            RecordUserAction.record("OfflinePages.ReloadButtonNotClicked");
        }
    };
}
 
Example #5
Source File: SnackbarCollection.java    From delion with Apache License 2.0 5 votes vote down vote up
boolean removeMatchingSnackbars(SnackbarController controller) {
    boolean snackbarRemoved = false;
    Iterator<Snackbar> iter = mSnackbars.iterator();
    while (iter.hasNext()) {
        Snackbar snackbar = iter.next();
        if (snackbar.getController() == controller) {
            iter.remove();
            snackbarRemoved = true;
        }
    }
    return snackbarRemoved;
}
 
Example #6
Source File: OfflinePageUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void showReloadSnackbar(Context context, SnackbarManager snackbarManager,
        final SnackbarController snackbarController, int tabId) {
    if (tabId == Tab.INVALID_TAB_ID) return;

    Log.d(TAG, "showReloadSnackbar called with controller " + snackbarController);
    Snackbar snackbar =
            Snackbar.make(context.getString(R.string.offline_pages_viewing_offline_page),
                            snackbarController, Snackbar.TYPE_ACTION,
                            Snackbar.UMA_OFFLINE_PAGE_RELOAD)
                    .setSingleLine(false)
                    .setAction(context.getString(R.string.reload), tabId);
    snackbar.setDuration(sSnackbarDurationMs);
    snackbarManager.showSnackbar(snackbar);
}
 
Example #7
Source File: Snackbar.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns a snackbar to display the given text. If this is a snackbar for a new
 * feature shown to the user, please add the feature name to SnackbarIdentifier in histograms.
 *
 * @param text The text to show on the snackbar.
 * @param controller The SnackbarController to receive callbacks about the snackbar's state.
 * @param type Type of the snackbar. Either {@link #TYPE_ACTION} or {@link #TYPE_NOTIFICATION}.
 * @param identifier The feature code of the snackbar. Should be one of the UMA* constants above
 */
public static Snackbar make(CharSequence text, SnackbarController controller, int type,
        int identifier) {
    Snackbar s = new Snackbar();
    s.mText = text;
    s.mController = controller;
    s.mType = type;
    s.mIdentifier = identifier;
    return s;
}
 
Example #8
Source File: SnackbarCollection.java    From 365browser with Apache License 2.0 5 votes vote down vote up
boolean removeMatchingSnackbars(SnackbarController controller, Object data) {
    boolean snackbarRemoved = false;
    Iterator<Snackbar> iter = mSnackbars.iterator();
    while (iter.hasNext()) {
        Snackbar snackbar = iter.next();
        if (snackbar.getController() == controller
                && objectsAreEqual(snackbar.getActionData(), data)) {
            iter.remove();
            controller.onDismissNoAction(data);
            snackbarRemoved = true;
        }
    }
    return snackbarRemoved;
}
 
Example #9
Source File: SnackbarCollection.java    From 365browser with Apache License 2.0 5 votes vote down vote up
boolean removeMatchingSnackbars(SnackbarController controller) {
    boolean snackbarRemoved = false;
    Iterator<Snackbar> iter = mSnackbars.iterator();
    while (iter.hasNext()) {
        Snackbar snackbar = iter.next();
        if (snackbar.getController() == controller) {
            iter.remove();
            controller.onDismissNoAction(snackbar.getActionData());
            snackbarRemoved = true;
        }
    }
    return snackbarRemoved;
}
 
Example #10
Source File: SnackbarCollection.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private Snackbar removeCurrent(boolean isAction) {
    Snackbar current = mSnackbars.pollFirst();
    if (current != null) {
        SnackbarController controller = current.getController();
        if (isAction) controller.onAction(current.getActionData());
        else controller.onDismissNoAction(current.getActionData());
    }
    return current;
}
 
Example #11
Source File: OfflinePageUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the "reload" snackbar for the given tab.
 * @param activity The activity owning the tab.
 * @param snackbarController Class to show the snackbar.
 */
public static void showReloadSnackbar(Context context, SnackbarManager snackbarManager,
        final SnackbarController snackbarController, int tabId) {
    if (tabId == Tab.INVALID_TAB_ID) return;

    Log.d(TAG, "showReloadSnackbar called with controller " + snackbarController);
    Snackbar snackbar =
            Snackbar.make(context.getString(R.string.offline_pages_viewing_offline_page),
                    snackbarController, Snackbar.TYPE_ACTION, Snackbar.UMA_OFFLINE_PAGE_RELOAD)
                    .setSingleLine(false).setAction(context.getString(R.string.reload), tabId);
    snackbar.setDuration(sSnackbarDurationMs);
    snackbarManager.showSnackbar(snackbar);
}
 
Example #12
Source File: OfflinePageUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the snackbar for the current tab to provide offline specific information if needed.
 * @param activity The activity owning the tab.
 * @param tab The current tab.
 */
public static void showOfflineSnackbarIfNecessary(ChromeActivity activity, Tab tab) {
    if (OfflinePageTabObserver.getInstance() == null
            || !OfflinePageTabObserver.getInstance().isCurrentContext(
                       activity.getBaseContext())) {
        SnackbarController snackbarController =
                createReloadSnackbarController(activity.getTabModelSelector());
        OfflinePageTabObserver.init(
                activity.getBaseContext(), activity.getSnackbarManager(), snackbarController);
    }

    showOfflineSnackbarIfNecessary(tab);
}
 
Example #13
Source File: OfflinePageTabObserver.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
void reinitialize(Context context, SnackbarManager manager, SnackbarController controller) {
    // TODO(fgorski): Work out if we need to also update network changes observer with the
    // context change.
    mContext = context;
    mSnackbarManager = manager;
    mSnackbarController = controller;
}
 
Example #14
Source File: OfflinePageTabObserver.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a new OfflinePageTabObserver.
 * @param context Android context.
 * @param snackbarManager The snackbar manager to show and dismiss snackbars.
 * @param snackbarController Controller to use to build the snackbar.
 */
OfflinePageTabObserver(Context context, SnackbarManager snackbarManager,
        SnackbarController snackbarController) {
    reinitialize(context, snackbarManager, snackbarController);

    // The first time observer is created snackbar has net yet been shown.
    mIsObservingNetworkChanges = false;
}
 
Example #15
Source File: OfflinePageTabObserver.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
static void init(Context context, SnackbarManager manager, SnackbarController controller) {
    if (sInstance == null) {
        sInstance = new OfflinePageTabObserver(context, manager, controller);
        return;
    }
    sInstance.reinitialize(context, manager, controller);
}
 
Example #16
Source File: Snackbar.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns a snackbar to display the given text. If this is a snackbar for a new
 * feature shown to the user, please add the feature name to SnackbarIdentifier in histograms.
 *
 * @param text The text to show on the snackbar.
 * @param controller The SnackbarController to receive callbacks about the snackbar's state.
 * @param type Type of the snackbar. Either {@link #TYPE_ACTION} or {@link #TYPE_NOTIFICATION}.
 * @param identifier The feature code of the snackbar. Should be one of the UMA* constants above
 */
public static Snackbar make(CharSequence text, SnackbarController controller, int type,
        int identifier) {
    Snackbar s = new Snackbar();
    s.mText = text;
    s.mController = controller;
    s.mType = type;
    s.mIdentifier = identifier;
    return s;
}
 
Example #17
Source File: SnackbarCollection.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
boolean removeMatchingSnackbars(SnackbarController controller, Object data) {
    boolean snackbarRemoved = false;
    Iterator<Snackbar> iter = mSnackbars.iterator();
    while (iter.hasNext()) {
        Snackbar snackbar = iter.next();
        if (snackbar.getController() == controller
                && objectsAreEqual(snackbar.getActionData(), data)) {
            iter.remove();
            controller.onDismissNoAction(data);
            snackbarRemoved = true;
        }
    }
    return snackbarRemoved;
}
 
Example #18
Source File: SnackbarCollection.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
boolean removeMatchingSnackbars(SnackbarController controller) {
    boolean snackbarRemoved = false;
    Iterator<Snackbar> iter = mSnackbars.iterator();
    while (iter.hasNext()) {
        Snackbar snackbar = iter.next();
        if (snackbar.getController() == controller) {
            iter.remove();
            controller.onDismissNoAction(snackbar.getActionData());
            snackbarRemoved = true;
        }
    }
    return snackbarRemoved;
}
 
Example #19
Source File: SnackbarCollection.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private Snackbar removeCurrent(boolean isAction) {
    Snackbar current = mSnackbars.pollFirst();
    if (current != null) {
        SnackbarController controller = current.getController();
        if (isAction) controller.onAction(current.getActionData());
        else controller.onDismissNoAction(current.getActionData());
    }
    return current;
}
 
Example #20
Source File: OfflinePageUtils.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the "reload" snackbar for the given tab.
 * @param activity The activity owning the tab.
 * @param snackbarController Class to show the snackbar.
 */
public static void showReloadSnackbar(Context context, SnackbarManager snackbarManager,
        final SnackbarController snackbarController, int tabId) {
    if (tabId == Tab.INVALID_TAB_ID) return;

    Log.d(TAG, "showReloadSnackbar called with controller " + snackbarController);
    Snackbar snackbar =
            Snackbar.make(context.getString(R.string.offline_pages_viewing_offline_page),
                    snackbarController, Snackbar.TYPE_ACTION, Snackbar.UMA_OFFLINE_PAGE_RELOAD)
                    .setSingleLine(false).setAction(context.getString(R.string.reload), tabId);
    snackbar.setDuration(SNACKBAR_DURATION);
    snackbarManager.showSnackbar(snackbar);
}
 
Example #21
Source File: OfflinePageUtils.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the snackbar for the current tab to provide offline specific information if needed.
 * @param activity The activity owning the tab.
 * @param tab The current tab.
 */
public static void showOfflineSnackbarIfNecessary(ChromeActivity activity, Tab tab) {
    if (!OfflinePageBridge.isOfflinePagesEnabled()) return;

    if (OfflinePageTabObserver.getInstance() == null) {
        SnackbarController snackbarController =
                createReloadSnackbarController(activity.getTabModelSelector());
        OfflinePageTabObserver.init(
                activity.getBaseContext(), activity.getSnackbarManager(), snackbarController);
    }

    showOfflineSnackbarIfNecessary(tab);
}
 
Example #22
Source File: OfflinePageTabObserver.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a new OfflinePageTabObserver.
 * @param context Android context.
 * @param snackbarManager The snackbar manager to show and dismiss snackbars.
 * @param snackbarController Controller to use to build the snackbar.
 */
OfflinePageTabObserver(Context context, SnackbarManager snackbarManager,
        SnackbarController snackbarController) {
    mContext = context;
    mSnackbarManager = snackbarManager;
    mSnackbarController = snackbarController;

    // The first time observer is created snackbar has net yet been shown.
    mWasSnackbarShown = false;
    mIsObservingNetworkChanges = false;
}
 
Example #23
Source File: SnackbarCollection.java    From delion with Apache License 2.0 5 votes vote down vote up
private Snackbar removeCurrent(boolean isAction) {
    Snackbar current = mSnackbars.pollFirst();
    if (current != null) {
        SnackbarController controller = current.getController();
        if (isAction) controller.onAction(current.getActionData());
        else controller.onDismissNoAction(current.getActionData());
    }
    return current;
}
 
Example #24
Source File: SnackbarCollection.java    From delion with Apache License 2.0 5 votes vote down vote up
boolean removeMatchingSnackbars(SnackbarController controller, Object data) {
    boolean snackbarRemoved = false;
    Iterator<Snackbar> iter = mSnackbars.iterator();
    while (iter.hasNext()) {
        Snackbar snackbar = iter.next();
        if (snackbar.getController() == controller
                && objectsAreEqual(snackbar.getActionData(), data)) {
            iter.remove();
            snackbarRemoved = true;
        }
    }
    return snackbarRemoved;
}
 
Example #25
Source File: Snackbar.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns a snackbar to display the given text. If this is a snackbar for a new
 * feature shown to the user, please add the feature name to SnackbarIdentifier in histograms.
 *
 * @param text The text to show on the snackbar.
 * @param controller The SnackbarController to receive callbacks about the snackbar's state.
 * @param type Type of the snackbar. Either {@link #TYPE_ACTION} or {@link #TYPE_NOTIFICATION}.
 * @param identifier The feature code of the snackbar. Should be one of the UMA* constants above
 */
public static Snackbar make(CharSequence text, SnackbarController controller, int type,
        int identifier) {
    Snackbar s = new Snackbar();
    s.mText = text;
    s.mController = controller;
    s.mType = type;
    s.mIdentifier = identifier;
    return s;
}
 
Example #26
Source File: OfflinePageTabObserver.java    From delion with Apache License 2.0 4 votes vote down vote up
static void init(Context context, SnackbarManager manager, SnackbarController controller) {
    sInstance = new OfflinePageTabObserver(context, manager, controller);
}
 
Example #27
Source File: OfflinePageUtils.java    From 365browser with Apache License 2.0 4 votes vote down vote up
protected void showReloadSnackbarInternal(Context context, SnackbarManager snackbarManager,
final SnackbarController snackbarController, int tabId) {}
 
Example #28
Source File: Snackbar.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * @return The {@link SnackbarController} that controls this snackbar.
 */
@VisibleForTesting
public SnackbarController getController() {
    return mController;
}
 
Example #29
Source File: Snackbar.java    From delion with Apache License 2.0 4 votes vote down vote up
SnackbarController getController() {
    return mController;
}
 
Example #30
Source File: Snackbar.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
SnackbarController getController() {
    return mController;
}