Example usage for android.webkit WebView WebView

List of usage examples for android.webkit WebView WebView

Introduction

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

Prototype

public WebView(Context context) 

Source Link

Document

Constructs a new WebView with an Activity Context object.

Usage

From source file:de.cellular.lib.lightlib.backend.LLRequest.java

/**
 * Instantiates a new {@link LLRequest}.
 * //from   w  w  w . j  a va2 s. com
 * @since 1.0
 * 
 * @param _context
 *            the Context
 * @param _handler
 *            the {@link LLRequestResponsibleObject} object that can response to the request.
 * @param _method
 *            the request {@link Method}.
 */
protected LLRequest(Context _context, LLRequestResponsibleObject _handler, Method _method) {
    mUserAgent = new WebView(_context).getSettings().getUserAgentString();
    mHandler = _handler;
    mMethod = _method;
    mContext = _context;
}

From source file:com.javielinux.facebook.FacebookHandler.java

public void showWebView() {
    if (isWebViewShown) {
        return;/*w w  w  .java  2s  .  c  om*/
    }

    CookieSyncManager.createInstance(activity);

    mWebView = new WebView(activity);

    layout.addView(mWebView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    CookieManager.getInstance().removeAllCookie();
    CookieManager.getInstance().removeExpiredCookie();
    CookieManager.getInstance().removeSessionCookie();

    CookieSyncManager.getInstance().sync();

    isWebViewShown = true;
}

From source file:com.dabay6.libraries.androidshared.ui.dialogs.changelog.util.ChangeLogDialogUtils.java

/**
 * @param context   {@link Context} used to retrieve resources.
 * @param assetName Name of the asset file containing the change log json.
 * @param style     The css style to be applied to the html.
 * @param callback  The callback to call upon dismissal of the change log alert dialog.
 *
 * @return {@link AlertDialog} used to display the change log.
 *//*from w w  w . j  a va  2  s .c om*/
public static AlertDialog createDialog(final Context context, final String assetName, final String style,
        final OnChangeLogDialogListener callback) {
    final AlertDialog.Builder builder;
    final Resources res = context.getResources();
    final String title = res.getString(R.string.change_log_title, AppUtils.getApplicationVersion(context));
    final WebSettings settings;
    final WebView web = new WebView(context);
    String html;

    try {
        html = getHtmlChangeLog(context, assetName, style);

        settings = web.getSettings();
        settings.setSupportZoom(false);
    } catch (final IOException ex) {
        html = StringUtils.empty();

        Logger.error(TAG, ex.getMessage(), ex);
    }

    web.loadData(html, "text/html", "utf-8");

    builder = new AlertDialog.Builder(context);
    builder.setTitle(title).setView(web).setPositiveButton(R.string.change_log_close,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    dialog.dismiss();
                    if (callback != null) {
                        callback.onChangeLogDismissed();
                    }
                }
            });

    return builder.create();
}

From source file:com.amgems.uwschedule.api.uw.LoginAuthenticator.java

