Created
July 31, 2013 09:16
-
-
Save yava555/6120617 to your computer and use it in GitHub Desktop.
ProgressWebView WebView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.cleanmaster.photosync.widget; | |
import android.content.Context; | |
import android.util.AttributeSet; | |
import android.webkit.WebView; | |
import android.widget.ProgressBar; | |
public class ProgressWebView extends WebView { | |
private ProgressBar mProgressbar; | |
public ProgressWebView(Context context) { | |
super(context); | |
addProgressBar(); | |
setWebChromeClient(new WebChromeClient()); | |
} | |
public ProgressWebView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
addProgressBar(); | |
setWebChromeClient(new WebChromeClient()); | |
} | |
public ProgressWebView(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
addProgressBar(); | |
setWebChromeClient(new WebChromeClient()); | |
} | |
@SuppressWarnings("deprecation") | |
private void addProgressBar() { | |
mProgressbar = new ProgressBar(getContext(), null, android.R.attr.progressBarStyleHorizontal); | |
mProgressbar.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 3, 0, 0)); | |
addView(mProgressbar); | |
} | |
public class WebChromeClient extends android.webkit.WebChromeClient { | |
@Override | |
public void onProgressChanged(WebView view, int newProgress) { | |
if (newProgress == 100) { | |
mProgressbar.setVisibility(GONE); | |
} else { | |
if (mProgressbar.getVisibility() == GONE) | |
mProgressbar.setVisibility(VISIBLE); | |
mProgressbar.setProgress(newProgress); | |
} | |
super.onProgressChanged(view, newProgress); | |
} | |
} | |
@SuppressWarnings("deprecation") | |
@Override | |
protected void onScrollChanged(int l, int t, int oldl, int oldt) { | |
LayoutParams lp = (LayoutParams) mProgressbar.getLayoutParams(); | |
lp.x = l; | |
lp.y = t; | |
mProgressbar.setLayoutParams(lp); | |
super.onScrollChanged(l, t, oldl, oldt); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment