7 package com.google.appinventor.components.runtime.util;
9 import android.app.Activity;
10 import android.util.Log;
11 import android.view.View;
12 import android.view.animation.Animation;
13 import android.view.animation.AnimationSet;
14 import android.view.animation.TranslateAnimation;
32 private static void ApplyHorizontalScrollAnimation(View view,
boolean left,
int speed) {
33 float sign = left ? 1f : -1f;
34 AnimationSet animationSet =
new AnimationSet(
true);
35 animationSet.setRepeatCount(Animation.INFINITE);
36 animationSet.setRepeatMode(Animation.RESTART);
38 TranslateAnimation move =
new TranslateAnimation(Animation.RELATIVE_TO_PARENT, sign * 0.70f,
39 Animation.RELATIVE_TO_PARENT, sign * -0.70f, Animation.RELATIVE_TO_PARENT, 0,
40 Animation.RELATIVE_TO_PARENT, 0);
41 move.setStartOffset(0);
42 move.setDuration(speed);
43 move.setFillAfter(
true);
44 animationSet.addAnimation(move);
45 view.startAnimation(animationSet);
57 if (animation.equals(
"ScrollRightSlow")) {
58 ApplyHorizontalScrollAnimation(view,
false, 8000);
59 }
else if (animation.equals(
"ScrollRight")) {
60 ApplyHorizontalScrollAnimation(view,
false, 4000);
61 }
else if (animation.equals(
"ScrollRightFast")) {
62 ApplyHorizontalScrollAnimation(view,
false, 1000);
63 }
else if (animation.equals(
"ScrollLeftSlow")) {
64 ApplyHorizontalScrollAnimation(view,
true, 8000);
65 }
else if (animation.equals(
"ScrollLeft")) {
66 ApplyHorizontalScrollAnimation(view,
true, 4000);
67 }
else if (animation.equals(
"ScrollLeftFast")) {
68 ApplyHorizontalScrollAnimation(view,
true, 1000);
69 }
else if (animation.equals(
"Stop")) {
70 view.clearAnimation();
82 if (animType ==
null) {
86 Log.e(
"AnimationUtil",
"Screen animations are not available on android versions less than 2.0.");
92 if (animType.equalsIgnoreCase(
"fade")) {
93 enter = activity.getResources().getIdentifier(
"fadein",
"anim", activity.getPackageName());
94 exit = activity.getResources().getIdentifier(
"hold",
"anim", activity.getPackageName());
95 }
else if (animType.equalsIgnoreCase(
"zoom")) {
96 exit = activity.getResources().getIdentifier(
"zoom_exit",
"anim", activity.getPackageName());
97 enter = activity.getResources().getIdentifier(
"zoom_enter",
"anim", activity.getPackageName());
98 }
else if (animType.equalsIgnoreCase(
"slidehorizontal")) {
99 exit = activity.getResources().getIdentifier(
"slide_exit",
"anim", activity.getPackageName());
100 enter = activity.getResources().getIdentifier(
"slide_enter",
"anim", activity.getPackageName());
101 }
else if (animType.equalsIgnoreCase(
"slidevertical")) {
102 exit = activity.getResources().getIdentifier(
"slide_v_exit",
"anim", activity.getPackageName());
103 enter = activity.getResources().getIdentifier(
"slide_v_enter",
"anim", activity.getPackageName());
104 }
else if (animType.equalsIgnoreCase(
"none")) {
122 if (animType ==
null) {
126 Log.e(
"AnimationUtil",
"Screen animations are not available on android versions less than 2.0.");
131 if (animType.equalsIgnoreCase(
"fade")) {
132 exit = activity.getResources().getIdentifier(
"fadeout",
"anim", activity.getPackageName());
133 enter = activity.getResources().getIdentifier(
"hold",
"anim", activity.getPackageName());
134 }
else if (animType.equalsIgnoreCase(
"zoom")) {
135 exit = activity.getResources().getIdentifier(
"zoom_exit_reverse",
"anim", activity.getPackageName());
136 enter = activity.getResources().getIdentifier(
"zoom_enter_reverse",
"anim", activity.getPackageName());
137 }
else if (animType.equalsIgnoreCase(
"slidehorizontal")) {
138 exit = activity.getResources().getIdentifier(
"slide_exit_reverse",
"anim", activity.getPackageName());
139 enter = activity.getResources().getIdentifier(
"slide_enter_reverse",
"anim", activity.getPackageName());
140 }
else if (animType.equalsIgnoreCase(
"slidevertical")) {
141 exit = activity.getResources().getIdentifier(
"slide_v_exit_reverse",
"anim", activity.getPackageName());
142 enter = activity.getResources().getIdentifier(
"slide_v_enter_reverse",
"anim", activity.getPackageName());
143 }
else if (animType.equalsIgnoreCase(
"none")) {