Android WebView Customization

Jyotishgher Astrology
By -
0
Android WebView Customization


package nanoakhi.rcfinternal.volley.coaches;

import nanoakhi.rcfinternal.R;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Display;
import android.view.MenuItem;
import android.webkit.WebSettings.ZoomDensity;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class ListCoachesWebView extends Activity {



WebView ourBrow;

/** Called when the activity is first created. */
@SuppressWarnings("deprecation")
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webcalculator);





       //SETTING DISPLAY PROPERTIES
Display display = getWindowManager().getDefaultDisplay();

final int version = android.os.Build.VERSION.SDK_INT;
final int width;
if (version >= 13) {
Point size = new Point();
display.getSize(size);
width = size.x;
} else {
// Display display = getWindowManager().getDefaultDisplay();
width = display.getWidth();
}
// int width=display.getWidth();

String data = "<html><head><title>Example</title><meta name=\"viewport\"\"content=\"width="
+ width + ", initial-scale=0.65 \" /></head>";
data = data + "<body><center><img width=\"" + width + "\" src=\"" + url
+ "\" /></center></body></html>";




ourBrow = (WebView) findViewById(R.id.webView1);

ourBrow.getSettings().setJavaScriptEnabled(true);
ourBrow.getSettings().setLoadWithOverviewMode(true);
ourBrow.getSettings().setUseWideViewPort(true);
ourBrow.getSettings().setBuiltInZoomControls(true);
ourBrow.getSettings().setDisplayZoomControls(true);

ourBrow.setWebViewClient(new WebViewClient());
// ourBrow.loadUrl("http://www.ganeshaspeaks.com/hindi/aries.action");

final AlertDialog alertDialog = new AlertDialog.Builder(this).create();

// final ProgressDialog progressBar =
// ProgressDialog.show(CalList.this,"Loading", "Fetching..");
final ProgressDialog pDialog = new ProgressDialog(
ListCoachesWebView.this, R.style.MyTheme);
pDialog.setTitle("Directing..");
pDialog.setMessage("Please wait.");
pDialog.setIcon(android.R.drawable.ic_dialog_info);
pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pDialog.setCancelable(true);
pDialog.show();
ourBrow.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {

view.loadUrl(url);
return true;
}

public void onPageFinished(WebView view, String url) {

if (pDialog.isShowing()) {
pDialog.dismiss();
}
}

@SuppressWarnings("deprecation")
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
// Log.e(TAG, "Error: " + description);

alertDialog.setTitle("Error");
alertDialog.setMessage(description);
alertDialog.setButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
return;
}
});
alertDialog.show();
}
});
ourBrow.loadData(data, "text/html", null);
}
}

Post a Comment

0Comments

Post a Comment (0)