Progress bars are our basic needs when we want to show something for a long time or some progress takes a long time and we want to show it’s progress.
Keeping that in mind ANDROID also has built in progress views.
There are basically two types of progress views in ANDROID.
ProgressDialog.STYLE_SPINNER and ProgressDialog.STYLE_HORIZONTAL
Take a look at this simple example that loads a progressBar on “onCreate”….
public class Example extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ProgressDialog dialog = ProgressDialog.show(Example.this, "", "Loading...", true);
}
}

The following example shows how to draw a rectangle using the Paint Class in ANDROID. Just copy and paste the following code to your file and you are done.
package Draw2.pack;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
public class Draw2 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new myView(this));
}
private class myView extends View{
public myView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
Paint myPaint = new Paint();
myPaint.setColor(Color.GREEN);
myPaint.setStyle(Paint.Style.STROKE);
myPaint.setStrokeWidth(3);
canvas.drawRect(10, 10, 100, 100, myPaint);
}
}
}
Please checkout the “LogCat” for the output.
If you don’t know about Logcat In Eclipse “Go to Window->showView and search for Logcat”.
package com.ip;
import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
public class Get_IP extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
// WifiInfo wifiInfo = wifiManager.getConnectionInfo();
// int ipAddress = wifiInfo.getIpAddress();
// String ip = intToIp(ipAddress);
StringBuffer buf = new StringBuffer();
buf.append("VERSION.RELEASE {"+Build.VERSION.RELEASE+"}");
buf.append("nVERSION.INCREMENTAL {"+Build.VERSION.INCREMENTAL +"}");
buf.append("nVERSION.SDK {"+Build.VERSION.SDK+"}");
buf.append("nBOARD {"+Build.BOARD+"}");
buf.append("nBRAND {"+Build.BRAND+"}");
buf.append("nDEVICE {"+Build.DEVICE+"}");
buf.append("nFINGERPRINT {"+Build.FINGERPRINT+"}");
buf.append("nHOST {"+Build.HOST+"}");
buf.append("nID {"+Build.ID+"}");
System.out.println("build"+buf);
System.out.println("Phone Number = " + getMy10DigitPhoneNumber());
}
public String intToIp(int i) {
return ((i >> 24 ) & 0xFF ) + "." +
((i >> 16 ) & 0xFF) + "." +
((i >> 8 ) & 0xFF) + "." +
( i & 0xFF) ;
}
private String getMyPhoneNumber(){
TelephonyManager mTelephonyMgr;
mTelephonyMgr = (TelephonyManager)
getSystemService(Context.TELEPHONY_SERVICE);
return mTelephonyMgr.getLine1Number();
}
private String getMy10DigitPhoneNumber(){
String s = getMyPhoneNumber();
return s.substring(2);
}
}
The following java code helps you to show a webpage in ANDROID and enable javascript.
package com.pack;
import android.app.Activity;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.graphics.SumPathEffect;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.View.OnKeyListener;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import android.widget.Toast;
public class myHTML extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webview = (WebView)findViewById(R.id.webview);
TextView tv = (TextView)findViewById(R.id.tv);
tv.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
return false;
}
});
try{
webview.getSettings().setJavaScriptEnabled(true);
// setContentView(webview);
final Activity activity = this;
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
activity.setProgress(progress * 10000);
Toast.makeText(activity, "Loading " , Toast.LENGTH_SHORT).show();
}
});
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
String summary = "HELLO";
/*To load from a string use loadDataWithBaseURL */
webview.loadDataWithBaseURL("",summary, "text/html", "utf-8", "");
/* To load from a file use loadUrl(remote or local) */
//webview.loadUrl("file:///android_asset/test.html");
}catch(Exception e){
Toast.makeText(myHTML.this,e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}