Skip to content
This repository was archived by the owner on Nov 30, 2021. It is now read-only.

Comments

Homework 4.2#3

Open
AndreiGrek wants to merge 2 commits intomasterfrom
Homework4.2
Open

Homework 4.2#3
AndreiGrek wants to merge 2 commits intomasterfrom
Homework4.2

Conversation

@AndreiGrek
Copy link
Owner

No description provided.

Comment on lines 18 to 25
Random rand = new Random();
View arc1;
Paint paintTemp;
Paint paintSmall;
Paint paintArc1;
Paint paintArc2;
Paint paintArc3;
Paint paintArc4;

Choose a reason for hiding this comment

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

нет модификаторов доступа. в данном случае это обычные поля класса. они должны быть приватными


if (event.getAction() == MotionEvent.ACTION_DOWN) {
// Toast.makeText(this, "ergerg", Toast.LENGTH_SHORT).show();
if ((event.getX() - centerX) * (event.getX() - centerX) + (event.getY() - centerY) * (event.getY() - centerY) <= 150 * 150) {

Choose a reason for hiding this comment

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

Я бы посоветовал вынести расчеты в отдельные методы и просто их здесь вызывать. Так код твой намного проще будет понимать

paintArc2.setColor(paintArc1.getColor());
paintArc1.setColor(paintTemp.getColor());
invalidate();
} else if ((event.getX() - centerX) * (event.getX() - centerX) + (event.getY() - centerY) * (event.getY() - centerY) <= 400 * 400) {

Choose a reason for hiding this comment

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

Я бы посоветовал вынести расчеты в отдельные методы и просто их здесь вызывать. Так код твой намного проще будет понимать

paintArc1.setColor(paintTemp.getColor());
invalidate();
} else if ((event.getX() - centerX) * (event.getX() - centerX) + (event.getY() - centerY) * (event.getY() - centerY) <= 400 * 400) {
if (event.getX() > centerX && event.getX() < centerX + 400 && event.getY() > centerY && event.getY() < centerY + 400) {

Choose a reason for hiding this comment

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

Я бы посоветовал вынести расчеты в отдельные методы и просто их здесь вызывать. Так код твой намного проще будет понимать

if (event.getX() > centerX && event.getX() < centerX + 400 && event.getY() > centerY && event.getY() < centerY + 400) {
paintArc1.setColor(rand.nextInt(2147483646));
invalidate();
} else if (event.getX() < centerX && event.getX() > centerX - 400 && event.getY() > centerY && event.getY() < centerY + 400) {

Choose a reason for hiding this comment

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

Я бы посоветовал вынести расчеты в отдельные методы и просто их здесь вызывать. Так код твой намного проще будет понимать

} else if (event.getX() < centerX && event.getX() > centerX - 400 && event.getY() > centerY && event.getY() < centerY + 400) {
paintArc2.setColor(rand.nextInt(2147483646));
invalidate();
} else if (event.getX() < centerX && event.getX() > centerX - 400 && event.getY() < centerY && event.getY() > centerY - 400) {

Choose a reason for hiding this comment

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

Я бы посоветовал вынести расчеты в отдельные методы и просто их здесь вызывать. Так код твой намного проще будет понимать

} else if (event.getX() < centerX && event.getX() > centerX - 400 && event.getY() < centerY && event.getY() > centerY - 400) {
paintArc3.setColor(rand.nextInt(2147483646));
invalidate();
} else if (event.getX() > centerX && event.getX() < centerX + 400 && event.getY() < centerY && event.getY() > centerY - 400) {

Choose a reason for hiding this comment

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

Я бы посоветовал вынести расчеты в отдельные методы и просто их здесь вызывать. Так код твой намного проще будет понимать


import java.util.Random;

public class Custom extends View {

Choose a reason for hiding this comment

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

Не самое удачное имя для класса. Не сразу понятно что тут имеется ввиду.

}

@Override
public boolean onTouchEvent(MotionEvent event) {

Choose a reason for hiding this comment

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

Смотри. У тебя есть твоя вьюха Custom. Именно она должна сообщать о том, что она нажата и передавать в активити координаты. В твоей же реализации onTouchEvent в этой активити отрабатывает на нажатие всего активити. В общем. Тебе надо создать свой лисенер и установить его в твою view. И если у тебя будет нажат сектор, то через этот лисенер надо передать в активити координаты.

Choose a reason for hiding this comment

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

import android.view.MotionEvent;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

Choose a reason for hiding this comment

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

Если не ошибаюсь, то в задании надо было добавить Switch и показывать либо Toast, либо Snackbar

private int centerY;
private float smallCircleArea;
private float bigCircleArea;
CoordinateListener coordinateListener;

Choose a reason for hiding this comment

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

Нет модификатора доступа =)

invalidate();
} else if (isSecondSector(event)) {
paintArc2.setColor(rand.nextInt(2147483646));
coordinateListener.getCoordinates(event.getX(), event.getY(), paintArc2.getColor());

Choose a reason for hiding this comment

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

coordinateListener тоже лучше проверять на null. Java же сама по себе подразумевает что любой объект может быть null, а тут ты его еще и устанавливаешь через сеттер. Так что ты точно не можешь сказать что он не null. В этом случае я бы еще порекомендовал вынести работу с coordinateListener в отдельный метод, а координаты и цвет передавать туда в качестве параметров метода

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants