Skip to content

Commit

Permalink
浏览器增加进度条
Browse files Browse the repository at this point in the history
  • Loading branch information
pansong291 committed Oct 16, 2019
1 parent d30eb01 commit f82f4a5
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 17 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

<activity
android:name=".ui.HtmlViewerActivity"
android:label="Loading..."
android:resizeableActivity="true"/>

</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,44 @@
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ProgressBar;
import android.widget.Toast;
import pansong291.xposed.quickenergy.R;

public class HtmlViewerActivity extends Activity
{
private MyWebView mWebView;
private Uri uri;
MyWebView mWebView;
ProgressBar pgb;
Uri uri;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mWebView = new MyWebView(this);
setContentView(mWebView);
setContentView(R.layout.activity_html_viewer);

mWebView = (MyWebView) findViewById(R.id.mwv_webview);
pgb = (ProgressBar) findViewById(R.id.pgb_webview);

uri = getIntent().getData();

mWebView.setWebChromeClient(
new WebChromeClient()
{
public void onProgressChanged(WebView view, int progress)
{
pgb.setProgress(progress);
if(progress == 100)
{
setTitle(uri.getLastPathSegment());
pgb.setVisibility(View.GONE);
}
}
});
mWebView.loadUrl(uri.toString());
setTitle(uri.getLastPathSegment());
}

@Override
Expand Down
47 changes: 35 additions & 12 deletions app/src/main/java/pansong291/xposed/quickenergy/ui/MyWebView.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pansong291.xposed.quickenergy.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
Expand All @@ -10,6 +11,28 @@ public class MyWebView extends WebView
public MyWebView(Context c)
{
super(c);
defInit();
}
public MyWebView(Context context, AttributeSet attrs)
{
super(context, attrs);
defInit();
}

public MyWebView(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
defInit();
}

public MyWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
{
super(context, attrs, defStyleAttr, defStyleRes);
defInit();
}

private void defInit()
{
getSettings().setSupportZoom(true);
getSettings().setBuiltInZoomControls(true);
getSettings().setDisplayZoomControls(false);
Expand All @@ -23,19 +46,19 @@ public MyWebView(Context c)
public void onPageFinished(WebView view, String url)
{
if(url.endsWith(".log"))
postDelayed(
new Runnable()
{
@Override
public void run()
postDelayed(
new Runnable()
{
if(Thread.interrupted()) return;
if(getContentHeight() == 0)
postDelayed(this, 100);
else
scrollToBottom();
}
}, 500);
@Override
public void run()
{
if(Thread.interrupted()) return;
if(getContentHeight() == 0)
postDelayed(this, 100);
else
scrollToBottom();
}
}, 500);
}
});
}
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/res/layout/activity_html_viewer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<pansong291.xposed.quickenergy.ui.MyWebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mwv_webview"/>

<ProgressBar
android:layout_width="match_parent"
style="?android:attr/progressBarStyleHorizontal"
android:layout_height="wrap_content"
android:id="@+id/pgb_webview"/>

</RelativeLayout>

0 comments on commit f82f4a5

Please sign in to comment.