示例#1
0
 void myDraw() {
   float width, height;
   width = getMeasuredWidth();
   height = getMeasuredHeight();
   canvas = holder.lockCanvas();
   canvas.drawColor(Color.GREEN);
   canvas.drawPath(path, paint);
   holder.unlockCanvasAndPost(canvas);
 }
示例#2
0
  public void mDraw() {

    mCanvas = mHolder.lockCanvas(); // 获得画布对象,开始对画布画画

    mCanvas.drawColor(++i); // 设置画布颜色为黑色

    canvasMethod(mCanvas); // 调用自定义的方法,主要是在传进去的画布对象上画画

    mHolder.unlockCanvasAndPost(mCanvas); // 把画布显示在屏幕上
  }
示例#3
0
  public FlxGameView(FlxGame game, Context context, AttributeSet attrs) {
    super(context, attrs);

    SurfaceHolder holder = getHolder();
    holder.addCallback(this);

    this.activity = (Activity) context;

    this.game = game;

    this.setFocusable(true);
    this.setFocusableInTouchMode(true);
  }
示例#4
0
  // Setup
  protected void onCreate(Bundle savedInstanceState) {
    // Log.v("SDL", "onCreate()");
    super.onCreate(savedInstanceState);

    // So we can call stuff from static callbacks
    mSingleton = this;

    // Set up the surface
    mSurface = new SDLSurface(getApplication());
    setContentView(mSurface);
    SurfaceHolder holder = mSurface.getHolder();
    holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
  }
示例#5
0
  /** 构造函数,主要对一些对象初始化 */
  public MySurfaceView(Context context) {
    super(context);

    mHolder = this.getHolder(); // 获得SurfaceHolder对象
    mHolder.addCallback(this); // 添加状态监听

    mPaint = new Paint(); // 创建一个画笔对象
    mPaint.setColor(Color.WHITE); // 设置画笔的颜色为白色

    qPaint = new Paint(); // 创建一个画笔对象
    qPaint.setAntiAlias(true); // 消除锯齿
    qPaint.setStyle(Paint.Style.STROKE); // 设置画笔风格为描边
    qPaint.setStrokeWidth(3); // 设置描边的宽度为3
    qPaint.setColor(Color.GREEN); // 设置画笔的颜色为绿色

    // 创建路径对象
    mPath = new Path();
    qPath = new Path();
    tPath = new Path();

    // 设置坐标为50,100
    mX = 50;
    mY = 100;

    // 设置贝塞尔曲线的开始坐标为(10,200)
    qStartX = 10;
    qStartY = 200;

    setFocusable(true); // 设置焦点
  }
示例#6
0
 // Called when we have a valid drawing surface
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
   Log.v("SDL", "surfaceCreated()");
   holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
   // Set mIsSurfaceReady to 'true' *before* any call to handleResume
   SDLActivity.mIsSurfaceReady = true;
 }
示例#7
0
 public GLView(Activity context) {
   super(context);
   act = context;
   glView = this;
   initSurface = false;
   initNative = false;
   SurfaceHolder holder = getHolder();
   holder.setType(SurfaceHolder.SURFACE_TYPE_GPU); // needed for Android 1.6
   holder.addCallback(this);
   mEglHelper = new EglHelper();
   mEglHelper.start();
   if (mEglHelper.configHasAlpha) holder.setFormat(PixelFormat.TRANSLUCENT);
   // Log.i(logTag, "set surface type");
   setFocusable(true);
   setFocusableInTouchMode(true);
   setKeepScreenOn(true);
 }
示例#8
0
  /**
   * 画整体chart图
   *
   * @param translatX chart图偏移量
   */
  public void refreshChart(int translatX) {
    synchronized (holder) {
      translationChart(translatX);

      if (holder != null) {
        Canvas canvas = holder.lockCanvas();
        if (canvas != null) {
          canvas.drawColor(backColor);
          drawGridLine(canvas);
          drawChartLine(canvas);
          drawLimitRect(canvas);
          drawAxesLine(canvas);
          drawYValueText(canvas);
          holder.unlockCanvasAndPost(canvas);
        }
      }
    }
  }
示例#9
0
 public MyView(Context context) {
   super(context);
   paint = new Paint();
   paint.setColor(Color.BLUE);
   paint.setStyle(Paint.Style.STROKE); // 设置画笔风格为描边
   paint.setStrokeWidth(10);
   random = new Random();
   setFocusable(true);
   holder = getHolder();
   holder.addCallback(this);
   path = new Path();
 }
示例#10
0
 @Override
 public void run() {
   while (running) {
     Canvas c = null;
     try {
       c = surfaceHolder.lockCanvas(null);
       synchronized (surfaceHolder) {
         if (!game.onEnterFrame(c)) {
           running = false;
           game.shutdown(true);
           view.shutdown();
         }
       }
     } finally {
       // do this in a finally so that if an exception is thrown
       // during the above, we don't leave the Surface in an
       // inconsistent state
       if (c != null) {
         surfaceHolder.unlockCanvasAndPost(c);
       }
     }
   }
 }
示例#11
0
 // Called when we have a valid drawing surface
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
   Log.v("SDL", "surfaceCreated()");
   holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
 }
示例#12
0
 public ChartView(Context context, AttributeSet attrs, int defStyle) {
   super(context, attrs, defStyle);
   this.context = context;
   holder = getHolder();
   holder.addCallback(new ChartCallBack());
 }
示例#13
0
 // Called when we have a valid drawing surface
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
   Log.v("SDL", "surfaceCreated()");
   holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
   enableSensor(Sensor.TYPE_ACCELEROMETER, true);
 }