AutoFocusCallback.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (C) 2010 ZXing authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.uas.equipment.camera;
  17. import android.hardware.Camera;
  18. import android.os.Handler;
  19. import android.os.Message;
  20. import android.util.Log;
  21. public final class AutoFocusCallback implements Camera.AutoFocusCallback {
  22. private static final String TAG = AutoFocusCallback.class.getSimpleName();
  23. private static final long AUTOFOCUS_INTERVAL_MS = 1500L;
  24. private Handler autoFocusHandler;
  25. private int autoFocusMessage;
  26. public void setHandler(Handler autoFocusHandler, int autoFocusMessage) {
  27. this.autoFocusHandler = autoFocusHandler;
  28. this.autoFocusMessage = autoFocusMessage;
  29. }
  30. public void onAutoFocus(boolean success, Camera camera) {
  31. if (autoFocusHandler != null) {
  32. Message message = autoFocusHandler.obtainMessage(autoFocusMessage, success);
  33. autoFocusHandler.sendMessageDelayed(message, AUTOFOCUS_INTERVAL_MS);
  34. autoFocusHandler = null;
  35. } else {
  36. Log.d(TAG, "Got auto-focus callback, but no handler for it");
  37. }
  38. }
  39. }