Skip to content

Commit

Permalink
自动调整界面防止拉伸
Browse files Browse the repository at this point in the history
  • Loading branch information
ailiwean committed Jun 30, 2019
1 parent a2c97f0 commit 37a4bd0
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 24 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@
- **光场值变化动态提醒是否需要打开手电筒**
- **手势操作双击或双指滑动拉近相机**
- **自动放大缩小二维码**
<<<<<<< HEAD
- **TextureView解决预览拉伸**
=======
- **TextureView避免预览拉伸**
>>>>>>> 22b77eacb43fc50134ed71b3418b565a60d09457

2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<com.wishzixing.lib.views.WishView
android:id="@+id/wishView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="500dp" />

</android.support.constraint.ConstraintLayout>
6 changes: 4 additions & 2 deletions lib/src/main/java/com/wishzixing/lib/able/AutoFocusAble.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class AutoFocusAble implements PixsValuesCus {

//上次广场强度根据不同的广场强度变换确定是否需要调焦
private int lastAcDark = 0;
private final HandlerThread handlerThread;

private void startAutoFocus() {
if (CameraConfig.getInstance().getAutoFocusModel() == AutoFocusConfig.TIME)
Expand Down Expand Up @@ -66,14 +67,16 @@ public void cusAction(byte[] data, Camera camera, int x, int y) {

@Override
public void stop() {
handlerThread.interrupt();
timeHandler.removeCallbacksAndMessages(null);
SensorManager.getInstance().stopListener();
}

private final long TIMEINTERVAL = 1500L;
private int model = 0;

private AutoFocusAble() {
HandlerThread handlerThread = new HandlerThread("time");
handlerThread = new HandlerThread("time");
handlerThread.start();
timeHandler = new Handler(handlerThread.getLooper());
}
Expand All @@ -97,7 +100,6 @@ private void setFocus() {
return;

Camera camera = CameraManager.get().getCamera();
camera.startPreview();
camera.autoFocus(AutoFocusCallback.getInstance());

}
Expand Down
5 changes: 2 additions & 3 deletions lib/src/main/java/com/wishzixing/lib/able/AutoZoomAble.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ public void cusAction(final byte[] data, final Camera camera, final int x, final
ZoomUtils.setZoom(ZoomUtils.getZoom() + ZoomUtils.getMaxZoom() / 20);
}

Log.e("len:" + len, "showRectLen/2:" + showRectLen / 2);

if (len > showRectLen / 2) {
ZoomUtils.setZoom(ZoomUtils.getZoom() - ZoomUtils.getMaxZoom() / 20);
}
Expand All @@ -90,7 +88,8 @@ public void cusAction(final byte[] data, final Camera camera, final int x, final

@Override
public void stop() {

handlerThread.interrupt();
handler.removeCallbacksAndMessages(null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void cusAction(final byte[] data, Camera camera, final int x, final int y

@Override
public void stop() {

scanResult.clear();
}

private DecodePixAble() {
Expand Down
11 changes: 7 additions & 4 deletions lib/src/main/java/com/wishzixing/lib/manager/CameraManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import android.content.Context;
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.util.Log;
import android.view.SurfaceHolder;

import com.wishzixing.lib.config.CameraConfig;
import com.wishzixing.lib.config.Config;
import com.wishzixing.lib.listener.AutoFocusCallback;
import com.wishzixing.lib.listener.PreviewCallback;

Expand Down Expand Up @@ -120,6 +120,9 @@ public void openDriver(SurfaceHolder holder) {
FlashlightManager.enableFlashlight();
this.showType = ShowType.SurfaceView;
}

Config.useDefault();
initCamera();
}

public void openDriver(SurfaceTexture surfaceTexture) {
Expand All @@ -145,6 +148,8 @@ public void openDriver(SurfaceTexture surfaceTexture) {
this.showType = ShowType.TextureView;
}

Config.useDefault();
initCamera();
}

/**
Expand Down Expand Up @@ -175,21 +180,19 @@ public void startPreview() {
}

public void initCamera() {

if (camera == null)
return;

parameters = camera.getParameters();
parameters.set("flash-value", 10);
parameters.set("flash-mode", "off");
parameters.set("zoom", "1");
parameters.set("taking-picture-zoom", CameraConfig.getInstance().getTenDesiredZoom());
parameters.setPreviewSize(CameraConfig.getInstance().getCameraPoint().x, CameraConfig.getInstance().getCameraPoint().y);
Log.e("X:" + CameraConfig.getInstance().getCameraPoint().x, "Y:" + CameraConfig.getInstance().getCameraPoint().y);
camera.setDisplayOrientation(90);
camera.setParameters(parameters);
startPreview();
requestPreviewFrame();
camera.autoFocus(AutoFocusCallback.getInstance());
}

public ShowType getShowType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,12 @@ public void run() {

}

public void stop() {

for (PixsValuesCus cus : actionList) {
cus.stop();
}

}

}
18 changes: 16 additions & 2 deletions lib/src/main/java/com/wishzixing/lib/util/RxBeepUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,23 @@ public static void playBeep() {
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
file.close();
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
mediaPlayer.prepare();
mediaPlayer.start();
mediaPlayer.prepareAsync();
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mediaPlayer.start();
}
});
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer = null;
}
});
} catch (IOException e) {
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer = null;
}
Expand Down
19 changes: 19 additions & 0 deletions lib/src/main/java/com/wishzixing/lib/views/WishView.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public void onCreate(Activity activity) {
initView();
initDefDelegate();
initConfig();
initAccelerated();
wishViewDelegate.onCreate(activity);
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
// activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
Expand All @@ -233,6 +234,23 @@ public void run() {
});
}

//启用硬件加速
private void initAccelerated() {

get.get().getWindow().setFlags(
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);

if (surfaceView != null)
if (surfaceView.isHardwareAccelerated())
surfaceView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

if (textureView != null)
if (textureView.isHardwareAccelerated())
textureView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

}

private void requestPermission() {

if (PermissionUtils.hasPermission(get.get()))
Expand All @@ -251,6 +269,7 @@ public void onReceive(Context context, Intent intent) {
get.get().unregisterReceiver(this);
}
}, intentFilter);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.wishzixing.lib.WishLife;
import com.wishzixing.lib.config.AutoFocusConfig;
import com.wishzixing.lib.config.CameraConfig;
import com.wishzixing.lib.config.Config;
import com.wishzixing.lib.config.ParseRectConfig;
import com.wishzixing.lib.config.PointConfig;
import com.wishzixing.lib.config.ScanConfig;
Expand Down Expand Up @@ -139,7 +138,6 @@ public void onSurfaceTextureUpdated(SurfaceTexture surface) {
}
});
hasTexture = true;

}


Expand Down Expand Up @@ -211,16 +209,13 @@ public void refreshCamera() {
if (textureView != null)
CameraManager.get().openDriver(textureView.getSurfaceTexture());

Config.useDefault();

if (surfaceListener != null)
surfaceListener.onCreate();

CameraManager.get().initCamera();
}

@Override
public void onDestory() {
PixsValuesCusManager.getInstance().stop();
inactivityTimer.shutdown();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/res/layout/activity_scaner_code.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
android:id="@+id/capture_crop_layout"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:background="@drawable/capture"
android:contentDescription="@string/app_name">

Expand Down

0 comments on commit 37a4bd0

Please sign in to comment.