use of org.mozilla.focus.widget.FloatingSessionsButton 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.widget.FloatingSessionsButton 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());
}
});
}
Aggregations