Thursday, 15 September 2011

Animation in Android

In this Post i will tell you about the simple blinking animation using apha property of android.
First create a class as follows by extending the Animation class:

BlinkAnimation,java

public class BlinkAnimation extends Animation {
    private int totalBlinks;
    private boolean finishOff;
   
    public BlinkAnimation(int totalBlinks, boolean finishOff) {
        this.totalBlinks = totalBlinks;
        this.finishOff = finishOff;
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        float period = interpolatedTime * totalBlinks * 3.14f + (finishOff ? 3.14f / 2 : 0);
        t.setAlpha(Math.abs(FloatMath.cos(period)));
    }

    @Override
    public boolean willChangeBounds() {
        return false;
    }

    @Override
    public boolean willChangeTransformationMatrix() {
        return false;
    }
}


Next step is to create a avtivity to instaniate the animation as follows:

TestActivity.java


public class TestActivity extends Activity implements OnClickListener, AnimationListener {
    private ImageView image;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        image = (ImageView) findViewById(R.id.image);
        ((Button) findViewById(R.id.button)).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.button) {
            Animation animation;
            if (image.getVisibility() == View.VISIBLE) {
                animation = new BlinkAnimation(3, true);
                animation.setInterpolator(new DecelerateInterpolator());
            } else {
                animation = new BlinkAnimation(3, false);
                animation.setInterpolator(new AccelerateInterpolator());
            }
            animation.setDuration(1000L);
            animation.setAnimationListener(this);
           
            image.startAnimation(animation);
        }
    }

    @Override
    public void onAnimationEnd(Animation animation) {
        image.setVisibility(image.getVisibility() == View.VISIBLE ?
                View.INVISIBLE : View.VISIBLE);
    }

    @Override
    public void onAnimationRepeat(Animation animation) {}

    @Override
    public void onAnimationStart(Animation animation) {}
}



and your XML file would look like this a follows:

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <ImageView
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="30dip"
    android:src="@drawable/icon" />
  <Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginTop="30dip"
    android:text="Please click me" />
</LinearLayout>

Monday, 12 September 2011

Netflix Now Works on Android 2.2 and 2.3 Devices

Netflix customers who want to watch the latest shows on the go using their smartphones have gotten some good news, but not everyone will be able to share in the party.


Source: http://www.pcworld.com/article/239830/netflix_now_works_on_android_22_and_23_devices.html

Saturday, 10 September 2011

Android Ice cream sandwich

Android users waiting for the Ice Cream Sandwich version of the mobile operating system will see the latest flavor pop up sometime in October or November.
Google's own executive chairman, Eric Schmidt, tipped off the time frame for the new version of Android in an interview yesterday with Salesforce CEO Marc Benioff.

Thursday, 8 September 2011

XMPP or Jabber for Chatting in Android

This Tutorial will tell you how to create a XMPP Client  for Android.
You can connect to any Server  like Gmail or Facebook or create your own Server using Open Fire.

  • For Information regarding how to setup Jabber Messaging Server and Use Miranda IM Client refer to:
             http://www.wowtutorial.org/tutorial/52.html


  • And download Miranda IM Client 
  • Next thing is to Connect to this Server Using your own Android Application: 
          You need to use the Smack Api for this purpose, which can be downloaded from the follwing link:
OR
 
After You have downlaoded the Smack Library Now you need to add it in your project's Refrenced Libraries. 
 
       1.Connection With The Server:
 
private XMPPClient xmppClient;
    private XMPPConnection connection;
    private ArrayList<String> messages = new ArrayList(); 
    public void login(String userName, String password) throws XMPPException
    {
    ConnectionConfiguration config = new ConnectionConfiguration("HOST",PORT, "SERVICE");
    connection = new XMPPConnection(config);
    connection.connect();
 
    //LOGIN USING THE FOLLWING login() 
 
    connection.login(userName, password);
    xmppClient.setConnection(connection); 
    }
 
  2.Send Message to a Person:
 
   Message msg = new Message("Recepiont", Message.Type.chat);
 msg.setBody(text);
 connection.sendPacket(msg); 

  3.For incoming messages from other users:
 
  public void setConnection
 (XMPPConnection connection) {
 this.connection = connection;
 if (connection != null) {
   // Add a packet listener to get messages sent to us
  PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
  connection.addPacketListener(new PacketListener() {
   public void processPacket(Packet packet) {
    Message message = (Message) packet;
     if (message.getBody() != null) {
    String fromName = StringUtils.parseBareAddress(message.getFrom());
    Log.i("XMPPClient", "Got text [" + message.getBody() + "] from [" + fromName + "]");
    messages.add(fromName + ":");
    messages.add(message.getBody());
    // Add the incoming message to the list view
    mHandler.post(new Runnable() {
    public void run() {
    setListAdapter();
     }
    });
     }
    }
   }, filter);
  }
 }
 
  4.To Sign Out or Disconnect from the Server: 

 public void signOut()
 {
  connection.disconnect();
 }
 
 
 
  There are a lot of other things which you can do using smack API.
  You can find the detailed documentation of each class in the following link:
http://www.igniterealtime.org/builds/smack/docs/latest/documentation/index.html






SOURCE: http://davanum.wordpress.com/2007/12/31/android-just-use-smack-api-for-xmpp/