Skip to content
This repository has been archived by the owner on Mar 1, 2021. It is now read-only.

Basketball HW #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Basketball HW #13

wants to merge 2 commits into from

Conversation

p-daniil
Copy link

No description provided.

@p-daniil
Copy link
Author

Сила броска зависит от вертикального слайда по мячу. Область попадания сделал соразмерной щиту, чтобы почаще попадать)

@otopba otopba self-requested a review April 29, 2019 21:14
Copy link

@otopba otopba left a 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() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно конечно и GlobalLayoutListener использовать, но тут достаточно post

Copy link
Author

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();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше перед тем как брать новый VelocityTracker отпустить старый методом recycle

Copy link
Author

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;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Author

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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xVelocity не используется

Copy link
Author

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();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если ни разу не кинуть и свернуть приложение будет NPE. Т.к. velocityTracker и animatorSet могут быть еще не созданы

Copy link
Author

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));
Copy link

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)

Copy link
Author

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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не обязательно каждый раз искать view, можно сохранить его в поле класса

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавил в поля класса

@otopba
Copy link

otopba commented May 4, 2019

Работа принята
10 балов

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants