Tuesday, January 10, 2012

Display a custom dialog in your Android application

1-make your dialog layout as you like it and you can treat it as any activity layout
2-create class extends dialog class
3-set content  by your own layout
4-you can use dialog.show() to show your dialog as you like

How to make you ImageButton back ground transparent

it is so easy to do that just follow steps and you will get what you want
1-load your button in XML layout and give it   id as imagebutton and set it's background as you like
2- at your java class declare imagebutton
 ImageButton mybtn;  
3-load your button from xml to java
 mybtn=(ImageButton)findViewById(R.id.imagebutton);  
4- set transparent back ground
 mybtn.setBackgroundColor(android.R.color.transparent);  

Sunday, January 8, 2012

Time Format

you can get time and date

1:  import java.text.Format;  
2:  import java.text.SimpleDateFormat;  
3:  import java.util.Date;  
4:  Date date = new Date();  
5:  Format dayformat;  
6:  dayformat = new SimpleDateFormat("dd");  
7:  String strDay = dayformat.format(date);  
8:  Format monthformat;  
9:  monthformat = new SimpleDateFormat("MM");  
10:  String strMonth = monthformat.format(date);  
11:  Format yearformat;  
12:  yearformat = new SimpleDateFormat("yy");  
13:  String strYear = yearformat.format(date);  
14:  Format minuteformat;  
15:  minuteformat = new SimpleDateFormat("mm");  
16:  String strMinute = minuteformat.format(date);  
17:  Format hourformat;  
18:  hourformat = new SimpleDateFormat("HH");  
19:  String strHour = hourformat.format(date);  
you can use this strings as you like
enjoy android feel free to ask  

Saturday, January 7, 2012

Animation Collection

Animation Collection


try this animation it contain of fading and rotation apply it at round image you can get very good animation

1:  <?xml version="1.0" encoding="utf-8" ?>  
2:  <set  
3:    xmlns:android="http://schemas.android.com/apk/res/android"  
4:    android:shareInterpolator="false">  
5:    <rotate  
6:      android:fromDegrees="0"  
7:      android:toDegrees="360"  
8:      android:pivotX="50%"  
9:      android:pivotY="50%"  
10:      android:duration="2000" ></rotate>  
11:    <alpha  
12:      android:fromAlpha="0.0"  
13:      android:toAlpha="1.0"  
14:      android:duration="2000">  
15:    </alpha>  
16:    <scale  
17:      android:pivotX="50%"  
18:      android:pivotY="50%"  
19:      android:fromXScale=".1"  
20:      android:fromYScale=".1"  
21:      android:toXScale="1.0"  
22:      android:toYScale="1.0"  
23:      android:duration="2000" />  
24:  </set>  

Phone states

Phone States


you can detect phone states and do any thing as your like your code to do 


1:  public class testsonqdappel extends Activity {  
2:  private TelephonyManager telephone;  
3:  private MediaPlayer audio;  
4:  public void onCreate(Bundle savedInstanceState) {  
5:  // TODO Auto-generated method stub  
6:  super.onCreate(savedInstanceState);  
7:  telephone = (TelephonyManager)getSystemService  
8:  (Context.TELEPHONY_SERVICE);  
9:  }  
10:  private PhoneStateListener psl = new PhoneStateListener() {  
11:  @Override  
12:  public void onCallStateChanged (int state, String   
13:  incomingNumber)  
14:  {  
15:  state = telephone.getCallState();  
16:  if(state ==  
17:  android.telephony.TelephonyManager.CALL_STATE_IDLE)  
18:  {  
19:  audio = MediaPlayer.create(getBaseContext(),  
20:  R.raw.bonjour);  
21:  audio.start();  
22:  }  
23:  if (state ==  
24:  android.telephony.TelephonyManager.CALL_STATE_RINGING)  
25:  {  
26:  audio = MediaPlayer.create(getBaseContext(),  
27:  R.raw.batterie);  
28:  audio.start();  
29:  }  
30:  if (state ==  
31:  android.telephony.TelephonyManager.CALL_STATE_OFFHOOK)  
32:  {  
33:  audio = MediaPlayer.create(getBaseContext(),  
34:  R.raw.pleine);  
35:  audio.start();  
36:  }  
37:  }  
38:  };  
39:  }  


small and important tips

Small and Important Tips
 
1)every activity must write in manifest file.
2)don't forget to write your permeation in manifest file.
3)use log-cat with debugging statement to catch any error 

find current location latitude and longitude


find current location latitude and longitude

you can use this to get your location 

1:  public class GPSmap extends Activity {  
2:   // GeoPoint geoPoint;  
3:    @Override  
4:    public void onCreate(Bundle savedInstanceState) {  
5:      super.onCreate(savedInstanceState);  
6:      LocationManager locManager;  
7:      setContentView(R.layout.main);  
8:      locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);   
9:      locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000L,500.0f, locationListener);  
10:      Location location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);  
11:      if(location != null)                  
12:      {  
13:        double latitude = location.getLatitude();  
14:      double longitude = location.getLongitude();  
15:      }   
16:     }  
17:    private void updateWithNewLocation(Location location) {  
18:      TextView myLocationText = (TextView)findViewById(R.id.text);  
19:      String latLongString = "";  
20:      if (location != null) {  
21:        double lat = location.getLatitude();  
22:        double lng = location.getLongitude();  
23:        latLongString = "Lat:" + lat + "\nLong:" + lng;  
24:      } else {  
25:        latLongString = "No location found";  
26:      }  
27:       myLocationText.setText("Your Current Position is:\n" +  
28:          latLongString);  
29:    }  
30:    private final LocationListener locationListener = new LocationListener() {  
31:      public void onLocationChanged(Location location) {  
32:        updateWithNewLocation(location);  
33:      }  
34:      public void onProviderDisabled(String provider) {  
35:        updateWithNewLocation(null);  
36:      }  
37:      public void onProviderEnabled(String provider) {  
38:      }  
39:      public void onStatusChanged(String provider, int status, Bundle extras) {  
40:      }  
41:    };  
42:  }