Search in sources :

Example 1 with CustomTabConfig

use of org.mozilla.focus.customtabs.CustomTabConfig 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 CustomTabConfig

use of org.mozilla.focus.customtabs.CustomTabConfig in project focus-android by mozilla-mobile.

the class SessionTest method testCustomTabConfiguration.

@Test
public void testCustomTabConfiguration() {
    final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    builder.setToolbarColor(Color.GREEN);
    final Intent rawIntent = builder.build().intent;
    rawIntent.putExtra(CustomTabConfig.EXTRA_CUSTOM_TAB_ID, UUID.randomUUID().toString());
    final SafeIntent intent = new SafeIntent(rawIntent);
    final CustomTabConfig customTabConfig = CustomTabConfig.parseCustomTabIntent(RuntimeEnvironment.application, intent);
    final Session session = new Session(TEST_URL, customTabConfig);
    assertTrue(session.isCustomTab());
    assertNotNull(session.getCustomTabConfig());
    assertNotNull(session.getCustomTabConfig().toolbarColor);
    assertEquals(Color.GREEN, (int) session.getCustomTabConfig().toolbarColor);
}
Also used : CustomTabsIntent(android.support.customtabs.CustomTabsIntent) CustomTabConfig(org.mozilla.focus.customtabs.CustomTabConfig) SafeIntent(mozilla.components.utils.SafeIntent) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) SafeIntent(mozilla.components.utils.SafeIntent) Test(org.junit.Test)

Example 3 with CustomTabConfig

use of org.mozilla.focus.customtabs.CustomTabConfig in project focus-android by mozilla-mobile.

the class SessionManagerTest method testCustomTabIntent.

@Test
public void testCustomTabIntent() {
    final SessionManager sessionManager = SessionManager.getInstance();
    final SafeIntent intent = new SafeIntent(new CustomTabsIntent.Builder().setToolbarColor(Color.GREEN).addDefaultShareMenuItem().build().intent.setData(Uri.parse(TEST_URL)).putExtra(CustomTabConfig.EXTRA_CUSTOM_TAB_ID, UUID.randomUUID().toString()));
    sessionManager.handleIntent(RuntimeEnvironment.application, intent, null);
    final List<Session> sessions = sessionManager.getSessions().getValue();
    assertNotNull(sessions);
    assertEquals(0, sessions.size());
    final List<Session> customTabSessions = sessionManager.getCustomTabSessions().getValue();
    assertNotNull(customTabSessions);
    assertEquals(1, customTabSessions.size());
    final Session session = customTabSessions.get(0);
    assertEquals(TEST_URL, session.getUrl().getValue());
    assertTrue(session.isCustomTab());
    assertNotNull(session.getCustomTabConfig());
    final CustomTabConfig config = session.getCustomTabConfig();
    assertNotNull(config.toolbarColor);
    assertEquals(Color.GREEN, config.toolbarColor.intValue());
    assertTrue(config.showShareMenuItem);
    assertFalse(sessionManager.hasSession());
}
Also used : CustomTabsIntent(android.support.customtabs.CustomTabsIntent) CustomTabConfig(org.mozilla.focus.customtabs.CustomTabConfig) SafeIntent(mozilla.components.utils.SafeIntent) Test(org.junit.Test)

Example 4 with CustomTabConfig

use of org.mozilla.focus.customtabs.CustomTabConfig in project focus-android by mozilla-mobile.

the class BrowserMenuAdapter method addCustomTabMenuItems.

private void addCustomTabMenuItems(final List<MenuItem> items, @NonNull final CustomTabConfig customTabConfig) {
    for (final CustomTabConfig.CustomTabMenuItem inputItem : customTabConfig.menuItems) {
        final String name = inputItem.name;
        final PendingIntent pendingIntent = inputItem.pendingIntent;
        final MenuItem item = new MenuItem(R.id.custom_tab_menu_item, name, pendingIntent);
        items.add(item);
    }
}
Also used : CustomTabConfig(org.mozilla.focus.customtabs.CustomTabConfig) PendingIntent(android.app.PendingIntent)

Aggregations

CustomTabConfig (org.mozilla.focus.customtabs.CustomTabConfig)4 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)2 SafeIntent (mozilla.components.utils.SafeIntent)2 Test (org.junit.Test)2 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 IWebView (org.mozilla.focus.web.IWebView)1 FloatingEraseButton (org.mozilla.focus.widget.FloatingEraseButton)1 FloatingSessionsButton (org.mozilla.focus.widget.FloatingSessionsButton)1