Skip to content

Commit

Permalink
Merge pull request #28 from kadbbz/dev-1.18
Browse files Browse the repository at this point in the history
Dev 1.18
  • Loading branch information
kadbbz authored Aug 2, 2024
2 parents 998c548 + 5b6dedb commit 5233ecd
Show file tree
Hide file tree
Showing 60 changed files with 386 additions and 38 deletions.
6 changes: 5 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ android {
//noinspection ExpiredTargetSdkVersion
targetSdk 29 // 超过29后,文件权限要大改
versionCode 4
versionName '1.18.3-release'
versionName '1.18.4-release'
manifestPlaceholders = [
JPUSH_PKGNAME : applicationId,
JPUSH_APPKEY : "599fe3f0f0f55d42155fae05", //JPush上注册的包名对应的Appkey,与包名相关,如果修改package name,需要自行注册极光推送账号,并修改这个选项
JPUSH_CHANNEL : "developer-default"
]

defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}

buildTypes {
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

34 changes: 24 additions & 10 deletions app/src/main/java/com/huozige/lab/container/BaseActivity.java
Original file line number Diff line number Diff line change
@@ -1,48 +1,62 @@
package com.huozige.lab.container;

import android.graphics.drawable.ColorDrawable;
import android.graphics.Color;
import android.view.Window;
import android.view.WindowManager;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.huozige.lab.container.utilities.ColorUtility;
import com.huozige.lab.container.utilities.ConfigManager;

/**
* HAC所有页面的基类,提供权限申请、操作栏颜色配置等功能
*/
public class BaseActivity extends AppCompatActivity {

public BaseActivity(){
public BaseActivity() {
super();
}

/**
* 刷新操作栏颜色
*/
public void refreshActionBar(){
public void refreshActionBar() {

// 需要支持跨线程调用
this.runOnUiThread(() -> {

// 设置动作栏
ActionBar actionBar = getSupportActionBar();

if(actionBar!=null){
if(!ConfigManager.getInstance().getActionBarVisible()){
if (actionBar != null) {
if (!ConfigManager.getInstance().getActionBarVisible()) {
// 隐藏ActionBar
actionBar.hide();
}else{

// 设置ActionBar的颜色
actionBar.setBackgroundDrawable(new ColorDrawable(ConfigManager.getInstance().getTCD()));
} else {

// 设置状态栏颜色,做沉浸式体验
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(ConfigManager.getInstance().getTCD());

// 设置ActionBar的颜色,需要避免文字和背景颜色过于接近
Toolbar aBar = findViewById(androidx.appcompat.R.id.action_bar);

if (aBar != null) {

aBar.setBackgroundColor(ConfigManager.getInstance().getTCD());
// 深色采用黑色文字,浅色用白色文字
if (ColorUtility.getGrayScale(ConfigManager.getInstance().getTCD()) > ColorUtility.GRAYSCALE_THRESHOLD_BRIGHT_COLOR) {
aBar.setTitleTextColor(Color.BLACK);
} else {
aBar.setTitleTextColor(Color.WHITE);
}

}
}
}

Expand All @@ -54,7 +68,7 @@ public void refreshActionBar(){
* 每次恢复时,都需要重设颜色
*/
@Override
public void onResume() {
protected void onResume() {
super.onResume();

refreshActionBar();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.huozige.lab.container;

import androidx.appcompat.app.ActionBar;
import android.app.Activity;
import android.content.Intent;

Expand Down Expand Up @@ -30,6 +31,15 @@ public class HACQRCodeScanActivity extends BarcodeCameraScanActivity {
*/
public static final String EXTRA_QR_CODE_HINTS = "qr";

@Override
protected void onResume(){
super.onResume();

// 强制隐藏标题栏
ActionBar aBar = getSupportActionBar();
if(aBar!=null) aBar.hide();
}

@Override
public void initCameraScan(@NonNull CameraScan<Result> cameraScan) {
super.initCameraScan(cameraScan);
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/com/huozige/lab/container/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
Expand All @@ -12,6 +14,7 @@
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;

import com.elvishew.xlog.XLog;
import com.hjq.permissions.Permission;
Expand All @@ -21,6 +24,7 @@
import com.huozige.lab.container.platform.hzg.HZGWebInterop;
import com.huozige.lab.container.proxy.AbstractProxy;
import com.huozige.lab.container.proxy.ProxyRegister;
import com.huozige.lab.container.utilities.ColorUtility;
import com.huozige.lab.container.utilities.ConfigManager;
import com.huozige.lab.container.utilities.DeviceUtilities;
import com.huozige.lab.container.utilities.PermissionsUtility;
Expand Down Expand Up @@ -242,6 +246,23 @@ public boolean onCreateOptionsMenu(Menu menu) {

// 你可以在这里创建新的菜单

// 设置ActionBar的图标颜色,避免文字和背景颜色过于接近
Toolbar aBar = findViewById(androidx.appcompat.R.id.action_bar);

if (aBar != null) {
Drawable oriIcon = aBar.getOverflowIcon();
// 深色采用黑色文字,浅色用白色文字
if (ColorUtility.getGrayScale(ConfigManager.getInstance().getTCD()) > ColorUtility.GRAYSCALE_THRESHOLD_BRIGHT_COLOR) {
if (oriIcon != null) {
aBar.setOverflowIcon(ColorUtility.resetImageTintColorTo(oriIcon, Color.BLACK));
}
} else {
if (oriIcon != null) {
aBar.setOverflowIcon(ColorUtility.resetImageTintColorTo(oriIcon, Color.WHITE));
}
}
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class HZGCacheFilter extends AbstractStaticFilesCacheFilter {
final static String[] SUPPORTED_VERSIONS = {
"9.0.6.0", // 9.0
"9.0.103.0",// 9.1
"10.0.2.0",}; // 10.0
"10.0.3.0",}; // 10.0

/**
* 执行缓存检查
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.huozige.lab.container.proxy.support;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

public class BaseActivityNoActionBar extends AppCompatActivity {

@Override
protected void onResume(){
super.onResume();
ActionBar aBar = getSupportActionBar();
if (aBar != null) aBar.hide();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.elvishew.xlog.XLog;
import com.hjq.permissions.Permission;
import com.huozige.lab.container.R;
import com.huozige.lab.container.proxy.support.BaseActivityNoActionBar;
import com.huozige.lab.container.utilities.DeviceUtilities;
import com.huozige.lab.container.utilities.PermissionsUtility;
import com.otaliastudios.cameraview.CameraListener;
Expand All @@ -28,7 +28,7 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class CameraViewActivity extends AppCompatActivity {
public class CameraViewActivity extends BaseActivityNoActionBar {

public static final String EXTRA_OPERATION = "op";
public static final String OPERATION_TAKE_PHOTO = "photo";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
import android.widget.ProgressBar;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.elvishew.xlog.XLog;
import com.github.barteksc.pdfviewer.PDFView;
import com.huozige.lab.container.BaseActivity;
import com.huozige.lab.container.R;
import com.huozige.lab.container.utilities.DeviceUtilities;
import com.huozige.lab.container.utilities.HACDownloadManager;
Expand All @@ -25,7 +24,7 @@
/**
* 下载并预览PDF的页面
*/
public class PDFPreviewActivity extends AppCompatActivity {
public class PDFPreviewActivity extends BaseActivity {

private String _url, _password, _fileName, _localFilePath;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.elvishew.xlog.XLog;
import com.huozige.lab.container.R;
import com.huozige.lab.container.proxy.support.BaseActivityNoActionBar;
import com.huozige.lab.container.utilities.StringConvertUtility;

import java.util.Base64;

public class BleProxy_ReadingActivity extends AppCompatActivity {
public class BleProxy_ReadingActivity extends BaseActivityNoActionBar {

public final static int STATUS_OK = 0;
public final static int STATUS_ERROR = -10;
Expand All @@ -39,7 +38,7 @@ public class BleProxy_ReadingActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

helper= BleHelper.getInstance(getApplication());
helper = BleHelper.getInstance(getApplication());

setContentView(R.layout.activity_ble_proxy_reading);
findViewById(R.id.button_cancel).setOnClickListener(_cancelButtonClick);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@
import android.nfc.Tag;
import android.os.Bundle;
import android.os.Parcelable;

import com.elvishew.xlog.XLog;

import android.view.View;
import android.widget.Toast;

import com.huozige.lab.container.BaseActivity;
import com.elvishew.xlog.XLog;
import com.huozige.lab.container.R;
import com.huozige.lab.container.proxy.support.BaseActivityNoActionBar;

import java.util.ArrayList;

/**
* 实现方法参考:<a href="https://blog.csdn.net/qq_37565670/article/details/119240737">...</a>
*/
public class NfcProxy_ReadingActivity extends BaseActivity {
public class NfcProxy_ReadingActivity extends BaseActivityNoActionBar {

public final static int SCAN_STATUS_OK = 0;
public final static int SCAN_STATUS_NA = -10;
Expand Down Expand Up @@ -113,7 +111,8 @@ protected void onNewIntent(Intent intent) {
XLog.v("扫描到NFC标签,即将读取");
Intent data = getIntent();
Tag tag = data.getParcelableExtra(NfcAdapter.EXTRA_TAG);
String tagInHex = bytesToHex(tag.getId());

String tagInHex = (tag != null) ? bytesToHex(tag.getId()) : "";

XLog.v("NFC标签的TAG ID为:" + tagInHex);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import com.elvishew.xlog.XLog;
import android.view.View;

import com.huozige.lab.container.BaseActivity;
import com.elvishew.xlog.XLog;
import com.huozige.lab.container.R;
import com.huozige.lab.container.proxy.support.BaseActivityNoActionBar;
import com.huozige.lab.container.utilities.ConfigManager;

/**
* 单次扫描:等待PDA扫码广播的页面,该页面支持用户自行取消
*/
public class PDAProxy_SingleScanActivity extends BaseActivity {
public class PDAProxy_SingleScanActivity extends BaseActivityNoActionBar {

public final static int SCAN_STATUS_OK = 0;
public final static int SCAN_STATUS_CANCEL = -1;
Expand All @@ -33,7 +33,7 @@ public void onReceive(Context context, Intent intent) {
XLog.v("收到单次扫码结果的广播");

// 按照厂商的文档,从广播中获取扫码结果
String result = intent.getStringExtra( (null == ConfigManager.getInstance().getScanExtra())? getString( R.string.feature_scanner_extra_key_barcode_broadcast):ConfigManager.getInstance().getScanExtra());
String result = intent.getStringExtra((null == ConfigManager.getInstance().getScanExtra()) ? getString(R.string.feature_scanner_extra_key_barcode_broadcast) : ConfigManager.getInstance().getScanExtra());

XLog.v("扫码结果是:" + result);

Expand Down Expand Up @@ -79,7 +79,7 @@ public void onResume() {

super.onResume();

String intentF = (ConfigManager.getInstance().getScanAction() == null)?getString(R.string.feature_scanner_broadcast_name):ConfigManager.getInstance().getScanAction();
String intentF = (ConfigManager.getInstance().getScanAction() == null) ? getString(R.string.feature_scanner_broadcast_name) : ConfigManager.getInstance().getScanAction();

// 按照名称来过滤出需要处理的广播
IntentFilter intentFilter = new IntentFilter(intentF);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.huozige.lab.container.utilities;

import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.drawable.Drawable;

import androidx.annotation.ColorInt;
import androidx.core.graphics.drawable.DrawableCompat;

/**
* 颜色相关的帮助类
*/
public class ColorUtility {

// 灰度值的阈值,高于高值意味着深色,否则为暗色
public static double GRAYSCALE_THRESHOLD_BRIGHT_COLOR = 122.5;

/**
* 获取灰度值
*
* @param color 色彩
* @return 灰度值(0-255)
*/
public static double getGrayScale(@ColorInt int color) {
return getGrayScale(Color.red(color), Color.green(color), Color.blue(color));
}

/**
* 获取灰度值
*
* @param red 红色分量
* @param green 绿色分量
* @param blue 蓝色分量
* @return 灰度值(0-255)
*/
public static double getGrayScale(int red, int green, int blue) {
return (red * 0.299) + (green * 0.587) + (blue * 0.114);
}

/**
* 重置图片的颜色
*
* @param orig 原始图片
* @param colorRes 新的颜色
* @return 处理后的图片
*/
public static Drawable resetImageTintColorTo(Drawable orig, @ColorInt int colorRes) {
Drawable wrap = DrawableCompat.wrap(orig).mutate();
//将Drawable重新着色
DrawableCompat.setTintList(wrap, ColorStateList.valueOf(colorRes));
DrawableCompat.setTint(wrap, colorRes);
return wrap;
}
}
Loading

0 comments on commit 5233ecd

Please sign in to comment.