Example usage for android.webkit WebView setVisibility

List of usage examples for android.webkit WebView setVisibility

Introduction

In this page you can find the example usage for android.webkit WebView setVisibility.

Prototype

@RemotableViewMethod
public void setVisibility(@Visibility int visibility) 

Source Link

Document

Set the visibility state of this view.

Usage

From source file:com.hhs.hfnavigator.slidingtabs.harbinger.LiveStreamFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_webview, null);

    progressWheel = (ProgressWheel) root.findViewById(R.id.webViewProgress);

    swipeRefreshLayout = (SwipeRefreshLayout) root.findViewById(R.id.swipe);
    swipeRefreshLayout.setEnabled(false);
    progressWheel.spin();/*from   w w  w  .  ja v a 2 s . c om*/

    final WebView webView = (WebView) root.findViewById(R.id.webView);
    if (webView != null) {
        webView.setWebViewClient(new WebViewClient() {

            public void onPageFinished(WebView view, String url) {
                progressWheel.stopSpinning();
                webView.setVisibility(View.VISIBLE);
            }
        });
        webView.loadUrl("http://www.harbingernews.net/livestreams");
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setDisplayZoomControls(false);

    }
    webView.setVisibility(View.INVISIBLE);
    return root;
}

From source file:nirwan.cordova.plugin.printer.Printer.java

private void loadContentAsBitmapIntoPrintController(String content, final Intent intent) {
    Activity ctx = cordova.getActivity();
    final WebView page = new WebView(ctx);
    final Printer self = this;

    page.setVisibility(View.INVISIBLE);
    page.getSettings().setJavaScriptEnabled(false);

    page.setWebViewClient(new WebViewClient() {
        @Override/*from  w  ww.  j  a va2 s .  c o  m*/
        public void onPageFinished(final WebView page, String url) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Bitmap screenshot = self.takeScreenshot(page);
                    File tmpFile = self.saveScreenshotToTmpFile(screenshot);
                    ViewGroup vg = (ViewGroup) (page.getParent());

                    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tmpFile));

                    vg.removeView(page);
                }
            }, 1000);
        }
    });

    //Set base URI to the assets/www folder
    String baseURL = webView.getUrl();
    baseURL = baseURL.substring(0, baseURL.lastIndexOf('/') + 1);

    ctx.addContentView(page, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    page.loadDataWithBaseURL(baseURL, content, "text/html", "UTF-8", null);
}

From source file:in.rab.bildkort.DefinitionFragment.java

public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    String definition = getArguments().getString("definition");
    Boolean isHtml = getArguments().getBoolean("isHtml");

    mEditText = (EditText) getView().findViewById(R.id.editText);
    WebView webView = (WebView) getView().findViewById(R.id.webView);

    if (isHtml) {
        // Anki centers text by default, which is not optimal for large HTML
        // chunks such as those we get from NE.
        definition = "<div style=\"text-align: left\">" + definition + "</div>";

        mEditText.setVisibility(View.GONE);
        webView.setVisibility(View.VISIBLE);
    } else {//w  w w . ja  v a 2s  .co  m
        mEditText.setVisibility(View.VISIBLE);
        webView.setVisibility(View.GONE);
    }

    mEditText.setText(definition);
    webView.loadDataWithBaseURL("http://fake", definition, "text/html", "UTF-8", null);
}

From source file:com.mimo.service.api.MimoOauth2Client.java

/**
 * Instantiate a webview and allows the user to login to the Api form within
 * the application// ww  w .j a  v a 2  s. co  m
 * 
 * @param p_view
 *            : Calling view
 * 
 * @param p_activity
 *            : Calling Activity reference
 **/

