Wednesday 30 May 2012

Set Full screen of windows in android


Write below code in oncreate method to set full  screen mode:-
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
     

Tuesday 29 May 2012

How to remove Listview back black color in android

You need to set  android:cacheColorHint Properties of listview :-
For Exm--


android:cacheColorHint="#00000000"

Set Round Corner Layout in android Using Shape xml

1) create Drawable xml (Shape type) in res folder :-
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
   
    <corners android:radius="10dp" />
    <solid android:color="#CCFFFFFF"/>

</shape>

2) Now set this to layout background :-
             layout.setBackgroundResource(R.drawable.shape);

Set Adapter in ListView in Android using ArrayAdapter


1)..First Create ArrayAdapter Object with row layout and textview :-
ArrayAdapter<String> News=new ArrayAdapter<String>(this, R.layout.gl_row,R.id.textView2, <your string array object of data>);

2) Now set this adapter in listview :-
list.setAdapter(News);

Monday 28 May 2012

How to use Timer in Android for update UI


public class myActivity extends Activity {
 private Timer myTimer;
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  setContentView(R.layout.main);

  myTimer = new Timer();
  myTimer.schedule(new TimerTask() {
   @Override
   public void run() {
    TimerMethod();
   }

  }, 0, 1000);
 }
 private void TimerMethod()
 {
  //This method is called directly by the timer
  //and runs in the same thread as the timer.
  //We call the method that will work with the UI
  //through the runOnUiThread method.
  this.runOnUiThread(Timer_Tick);
 }
 private Runnable Timer_Tick = new Runnable() {
  public void run() {
  //This method runs in the same thread as the UI.            
  //Do something to the UI thread here
  }
 };
}

Sunday 27 May 2012

Share Image on Facebook or mail in Android


Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse("android.resource://com.hanuma/" + R.drawable.front);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
sharingIntent.putExtra(Intent.EXTRA_TITLE, "New Upcoming Android Game by Fundumobi.com!");
sharingIntent.putExtra(Intent.EXTRA_TEXT,"New Upcoming Android Game by Fundumobi.com!");
context.startActivity(Intent.createChooser(sharingIntent, "New Game"));

Send SMS in Android


Intent intentt = new Intent(Intent.ACTION_VIEW);        
intentt.setData(Uri.parse("sms:"));
intentt.setType("vnd.android-dir/mms-sms");
intentt.putExtra(Intent.EXTRA_TEXT, "");
intentt.putExtra("address", selecteditem_phone);
startActivityForResult(Intent.createChooser(intentt, ""), 0);

Share Intent in Android


Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_TITLE, "New Upcoming Android Game by Fundumobi.com!");
sharingIntent.putExtra(Intent.EXTRA_TEXT,"New Upcoming Android Game by Fundumobi.com!");
startActivity(Intent.createChooser(sharingIntent, "Share"));

Thursday 24 May 2012

Open Url in Android Browser


Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(browserIntent);

Image Url to Bitmap


public static AndroidHttpClient httpclient = null;
public static Bitmap getBitmap(String url) {
   Bitmap bm = null;
   try {
       URL aURL = new URL(url);
       URLConnection conn = aURL.openConnection();
       conn.connect();
       InputStream is = conn.getInputStream();
       BufferedInputStream bis = new BufferedInputStream(is);
       bm = BitmapFactory.decodeStream(new FlushedInputStream(is));
       bis.close();
       is.close();
   }
   catch (Exception e) {
       e.printStackTrace();
   }
   finally {
       if (httpclient != null) {
           httpclient.close();
       }
   }
   return bm;
}

/** Classes **/
private static class FlushedInputStream extends FilterInputStream {
   public FlushedInputStream(InputStream inputStream) {
       super(inputStream);
   }

   @Override
   public long skip(long n) throws IOException {
       long totalBytesSkipped = 0L;
       while (totalBytesSkipped < n) {
           long bytesSkipped = in.skip(n - totalBytesSkipped);
           if (bytesSkipped == 0L) {
               int b = read();
               if (b < 0) {
                   break; // we reached EOF
               } else {
                   bytesSkipped = 1; // we read one byte
               }
           }
           totalBytesSkipped += bytesSkipped;
       }
       return totalBytesSkipped;
   }
}

