Search in sources :

Example 1 with IWebView

use of org.mozilla.focus.web.IWebView in project focus-android by mozilla-mobile.

the class BrowserFragment method shareCurrentUrl.

private void shareCurrentUrl() {
    final String url = getUrl();
    final Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, url);
    // Use title from webView if it's content matches the url
    final IWebView webView = getWebView();
    if (webView != null) {
        final String contentUrl = webView.getUrl();
        if (contentUrl != null && contentUrl.equals(url)) {
            final String contentTitle = webView.getTitle();
            shareIntent.putExtra(Intent.EXTRA_SUBJECT, contentTitle);
        }
    }
    startActivity(Intent.createChooser(shareIntent, getString(R.string.share_dialog_title)));
    TelemetryWrapper.shareEvent();
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) IWebView(org.mozilla.focus.web.IWebView)

Example 2 with IWebView

use of org.mozilla.focus.web.IWebView in project focus-android by mozilla-mobile.

the class BrowserFragment method setBlockingEnabled.

public void setBlockingEnabled(boolean enabled) {
    final IWebView webView = getWebView();
    if (webView != null) {
        webView.setBlockingEnabled(enabled);
    }
    statusBar.setBackgroundResource(enabled ? R.drawable.animated_background : R.drawable.animated_background_disabled);
    if (!session.isCustomTab()) {
        // Only update the toolbar background if this is not a custom tab. Custom tabs set their
        // own color and we do not want to override this here.
        urlBar.setBackgroundResource(enabled ? R.drawable.animated_background : R.drawable.animated_background_disabled);
        backgroundTransitionGroup = new TransitionDrawableGroup((TransitionDrawable) urlBar.getBackground(), (TransitionDrawable) statusBar.getBackground());
    } else {
        backgroundTransitionGroup = new TransitionDrawableGroup((TransitionDrawable) statusBar.getBackground());
    }
}
Also used : TransitionDrawableGroup(org.mozilla.focus.animation.TransitionDrawableGroup) TransitionDrawable(android.graphics.drawable.TransitionDrawable) IWebView(org.mozilla.focus.web.IWebView)

Example 3 with IWebView

use of org.mozilla.focus.web.IWebView 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");
    }
}
Also used : SessionsSheetFragment(org.mozilla.focus.session.ui.SessionsSheetFragment) LocaleAwareAppCompatActivity(org.mozilla.focus.locale.LocaleAwareAppCompatActivity) ActivityInfo(android.content.pm.ActivityInfo) InstallFirefoxActivity(org.mozilla.focus.activity.InstallFirefoxActivity) MainActivity(org.mozilla.focus.activity.MainActivity) LocaleAwareAppCompatActivity(org.mozilla.focus.locale.LocaleAwareAppCompatActivity) Activity(android.app.Activity) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) IWebView(org.mozilla.focus.web.IWebView) MainActivity(org.mozilla.focus.activity.MainActivity) Browsers(org.mozilla.focus.utils.Browsers) DialogFragment(android.support.v4.app.DialogFragment) Fragment(android.support.v4.app.Fragment) OpenWithFragment(org.mozilla.focus.open.OpenWithFragment) SessionsSheetFragment(org.mozilla.focus.session.ui.SessionsSheetFragment) OpenWithFragment(org.mozilla.focus.open.OpenWithFragment) BrowserMenu(org.mozilla.focus.menu.browser.BrowserMenu)

Example 4 with IWebView

use of org.mozilla.focus.web.IWebView in project focus-android by mozilla-mobile.

the class BrowserFragment method updateToolbarButtonStates.

private void updateToolbarButtonStates(boolean isLoading) {
    if (forwardButton == null || backButton == null || refreshButton == null || stopButton == null) {
        return;
    }
    final IWebView webView = getWebView();
    if (webView == null) {
        return;
    }
    final boolean canGoForward = webView.canGoForward();
    final boolean canGoBack = webView.canGoBack();
    forwardButton.setEnabled(canGoForward);
    forwardButton.setAlpha(canGoForward ? 1.0f : 0.5f);
    backButton.setEnabled(canGoBack);
    backButton.setAlpha(canGoBack ? 1.0f : 0.5f);
    refreshButton.setVisibility(isLoading ? View.GONE : View.VISIBLE);
    stopButton.setVisibility(isLoading ? View.VISIBLE : View.GONE);
}
Also used : IWebView(org.mozilla.focus.web.IWebView)

Example 5 with IWebView

use of org.mozilla.focus.web.IWebView in project focus-android by mozilla-mobile.

the class BrowserFragment method erase.

public void erase() {
    final IWebView webView = getWebView();
    if (webView != null) {
        webView.cleanup();
    }
    SessionManager.getInstance().removeCurrentSession();
}
Also used : IWebView(org.mozilla.focus.web.IWebView)

Aggregations

IWebView (org.mozilla.focus.web.IWebView)5 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 Activity (android.app.Activity)1 ActivityInfo (android.content.pm.ActivityInfo)1 TransitionDrawable (android.graphics.drawable.TransitionDrawable)1 DialogFragment (android.support.v4.app.DialogFragment)1 Fragment (android.support.v4.app.Fragment)1 InstallFirefoxActivity (org.mozilla.focus.activity.InstallFirefoxActivity)1 MainActivity (org.mozilla.focus.activity.MainActivity)1 TransitionDrawableGroup (org.mozilla.focus.animation.TransitionDrawableGroup)1 LocaleAwareAppCompatActivity (org.mozilla.focus.locale.LocaleAwareAppCompatActivity)1 BrowserMenu (org.mozilla.focus.menu.browser.BrowserMenu)1 OpenWithFragment (org.mozilla.focus.open.OpenWithFragment)1 SessionsSheetFragment (org.mozilla.focus.session.ui.SessionsSheetFragment)1 Browsers (org.mozilla.focus.utils.Browsers)1