Java 类android.view.SurfaceHolder 实例源码

项目:QRCodeScanner    文件:BarcodeScanView.java   
private void init() {
    // init surfaceholder
    SurfaceHolder holder = getHolder();
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    holder.addCallback(this);

    WindowManager manager = (WindowManager) getContext().getSystemService(
            Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();
    screenWidth = display.getWidth();
    screenHeight = display.getHeight();
    int width = screenWidth >= screenHeight ? screenWidth : screenHeight;
    int height = screenWidth + screenHeight - width;
    int rotation = display.getRotation();
    mScanner = CameraScanner.getInstance();
    mScanner.setRotation(0);  //此处直接设为0,配合竖屏展示
    mScanner.setReqSize(width, height);

}
项目:FaceDetectDemo    文件:CameraBridgeViewBase.java   
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    Log.d(TAG, "call surfaceChanged event");
    synchronized(mSyncObject) {
        if (!mSurfaceExist) {
            mSurfaceExist = true;
            checkCurrentState();
        } else {
            /** Surface changed. We need to stop camera and restart with new parameters */
            /* Pretend that old surface has been destroyed */
            mSurfaceExist = false;
            checkCurrentState();
            /* Now use new surface. Say we have it now */
            mSurfaceExist = true;
            checkCurrentState();
        }
    }
}
项目:TPlayer    文件:VideoView.java   
@SuppressWarnings("deprecation")
private void initVideoView(Context ctx) {
  mContext = ctx;
  mVideoWidth = 0;
  mVideoHeight = 0;
  getHolder().setFormat(PixelFormat.RGBA_8888); // PixelFormat.RGB_565
  getHolder().addCallback(mSHCallback);
  // this value only use Hardware decoder before Android 2.3
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB && mHardwareDecoder) {
    getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  }
  setFocusable(true);
  setFocusableInTouchMode(true);
  requestFocus();
  mCurrentState = STATE_IDLE;
  mTargetState = STATE_IDLE;
  if (ctx instanceof Activity) {
      ((Activity) ctx).setVolumeControlStream(AudioManager.STREAM_MUSIC);
  }
}
项目:BilibiliClient    文件:VideoPlayerView.java   
public void surfaceChanged(SurfaceHolder holder, int format, int w,
                           int h) {

  mSurfaceHolder = holder;
  if (mMediaPlayer != null) {
    mMediaPlayer.setDisplay(mSurfaceHolder);
  }

  mSurfaceWidth = w;
  mSurfaceHeight = h;
  boolean isValidState = (mTargetState == STATE_PLAYING);
  boolean hasValidSize = (mVideoWidth == w && mVideoHeight == h);
  if (mMediaPlayer != null && isValidState && hasValidSize) {
    if (mSeekWhenPrepared != 0) {
      seekTo(mSeekWhenPrepared);
    }
    start();
    if (mMediaController != null) {
      if (mMediaController.isShowing()) {
        mMediaController.hide();
      }
      mMediaController.show();
    }
  }
}
项目:GitHub    文件:CameraManager.java   
/**
 * Opens the camera driver and initializes the hardware parameters.
 *
 * @param holder The surface object which the camera will draw preview frames into.
 * @throws IOException Indicates the camera driver failed to open.
 */
