Skip to content

Commit

Permalink
Added animation for zoom hint
Browse files Browse the repository at this point in the history
  • Loading branch information
john0227 committed May 11, 2022
1 parent 4a217c3 commit 6ad9db3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.ImageButton;
Expand Down Expand Up @@ -48,6 +49,7 @@
import com.android.myproj.minesweeper.game.logic.Tile;
import com.android.myproj.minesweeper.game.logic.TileValue;
import com.android.myproj.minesweeper.util.AlertDialogBuilderUtil;
import com.android.myproj.minesweeper.util.AnimationUtil;
import com.android.myproj.minesweeper.util.ConvertUnitUtil;
import com.android.myproj.minesweeper.util.DelayUtil;
import com.android.myproj.minesweeper.util.HistoryUtil;
Expand Down Expand Up @@ -555,25 +557,36 @@ private void showZoomHint() {
LayoutInflater.from(this).inflate(R.layout.zoom_hint, this.rootLayout, true);
ConstraintLayout rootLayoutZoom = findViewById(R.id.rootLayout_zoom_hint);

ImageView zoomIv = findViewById(R.id.iv_zoom_in_out);
zoomIv.setImageResource(R.drawable.avd_zoom_in_out);
AnimatedVectorDrawable avd = (AnimatedVectorDrawable) zoomIv.getDrawable();
// Animate ImageView
ImageView ivZoom = findViewById(R.id.iv_zoom_in_out);
ivZoom.setImageResource(R.drawable.avd_zoom_in_out);
AnimatedVectorDrawable avd = (AnimatedVectorDrawable) ivZoom.getDrawable();
avd.registerAnimationCallback(new Animatable2.AnimationCallback() {
@Override
public void onAnimationEnd(Drawable drawable) {
zoomIv.post(avd::start);
ivZoom.post(avd::start);
}
});
avd.start();

// Remove zoom hint if player touches screen
rootLayoutZoom.setOnClickListener(view -> this.rootLayout.removeView(rootLayoutZoom));
// Or if 10 seconds pass
this.gameHandler.postDelayed(() -> {
// Animate TextView
TextView tvZoom = findViewById(R.id.tv_zoom_in_out);
tvZoom.startAnimation(AnimationUtils.loadAnimation(this, R.anim.anim_zoom_in_out));

Runnable removeZoomHint = () -> {
// If ZoomHint layout is present on screen
if (findViewById(R.id.rootLayout_zoom_hint) != null) {
this.rootLayout.removeView(rootLayoutZoom);
this.gameHandler.postDelayed(() -> {
avd.clearAnimationCallbacks();
tvZoom.clearAnimation();
}, 340);
AnimationUtil.fadeOut(rootLayoutZoom, this.rootLayout, 350);
}
}, 10000);
};
// Remove zoom hint if player touches screen
rootLayoutZoom.setOnClickListener(view -> removeZoomHint.run());
// Or if 10 seconds pass
this.gameHandler.postDelayed(removeZoomHint, 10000);
}

private void resetZoom(boolean enableZoom) {
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/common/anim/anim_zoom_in_out.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/anticipate_overshoot_interpolator">
<scale
android:duration="1550"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.15"
android:toYScale="1.15"
android:repeatCount="infinite"
android:repeatMode="reverse">
</scale>
</set>
7 changes: 4 additions & 3 deletions app/src/main/res/common/layout/zoom_hint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
app:srcCompat="@drawable/avd_zoom_in_out" />

<TextView
android:id="@+id/textView"
android:id="@+id/tv_zoom_in_out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginTop="30dp"
android:gravity="center"
android:text="ZOOM IN AND OUT"
android:textSize="20dp"
android:textSize="25dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="@+id/iv_zoom_in_out"
app:layout_constraintStart_toStartOf="@+id/iv_zoom_in_out"
app:layout_constraintTop_toBottomOf="@+id/iv_zoom_in_out" />
Expand Down

0 comments on commit 6ad9db3

Please sign in to comment.