Search in sources :

Example 1 with FloatingEraseButton

use of org.mozilla.focus.widget.FloatingEraseButton in project focus-android by mozilla-mobile.

the class BrowserFragment method initialiseCustomTabUi.

private void initialiseCustomTabUi(@NonNull final View view) {
    final CustomTabConfig customTabConfig = session.getCustomTabConfig();
    // Unfortunately there's no simpler way to have the FAB only in normal-browser mode.
    // - ViewStub: requires splitting attributes for the FAB between the ViewStub, and actual FAB layout file.
    // Moreover, the layout behaviour just doesn't work unless you set it programatically.
    // - View.GONE: doesn't work because the layout-behaviour makes the FAB visible again when scrolling.
    // - Adding at runtime: works, but then we need to use a separate layout file (and you need
    // to set some attributes programatically, same as ViewStub).
    final FloatingEraseButton erase = view.findViewById(R.id.erase);
    final ViewGroup eraseContainer = (ViewGroup) erase.getParent();
    eraseContainer.removeView(erase);
    final FloatingSessionsButton sessions = view.findViewById(R.id.tabs);
    eraseContainer.removeView(sessions);
    final int textColor;
    if (customTabConfig.toolbarColor != null) {
        urlBar.setBackgroundColor(customTabConfig.toolbarColor);
        textColor = ColorUtils.getReadableTextColor(customTabConfig.toolbarColor);
        urlView.setTextColor(textColor);
    } else {
        textColor = Color.WHITE;
    }
    final ImageView closeButton = (ImageView) view.findViewById(R.id.customtab_close);
    closeButton.setVisibility(View.VISIBLE);
    closeButton.setOnClickListener(this);
    if (customTabConfig.closeButtonIcon != null) {
        closeButton.setImageBitmap(customTabConfig.closeButtonIcon);
    } else {
        // Always set the icon in case it's been overridden by a previous CT invocation
        final Drawable closeIcon = DrawableUtils.INSTANCE.loadAndTintDrawable(getContext(), R.drawable.ic_close, textColor);
        closeButton.setImageDrawable(closeIcon);
    }
    if (customTabConfig.disableUrlbarHiding) {
        AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) urlBar.getLayoutParams();
        params.setScrollFlags(0);
    }
    if (customTabConfig.actionButtonConfig != null) {
        final ImageButton actionButton = (ImageButton) view.findViewById(R.id.customtab_actionbutton);
        actionButton.setVisibility(View.VISIBLE);
        actionButton.setImageBitmap(customTabConfig.actionButtonConfig.icon);
        actionButton.setContentDescription(customTabConfig.actionButtonConfig.description);
        final PendingIntent pendingIntent = customTabConfig.actionButtonConfig.pendingIntent;
        actionButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                try {
                    final Intent intent = new Intent();
                    intent.setData(Uri.parse(getUrl()));
                    pendingIntent.send(getContext(), 0, intent);
                } catch (PendingIntent.CanceledException e) {
                // There's really nothing we can do here...
                }
                TelemetryWrapper.customTabActionButtonEvent();
            }
        });
    } else {
        // If the third-party app doesn't provide an action button configuration then we are
        // going to disable a "Share" button in the toolbar instead.
        final ImageButton shareButton = view.findViewById(R.id.customtab_actionbutton);
        shareButton.setVisibility(View.VISIBLE);
        shareButton.setImageDrawable(DrawableUtils.INSTANCE.loadAndTintDrawable(getContext(), R.drawable.ic_share, textColor));
        shareButton.setContentDescription(getString(R.string.menu_share));
        shareButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                shareCurrentUrl();
            }
        });
    }
    // We need to tint some icons.. We already tinted the close button above. Let's tint our other icons too.
    securityView.setColorFilter(textColor);
    final Drawable menuIcon = DrawableUtils.INSTANCE.loadAndTintDrawable(getContext(), R.drawable.ic_menu, textColor);
    menuView.setImageDrawable(menuIcon);
}
Also used : ViewGroup(android.view.ViewGroup) FloatingSessionsButton(org.mozilla.focus.widget.FloatingSessionsButton) CustomTabConfig(org.mozilla.focus.customtabs.CustomTabConfig) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ImageView(android.widget.ImageView) IWebView(org.mozilla.focus.web.IWebView) View(android.view.View) TextView(android.widget.TextView) FloatingEraseButton(org.mozilla.focus.widget.FloatingEraseButton) ImageButton(android.widget.ImageButton) ImageView(android.widget.ImageView) AppBarLayout(android.support.design.widget.AppBarLayout) PendingIntent(android.app.PendingIntent)

Example 2 with FloatingEraseButton

use of org.mozilla.focus.widget.FloatingEraseButton in project focus-android by mozilla-mobile.

the class BrowserFragment method initialiseNormalBrowserUi.

private void initialiseNormalBrowserUi(@NonNull final View view) {
    final FloatingEraseButton eraseButton = view.findViewById(R.id.erase);
    eraseButton.setOnClickListener(this);
    urlView.setOnClickListener(this);
    final FloatingSessionsButton tabsButton = view.findViewById(R.id.tabs);
    tabsButton.setOnClickListener(this);
    sessionManager.getSessions().observe(this, new NonNullObserver<List<Session>>() {

        @Override
        protected void onValueChanged(@NonNull List<Session> sessions) {
            tabsButton.updateSessionsCount(sessions.size());
            eraseButton.updateSessionsCount(sessions.size());
        }
    });
}
Also used : FloatingEraseButton(org.mozilla.focus.widget.FloatingEraseButton) FloatingSessionsButton(org.mozilla.focus.widget.FloatingSessionsButton) List(java.util.List) NullSession(org.mozilla.focus.session.NullSession) Session(org.mozilla.focus.session.Session)

Aggregations

FloatingEraseButton (org.mozilla.focus.widget.FloatingEraseButton)2 FloatingSessionsButton (org.mozilla.focus.widget.FloatingSessionsButton)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Drawable (android.graphics.drawable.Drawable)1 TransitionDrawable (android.graphics.drawable.TransitionDrawable)1 AppBarLayout (android.support.design.widget.AppBarLayout)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 ImageButton (android.widget.ImageButton)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 List (java.util.List)1 CustomTabConfig (org.mozilla.focus.customtabs.CustomTabConfig)1 NullSession (org.mozilla.focus.session.NullSession)1 Session (org.mozilla.focus.session.Session)1 IWebView (org.mozilla.focus.web.IWebView)1