private LoginAuthenticator(Context context, Handler handler, HttpClient httpClient, String username,
        String password) {//from  w  w  w.  ja  va2  s.com
    mUsername = username;
    mPassword = password;
    mCookiesValue = "";

    mHttpClient = httpClient;
    mLoadingFinished = false;
    mJsWebview = new WebView(context);
    mHandler = handler;
    CookieManager.getInstance().removeAllCookie();
    mJsWebview.getSettings().setJavaScriptEnabled(true);
    mJsWebview.addJavascriptInterface(new CaptureHtmBody(), CaptureHtmBody.INTERFACE_NAME);
    mJsWebview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            // If the page has been loaded before, then the WebView must have
            // returned from a JavaScript redirect required for
            // appropriate login cookies. This is when the html content
            // should be captured and processed
            if (mPageLoadCount >= 1)
                view.loadUrl(CaptureHtmBody.CAPTURE_HTML_SCRIPT);
            mPageLoadCount++;
        }
    });
}

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/*from   w ww . j av a  2  s  .c om*/
 * 
 * @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:com.twitter4rk.TwitterAuthFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mTwitterWebView = new WebView(getActivity());
    final Bundle args = getArguments();
    if (args == null) {
        // This wont be case because startTwitterAuth() handles args for
        // fragment
        throw new IllegalArgumentException(
                "No arguments passed to fragment, Please use startTwitterAuth(...) method for showing this fragment");
    }/*  w  w  w  . j  a v a 2  s . co m*/
    // Get builder from args
    mBuilder = args.getParcelable(BUILDER_KEY);
    // Hide action bar
    if (mBuilder.hideActionBar)
        mBuilder.activity.getActionBar().hide();
    // Init progress dialog
    mProgressDialog = new ProgressDialog(mBuilder.activity);
    mProgressDialog.setMessage(mBuilder.progressText == null ? "Loading ..." : mBuilder.progressText);
    if (mBuilder.isProgressEnabled)
        mProgressDialog.show();

    // Init ConfigurationBuilder twitter4j
    final ConfigurationBuilder cb = new ConfigurationBuilder();
    if (mBuilder.isDebugEnabled)
        cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey(mBuilder.consumerKey);
    cb.setOAuthConsumerSecret(mBuilder.consumerSecret);

    // Web view client to handler url loading
    mTwitterWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // Get url first
            final Uri uri = Uri.parse(url);
            // Check if we need to see for callback URL
            if (mBuilder.callbackUrl != null && url.contains(mBuilder.callbackUrl)) {
                // Get req info
                String oauthToken = uri.getQueryParameter("oauth_token");
                String oauthVerifier = uri.getQueryParameter("oauth_verifier");
                if (mListener != null)
                    mListener.onSuccess(oauthToken, oauthVerifier);
                if (mBuilder.isActionBarVisible && mBuilder.hideActionBar && getActivity() != null)
                    getActivity().getActionBar().show();
                mIsAuthenticated = true;
                removeMe();
                return true;
                // If no callback URL then check for info directly
            } else if (uri.getQueryParameter("oauth_token") != null
                    && uri.getQueryParameter("oauth_verifier") != null) {
                // Get req info
                String oauthToken = uri.getQueryParameter("oauth_token");
                String oauthVerifier = uri.getQueryParameter("oauth_verifier");
                if (mListener != null)
                    mListener.onSuccess(oauthToken, oauthVerifier);
                if (mBuilder.isActionBarVisible && mBuilder.hideActionBar && getActivity() != null)
                    getActivity().getActionBar().show();
                mIsAuthenticated = true;
                removeMe();
                return true;
                // If nothing then its failure
            } else {
                // Notify user
                if (mListener != null)
                    mListener.onFailure(
                            new Exception("Couldn't find the callback URL or oath parameters in response"));
                if (mBuilder.isActionBarVisible && mBuilder.hideActionBar && getActivity() != null)
                    getActivity().getActionBar().show();
                removeMe();
                return false;
            }
        }
    });
    // Web Crome client to handler progress dialog visibility
    mTwitterWebView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            if (newProgress == 100) {
                if (mProgressDialog.isShowing())
                    mProgressDialog.dismiss();
            }
        }
    });
    final Handler handler = new Handler();
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                final TwitterFactory twitterFactory = new TwitterFactory(cb.build());
                final Twitter twitter = twitterFactory.getInstance();
                RequestToken requestToken = null;
                if (mBuilder.callbackUrl == null)
                    requestToken = twitter.getOAuthRequestToken();
                else
                    requestToken = twitter.getOAuthRequestToken(mBuilder.callbackUrl);
                final RequestToken finalRequestToken = requestToken;
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        final String url = finalRequestToken.getAuthorizationURL();
                        mTwitterWebView.loadUrl(url);
                    }
                });
            } catch (TwitterException e) {
                e.printStackTrace();
            }
        }
    }).start();

    return mTwitterWebView;
}

From source file:com.chute.components.android.imagesharer.activity.DialogActivity.java

@Override
public View getWebView() {
    webView = new WebView(getApplicationContext());
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.setWebViewClient(new BaseWebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.setKeepScreenOn(true);//  w  w  w .  j  a  v  a 2s  .co  m
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setUserAgentString(
            "Mozilla/5.0 (Linux; U; Android 2.0; en-us; Droid Build/ESD20) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17");
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    FrameLayout frameLayout = new FrameLayout(getApplicationContext());
    frameLayout.setMinimumHeight(150);
    progressBar = new ProgressBar(getApplicationContext());
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(100, 100);
    layoutParams.gravity = Gravity.CENTER;
    progressBar.setLayoutParams(layoutParams);
    frameLayout.addView(webView);
    frameLayout.addView(progressBar);
    return frameLayout;
}

From source file:com.commonsware.android.print.MainActivity.java

private WebView getWebView() {
    if (wv == null) {
        wv = new WebView(this);
    }

    return (wv);
}

From source file:com.msopentech.thali.utilities.android.AndroidXmlHttpRequestTestActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    webView = new WebView(this);
    //TODO: Oh, this is all a huge security hole.
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setAllowFileAccessFromFileURLs(true);
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setAppCacheEnabled(true);
    webView.getSettings().setDatabaseEnabled(true);
    webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
    webView.getSettings().setAllowContentAccess(true);
    webView.getSettings().setLoadsImagesAutomatically(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }/* w  w w  . j a v  a 2s . c  o  m*/
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Log.e("xmlhttptest", "errorCode: " + errorCode + ", description: " + description + ", failingUrl: "
                    + failingUrl);
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    });
    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            Log.e("xmlhttptest", consoleMessage.message() + " - " + consoleMessage.messageLevel().toString()
                    + " - " + consoleMessage.lineNumber() + " - " + consoleMessage.sourceId());
            return false;
        }
    });

    bridgeManager = new AndroidBridgeManager(this, webView);
}

From source file:com.frublin.androidoauth2.FsDialog.java

private void setUpWebView() {
    mWebView = new WebView(getContext());
    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.setWebViewClient(new FsDialog.FsWebViewClient());
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.loadUrl(mUrl);/*from www. j  a  v  a  2 s .  co  m*/
    mWebView.setLayoutParams(FILL);
    mContent.addView(mWebView);
}