@SuppressLint("SetJavaScriptEnabled")
public void login(View p_view, Activity p_activity) {

    final Activity m_activity;
    m_activity = p_activity;
    String m_url = this.m_api.getAuthUrl();
    WebView m_webview = new WebView(p_view.getContext());
    m_webview.getSettings().setJavaScriptEnabled(true);
    m_webview.setVisibility(View.VISIBLE);
    m_activity.setContentView(m_webview);

    m_webview.requestFocus(View.FOCUS_DOWN);
    /**
     * Open the softkeyboard of the device to input the text in form which
     * loads in webview.
     */
    m_webview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View p_v, MotionEvent p_event) {
            switch (p_event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (!p_v.hasFocus()) {
                    p_v.requestFocus();
                }
                break;
            }
            return false;
        }
    });

    /**
     * Show the progressbar in the title of the activity untill the page
     * loads the give url.
     */
    m_webview.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView p_view, int p_newProgress) {
            ((Activity) m_context).setProgress(p_newProgress * 100);
            ((Activity) m_context).setTitle(MimoAPIConstants.DIALOG_TEXT_LOADING);

            if (p_newProgress == 100)
                ((Activity) m_context).setTitle(m_context.getString(R.string.app_name));
        }
    });

    m_webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView p_view, String p_url, Bitmap p_favicon) {
        }

        @Override
        public void onReceivedHttpAuthRequest(WebView p_view, HttpAuthHandler p_handler, String p_url,
                String p_realm) {
            p_handler.proceed(MimoAPIConstants.USERNAME, MimoAPIConstants.PASSWORD);
        }

        public void onPageFinished(WebView p_view, String p_url) {
            if (MimoAPIConstants.DEBUG) {
                Log.d(TAG, "Page Url = " + p_url);
            }
            if (p_url.contains("?code=")) {
                if (p_url.indexOf("code=") != -1) {
                    String[] m_urlSplit = p_url.split("=");

                    String m_tempString1 = m_urlSplit[1];
                    if (MimoAPIConstants.DEBUG) {
                        Log.d(TAG, "TempString1 = " + m_tempString1);
                    }
                    String[] m_urlSplit1 = m_tempString1.split("&");

                    String m_code = m_urlSplit1[0];
                    if (MimoAPIConstants.DEBUG) {
                        Log.d(TAG, "code = " + m_code);
                    }
                    MimoOauth2Client.this.m_code = m_code;
                    Thread m_thread = new Thread() {
                        public void run() {
                            String m_token = requesttoken(MimoOauth2Client.this.m_code);

                            Log.d(TAG, "Token = " + m_token);

                            Intent m_navigateIntent = new Intent(m_activity, MimoTransactions.class);

                            m_navigateIntent.putExtra(MimoAPIConstants.KEY_TOKEN, m_token);

                            m_activity.startActivity(m_navigateIntent);
                        }
                    };
                    m_thread.start();
                } else {
                    if (MimoAPIConstants.DEBUG) {
                        Log.d(TAG, "going in else");
                    }
                }
            } else if (p_url.contains(MimoAPIConstants.URL_KEY_TOKEN)) {
                if (p_url.indexOf(MimoAPIConstants.URL_KEY_TOKEN) != -1) {
                    String[] m_urlSplit = p_url.split("=");
                    final String m_token = m_urlSplit[1];

                    Thread m_thread = new Thread() {
                        public void run() {
                            Intent m_navigateIntent = new Intent(m_activity, MimoTransactions.class);
                            m_navigateIntent.putExtra(MimoAPIConstants.KEY_TOKEN, m_token);
                            m_activity.startActivity(m_navigateIntent);
                        }
                    };
                    m_thread.start();
                }
            }
        };
    });

    m_webview.loadUrl(m_url);
}

From source file:org.alfresco.mobile.android.application.accounts.fragment.AccountOAuthFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (getDialog() != null) {
        getDialog().setTitle(R.string.account_wizard_step2_title);
        getDialog().requestWindowFeature(Window.FEATURE_LEFT_ICON);
    } else {/*w w w  .j  a v a2s .  c  om*/
        UIUtils.displayTitle(getActivity(), R.string.account_wizard_step2_title,
                !(getActivity() instanceof HomeScreenActivity));
    }

    final View v = super.onCreateView(inflater, container, savedInstanceState);

    setOnOAuthAccessTokenListener(new OnOAuthAccessTokenListener() {

        @Override
        public void failedRequestAccessToken(Exception e) {
            if (DisplayUtils.hasCentralPane(getActivity())) {
                ((MainActivity) getActivity()).clearScreen();
            } else {
                getActivity().getFragmentManager().popBackStack();
            }

            Log.e(TAG, Log.getStackTraceString(e));
            MessengerManager.showLongToast(getActivity(), getActivity().getString(R.string.error_general));
        }

        @Override
        public void beforeRequestAccessToken(Bundle b) {
            int operationId = CreateAccountRequest.TYPE_ID;
            String intentId = IntentIntegrator.ACTION_CREATE_ACCOUNT_COMPLETED;
            if (getArguments().containsKey(PARAM_ACCOUNT)) {
                operationId = LoadSessionRequest.TYPE_ID;
                intentId = IntentIntegrator.ACTION_LOAD_ACCOUNT_COMPLETED;
            }

            if (getFragmentManager().findFragmentByTag(OperationWaitingDialogFragment.TAG) == null) {
                // Create Account + Session
                OperationWaitingDialogFragment
                        .newInstance(intentId, operationId, R.drawable.ic_cloud, getString(R.string.wait_title),
                                getString(R.string.wait_message), null, 0)
                        .show(getFragmentManager(), OperationWaitingDialogFragment.TAG);
            }
        }

        @Override
        public void afterRequestAccessToken(OAuthData result) {
            load(result);
        }
    });

    final View waiting = v.findViewById(R.id.waiting);

    setOnOAuthWebViewListener(new OnOAuthWebViewListener() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (waiting != null) {
                waiting.setVisibility(View.GONE);
            }
            view.setVisibility(View.VISIBLE);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            waiting.setVisibility(View.VISIBLE);
        }

    });

    return v;
}

From source file:com.gsma.mobileconnect.helpers.AuthorizationService.java

/**
 * Handles the process between the MNO and the end user for the end user to
 * sign in/ authorize the application. The application hands over to the
 * browser during the authorization step. On completion the MNO redirects to
 * the application sending the completion information as URL parameters.
 *
 * @param config           the mobile config
 * @param authUri          the URI to the MNO's authorization page
 * @param scopes           which is an application specified string value.
 * @param redirectUri      which is the return point after the user has
 *                         authenticated/consented.
 * @param state            which is application specified.
 * @param nonce            which is application specified.
 * @param maxAge           which is an integer value.
 * @param acrValues        which is an application specified.
 * @param context          The Android context
 * @param listener         The listener used to alert the activity to the change
 * @param response         The information captured in the discovery phase.
 * @param hmapExtraOptions A HashMap containing additional authorization options
 * @throws UnsupportedEncodingException//from   w w w.j a va 2 s  . co  m
 */
public void authorize(final MobileConnectConfig config, String authUri, final String scopes,
        final String redirectUri, final String state, final String nonce, final int maxAge,
        final String acrValues, final Context context, final AuthorizationListener listener,
        final DiscoveryResponse response, final HashMap<String, Object> hmapExtraOptions)
        throws UnsupportedEncodingException {
    final JsonNode discoveryResponseWrapper = response.getResponseData();
    final JsonNode discoveryResponseJsonNode = discoveryResponseWrapper.get("response");

    String clientId = null;
    String clientSecret = null;

    try {
        clientId = AndroidJsonUtils.getExpectedStringValue(discoveryResponseJsonNode, "client_id");
    } catch (final NoFieldException e) {
        e.printStackTrace();
    }
    Log.d(TAG, "clientId = " + clientId);

    try {
        clientSecret = AndroidJsonUtils.getExpectedStringValue(discoveryResponseJsonNode, "client_secret");
    } catch (final NoFieldException e) {
        e.printStackTrace();
    }
    Log.d(TAG, "clientSecret = " + clientSecret);

    try {
        Log.d(TAG, "clientSecret = " + clientId);
        Log.d(TAG, "authUri = " + authUri);
        Log.d(TAG, "responseType = code");
        Log.d(TAG, "clientId = " + clientSecret);
        Log.d(TAG, "scopes = " + scopes);
        Log.d(TAG, "returnUri = " + redirectUri);
        Log.d(TAG, "state = " + state);
        Log.d(TAG, "nonce = " + nonce);
        Log.d(TAG, "maxAge = " + maxAge);
        Log.d(TAG, "acrValues = " + acrValues);

        if (authUri == null) {
            authUri = "";
        }
        String requestUri = authUri;
        if (authUri.indexOf("?") == -1) {
            requestUri += "?";
        } else if (authUri.indexOf("&") == -1) {
            requestUri += "&";
        }
        final String charSet = Charset.defaultCharset().name();
        requestUri += "response_type=" + URLEncoder.encode("code", charSet);
        requestUri += "&client_id=" + URLEncoder.encode(clientId, charSet);
        requestUri += "&scope=" + URLEncoder.encode(scopes, charSet);
        requestUri += "&redirect_uri=" + URLEncoder.encode(redirectUri, charSet);
        requestUri += "&state=" + URLEncoder.encode(state, charSet);
        requestUri += "&nonce=" + URLEncoder.encode(nonce, charSet);
        //  requestUri += "&prompt=" + URLEncoder.encode(prompt.value(), charSet);
        requestUri += "&max_age=" + URLEncoder.encode(Integer.toString(maxAge), charSet);
        requestUri += "&acr_values=" + URLEncoder.encode(acrValues);

        if (hmapExtraOptions != null && hmapExtraOptions.size() > 0) {
            for (final String key : hmapExtraOptions.keySet()) {
                requestUri += "&" + key + "="
                        + URLEncoder.encode(hmapExtraOptions.get(key).toString(), charSet);
            }
        }

        final RelativeLayout webViewLayout = (RelativeLayout) LayoutInflater.from(context)
                .inflate(R.layout.layout_web_view, null);

        final InteractableWebView webView = (InteractableWebView) webViewLayout.findViewById(R.id.web_view);
        final ProgressBar progressBar = (ProgressBar) webViewLayout.findViewById(R.id.progressBar);

        final DiscoveryAuthenticationDialog dialog = new DiscoveryAuthenticationDialog(context);

        if (webView.getParent() != null) {
            ((ViewGroup) webView.getParent()).removeView(webView);
        }

        dialog.setContentView(webView);

        webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onCloseWindow(final WebView w) {
                super.onCloseWindow(w);
                Log.d(TAG, "Window close");
                w.setVisibility(View.INVISIBLE);
                w.destroy();
            }
        });

        final AuthorizationWebViewClient client = new AuthorizationWebViewClient(dialog, progressBar, listener,
                redirectUri, config, response);
        webView.setWebViewClient(client);

        dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(final DialogInterface dialogInterface) {
                Log.e("Auth Dialog", "dismissed");
                dialogInterface.dismiss();
                closeWebViewAndNotify(listener, webView);
            }
        });

        webView.loadUrl(requestUri);

        try {
            dialog.show();
        } catch (final WindowManager.BadTokenException exception) {
            Log.e("Discovery Dialog", exception.getMessage());
        }
    } catch (final NullPointerException e) {
        Log.d(TAG, "NullPointerException=" + e.getMessage(), e);
    }
}

From source file:org.alfresco.mobile.android.application.fragments.signin.AccountOAuthFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View v = super.onCreateView(inflater, container, savedInstanceState);
    setOnOAuthAccessTokenListener(new OnOAuthAccessTokenListener() {

        @Override/*from  w w  w.  j a  va  2 s.co m*/
        public void failedRequestAccessToken(Exception e) {
            retryOAuthAuthentication();
            Log.e(TAG, Log.getStackTraceString(e));
        }

        @Override
        public void beforeRequestAccessToken(Bundle b) {
            if (getActivity() instanceof BaseActivity) {
                ((BaseActivity) getActivity()).displayWaitingDialog();
            }
        }

        @Override
        public void afterRequestAccessToken(OAuthData result) {
            load(result);
        }
    });

    final View waiting = v.findViewById(R.id.waiting);

    setOnOAuthWebViewListener(new OnOAuthWebViewListener() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (url.startsWith(callback.replace("http", "https"))) {
                if (waiting != null) {
                    waiting.setVisibility(View.VISIBLE);
                }
                view.setVisibility(View.GONE);
            } else if (OAuthConstant.PUBLIC_API_OAUTH_AUTHORIZE_URL.equals(url)) {
                retryOAuthAuthentication();
                if (waiting != null) {
                    waiting.setVisibility(View.VISIBLE);
                }
                view.setVisibility(View.GONE);
            } else {
                if (waiting != null) {
                    waiting.setVisibility(View.GONE);
                }
                view.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            waiting.setVisibility(View.VISIBLE);
        }

    });

    return v;
}

From source file:com.hhs.hfnavigator.slidingtabs.home.BusFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_webview, null);

    swipeRefreshLayout = (SwipeRefreshLayout) root.findViewById(R.id.swipe);
    progressWheel = (ProgressWheel) root.findViewById(R.id.webViewProgress);

    swipeRefreshLayout.setEnabled(false);

    final WebView webView = (WebView) root.findViewById(R.id.webView);
    if (webView != null) {
        webView.loadUrl("http://vqr.mx/DmkD");
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setDisplayZoomControls(false);
        webView.setWebViewClient(new WebViewClient() {

            public void onPageFinished(WebView view, String url) {
                progressWheel.stopSpinning();
                swipeRefreshLayout.setRefreshing(false);
                webView.setVisibility(View.VISIBLE);
            }//from w  w  w.j  ava  2  s. c o m
        });
    }
    progressWheel.spin();
    webView.setVisibility(View.INVISIBLE);

    //        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    //            @Override
    //            public void onRefresh() {
    //                if (CheckNetwork.isInternetAvailable(getActivity())) {
    //                    webView.reload();
    //                }
    //            }
    //        });
    //
    //        swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
    //                android.R.color.holo_red_light,
    //                android.R.color.holo_green_light,
    //                android.R.color.holo_orange_light);

    return root;
}

From source file:io.github.hidroh.materialistic.OfflineWebActivity.java

@SuppressWarnings("ConstantConditions")
@Override/*from w w w.  ja  v  a2  s.com*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String url = getIntent().getStringExtra(EXTRA_URL);
    if (TextUtils.isEmpty(url)) {
        finish();
        return;
    }
    setTitle(url);
    setContentView(R.layout.activity_offline_web);
    final NestedScrollView scrollView = (NestedScrollView) findViewById(R.id.nested_scroll_view);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setOnClickListener(v -> scrollView.smoothScrollTo(0, 0));
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayOptions(
            ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE);
    getSupportActionBar().setSubtitle(R.string.offline);
    final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress);
    final WebView webView = (WebView) findViewById(R.id.web_view);
    webView.setBackgroundColor(Color.TRANSPARENT);
    webView.setWebViewClient(new AdBlockWebViewClient(Preferences.adBlockEnabled(this)) {
        @Override
        public void onPageFinished(WebView view, String url) {
            setTitle(view.getTitle());
        }
    });
    webView.setWebChromeClient(new CacheableWebView.ArchiveClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            progressBar.setVisibility(View.VISIBLE);
            progressBar.setProgress(newProgress);
            if (newProgress == 100) {
                progressBar.setVisibility(View.GONE);
                webView.setBackgroundColor(Color.WHITE);
                webView.setVisibility(View.VISIBLE);
            }
        }
    });
    AppUtils.toggleWebViewZoom(webView.getSettings(), true);
    webView.loadUrl(url);
}

From source file:com.aniruddhc.acemusic.player.Utils.Common.java

@Override
public void onCreate() {
    super.onCreate();

    //Application context.
    mContext = getApplicationContext();/*  ww  w.  j a  v a2 s . c o m*/

    //SharedPreferences.
    mSharedPreferences = this.getSharedPreferences("com.aniruddhc.acemusic.player", Context.MODE_PRIVATE);

    //Init the database.
    mDBAccessHelper = new DBAccessHelper(mContext);

    //Playback kickstarter.
    mPlaybackKickstarter = new PlaybackKickstarter(this.getApplicationContext());

    //Picasso.
    mPicasso = new Picasso.Builder(mContext).build();

    //ImageLoader.
    mImageLoader = ImageLoader.getInstance();
    mImageLoaderConfiguration = new ImageLoaderConfiguration.Builder(getApplicationContext())
            .memoryCache(new WeakMemoryCache()).memoryCacheSizePercentage(13)
            .imageDownloader(new ByteArrayUniversalImageLoader(mContext)).build();
    mImageLoader.init(mImageLoaderConfiguration);

    //Init DisplayImageOptions.
    initDisplayImageOptions();

    //Log the user into Google Play Music only if the account is currently set up and active.
    if (mSharedPreferences.getBoolean("GOOGLE_PLAY_MUSIC_ENABLED", false) == true) {

        //Create a temp WebView to retrieve the user agent string.
        String userAgentString = "";
        if (mSharedPreferences.getBoolean("GOT_USER_AGENT", false) == false) {
            WebView webView = new WebView(getApplicationContext());
            webView.setVisibility(View.GONE);
            webView.loadUrl("http://www.google.com");
            userAgentString = webView.getSettings().getUserAgentString();
            mSharedPreferences.edit().putBoolean("GOT_USER_AGENT", true).commit();
            mSharedPreferences.edit().putString("USER_AGENT", userAgentString).commit();
            webView = null;
        }

        setGMusicClientCalls(GMusicClientCalls.getInstance(getApplicationContext()));
        GMusicClientCalls.setWebClientUserAgent(userAgentString);
        String accountName = mSharedPreferences.getString("GOOGLE_PLAY_MUSIC_ACCOUNT", "");

        //Authenticate with Google.
        AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask(mContext, false,
                accountName);
        task.execute();

    }

}