Unit 2 - Practice Quiz

CSE227 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is the primary purpose of the Canvas class in Android?

Canvas Easy
A. To hold the 'draw' calls for creating 2D graphics.
B. To store application data in a database.
C. To manage user input events like clicks.
D. To handle network requests.

2 Which class is used to specify the color, style, and font for drawing on a Canvas?

Canvas Easy
A. Color
B. Brush
C. Style
D. Paint

3 Which Canvas method would you use to draw a circle?

Canvas Easy
A. drawArc()
B. drawOval()
C. drawPoint()
D. drawCircle()

4 What is the purpose of the onDraw(Canvas canvas) method in a custom View?

Canvas Easy
A. It's used to initialize the view's properties.
B. It handles click events for the view.
C. It's where you place your custom drawing code.
D. It defines the layout size of the view.

5 If you want to draw only the outline of a rectangle, which Paint.Style should you use?

Canvas Easy
A. Paint.Style.FILL
B. Paint.Style.FILL_AND_STROKE
C. Paint.Style.STROKE
D. Paint.Style.OUTLINE

6 Which method is used to draw text on a Canvas?

Canvas Easy
A. drawText()
B. drawLabel()
C. writeText()
D. printString()

7 To draw a straight line between two points on a Canvas, which method is used?

Canvas Easy
A. drawLine()
B. drawVector()
C. drawPath()
D. connectPoints()

8 What are the two main animation systems available in Android?

Animations Easy
A. Canvas Animation and Object Animation
B. Frame Animation and Tween Animation
C. Layout Animation and Drawable Animation
D. Property Animation and View Animation

9 Which type of animation actually modifies the properties of the target object, allowing it to respond to clicks at its new location?

Animations Easy
A. Frame Animation
B. View Animation
C. Property Animation
D. Drawable Animation

10 In which resource directory are XML files for View Animations (tween animations) typically stored?

Animations Easy
A. res/drawable/
B. res/anim/
C. res/layout/
D. res/animator/

11 What is the role of an Interpolator in Android animations?

Animations Easy
A. To define the color of an animation.
B. To define the rate of change of an animation.
C. To set the starting value of an animation.
D. To specify the duration of an animation.

12 Which class is the simplest way to animate a View's property, such as alpha or rotation, by name?

Animations Easy
A. AnimatorSet
B. ValueAnimator
C. ViewPropertyAnimator
D. ObjectAnimator

13 What is the primary function of the ValueAnimator class?

Animations Easy
A. It directly animates a specific property of a View.
B. It calculates animated values over time but does not act on any object.
C. It groups multiple animations to play together.
D. It defines the layout changes for animations.

14 What does the <alpha> XML tag represent in a View Animation file?

Animations Easy
A. A rotation animation.
B. A fade-in or fade-out animation.
C. A movement animation.
D. A scaling animation.

15 What is the main purpose of the Android Transition framework?

Transitions Easy
A. To manage background threads for long-running tasks.
B. To animate UI changes within the layout of a single activity.
C. To draw custom 2D graphics on a Canvas.
D. To handle navigation between different activities.

16 In the Transition framework, what does a Scene represent?

Transitions Easy
A. A user interaction event like a button click.
B. A snapshot of a view hierarchy in a particular state.
C. A full-screen component, similar to an Activity.
D. A single animation effect like a fade or slide.

17 Which predefined Transition is specifically designed to animate the appearance and disappearance of views?

Transitions Easy
A. ChangeImageTransform
B. ChangeBounds
C. Move
D. Fade

18 Which method is called to begin the animation from the current layout to a new Scene?

Transitions Easy
A. Animator.start(scene)
B. View.transitionTo(scene)
C. Scene.enter()
D. TransitionManager.go(scene)

19 What is a "Shared Element Transition" primarily used for?

Transitions Easy
A. Animating a view as it moves between two different activities or fragments.
B. Sharing an animation definition between multiple applications.
C. A transition that is defined in a shared XML file for reusability.
D. A transition that affects all views on the screen simultaneously.

20 Which transition class automatically animates changes to a view's position and size?

Transitions Easy
A. Fade
B. Slide
C. Explode
D. ChangeBounds

21 In a custom View, you want to draw a circle, rotate the coordinate system by 45 degrees, and then draw a square centered at the same point as the circle. What will be the final visual outcome?

Canvas Medium
A. A non-rotated square drawn on top of a rotated circle.
B. The behavior is undefined and depends on the Android version.
C. A rotated square drawn on top of a non-rotated circle.
D. A rotated square and a rotated circle.

22 You are implementing a custom drawing View. To apply a complex transformation (e.g., a rotation followed by a translation) and then revert to the original state for subsequent drawing operations, which pair of Canvas methods is most efficient?

Canvas Medium
A. Manually applying the inverse transformations in reverse order.
B. canvas.getMatrix() and canvas.setMatrix()
C. Creating a new Canvas object for the transformed drawing.
D. canvas.save() and canvas.restore()

23 What is the primary difference between a ValueAnimator and an ObjectAnimator?

Animations Medium
A. ObjectAnimator can be used in an AnimatorSet, but ValueAnimator cannot.
B. ValueAnimator is part of the older View Animation system, while ObjectAnimator is part of the Property Animation system.
C. ObjectAnimator directly modifies a target object's property, while ValueAnimator only calculates animated values and requires a listener to apply them.
D. ValueAnimator can only animate integer values, while ObjectAnimator can animate any property.

24 To create a shared element transition between two Activities, ActivityA and ActivityB, which XML attribute is essential for linking the shared views?

Transitions Medium
A. android:id
B. android:sharedElementName
C. android:tag
D. android:transitionName

25 Consider the following code in onDraw(Canvas canvas):
java
paint.setColor(Color.BLUE);
canvas.translate(100, 100);
canvas.drawRect(0, 0, 50, 50, paint);

paint.setColor(Color.RED);
canvas.scale(2, 2, 0, 0); // Scale around the current origin's (0,0) point
canvas.drawRect(0, 0, 25, 25, paint);

What is the final appearance on the screen?

Canvas Medium
A. A blue 50x50 square at (100, 100) and a red 50x50 square at (200, 200).
B. A red 25x25 square inside a blue 50x50 square at position (100, 100).
C. A blue 50x50 square at (100, 100) and a red 25x25 square at (200, 200).
D. A red 50x50 square drawn exactly on top of a blue 50x50 square at position (100, 100).

26 You want to animate a custom view's property named cornerRadius using ObjectAnimator. The custom view class does not have a setCornerRadius(float radius) method. What will happen when you try to run the animation?

Animations Medium
A. The app will crash with a NoSuchMethodException.
B. The animation will run, but have no visual effect.
C. ObjectAnimator will automatically create the setter method using reflection.
D. A lint warning will be generated, but the app will run without crashing.

27 What is the primary purpose of the TransitionManager.beginDelayedTransition(ViewGroup root) method?

Transitions Medium
A. To define a transition that will run when the Activity is created.
B. To reverse a previously run transition.
C. To capture the state of views in a ViewGroup before and after the next layout pass, and automatically animate the changes.
D. To start a transition after a specified delay, defined in milliseconds.

28 You use a LinearInterpolator for an animation. How does this affect the animation's rate of change over time?

Animations Medium
A. The animation starts fast and then slows down.
B. The animation starts slow and then speeds up.
C. The animation moves at a constant speed.
D. The animation starts slow, accelerates, and then decelerates.

29 What is the main performance-related reason to avoid object allocations inside the onDraw() method of a custom View?

Canvas Medium
A. Object allocations in onDraw() can cause memory leaks.
B. Allocating objects in onDraw() consumes excessive battery power.
C. Paint and Path objects cannot be instantiated inside onDraw().
D. onDraw() is called frequently, and repeated allocations can trigger the Garbage Collector, causing stuttering or 'jank'.

30 When creating a custom Transition, which two methods are the most critical to override to define the transition's behavior?

Transitions Medium
A. captureStartValues(TransitionValues) and captureEndValues(TransitionValues)
B. start() and end()
C. onAppear() and onDisappear()
D. setDuration() and setInterpolator()

31 How does a Property Animation (e.g., ObjectAnimator) differ from a View Animation in terms of its effect on the animated View?

Animations Medium
A. View Animations can animate any object, whereas Property Animations are limited to View subclasses.
B. View Animations are more performant as they run on a separate thread.
C. Property Animations modify the actual properties of the View object, while View Animations only change how the View is drawn on the screen.
D. Property Animations can only be defined in XML, while View Animations can only be defined in code.

32 You need to draw a shape that is the intersection of a circle and a rectangle. Which Canvas method would be most suitable for this task?

Canvas Medium
A. Using a PorterDuff.Mode.SRC_IN Xfermode on a Paint object.
B. canvas.drawPath() with two separate paths.
C. canvas.drawVertices() with a custom vertex buffer.
D. canvas.clipPath(circlePath) followed by canvas.drawRect(...).

33 You want to run three animations simultaneously: fade in a TextView, scale up an ImageView, and move a Button. Which component is best suited for coordinating these animations?

Animations Medium
A. AnimationSet from the View Animation framework.
B. A custom Thread that updates view properties manually.
C. ValueAnimator with multiple update listeners.
D. AnimatorSet with playTogether().

34 In the Material Design transition framework, what is the purpose of the Explode transition?

Transitions Medium
A. It moves views along a curved path defined by an XML Path.
B. It animates non-shared views by moving them from or to the center of the scene.
C. It animates the shared elements to grow from the center outwards.
D. It causes the Activity to fade out with a crackling effect.

35 To draw a quadratic Bézier curve on a Canvas, your Path object needs a starting point, an end point, and one other point. What is the role of this third point?

Canvas Medium
A. A pivot point for rotating the curve.
B. A secondary end point for creating a closed shape.
C. A control point that pulls the curve towards it.
D. The center point of the curve's arc.

36 You want to animate a background color change from red to blue smoothly. Which class would you typically use with a ValueAnimator or ObjectAnimator to ensure correct color interpolation?

Animations Medium
A. GradientEvaluator
B. ColorInterpolator
C. RgbInterpolator
D. ArgbEvaluator

37 You are using TransitionManager.beginDelayedTransition() to animate a layout change, but you want one specific ImageView to remain static. How can you achieve this?

Transitions Medium
A. Set the ImageView's visibility to GONE before the transition starts.
B. Set the ImageView's android:animateLayoutChanges attribute to false.
C. There is no way to exclude a single view; the entire ViewGroup is always animated.
D. Use the transition.removeTarget(imageView) method.

38 What is the purpose of a Keyframe in a property animation?

Animations Medium
A. To define the animation's duration and repeat count in a single object.
B. To define the start and end values of an animation.
C. To define a specific value for a property at a specific point in the animation's timeline.
D. To mark a point in the animation where a listener callback should be triggered.

39 You are implementing a Fragment transaction and want the exiting fragment to slide to the left and the entering fragment to slide in from the right. Which method would you use on the FragmentTransaction to achieve this?

Transitions Medium
A. setCustomAnimations()
B. setTransitionStyle()
C. setSharedElementEnterTransition()
D. addSharedElement()

40 You are drawing text on a Canvas and want it to be perfectly centered horizontally at a specific x-coordinate. Which Paint setting is crucial for this?

Canvas Medium
A. paint.setLetterSpacing(0.1f)
B. paint.setTextAlign(Paint.Align.CENTER)
C. paint.setStyle(Paint.Style.FILL_AND_STROKE)
D. paint.setTextSize(50f)

41 You are implementing a custom View where you need to draw a shape and then apply a PorterDuff.Mode.XOR blend mode to a semi-transparent overlay. To ensure the blend mode only affects the specific shape and not the entire View background, which Canvas operation is most appropriate and why?

