Skip to content

Commit

Permalink
代码优化,减少页面requestLayout速度
Browse files Browse the repository at this point in the history
  • Loading branch information
ailiwean committed Oct 18, 2020
1 parent 9c5899c commit 7fb5225
Show file tree
Hide file tree
Showing 34 changed files with 378 additions and 244 deletions.
6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ android {
defaultConfig {
applicationId "com.android.NBZxing"
minSdkVersion 17
targetSdkVersion 29
versionCode 15
versionName "1.15"
targetSdkVersion 27
versionCode 17
versionName "1.21"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.release
compileOptions {
Expand Down Expand Up @@ -46,6 +46,7 @@ dependencies {
api "androidx.appcompat:appcompat:1.1.0"
implementation 'com.zhihu.android:matisse:0.5.3-beta3'
api "com.github.bumptech.glide:glide:4.11.0"
api 'com.tencent.bugly:crashreport:3.2.3'
//
// implementation 'com.github.ailiwean:NBZxing-Scale:0.0.3'
// implementation 'com.github.ailiwean:NBZxing:0.0.25'
Expand Down
4 changes: 3 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
-keep public class com.ailiwean.module_grayscale.GrayScaleDispatch
-keep public class com.ailiwean.module_grayscale.GrayScaleDispatch
-dontwarn com.tencent.bugly.**
-keep public class com.tencent.bugly.**{*;}
16 changes: 15 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,36 @@

<uses-permission android:name="android.permission.CAMERA" />

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_LOGS" />

<!-- 可选-->
<uses-permission
android:name="android.permission.READ_LOGS"
tools:ignore="ProtectedPermissions" /> <!-- 获取logcat日志 -->

<application
android:name=".App"
android:allowBackup="true"
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:roundIcon="@drawable/app_icon"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.NoActionBar"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">

<activity android:name=".MainActivity">
<activity android:name=".MainActiviy">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".ScanActivity" />

</application>

Expand Down
22 changes: 22 additions & 0 deletions app/src/main/java/com/android/NBZxing/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.android.NBZxing;

import android.app.Application;

import com.tencent.bugly.crashreport.CrashReport;


/**
* @Package: com.android.NBZxing
* @ClassName: App
* @Description:
* @Author: SWY
* @CreateDate: 2020/10/1 9:22 PM
*/
public class App extends Application {

@Override
public void onCreate() {
super.onCreate();
CrashReport.initCrashReport(getApplicationContext(), "99de934384", true);
}
}
4 changes: 0 additions & 4 deletions app/src/main/java/com/android/NBZxing/CusScanView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ import com.google.android.cameraview.AspectRatio
*/
class CusScanView @JvmOverloads constructor(context: Context, attributeSet: AttributeSet? = null, def: Int = 0) : NBZxingView(context, attributeSet, def) {

init {
setAspectRatio(AspectRatio.of(16, 9))
}

override fun resultBack(content: String) {
Toast.makeText(context, content, Toast.LENGTH_SHORT).show()
}
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/com/android/NBZxing/MainActiviy.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.android.NBZxing

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity

/**
* @Package: com.android.NBZxing
* @ClassName: MainActiviy
* @Description:
* @Author: SWY
* @CreateDate: 2020/10/18 7:26 PM
*/
class MainActiviy : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_select)
}

fun toClick(view: View) {
ScanActivity.startSelf(this)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,33 @@ package com.android.NBZxing

import android.Manifest
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.pm.ActivityInfo
import android.content.pm.PackageManager
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.Window
import android.view.WindowManager
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.zhihu.matisse.Matisse
import com.zhihu.matisse.MimeType
import com.zhihu.matisse.engine.impl.GlideEngine

class MainActivity : AppCompatActivity() {
class ScanActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// requestWindowFeature(Window.FEATURE_NO_TITLE)
// window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
// WindowManager.LayoutParams.FLAG_FULLSCREEN);
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
// WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
// }
setContentView(R.layout.activity_main)
findViewById<CusScanView>(R.id.zxingview)
.synchLifeStart(this)
Expand All @@ -28,10 +39,13 @@ class MainActivity : AppCompatActivity() {
// .commit();
}

fun initView() {
companion object {
fun startSelf(context: Context) {
context.startActivity(Intent(context, ScanActivity::class.java))
}
}

findViewById<View>(R.id.vToolBar)
.setBackgroundColor(Color.parseColor("#2f000000"))
fun initView() {

findViewById<TextView>(R.id.vTitle).text = "扫一扫"

Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@

<include layout="@layout/tool_title" />


</FrameLayout>
17 changes: 17 additions & 0 deletions app/src/main/res/layout/activity_select.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:ignore="MissingDefaultResource">


<Button
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="toClick"
android:text="扫码" />

</FrameLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/tool_title.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/vToolBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
tools:ignore="ResourceName">

Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ allprojects {
google()
jcenter()
maven { url 'https://jitpack.io' }
maven { url "https://raw.githubusercontent.com/Pgyer/mvn_repo_pgyer/master" }
}
}

Expand Down
4 changes: 0 additions & 4 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#Thu Apr 30 15:56:24 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
<<<<<<< HEAD
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-bin.zip
=======
>>>>>>> backTexture
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ boolean isReady() {
void configureTransform() {
Matrix matrix = new Matrix();

if (Utils.getContext().getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_LANDSCAPE && mDisplayOrientation == 0)
if (Utils.INSTANCE.getContext() != null &&
Utils.INSTANCE.getContext().getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_LANDSCAPE && mDisplayOrientation == 0)
mDisplayOrientation = Config.displayOrientation;

if (mDisplayOrientation % 180 == 90) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,12 @@ public void onDisconnected(@NonNull CameraDevice camera) {

@Override
public void onError(@NonNull CameraDevice camera, int error) {
restart();
mCamera = null;
restart();
}

};

boolean isTrue;

private final CameraCaptureSession.StateCallback mSessionCallback
= new CameraCaptureSession.StateCallback() {

Expand Down Expand Up @@ -217,7 +215,6 @@ public void updatePreView(PreviewImpl preview) {
@Override
boolean start() {
synchronized (Camera2.class) {

if (isCameraOpened())
return true;

Expand Down Expand Up @@ -391,7 +388,6 @@ void setZoom(float percent) {
try {
Rect showRect = CameraHelper.getZoomRect(mCameraCharacteristics, percent);
mPreviewRequestBuilder.set(CaptureRequest.SCALER_CROP_REGION, showRect);
mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback, null);
rectMeteringWithFocus(showRect);
} catch (Exception e) {
restart();
Expand Down Expand Up @@ -500,7 +496,7 @@ private boolean collectCameraInfo() {
}

if (!mPreviewSizes.ratios().contains(mAspectRatio)) {
//扫码没有16:9则取4:3
//扫码没有设置的则取4:3
mAspectRatio = Constants.DEFAULT_ASPECT_RATIO;
//没有4:3则取最接近的
if (!mPreviewSizes.ratios().contains(mAspectRatio)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ interface Callback {

private Callback mCallback;

private int mWidth;
private volatile int mWidth;

private int mHeight;
private volatile int mHeight;

void setCallback(Callback callback) {
mCallback = callback;
Expand Down Expand Up @@ -86,7 +86,11 @@ void setSize(int width, int height) {
getView().setTranslationX((float) -(width - v.getMeasuredWidth()) / 2);
if (height > v.getMeasuredHeight())
getView().setTranslationY((float) -(height - v.getMeasuredHeight()) / 2);
cameraHandler.getLooper().getThread().interrupt();

if (cameraHandler != null &&
cameraHandler.getLooper().getThread().getState() == Thread.State.TIMED_WAITING)
cameraHandler.getLooper().getThread().interrupt();

}

int getWidth() {
Expand All @@ -98,10 +102,12 @@ int getHeight() {
}

/***
* 当相机测量出的不支持设定的, 则提供一个支持的参数
* 同步比例
* @param aspectRatio
*/
public void updateAspectRatio(AspectRatio aspectRatio) {
mWidth = 0;
mHeight = 0;
if (getView().getParent() instanceof CameraView) {
((CameraView) getView().getParent()).setAspectRatio(aspectRatio);
}
Expand Down
Loading

0 comments on commit 7fb5225

Please sign in to comment.