Tuesday 22 May 2012

Rotate Image On canvas in android


    Matrix transform = new Matrix();
    transform.setTranslate(xOfCentre, yOfCentre);
    transform.preRotate(turnDegrees, width/2, height/2);
    canvas.drawBitmap(bitmap, transform, null);

Saturday 19 May 2012

Open url in Webview in android


WebView webview =( WebView)findViewById(R.id.webView1);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.setWebViewClient(new WebViewClient());
webview.loadUrl("http://www.youtube.com/");

Friday 18 May 2012

Android ListView ItemClick Event using implement itemclickListener



public class NewsList extends Activity implements OnItemClickListener {
   
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
setContentView(R.layout.newslist);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, R.layout.newsrow,R.id.newslisttext, Data.NewsCat);
ListView list=(ListView)findViewById(R.id.listView1);
list.setAdapter(adapter);
list.setOnItemClickListener(this);
   // TODO Auto-generated method stub
}

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
Intent i=new Intent();
i.setClass(NewsList.this, NewsList2.class);
Bundle b=new Bundle();
b.putString("title", arg0.getItemAtPosition(arg2).toString());
b.putInt("index", arg2);
i.putExtras(b);
NewsList.this.startActivity(i);
}



Android Button or ImageButton Click Using Implements onclickListener



public class Aboutus extends Activity implements OnClickListener {
private ImageButton back;
@Override
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
     setContentView(R.layout.aboutus);
            back=(ImageButton)findViewById(R.id.header_left_btn);
              back.setOnClickListener(this);
}
public void onClick(View arg0) {

if(arg0==back)
{
finish();
}
}

}

Android Button or Imagebutton click Event using set OnClickListener Method



public class Aboutus extends Activity {
private ImageButton back;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        back=(ImageButton)findViewById(R.id.header_left_btn);
        back.setOnClickListener(new OnClickListener(){

public void onClick(View arg0) {
// TODO Auto-generated method stub
finish();
}
       
        });
}
}

Thursday 17 May 2012

How to Call Listview Footer controls Event in android


View footerView = ((LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer, null, false);
list.addFooterView(footerView);
ImageButton all=(ImageButton)footerView.findViewById(R.id.imageButton1);
all.setOnClickListener(this);

Add footer in android Listview

Sample code for add Footer in Listview :-


View footerView = ((LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer, null, false);
list.addFooterView(footerView);

Tuesday 15 May 2012

Round Corner LinearLayout in Android

main.xml:-


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
     >

  <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:layout_margin="15dp"
        android:background="@drawable/myshape">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_margin="15dp">

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Rounded Corners!"
                android:textStyle="bold"
                android:textColor="#707070"

                />

        </LinearLayout>


    </LinearLayout>
</LinearLayout>

myshape.xml :-


<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
   
    <corners android:radius="10dp" />
    <solid android:color="#CCFFFFFF"/>

</shape>



Monday 14 May 2012

AutoCompleteTextView in Android

Layout:-


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <AutoCompleteTextView
        android:id="@+id/autoCompleteTextView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:text="AutoCompleteTextView" >

        <requestFocus />
    </AutoCompleteTextView>

 </LinearLayout>

Java Code:-


import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class AddCompany extends Activity {
private AutoCompleteTextView autotext;
private String[] objects={"abc","xyz","afdf"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
setContentView(R.layout.profilelist);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, R.id.textView2, objects);
autotext=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
autotext.setThreshold(3);
autotext.setAdapter(adapter);
   // TODO Auto-generated method stub
}

}

Sunday 13 May 2012

Set Html Text in TextView in android


TextView xyz= (TextView)findViewById(R.id.xyz);
xyz.setText(Html.fromHtml(getString(R.string.nice_html)));

Friday 11 May 2012

Close An Activity in Android

finish(); function use to close any activity.

Start an Activity in android

You can start another activity by calling startActivity(), passing it an Intent that describes the activity you want to start.


Intent intent = new Intent(this, SignInActivity.class);
startActivity(intent);

Activities in Android

An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map. Each activity is given a window in which to draw its user interface.

Creating an Activity:-

To create an activity, you must create a subclass of  Activity.

import android.app.Activity;
import android.os.Bundle;

public class MyActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}


