use of org.mozilla.focus.menu.browser.BrowserMenu in project focus-android by mozilla-mobile.
the class BrowserFragment method inflateLayout.
@Override
public View inflateLayout(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (savedInstanceState != null && savedInstanceState.containsKey(RESTORE_KEY_DOWNLOAD)) {
// If this activity was destroyed before we could start a download (e.g. because we were waiting for a permission)
// then restore the download object.
pendingDownload = savedInstanceState.getParcelable(RESTORE_KEY_DOWNLOAD);
}
final View view = inflater.inflate(R.layout.fragment_browser, container, false);
videoContainer = (ViewGroup) view.findViewById(R.id.video_container);
browserContainer = view.findViewById(R.id.browser_container);
urlBar = view.findViewById(R.id.urlbar);
statusBar = view.findViewById(R.id.status_bar_background);
popupTint = view.findViewById(R.id.popup_tint);
urlView = (TextView) view.findViewById(R.id.display_url);
progressView = (AnimatedProgressBar) view.findViewById(R.id.progress);
swipeRefresh = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh);
swipeRefresh.setColorSchemeResources(R.color.colorAccent);
swipeRefresh.setEnabled(Features.SWIPE_TO_REFRESH);
swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
reload();
TelemetryWrapper.swipeReloadEvent();
}
});
session.getUrl().observe(this, new Observer<String>() {
@Override
public void onChanged(@Nullable String url) {
urlView.setText(UrlUtils.stripUserInfo(url));
}
});
setBlockingEnabled(session.isBlockingEnabled());
session.getLoading().observe(this, new AverageLoadTimeObserver(session));
session.getLoading().observe(this, new NonNullObserver<Boolean>() {
@Override
public void onValueChanged(@NonNull Boolean loading) {
if (loading) {
backgroundTransitionGroup.resetTransition();
progressView.setProgress(5);
progressView.setVisibility(View.VISIBLE);
} else {
if (progressView.getVisibility() == View.VISIBLE) {
// We start a transition only if a page was just loading before
// allowing to avoid issue #1179
backgroundTransitionGroup.startTransition(ANIMATION_DURATION);
progressView.setVisibility(View.GONE);
}
swipeRefresh.setRefreshing(false);
}
updateBlockingBadging(loading || session.isBlockingEnabled());
updateToolbarButtonStates(loading);
final BrowserMenu menu = menuWeakReference.get();
if (menu != null) {
menu.updateLoading(loading);
}
}
});
if ((refreshButton = view.findViewById(R.id.refresh)) != null) {
refreshButton.setOnClickListener(this);
}
if ((stopButton = view.findViewById(R.id.stop)) != null) {
stopButton.setOnClickListener(this);
}
if ((forwardButton = view.findViewById(R.id.forward)) != null) {
forwardButton.setOnClickListener(this);
}
if ((backButton = view.findViewById(R.id.back)) != null) {
backButton.setOnClickListener(this);
}
final ImageView blockIcon = (ImageView) view.findViewById(R.id.block_image);
blockIcon.setImageResource(R.drawable.ic_tracking_protection_disabled);
blockView = (FrameLayout) view.findViewById(R.id.block);
securityView = view.findViewById(R.id.security_info);
session.getSecure().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean secure) {
if (!session.getLoading().getValue()) {
if (secure) {
securityView.setImageResource(R.drawable.ic_lock);
} else {
if (URLUtil.isHttpUrl(getUrl())) {
// HTTP site
securityView.setImageResource(R.drawable.ic_internet);
} else {
// Certificate is bad
securityView.setImageResource(R.drawable.ic_warning);
}
}
} else {
securityView.setImageResource(R.drawable.ic_internet);
}
}
});
securityView.setOnClickListener(this);
session.getProgress().observe(this, new Observer<Integer>() {
@Override
public void onChanged(Integer progress) {
progressView.setProgress(progress);
}
});
menuView = (ImageButton) view.findViewById(R.id.menuView);
menuView.setOnClickListener(this);
if (session.isCustomTab()) {
initialiseCustomTabUi(view);
} else {
initialiseNormalBrowserUi(view);
}
return view;
}
use of org.mozilla.focus.menu.browser.BrowserMenu in project focus-android by mozilla-mobile.
the class BrowserFragment method onClick.
@Override
public void onClick(View view) {
switch(view.getId()) {
case R.id.menuView:
BrowserMenu menu = new BrowserMenu(getActivity(), this, session.getCustomTabConfig());
menu.show(menuView);
menuWeakReference = new WeakReference<>(menu);
break;
case R.id.display_url:
final Fragment urlFragment = UrlInputFragment.createWithSession(session, urlView);
getActivity().getSupportFragmentManager().beginTransaction().add(R.id.container, urlFragment, UrlInputFragment.FRAGMENT_TAG).commit();
break;
case R.id.erase:
{
TelemetryWrapper.eraseEvent();
erase();
break;
}
case R.id.tabs:
getActivity().getSupportFragmentManager().beginTransaction().add(R.id.container, new SessionsSheetFragment(), SessionsSheetFragment.FRAGMENT_TAG).commit();
TelemetryWrapper.openTabsTrayEvent();
break;
case R.id.back:
{
goBack();
break;
}
case R.id.forward:
{
final IWebView webView = getWebView();
if (webView != null) {
webView.goForward();
}
break;
}
case R.id.refresh:
{
reload();
TelemetryWrapper.menuReloadEvent();
break;
}
case R.id.stop:
{
final IWebView webView = getWebView();
if (webView != null) {
webView.stopLoading();
}
break;
}
case R.id.open_in_firefox_focus:
{
sessionManager.moveCustomTabToRegularSessions(session);
final IWebView webView = getWebView();
if (webView != null) {
webView.saveWebViewState(session);
}
final Intent intent = new Intent(getContext(), MainActivity.class);
intent.setAction(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
TelemetryWrapper.openFullBrowser();
final Activity activity = getActivity();
if (activity != null) {
activity.finish();
}
break;
}
case R.id.share:
{
shareCurrentUrl();
break;
}
case R.id.settings:
((LocaleAwareAppCompatActivity) getActivity()).openPreferences();
break;
case R.id.open_default:
{
final Browsers browsers = new Browsers(getContext(), getUrl());
final ActivityInfo defaultBrowser = browsers.getDefaultBrowser();
if (defaultBrowser == null) {
// BrowserMenuAdapter.initializeMenu()
throw new IllegalStateException("<Open with $Default> was shown when no default browser is set");
}
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getUrl()));
intent.setPackage(defaultBrowser.packageName);
startActivity(intent);
if (browsers.isFirefoxDefaultBrowser()) {
TelemetryWrapper.openFirefoxEvent();
} else {
TelemetryWrapper.openDefaultAppEvent();
}
break;
}
case R.id.open_select_browser:
{
final Browsers browsers = new Browsers(getContext(), getUrl());
final ActivityInfo[] apps = browsers.getInstalledBrowsers();
final ActivityInfo store = browsers.hasFirefoxBrandedBrowserInstalled() ? null : InstallFirefoxActivity.resolveAppStore(getContext());
final OpenWithFragment fragment = OpenWithFragment.newInstance(apps, getUrl(), store);
fragment.show(getFragmentManager(), OpenWithFragment.FRAGMENT_TAG);
TelemetryWrapper.openSelectionEvent();
break;
}
case R.id.customtab_close:
{
erase();
getActivity().finish();
TelemetryWrapper.closeCustomTabEvent();
break;
}
case R.id.help:
SessionManager.getInstance().createSession(Source.MENU, SupportUtils.HELP_URL);
break;
case R.id.help_trackers:
SessionManager.getInstance().createSession(Source.MENU, SupportUtils.getSumoURLForTopic(getContext(), SupportUtils.SumoTopic.TRACKERS));
break;
case R.id.add_to_homescreen:
final IWebView webView = getWebView();
if (webView == null) {
break;
}
final String url = webView.getUrl();
final String title = webView.getTitle();
showAddToHomescreenDialog(url, title);
break;
case R.id.security_info:
showSecurityPopUp();
break;
default:
throw new IllegalArgumentException("Unhandled menu item in BrowserFragment");
}
}
use of org.mozilla.focus.menu.browser.BrowserMenu in project focus-android by mozilla-mobile.
the class BrowserFragment method onPause.
@Override
public void onPause() {
super.onPause();
getContext().unregisterReceiver(downloadBroadcastReceiver);
final BrowserMenu menu = menuWeakReference.get();
if (menu != null) {
menu.dismiss();
menuWeakReference.clear();
}
}
Aggregations