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

The following are Jave code examples for showing how to use addCallback() of the android.view.SurfaceHolder class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: GitHub   File: CaptureActivity.java   Source Code and License Vote up 6 votes
@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;
}
 
Example 2
Project: LucaHome-MediaServer   File: GameView.java   Source Code and License Vote up 6 votes
public GameView(
        @NonNull Context context,
        @NonNull AttributeSet attributeSet) {
    super(context, attributeSet);

    _logger = new SmartMirrorLogger(TAG);
    _logger.Debug("GameView created...");

    _receiverController = new ReceiverController(context);

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

    _thread = new GameThread(holder);
}
 
Example 3
Project: BarcodeReaderView   File: BarcodeReaderView.java   Source Code and License Vote up 6 votes
/**
 * 启动相机预览与扫描,在Activity/Fragment的onResume方法中调用。
 */
public void onResume() {
    if (checkCameraHardware()) {
        mCameraManager = new CameraManager(this);
        if (frameWidth > 0 && frameHeight > 0) {
            mCameraManager.setManualFramingRect(frameWidth, frameHeight, frameTopOffset);
        }
        SurfaceHolder surfaceHolder = getHolder();
        if (hasSurface) {
            initCamera(surfaceHolder);
        } else {
            surfaceHolder.addCallback(this);
        }
    } else {
        if (mOnBarcodeReadListener != null) {
            mOnBarcodeReadListener.onCameraNotFound();
        }
    }
}
 
Example 4
Project: decoy   File: CaptureVideoActivity.java   Source Code and License Vote up 6 votes
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFormat(PixelFormat.TRANSLUCENT); // 使得窗口支持透明度
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.nim_capture_video_activity);
    setTitle(R.string.video_record);

    parseIntent();
    findViews();
    initActionBar();

    setViewsListener();
    updateRecordUI();

    getVideoPreviewSize();

    surfaceview = (SurfaceView) this.findViewById(R.id.videoView);
    SurfaceHolder holder = surfaceview.getHolder();
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    holder.addCallback(this);

    resizeSurfaceView();
}
 
Example 5
Project: EVideoRecorder   File: ERecorderActivity.java   Source Code and License Vote up 6 votes
@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加入回调接口
}
 
Example 6
Project: Exoplayer2Radio   File: SimpleExoPlayer.java   Source Code and License Vote up 5 votes
/**
 * Sets the {@link SurfaceHolder} that holds the {@link Surface} onto which video will be
 * rendered. The player will track the lifecycle of the surface automatically.
 *
 * @param surfaceHolder The surface holder.
 */
public void setVideoSurfaceHolder(SurfaceHolder surfaceHolder) {
  removeSurfaceCallbacks();
  this.surfaceHolder = surfaceHolder;
  if (surfaceHolder == null) {
    setVideoSurfaceInternal(null, false);
  } else {
    setVideoSurfaceInternal(surfaceHolder.getSurface(), false);
    surfaceHolder.addCallback(componentListener);
  }
}
 
Example 7
Project: libRtmp   File: LivingView.java   Source Code and License Vote up 5 votes
@SuppressWarnings("deprecation")
private void initRenderer() {
    mRenderer = new RendererImpl(mGLSurfaceView);
    mGLSurfaceView.setEGLContextClientVersion(2);
    mGLSurfaceView.setRenderer(mRenderer);
    mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    SurfaceHolder surfaceHolder = mGLSurfaceView.getHolder();
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    surfaceHolder.addCallback(mSurfaceHolderCallback);
}
 
Example 8
Project: WeiXinRecordedDemo   File: MediaRecorderBase.java   Source Code and License Vote up 5 votes
/**
 * 设置预览输出SurfaceHolder
 * @param sh
 */
@SuppressWarnings("deprecation")
public void setSurfaceHolder(SurfaceHolder sh) {
	if (sh != null) {
		sh.addCallback(this);
		if (!DeviceUtils.hasHoneycomb()) {
			sh.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
		}
	}
}
 
Example 9
Project: WeiXinRecordedDemo   File: MediaRecorderBase.java   Source Code and License Vote up 5 votes
/**
 * 设置预览输出SurfaceHolder
 * @param sh
 */
@SuppressWarnings("deprecation")
public void setSurfaceHolder(SurfaceHolder sh) {
	if (sh != null) {
		sh.addCallback(this);
		if (!DeviceUtils.hasHoneycomb()) {
			sh.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
		}
	}
}
 
Example 10
Project: stars-daydream-android   File: DreamView.java   Source Code and License Vote up 5 votes
public DreamView(Context context, AttributeSet attrs) {
    super(context, attrs);

    // Disable hardware acceleration so we can use BlurMaskFilter
    setLayerType(View.LAYER_TYPE_SOFTWARE, null);

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

    mRenderThread = new RenderThread(context, holder);
}
 
