Android Open Source - Blufpoker My Surface View






From Project

Back to project page Blufpoker.

License

The source code is released under:

Apache License

If you think the Android project Blufpoker listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.stofkat.blufpoker;
/*from  w  w w .j  a v  a  2  s  .  com*/
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class MySurfaceView extends SurfaceView implements SurfaceHolder.Callback{
  
  private MySurfaceThread thread;
  private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
  int cx, cy, offx, offy;

  public MySurfaceView(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
    init();
  }

  public MySurfaceView(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
    init();
  }

  public MySurfaceView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    // TODO Auto-generated constructor stub
    init();
  }

   private void init(){
      getHolder().addCallback(this);
      thread = new MySurfaceThread(getHolder(), this);
     
      setFocusable(true); // make sure we get key events
     
      paint.setStyle(Paint.Style.STROKE);
      paint.setStrokeWidth(3);
      paint.setColor(Color.WHITE);
     
      cx = 0;
      cy = 0;
      offx = 10;
      offy = 10;
     
     }
  
  @Override
  public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    // TODO Auto-generated method stub
    
  }

  @Override
  public void surfaceCreated(SurfaceHolder holder) {
    // TODO Auto-generated method stub
    thread.setRunning(true);
    thread.start();
    
  }

  @Override
  public void surfaceDestroyed(SurfaceHolder holder) {
    // TODO Auto-generated method stub
    boolean retry = true;
    thread.setRunning(false);
    while (retry) {
      try {
        thread.join();
        retry = false;
      } 
      catch (InterruptedException e) {
      }
    }
  }

  @Override
  protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    canvas.drawRGB(0, 0, 0);
    canvas.drawCircle(cx, cy, 3, paint);
    cx += offx;
    if (cx > getWidth() || (cx < 0)){
      offx *= -1;
      cx += offx;
    }
    
    cy += offy;
    if (cy > getHeight() || (cy < 0)){
      offy *= -1;
      cy += offy;
    }
  }
}




Java Source Code List

org.stofkat.blufpoker.AndroidMergeSurfaceView.java
org.stofkat.blufpoker.BlufPokerActivity.java
org.stofkat.blufpoker.IntentKeys.java
org.stofkat.blufpoker.MyGLRenderer.java
org.stofkat.blufpoker.MyGLSurfaceView.java
org.stofkat.blufpoker.MySurfaceThread.java
org.stofkat.blufpoker.MySurfaceView.java
org.stofkat.blufpoker.OpenGLES20Activity.java
org.stofkat.blufpoker.Square.java
org.stofkat.blufpoker.Test.java
org.stofkat.blufpoker.Triangle.java
org.stofkat.blufpoker.util.SystemUiHiderBase.java
org.stofkat.blufpoker.util.SystemUiHiderHoneycomb.java
org.stofkat.blufpoker.util.SystemUiHider.java