支持缩放变焦
This commit is contained in:
@@ -178,7 +178,11 @@ public class CaptureActivity extends Activity implements SurfaceHolder.Callback
|
||||
handler = null;
|
||||
lastResult = null;
|
||||
|
||||
setRequestedOrientation(getCurrentOrientation());
|
||||
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
} else {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||
}
|
||||
|
||||
resetStatusView();
|
||||
|
||||
@@ -270,26 +274,26 @@ public class CaptureActivity extends Activity implements SurfaceHolder.Callback
|
||||
}
|
||||
}
|
||||
|
||||
private int getCurrentOrientation() {
|
||||
int rotation = getWindowManager().getDefaultDisplay().getRotation();
|
||||
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
switch (rotation) {
|
||||
case Surface.ROTATION_0:
|
||||
case Surface.ROTATION_90:
|
||||
return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
|
||||
default:
|
||||
return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
|
||||
}
|
||||
} else {
|
||||
switch (rotation) {
|
||||
case Surface.ROTATION_0:
|
||||
case Surface.ROTATION_270:
|
||||
return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
default:
|
||||
return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
// private int getCurrentOrientation() {
|
||||
// int rotation = getWindowManager().getDefaultDisplay().getRotation();
|
||||
// if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
// switch (rotation) {
|
||||
// case Surface.ROTATION_0:
|
||||
// case Surface.ROTATION_90:
|
||||
// return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
|
||||
// default:
|
||||
// return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
|
||||
// }
|
||||
// } else {
|
||||
// switch (rotation) {
|
||||
// case Surface.ROTATION_0:
|
||||
// case Surface.ROTATION_270:
|
||||
// return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
|
||||
// default:
|
||||
// return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private static boolean isZXingURL(String dataString) {
|
||||
if (dataString == null) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.os.AsyncTask;
|
||||
import android.os.BatteryManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
|
||||
/**
|
||||
@@ -44,14 +45,14 @@ final class InactivityTimer {
|
||||
|
||||
InactivityTimer(Activity activity) {
|
||||
this.activity = activity;
|
||||
powerStatusReceiver = new PowerStatusReceiver();
|
||||
powerStatusReceiver = new PowerStatusReceiver(this);
|
||||
registered = false;
|
||||
onActivity();
|
||||
}
|
||||
|
||||
synchronized void onActivity() {
|
||||
cancel();
|
||||
inactivityTask = new InactivityAsyncTask();
|
||||
inactivityTask = new InactivityAsyncTask(activity);
|
||||
try {
|
||||
inactivityTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} catch (RejectedExecutionException ree) {
|
||||
@@ -91,28 +92,49 @@ final class InactivityTimer {
|
||||
cancel();
|
||||
}
|
||||
|
||||
private final class PowerStatusReceiver extends BroadcastReceiver {
|
||||
private static class PowerStatusReceiver extends BroadcastReceiver {
|
||||
|
||||
private WeakReference<InactivityTimer> weakReference;
|
||||
|
||||
public PowerStatusReceiver(InactivityTimer inactivityTimer){
|
||||
weakReference = new WeakReference<>(inactivityTimer);
|
||||
}
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
|
||||
// 0 indicates that we're on battery
|
||||
boolean onBatteryNow = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) <= 0;
|
||||
if (onBatteryNow) {
|
||||
InactivityTimer.this.onActivity();
|
||||
} else {
|
||||
InactivityTimer.this.cancel();
|
||||
|
||||
InactivityTimer inactivityTimer = weakReference.get();
|
||||
if(inactivityTimer!=null){
|
||||
boolean onBatteryNow = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) <= 0;
|
||||
if (onBatteryNow) {
|
||||
inactivityTimer.onActivity();
|
||||
} else {
|
||||
inactivityTimer.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class InactivityAsyncTask extends AsyncTask<Object,Object,Object> {
|
||||
private static class InactivityAsyncTask extends AsyncTask<Object,Object,Object> {
|
||||
|
||||
private WeakReference<Activity> weakReference;
|
||||
|
||||
public InactivityAsyncTask(Activity activity){
|
||||
weakReference = new WeakReference<>(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doInBackground(Object... objects) {
|
||||
try {
|
||||
Thread.sleep(INACTIVITY_DELAY_MS);
|
||||
Log.i(TAG, "Finishing activity due to inactivity");
|
||||
activity.finish();
|
||||
Activity activity = weakReference.get();
|
||||
if(activity!=null){
|
||||
activity.finish();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// continue without killing
|
||||
}
|
||||
|
||||
@@ -132,6 +132,8 @@ public final class ViewfinderView extends View {
|
||||
textPadding = array.getDimension(R.styleable.ViewfinderView_textPadding,TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,24,getResources().getDisplayMetrics()));
|
||||
textLocation = TextLocation.getFromInt(array.getInt(R.styleable.ViewfinderView_textLocation,0));
|
||||
|
||||
array.recycle();
|
||||
|
||||
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
|
||||
scannerAlpha = 0;
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.os.AsyncTask;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
@@ -66,7 +67,7 @@ final class AutoFocusManager implements Camera.AutoFocusCallback {
|
||||
|
||||
private synchronized void autoFocusAgainLater() {
|
||||
if (!stopped && outstandingTask == null) {
|
||||
AutoFocusTask newTask = new AutoFocusTask();
|
||||
AutoFocusTask newTask = new AutoFocusTask(this);
|
||||
try {
|
||||
newTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
outstandingTask = newTask;
|
||||
@@ -116,7 +117,14 @@ final class AutoFocusManager implements Camera.AutoFocusCallback {
|
||||
}
|
||||
}
|
||||
|
||||
private final class AutoFocusTask extends AsyncTask<Object,Object,Object> {
|
||||
private static class AutoFocusTask extends AsyncTask<Object,Object,Object> {
|
||||
|
||||
private WeakReference<AutoFocusManager> weakReference;
|
||||
|
||||
public AutoFocusTask(AutoFocusManager manager){
|
||||
weakReference = new WeakReference<>(manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object doInBackground(Object... voids) {
|
||||
try {
|
||||
@@ -124,7 +132,10 @@ final class AutoFocusManager implements Camera.AutoFocusCallback {
|
||||
} catch (InterruptedException e) {
|
||||
// continue
|
||||
}
|
||||
start();
|
||||
AutoFocusManager manager = weakReference.get();
|
||||
if(manager!=null){
|
||||
manager.start();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user