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 f82f4a5 commit 01c2fd7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

<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 @@ -3,7 +3,6 @@
import android.app.Activity;
import android.content.ClipboardManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -18,7 +17,6 @@ public class HtmlViewerActivity extends Activity
{
MyWebView mWebView;
ProgressBar pgb;
Uri uri;

@Override
protected void onCreate(Bundle savedInstanceState)
Expand All @@ -29,22 +27,25 @@ protected void onCreate(Bundle savedInstanceState)
mWebView = (MyWebView) findViewById(R.id.mwv_webview);
pgb = (ProgressBar) findViewById(R.id.pgb_webview);

uri = getIntent().getData();

mWebView.setWebChromeClient(
new WebChromeClient()
{
@Override
public void onProgressChanged(WebView view, int progress)
{
pgb.setProgress(progress);
if(progress == 100)
if(progress < 100)
{
setTitle("Loading...");
pgb.setVisibility(View.VISIBLE);
}else
{
setTitle(uri.getLastPathSegment());
setTitle(mWebView.getTitle());
pgb.setVisibility(View.GONE);
}
}
});
mWebView.loadUrl(uri.toString());
mWebView.loadUrl(getIntent().getData().toString());
}

@Override
Expand All @@ -66,13 +67,13 @@ public boolean onOptionsItemSelected(MenuItem item)
Intent it = new Intent(Intent.ACTION_VIEW);
it.addCategory(Intent.CATEGORY_DEFAULT);
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
it.setDataAndType(uri, "text/html");
it.setDataAndType(getIntent().getData(), "text/html");
startActivity(Intent.createChooser(it, "Choose a browser"));
break;

case 2:
ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
cm.setText(uri.toString());
cm.setText(mWebView.getUrl());
Toast.makeText(this, "Copy success", 0).show();
break;

Expand Down

0 comments on commit 01c2fd7

Please sign in to comment.