Wednesday, 24 September 2014

how to gridview random fadin animation in android example

res/anim/layout_random_fade_in.xml

<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/re/android"
    android:animation="@anim/fade_in"
    android:animationOrder="random"
    android:delay="0.5" />


res/anim/fade_in.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="@android:integer/config_longAnimTime"
    android:fromAlpha="0.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:toAlpha="1.0" />


res/layout/activity_main.xml

  <GridView
            android:id="@+id/gridView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:columnWidth="100dp"
            android:drawSelectorOnTop="true"
            android:fadingEdge="none"
            android:gravity="center"
            android:numColumns="3"
            android:stretchMode="columnWidth"
            android:verticalSpacing="2dp" >
        </GridView>



MainActivity.java

public class MainActivity extends Activity implements AnimationListener {
     private GridView gridView;


@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);


      gridView = (GridView) findViewById(R.id.gridView);

   LayoutAnimationController layoutAnimation =   AnimationUtils.loadLayoutAnimation(getApplicationContext(),R.anim.layout_random_fade_in);
gridView.setLayoutAnimation(layoutAnimation);
    }
 @Override
    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub
      
    }
    @Override
    public void onAnimationEnd(Animation animation) {
        // TODO Auto-generated method stub
    }  
    @Override
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub
      
    }

}

how to slide_down animation in android

res/animation/slide_down.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">

    <scale
        android:duration="1000"
        android:fromXScale="1.0"
        android:fromYScale="0.0"
        android:toXScale="1.0"
        android:toYScale="1.0" />

</set>

res/layout/activity_slide_down.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
   
    <ImageView android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher/>
   
    <Button android:id="@+id/btn_Start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Start Animation/>
   
</RelativeLayout>

MainActivity.java

package example.animations;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity implements AnimationListener {

    ImageView image;
    Button btn_Start;
    Animation animationSlide_down;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_slide_down);

        image= (ImageView) findViewById(R.id.image);
        btn_Start= (Button) findViewById(R.id.btn_Start);

      
        animationRotate= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.slide_down);
        animationRotate.setAnimationListener(this);

        btn_Start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            
               image.startAnimation(animationSlide_down);
            }
        });

    }

    @Override
    public void onAnimationEnd(Animation animation) {
             if (animation == animationSlide_down) {
        }

    }
    @Override
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub

    }
    @Override
    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub

    }

}

how to zoom_out animation in android

res/animation/zoom_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >

    <scale
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="1000"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="0.5"
        android:toYScale="0.5" >
    </scale>

</set>

res/layout/activity_zoom_out.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
   
    <ImageView android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher/>
   
    <Button android:id="@+id/btn_Start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Start Animation/>
   
</RelativeLayout>

MainActivity.java

package example.animations;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity implements AnimationListener {

    ImageView image;
    Button btn_Start;
    Animation animationZoom_out;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zoom_out);

        image= (ImageView) findViewById(R.id.image);
        btn_Start= (Button) findViewById(R.id.btn_Start);

      
        animationRotate= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.zoom_out);
        animationRotate.setAnimationListener(this);

        btn_Start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            
               image.startAnimation(animationZoom_out);
            }
        });

    }

    @Override
    public void onAnimationEnd(Animation animation) {
             if (animation == animationZoom_out) {
        }

    }
    @Override
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub

    }
    @Override
    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub

    }

}

how to zoom_in animation in android

res/animation/zoom_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >

    <scale
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="2000"
        android:fromXScale="1"
        android:fromYScale="1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="3"
        android:toYScale="3" >
    </scale>

</set>

res/layout/activity_zoom_in.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
   
    <ImageView android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher/>
   
    <Button android:id="@+id/btn_Start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Start Animation/>
   
</RelativeLayout>

MainActivity.java

package example.animations;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity implements AnimationListener {

    ImageView image;
    Button btn_Start;
    Animation animationZoom_in;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zoom_in);

        image= (ImageView) findViewById(R.id.image);
        btn_Start= (Button) findViewById(R.id.btn_Start);

      
        animationRotate= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.zoom_in);
        animationRotate.setAnimationListener(this);

        btn_Start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            
               image.startAnimation(animationZoom_in);
            }
        });

    }

    @Override
    public void onAnimationEnd(Animation animation) {
             if (animation == animationZoom_in) {
        }

    }
    @Override
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub

    }
    @Override
    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub

    }

}

how to move animation in android

res/animation/move.xml

<?xml version="1.0" encoding="utf-8"?>
<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:fillAfter="true">

   <translate
        android:fromXDelta="0%p"
        android:toXDelta="75%p"
        android:duration="800" />
</set>

res/layout/activity_move.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
   
    <ImageView android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher/>
   
    <Button android:id="@+id/btn_Start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Start Animation/>
   
</RelativeLayout>

MainActivity.java

package example.animations;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity implements AnimationListener {

    ImageView image;
    Button btn_Start;
    Animation animationMove;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_move);

        image= (ImageView) findViewById(R.id.image);
        btn_Start= (Button) findViewById(R.id.btn_Start);

      
        animationRotate= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.move);
        animationRotate.setAnimationListener(this);

        btn_Start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            
               image.startAnimation(animationMove);
            }
        });

    }

    @Override
    public void onAnimationEnd(Animation animation) {
             if (animation == animationMove) {
        }

    }
    @Override
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub

    }
    @Override
    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub

    }

}

Sunday, 14 September 2014

how to rotate animation in android

res/animation/rotate.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <rotate
        android:duration="600"
        android:fromDegrees="0"
        android:interpolator="@android:anim/cycle_interpolator"
        android:pivotX="50%"
        android:pivotY="50%"
        android:repeatCount="infinite"
        android:repeatMode="restart"
        android:toDegrees="90" />

</set>

res/layout/activity_rotate.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
   
    <ImageView android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher/>
   
    <Button android:id="@+id/btn_Start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Start Animation/>
   
</RelativeLayout>

MainActivity.java

package example.animations;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity implements AnimationListener {

    ImageView image;
    Button btn_Start;
    Animation animationRotate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rotate);

        image= (ImageView) findViewById(R.id.image);
        btn_Start= (Button) findViewById(R.id.btn_Start);

      
        animationRotate= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.rotate);
        animationRotate.setAnimationListener(this);

        btn_Start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            
               image.startAnimation(animationRotate);
            }
        });

    }

    @Override
    public void onAnimationEnd(Animation animation) {
             if (animation == animationRotate) {
        }

    }
    @Override
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub

    }
    @Override
    public void onAnimationStart(Animation animation) {
        // TODO Auto-generated method stub

    }

}

Monday, 8 September 2014

how to get IP Address in android


IPAddress.java

package com.example.ip;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
 
  try {
   for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();)
   {
              NetworkInterface intf = en.nextElement();
              for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();)
              {
                  InetAddress inetAddress = enumIpAddr.nextElement();
                  if (!inetAddress.isLoopbackAddress())
                  {
                  TextView tv_ip= (TextView) findViewById(R.id.tv_ipaddress);
                  tv_ip.setText(inetAddress.getHostAddress());
                  }
              }
          }
  } catch (Exception e)
  {
   Log.e("******", e.toString());
  }
 }

AndroidManifest

    <uses-permission android:name="android.permission.INTERNET" />