public void openDriver(SurfaceHolder holder) throws IOException {
    if (camera == null) {
        camera = Camera.open();
        if (camera == null) {
            throw new IOException();
        }
        camera.setPreviewDisplay(holder);

        if (!initialized) {
            initialized = true;
            configManager.initFromCameraParameters(camera);
        }
        configManager.setDesiredCameraParameters(camera);

        //FIXME
        //     SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        //�Ƿ�ʹ��ǰ��
        //      if (prefs.getBoolean(PreferencesActivity.KEY_FRONT_LIGHT, false)) {
        //        FlashlightManager.enableFlashlight();
        //      }
        FlashlightManager.enableFlashlight();
    }
}
项目:MOAAP    文件:CameraBridgeViewBase.java   
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    Log.d(TAG, "call surfaceChanged event");
    synchronized(mSyncObject) {
        if (!mSurfaceExist) {
            mSurfaceExist = true;
            checkCurrentState();
        } else {
            /** Surface changed. We need to stop camera and restart with new parameters */
            /* Pretend that old surface has been destroyed */
            mSurfaceExist = false;
            checkCurrentState();
            /* Now use new surface. Say we have it now */
            mSurfaceExist = true;
            checkCurrentState();
        }
    }
}
项目:CSipSimple    文件:ViESurfaceRenderer.java   
public void surfaceChanged(SurfaceHolder holder, int format,
        int in_width, int in_height) {
    Log.d(TAG, "ViESurfaceRender::surfaceChanged");

    changeDestRect(in_width, in_height);

    Log.d(TAG, "ViESurfaceRender::surfaceChanged" +
            " in_width:" + in_width + " in_height:" + in_height +
            " srcRect.left:" + srcRect.left +
            " srcRect.top:" + srcRect.top +
            " srcRect.right:" + srcRect.right +
            " srcRect.bottom:" + srcRect.bottom +
            " dstRect.left:" + dstRect.left +
            " dstRect.top:" + dstRect.top +
            " dstRect.right:" + dstRect.right +
            " dstRect.bottom:" + dstRect.bottom);
}
项目:OpenCV    文件:CameraBridgeViewBase.java   
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    Log.d(TAG, "call surfaceChanged event");
    synchronized(mSyncObject) {
        if (!mSurfaceExist) {
            mSurfaceExist = true;
            checkCurrentState();
        } else {
            /** Surface changed. We need to stop camera and restart with new parameters */
            /* Pretend that old surface has been destroyed */
            mSurfaceExist = false;
            checkCurrentState();
            /* Now use new surface. Say we have it now */
            mSurfaceExist = true;
            checkCurrentState();
        }
    }
}
项目:GestureVideoView    文件:SurfaceRenderView.java   
@Override
public void surfaceChanged(SurfaceHolder holder, int format,
                           int width, int height) {
    mSurfaceHolder = holder;
    mIsFormatChanged = true;
    mFormat = format;
    mWidth = width;
    mHeight = height;

    // mMeasureHelper.setVideoSize(width, height);

    ISurfaceHolder surfaceHolder = new InternalSurfaceHolder(mWeakSurfaceView.get(), mSurfaceHolder);
    for (IRenderCallback renderCallback : mRenderCallbackMap.keySet()) {
        renderCallback.onSurfaceChanged(surfaceHolder, format, width, height);
    }
}
项目:MeiLa_GNN    文件:CameraManager.java   
/**
     * Opens the camera driver and initializes the hardware parameters.
     *
     * @param holder The surface object which the camera will draw preview frames into.
     * @throws IOException Indicates the camera driver failed to open.
     */
    public void openDriver(SurfaceHolder holder) throws IOException {
        if (camera == null) {
            camera = Camera.open();
            if (camera == null) {
                throw new IOException();
            }
            camera.setPreviewDisplay(holder);

            if (!initialized) {
                initialized = true;
                configManager.initFromCameraParameters(camera);
            }
            configManager.setDesiredCameraParameters(camera);

            //FIXME
            //     SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            //�Ƿ�ʹ��ǰ��
//      if (prefs.getBoolean(PreferencesActivity.KEY_FRONT_LIGHT, false)) {
//        FlashlightManager.enableFlashlight();
//      }
            FlashlightManager.enableFlashlight();
        }
    }
