2017-10-11 8 views
-1

私はdialogFragmentユーザーがパスワードをリセットしたときに成功した結果、linearlayoutは3ドットアニメーションを表示しないようにしていますが、アニメーションをキャンセルする必要があります。またはlinearlayoutが表示されていない場合、アニメーションはトリガーされませんか?アニメーションが表示されていない場合、アニメーションをキャンセルする必要がありますか?

ビューが見えない、または消えた場合、アニメーションが連続しているかどうかを知りたいだけですか?

ありがとうございます。

enter image description here enter image description here

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); 
} 
} 
+0

アニメーションコードで回答を編集して確認することができます。 – tamtom

答えて

0

私はデバッグをいくつか行いました。ビューが見えない場合、アニメーションが機能していないことが分かりました。

0

あなたはキャンセルまたは内部にあなたのアニメーションを止める設定することができます方法onResume()またはONSTART()、アクティビティが作成されたときにこれらのメソッドが呼び出されます。あなたが確認できる詳細情報についてActivity Lifecycle

関連する問題