Пример #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);
 }
  public void onSensorChanged(String sensorStr) {
    Log.v(TAG, "onSensorChanged : " + sensorStr);

    String[] fs = sensorStr.split(",");
    if (fs.length == 4) {
      acceValusW = Float.parseFloat(fs[0]) * (BASE - 10);
      // 获得x轴的值
      acceValusX = Float.parseFloat(fs[1]) * (BASE - 10);
      // 获得y轴的值
      acceValusY = Float.parseFloat(fs[2]) * (BASE - 10);
      // 获得z轴的值
      acceValusZ = Float.parseFloat(fs[3]) * (BASE - 10);
      // 锁定整个SurfaceView
      Canvas mCanvas = mSurfaceHolder.lockCanvas();
      try {
        if (mCanvas != null) {
          // 画笔的颜色(红)
          mPaint.setColor(Color.RED);
          // 画X轴的点
          mCanvas.drawPoint(x, (int) (BASE + acceValusX), mPaint);
          // 画笔的颜色(绿)
          mPaint.setColor(Color.GREEN);
          // 画Y轴的点
          mCanvas.drawPoint(x, (int) (BASE * 2 + acceValusY), mPaint);
          // 画笔的颜色(蓝)
          mPaint.setColor(Color.CYAN);
          // 画Z轴的点
          mCanvas.drawPoint(x, (int) (BASE * 3 + acceValusZ), mPaint);
          // 画笔的颜色(huang)
          mPaint.setColor(Color.WHITE);
          // 画W轴的点
          mCanvas.drawPoint(x, (int) (BASE * 4 + acceValusW), mPaint);
          // 横坐标+1

          x++;
          // 如果已经画到了屏幕的最右边
          // if (x > getWindowManager().getDefaultDisplay().getWidth()) {
          if (x > mCanvas.getWidth()) {
            x = 0;
            // 清屏
            mCanvas.drawColor(Color.BLACK);
          }
          // 绘制完成,提交修改
          mSurfaceHolder.unlockCanvasAndPost(mCanvas);
        }
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        if (mCanvas != null) {
          // 重新锁一次
          mSurfaceHolder.lockCanvas(new Rect(0, 0, 0, 0));
          mSurfaceHolder.unlockCanvasAndPost(mCanvas);
        }
      }
    }
  }
Пример #3
0
  public void mDraw() {

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

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

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

    mHolder.unlockCanvasAndPost(mCanvas); // 把画布显示在屏幕上
  }
Пример #4
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); // 设置焦点
  }
Пример #5
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();
 }
  protected void displayVideoFrame(SurfaceHolder holder) {

    if (videoFormat != null) {
      try {
        ISurfaceWrapper surface = AndroidMediaObjectFactory.Converter.convert(holder.getSurface());
        mediaFileInfo.setOutputSurface(surface);

        ByteBuffer buffer = ByteBuffer.allocate(1);
        mediaFileInfo.getFrameAtPosition(100, buffer);

      } catch (Exception e) {
        String message = (e.getMessage() != null) ? e.getMessage() : e.toString();

        showMessageBox(
            message,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialogInterface, int i) {}
            });
      }
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gatt_services_characteristics);

    final Intent intent = getIntent();
    mDeviceName = intent.getStringExtra(EXTRAS_DEVICE_NAME);
    mDeviceAddress = intent.getStringExtra(EXTRAS_DEVICE_ADDRESS);

    // Sets up UI references.
    mConnectionState = (TextView) findViewById(R.id.connection_state);
    // is serial present?
    isSerial = (TextView) findViewById(R.id.isSerial);

    msgEdit = (EditText) findViewById(R.id.editText);
    returnText = (TextView) findViewById(R.id.returnText);

    sendButton = (Button) findViewById(R.id.sendButton);
    //        timeButton = (Button) findViewById(R.id.timeButton);

    sendButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            if (characteristicReady) {
              StringBuffer sb = new StringBuffer("m");
              sb.append(msgEdit.getText()).append("\n");

              sendMessage(sb.toString());
            }
          }
        });

    //        timeButton.setOnClickListener(new View.OnClickListener() {
    //
    //            @Override
    //            public void onClick(View v) {
    //                if (characteristicReady) {
    //                    StringBuffer sb = new StringBuffer("t");
    //                    Date now = new Date();
    //                    sb.append(DATE_FORMAT.format(now)).append("\n");
    //
    //                    sendMessage(sb.toString());
    //                }
    //            }
    //        });

    infoButton = (ImageView) findViewById(R.id.infoImage);
    infoButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            iascDialog();
          }
        });

    mSurfaceView = (SurfaceView) findViewById(R.id.surfaceView);
    mSurfaceHolder = mSurfaceView.getHolder();
    mSurfaceHolder.addCallback(new MyHolder());

    mPaint = new Paint();
    // 画笔的粗细
    mPaint.setStrokeWidth(5.0f);

    getActionBar().setTitle(mDeviceName);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    Intent gattServiceIntent = new Intent(this, BluetoothLeService.class);
    bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE);
  }