-
Notifications
You must be signed in to change notification settings - Fork 17
Basketball HW #13
base: master
Are you sure you want to change the base?
Basketball HW #13
Conversation
Сила броска зависит от вертикального слайда по мячу. Область попадания сделал соразмерной щиту, чтобы почаще попадать) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Хорошая работа. Небольшие правки
|
||
final View ball = getBall(); | ||
ViewTreeObserver ballObserver = ball.getViewTreeObserver(); | ||
ballObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можно конечно и GlobalLayoutListener использовать, но тут достаточно post
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправил
public boolean onTouch(View v, MotionEvent event) { | ||
switch (event.getAction()) { | ||
case MotionEvent.ACTION_DOWN: { | ||
velocityTracker = VelocityTracker.obtain(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше перед тем как брать новый VelocityTracker отпустить старый методом recycle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Сделал
TypeEvaluator<Float> xEvaluator = new TypeEvaluator<Float>() { | ||
@Override | ||
public Float evaluate(float fraction, Float startValue, Float endValue) { | ||
// float result = startValue + fraction * xVelocity; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это была попытка учесть горизонтальную скорость, но там надо подзапариться с формулами из физики, чтобы получить startValue и endValue. По закоменченой формуле анимация заканчивается раньше, чем необходимо, поэтому не стал ее использовать.
}); | ||
} | ||
|
||
private void animateBall(final View ball, final float xVelocity, final float yVelocity) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xVelocity не используется
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Убрал
@Override | ||
protected void onStop() { | ||
super.onStop(); | ||
velocityTracker.recycle(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если ни разу не кинуть и свернуть приложение будет NPE. Т.к. velocityTracker и animatorSet могут быть еще не созданы
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Пофиксил
float rating = ((float) successfulThrows / allThrows) * starCount; | ||
ratingView.setActiveStarCount(Math.round(rating)); | ||
TextView counter = findViewById(R.id.point_counter); | ||
counter.setText(String.format("%d/%d", successfulThrows, allThrows)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Когда работаешь с числами в строках, лучше явно указывать локаль. Т.к. не на всех языках цифры выглядят так, как мы привыкли
String.format(Locale.ENGLISH, "%d/%d", successfulThrows, allThrows)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Добавил, запомню на будущее
} | ||
|
||
private void updateViews() { | ||
RatingView ratingView = findViewById(R.id.star_rating); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не обязательно каждый раз искать view, можно сохранить его в поле класса
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Добавил в поля класса
Работа принята |
No description provided.