QuestionQuestion

The purpose of this lab assignment is to:
• Develop Android Apps that contain Graphics and Animations
• Practice the use of frame-by-frame animations
• Practice the use of tweened animations

Exercise 1
Write an Android application that allows the user to draw horizontal or vertical lines, starting from a given position, using up, down, left, and right keys of Android keypad. Use a Canvas object to implement the drawings. Use different tweening transformations for implementing your solution.

Allow the user to choose colors and the thickness of lines. Allow the user to clear the drawings and restart.
Here is a simple activity that handles key events:
public class KeyEventTestActivity extends Activity {
    @Override   /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
    }

       public boolean onKeyDown(int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
                            textUpdate( keyCode);
                            return true;
                   }
                        return false;
                }

       public void textUpdate(int keyCode) {
                TextView text = (TextView)findViewById(R.id.testText);
                text.setText("You pressed the key: " +keyCode);
       }
}

The following is the main.xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
       android:orientation="vertical"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent">

    <TextView android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:id="@+id/testText"
                  android:text="BEFORE PRESSING A KEY!"
                  android:textColor="#FFDDAA"
                  android:textSize="19px"/>

</LinearLayout>

Exercise 2
In this exercise you will develop a frame-by-frame animation. Create a series of pictures that differ slightly from each other. Your animation should be original, relate to things that you like or express an idea of yours. Allow the user to start and stop the animation.

Exercise 3
In this exercise you will create a tweened animation similar to TweenActivity. Create an application named TorontoView. Display a png picture of CN Tower and the Canadian flag on top of the tower. Apply the necessary transformations (rotate, scale, translate) to make the flag revolve nicely around the tower. Define tweening transformations as XML resource files.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import android.graphics.PorterDuff;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    Canvas canvas;

    ImageView view;
    Paint paint;

    int x,y;
    int endx, endy;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);
       view = (ImageView) findViewById(R.id.img_view);
       Display currentDisplay = getWindowManager().getDefaultDisplay();
       float w = currentDisplay.getWidth();
       float h = currentDisplay.getHeight();
       Bitmap bitmap = Bitmap.createBitmap((int) w, (int) h,
                Bitmap.Config.ARGB_8888);
       canvas = new Canvas(bitmap);
       paint = new Paint();
       paint.setColor(Color.MAGENTA);
       paint.setStrokeWidth(20);
       view.setImageBitmap(bitmap);
       endx = (int) ( 2 * w / 3) ;
       x = (int) w / 3 ;
       endy = y = (int) h / 2;
       canvas.drawLine(x, y, endx, endy, paint);
    }

    public void clickButton(View v){
       switch (v.getId()){
            case R.id.left:
                endx -= 10;
                x -= 10;
                canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
                canvas.drawLine(x, y, endx, endy, paint);
                view.invalidate();
                break;
            case R.id.down:
                endy += 10;
                y += 10;
                canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
                canvas.drawLine(x, y, endx, endy, paint);
                view.invalidate();
                break;
            case R.id.up:
                endy -= 10;
                y -= 10;
                canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
                canvas.drawLine(x, y, endx, endy, paint);
                view.invalidate();
                break;
            case R.id.right:
                endx += 10;
                x += 10;
                canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
                canvas.drawLine(x, y, endx, endy, paint);
                view.invalidate();
                break;
            case R.id.blue:
                paint.setColor(Color.BLUE);
                canvas.drawLine(x, y, endx, endy, paint);
                view.invalidate();
                break;...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$105.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats