/*
* Copyright (C) 2013 Koushik Dutta (@koush)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.koushikdutta.boilerplate;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
public final class AnimatedView {
public static void setOnClickListener(final View view, final OnClickListener listener) {
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ScaleAnimation scale = new ScaleAnimation(.95f, 1f, .95f, 1f, Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
scale.setDuration(250);
view.startAnimation(scale);
listener.onClick(view);
}
});
}
public static void setOnLongClickListener(final View view, final View.OnLongClickListener listener) {
view.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
ScaleAnimation scale = new ScaleAnimation(.95f, 1f, .95f, 1f, Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
scale.setDuration(250);
view.startAnimation(scale);
return listener.onLongClick(view);
}
});
}
}