Amazon Gift Cards

Saturday, December 25, 2010

Merry Christmas, Happy New Year, Android 2010, Android 2011

First of all Merry Christmas, and i'll be going into hibernation mode until the new year comes so Happy New Year as well :)

Android in 2010
* Our little green friend has been on its way to world domination, we just launch a new one into the outer space (Which later would be known as the origin of the terminators)
* Android is found in multiple devices, from Phones, to Tablets (Galaxy Tab having 10M sold), to Google TV (my sister in US got me one :-] ), and a lot more
* Froyo & Gingerbread released, Market got its much awaited update, rooting/custom roms/xda are still strong and awesome
* People still call upon fragmentation on Android, yes it is but i would say its just fragmented between low end device and high end device which is better then the linux/unix fragmentation, and unless you're a game programmer the chances you would get this hardcore fragmentation is really less.

Our Site
* This year has been a slow year for TutorialForAndroid.com and i hope i could make more tutorials next year
* Last year i shown i was doing something that could build android app easier, I announced it way too early and then Google created App Creator (I suggest everyone to give it a try), and i stopped the development and move on with something else like ShootAndLearn app

Android 2011
* Android would penetrate more market with Google TV having its app features, Tablets popping out left and right, PSP2 capturing the gaming community
* Android would not slow down its development, release often is better to push technology forward and Android is still young and evolving


* Quick Prediction on the future of Android (2011 and beyond)
* Finally i'll work for Google (ahahha) or be an Android programmer (I love WebProgramming too especially frontend technology like Javascript,Actionscript and CSS, yes Android is also frontend)
* PS4 would be announced as Google TV with PS and PSN
* Android would benefit from Chrome OS and vice versa (More apps would be web centric via webview)
* Java would not be the only language you can code Android with (currently you could do it) but future would be better (Javascript, Python or Ruby please)
* Android ndk would/should be married to Google Native Client (used in Chrome)
* O3D, WebGL, more HTML5 features to include in future version of Android
* Android would have WAC/Bondi features where you could call native functions from any website given you would grant them permission, Chrome OS might be the first to try this

As you can see most of my prediction expect PS4 is actually Android meeting Chrome OS, like what Eric Schmidt stated Android would eventually marry Chrome OS (Android 5.0?), this might not happen in 1 year time but most of the technologies between them are just overlapping each other and it make sense for them to meet later on (currently its still not ideal for it to happen).

To conclude our green friend has and would remain strong and I here would try to help more friends to get into the green robot army :) Merry Christmas and Happy New year to all of you

Tuesday, December 14, 2010

Previewing while Drawing with Canvas in Android

After my site being gone from the web yesterday, its back :) it happens to be a blogger bug. Anyway i got a lot of request on how to preview your drawing, and continue our Drawing with Canvas series, here is how to preview while drawing.

Notes
• The files are uploaded in http://goo.gl/ecHpE
• The project was build in IntelliJ and it should be easy to import to Eclipse

What Do I Need
DrawingSurface
public class DrawingSurface extends SurfaceView implements SurfaceHolder.Callback {
  public boolean isDrawing = true;
  public DrawingPath previewPath;

  private Handler previewDoneHandler = new Handler(){
    @Override
    public void handleMessage(Message msg) {
      isDrawing = false;
    }
  };

  class DrawThread extends Thread{
    @Override
    public void run() {
      commandManager.executeAll(c,previewDoneHandler);
      previewPath.draw(c);
    }
  };
}



Drawing Activity
public class DrawingActivity extends Activity implements View.OnTouchListener{
  public void onCreate(Bundle savedInstanceState) {
    drawingSurface.previewPath = new DrawingPath();
    drawingSurface.previewPath.path = new Path();
    drawingSurface.previewPath.paint = getPreviewPaint();
    ...
  }
  private Paint getPreviewPaint(){
    final Paint previewPaint = new Paint();
    previewPaint.setColor(0xFFC1C1C1);
    previewPaint.setStyle(Paint.Style.STROKE);
    previewPaint.setStrokeJoin(Paint.Join.ROUND);
    previewPaint.setStrokeCap(Paint.Cap.ROUND);
    previewPaint.setStrokeWidth(3);
    return previewPaint;
  }

  public boolean onTouch(View view, MotionEvent motionEvent) {
    if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
      currentBrush.mouseDown(drawingSurface.previewPath.path, motionEvent.getX(), motionEvent.getY());
    }else if(motionEvent.getAction() == MotionEvent.ACTION_MOVE){
      currentBrush.mouseMove(drawingSurface.previewPath.path, motionEvent.getX(), motionEvent.getY());
    }else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
      currentBrush.mouseUp(drawingSurface.previewPath.path, motionEvent.getX(), motionEvent.getY());
      drawingSurface.previewPath.path = new Path();
    }
  }
}



Quick Explanation
Ads from Amazon:
Explanation
public boolean isDrawing = true;
Lets introduce something that would tell our app if we are drawing or not.

public DrawingPath previewPath;
Here we create another DrawingPath which would only do the preview for us

private Handler previewDoneHandler = new Handler(){
  @Override
  public void handleMessage(Message msg) {
    isDrawing = false;
  }
};

Here we create a handler to tell our app to stop drawing at the end of the last path it has drawn (this function should named differently, ahhah)

class DrawThread extends Thread{
  @Override
  public void run() {
    commandManager.executeAll(c,previewDoneHandler);
    previewPath.draw(c);
  }
};

Here you draw the preview path and pass our complete handler to stop our app from drawing over and over

public void onCreate(Bundle savedInstanceState) {
  drawingSurface.previewPath = new DrawingPath();
  drawingSurface.previewPath.path = new Path();
  drawingSurface.previewPath.paint = getPreviewPaint();
  ...
private Paint getPreviewPaint(){
  ...
}

Here we just initialize the previewPath with a different path (a kinda gray paint, 0xFFC1C1C1)

public boolean onTouch(View view, MotionEvent motionEvent) {
  if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
nbsp;   currentBrush.mouseDown(drawingSurface.previewPath.path, motionEvent.getX(), motionEvent.getY());
  }else if(motionEvent.getAction() == MotionEvent.ACTION_MOVE){
    currentBrush.mouseMove(drawingSurface.previewPath.path, motionEvent.getX(), motionEvent.getY());
  }else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
    currentBrush.mouseUp(drawingSurface.previewPath.path, motionEvent.getX(), motionEvent.getY());
    drawingSurface.previewPath.path = new Path();
  }
}

Here we use the concept we understood from brushes Read the explanation here

Hope this helps :)

Wednesday, December 8, 2010

Drawing with Canvas in Android, Brushes

Continuing with our Drawing in Canvas series, let us see how to implement brushes.


Introduction
Drawing lines is boring, lets draw something else

Notes
• We would introduce a new package com.almondmendoza.drawings.brush
• The files are uploaded in http://goo.gl/ecHpE
• The project was build in IntelliJ and it should be easy to import to Eclipse

What Do I Need
IBrush.java
public interface IBrush {
    public void mouseDown( Path path, float x, float y);
    public void mouseMove( Path path, float x, float y);
    public void mouseUp( Path path, float x, float y);
}


Brush.java
public class Brush implements  IBrush {
    public void mouseDown(Path path, float x, float y) {
        // add codes here if it would affect every brush
    }

    public void mouseMove(Path path, float x, float y) {
        // add codes here if it would affect every brush
    }

    public void mouseUp(Path path, float x, float y) {
        // add codes here if it would affect every brush
    }
}



Pen.java
public class PenBrush extends Brush{
    @Override
    public void mouseDown(Path path, float x, float y) {
        path.moveTo( x, y );
        path.lineTo(x, y);
    }

    @Override
    public void mouseMove(Path path, float x, float y) {
        path.lineTo( x, y );
    }

    @Override
    public void mouseUp(Path path, float x, float y) {
        path.lineTo( x, y );
    }
}


CircleBrush.java
public class CircleBrush extends Brush{
    @Override
    public void mouseMove(Path path, float x, float y) {
        path.addCircle(x,y,10,Path.Direction.CW);
    }
}


DrawingActivity.java
public class DrawingActivity extends Activity implements View.OnTouchListener{
    ...
    private Brush currentBrush;
    public void onCreate(Bundle savedInstanceState) {
        ...
        currentBrush = new PenBrush();
        ...
    }

    public boolean onTouch(View view, MotionEvent motionEvent) {
        if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
            currentBrush.mouseDown(currentDrawingPath.path, motionEvent.getX(), motionEvent.getY());
        } else if(motionEvent.getAction() == MotionEvent.ACTION_MOVE){
            currentBrush.mouseMove( currentDrawingPath.path, motionEvent.getX(), motionEvent.getY() );
        } else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
            currentBrush.mouseUp( currentDrawingPath.path, motionEvent.getX(), motionEvent.getY() );
            drawingSurface.isDrawing = true;
        }
        return true;
    }

    public void onClick(View view){
        switch (view.getId()){
            ...
            case R.id.circleBtn:
                currentBrush = new CircleBrush();
                break;
            case R.id.pathBtn:
                currentBrush = new PenBrush();
                break;
        }
    }



Quick Explanation
Ads from Amazon:
Explanation
public interface IBrush {
  public void mouseDown( Path path, float x, float y);
  public void mouseMove( Path path, float x, float y);
  public void mouseUp( Path path, float x, float y);
}

We begin by creating a brush interface so that our brushes would be united :)

public class Brush implements IBrush {
  ...
}

Our brush class would serve as base classes for our other brushes, here we can implement codes that would be shared across different brushes

public class PenBrush extends Brush{ ... }
From our previous article from the series we had implemented these codes directly on onTouch function on DrawingActivity, here we just move it to its own Brush class.

public class CircleBrush extends Brush{
  @Override
  public void mouseMove(Path path, float x, float y) {
    path.addCircle(x,y,10,Path.Direction.CW);
  }
}

In here we only make use of the mouseMove of our Brush class, as you can see we have path.addCircle where we could make other brushes by changing this to other function or adding more then one path (For other shapes available kindly refer to the Path Reference

public boolean onTouch(View view, MotionEvent motionEvent) {
  if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
    currentBrush.mouseDown(currentDrawingPath.path, motionEvent.getX(), motionEvent.getY());
  }else if(motionEvent.getAction() == MotionEvent.ACTION_MOVE){
    currentBrush.mouseMove( currentDrawingPath.path, motionEvent.getX(), motionEvent.getY() );
  }else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
    currentBrush.mouseUp( currentDrawingPath.path, motionEvent.getX(), motionEvent.getY() );
    drawingSurface.isDrawing = true;
  }
  return true;
}

We rewrote the function to use our brushes to do the paths so that we could change the brush and not care about this function.

public void onClick(View view){
  switch (view.getId()){
    ...
    case R.id.circleBtn:
      currentBrush = new CircleBrush();
    break;
    case R.id.pathBtn:
      currentBrush = new PenBrush();
    break;
  }
}

This is now we change brushes

Conclusion
To add new brushes, just create a new class that extends the Brush class.

Tuesday, December 7, 2010

My Battery Status 2.1.0

Been fixing the UI part of My battery status for days, now its live, anyone can search them on the market (search for com.almondmendoza.monBattery). Next article should be back to our series :)

Friday, December 3, 2010

TutorialForAndroid first 1000 visit

After 2-3 years of this site, I finally hit the 1000 visit one single day, which just means i'm atleast helping 1000 (if all reads the tutorial) or a lot of programmers to Android with these tutorials :)

I would like to thanks everyone, and as we go forward, i would like focus on making series (like the drawing series) and as a new step to this site and my career, im opening up suggestions on what i could blog thus making use of google moderator http://www.google.com/moderator/#15/e=40510&t=40510.40, anyone can suggest a topic (please be warned that i do need time to learn them as well and only after work)

Thanks again