package appsmate.com.unclick;
import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AlertDialog; 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.KeyEvent; import android.view.MenuItem; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private String url_Ini = "http://unclickcapilla.esy.es/";
private String url_Almacen = "http://unclickcapilla.esy.es/almacen.html";
private String url_Carniceria = "http://unclickcapilla.esy.es/carniceria.html";
private String url_Verduleria = "http://unclickcapilla.esy.es/verduleria.html";
private String url_Indumentaria = "http://unclickcapilla.esy.es/indumentaria.html";
private String url_Resto = "http://unclickcapilla.esy.es/restoranparrillas.html";
private String url_Delivery =package "http://unclickcapilla.esyappsmate.es/deliverycom.html";unclick;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
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.KeyEvent;
import android.view.MenuItem;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
privatepublic ProgressDialogclass mProgressDialog;MainActivity extends AppCompatActivity
private WebView webviewsi; implements NavigationView.OnNavigationItemSelectedListener {
private String url_Ini = "http://unclickcapilla.esy.es/";
private String url_Almacen = "http://unclickcapilla.esy.es/almacen.html";
private String url_Carniceria = "http://unclickcapilla.esy.es/carniceria.html";
private String url_Verduleria = "http://unclickcapilla.esy.es/verduleria.html";
private String url_Indumentaria = "http://unclickcapilla.esy.es/indumentaria.html";
private String url_Resto = "http://unclickcapilla.esy.es/restoranparrillas.html";
private String url_Delivery = "http://unclickcapilla.esy.es/delivery.html";
@Override
protected void onCreate(Bundle savedInstanceState) {
private ProgressDialog mProgressDialog;
super.onCreate(savedInstanceState);
private WebView setContentView(R.layout.activity_main);webviewsi;
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);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mProgressDialog = new ProgressDialog(this);
webviewsi = (WebView) findViewById(R.id.webviewsi);
WebSettings websetting = webviewsi.getSettings();
websetting.setJavaScriptEnabled(true);
websetting.setSupportZoom(true);
websetting.setDisplayZoomControls(false);
webviewsi.setWebViewClient(new WebViewClient Toolbar toolbar = (Toolbar) {findViewById(R.id.toolbar);
publicsetSupportActionBar(toolbar);
void onReceivedError(WebView webView, int errorCode, String description, StringDrawerLayout failingUrldrawer = (DrawerLayout) {findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = trynew {ActionBarDrawerToggle(
webViewthis, drawer, toolbar, R.stopLoading(string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
} catch (Exception e) {toggle.syncState();
NavigationView navigationView = (NavigationView) }findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
if (webviewsi.canGoBack()) {
webviewsi.goBack();
}
mProgressDialog = new webView.loadUrlProgressDialog("about:blank"this);
AlertDialog alertDialogwebviewsi = new(WebView) AlertDialog.BuilderfindViewById(MainActivityR.this)id.create(webviewsi);
WebSettings websetting = alertDialogwebviewsi.setTitlegetSettings("Error");
alertDialogwebsetting.setMessagesetJavaScriptEnabled("Necesitamos estar conectadostrue);
a una red para mostrarte el contenido ..websetting. :setSupportZoom("true);
websetting.setDisplayZoomControls(false);
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "De nuevo", new DialogInterfacewebviewsi.OnClickListenersetWebViewClient(new WebViewClient() {
public void onClickonReceivedError(DialogInterfaceWebView dialogwebView, int whicherrorCode, String description, String failingUrl) {
try {
finish webView.stopLoading();
} catch startActivity(getIntent()Exception e); {
}
});
alertDialog if (webviewsi.showcanGoBack();) {
super.onReceivedError(webView, errorCode, description, failingUrl webviewsi.goBack();
}
});
webView.loadUrl("about:blank");
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("Error");
alertDialog.setMessage("Necesitamos estar conectados a una red para mostrarte el contenido ... :(");
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "De nuevo", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
startActivity(getIntent());
}
});
alertDialog.show();
super.onReceivedError(webView, errorCode, description, failingUrl);
}
});
webviewsi.setWebChromeClient(new WebChromeClient() {
@Override
webviewsi.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int progress) {
mProgressDialog.setTitle("Un momento...");
mProgressDialog.setMessage("Solicitando contenido a la base de datos ...");
mProgressDialog.setProgress(0);
mProgressDialog.show();
MainActivity.this.setProgress(progress * 1000);
mProgressDialog.incrementProgressBy(progress);
if (progress == 100) {
mProgressDialog.dismiss();
}
}
}
});
webviewsi.loadUrl(url_Ini);
}
@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 onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.portada) {
webviewsi.getSettings();
webviewsi.loadUrl(url_Ini);
}
if (id == R.id.almacen) {
webviewsi.getSettings();
webviewsi.loadUrl(url_Almacen);
}
if (id == R.id.caniceria) {
webviewsi.getSettings();
webviewsi.loadUrl(url_Carniceria);
}
if (id == R.id.verduleria) {
webviewsi.getSettings();
webviewsi.loadUrl(url_Verduleria);
}
if (id == R.id.indumentaria) {
webviewsi.getSettings();
webviewsi.loadUrl(url_Indumentaria);
}
if (id == R.id.resto) {
webviewsi.getSettings();
webviewsi.loadUrl(url_Resto);
}
if (id == R.id.delivery) {
webviewsi.getSettings();
webviewsi.loadUrl(url_Delivery);
}
if (id == R.id.autos) {
Intent intent = new Intent (this, Autos.class);
startActivity(intent);
} else if (id == R.id.motos) {
Intent intent = new Intent (this, Motos.class);
startActivity(intent);
} else if (id == R.id.nav_empleos) {
Intent intent = new Intent (this, Empleos.class);
startActivity(intent);
}
else if (id == R.id.comidas)
{
Intent intent = new Intent (this, ParaComer.class);
startActivity(intent);
}
else if (id == R.id.hogar) {
Intent intent = new Intent (this, Hogar.class);
startActivity(intent);
} else if (id == R.id.saludybelleza) {
Intent intent = new Intent (this, SaludYBelleza.class);
startActivity(intent);
}
else if (id == R.id.telefonia) {
Intent intent = new Intent (this, Telefonos.class);
startActivity(intent);
}
else if (id == R.id.campoymascotas) {
Intent intent = new Intent (this, CampoyMascotas.class);
startActivity(intent);
}
else if (id == R.id.alquileres) {
Intent intent = new Intent (this, Alquileres.class);
startActivity(intent);
}
else if (id == R.id.corralon) {
Intent intent = new Intent (this, Corralon.class);
startActivity(intent);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && webviewsi.canGoBack()) {
webviewsi.goBack();
return true;
}
// If it wasn't the Back key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
return super.onKeyDown(keyCode, event);
}
// If it wasn't the Back key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
return super.onKeyDown(keyCode, event);
}
}