Tuesday, January 31, 2012

Animation For Textview in Android

Animation For Textview in Android

 i have wrote code   animation for textview.

where we can textview animation ex: flash news or new message received there we can use it. etc...

 Download Source Code


source code
 private class LocalFadeInAnimationListener implements AnimationListener {
       
        public void onAnimationEnd(Animation animation) {
            launchOutAnimation();
        }
       
        public void onAnimationRepeat(Animation animation){
        }
   
        public void onAnimationStart(Animation animation) {
        }
    };
   
    /**
     * Animation listener for fade-in
     *
     * @author VIJAYAKUMAR
     *
     */
    private class LocalFadeOutAnimationListener implements AnimationListener {
       
        public void onAnimationEnd(Animation animation) {
            launchInAnimation();
        }
       
        public void onAnimationRepeat(Animation animation) {
        }
   
        public void onAnimationStart(Animation animation) {
        }
    };
   

anim xml code
fadein.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromAlpha="0.1"
    android:toAlpha="1.0"
    android:duration="1000"
>

</alpha>

fadeout.xml
<?xml version="1.0" encoding="utf-8"?>
<alpha

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromAlpha="1.0"
    android:toAlpha="0.1"
    android:duration="1000"
>

</alpha>



Monday, January 23, 2012

update Ui from TimerTask in android

update Ui from TimerTask in android

In my application i have to send lati and lang values to server every 5 min.
Through timer task and (using service(my requirement is service thats why i am using service you can use activity itself)) i achieved this one.

Sample code

public class VehicleTrackingService extends Service {
    private Timer timer = new Timer();
    private static final long UPDATE_INTERVAL = 300000;
    Location l             = null;
    LocationManager lm;
    String userid;

    public void onCreate() {
        super.onCreate();
        SharedPreferences sharedPreferences = getSharedPreferences(
         DizlaActivity.PREFS_NAME, MODE_PRIVATE);
        userid = sharedPreferences.getString("user_id", "");
        locationUpdates();
    }

    private void locationUpdates() {
        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
               int i = 0;          
               lm     = (LocationManager)                            getSystemService(Context.LOCATION_SERVICE);
                List<String> providers = lm.getProviders(true);
                for (int j = providers.size() - 1; j >= 0; j--) 
                      {
                    l = lm.getLastKnownLocation(providers.get(i));
                    if (l != null)
                        break;
                     }
                  if (l==null) {
                       return;
                     }
              
            final    String lat = String.valueOf(l.getLatitude());
            final    String log = String.valueOf(l.getLongitude());
               //  do some values send to server method here          
              
        }
        }, 0, UPDATE_INTERVAL);
        }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (timer != null) {
            timer.cancel();
        }
    }
}

Monday, January 9, 2012

Autostart our own application when android device bootup compeleted

Autostart  own application at bootup.

when you power on the device open our application below the codes.
through receiver we can achive this one .

Androidmenifest.xml

 <receiver android:enabled="true" android:name=".OpenOurAppReceiver"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED">

        <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

OpenOurAppReceiver.class
public class
OpenOurAppReceiver extends BroadcastReceiver{
    @Override
    public void onReceive(Context context, Intent intent) {
            Intent i = new Intent(context, MainActivity.class);  
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
               context.startActivity(i);  

    }

}

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...