Java Code Examples for android.view.SurfaceHolder#addCallback()

The following examples show how to use android.view.SurfaceHolder#addCallback() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CaptureActivity.java    From Mobike with Apache License 2.0 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    Log.d(TAG, "xxxxxxxxxxxxxxxxxxxonResume");
    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    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;
    final AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
    if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
        playBeep = false;
    }
    initBeepSound();
    vibrate = true;
}
 
Example 2
Source File: CaptureActivity.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();
    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    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;

}
 
Example 3
Source File: VideoSurfaceLayer.java    From google-media-framework-android with Apache License 2.0 6 votes vote down vote up
@Override
public FrameLayout createView(LayerManager layerManager) {
  this.layerManager = layerManager;

  LayoutInflater inflater = layerManager.getActivity().getLayoutInflater();
  view = (FrameLayout) inflater.inflate(R.layout.video_surface_layer, null);

  layerManager.getExoplayerWrapper().addListener(playbackListener);

  surfaceView = (VideoSurfaceView) view.findViewById(R.id.surface_view);
  if (surfaceView != null) {
    SurfaceHolder holder = surfaceView.getHolder();
    holder.addCallback(surfaceHolderCallback);
  }

  return view;
}
 
Example 4
Source File: GLSurfaceView2.java    From java6-android-glframework with Mozilla Public License 2.0 5 votes vote down vote up
private void init()
{
   // Install a SurfaceHolder.Callback so we get notified when the
   // underlying surface is created and destroyed
   SurfaceHolder holder = getHolder();
   holder.addCallback(this);
}
 
Example 5
Source File: MainActivity.java    From EvilsLive with MIT License 5 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        setSupportActionBar(mToolbar);

        mPermissionsChecker = new PermissionsChecker(this);

        streamer = new EvilsLiveStreamer(this);

//        ViewGroup.LayoutParams layoutParams = mPreviewView.getLayoutParams();
//        layoutParams.width = 640;
//        layoutParams.height = 480;
//        mPreviewView.setLayoutParams(layoutParams);
        SurfaceHolder holder = mPreviewView.getHolder();
        holder.addCallback(this);

        audioCapture = new AudioCapture();
        audioPlay = new AudioPlayer();

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        ActivityComponent activityComponent = DaggerActivityComponent.builder()
                .activityModule(new ActivityModule(this)).build();
        activityComponent.getActivity();

//        CameraComponent cameraComponent = DaggerCameraComponent.builder().activityComponent(activityComponent).
//                cameraModule(new com.thinkkeep.videolib.di.modules.CameraModule(this)).build();
//        cameraComponent.inject(this);
    }
 
Example 6
Source File: MjpegView.java    From CameraV with GNU General Public License v3.0 5 votes vote down vote up
private void init(Context context) {
	mContext = context;
    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    //thread = new MjpegViewThread(holder, context);
    setFocusable(true);
    
    mPlayer = new MjpegPlayer(holder, mContext, mIn);
    mPlayer.setDisplay(getWidth(), getHeight(), MjpegView.SIZE_BEST_FIT);
    mIsPrepared = true;
    attachMediaController();
    mPlayer.showFps(true);
}
 
Example 7
Source File: CaptureActivity.java    From KSYMediaPlayer_Android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onResume() {
	super.onResume();
	SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
	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;
	
	//quit the scan view
	cancelScanButton.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			CaptureActivity.this.finish();
		}
	});
}
 
Example 8
Source File: FaceDetectRGBActivity.java    From FaceDetectCamera with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Check for the camera permission before accessing the camera.  If the
    // permission is not granted yet, request permission.
    SurfaceHolder holder = mView.getHolder();
    holder.addCallback(this);
    holder.setFormat(ImageFormat.NV21);
}
 
Example 9
Source File: GameView.java    From wearabird with MIT License 5 votes vote down vote up
private void init(@SuppressWarnings("UnusedParameters") Context context) {
	SurfaceHolder holder = getHolder();
	holder.addCallback(this);
	holder.setFormat(PixelFormat.RGBA_8888);
	setKeepScreenOn(true);
	mainThreadHandler = new Handler(Looper.getMainLooper());
}
 
Example 10
Source File: CameraSurfaceView.java    From open-quartz with Apache License 2.0 5 votes vote down vote up
public CameraSurfaceView(Context context) {
    super(context);

    final SurfaceHolder surfaceHolder = getHolder();
    surfaceHolder.addCallback(this);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
 
Example 11
Source File: CaptureActivity.java    From FoodOrdering with Apache License 2.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    // CameraManager必须在这里初始化,而不是在onCreate()中。
    // 这是必须的,因为当我们第一次进入时需要显示帮助页,我们并不想打开Camera,测量屏幕大小
    // 当扫描框的尺寸不正确时会出现bug
    cameraManager = new CameraManager(getApplication());

    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);

    handler = null;

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // activity在paused时但不会stopped,因此surface仍旧存在;
        // surfaceCreated()不会调用,因此在这里初始化camera
        initCamera(surfaceHolder);
    } else {
        // 重置callback,等待surfaceCreated()来初始化camera
        surfaceHolder.addCallback(this);
    }

    beepManager.updatePrefs();
    inactivityTimer.onResume();

    source = IntentSource.NONE;
    decodeFormats = null;
    characterSet = null;
}
 
Example 12
Source File: SquareMotionView.java    From ToyView with MIT License 5 votes vote down vote up
private void initPaint() {
    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
    holder.setFormat(PixelFormat.TRANSPARENT);
    setZOrderOnTop(true);

    linePaint.setAntiAlias(true);
    linePaint.setColor(0xff05225C);
    linePaint.setStyle(Paint.Style.STROKE);
    linePaint.setStrokeCap(Paint.Cap.ROUND);
    linePaint.setStrokeWidth(20);

}
 
Example 13
Source File: BubbleGraphView.java    From HzGrapher with Apache License 2.0 5 votes vote down vote up
private void initView ( Context ctx , BubbleGraphVO vo )
{
	ErrorCode ec = ErrorDetector.checkGraphObject(vo);
	ec.printError();
	
	SurfaceHolder holder = this.getHolder();
	holder.addCallback(this);
	mContext = ctx;
}
 
Example 14
Source File: VideoViewRecycler.java    From MaterialDesignSupport with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
public VideoViewRecycler(Context context, AttributeSet attrs) {
    super(context, attrs);

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

    mContext = context;
}
 
Example 15
Source File: CaptureActivity.java    From vmqApk with MIT License 5 votes vote down vote up
@Override
    protected void onResume() {
        super.onResume();
        SurfaceView surfaceView = (SurfaceView) findViewById(R.id.scanner_view);
        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;

        //quit the scan view
//		cancelScanButton.setOnClickListener(new OnClickListener() {
//
//			@Override
//			public void onClick(View v) {
//				CaptureActivity.this.finish();
//			}
//		});
    }
 
Example 16
Source File: CaptureActivity.java    From BarcodeEye with Apache License 2.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    // CameraManager must be initialized here, not in onCreate(). This is necessary because we don't
    // want to open the camera driver and measure the screen size if we're going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the wrong size and partially
    // off screen.
    mCameraManager = new CameraManager(getApplication());
    mViewfinderView.setCameraManager(mCameraManager);

    mHandler = null;

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (mHasSurface) {
        // The activity was paused but not stopped, so the surface still exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the camera.
        surfaceHolder.addCallback(this);
    }

    mBeepManager.updatePrefs();
    mAmbientLightManager.start(mCameraManager);

    mInactivityTimer.onResume();
}
 
Example 17
Source File: SurfaceViewMediaRender.java    From android-jungle-mediaplayer with Apache License 2.0 4 votes vote down vote up
@Override
public void initRender() {
    SurfaceHolder holder = mSurfaceView.getHolder();
    holder.addCallback(this);
    mIsRenderValid = !holder.isCreating();
}
 
