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);
}
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);
}
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());
}
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);
}
}
Aggregations