What is Content providers??

A content provider manages a shared set of application data. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your application can access. Through the content provider, other applications can query or even modify the data

What is Content providers???

A broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured.

Saturday 5 May 2012

How to open Default Sms Screen To Send SMS in Android

Below Code show how we send SMS using new intent in android:-

                Intent sendIntent = new Intent(Intent.ACTION_VIEW);
               sendIntent.putExtra("sms_body", "Your Msg");
               sendIntent.setType("vnd.android-dir/mms-sms");
               startActivity(sendIntent);

Thursday 3 May 2012

Animation between screen change in Android

If you want to change your application screen with animation then following post help you. 1) First make anim folder in res and put all animation xml in anim folder. you can find animation xml in android demo application in android sdk. 2) Now write folowing code on your activity. 


public class Logo extends Activity 

private static final int SPLASH_DISPLAY_TIME = 2000;
/** Called when the activity is first created. */ 
@Override public void onCreate(Bundle savedInstanceState) 

super.onCreate(savedInstanceState); 
requestWindowFeature(Window.FEATURE_NO_TITLE); 
setContentView(R.layout.logo); 
new Handler().postDelayed(new Runnable() { 
public void run() { 
Intent intent = new Intent(); 
intent.setClass(Logo.this, Splesh.class); 
Logo.this.startActivity(intent); 
Logo.this.finish(); 
// transition from logo to splash 
overridePendingTransition(R.anim.activityfadein, R.anim.splashfadeout); 
} }, SPLASH_DISPLAY_TIME); 
} }

Transparent background and divider in listview in Android

Set Below to properties in listview 
android:cachecolorhint="#00000000" 
android:divider="@drawable/divider"

Alert Message Box in Android


ALERTDIALOG.BUILDER ADB=NEW ALERTDIALOG.BUILDER(ACTIVITY);

    adb.setTitle("Alert?");
    adb.setMessage("Do you want to delete Note.");
    adb.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                
            System.out.println("zdfsdfksjDfjkds:hi me hi me  "+holder.id.getText());
          }
    }
      );
    adb.setNegativeButton("No", null);
    adb.show();

Method of create signed apk for android

Click here...... This link use full for create signed your apk

How to make a progress dialog In Android

The first thing you have to do is, making your progress dialog accessible from the entire Main class.
So, how do we do that? easy!
Define the progress dialog in the name space as so:

1
private ProgressDialog progressDialog;
Now we want to create a functions which will be holding our Thread and ProgressDialog.
We can do this by adding the following code:

01
private void runDialog(final int seconds)
02 {
03         progressDialog = ProgressDialog.show(this"Please wait....""Here your message");
04
05         new Thread(new Runnable(){
06             public void run(){
07                 try {
08                             Thread.sleep(seconds * 1000);
09                     progressDialog.dismiss();
10                 catch (InterruptedException e) {
11                     e.printStackTrace();
12                 }
13             }
14         }).start();
15 }
So what does that piece of code do exactly? Lets go over this code 1 step at a time.

1
progressDialog = ProgressDialog.show(this"Please wait....""Here your message");
The following code create's and starts the ProgressDialog.

01
new Thread(new Runnable(){
02     public void run(){
03         try {
04             Thread.sleep(seconds * 1000);
05             progressDialog.dismiss();
06         catch (InterruptedException e) {
07             e.printStackTrace();
08         }
09     }
10 }).start();
This piece of code create a "Thread" a thread runs in the background of your applications, which lets your GUI (Graphical User Interface) run without interference. If you would do this without a Thread, you GUI would freeze / lock untill the process is completed.
Lets move to the next piece:

1
Thread.sleep(seconds * 1000);
After the thread starts to run it's code, when it reaches the thread.sleep() command it's waits for a given amount of time and the continues to execute the rest of the code. So in our case it waits for 5 seconds before running the following command:

1
progressDialog.dismiss();
This piece of code dismisses / stops the progress dialog.
A thread is most commonly used for background (service) operations, for example....you create aThread (worker) which checks if you receive any message's or, checks your battery status, play music, and the list goes on and on.

Wednesday 2 May 2012

Auto Switch between tow activity in android

Our First Activity class Logo. :-



public class Logo extends Activity {
private static final int SPLASH_DISPLAY_TIME = 4000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   requestWindowFeature(Window.FEATURE_NO_TITLE);
        // making it full screen
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.logo);
        new Handler().postDelayed(new Runnable() {
            public void run() {

                Intent intent = new Intent();
                intent.setClass(Logo.this, Splesh.class);

                Logo.this.startActivity(intent);
                Logo.this.finish();


            }
        }, SPLASH_DISPLAY_TIME);
   // TODO Auto-generated method stub
}

}

Second Activity Class Splesh :-


public class Splesh extends Activity {
private static final int SPLASH_DISPLAY_TIME = 4000;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   requestWindowFeature(Window.FEATURE_NO_TITLE);
        // making it full screen
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
 
        setContentView(R.layout.splesh);
     
        new Handler().postDelayed(new Runnable() {
            public void run() {

                Intent intent = new Intent();
                intent.setClass(Splesh.this, NewActivity.class);

                Splesh.this.startActivity(intent);
                Splesh.this.finish();
     

            }
        }, SPLASH_DISPLAY_TIME);
   // TODO Auto-generated method stub
}


}



Another Way to Make Splash Screen in android

Here is process to show splash screen :-



public class Logo extends Activity {
private static final int SPLASH_DISPLAY_TIME = 4000;

@Override
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.logo);
             new Handler().postDelayed(new Runnable() {
              public void run() {
                Intent intent = new Intent();
                intent.setClass(Logo.this, Splesh.class);
                Logo.this.startActivity(intent);
                Logo.this.finish();
            }
        }, SPLASH_DISPLAY_TIME);
 
}

}

How to make a basic splash screen

The following code will show you how to create a basic splashscreen for your Android application that will stay for 5 seconds. If we don't want to wait we can tap the screen to go directly to the next Activity. Source project is on the bottom of the tutorial.
Lets go through the code to see how simple it is to make a very basic splash screen for your application.
The splashscreen will be the startup Activity for our application and on application launch a Thread will start that will listen for touch events.
01public class SplashScreen extends Activity {
02
03    //how long until we go to the next activity
04    protected int _splashTime = 5000;
05
06    private Thread splashTread;
07
08    /** Called when the activity is first created. */
09    @Override
10    public void onCreate(Bundle savedInstanceState) {
11        super.onCreate(savedInstanceState);
12        setContentView(R.layout.splash);
13
14        final SplashScreen sPlashScreen = this;
15
16        // thread for displaying the SplashScreen
17        splashTread = new Thread() {
18            @Override
19            public void run() {
20                try {
21                    synchronized(this){
22
23                        //wait 5 sec
24                        wait(_splashTime);
25                    }
26
27                catch(InterruptedException e) {}
28                finally {
29                    finish();
30
31                    //start a new activity
32                    Intent i = new Intent();
33                    i.setClass(sPlashScreen, Main.class);
34                    startActivity(i);
35
36                    stop();
37                }
38            }
39        };
40
41        splashTread.start();
42    }
43
44    //Function that will handle the touch
45    @Override
46    public boolean onTouchEvent(MotionEvent event) {
47        if (event.getAction() == MotionEvent.ACTION_DOWN) {
48            synchronized(splashTread){
49                splashTread.notifyAll();
50            }
51        }
52        return true;
53    }
54
55}