Example 18
Source File: CaptureActivity.java    From BarcodeScanner with Apache License 2.0 4 votes vote down vote up
@Override
protected void onResume() {
	super.onResume();

	// CameraManager must be initialized here, not in onCreate(). This is
	// necessary because we don't
	// want to open the camera driver and measure the screen size if we're
	// going to show the help on
	// first launch. That led to bugs where the scanning rectangle was the
	// wrong size and partially
	// off screen.

	// 相机初始化的动作需要开启相机并测量屏幕大小,这些操作
	// 不建议放到onCreate中,因为如果在onCreate中加上首次启动展示帮助信息的代码的 话,
	// 会导致扫描窗口的尺寸计算有误的bug
	cameraManager = new CameraManager(getApplication());

	viewfinderView = (ViewfinderView) findViewById(R.id.capture_viewfinder_view);
	viewfinderView.setCameraManager(cameraManager);

	handler = null;
	lastResult = null;

	// 摄像头预览功能必须借助SurfaceView,因此也需要在一开始对其进行初始化
	// 如果需要了解SurfaceView的原理
	// 参考:http://blog.csdn.net/luoshengyang/article/details/8661317
	SurfaceView surfaceView = (SurfaceView) findViewById(R.id.capture_preview_view); // 预览
	SurfaceHolder surfaceHolder = surfaceView.getHolder();
	if (hasSurface) {
		// The activity was paused but not stopped, so the surface still
		// exists. Therefore
		// surfaceCreated() won't be called, so init the camera here.
		initCamera(surfaceHolder);

	}
	else {
		// 防止sdk8的设备初始化预览异常
		surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

		// Install the callback and wait for surfaceCreated() to init the
		// camera.
		surfaceHolder.addCallback(this);
	}

	// 加载声音配置,其实在BeemManager的构造器中也会调用该方法,即在onCreate的时候会调用一次
	beepManager.updatePrefs();

	// 启动闪光灯调节器
	ambientLightManager.start(cameraManager);

	// 恢复活动监控器
	inactivityTimer.onResume();

	source = IntentSource.NONE;
	decodeFormats = null;
	characterSet = null;
}
 
Example 19
Source File: EglSurfaceView.java    From AudioVideoCodec with Apache License 2.0 4 votes vote down vote up
public EglSurfaceView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //获取surfaceHolder预览对象
    SurfaceHolder surfaceHolder = getHolder();
    surfaceHolder.addCallback(this);
}
 
Example 20
Source File: CaptureActivity.java    From AndroidWebServ with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onResume() {
    super.onResume();

    // CameraManager must be initialized here, not in onCreate(). This is necessary because we don't
    // want to open the camera driver and measure the screen size if we're going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the wrong size and partially
    // off screen.
    cameraManager = new CameraManager(getApplication());

    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);

    statusView = (TextView) findViewById(R.id.status_view);

    handler = null;

    resetStatusView();

    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the camera.
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    ambientLightManager.start(cameraManager);

    inactivityTimer.onResume();

    Intent intent = getIntent();

    decodeFormats = null;
    characterSet = null;

    if (intent != null) {

        String action = intent.getAction();

        if (Intents.Scan.ACTION.equals(action)) {

            // Scan the formats the intent requested, and return the result to the calling activity.
            decodeFormats = DecodeFormatManager.parseDecodeFormats(intent);
            decodeHints = DecodeHintManager.parseDecodeHints(intent);

            if (intent.hasExtra(Intents.Scan.WIDTH) && intent.hasExtra(Intents.Scan.HEIGHT)) {
                int width = intent.getIntExtra(Intents.Scan.WIDTH, 0);
                int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0);
                if (width > 0 && height > 0) {
                    cameraManager.setManualFramingRect(width, height);
                }
            }

            String customPromptMessage = intent.getStringExtra(Intents.Scan.PROMPT_MESSAGE);
            if (customPromptMessage != null) {
                statusView.setText(customPromptMessage);
            }

        }

        characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);

    }
}