use of android.view.animation.Animation.AnimationListener in project FloatingStickies by MohammadAdib.
the class MainActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
boolean key = prefs.getBoolean("key", false);
if (!key) {
setContentView(R.layout.tutorial);
final ImageView iv1 = (ImageView) findViewById(R.id.imageView1);
final ImageView iv2 = (ImageView) findViewById(R.id.imageView2);
final ImageView iv3 = (ImageView) findViewById(R.id.imageView3);
final ImageView iv4 = (ImageView) findViewById(R.id.done);
final CheckBox cb = (CheckBox) findViewById(R.id.checkBox);
final Animation anim1 = AnimationUtils.loadAnimation(this, R.anim.show);
final Animation anim2 = AnimationUtils.loadAnimation(this, R.anim.show);
final Animation anim3 = AnimationUtils.loadAnimation(this, R.anim.show);
final Animation anim4 = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
final Animation anim5 = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);
final Animation anim6 = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
anim1.setDuration(500);
anim2.setDuration(500);
anim3.setDuration(500);
anim1.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
iv1.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
iv2.startAnimation(anim2);
}
});
anim2.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
iv2.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
iv3.startAnimation(anim3);
}
});
anim3.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
iv3.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
iv4.startAnimation(anim4);
iv4.setOnTouchListener(MainActivity.this);
}
});
anim4.setDuration(1000);
anim4.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
iv4.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
iv4.startAnimation(anim5);
}
});
anim5.setDuration(1000);
anim5.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
iv4.startAnimation(anim4);
}
});
iv1.startAnimation(anim1);
cb.startAnimation(anim6);
} else {
finish();
}
}
use of android.view.animation.Animation.AnimationListener in project FloatingStickies by MohammadAdib.
the class StandOutWindow method hide.
/**
* Hide a window corresponding to the id. Show a notification for the hidden
* window.
*
* @param id The id of the window.
*/
public final synchronized void hide(int id) {
// get the view corresponding to the id
final Window window = getWindow(id);
if (window == null) {
throw new IllegalArgumentException("Tried to hide(" + id + ") a null window.");
}
if (window.visibility == Window.VISIBILITY_GONE) {
throw new IllegalStateException("Tried to hide(" + id + ") a window that is not shown.");
}
// alert callbacks and cancel if instructed
if (onHide(id, window)) {
Log.w(TAG, "Window " + id + " hide cancelled by implementation.");
return;
}
// check if hide enabled
if (Utils.isSet(window.flags, StandOutFlags.FLAG_WINDOW_HIDE_ENABLE)) {
window.visibility = Window.VISIBILITY_TRANSITION;
// get the hidden notification for this view
Notification notification = getHiddenNotification(id);
// get animation
Animation animation = getHideAnimation(id);
try {
// animate
if (animation != null) {
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
// remove the window from the window manager
mWindowManager.removeView(window);
window.visibility = Window.VISIBILITY_GONE;
}
});
window.getChildAt(0).startAnimation(animation);
} else {
// remove the window from the window manager
mWindowManager.removeView(window);
}
} catch (Exception ex) {
ex.printStackTrace();
}
// display the notification
notification.flags = notification.flags | Notification.FLAG_NO_CLEAR | Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(getClass().hashCode() + id, notification);
} else {
// if hide not enabled, close window
close(id);
}
}
use of android.view.animation.Animation.AnimationListener in project FloatingStickies by MohammadAdib.
the class StandOutWindow method onTouchHandleMove.
@SuppressWarnings("deprecation")
public boolean onTouchHandleMove(final int id, final Window window, View view, MotionEvent event) {
try {
StandOutLayoutParams params = window.getLayoutParams();
// how much you have to move in either direction in order for the
// gesture to be a move and not tap
int totalDeltaX = window.touchInfo.lastX - window.touchInfo.firstX;
int totalDeltaY = window.touchInfo.lastY - window.touchInfo.firstY;
Animation mFadeOut = AnimationUtils.loadAnimation(this, R.anim.dock);
final Animation mFadeOut2 = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);
final Animation mFadeIn = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
final Animation mFadeIn2 = AnimationUtils.loadAnimation(this, R.anim.show);
final Animation mFadeInG = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
final Animation mFadeOutG = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);
final View win = window.findViewById(R.id.window);
final ImageView dockIcon = (ImageView) window.findViewById(R.id.preview);
final ImageView dockGlow = (ImageView) window.findViewById(R.id.dockglow);
final Drawable drawable = getResources().getDrawable(R.drawable.pencil);
FrameLayout body = (FrameLayout) window.findViewById(R.id.body);
dockIcon.setImageDrawable(getResources().getDrawable((Integer) body.getTag()));
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
window.touchInfo.lastX = (int) event.getRawX();
window.touchInfo.lastY = (int) event.getRawY();
window.touchInfo.firstX = window.touchInfo.lastX;
window.touchInfo.firstY = window.touchInfo.lastY;
break;
case MotionEvent.ACTION_MOVE:
int deltaX = (int) event.getRawX() - window.touchInfo.lastX;
int deltaY = (int) event.getRawY() - window.touchInfo.lastY;
window.touchInfo.lastX = (int) event.getRawX();
window.touchInfo.lastY = (int) event.getRawY();
if (window.touchInfo.moving || Math.abs(totalDeltaX) >= params.threshold || Math.abs(totalDeltaY) >= params.threshold) {
window.touchInfo.moving = true;
// if window is moveable
if (Utils.isSet(window.flags, StandOutFlags.FLAG_BODY_MOVE_ENABLE)) {
// update the position of the window
if (event.getPointerCount() == 1) {
params.x += deltaX;
params.y += deltaY;
}
window.edit().setPosition(params.x, params.y).commit();
if (window.getWidth() < mWindowManager.getDefaultDisplay().getWidth()) {
if (params.x > 0 && window.touchEdge && window.fullSize) {
dockGlow.startAnimation(mFadeOutG);
dockGlow.setVisibility(View.GONE);
window.touchEdge = false;
}
if (params.x > pxFromDp(8)) {
window.touchEdge = false;
// Attempt at undocking.
if (!window.fullSize) {
window.fullSize = true;
undocking = true;
dockIcon.setVisibility(View.GONE);
mFadeOut2.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
Log.d("FloatingFolder", "Animation started");
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
Log.d("FloatingFolder", "Animation ended");
// post so that screenshot
// is
// invisible
// before anything else
// happens
dockIcon.post(new Runnable() {
@Override
public void run() {
StandOutLayoutParams params = window.getLayoutParams();
Drawable drawable = dockIcon.getDrawable();
dockIcon.setImageDrawable(null);
params.y = params.y - window.dockH / 2 + drawable.getIntrinsicHeight() / 2;
params.width = window.dockW;
params.height = window.dockH;
updateViewLayout(id, params);
win.setVisibility(View.VISIBLE);
gracePeriod = System.currentTimeMillis();
win.startAnimation(mFadeIn2);
undocking = false;
}
});
}
});
gracePeriod = System.currentTimeMillis();
dockIcon.startAnimation(mFadeOut2);
}
} else {
if (!window.touchEdge && params.x <= 0) {
dockGlow.setVisibility(View.VISIBLE);
dockGlow.startAnimation(mFadeInG);
window.touchEdge = true;
}
}
}
} else {
window.edit().setPosition(params.x, params.y).commit();
}
}
break;
case MotionEvent.ACTION_UP:
if (window.fullSize && window.getWidth() < mWindowManager.getDefaultDisplay().getWidth()) {
// Attempt at docking
if (params.x <= 0 && !undocking) {
window.dockH = window.getHeight();
window.dockW = window.getWidth();
window.fullSize = false;
mFadeOut.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
dockGlow.setVisibility(View.GONE);
win.setVisibility(View.GONE);
// post so that the folder is invisible
// before
// anything else happens
dockIcon.post(new Runnable() {
@Override
public void run() {
StandOutLayoutParams params = window.getLayoutParams();
params.y = params.y + params.height / 2 - pxFromDp(40) / 2;
params.width = pxFromDp(40);
params.height = pxFromDp(40);
updateViewLayout(id, params);
dockIcon.setVisibility(View.VISIBLE);
dockIcon.startAnimation(mFadeIn);
}
});
}
});
gracePeriod = System.currentTimeMillis();
win.startAnimation(mFadeOut);
}
window.touchInfo.moving = false;
onMove(id, window, view, event);
break;
}
if (!window.fullSize && params.x > 0 && params.x <= pxFromDp(8)) {
window.edit().setPosition(0, params.y).commit();
}
// bring to front on tap
boolean tap = Math.abs(totalDeltaX) < params.threshold && Math.abs(totalDeltaY) < params.threshold;
if (tap) {
StandOutWindow.this.bringToFront(id);
}
}
} catch (Exception e) {
}
return true;
}
use of android.view.animation.Animation.AnimationListener in project UltimateAndroid by cymcsg.
the class AbstractSlideExpandableListAdapter method animateView.
/**
* Performs either COLLAPSE or EXPAND animation on the target view
*
* @param target the view to animate
* @param type the animation type, either ExpandCollapseAnimation.COLLAPSE
* or ExpandCollapseAnimation.EXPAND
*/
private void animateView(final View target, final int type) {
Animation anim = new ExpandCollapseAnimation(target, type);
anim.setDuration(getAnimationDuration());
anim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
if (type == ExpandCollapseAnimation.EXPAND) {
if (parent instanceof ListView) {
ListView listView = (ListView) parent;
int movement = target.getBottom();
Rect r = new Rect();
boolean visible = target.getGlobalVisibleRect(r);
Rect r2 = new Rect();
listView.getGlobalVisibleRect(r2);
if (!visible) {
listView.smoothScrollBy(movement, getAnimationDuration());
} else {
if (r2.bottom == r.bottom) {
listView.smoothScrollBy(movement, getAnimationDuration());
}
}
}
}
}
});
target.startAnimation(anim);
}
use of android.view.animation.Animation.AnimationListener in project UltimateAndroid by cymcsg.
the class AnimationFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mListView = (QuickReturnListView) getListView();
mQuickReturnView.setText("Animation");
mListView.addHeaderView(mHeader);
String[] array = new String[] { "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android", "Android" };
setListAdapter(new ArrayAdapter<String>(getActivity(), R.layout.quick_return_listview_list_item, R.id.text1, array));
mListView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mQuickReturnHeight = mQuickReturnView.getHeight();
mListView.computeScrollY();
mCachedVerticalScrollRange = mListView.getListHeight();
}
});
mListView.setOnScrollListener(new OnScrollListener() {
@SuppressLint("NewApi")
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
mScrollY = 0;
int translationY = 0;
if (mListView.scrollYIsComputed()) {
mScrollY = mListView.getComputedScrollY();
}
rawY = mPlaceHolder.getTop() - Math.min(mCachedVerticalScrollRange - mListView.getHeight(), mScrollY);
switch(mState) {
case STATE_OFFSCREEN:
if (rawY <= mMinRawY) {
mMinRawY = rawY;
} else {
mState = STATE_RETURNING;
}
translationY = rawY;
break;
case STATE_ONSCREEN:
if (rawY < -mQuickReturnHeight) {
System.out.println("test3");
mState = STATE_OFFSCREEN;
mMinRawY = rawY;
}
translationY = rawY;
break;
case STATE_RETURNING:
if (translationY > 0) {
translationY = 0;
mMinRawY = rawY - mQuickReturnHeight;
} else if (rawY > 0) {
mState = STATE_ONSCREEN;
translationY = rawY;
} else if (translationY < -mQuickReturnHeight) {
mState = STATE_OFFSCREEN;
mMinRawY = rawY;
} else if (mQuickReturnView.getTranslationY() != 0 && !noAnimation) {
noAnimation = true;
anim = new TranslateAnimation(0, 0, -mQuickReturnHeight, 0);
anim.setFillAfter(true);
anim.setDuration(250);
mQuickReturnView.startAnimation(anim);
anim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
noAnimation = false;
mMinRawY = rawY;
mState = STATE_EXPANDED;
}
});
}
break;
case STATE_EXPANDED:
if (rawY < mMinRawY - 2 && !noAnimation) {
noAnimation = true;
anim = new TranslateAnimation(0, 0, 0, -mQuickReturnHeight);
anim.setFillAfter(true);
anim.setDuration(250);
anim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
noAnimation = false;
mState = STATE_OFFSCREEN;
}
});
mQuickReturnView.startAnimation(anim);
} else if (translationY > 0) {
translationY = 0;
mMinRawY = rawY - mQuickReturnHeight;
} else if (rawY > 0) {
mState = STATE_ONSCREEN;
translationY = rawY;
} else if (translationY < -mQuickReturnHeight) {
mState = STATE_OFFSCREEN;
mMinRawY = rawY;
} else {
mMinRawY = rawY;
}
}
/** this can be used if the build is below honeycomb **/
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB) {
anim = new TranslateAnimation(0, 0, translationY, translationY);
anim.setFillAfter(true);
anim.setDuration(0);
mQuickReturnView.startAnimation(anim);
} else {
mQuickReturnView.setTranslationY(translationY);
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
});
}
Aggregations