title: Android Custom Camera Zoom Not Working
body: <p>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 is my code using SDK min 8 target 14:</p>
  
  <pre><code>@Override
          public void surfaceChanged(SurfaceHolder holder, int format, int width,
                  int height) {
              if (isPreviewing){ 
                  camera.stopPreview(); 
              }
  
              Camera.Parameters p = camera.getParameters();
              p.setPreviewSize(sizes.get(0).width, sizes.get(0).height);
              p.setColorEffect(effect); 
  
              zoomControls = (ZoomControls) findViewById(R.id.zoomControls);
  
              if (p.isZoomSupported()) {
                  maxZoomLevel = p.getMaxZoom();
                  Toast.makeText(PictureTaker.this, String.valueOf(maxZoomLevel),Toast.LENGTH_LONG).show();
                  zoomControls.setIsZoomInEnabled(true);
                  zoomControls.setIsZoomOutEnabled(true);
  
                  zoomControls.setOnZoomInClickListener(new OnClickListener() {
                      public void onClick(View v) {
                          if (currentZoomLevel &lt; maxZoomLevel) {
                              currentZoomLevel++;
                              camera.startSmoothZoom(currentZoomLevel);
                              //Toast.makeText(PictureTaker.this, String.valueOf(currentZoomLevel),Toast.LENGTH_LONG).show();
                          }
                      }
                  });
  
                  zoomControls.setOnZoomOutClickListener(new OnClickListener() {
                      public void onClick(View v) {
                          if (currentZoomLevel &gt; 0) {
                              currentZoomLevel--;
                              camera.startSmoothZoom(currentZoomLevel);
                          }
                      }
                  });
              } else {
                  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;
          }
  </code></pre>
  
  <p>The setColorEffect is coming from the options menu and works perfectly. I know isZoomSupported and getMaxZoom are working because the Toast displays a "59" when the code runs, but the zoom buttons do nothing. This is the zoomControl from the XML</p>
  
  <pre><code>&lt;ZoomControls
   android:id="@+id/zoomControls"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_alignParentBottom="true"
   android:layout_centerHorizontal="true"
   android:layout_marginBottom="17dp"
   android:baselineAligned="false"
   android:gravity="center_horizontal"
   android:orientation="horizontal" /&gt;
  </code></pre>
  
  <p>I have all the necessary permissions in the Manifest and no errors are showing in LogCat. Not sure what I'm doing wrong. I added a second Toast to report if the currentZoomLevel is being changed when the button is pressed and it shows the value getting incremented by one each time. I also tried not using startSmoothZoom and just setting the zoom with </p>
  
  <pre><code>p.setZoom(currentZoomLevel); or p.setZoomLevel(15); 
  </code></pre>
  
  <p>and neither one works either. My phone, HTC Incredible does have a perfectly working zoom on its native camera app. If I comment out the zoomControl parts of the code, everything works fine and all other features of the custom camera work fine even with the zoomControl code in there, it just doesn't zoom.</p>