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