Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a custom UIview that initially generates the figure on the right: Four re

ID: 3832297 • Letter: C

Question

Create a custom UIview that initially generates the figure on the right: Four rectangles on the 4 corners of the screen. The length /width of the rectangles are one third of the bounds height/width. 1- When you tap the screen, the view will be redrawn as if the tap location is the new center. When you pan and drag you finger inside any of the 4 rectangles, that rectangle will grow or shrink based on the finger movement (towards inside or outside). The maximum is to hit the borders of other rectangles. When you pinch the screen, the view will change its scale such that the 4 rectangles will grow or shrink based whether you pinch in or out. Again, the maximum is the length/width reaches half the bounds height/width.

Explanation / Answer

package com.ebookfrenzy.pinchexample; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; import android.view.ScaleGestureDetector; import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener; import android.widget.TextView; public class PinchExampleActivity extends ActionBarActivity { TextView scaleText; ScaleGestureDetector scaleGestureDetector; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pinch_example); scaleText = (TextView)findViewById(R.id.myTextView); scaleGestureDetector = new ScaleGestureDetector(this, new MyOnScaleGestureListener()); } @Override public boolean onTouchEvent(MotionEvent event) { scaleGestureDetector.onTouchEvent(event); return true; } public class MyOnScaleGestureListener extends SimpleOnScaleGestureListener { @Override public boolean onScale(ScaleGestureDetector detector) { float scaleFactor = detector.getScaleFactor(); if (scaleFactor > 1) { scaleText.setText("Zooming Out"); } else { scaleText.setText("Zooming In"); } return true; } @Override public boolean onScaleBegin(ScaleGestureDetector detector) { return true; } @Override public void onScaleEnd(ScaleGestureDetector detector) { } } . . .

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote