I’m posting here the source code, if anyone
is interested, or simply doesn’t want to waste the time creating a new
one.
gallery.setOnItemClickListener(new OnItemClickListener() {
@SuppressWarnings("unused")
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
count++;
View lastView = null;
Animation grow = AnimationUtils.loadAnimation(getBaseContext(), R.anim.image_scale);
if(count == 1){
Calendar cal = Calendar.getInstance();
prvsSec = cal.get(Calendar.SECOND);
}
if(count == 2 ){
Calendar cal = Calendar.getInstance();
curSec = cal.get(Calendar.SECOND);
count = 0;
if((curSec - prvsSec) <=1){
if(!hasPrvsTap){
try {
if (lastView != null)
lastView.clearAnimation();
} catch (Exception e) {
e.printStackTrace();
}
try {
view.startAnimation(grow);
} catch (Exception e) {
e.printStackTrace();
}
lastView = view;
hasPrvsTap = true;
}
else{
view.clearAnimation();
hasPrvsTap = false;
}
}
else{
Calendar cal2 = Calendar.getInstance();
prvsSec = cal2.get(Calendar.SECOND);
count = 1;
}
}
}
});
@SuppressWarnings("unused")
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
count++;
View lastView = null;
Animation grow = AnimationUtils.loadAnimation(getBaseContext(), R.anim.image_scale);
if(count == 1){
Calendar cal = Calendar.getInstance();
prvsSec = cal.get(Calendar.SECOND);
}
if(count == 2 ){
Calendar cal = Calendar.getInstance();
curSec = cal.get(Calendar.SECOND);
count = 0;
if((curSec - prvsSec) <=1){
if(!hasPrvsTap){
try {
if (lastView != null)
lastView.clearAnimation();
} catch (Exception e) {
e.printStackTrace();
}
try {
view.startAnimation(grow);
} catch (Exception e) {
e.printStackTrace();
}
lastView = view;
hasPrvsTap = true;
}
else{
view.clearAnimation();
hasPrvsTap = false;
}
}
else{
Calendar cal2 = Calendar.getInstance();
prvsSec = cal2.get(Calendar.SECOND);
count = 1;
}
}
}
});
I get Calender Instance because of calculate time between two tap.
Following are animation for image scale .Place image_scale.xml in res-> anim:
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="150"
android:fillAfter="true"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.25"
android:toYScale="1.25" >
</scale>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="150"
android:fillAfter="true"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.25"
android:toYScale="1.25" >
</scale>
No comments:
Post a Comment