Progress bar continua depois de Pagina web carregar
27/05/2016
0
fiz um webview e coloquei uma progress bar enquanto a pagina era carregada, mas como o site tem bastante redirecionamento a barra fica la infinitamente, como resolver isso ?
package com.libertynetworkbrasil.libertynetwork; import android.app.ProgressDialog; import android.content.ActivityNotFoundException; import android.content.Intent; import android.graphics.Bitmap; import android.net.Uri; import android.net.http.SslError; import android.os.Bundle; import android.os.Handler; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.view.KeyEvent; import android.view.View; import android.support.design.widget.NavigationView; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.webkit.SslErrorHandler; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import java.util.TimerTask; public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { //iniciando webview private WebView mwebview; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); //webview mwebview=(WebView)findViewById(R.id.meuwebView); WebSettings webSettings = mwebview.getSettings(); webSettings.setJavaScriptEnabled(true); //melhorando perfomace do webview mwebview.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH); mwebview.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); mwebview.getSettings().setAppCacheEnabled(true); mwebview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); webSettings.setDomStorageEnabled(true); webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); webSettings.setUseWideViewPort(true); webSettings.setSavePassword(true); webSettings.setSaveFormData(true); webSettings.setEnableSmoothTransition(true); mwebview.loadUrl("https://liberty.division.yt"); //força abrir pagina no app mwebview.setWebViewClient(new MyWebviewClient()); } @Override public void onBackPressed() { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else { super.onBackPressed(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { Intent sobre = new Intent(this, sobre.class); startActivity(sobre); return true; } return super.onOptionsItemSelected(item); } @SuppressWarnings("StatementWithEmptyBody") @Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.site) { mwebview.loadUrl("http://libertynetworkbrasil.com"); } else if (id == R.id.painel) { mwebview.loadUrl("https://liberty.division.yt/pt"); } else if (id == R.id.pagamentos) { mwebview.loadUrl("https://liberty.division.yt/pt/payments"); } else if (id == R.id.aplicativos) { mwebview.loadUrl("https://liberty.division.yt/pt/apps"); } else if (id == R.id.config) { mwebview.loadUrl("https://liberty.division.yt/pt/settings"); } else if (id == R.id.youtube) { Intent intent=null; try { intent =new Intent(Intent.ACTION_VIEW); intent.setPackage("com.google.android.youtube"); intent.setData(Uri.parse("http://www.youtube.com/user/NetworkLiberty")); startActivity(intent); } catch (ActivityNotFoundException e) { intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://www.youtube.com/user/NetworkLiberty")); startActivity(intent); } }else if (id == R.id.faq) { mwebview.loadUrl("https://libertynetworkbrasil.freshdesk.com/support/home"); }else if (id == R.id.email) { Intent send = new Intent(Intent.ACTION_SENDTO); String uriText = "mailto:" + Uri.encode("suporte@libertynetworkbrasil.com"); Uri uri = Uri.parse(uriText); send.setData(uri); startActivity(Intent.createChooser(send, "Enviar email com...")); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; } boolean loadingFinished = true; boolean redirect = false; private class MyWebviewClient extends WebViewClient { @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.proceed(); // Ignore SSL certificate errors } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { mwebview.loadUrl(url); return true; } //ProgressDialogue ProgressDialog pd = null; @Override public void onPageStarted (WebView view, String url, Bitmap favicon){ pd = new ProgressDialog(MainActivity.this); pd.setTitle("Aguarde"); pd.setMessage("Carregando.."); pd.show(); super.onPageStarted(view, url, favicon); } @Override public void onPageFinished (WebView view, String url){ pd.dismiss(); super.onPageFinished(view, url); } } //voltar se apertar botao voltar @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: if (mwebview.canGoBack()) { mwebview.goBack(); } else { finish(); } return true; } } return super.onKeyDown(keyCode, event); } }
Igor Oliveira
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)