private void setBubbleAndHandlePosition(float y) { int bubbleHeight = bubble.getHeight(); int handleHeight = handle.getHeight(); handle.setY(getValueInRange(0, height - handleHeight, (int) (y - handleHeight / 2))); bubble.setY( getValueInRange(0, height - bubbleHeight - handleHeight / 2, (int) (y - bubbleHeight))); }
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); View gridLayout = findViewById(R.id.book_folder_gridLayout); downloadingView.setX(gridLayout.getX() + gridLayout.getWidth() / 3); downloadingView.setY(gridLayout.getY() + gridLayout.getHeight() - 20); textView.setText(childViews.size() + ""); textView.setX(gridLayout.getWidth() - textView.getWidth()); textView.setY(gridLayout.getHeight() - 33); }
@Override public boolean onTouch(View v, MotionEvent event) { ImageView victim1 = (ImageView) findViewById(R.id.imgVictim1); if (event.getAction() == MotionEvent.ACTION_DOWN) { victim1.setAlpha(0f); Random rand = new Random(); TextView msg = new TextView(HomeActivity.this); msg.setText(R.string.txt_lifted); msg.setTextSize(25); msg.setTypeface(Typeface.DEFAULT_BOLD); msg.setX(rand.nextInt(layout.getWidth() - (layout.getWidth() / 100 * 20))); msg.setY(rand.nextInt(layout.getHeight() - (layout.getHeight() / 100 * 10))); msg.setRotation(rand.nextInt(90) - 45); textViewList.add(msg); layout.addView(msg); if (textViewList.size() > 10) { layout.removeView(textViewList.get(0)); textViewList.remove(textViewList.get(0)); } int idNextPlayed = soundIdList.get(rand.nextInt(soundIdList.size() - 1)); while (idLastPlayed == idNextPlayed) { idNextPlayed = soundIdList.get(rand.nextInt(soundIdList.size() - 1)); } soundPool.play(idNextPlayed, 1, 1, 1, 0, 1); idLastPlayed = idNextPlayed; } if (event.getAction() == MotionEvent.ACTION_UP) { victim1.setAlpha(1f); } return true; }