项目:EVideoRecorder    文件:ERecorderActivity.java   
@Override
protected void initView() {

    mSurfaceview = (SurfaceView) findViewById(R.id.surfaceview);
    mRlTakeVedio = (RelativeLayout) findViewById(R.id.rl_take_vedio);
    mIvCancel = (ImageView) findViewById(R.id.iv_cancel);
    mTrpbController = (TimeRoundProgressBar) findViewById(R.id.trpb_controller);
    mRlConfrmVedio = (RelativeLayout) findViewById(R.id.rl_confrm_vedio);
    mIvDelete = (ImageView) findViewById(R.id.iv_delete);
    mIvConfirm = (ImageView) findViewById(R.id.iv_confirm);


    mDialog = ERecorderActivityImpl.getCreateVedioDialog(getActivity());
    mTrpbController.setMax(mRecordTime);

    SurfaceHolder holder = mSurfaceview.getHolder();// 取得holder
    holder.setFormat(PixelFormat.TRANSPARENT);
    holder.setKeepScreenOn(true);
    holder.addCallback(this); // holder加入回调接口
}
项目:CSipSimple    文件:ViESurfaceRenderer.java   
public void surfaceCreated(SurfaceHolder holder) {
    Canvas canvas = surfaceHolder.lockCanvas();
    if(canvas != null) {
        Rect dst = surfaceHolder.getSurfaceFrame();
        if(dst != null) {
            changeDestRect(dst.right - dst.left, dst.bottom - dst.top);
            Log.d(TAG, "ViESurfaceRender::surfaceCreated" +
                    " dst.left:" + dst.left +
                    " dst.top:" + dst.top +
                    " dst.right:" + dst.right +
                    " dst.bottom:" + dst.bottom +
                    " srcRect.left:" + srcRect.left +
                    " srcRect.top:" + srcRect.top +
                    " srcRect.right:" + srcRect.right +
                    " srcRect.bottom:" + srcRect.bottom +
                    " dstRect.left:" + dstRect.left +
                    " dstRect.top:" + dstRect.top +
                    " dstRect.right:" + dstRect.right +
                    " dstRect.bottom:" + dstRect.bottom);
        }
        surfaceHolder.unlockCanvasAndPost(canvas);
    }
}
项目:AndroidBasicLibs    文件:CaptureActivity.java   
@Override
protected void onResume() {
    super.onResume();
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        initCamera(surfaceHolder);
    } else {
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }
    decodeFormats = null;
    characterSet = null;

    playBeep = true;
    AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
    if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
        playBeep = false;
    }
    initBeepSound();
    vibrate = true;
}
项目:RLibrary    文件:UIScanView.java   
private void initCamera(SurfaceHolder surfaceHolder) {
    if (surfaceHolder == null) {
        return;
    }
    if (cameraManager.isOpen()) {
        return;
    }
    try {
        cameraManager.openDriver(surfaceHolder);
        if (handler == null) {
            handler = new CaptureActivityHandler(this, decodeFormats,
                    decodeHints, characterSet, cameraManager);
        }
        decodeOrStoreSavedBitmap(null, null);
    } catch (IOException ioe) {
        displayFrameworkBugMessageAndExit();
    } catch (RuntimeException e) {
        displayFrameworkBugMessageAndExit();
    }
}
项目:ZXingDemo    文件:CameraManager.java   
/**
   * Opens the camera driver and initializes the hardware parameters.
   *
   * @param holder The surface object which the camera will draw preview frames into.
   * @throws IOException Indicates the camera driver failed to open.
   */
  public void openDriver(SurfaceHolder holder) throws IOException {
    if (camera == null) {
      camera = Camera.open();
      if (camera == null) {
        throw new IOException();
      }
      camera.setPreviewDisplay(holder);

      if (!initialized) {
        initialized = true;
        configManager.initFromCameraParameters(camera);
      }
      configManager.setDesiredCameraParameters(camera);

      //FIXME
 //     SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
      //是否使用前灯
//      if (prefs.getBoolean(PreferencesActivity.KEY_FRONT_LIGHT, false)) {
//        FlashlightManager.enableFlashlight();
//      }
      FlashlightManager.enableFlashlight();
    }
  }
项目:Dendroid-HTTP-RAT    文件:CameraView.java   
@SuppressWarnings("deprecation")
public void onCreate(Bundle icicle){
          super.onCreate(icicle);

          Log.e(TAG, "onCreate");

          setContentView(R.layout.cameraview);

          mSurfaceView = (SurfaceView) findViewById(R.id.surface_camera);
          mSurfaceHolder = mSurfaceView.getHolder();
          mSurfaceHolder.addCallback(this);
          mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
      }
项目:QuanMinTV    文件:MediaPlayer.java   
/**
 * Sets the SurfaceHolder to use for displaying the video portion of the
 * media. This call is optional. Not calling it when playing back a video will
 * result in only the audio track being played.
 *
 * @param sh the SurfaceHolder to use for video display
 */
public void setDisplay(SurfaceHolder sh) {
  if (sh == null) {
    releaseDisplay();
  } else {
    mSurfaceHolder = sh;
    mSurface = sh.getSurface();
    _setVideoSurface(mSurface);
    updateSurfaceScreenOn();
  }
}
项目:AndroidRTC    文件:SurfaceViewRenderer.java   
@Override
public void surfaceCreated(final SurfaceHolder holder) {
  ThreadUtils.checkIsOnMainThread();
  eglRenderer.createEglSurface(holder.getSurface());
  surfaceWidth = surfaceHeight = 0;
  updateSurfaceSize();
}
项目:AR    文件:CameraView.java   
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height ) {
    Camera.Parameters parameters = camera.getParameters();
    List<Camera.Size> previewSizes = parameters.getSupportedPreviewSizes();
    Camera.Size previewSize = previewSizes.get(previewSizes.size()-1);
    Camera.Parameters p = camera.getParameters();

    p.setPreviewSize( previewSize.width, previewSize.height );
    camera.setParameters( p );
    try{camera.setPreviewDisplay( holder );} catch(IOException e){e.printStackTrace();}
    camera.startPreview();
}
项目:Expert-Android-Programming    文件:DefaultEasyCamera.java   
@Override
public CameraActions startPreview(SurfaceHolder holder) throws IOException {
    if (holder == null) {
        throw new NullPointerException("You cannot start preview without a preview surface");
    }
    camera.setPreviewDisplay(holder);
    camera.startPreview();
    return new DefaultCameraActions(this);
}
项目:Mobike    文件:CaptureActivity.java   
private void initCamera(SurfaceHolder surfaceHolder) {
    try {
        CameraManager.get().openDriver(surfaceHolder);
    } catch (IOException ioe) {
        return;
    } catch (RuntimeException e) {
        return;
    }
    if (handler == null) {
        handler = new CaptureActivityHandler(this, decodeFormats,
                characterSet);
    }
}
项目:boohee_v5.6    文件:SurfaceRenderView.java   
public void surfaceDestroyed(SurfaceHolder holder) {
    this.mSurfaceHolder = null;
    this.mIsFormatChanged = false;
    this.mFormat = 0;
    this.mWidth = 0;
    this.mHeight = 0;
    ISurfaceHolder surfaceHolder = new InternalSurfaceHolder((SurfaceRenderView) this
            .mWeakSurfaceView.get(), this.mSurfaceHolder);
    for (IRenderCallback renderCallback : this.mRenderCallbackMap.keySet()) {
        renderCallback.onSurfaceDestroyed(surfaceHolder);
    }
}
项目:GestureVideoView    文件:SurfaceRenderView.java   
private void initView(Context context) {
    mMeasureHelper = new MeasureHelper(this);
    mSurfaceCallback = new SurfaceCallback(this);
    getHolder().addCallback(mSurfaceCallback);
    //noinspection deprecation
    getHolder().setType(SurfaceHolder.SURFACE_TYPE_NORMAL);
}
项目:AdronEngine    文件:CameraSurface.java   
public CameraSurface( Context context ) {
    super( context );
    // We're implementing the Callback interface and want to get notified
    // about certain surface events.
    getHolder().addCallback( this );
    // We're changing the surface to a PUSH surface, meaning we're receiving
    // all buffer data from another component - the camera, in this case.
    getHolder().setType( SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS );
}
项目:GitHub    文件:SurfaceRenderView.java   
private void initView(Context context) {
    mMeasureHelper = new MeasureHelper(this);
    mSurfaceCallback = new SurfaceCallback(this);
    getHolder().addCallback(mSurfaceCallback);
    //noinspection deprecation
    getHolder().setType(SurfaceHolder.SURFACE_TYPE_NORMAL);
}
项目:letv    文件:VideoViewH264m3u8_4D.java   
public void surfaceCreated(SurfaceHolder holder) {
    LogTag.i("mSHCallback:surfaceCreated()");
    if (VideoViewH264m3u8_4D.this.mSurfaceHolder == null) {
        VideoViewH264m3u8_4D.this.mSurfaceHolder = holder;
        VideoViewH264m3u8_4D.this.openVideo();
    }
}
项目:NSMPlayer-Android    文件:WrapExoPlayer.java   
@Override
public void setDisplay(SurfaceHolder sh) {
    if (sh == null) {
        setSurface(null);
    } else {
        setSurface(sh.getSurface());
    }
}
项目:GitHub    文件:FireView.java   
@Override
public void surfaceCreated(SurfaceHolder holder) {
    fireHeight = getHeight() * 3 / 4;
    halfWidth = getWidth() / 2;
    fireWidth = halfWidth / 4;
    distance = fireWidth / 8;
    running = true;
    new RefreshThread().start();
}
项目:keepass2android    文件:CaptureActivity.java   
@Override
public void surfaceCreated(SurfaceHolder holder) {
  if (holder == null) {
    Log.e(TAG, "*** WARNING *** surfaceCreated() gave us a null surface!");
  }
  if (!hasSurface) {
    hasSurface = true;
    initCamera(holder);
  }
}
项目:AndroidRTC    文件:EglBase10.java   
private void createSurfaceInternal(Object nativeWindow) {
  if (!(nativeWindow instanceof SurfaceHolder) && !(nativeWindow instanceof SurfaceTexture)) {
    throw new IllegalStateException("Input must be either a SurfaceHolder or SurfaceTexture");
  }
  checkIsNotReleased();
  if (eglSurface != EGL10.EGL_NO_SURFACE) {
    throw new RuntimeException("Already has an EGLSurface");
  }
  int[] surfaceAttribs = {EGL10.EGL_NONE};
  eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, nativeWindow, surfaceAttribs);
  if (eglSurface == EGL10.EGL_NO_SURFACE) {
    throw new RuntimeException(
        "Failed to create window surface: 0x" + Integer.toHexString(egl.eglGetError()));
  }
}
项目:tvConnect_android    文件:ImageSurfaceView.java   
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
                           int height) {

    synchronized (ImageSurfaceView.class) {
        mRectDes.set(0, 0, width, height);
        mSurfaceHeight = height;
        mSurfaceWidth = width;
        init(default_scale);
        if (mBitmap != null) {
            showBitmap();
        }
    }
}
项目:aos-Video    文件:Player.java   
public void surfaceDestroyed(SurfaceHolder holder)
{
    // after we return from this we can't use the surface any more
    mSurfaceHolder = null;
    mSurfaceWidth = 0;
    mSurfaceHeight = 0;
    stopPlayback();
}
项目:AndroidBasicLibs    文件:CaptureActivity.java   
private void initCamera(SurfaceHolder surfaceHolder) {
    try {
        CameraManager.get().openDriver(surfaceHolder);
    } catch (IOException ioe) {
        return;
    } catch (RuntimeException e) {
        return;
    }
    if (handler == null) {
        handler = new CaptureActivityHandler(this, decodeFormats,
                characterSet, viewfinderView, this);
    }
}
项目:PlayerBase    文件:SurfaceRenderView.java   
private void initView(Context context) {
    mMeasureHelper = new MeasureHelper(this);
    mSurfaceCallback = new SurfaceCallback(this);
    getHolder().addCallback(mSurfaceCallback);
    //noinspection deprecation
    getHolder().setType(SurfaceHolder.SURFACE_TYPE_NORMAL);
}
项目:CameraCardCropDemo    文件:CameraView.java   
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    if (autoFocusManager != null) {
        autoFocusManager.stop();
        autoFocusManager = null;
    }
}
项目:HexColorTime    文件:Wallpaper.java   
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format,
                             int width, int height) {
    super.onSurfaceChanged(holder, format, width, height);
    draw();
}
项目:WithYou    文件:VideoVerify.java   
@Override
public void surfaceCreated(SurfaceHolder holder) {
    openCamera();
}
项目:PlayerBase    文件:DelegateDecoderPlayer.java   
@Override
public void setDisplay(SurfaceHolder surfaceHolder) {
    if(isLegalState()){
        mDecoder.setDisplay(surfaceHolder);
    }
}
项目:ubiquitous    文件:MyWatchFace.java   
@Override
public void onCreate(SurfaceHolder holder) {
    super.onCreate(holder);

    setWatchFaceStyle(new WatchFaceStyle.Builder(MyWatchFace.this)
            .setCardPeekMode(WatchFaceStyle.PEEK_MODE_VARIABLE)
            .setBackgroundVisibility(WatchFaceStyle.BACKGROUND_VISIBILITY_INTERRUPTIVE)
            .setShowSystemUiTime(false)
            .setAcceptsTapEvents(true)
            .build());
    Resources resources = MyWatchFace.this.getResources();
    mYOffset = resources.getDimension(R.dimen.digital_y_offset);
    mY1Offset = resources.getDimension(R.dimen.digital_y1_offset);

    mLowTextSize = resources.getDimension(R.dimen.low_temp_text_size);
    mHighTextSize = resources.getDimension(R.dimen.high_temp_text_size);

    dp_10 = resources.getDimension(R.dimen.dp_10);
    dp_5 = resources.getDimension(R.dimen.dp_5);

    mBackgroundPaint = new Paint();
    mBackgroundPaint.setColor(resources.getColor(R.color.colorPrimary));

    mTextPaint = new Paint();
    mTextPaint = createTextPaint(resources.getColor(R.color.digital_text));

    dateTextPaint = new Paint();
    dateTextPaint = createTextPaint(resources.getColor(R.color.light_white));

    lineTextPaint = new Paint();
    lineTextPaint = createTextPaint(resources.getColor(R.color.light_white));

    mLowTempPaint = new Paint();
    mLowTempPaint = createTextPaint(resources.getColor(R.color.light_white));

    mHighTempPaint = new Paint();
    mHighTempPaint = createTextPaint(resources.getColor(R.color.white));

    mCalendar = Calendar.getInstance();

    mWearClient = new GoogleApiClient.Builder(MyWatchFace.this)
            .addApi(Wearable.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
}
项目:FaceDetectDemo    文件:CameraBridgeViewBase.java   
public void surfaceCreated(SurfaceHolder holder) {
    /* Do nothing. Wait until surfaceChanged delivered */
}