public void dropIn(View view) { if (gameIsActive) { ImageView counter = (ImageView) view; String tag = (String) counter.getTag(); int num = Integer.parseInt(tag); if (spots[num] == 2) { counter.setTranslationY(-1000f); if (player == 0) { counter.setImageResource(R.drawable.yellow); spots[num] = 0; checkIfWon(); player = 1; } else if (player == 1) { counter.setImageResource(R.drawable.red); spots[num] = 1; checkIfWon(); player = 0; } counter.animate().translationYBy(1000f).rotation(360).setDuration(1000); } else Toast.makeText(this, "Please Choose A Spot That Hasn't Been Taken", Toast.LENGTH_SHORT) .show(); } }
public void expandFab() { mFabType = FAB_EXPAND; mAnimatingFab = true; // Center point on the screen of the FAB. int x = (int) (centerX(mFab)); int y = (int) (centerY(mFab)); // Start and end radius of the sheet expand animation. float startRadius = getFabSizePx() / 2; float endRadius = calculateStartRadius(x, y); mFabExpandLayout.setAlpha(0f); mFabExpandLayout.setVisibility(View.VISIBLE); mFab.setVisibility(View.INVISIBLE); mFab.setTranslationX(0f); mFab.setTranslationY(0f); mFab.setAlpha(1f); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { expandPreLollipop(x, y, startRadius, endRadius); } else { expandLollipop(x, y, startRadius, endRadius); } }
@Override public void onClick(View v) { if (startButton.getVisibility() == View.VISIBLE) { startButton.setVisibility(View.INVISIBLE); } if (upAnimation.isStarted()) { upAnimation.cancel(); } if (startPosition == 0) { startPosition = bird.getTop(); } isUpAnimationCancelled = false; isDownEndByClick = true; // bird.layout(bird.getLeft(), 228, bird.getRight(), 228 + bird.getMeasuredHeight()); bird.layout( bird.getLeft(), (int) bird.getY(), bird.getRight(), (int) bird.getY() + bird.getMeasuredHeight()); bird.setTranslationY(0); upAnimation.start(); }
@Override public boolean onTouch(View view, MotionEvent motionEvent) { float new_x = motionEvent.getRawX(); float new_y = motionEvent.getRawY(); float delta_y = Math.abs(start_y - new_y); float delta_x = Math.abs(start_x - new_x); switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: image_view.setTranslationY(0.f); start_x = motionEvent.getRawX(); start_y = motionEvent.getRawY(); target_reached = false; return true; case MotionEvent.ACTION_MOVE: if (delta_y > MAX_SLIDE) { if (!target_reached) { target_reached = true; image_view .animate() .setStartDelay(0) .setInterpolator(new OvershootInterpolator(4.f)) .translationY(TARGET * ((start_y < new_y) ? 1 : -1)) .scaleX(1.f) .scaleY(1.f); } } else { target_reached = false; float movement = (float) ((-Math.exp(-delta_y / MAX_SLIDE) + 1.f) * MAX_SLIDE); movement *= (start_y < new_y) ? 1 : -1; image_view.setTranslationY(movement); image_view.setScaleY(1 + delta_y / 900.f); image_view.setScaleX(1 - delta_y / 2000.f); } return true; case MotionEvent.ACTION_UP: image_view .animate() .setInterpolator(new OvershootInterpolator(4.f)) .translationY(0) .scaleX(1.f) .scaleY(1.f); return true; } return false; }
public void dropIn(View view) { ImageView counter = (ImageView) view; // need to move it off the screen.Apply red or yellow. int tappedCounter = Integer.parseInt(counter.getTag().toString()); // if it hasn't been tapped if (gameState[tappedCounter] == 2) { counter.setTranslationY(-1000f); // set the image. if (activePlayer == 0) { counter.setImageResource(R.drawable.yellow); activePlayer = 1; gameState[tappedCounter] = activePlayer; } else { counter.setImageResource(R.drawable.red); activePlayer = 0; } // Move it back to position counter.animate().translationYBy(1000f).rotation(180).setDuration(300); for (int[] winningPosition : this.winningPositions) { // check if winning positions in game state. if (gameState[winningPosition[0]] == gameState[winningPosition[1]] && gameState[winningPosition[1]] == gameState[winningPosition[2]] && gameState[winningPosition[0]] != 2) { String winner = "Red"; if (gameState[winningPosition[0]] == 0) { winner = "Yellow"; } // Someon has one TextView winnerMessage = (TextView) findViewById(R.id.winnerText); winnerMessage.setText("Player " + activePlayer + " has won"); LinearLayout layout = (LinearLayout) findViewById(R.id.winnerlayout); layout.setVisibility(view.VISIBLE); } } } }
@Override public void onAnimationEnd(Animator animation) { // TODO Auto-generated method stub Log.v( "Debug", "Animation End: " + bird.getY() + ".." + bird.getTop() + ".." + bird.getTranslationY()); if (!isUpAnimationCancelled) { // start to drop // downAnimation.setFloatValues(deltaY); bird.layout( bird.getLeft(), (int) bird.getY(), bird.getRight(), (int) bird.getY() + bird.getMeasuredHeight()); bird.setTranslationY(0); downAnimation.setFloatValues(startPosition - bird.getTop()); downAnimation.start(); } }