From 67055b73837a5020748e838b16768eab79560f4c Mon Sep 17 00:00:00 2001 From: Nadya Date: Sun, 7 Apr 2019 19:57:31 +0300 Subject: [PATCH 1/5] def --- app/src/main/AndroidManifest.xml | 3 +- app/src/main/res/layout/activity_main.xml | 40 +++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 84e3889..ecf75f6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,7 +9,8 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> - + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 037bef1..dc9f004 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,5 +6,45 @@ android:layout_height="match_parent" tools:context=".MainActivity"> + + + + + + + \ No newline at end of file From d115acb5232b99468547c464b0fc1d30d985cab8 Mon Sep 17 00:00:00 2001 From: Nadya Date: Wed, 10 Apr 2019 23:43:36 +0300 Subject: [PATCH 2/5] def --- .../technopolis/basketball/MainActivity.java | 140 ++++++++++++++++++ .../main/res/drawable/ic_grade_black_24dp.xml | 5 + .../main/res/drawable/ic_grade_red_24dp.xml | 5 + app/src/main/res/layout/activity_main.xml | 87 ++++++++--- 4 files changed, 218 insertions(+), 19 deletions(-) create mode 100644 app/src/main/res/drawable/ic_grade_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_grade_red_24dp.xml diff --git a/app/src/main/java/ru/ok/technopolis/basketball/MainActivity.java b/app/src/main/java/ru/ok/technopolis/basketball/MainActivity.java index 8f71141..33ab9d9 100644 --- a/app/src/main/java/ru/ok/technopolis/basketball/MainActivity.java +++ b/app/src/main/java/ru/ok/technopolis/basketball/MainActivity.java @@ -2,12 +2,152 @@ import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; +import android.animation.ValueAnimator; +import android.support.constraint.ConstraintLayout; +import android.view.GestureDetector; +import android.view.MotionEvent; +import android.view.View; +import android.widget.ImageView; +import android.annotation.SuppressLint; public class MainActivity extends AppCompatActivity { + private ImageView ball; + private ImageView hoop; + private float beginX; + private float beginY; + public int hits = 0; + private boolean hit = false; + @SuppressLint("ClickableViewAccessibility") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + ball = findViewById(R.id.activity_main_ball); + hoop = findViewById(R.id.activity_main_hoop); + + final ConstraintLayout activityMain = findViewById(R.id.activity_main); + + final GestureDetector gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() { + @Override + public boolean onDown(MotionEvent e) { + beginX = ball.getX(); + beginY = ball.getY(); + return true; + } + + @Override + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { + + float targetSize = (float) hoop.getWidth() / 3 - (float) ball.getWidth() *0.8f; + float xHoop = hoop.getX(); + float yHoop = hoop.getY(); + + return AnimatorTrack((e2.getRawX() - e1.getRawX()), (e2.getRawY() - e1.getRawY()), xHoop, yHoop, targetSize); + } + }); + + activityMain.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + gestureDetector.onTouchEvent(event); + return true; + } + }); + } + + public boolean AnimatorTrack(final float X, final float Y, final float xHoop, final float yHoop, final float targetSize) { + ValueAnimator aniView = ValueAnimator.ofFloat(0, 1); + + aniView.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + @Override + public void onAnimationUpdate(ValueAnimator valueAnimator) { + float x = ball.getX(); + float y = ball.getY(); + int rotation = 50 + (int) (Math.random() * 101); + + float value = (Float) valueAnimator.getAnimatedValue(); + float angle = value * 3.14f; + + ball.setRotation(rotation * value); + ball.setTranslationX((float) ((1 - Math.cos(angle)) * X)); + ball.setTranslationY((float) (-Math.sin(angle) * Math.abs(Y))); + + if ((Math.abs(xHoop - x) <= targetSize) && (Math.abs(yHoop - y) <= targetSize)) hit = true; + } + }); + + aniView.addListener(new AnimatorListenerAdapter() { + + @Override + public void onAnimationStart(Animator animation) { + super.onAnimationStart(animation); + ball.setX(beginX); + ball.setY(beginY); + if (hits ==5 || hits ==0) { + hits =0; + SetStars(hits); + } + } + + @Override + public void onAnimationEnd(Animator animation) { + super.onAnimationStart(animation); + ball.setX(beginX); + ball.setY(beginY); + if (hit) { + hits++; + SetStars(hits); + hit = false; + } + } + }); + aniView.setDuration(1200); + aniView.start(); + + return true; + } + + public void SetStars(int hits) { + ImageView star; + switch (hits) { + case 1: + star = findViewById(R.id.imageStar1); + star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_red_24dp)); + break; + case 2: + star = findViewById(R.id.imageStar2); + star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_red_24dp)); + break; + case 3: + star = findViewById(R.id.imageStar3); + star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_red_24dp)); + break; + case 4: + star = findViewById(R.id.imageStar4); + star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_red_24dp)); + break; + case 5: + star = findViewById(R.id.imageStar5); + star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_red_24dp)); + hits = 0; + break; + default: + star = findViewById(R.id.imageStar1); + star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_black_24dp)); + star = findViewById(R.id.imageStar2); + star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_black_24dp)); + star = findViewById(R.id.imageStar3); + star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_black_24dp)); + star = findViewById(R.id.imageStar4); + star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_black_24dp)); + star = findViewById(R.id.imageStar5); + star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_black_24dp)); + hits = 0; + break; + } + return; } } diff --git a/app/src/main/res/drawable/ic_grade_black_24dp.xml b/app/src/main/res/drawable/ic_grade_black_24dp.xml new file mode 100644 index 0000000..61ddfdf --- /dev/null +++ b/app/src/main/res/drawable/ic_grade_black_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_grade_red_24dp.xml b/app/src/main/res/drawable/ic_grade_red_24dp.xml new file mode 100644 index 0000000..6db0584 --- /dev/null +++ b/app/src/main/res/drawable/ic_grade_red_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index dc9f004..016a8af 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -2,49 +2,98 @@ + app:layout_constraintStart_toStartOf="parent" /> - + app:layout_constraintTop_toTopOf="parent" + app:srcCompat="@drawable/ic_grade_black_24dp" + tools:alpha="4" + android:contentDescription="TODO" /> + + + + + + + + + \ No newline at end of file From 8ead8e49efa0e4cbc25d15bfd9fda72067bfdbe8 Mon Sep 17 00:00:00 2001 From: Nadya Date: Sat, 4 May 2019 18:37:58 +0300 Subject: [PATCH 3/5] def --- .../technopolis/basketball/MainActivity.java | 58 +++++++++---------- app/src/main/res/layout/activity_main.xml | 19 +++--- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- 4 files changed, 41 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/ru/ok/technopolis/basketball/MainActivity.java b/app/src/main/java/ru/ok/technopolis/basketball/MainActivity.java index 33ab9d9..484d7b7 100644 --- a/app/src/main/java/ru/ok/technopolis/basketball/MainActivity.java +++ b/app/src/main/java/ru/ok/technopolis/basketball/MainActivity.java @@ -1,5 +1,6 @@ package ru.ok.technopolis.basketball; +import android.graphics.drawable.Drawable; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.animation.Animator; @@ -28,7 +29,7 @@ protected void onCreate(Bundle savedInstanceState) { ball = findViewById(R.id.activity_main_ball); hoop = findViewById(R.id.activity_main_hoop); - final ConstraintLayout activityMain = findViewById(R.id.activity_main); + final ConstraintLayout idMain = findViewById(R.id.activity_main); final GestureDetector gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() { @Override @@ -49,7 +50,7 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve } }); - activityMain.setOnTouchListener(new View.OnTouchListener() { + idMain.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { gestureDetector.onTouchEvent(event); @@ -59,27 +60,27 @@ public boolean onTouch(View v, MotionEvent event) { } public boolean AnimatorTrack(final float X, final float Y, final float xHoop, final float yHoop, final float targetSize) { - ValueAnimator aniView = ValueAnimator.ofFloat(0, 1); + ValueAnimator anyView = ValueAnimator.ofFloat(0, 1); - aniView.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + anyView.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float x = ball.getX(); float y = ball.getY(); int rotation = 50 + (int) (Math.random() * 101); - float value = (Float) valueAnimator.getAnimatedValue(); + float value = (float) valueAnimator.getAnimatedValue(); float angle = value * 3.14f; ball.setRotation(rotation * value); ball.setTranslationX((float) ((1 - Math.cos(angle)) * X)); ball.setTranslationY((float) (-Math.sin(angle) * Math.abs(Y))); - if ((Math.abs(xHoop - x) <= targetSize) && (Math.abs(yHoop - y) <= targetSize)) hit = true; + if ((Math.abs(xHoop - x) <= targetSize) && (Math.abs(yHoop - y) <= targetSize)) { hit = true;} } }); - aniView.addListener(new AnimatorListenerAdapter() { + anyView.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { @@ -104,47 +105,44 @@ public void onAnimationEnd(Animator animation) { } } }); - aniView.setDuration(1200); - aniView.start(); + anyView.setDuration(1200); + anyView.start(); return true; } public void SetStars(int hits) { - ImageView star; + Drawable redStar = getResources().getDrawable(R.drawable.ic_grade_red_24dp); + Drawable blackStar = getResources().getDrawable(R.drawable.ic_grade_black_24dp); + ImageView star1=findViewById(R.id.image_Star1); + ImageView star2=findViewById(R.id.image_Star2); + ImageView star3=findViewById(R.id.image_Star3); + ImageView star4=findViewById(R.id.image_Star4); + ImageView star5=findViewById(R.id.image_Star5); + switch (hits) { case 1: - star = findViewById(R.id.imageStar1); - star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_red_24dp)); + star1.setImageDrawable(redStar); break; case 2: - star = findViewById(R.id.imageStar2); - star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_red_24dp)); + star2.setImageDrawable(redStar); break; case 3: - star = findViewById(R.id.imageStar3); - star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_red_24dp)); + star3.setImageDrawable(redStar); break; case 4: - star = findViewById(R.id.imageStar4); - star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_red_24dp)); + star4.setImageDrawable(redStar); break; case 5: - star = findViewById(R.id.imageStar5); - star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_red_24dp)); + star5.setImageDrawable(redStar); hits = 0; break; default: - star = findViewById(R.id.imageStar1); - star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_black_24dp)); - star = findViewById(R.id.imageStar2); - star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_black_24dp)); - star = findViewById(R.id.imageStar3); - star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_black_24dp)); - star = findViewById(R.id.imageStar4); - star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_black_24dp)); - star = findViewById(R.id.imageStar5); - star.setImageDrawable(getResources().getDrawable(R.drawable.ic_grade_black_24dp)); + star1.setImageDrawable(blackStar); + star2.setImageDrawable(blackStar); + star3.setImageDrawable(blackStar); + star4.setImageDrawable(blackStar); + star5.setImageDrawable(blackStar); hits = 0; break; } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 016a8af..78e4634 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -22,6 +22,7 @@ android:layout_width="76dp" android:layout_height="131dp" android:layout_marginLeft="50dp" + android:layout_marginStart="30dp" android:layout_marginBottom="10dp" android:src="@drawable/player" app:layout_constraintBottom_toBottomOf="parent" @@ -39,7 +40,7 @@ app:layout_constraintStart_toStartOf="parent" /> diff --git a/build.gradle b/build.gradle index e11a5b3..fafc1b9 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.3.2' + classpath 'com.android.tools.build:gradle:3.4.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d8eb277..f586200 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Mar 24 00:28:03 MSK 2019 +#Sat Apr 27 16:19:44 MSK 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip From eaec775f42ea56c652c52ccd6f37c3cede9f5acf Mon Sep 17 00:00:00 2001 From: Nadya Date: Sat, 4 May 2019 18:43:43 +0300 Subject: [PATCH 4/5] def --- app/src/main/res/layout/activity_main.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 78e4634..3bb3aca 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -22,7 +22,7 @@ android:layout_width="76dp" android:layout_height="131dp" android:layout_marginLeft="50dp" - android:layout_marginStart="30dp" + android:layout_marginStart="60dp" android:layout_marginBottom="10dp" android:src="@drawable/player" app:layout_constraintBottom_toBottomOf="parent" From c8e919a923c486a121e5d7f1f88d9bac43da7b90 Mon Sep 17 00:00:00 2001 From: Nadya Date: Tue, 4 Jun 2019 22:29:53 +0300 Subject: [PATCH 5/5] def --- .../technopolis/basketball/MainActivity.java | 63 ++++++++++++------- app/src/main/res/layout/activity_main.xml | 18 +++--- 2 files changed, 51 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/ru/ok/technopolis/basketball/MainActivity.java b/app/src/main/java/ru/ok/technopolis/basketball/MainActivity.java index 484d7b7..ff593ea 100644 --- a/app/src/main/java/ru/ok/technopolis/basketball/MainActivity.java +++ b/app/src/main/java/ru/ok/technopolis/basketball/MainActivity.java @@ -20,6 +20,14 @@ public class MainActivity extends AppCompatActivity { private float beginY; public int hits = 0; private boolean hit = false; + private ValueAnimator animatorValue; + public Drawable redStar; + public Drawable blackStar; + public ImageView star1; + public ImageView star2; + public ImageView star3; + public ImageView star4; + public ImageView star5; @SuppressLint("ClickableViewAccessibility") @Override @@ -28,8 +36,15 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); ball = findViewById(R.id.activity_main_ball); hoop = findViewById(R.id.activity_main_hoop); + redStar = getResources().getDrawable(R.drawable.ic_grade_red_24dp); + blackStar = getResources().getDrawable(R.drawable.ic_grade_black_24dp); + star1=findViewById(R.id.image_star1); + star2=findViewById(R.id.image_star2); + star3=findViewById(R.id.image_star3); + star4=findViewById(R.id.image_star4); + star5=findViewById(R.id.image_star5); - final ConstraintLayout idMain = findViewById(R.id.activity_main); + final ConstraintLayout constraintLayout = findViewById(R.id.activity_main); final GestureDetector gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() { @Override @@ -41,7 +56,7 @@ public boolean onDown(MotionEvent e) { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { - + animatorValue = ValueAnimator.ofFloat(0, 1); float targetSize = (float) hoop.getWidth() / 3 - (float) ball.getWidth() *0.8f; float xHoop = hoop.getX(); float yHoop = hoop.getY(); @@ -50,7 +65,7 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve } }); - idMain.setOnTouchListener(new View.OnTouchListener() { + constraintLayout.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { gestureDetector.onTouchEvent(event); @@ -59,10 +74,25 @@ public boolean onTouch(View v, MotionEvent event) { }); } + @Override + protected void onDestroy() { + super.onDestroy(); + SetStars(0); + } + + @Override + protected void onStop() { + super.onStop(); + if (animatorValue != null) { + animatorValue.cancel(); + hits =0; + SetStars(hits); + } + } + public boolean AnimatorTrack(final float X, final float Y, final float xHoop, final float yHoop, final float targetSize) { - ValueAnimator anyView = ValueAnimator.ofFloat(0, 1); - anyView.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + animatorValue.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float x = ball.getX(); @@ -76,11 +106,13 @@ public void onAnimationUpdate(ValueAnimator valueAnimator) { ball.setTranslationX((float) ((1 - Math.cos(angle)) * X)); ball.setTranslationY((float) (-Math.sin(angle) * Math.abs(Y))); - if ((Math.abs(xHoop - x) <= targetSize) && (Math.abs(yHoop - y) <= targetSize)) { hit = true;} + if ((Math.abs(xHoop - x) <= targetSize) && (Math.abs(yHoop - y) <= targetSize)) { + hit = true; + } } }); - anyView.addListener(new AnimatorListenerAdapter() { + animatorValue.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { @@ -105,20 +137,12 @@ public void onAnimationEnd(Animator animation) { } } }); - anyView.setDuration(1200); - anyView.start(); - + animatorValue.setDuration(1200); + animatorValue.start(); return true; } public void SetStars(int hits) { - Drawable redStar = getResources().getDrawable(R.drawable.ic_grade_red_24dp); - Drawable blackStar = getResources().getDrawable(R.drawable.ic_grade_black_24dp); - ImageView star1=findViewById(R.id.image_Star1); - ImageView star2=findViewById(R.id.image_Star2); - ImageView star3=findViewById(R.id.image_Star3); - ImageView star4=findViewById(R.id.image_Star4); - ImageView star5=findViewById(R.id.image_Star5); switch (hits) { case 1: @@ -135,7 +159,6 @@ public void SetStars(int hits) { break; case 5: star5.setImageDrawable(redStar); - hits = 0; break; default: star1.setImageDrawable(blackStar); @@ -143,9 +166,7 @@ public void SetStars(int hits) { star3.setImageDrawable(blackStar); star4.setImageDrawable(blackStar); star5.setImageDrawable(blackStar); - hits = 0; break; - } - return; + }; } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 3bb3aca..32f5381 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -40,7 +40,7 @@ app:layout_constraintStart_toStartOf="parent" />