Example usage for android.webkit WebView stopLoading

List of usage examples for android.webkit WebView stopLoading

Introduction

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

Prototype

public void stopLoading() 

Source Link

Document

Stops the current load.

Usage

From source file:Main.java

public static void releaseWebView(WebView webview) {
    webview.stopLoading();
    webview.setWebChromeClient(null);// w ww  .  j a va 2  s.  c  o  m
    webview.setWebViewClient(null);
    webview.destroy();
    webview = null;
}

From source file:com.github.dfa.diaspora_android.util.Helpers.java

public static void showAspectList(final WebView wv, final App app) {
    wv.stopLoading();
    PodUserProfile profile = app.getPodUserProfile();
    StringBuffer sb = new StringBuffer();
    int intColor = ContextCompat.getColor(app, R.color.colorAccent);
    String strColor = String.format("#%06X", (0xFFFFFF & intColor));

    sb.append(//from w  w w .ja  v  a2 s.  c  o m
            "<html><body style='width:80%; margin-left:auto;margin-right:auto; font-size: 400%;'><center><b>");
    sb.append(String.format("<h1 style='color: %s; text-shadow: 4px 4px 12px #000000;'>%s</h1>", strColor,
            app.getString(R.string.jb_aspects)));
    sb.append("</b></center>");
    // Content
    for (PodAspect aspect : profile.getAspects()) {
        sb.append("&raquo; &nbsp;");
        sb.append(aspect.toHtmlLink(app));
        sb.append("</br></br>");
    }
    // End
    sb.append("</body></html>");
    wv.loadData(sb.toString(), "text/html", "UTF-16");
}

From source file:meizhi.meizhi.malin.utils.DestroyCleanUtil.java

@SuppressLint("ObsoleteSdkInt")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static void unBindView(View view) {
    if (view == null)
        return;/*from  www .  j av  a  2 s.c o m*/
    Drawable drawable;
    int i;
    //1.
    try {
        view.setOnClickListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //2.
    try {
        view.setOnCreateContextMenuListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //3.
    try {
        view.setOnFocusChangeListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //4.
    try {
        view.setOnKeyListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //5.
    try {
        view.setOnLongClickListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //6.
    try {
        view.setOnTouchListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //7.
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
            view.setOnApplyWindowInsetsListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //8.
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            view.setOnContextClickListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //9.
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            view.setOnScrollChangeListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //10.
    try {
        view.setOnDragListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //11.
    try {
        view.setOnGenericMotionListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //12.
    try {
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR2) {//13
            view.setOnHoverListener(null);
        }
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    //13.
    try {
        view.setOnSystemUiVisibilityChangeListener(null);
    } catch (Throwable e) {
        CrashReport.postCatchedException(e);
    }

    /**
     * @see SwipeRefreshLayout#onDetachedFromWindow()
     */
    if (view.getBackground() != null && !view.getClass().getName().equals(CIRCLE_CLASS)) {
        try {
            view.getBackground().setCallback(null);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {//16
                view.setBackgroundDrawable(null);
            } else {
                view.setBackground(null);
            }
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //ImageView
    if (view instanceof ImageView) {
        try {
            ImageView imageView = (ImageView) view;
            drawable = imageView.getDrawable();
            if (drawable != null) {
                drawable.setCallback(null);
            }
            imageView.setImageDrawable(null);
            imageView.setImageBitmap(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //TextView
    if (view instanceof TextView) {
        try {
            TextView textView = (TextView) view;
            textView.setCompoundDrawables(null, null, null, null);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                textView.setCompoundDrawablesRelative(null, null, null, null);
            }
            textView.setCursorVisible(false);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //ImageButton
    if (view instanceof ImageButton) {
        try {
            ImageButton imageButton = (ImageButton) view;
            drawable = imageButton.getDrawable();
            if (drawable != null) {
                drawable.setCallback(null);
            }
            imageButton.setImageDrawable(null);
            imageButton.setImageBitmap(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //ListView
    if (view instanceof ListView) {
        ListView listView = (ListView) view;

        try {
            listView.setAdapter(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnScrollListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnItemClickListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnItemLongClickListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }

        try {
            listView.setOnItemSelectedListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //RecyclerView
    if (view instanceof RecyclerView) {
        try {
            RecyclerView recyclerView = (RecyclerView) view;
            recyclerView.setAdapter(null);
            recyclerView.setChildDrawingOrderCallback(null);
            recyclerView.setOnScrollListener(null);
            recyclerView.addOnScrollListener(null);
            recyclerView.removeOnScrollListener(null);
            recyclerView.setRecyclerListener(null);
        } catch (Throwable e) {
            CrashReport.postCatchedException(e);
        }
    }

    //WebView
    if (view instanceof WebView) {

        WebView webView = (WebView) view;
        try {
            webView.stopLoading();
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.removeAllViews();
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.setWebChromeClient(null);
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.setWebViewClient(null);
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            webView.destroy();
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

        try {
            if (null != view.getParent() && view.getParent() instanceof ViewGroup) {
                ((ViewGroup) view.getParent()).removeView(view);
            }
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }

    }

    //SurfaceView
    if (view instanceof SurfaceView) {
        try {
            SurfaceView surfaceView = (SurfaceView) view;
            SurfaceHolder holder = surfaceView.getHolder();
            if (holder != null) {
                Surface surface = holder.getSurface();
                if (surface != null) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                        surface.release();
                    }
                }
            }
        } catch (Throwable ignored) {
            CrashReport.postCatchedException(ignored);
        }
    }

    view.destroyDrawingCache();
    view.clearAnimation();

    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        int childCount = (viewGroup).getChildCount();
        for (i = 0; i < childCount; i++) {
            unBindView((viewGroup).getChildAt(i));
        }
    }
}

From source file:com.just.agentweb.AgentWebUtils.java

static final void clearWebView(WebView m) {

    if (m == null) {
        return;//from   w  w w . java 2 s .  co  m
    }
    if (Looper.myLooper() != Looper.getMainLooper()) {
        return;
    }
    m.loadUrl("about:blank");
    m.stopLoading();
    if (m.getHandler() != null) {
        m.getHandler().removeCallbacksAndMessages(null);
    }
    m.removeAllViews();
    ViewGroup mViewGroup = null;
    if ((mViewGroup = ((ViewGroup) m.getParent())) != null) {
        mViewGroup.removeView(m);
    }
    m.setWebChromeClient(null);
    m.setWebViewClient(null);
    m.setTag(null);
    m.clearHistory();
    m.destroy();
    m = null;

}

From source file:com.jaspervanriet.huntingthatproduct.Activities.WebActivity.java

private void setupWebView() {
    mWebView.setWebViewClient(new WebViewClient() {
        @Override//w w  w.  j a v  a 2s.  co  m
        public void onLoadResource(WebView view, String url) {
            if (isPlayStoreLink(url)) {
                redirectToPlayStore(url);
                view.stopLoading();
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            getSupportActionBar().setTitle(mProductTitle);
            if (isPlayStoreLink(url)) {
                redirectToPlayStore(url);
            }
        }

        @Override
        public void onReceivedSslError(WebView view, @NonNull SslErrorHandler handler, SslError error) {
            Toast.makeText(WebActivity.this, getString(R.string.error_ssl), Toast.LENGTH_LONG).show();
        }
    });
    mWebView.loadUrl(mProductUrl);
    mWebView.getSettings().setBuiltInZoomControls(true);
    mWebView.getSettings().setDisplayZoomControls(false);
    mWebView.getSettings().setJavaScriptEnabled(true);
}

From source file:com.klinker.android.spotify.fragment.BaseOAuthFragment.java

/**
 * Set up the webview client that information should be displayed in
 *//*w w  w.j  a v  a 2  s  .c o  m*/
public WebViewClient getWebViewClient() {
    return new WebViewClient() {
        private boolean authComplete = false;

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            Log.v(TAG, "callback url: " + url);
            if (shouldRedirect(url)) {
                view.stopLoading();
                authComplete = processPageFinished(url, authComplete);
            }
        }
    };
}

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

private void closeWebViewAndNotify(final AuthorizationListener listener, final WebView webView) {
    webView.stopLoading();
    webView.loadData("", "text/html", null);
    listener.onAuthorizationDialogClose();
}

From source file:com.robandjen.comicsapp.FullscreenActivity.java

private void onCancel() {
    WebView wv = (WebView) findViewById(R.id.fullscreen_content);
    wv.stopLoading();
}

From source file:com.robandjen.comicsapp.FullscreenActivity.java

void showCurrentComic(String url) {
    if (url == null || url.isEmpty()) {
        url = mComicList.get(mCurComic).getURL();
    }// w ww  .j  a  va2 s  .  c  o m

    final WebView contentView = (WebView) findViewById(R.id.fullscreen_content);
    contentView.stopLoading();

    //Load about:blank to clear any extra data and have a well defined URL in history
    contentView.loadUrl("about:blank");
    contentView.loadUrl(url);
    contentView.clearHistory();
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setTitle(mComicList.get(mCurComic).getName());
    }
    updateShare(url);

    ExpandableListView elv = (ExpandableListView) findViewById(R.id.comic_drawer);
    long packedPos = mAdapter.comicsPosToPackedPos(mCurComic);

    //Selection doesn't work if expandGroup isn't called or group already expanded. ?????
    elv.expandGroup(ExpandableListView.getPackedPositionGroup(packedPos));
    elv.setSelectedChild(ExpandableListView.getPackedPositionGroup(packedPos),
            ExpandableListView.getPackedPositionChild(packedPos), true);
    elv.setItemChecked(elv.getFlatListPosition(packedPos), true);
}

From source file:com.ubikod.urbantag.ContentViewerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle extras = getIntent().getExtras();

    /* If we are coming from Notification delete notification */
    if (extras.getInt(NotificationHelper.FROM_NOTIFICATION, -1) == NotificationHelper.NEW_CONTENT_NOTIF) {
        NotificationHelper notificationHelper = new NotificationHelper(this);
        notificationHelper.closeContentNotif();
    } else if (extras.getInt(NotificationHelper.FROM_NOTIFICATION, -1) == NotificationHelper.NEW_PLACE_NOTIF) {
        NotificationHelper notificationHelper = new NotificationHelper(this);
        notificationHelper.closePlaceNotif();
    }/*  ww w  .  ja  v a 2  s . c  o m*/

    /* Fetch content info */
    ContentManager contentManager = new ContentManager(new DatabaseHelper(this, null));
    Log.i(UrbanTag.TAG, "View content : " + extras.getInt(CONTENT_ID));
    this.content = contentManager.get(extras.getInt(CONTENT_ID));
    if (this.content == null) {
        Toast.makeText(this, R.string.error_occured, Toast.LENGTH_SHORT).show();
        finish();
        return;
    }
    setTitle(content.getName());
    com.actionbarsherlock.app.ActionBar actionBar = this.getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    setContentView(R.layout.content_viewer);

    /* Find webview and create url for content */
    final WebView webView = (WebView) findViewById(R.id.webview);
    final String URL = UrbanTag.API_URL + ACTION_GET_CONTENT.replaceAll("%", "" + this.content.getId());

    /* Display progress animation */
    final ProgressDialog progress = ProgressDialog.show(this, "",
            this.getResources().getString(R.string.loading_content), false, true,
            new DialogInterface.OnCancelListener() {

                @Override
                public void onCancel(DialogInterface dialog) {
                    timeOutHandler.interrupt();
                    webView.stopLoading();
                    ContentViewerActivity.this.finish();
                }

            });

    /* Go fetch content */
    contentFetcher = new Thread(new Runnable() {

        DefaultHttpClient httpClient;

        @Override
        public void run() {
            Looper.prepare();
            Log.i(UrbanTag.TAG, "Fetching content...");
            httpClient = new DefaultHttpClient();
            try {
                String responseBody = httpClient.execute(new HttpGet(URL), new BasicResponseHandler());
                webView.loadDataWithBaseURL("fake://url/for/encoding/hack...", responseBody, mimeType, encoding,
                        "");
                timeOutHandler.interrupt();
                if (progress.isShowing())
                    progress.dismiss();
            } catch (ClientProtocolException cpe) {
                new Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), R.string.error_loading_content,
                                Toast.LENGTH_SHORT).show();
                    }
                });
                timeOutHandler.interrupt();
                progress.cancel();
            } catch (IOException ioe) {
                new Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), R.string.error_loading_content,
                                Toast.LENGTH_SHORT).show();
                    }
                });
                timeOutHandler.interrupt();
                progress.cancel();
            }

            Looper.loop();
        }

    });
    contentFetcher.start();

    /* TimeOut Handler */
    timeOutHandler = new Thread(new Runnable() {
        private int INCREMENT = 1000;

        @Override
        public void run() {
            Looper.prepare();
            try {
                for (int time = 0; time < TIMEOUT; time += INCREMENT) {
                    Thread.sleep(INCREMENT);
                }

                Log.w(UrbanTag.TAG, "TimeOut !");
                new Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), R.string.error_loading_content,
                                Toast.LENGTH_SHORT).show();
                    }
                });

                contentFetcher.interrupt();
                progress.cancel();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            Looper.loop();

        }

    });
    timeOutHandler.start();

}