Canvas Hard
A. Creating a separate Bitmap and Canvas, drawing there, and then using canvas.drawBitmap(): This works but is less efficient than saveLayer for in-place, isolated compositing.
B. canvas.save() followed by canvas.clipRect(bounds): Clipping restricts the drawing area but does not isolate the blending operation from the existing canvas content.
C. canvas.saveLayer(bounds, paint): It creates an off-screen buffer, allowing blend modes to operate in isolation on subsequent drawing commands before being composited back.
D. canvas.save() followed by setting an Xfermode on the Paint: This will apply the blend mode to everything drawn with that paint, potentially affecting the View's background if not clipped correctly.

42 Consider the following Matrix operations applied sequentially: matrix.setScale(2, 2); matrix.postTranslate(50, 0); matrix.preRotate(90);. If this matrix is applied to a point at (10, 20), what will be the final transformed coordinates? Remember the transformation formula is .

Canvas Hard
A. (-20, 70)
B. (80, 70)
C. (-40, 120)
D. (-40, 70)

43 You are creating a custom Interpolator to model a bounce effect. The desired behavior is that the animation overshoots to 1.2, then settles back to 1.0. Which getInterpolation(float input) implementation would best produce this effect near the end of the animation?

Animations Hard
A. A function using a bounce factor: float t = input; t *= t; return t * t * ((2.75f * t) - 1.75f); which is a standard ease-in interpolator.
B. Using new OvershootInterpolator(2.0f) which provides a simple overshoot but without the 'bounce back' behavior.
C. A function that uses a modified sine wave applied towards the end: return (float)(-1 * Math.pow(Math.E, -input / 0.3) * Math.cos(10 * input) + 1); which models a dampened harmonic oscillator.
D. A sinusoidal function like (float)(-0.5 * Math.cos(input * Math.PI) + 0.5) which only produces values between 0 and 1.

44 You are implementing a custom Transition to animate a TextView's color from a start color to an end color. In which lifecycle methods of the Transition class must you capture the color values, and which method is responsible for creating the Animator?

Transitions Hard
A. Capture both start and end colors in createAnimator(). The Animator is also created there.
B. Capture start color in createAnimator(), end color in onTransitionEnd(). Create the Animator in captureStartValues().
C. Capture start color in captureStartValues(), end color in onTransitionPause(). Create the Animator in captureEndValues().
D. Capture the start color in captureStartValues(), capture the end color in captureEndValues(). Create the Animator (e.g., a ValueAnimator) in createAnimator().

45 An AnimatorSet is configured as follows: Animator a, b, c, d; ... AnimatorSet set = new AnimatorSet(); set.play(a).with(b); set.play(c).after(a); set.play(d).after(b); What is the execution order of these animators?

Animations Hard
A. a and b run together, then c and d run together.
B. a and b run together. When a finishes, c starts. When b finishes, d starts. c and d may not start at the same time.
C. a, b, c, and d all run sequentially.
D. a and b run together, then c runs, then d runs.

46 When drawing a complex Path with many curves and lines on a hardware-accelerated Canvas, which of the following operations is most likely to cause a significant performance drop or force a fallback to software rendering?

Canvas Hard
A. Using Path.op(path1, path2, Path.Op.DIFFERENCE) to create a complex shape from two other paths before drawing.
B. Drawing the path with anti-aliasing enabled on the Paint object.
C. Applying a simple Matrix to the Canvas before drawing the path.
D. Drawing the path with a Paint object that has a ColorFilter applied.

47 In a shared element transition between a RecyclerView (Fragment A) and a detail view (Fragment B), you notice flickering or incorrect positioning. The item in the RecyclerView is temporarily replaced with the detail view before the transition ends. What is a likely cause and solution?

