Example usage for android.webkit ConsoleMessage lineNumber

List of usage examples for android.webkit ConsoleMessage lineNumber

Introduction

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

Prototype

public int lineNumber() 

Source Link

Usage

From source file:com.androidquery.simplefeed.PQuery.java

private void debug(WebView wv) {
    wv.setWebChromeClient(new WebChromeClient() {
        public boolean onConsoleMessage(ConsoleMessage cm) {
            AQUtility.debug(cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
            return true;
        }/* ww w  . ja v a  2s.c o  m*/
    });
}

From source file:org.quizreader.android.PageReadActivity.java

/** Called when the activity is first created. */
@SuppressLint("SetJavaScriptEnabled")
@Override/*from w w  w. ja  v  a2s  .c  o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.page_read);
    // immediately pop up loading dialog
    dialog = new ProgressDialog(this);
    dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    dialog.setMessage("loading page");
    dialog.show();
    // set up webview
    WebView webview = (WebView) findViewById(R.id.webView);
    webview.setWebViewClient(new QRWebViewClient());
    webview.setWebChromeClient(new WebChromeClient() {
        public boolean onConsoleMessage(ConsoleMessage cm) {
            Log.d("QuizReader", cm.message() + ", line " + cm.lineNumber() + " " + cm.sourceId());
            return true;
        }
    });
    WebSettings webSettings = webview.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webview.addJavascriptInterface(new QuizReaderInterface(), "qr");
    try {
        random = new Random();
        wordDao = new WordDao(this);
        qzzFile = new QzzFile(title.getFilepath(), this);
        URL htmlURL = qzzFile.getHTML(title.getId(), title.getSection());
        if (htmlURL == null) { // beyond the last section
            setResult(RESULT_END_TITLE);
            finish();
        }
        String externalForm = htmlURL.toExternalForm();
        webview.loadUrl(externalForm + "?paragraph=" + title.getParagraph());
    } catch (Exception ex) {
        webview.loadData(ex.toString(), "text/plain", null);
    }
}

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 a2s .  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:gov.whitehouse.ui.fragments.app.ArticleViewerFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.article_view, container, false);

    mWebView = (WebView) v.findViewById(R.id.webview);
    mProgressBar = (ProgressBar) v.findViewById(R.id.progress);

    mWebView.getSettings().setJavaScriptEnabled(true);
    // enabling plugins may yield a better result for YouTube videos
    mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);

    mWebView.setWebChromeClient(new WebChromeClient() {
        public boolean onConsoleMessage(ConsoleMessage cm) {
            Log.d(TAG, cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
            return true;
        }//from  w  ww.  j  a  va  2 s  .c  o  m
    });

    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Log.e(TAG, "Error in WebView: " + failingUrl + "; " + description);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            mProgressBar.setVisibility(View.INVISIBLE);
            mWebView.setVisibility(View.VISIBLE);
            Log.d(TAG, "page finished: " + url);

            if (url.equals(PAGE_TEMPLATE_URL)) {
                view.loadUrl(String.format("javascript:WhiteHouse.loadPage(%s);", mPageInfo.toString()));
            }
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.contains("youtube.com/")) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(intent);
                return true;
            }
            return false;
        }
    });

    return v;
}

From source file:org.apache.cordova.AndroidChromeClient.java

@TargetApi(8)
@Override//from ww  w  .ja v a 2 s  .  c  o m
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
    if (consoleMessage.message() != null)
        LOG.d(TAG, "%s: Line %d : %s", consoleMessage.sourceId(), consoleMessage.lineNumber(),
                consoleMessage.message());
    return super.onConsoleMessage(consoleMessage);
}

From source file:de.storyquest.client.ContentActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // enable immersive mode
    getWindow().getDecorView()// w  w  w. j a  v a2s.  c o  m
            .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

    // load initial layout
    setContentView(R.layout.activity_content);
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    View header = navigationView.getHeaderView(0);

    // apply theme
    try {
        Drawable d = Drawable.createFromStream(getAssets().open("sidebar.jpg"), null);
        navigationView.setBackground(d);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    // wire the drawer open event to the character sheet refresh
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer != null) {
        drawer.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                execJavaScriptInCharactersheet("if(typeof refresh!='undefined')refresh()");
            }
        });
    }

    // get extra data with bookmark to load
    Intent intent = getIntent();
    if (intent.hasExtra(BOOKMARKID))
        bookmarkId = intent.getStringExtra(BOOKMARKID);

    // set the cover image from assets
    ImageView coverImage = (ImageView) header.findViewById(R.id.coverImage);
    try {
        InputStream ims = getAssets().open("cover.png");
        Drawable d = Drawable.createFromStream(ims, null);
        coverImage.setImageDrawable(d);
    } catch (Exception e) {
        throw new RuntimeException("Error loading cover image. Is 'cover.png' available in assets?", e);
    }

    // make the web content debuggable from external chrome tools
    WebView.setWebContentsDebuggingEnabled(true);

    // enable script interfaces
    scriptSystem = new ScriptSystem(this);
    scriptStorage = new ScriptStorage(this,
            getApplicationContext().getSharedPreferences(ScriptStorage.CONTEXT, Context.MODE_PRIVATE));
    scriptSound = new ScriptSound(this);
    scriptGameServices = new ScriptGameServices(this);

    // setup character webview
    character = (WebView) header.findViewById(R.id.characterView);
    character.getSettings().setJavaScriptEnabled(true);
    character.getSettings().setDomStorageEnabled(true);
    character.getSettings().setAllowFileAccess(true);
    character.getSettings().setAppCacheEnabled(true);
    character.addJavascriptInterface(scriptSystem, "sqSystem");
    character.addJavascriptInterface(scriptStorage, "nativeStorage");
    character.addJavascriptInterface(scriptSound, "sqSound");
    character.addJavascriptInterface(scriptGameServices, "sqGameServices");
    character.loadUrl("file:///android_asset/character.html");

    // setup web view
    web = (WebView) findViewById(R.id.webView);
    web.getSettings().setJavaScriptEnabled(true);
    web.getSettings().setDomStorageEnabled(true);
    web.getSettings().setAllowFileAccess(true);
    web.getSettings().setAppCacheEnabled(true);
    web.addJavascriptInterface(scriptSystem, "sqSystem");
    web.addJavascriptInterface(scriptStorage, "nativeStorage");
    web.addJavascriptInterface(scriptSound, "sqSound");
    web.addJavascriptInterface(scriptGameServices, "sqGameServices");

    // adding event overrides for the web view
    web.setWebChromeClient(new WebChromeClient());
    web.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String urlText) {
            if (urlText.startsWith("http")) { // Could be cleverer and use a regex
                Log.d(LOGTAG, "Opening standard web intent window for " + urlText);
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(urlText));
                startActivity(i);
                return true;
            } else {
                Log.d(LOGTAG, "Loading in webview: " + urlText);
                web.loadUrl(urlText);
                return true;
            }
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            Log.d(LOGTAG, "Page rendering started: " + url + ".");
            displaySpinner(R.string.loading);
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            Log.d(LOGTAG, "Page rendering finished: " + url + ".");
            hideSpinner();
            if (bookmarkId != null && url.startsWith("file:///android_asset/content.html")) {
                Log.i(LOGTAG, "Loading bookmark " + bookmarkId + ".");
                execJavaScriptInContent("loadBookmark('" + bookmarkId + "')");
                bookmarkId = null;
            }
            super.onPageFinished(view, url);
        }

        @Override
        public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
            Log.d(LOGTAG, "Intercepted call: " + url + ".");
            return null;
        }
    });
    web.setWebChromeClient(new WebChromeClient() {
        public boolean onConsoleMessage(ConsoleMessage cm) {
            Log.d(LOGTAG, cm.message() + " - from line " + cm.lineNumber() + " of " + cm.sourceId());
            return true;
        }
    });
    web.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
    web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    web.requestFocus(View.FOCUS_DOWN);

    // finally loading content bootstrap
    Log.i(LOGTAG, "Loading index.html");
    web.loadUrl("file:///android_asset/index.html");
}

From source file:com.muzima.view.forms.FormWebViewActivity.java

private WebChromeClient createWebChromeClient() {
    return new WebChromeClient() {
        @Override//  ww w  .  j  a  v  a 2  s.  c  o m
        public void onProgressChanged(WebView view, int progress) {
            FormWebViewActivity.this.setProgress(progress * 1000);
            if (progress == 100) {
                progressDialog.dismiss();
            }
        }

        @Override
        public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            String message = format("Javascript Log. Message: {0}, lineNumber: {1}, sourceId, {2}",
                    consoleMessage.message(), consoleMessage.lineNumber(), consoleMessage.sourceId());
            if (consoleMessage.messageLevel() == ERROR) {
                Log.e(TAG, message);
            } else {
                Log.d(TAG, message);
            }
            return true;
        }
    };
}

From source file:com.google.android.apps.paco.FeedbackActivity.java

private void setWebChromeClientThatHandlesAlertsAsDialogs() {
    webView.setWebChromeClient(new WebChromeClient() {
        @Override/*  w w  w  .j a v  a 2 s  .  c om*/
        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {

            new AlertDialog.Builder(view.getContext()).setMessage(message).setCancelable(true)
                    .setPositiveButton(R.string.ok, new Dialog.OnClickListener() {

                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }

                    }).create().show();
            result.confirm();
            return true;
        }

        public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
            if (url.contains("file:///android_asset/map.html")) {
                if (showDialog == false) {
                    result.confirm();
                    return true;
                } else {
                    new AlertDialog.Builder(view.getContext()).setMessage(message).setCancelable(true)
                            .setPositiveButton(R.string.ok, new Dialog.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    showDialog = false;
                                    dialog.dismiss();
                                    result.confirm();
                                }
                            }).setNegativeButton(R.string.cancel_button, new Dialog.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    result.cancel();
                                }
                            }).create().show();
                    return true;
                }
            }
            return super.onJsConfirm(view, url, message, result);
        }

        @Override
        public void onConsoleMessage(String message, int lineNumber, String sourceID) {
            Log.d(PacoConstants.TAG, message + " -- From line " + lineNumber + " of " + sourceID);
        }

        @Override
        public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            Log.d(PacoConstants.TAG, "*" + consoleMessage.message() + " -- From line "
                    + consoleMessage.lineNumber() + " of " + consoleMessage.sourceId());
            return true;
        }

    });
}

From source file:com.quarterfull.newsAndroid.NewsDetailFragment.java

@SuppressLint("SetJavaScriptEnabled")
private void init_webView() {
    int backgroundColor = ColorHelper.getColorFromAttribute(getContext(), R.attr.news_detail_background_color);
    mWebView.setBackgroundColor(backgroundColor);

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(false);
    webSettings.setSupportMultipleWindows(false);
    webSettings.setSupportZoom(false);//  w w  w  .j a  va2s  .  c  o  m
    webSettings.setAppCacheEnabled(true);

    registerForContextMenu(mWebView);

    mWebView.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onConsoleMessage(ConsoleMessage cm) {
            Log.v(TAG, cm.message() + " at " + cm.sourceId() + ":" + cm.lineNumber());
            return true;
        }

        @Override
        public void onProgressChanged(WebView view, int progress) {
            if (progress < 100 && mProgressbarWebView.getVisibility() == ProgressBar.GONE) {
                mProgressbarWebView.setVisibility(ProgressBar.VISIBLE);
            }
            mProgressbarWebView.setProgress(progress);
            if (progress == 100) {
                mProgressbarWebView.setVisibility(ProgressBar.GONE);

                //The following three lines are a workaround for websites which don't use a background color
                int bgColor = ContextCompat.getColor(getContext(),
                        R.color.slider_listview_text_color_dark_theme);
                NewsDetailActivity ndActivity = ((NewsDetailActivity) getActivity());
                mWebView.setBackgroundColor(bgColor);
                ndActivity.mViewPager.setBackgroundColor(bgColor);

                if (ThemeChooser.isDarkTheme(getActivity())) {
                    mWebView.setBackgroundColor(
                            ContextCompat.getColor(getContext(), android.R.color.transparent));
                }
            }
        }
    });

    mWebView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            if (changedUrl) {
                changedUrl = false;

                if (!url.equals("file:///android_asset/") && (urls.isEmpty() || !urls.get(0).equals(url))) {
                    urls.add(0, url);

                    Log.v(TAG, "Page finished (added): " + url);
                }
            }

            super.onPageStarted(view, url, favicon);
        }
    });

    mWebView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (v.getId() == R.id.webview && event.getAction() == MotionEvent.ACTION_DOWN) {
                changedUrl = true;
            }

            return false;
        }
    });
}

From source file:com.muzima.view.forms.HTMLFormWebViewActivity.java

private WebChromeClient createWebChromeClient() {
    return new WebChromeClient() {
        @Override/*from   w  ww  .  j  a  v  a  2 s.  c  o  m*/
        public void onProgressChanged(WebView view, int progress) {
            HTMLFormWebViewActivity.this.setProgress(progress * 1000);
            if (progress == 100) {
                progressDialog.dismiss();
            }
        }

        @Override
        public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            String message = format("Javascript Log. Message: {0}, lineNumber: {1}, sourceId, {2}",
                    consoleMessage.message(), consoleMessage.lineNumber(), consoleMessage.sourceId());
            if (consoleMessage.messageLevel() == ERROR) {
                Log.e(TAG, message);
            } else {
                Log.d(TAG, message);
            }
            return true;
        }
    };
}