私はdialogFragment
ユーザーがパスワードをリセットしたときに成功した結果、linearlayout
は3ドットアニメーションを表示しないようにしていますが、アニメーションをキャンセルする必要があります。またはlinearlayout
が表示されていない場合、アニメーションはトリガーされませんか?アニメーションが表示されていない場合、アニメーションをキャンセルする必要がありますか?
ビューが見えない、または消えた場合、アニメーションが連続しているかどうかを知りたいだけですか?
ありがとうございます。
public class ResetPasswordDialog extends android.support.v4.app.DialogFragment {
private EditText emailInput;
private ImageView firstDot, secondDot, thirdDot;
private LinearLayout dotsLinear;
private Handler handler;
private Runnable runnable;
private Animation anim;
private Animation anim2;
private Animation anim3;
private Handler timeoutHandler;
private Runnable stopLoadingRunnable;
private TextView resetPassword;
public static ResetPasswordDialog newInstance() {
Bundle args = new Bundle();
ResetPasswordDialog fragment = new ResetPasswordDialog();
fragment.setArguments(args);
return fragment;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.reset_password, container, false);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
emailInput = (EditText) view.findViewById(R.id.et_email);
firstDot = (ImageView) view.findViewById(R.id.first_dot);
secondDot = (ImageView) view.findViewById(R.id.second_dot);
thirdDot = (ImageView) view.findViewById(R.id.third_dot);
dotsLinear = (LinearLayout) view.findViewById(R.id.dotsLinear);
resetPassword = (TextView) view.findViewById(R.id.reset_password);
initAnimation();
timeoutHandler = new Handler();
stopLoadingRunnable = new Runnable() {
@Override
public void run() {
Toast.makeText(getActivity(), R.string.reset_password_failed, Toast.LENGTH_SHORT).show();
stopDotsAnimation();
resetPassword.setVisibility(View.VISIBLE);
}
};
resetPassword.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ApiUtility.isEmailValid(emailInput.getText().toString())) {
startDotsAnimation();
resetPassword.setVisibility(View.INVISIBLE);
timeoutHandler.postDelayed(stopLoadingRunnable, 15000);
dotsLinear.setVisibility(View.VISIBLE);
emailInput.clearFocus();
ApiUtility.checkCustomerEmail(emailInput.getText().toString(), new ApiUtility.AuthenticationDelegate() {
@Override
public void invoke(MeetsCustomer meetsCustomer, Exception e) {
if (e == null) {
((LogInFragment) getTargetFragment()).attemptToResetPassword(emailInput.getText().toString());
} else if (e.toString().equals("java.lang.Exception: Customer not found")) {
resetPassword.setVisibility(View.VISIBLE);
removeTimeOutHandler();
stopDotsAnimation();
Toast.makeText(PlatformApplication.context, R.string.customer_not_found, Toast.LENGTH_SHORT).show();
} else {
removeTimeOutHandler();
stopDotsAnimation();
resetPassword.setVisibility(View.VISIBLE);
Toast.makeText(PlatformApplication.context, R.string.reset_password_failed, Toast.LENGTH_SHORT).show();
}
}
});
} else {
Toast.makeText(getActivity(), R.string.invalid_email, Toast.LENGTH_SHORT).show();
}
}
});
}
private void initAnimation() {
anim = new AlphaAnimation(0f, 1f);
anim.setDuration(600);
anim2 = new AlphaAnimation(0f, 1f);
anim2.setDuration(600);
anim2.setStartOffset(200);
anim3 = new AlphaAnimation(0f, 1f);
anim3.setDuration(600);
anim3.setStartOffset(400);
}
private void startDotsAnimation() {
handler = new Handler();
runnable = new Runnable() {
@Override
public void run() {
firstDot.startAnimation(anim);
secondDot.startAnimation(anim2);
thirdDot.startAnimation(anim3);
handler.postDelayed(this, 1000);
}
};
handler.post(runnable);
}
public void stopDotsAnimation() {
handler.removeCallbacks(runnable);
firstDot.getAnimation().cancel();
secondDot.getAnimation().cancel();
thirdDot.getAnimation().cancel();
dotsLinear.setVisibility(View.INVISIBLE);
}
public void removeTimeOutHandler() {
timeoutHandler.removeCallbacks(stopLoadingRunnable);
}
}
アニメーションコードで回答を編集して確認することができます。 – tamtom