I have seen several other questions on this subject but none seem to solve my problem. I have a custom camera app that is working fine, everything but the zoom buttons. this
Figured it out and maybe this can help some of the other people who have been having similar problems. It was the smoothzoom. Guess my HTC doesn't support this.
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
if (isPreviewing){
camera.stopPreview();
}
p = camera.getParameters();
p.setPreviewSize(sizes.get(0).width, sizes.get(0).height);
p.setColorEffect(effect);
if (p.isZoomSupported() && p.isSmoothZoomSupported()) {
//most phones
maxZoomLevel = p.getMaxZoom();
zoomControls.setIsZoomInEnabled(true);
zoomControls.setIsZoomOutEnabled(true);
zoomControls.setOnZoomInClickListener(new OnClickListener() {
public void onClick(View v) {
if (currentZoomLevel < maxZoomLevel) {
currentZoomLevel++;
camera.startSmoothZoom(currentZoomLevel);
}
}
});
zoomControls.setOnZoomOutClickListener(new OnClickListener() {
public void onClick(View v) {
if (currentZoomLevel > 0) {
currentZoomLevel--;
camera.startSmoothZoom(currentZoomLevel);
}
}
});
} else if (p.isZoomSupported() && !p.isSmoothZoomSupported()){
//stupid HTC phones
maxZoomLevel = p.getMaxZoom();
zoomControls.setIsZoomInEnabled(true);
zoomControls.setIsZoomOutEnabled(true);
zoomControls.setOnZoomInClickListener(new OnClickListener() {
public void onClick(View v) {
if (currentZoomLevel < maxZoomLevel) {
currentZoomLevel++;
p.setZoom(currentZoomLevel);
camera.setParameters(p);
}
}
});
zoomControls.setOnZoomOutClickListener(new OnClickListener() {
public void onClick(View v) {
if (currentZoomLevel > 0) {
currentZoomLevel--;
p.setZoom(currentZoomLevel);
camera.setParameters(p);
}
}
});
}else{
//no zoom on phone
zoomControls.setVisibility(View.GONE);
}
camera.setParameters(p);
try {
camera.setPreviewDisplay(holder);
} // end try
catch (IOException e) {
Log.v(TAG, e.toString());
} // end catch
camera.startPreview(); // begin the preview
isPreviewing = true;
} // end method surfaceChanged
This lets my HTC zoom in steps. The key was setting the camera's parameters after each button click. You could probably set the currentZoomLevel to any number you want, based on the maxZoomLevel, (my HTC is 59 but my Droid 4 is only 15), during the clicks of the ZoomControls to make the device zoom in and out faster. Might be a tidier way to code this, should probably put some checks in to make sure maxZoomSize doesn't return a NULL or something, but it's working on multiple devices.
Its simple forget about startSmoothZoom() method
follow this:
Camera.Parameters params = camera.getParameters();
params.setZoom(zoom_value);
camera.setParameters(params);
params.setZoom(currentZoomLevel); camera.setParameters(params); code also work at my Samsung G3 phone.