Transitions Hard
A. The postponeEnterTransition() was not called in Fragment B's onViewCreated. The solution is to call it and then call startPostponedEnterTransition() once the shared element is measured and laid out.
B. The ImageView's scaleType is different in the two fragments, causing a measurement mismatch. The solution is to use android:scaleType="centerCrop" on both.
C. The transition name is not unique for each item. The solution is to assign a unique transitionName to each view holder's view.
D. The Window content transitions are disabled. The solution is to enable them in the theme with <item name="android:windowActivityTransitions">true</item>.

48 You need to animate a custom object property, Circle.centerPoint, which is a PointF. The property does not have a public setter setCenterPoint(PointF). Which combination of animator and helper class is the most efficient and avoids reflection?

Animations Hard
A. Creating a wrapper class for Circle that has a setCenterPoint method and using ObjectAnimator on the wrapper.
B. ValueAnimator.ofObject(new PointFEvaluator(), startPoint, endPoint) and manually updating the property in an AnimatorUpdateListener.
C. Using a Property object: ObjectAnimator.ofObject(myCircle, new Property<Circle, PointF>(PointF.class, "centerPoint") { ... }, new PointFEvaluator(), newPoint).
D. ObjectAnimator.ofObject(myCircle, "centerPoint", new PointFEvaluator(), newPoint).

49 In a MotionLayout scene, you want a view to move along a circular arc path instead of a straight line between the start and end ConstraintSets. Which KeyFrameSet attribute is best suited for this?

MotionLayout Hard
A. A KeyCycle with waveShape="sin" to create an oscillation.
B. A KeyAttribute to change the view's rotation at the midpoint.
C. A KeyPosition with keyPositionType="pathRelative" and percentY="-0.5" at frame position 50.
D. A KeyPosition with keyPositionType="parentRelative" and percentY="-0.5" at 50% of the animation.

50 You use canvas.clipPath(myPath) to create a non-rectangular clipping region. Afterwards, you apply a rotation to the canvas with canvas.rotate(45). What is the result of subsequent drawing operations?

Canvas Hard
A. The clipPath operation is ignored because it was followed by a transformation.
B. This will throw an IllegalStateException as transformations are not allowed after clipping to a complex path.
C. The drawing is clipped by the original, un-rotated path.
D. The drawing is clipped by the path, and the clipping region itself is also rotated by 45 degrees.

51 You are using a SpringAnimation to create a physics-based movement. You want the animation to be very bouncy and overshoot its final position significantly, oscillating multiple times before settling. Which combination of stiffness and dampingRatio should you use?

Animations Hard
A. stiffness = SpringForce.STIFFNESS_LOW, dampingRatio = SpringForce.DAMPING_RATIO_NO_BOUNCY
B. stiffness = SpringForce.STIFFNESS_HIGH, dampingRatio = SpringForce.DAMPING_RATIO_HIGH_BOUNCY
C. stiffness = SpringForce.STIFFNESS_VERY_LOW, dampingRatio = SpringForce.DAMPING_RATIO_MEDIUM_BOUNCY
D. stiffness = SpringForce.STIFFNESS_MEDIUM, dampingRatio = SpringForce.DAMPING_RATIO_LOW_BOUNCY

52 What is the primary purpose of the TransitionValues object in the Android Transition Framework, and what is a common mistake when using its values Map?

Transitions Hard
A. It stores properties of a view at a specific moment (start or end); a common mistake is using a generic String key like "color" which can cause collisions with other transitions.
B. It is a direct reference to the View itself; a mistake is holding onto this reference, causing memory leaks.
C. It stores the Animator for a view; a mistake is trying to store non-serializable objects.
D. It stores the duration and interpolator for a transition; a mistake is setting a negative duration.

53 You're creating a ComposeShader to combine a BitmapShader (a texture) and a LinearGradient shader. If you use new ComposeShader(bitmapShader, linearGradient, PorterDuff.Mode.MULTIPLY), what will the visual outcome be?

