forked from finally-vince/ZXingMini
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
YooJia.Chen
committed
Nov 20, 2015
1 parent
12983b9
commit cf20b34
Showing
9 changed files
with
116 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 3 additions & 9 deletions
12
zxing/src/main/java/com/github/yoojia/zxing/camera/AutoFocusListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,8 @@ | ||
package com.github.yoojia.zxing.camera; | ||
|
||
/** | ||
* @author : Yoojia.Chen (yoojiachen@163.com) | ||
* 自动聚焦回调接口 | ||
* @author YOOJIA.CHEN (yoojiachen@gmail.com) | ||
*/ | ||
public interface AutoFocusListener { | ||
|
||
/** | ||
* 聚集完成时此接口被回调 | ||
* @param focusSuccess 是否聚集成功 | ||
*/ | ||
void onFocus(boolean focusSuccess); | ||
@Deprecated | ||
public interface AutoFocusListener extends FocusEventsListener{ | ||
} |
72 changes: 4 additions & 68 deletions
72
zxing/src/main/java/com/github/yoojia/zxing/camera/AutoFocusManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,11 @@ | ||
package com.github.yoojia.zxing.camera; | ||
|
||
import android.hardware.Camera; | ||
import android.os.Handler; | ||
import android.os.Looper; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
@Deprecated | ||
public class AutoFocusManager extends FocusManager{ | ||
|
||
/** | ||
* @author 陈小锅 (yoojia.chen@gmail.com) | ||
* @since 1.0 | ||
*/ | ||
public class AutoFocusManager implements Camera.AutoFocusCallback{ | ||
|
||
private final Camera mCamera; | ||
private final AutoFocusListener mAutoFocusListener; | ||
private final boolean mAutoFocusEnabled; | ||
|
||
private final AtomicInteger mPeriod = new AtomicInteger(0); | ||
|
||
private final Handler mFocusHandler = new Handler(Looper.getMainLooper()); | ||
|
||
private final Runnable mFocusTask = new Runnable() { | ||
@Override | ||
public void run() { | ||
requestAutoFocus(); | ||
final int period = mPeriod.get(); | ||
if (period > 0) { | ||
repeatAutoFocus(period); | ||
} | ||
} | ||
}; | ||
|
||
public AutoFocusManager(Camera camera, AutoFocusListener autoFocusListener) { | ||
mCamera = camera; | ||
mAutoFocusListener = autoFocusListener; | ||
final String mode = camera.getParameters().getFocusMode(); | ||
if (Camera.Parameters.FOCUS_MODE_AUTO.equals(mode) || Camera.Parameters.FOCUS_MODE_MACRO.equals(mode)){ | ||
mAutoFocusEnabled = true; | ||
}else{ | ||
mAutoFocusEnabled = false; | ||
} | ||
} | ||
|
||
@Override | ||
public void onAutoFocus(boolean success, Camera camera) { | ||
mAutoFocusListener.onFocus(success); | ||
} | ||
|
||
public void requestAutoFocus(){ | ||
mCamera.autoFocus(this); | ||
} | ||
|
||
public void startAutoFocus(int ms){ | ||
if (ms < 100) { | ||
throw new IllegalArgumentException("Auto Focus period time must more than 100ms !"); | ||
} | ||
if( ! mAutoFocusEnabled) { | ||
return; | ||
} | ||
mFocusHandler.removeCallbacks(mFocusTask); | ||
mPeriod.set(ms); | ||
mFocusHandler.post(mFocusTask); | ||
} | ||
|
||
private void repeatAutoFocus(int period){ | ||
mFocusHandler.postDelayed(mFocusTask, period); | ||
} | ||
|
||
public void stopAutoFocus(){ | ||
mPeriod.set(0); | ||
mFocusHandler.removeCallbacks(mFocusTask); | ||
public AutoFocusManager(Camera camera, FocusEventsListener focusEventsListener) { | ||
super(camera, focusEventsListener); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
zxing/src/main/java/com/github/yoojia/zxing/camera/FocusEventsListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.github.yoojia.zxing.camera; | ||
|
||
/** | ||
* 自动聚焦回调接口 | ||
* @author : YOOJIA.CHEN (yoojiachen@gmail.com) | ||
*/ | ||
public interface FocusEventsListener { | ||
|
||
/** | ||
* 聚集完成时此接口被回调 | ||
* @param focusSuccess 是否聚集成功 | ||
*/ | ||
void onFocus(boolean focusSuccess); | ||
} |
77 changes: 77 additions & 0 deletions
77
zxing/src/main/java/com/github/yoojia/zxing/camera/FocusManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.github.yoojia.zxing.camera; | ||
|
||
import android.hardware.Camera; | ||
import android.os.Handler; | ||
import android.os.Looper; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
/** | ||
* @author 陈小锅 (yoojia.chen@gmail.com) | ||
* @since 1.0 | ||
*/ | ||
public class FocusManager { | ||
|
||
private final Camera mCamera; | ||
private final FocusEventsListener mFocusEventsListener; | ||
private final boolean mAutoFocusEnabled; | ||
|
||
private final AtomicInteger mPeriod = new AtomicInteger(0); | ||
|
||
private final Handler mFocusHandler = new Handler(Looper.getMainLooper()); | ||
|
||
private final Runnable mFocusTask = new Runnable() { | ||
@Override | ||
public void run() { | ||
requestAutoFocus(); | ||
final int period = mPeriod.get(); | ||
if (period > 0) { | ||
repeatAutoFocus(period); | ||
} | ||
} | ||
}; | ||
|
||
private final Camera.AutoFocusCallback mAutoFocusCallback = new Camera.AutoFocusCallback() { | ||
@Override | ||
public void onAutoFocus(boolean success, Camera camera) { | ||
mFocusEventsListener.onFocus(success); | ||
} | ||
}; | ||
|
||
public FocusManager(Camera camera, FocusEventsListener focusEventsListener) { | ||
mCamera = camera; | ||
mFocusEventsListener = focusEventsListener; | ||
final String mode = camera.getParameters().getFocusMode(); | ||
if (Camera.Parameters.FOCUS_MODE_AUTO.equals(mode) || Camera.Parameters.FOCUS_MODE_MACRO.equals(mode)){ | ||
mAutoFocusEnabled = true; | ||
}else{ | ||
mAutoFocusEnabled = false; | ||
} | ||
} | ||
|
||
public void requestAutoFocus(){ | ||
mCamera.autoFocus(mAutoFocusCallback); | ||
} | ||
|
||
public void startAutoFocus(int ms){ | ||
if (ms < 100) { | ||
throw new IllegalArgumentException("Auto Focus period time must more than 100ms !"); | ||
} | ||
if( ! mAutoFocusEnabled) { | ||
return; | ||
} | ||
mFocusHandler.removeCallbacks(mFocusTask); | ||
mPeriod.set(ms); | ||
mFocusHandler.post(mFocusTask); | ||
} | ||
|
||
private void repeatAutoFocus(int period){ | ||
mFocusHandler.postDelayed(mFocusTask, period); | ||
} | ||
|
||
public void stopAutoFocus(){ | ||
mPeriod.set(0); | ||
mFocusHandler.removeCallbacks(mFocusTask); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters