public void flipCamera(View view) { stopCamera(); camera.flip(); viewfinder.invalidate(); startCamera(); updateMenu(); }
private void layout() { Rect frame = camera.getFrame(viewfinder.getWidth(), viewfinder.getHeight()); if (frame == null) { return; } Log.i(TAG, "Frame = " + frame + ", " + viewfinder.getWidth()); ViewGroup.LayoutParams p = bottomView.getLayoutParams(); SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview); p.height = surfaceView.getHeight() - frame.bottom; p.width = frame.width(); bottomView.setLayoutParams(p); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && hasNavBar(this)) { // Don't draw over nav bar bottomView.setPadding(0, 0, 0, getNavBarHeight()); } bottomView.requestLayout(); viewfinder.invalidate(); }
@Override @SuppressWarnings("deprecation") public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(R.layout.activity_main); camera = new CameraController(this); detector = new MarkerDetector(camera, this, experience); viewfinder = (ViewfinderView) findViewById(R.id.viewfinder); viewfinder.setCamera(camera); viewfinder.addSizeChangedListener( new ViewfinderView.SizeChangedListener() { @Override public void sizeHasChanged() { layout(); } }); final SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview); holder = surfaceView.getHolder(); holder.addCallback(camera); // deprecated setting, but required on Android versions prior to 3.0 //noinspection deprecation holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); bottomView = (RelativeLayout) findViewById(R.id.bottomView); settingsMenuButton = findViewById(R.id.settingsMenuButton); settingsMenu = findViewById(R.id.settingsMenu); modeText = (TextView) findViewById(R.id.modeText); Log.i(TAG, "Intent onCreate: " + getIntent()); onNewIntent(getIntent()); }