Canvas Hard
A. Only the LinearGradient will be visible, as the second shader in the constructor takes precedence.
B. The final pixel color will be the result of multiplying the color components of the texture pixel and the corresponding gradient pixel.
C. The gradient will act as a mask, revealing the texture only where the gradient is not transparent.
D. The texture will be drawn, and then the gradient will be drawn on top of it with 50% opacity.

54 When using ObjectAnimator to animate a custom view property, you notice jank and skipped frames. The animation is simple, animating a single float property. Profiling shows significant time spent in Method.invoke(). What is the most effective way to optimize this animation without rewriting it to use ValueAnimator?

Animations Hard
A. Running the animation on a background thread using HandlerThread.
B. Using a ViewPropertyAnimator instead, via myView.animate()....
C. Lowering the animation duration to make the jank less noticeable.
D. Creating a static Property object for the animated property and passing it to ObjectAnimator.ofFloat() instead of the property name string.

55 You are using TransitionManager.beginDelayedTransition with a ChangeBounds transition to animate a View's change in layout parameters. However, you want the View's children to move with their parent but not resize during the transition. How can you achieve this?

Transitions Hard
A. Use a TransitionSet that excludes all children from the ChangeBounds transition using excludeTarget().
B. Set a TransitionListener and manually reset the children's scale to 1.0 on each frame.
C. Set setResizeClip(true) on the ChangeBounds instance.
D. This is the default behavior of ChangeBounds and requires no special configuration.

56 In your onDraw, you have a loop that draws 1,000 small, overlapping, semi-transparent circles. The performance is poor. Which change would likely provide the biggest performance improvement when hardware acceleration is enabled?

Canvas Hard
A. Disabling anti-aliasing on the Paint object.
B. Drawing all the circles to an off-screen Bitmap with Canvas.saveLayer() and a new Paint, then drawing that bitmap once.
C. Combining all circle paths into a single Path using Path.addCircle() and drawing the combined path once.
D. Pre-allocating the Paint object outside the loop.

57 You need to create a PathInterpolator that makes an animation start fast, slow down dramatically in the middle, and then speed up again at the end. How would you define the control points (x1, y1) and (x2, y2) for its underlying cubic Bezier curve?

Animations Hard
A. (0.25, 0.1) and (0.25, 1.0). This is a standard ease-in-out curve.
B. (0.8, 0.0) and (0.2, 1.0). The curve moves 'backwards' in time along the x-axis, creating an S-shape.
C. (0.5, 0.0) and (0.5, 1.0). This creates a linear interpolation.
D. (0.0, 0.8) and (1.0, 0.2). The curve is very steep at the start and end, and very flat in the middle.

58 You are using MotionLayout and want to trigger an animation based on a custom event, not just user swipes or layout changes. For example, you want to transition to the 'end' state when a network request completes. How would you programmatically trigger this transition?

Transitions Hard
A. Create a new Transition object in code and apply it using TransitionManager.go().
B. Call motionLayout.transitionToState(R.id.end).
C. Use a StateListAnimator defined in XML to link the network event to a state change.
D. Call motionLayout.setTransition(R.id.start, R.id.end) followed by motionLayout.setProgress(1.0f).

59 You are drawing text on a Canvas. You need to ensure the exact vertical center of the text (from the top of the ascender to the bottom of the descender) is aligned with a specific y-coordinate, cy. Given a Paint object, how do you calculate the correct y value for the canvas.drawText call?

Canvas Hard
A. float y = cy;
B. Rect bounds = new Rect(); paint.getTextBounds("MyText", 0, 6, bounds); float y = cy - bounds.exactCenterY();
C. float y = cy - (paint.descent() + paint.ascent()) / 2;
D. float y = cy - paint.getTextSize() / 2;

60 You create a ValueAnimator that animates from 0 to 1 over 10 seconds. You set its repeat mode to REVERSE and repeat count to INFINITE. After 25 seconds, you call animator.getAnimatedValue(). Assuming a linear interpolator, what will the returned value be?

Animations Hard
A. 1.0
B. 0.5
C. 0.0
D. 0.25