Example 11
Project: EvilsLive   File: MainActivity.java   Source Code and License Vote up 5 votes
@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 12
Project: SeafoodBerserker   File: MainFishView.java   Source Code and License Vote up 5 votes
private void init(Context context) {
    if (!this.isInEditMode()) {

        splats[0] = BitmapFactory.decodeResource(getResources(), R.drawable.splat1);
        splats[1] = BitmapFactory.decodeResource(getResources(), R.drawable.splat2);
        splats[2] = BitmapFactory.decodeResource(getResources(), R.drawable.splat2);
        anchor[0] = BitmapFactory.decodeResource(getResources(), R.drawable.anchor_sm);
        axes[0] = BitmapFactory.decodeResource(getResources(), R.drawable.axe2);
        bgs[0] = BitmapFactory.decodeResource(getResources(), R.drawable.sea);
        fgtops[0] = BitmapFactory.decodeResource(getResources(), R.drawable.sail);
        fgbottoms[0] = BitmapFactory.decodeResource(getResources(), R.drawable.shipside2);

        final SurfaceHolder holder = getHolder();
        holder.addCallback(this);
        TypedArray fish = getResources().obtainTypedArray(R.array.fish);
        int[] values = getResources().getIntArray(R.array.points);
        totalValue = 0;
        for (int i = 0; i < fish.length(); i++) {
            FlyingItem item = new FlyingItem(BitmapFactory.decodeResource(getResources(), fish.getResourceId(i, 0)));
            item.setValue(values[i]);
            availableItems.add(item);
            totalValue += (100 - values[i]);
        }
        fish.recycle();

        this.setOnTouchListener(this);
        mLinePaint = new Paint();
        mLinePaint.setARGB(255, 255, 64, 64);
        mLinePaint.setStrokeWidth(5);
        mBGPaint = new Paint();
        mBGPaint.setARGB(255, 127, 127, 200);

        mTextPaint = new Paint();
        mTextPaint.setColor(Color.BLACK);
        mTextPaint.setShadowLayer(8,8,8,Color.WHITE);
        mTextPaint.setTextSize(80);

    }
}
 
Example 13
Project: GCSApp   File: QrCodeActivity.java   Source Code and License Vote up 5 votes
@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;

}
 
Example 14
Project: NeoTerm   File: GLSurfaceView_SDL.java   Source Code and License Vote up 5 votes
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);
	holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
	mKeyguardManager = ((KeyguardManager)getContext().getSystemService(Context.KEYGUARD_SERVICE));
}
 
Example 15
Project: meipai-Android   File: MediaRecorderBase.java   Source Code and License Vote up 5 votes
/**
 * 设置预览输出SurfaceHolder
 * @param sh
 */
@SuppressWarnings("deprecation")
public void setSurfaceHolder(SurfaceHolder sh) {
	if (sh != null) {
		sh.addCallback(this);
		if (!DeviceUtils.hasHoneycomb()) {
			sh.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
		}
	}
}
 
Example 16
Project: buildAPKsApps   File: SeismoView.java   Source Code and License Vote up 5 votes
public SeismoView(Context ctx, int period) {
  super(ctx);

  SurfaceHolder holder = getHolder();
  holder.addCallback(this);
  setKeepScreenOn(true);
  ctx_ = ctx;
  period_ = period;
}
 
Example 17
Project: CameraPreview   File: PreviewView.java   Source Code and License Vote up 5 votes
private void init() {
    LayoutInflater.from(getContext()).inflate(R.layout.preview_layout, this);
    mPreviewView = findViewById(R.id.preview);
    // Install a SurfaceHolder.Callback so we get notified when the
    // underlying surface is created and destroyed.
    SurfaceHolder holder = mPreviewView.getHolder();
    holder.addCallback(new PreviewCallback());
    // deprecated setting, but required on Android versions prior to 3.0
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

}
 
Example 18
Project: AJCPlayer   File: VideoPlayerActivity.java   Source Code and License Vote up 5 votes
@Override
protected void onResume() {
    super.onResume();

    mChromeCast.resume();

    SurfaceHolder holder = mSurfaceView.getHolder();
    DisplayMetrics metrics = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    holder.setFixedSize(metrics.widthPixels, (int) ((float) metrics.widthPixels / (float) 16 / (float) 9));
    holder.addCallback(this);

    videoPlayer.onViewSizeChanged();
}
 
Example 19
Project: EZFilter   File: GLSurfaceView.java   Source Code and License Vote up 5 votes
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);
    // setFormat is done by SurfaceView in SDK 2.3 and newer. Uncomment
    // this statement if back-porting to 2.2 or older:
    // holder.setFormat(PixelFormat.RGB_565);
    //
    // setType is not needed for SDK 2.0 or newer. Uncomment this
    // statement if back-porting this code to older SDKs.
    // holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
}
 
Example 20
Project: CodeScaner   File: CaptureActivity.java   Source Code and License Vote up 4 votes
@Override
protected void onResume() {
    super.onResume();

    // historyManager must be initialized here to update the history preference

    // 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);

    handler = null;

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);

    beepManager.updatePrefs();
    ambientLightManager.start(cameraManager);

    inactivityTimer.onResume();

    decodeFormats = EnumSet.noneOf(BarcodeFormat.class);
    decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
    decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
    characterSet = null;

    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);
    }
}