I am trying to have multiple buttons on my camera preview. The app has worked with a record button and a drop-down menu button. However, once I tried to add zoom buttons for the reticle, the app crashes. The code compiles but the app won't work. Can't seem to find a helpful answer anywhere else.
I have been maneuvering lines of code between onViewCreated(), onClick(), and onCreate() but I can't get the app to run.
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
if (null == savedInstanceState) {
getFragmentManager().beginTransaction()
.replace(R.id.container,Camera2VideoFragment.newInstance())
.commit();
}
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
mTextureView = view.findViewById(R.id.texture);
mButtonVideo = view.findViewById(R.id.video);
mZoomIn = view.findViewById(R.id.imageButton1);
mZoomOut = view.findViewById(R.id.imageButton2);
mButtonVideo.setOnClickListener(this);
mZoomIn.setOnClickListener(this);
mZoomOut.setOnClickListener(this);
view.findViewById(R.id.info).setOnClickListener(this);
view.findViewById(R.id.imageView1).setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.video: {
if (mIsRecordingVideo) {
stopRecordingVideo();
} else {
startRecordingVideo();
}
break;
}
case R.id.info: {
Activity activity = getActivity();
if (null != activity) {
new AlertDialog.Builder(activity)
.setMessage(R.string.intro_message)
.setPositiveButton(android.R.string.ok, null)
.show();
}
break;
}
case R.id.imageButton1: {
Activity activity = getActivity();
if (null != activity) {
ImageView img = view.findViewById(R.id.imageView1);
float x = img.getScaleX();
float y = img.getScaleY();
img.setScaleX(x + 2);
img.setScaleY(y + 2);
}
}
}
}
The code compiles but the app crashes. Logcat tells me the error is in the onViewCreated() with the setOnClickListeners(). The findViewById() is assigning null to the buttons but I can't figure out why.
I eventually want to make the zoom in/out buttons to zoom the video preview instead of the reticle. Any help with that would be great too. I also plan to make an adjustable brightness seekbar so help with that would be good too.