Dylan Poon

"Whoever is trying to bring you down is already below you"

By

In-Depth Blog Post #2: The Next Steps

It has been two weeks since the start of the second In-Depth Project! I have been working hard in the background to create some simple “proof of concept” apps to begin to learn to code as well as following tutorials to learn the coding language. Initially, I did say that I wanted to film a lengthy amount of video of myself coding, but the file corrupted, and I only have 5 minutes of un-sped up footage (out of what should have been 3 hours) which unluckily ended up being footage of myself trying to use the screen recording program. So, I will just explain what I did and include the products of what I have worked on.


 

Status Update:


My First App:

The first app I made was a simple image, which needed me to set variables and tell the engine what information to import into the app. It also taught me about coordinates on an app screen, hex codes for colors, and how not to have any errors in the code.

img-20190202-wa0000

Though unimpressive, the app took me around an hour to get working, and two more to perfect. I managed to place a circle, rectangle, a line, a hard to see dot, some text, and an image of “Bob” onto the screen.

(Code at the bottom of this post)


Movement Testing:

After getting that app to work, and meeting with my mentor again, I set out to make movement happen on the screen. However, I was a bit too arrogant when setting out to make it work, and after many hours of confusion, I turned to a resource that my mentor, Randy, had given me. I read through Javascript for Dummies for a couple of hours, and managed to get the program to partially work. When I saw Randy again, we reviewed what I had learned, as well as skimmed through my rough code to refine and remove the errors.

That is the product of a weekend with too much free time!

(Code at the bottom of this post)


How to Have a Beautiful Mind:


How to agree:

In Edward De Bono’s How To Have a Beautiful Mindit is stated that “a discussion should be a genuine attempt to explore a subject”, which applies nicely to the In-Depth Project, as well as the idea of seeking a mentor for the betterment of oneself (pg.5). Applying this directly to my project, I have found that my mentor’s teaching style differed from what I was normally used to. He tended to leave much of the questions I had about what it was like to code up to me to decide, and liked experience based learning, while I wanted to take a more direct path towards my goal. However, I realized that his past experiences and “logic bubble” must have been different than mine, as he began coding when computers first began to pop up in households, while I have been surrounded by technology my whole life. There must have been no answer to the question I asked him when he would have had the same question, and I have realized that answering the question on my own may be beneficial in some way. Taking this into consideration, I have found common ground in both wanting me to progress towards my goal, as well as towards answering my question. This was one example of agreement between Randy and I.

How to disagree:

While looking over and confirming the projects Randy and I would be working on, I pointed out that one of the projects seemed to be redundant, as it was simply an almost identical copy of another project. After discussing why there were two similar projects, my mentor still believed that the project would benefit me more if I did it. However, I found that this may waste an extra mentoring session, which would be very important due to the magnitude of my In-Depth selection. To avoid ruining my relations with my mentor, I “politely and gently rather than rudely and aggressively” presented my opinion, and left the conversation open for a later discussion, when either of our views may have changed on this topic (pg.26).

How to differ:

During my last meeting with Randy, we had a small difference when discussing the most efficient way to code an frames per second counter. I believed that it could be easily done without setting variables, since this was the way that I had done it previously. However, when my mentor stated that it could be, and should be done with variables, we differed, and expressed our opinions. Though both were technically correct, my mentor’s way of creating an fps counter was much more efficient, and utilized the same method as other parts of the code, meaning I could memorize less information. So, this difference was not regarding opinion, but rather regarded the better or more factual way of working more efficiently.


~ This is just the start of another In-Depth, and I will be sure to make the most of it!


 

Code:


 

My First App:

package com.dpoon.graphicsdemo;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.widget.ImageView;

public class MainActivity extends Activity {
    ImageView ourView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        draw();
        setContentView(ourView);
    }
    public void draw(){
        Bitmap blankBitmap;
        blankBitmap = Bitmap.createBitmap(600,600,Bitmap.Config.ARGB_8888);
        Canvas canvas;
        canvas = new Canvas(blankBitmap);

        ourView = new ImageView(this);
        ourView.setImageBitmap(blankBitmap);

        Paint paint;
        paint = new Paint();

        canvas.drawColor(Color.argb(255, 255, 255, 255));
        Bitmap bitmapBob;
        bitmapBob = BitmapFactory.decodeResource(this.getResources(), R.drawable.bob);
        canvas.drawBitmap(bitmapBob, 500, 50, paint);
        paint.setColor(Color.argb(255,  26, 128, 182));
        canvas.drawLine(50,50,250,250,paint);
        canvas.drawText("TALONS is fun!", 50, 50, paint);
        canvas.drawPoint(40,50,paint);
        canvas.drawCircle(350,250,100,paint);
        paint.setColor(Color.argb(255,  249, 129, 0));
        canvas.drawRect(50,450,500,550,paint);
    }
}

Movement Test:

package com.dpoon.movetest;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class MainActivity extends Activity {
    GameView gameView; 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        gameView = new GameView(this);
        setContentView(gameView);
    }

    class GameView extends SurfaceView implements Runnable {
        Thread gameThread = null; 
        SurfaceHolder ourHolder;
        volatile boolean playing;
        Canvas canvas;
        Paint paint;
        long fps;
        private long timeThisFrame;
        Bitmap bitmapBob;
        boolean isMoving = false;
        float walkSpeedPerSecond = 150;
        float bobXPosition = 10;                                      

        // When we initialize (call new()) gameView, this special constructor method runs.
        public GameView(Context context) {                                          
            super(context);                           
            ourHolder = getHolder();                       
            paint = new Paint();
            bitmapBob = BitmapFactory.decodeResource(this.getResources(), R.drawable.bob); 
            playing = true;                                         
        }

        @Override
        public void run() {
            while (playing) {
                long startFrameTime = System.currentTimeMillis(); 
                update();                                                               
                draw();                                                                  

                // Calculate the fps. Use the result to time animations and more.
                timeThisFrame = System.currentTimeMillis() - startFrameTime;

                if (timeThisFrame > 0) { fps = 1000 / timeThisFrame; }
            }
        }
            if(isMoving){ bobXPosition = bobXPosition + (walkSpeedPerSecond / fps); }
        }

        public void draw() {                                          
            if (ourHolder.getSurface().isValid()) {     
                canvas = ourHolder.lockCanvas();                           
                canvas.drawColor(Color.argb(255,  26, 128, 182));            
                paint.setColor(Color.argb(255,  249, 129, 0));    
                paint.setTextSize(45);                         
                canvas.drawText("FPS:" + fps, 20, 40, paint); 
                canvas.drawBitmap(bitmapBob, bobXPosition, 200, paint);  
                ourHolder.unlockCanvasAndPost(canvas);                
            }
        }
        public void pause() {
            playing = false;

            try { gameThread.join(); }
            catch (InterruptedException e) { Log.e("Error:", "joining thread"); }
        }
        public void resume() {
            playing = true;
            gameThread = new Thread(this);
            gameThread.start();
        }
        @Override
        public boolean onTouchEvent(MotionEvent motionEvent) {             
            switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
                case MotionEvent.ACTION_DOWN:                          
                    isMoving = true;            
                    break;
                case MotionEvent.ACTION_UP:                
                    isMoving = false;                           
                    break;
            }
            return true;
        }
    }                                               
    @Override
    protected void onResume() {             
        super.onResume();
        gameView.resume();                                
    }
    @Override
    protected void onPause() {               
        super.onPause();
        gameView.pause();               
    }
}

 

One Response to In-Depth Blog Post #2: The Next Steps

  1. Mulder says:

    Thanks for sharing the details of your first app!.! It gives us a sense of what is involved.
    Mulder

Leave a Reply

Your email address will not be published. Required fields are marked *

css.php