Skip to content

Commit

Permalink
1. 升级依赖库的版本
Browse files Browse the repository at this point in the history
2. 增加“拨打电话”功能
  • Loading branch information
kadbbz committed Aug 8, 2023
1 parent 8d05eec commit 2cbee85
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 31 deletions.
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.

10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ plugins {
}

android {
compileSdk 32
compileSdk 33

defaultConfig {
applicationId "com.huozige.lab.container"
minSdk 26
//noinspection ExpiredTargetSdkVersion
targetSdk 26
versionCode 4
versionName '1.11.0-release'
versionName '1.12.0-beta1'
}

buildTypes {
Expand All @@ -37,19 +37,19 @@ apply plugin: "realm-android"

dependencies {
implementation 'com.google.firebase:firebase-analytics:21.3.0'
implementation 'com.github.getActivity:XXPermissions:16.6'
implementation 'com.github.getActivity:XXPermissions:18.2'
//noinspection GradleDependency
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation files('libs/LPAPI-2021-02-02-R.jar')
implementation 'com.zhihu.android:matisse:0.5.3-beta3'
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'com.github.jenly1314:zxing-lite:2.1.1'
implementation 'com.github.jenly1314:zxing-lite:2.4.0'
implementation 'com.github.david-serrano:locationprovider:1.2'
implementation 'com.alibaba:fastjson:1.1.72.android'
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
implementation 'commons-io:commons-io:2.6'
implementation 'io.github.chiclaim:downloader:1.0.2'
implementation 'com.sunmi:printerx:1.0.11'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
}
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />

<uses-permission android:name="android.permission.INTERNET" /> <!-- 敏感权限 -->
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
Expand Down Expand Up @@ -86,6 +91,7 @@
android:exported="false" />
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
14 changes: 14 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 @@ -3,6 +3,7 @@

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
Expand All @@ -11,6 +12,7 @@

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;

import com.huozige.lab.container.platform.hzg.HZGCacheFilter;
import com.huozige.lab.container.platform.hzg.HZGWebInterop;
Expand Down Expand Up @@ -191,6 +193,18 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
return super.onKeyDown(keyCode, event);
}

/**
* 处理配置变更的事件,这里仅做日志记录
* @param newConfig The new device configuration.
*/
@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);

Log.v("HAC_BaseActivity","Config changed: "+ newConfig);

}

/**
* 在ActionBar上创建菜单,提供回到首页、刷新页面两个常用功能
*/
Expand Down
35 changes: 33 additions & 2 deletions app/src/main/java/com/huozige/lab/container/proxy/AppProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.Uri;
import android.util.Log;
import android.webkit.JavascriptInterface;

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;

import com.hjq.permissions.Permission;
import com.huozige.lab.container.QuickConfigActivity;
import com.huozige.lab.container.SettingActivity;
import com.huozige.lab.container.utilities.LifecycleUtility;
import com.huozige.lab.container.utilities.PermissionsUtility;

/**
* 让页面能对APP壳子进行操作
Expand All @@ -32,6 +35,8 @@
* app.openQuickConfigPage():打开快速配置页面
* 1.9.0
* app.closeApp():关闭应用
* 1.12.0
* app.dial(phoneNumber):拨打电话
*/
public class AppProxy extends AbstractProxy {

Expand All @@ -41,6 +46,16 @@ public class AppProxy extends AbstractProxy {

static final String LOG_TAG = "HAC_AppProxy";

/**
* 根据传递过来的字符串判断是否为true
*
* @param text 用来判断的字符串,如1、true、yes均被视为true
* @return 判断结果
*/
private boolean assertSwitch(String text) {
return text != null && text.length() > 0 && !text.equalsIgnoreCase("0") && !text.equalsIgnoreCase("false") && !text.equalsIgnoreCase("no");
}

/**
* 注册的名称为:app
*/
Expand Down Expand Up @@ -102,6 +117,22 @@ public void openSettingPage() {
);
}

/**
* 拨打电话
*/
@JavascriptInterface
public void dial(String phoneNumber) {

PermissionsUtility.asyncRequirePermissions(this.getInterop().getActivityContext(), new String[]{
Permission.CALL_PHONE
}, () -> {
Intent intent = new Intent();
intent.setAction("android.intent.action.CALL");
intent.setData(Uri.parse("tel:" + phoneNumber));
this.getInterop().getActivityContext().startActivity(intent);
});
}

/**
* 注册到页面的app.openQuickConfigPage()方法
* 导航到快速配置页面
Expand All @@ -120,7 +151,7 @@ public void openQuickConfigPage() {
@JavascriptInterface
public void toggleSettingMenu(String shouldShow) {

getConfigManager().upsertSettingMenuVisible(shouldShow != null && shouldShow.length() > 0 && !shouldShow.equalsIgnoreCase("0") && !shouldShow.equalsIgnoreCase("false") && !shouldShow.equalsIgnoreCase("no"));
getConfigManager().upsertSettingMenuVisible(assertSwitch(shouldShow));

// 重启生效
LifecycleUtility.restart(getInterop().getActivityContext());
Expand All @@ -133,7 +164,7 @@ public void toggleSettingMenu(String shouldShow) {
@JavascriptInterface
public void toggleActionBar(String shouldShow) {

getConfigManager().upsertActionBarVisible(shouldShow != null && shouldShow.length() > 0 && !shouldShow.equalsIgnoreCase("0") && !shouldShow.equalsIgnoreCase("false") && !shouldShow.equalsIgnoreCase("no"));
getConfigManager().upsertActionBarVisible(assertSwitch(shouldShow));

// 重启生效
LifecycleUtility.restart(getInterop().getActivityContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.XXPermissions;
import com.huozige.lab.container.R;
Expand Down Expand Up @@ -32,7 +34,7 @@ public static void asyncRequirePermissions(Context context, String[] permissions
.request(new OnPermissionCallback() {

@Override
public void onGranted(List<String> permissions, boolean all) {
public void onGranted(@NonNull List<String> permissions, boolean all) {
if (!all) {
Log.w(LOG_TAG,"申请的权限中部分成功,部分失败,已提示给用户");

Expand All @@ -45,7 +47,7 @@ public void onGranted(List<String> permissions, boolean all) {
}

@Override
public void onDenied(List<String> permissions, boolean never) {
public void onDenied(@NonNull List<String> permissions, boolean never) {
if (never) {

Log.e(LOG_TAG,"权限申请被拒绝且勾选为never,即将导航到系统的权限设置页面");
Expand Down
34 changes: 16 additions & 18 deletions app/src/main/java/com/huozige/lab/container/webview/HACWebView.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import android.widget.LinearLayout;
import android.widget.ProgressBar;

import androidx.annotation.NonNull;

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

/**
Expand All @@ -34,13 +36,20 @@ public class HACWebView extends WebView {
*/
private int getMajorVersion(){
PackageInfo pinfo = WebView.getCurrentWebViewPackage();
Log.v(LOG_TAG,"Init:检测到WebView的PackageName: " + pinfo.packageName);
Log.v(LOG_TAG,"Init:检测到WebView的VersionName: " + pinfo.versionName);
Log.v(LOG_TAG,"Init:检测到WebView的VersionCode: " + pinfo.versionCode);

String major = pinfo.versionName.split("\\.")[0];
if(pinfo == null){
Log.e(LOG_TAG,"无法获取浏览器的版本号,跳过了版本检查。");
return Integer.MAX_VALUE; // 如果无法获取版本号,按照可以使用来处理
}else{
Log.v(LOG_TAG,"Init:检测到WebView的PackageName: " + pinfo.packageName);
Log.v(LOG_TAG,"Init:检测到WebView的VersionName: " + pinfo.versionName);
Log.v(LOG_TAG,"Init:检测到WebView的VersionCode: " + pinfo.versionCode);

String major = pinfo.versionName.split("\\.")[0];

return Integer.parseInt(major);
}

return Integer.parseInt(major);
}

/**
Expand Down Expand Up @@ -80,9 +89,7 @@ public HACWebView(Context context) {

// 缓存
settings.setDomStorageEnabled(true); // DOM缓存
settings.setAppCacheEnabled(true); // 数据缓存(活字格采用的本地库就是这个)
settings.setAppCachePath(context.getApplicationContext().getCacheDir().getAbsolutePath()); // 数据缓存路径
settings.setCacheMode(WebSettings.LOAD_DEFAULT);
settings.setCacheMode(WebSettings.LOAD_DEFAULT); // 采用默认的缓存策略

// 布局
settings.setUseWideViewPort(true); // 默认全屏
Expand Down Expand Up @@ -111,15 +118,6 @@ public HACWebView(Context context) {

}

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
LayoutParams lp = (LayoutParams) _progressBar.getLayoutParams();
lp.x = l;
lp.y = t;
_progressBar.setLayoutParams(lp);
super.onScrollChanged(l, t, oldl, oldt);
}

/**
* 设置加载进度
*
Expand Down Expand Up @@ -160,7 +158,7 @@ public void refreshWebView() {
* @param url URL地址或JS脚本
*/
@Override
public void loadUrl(String url) {
public void loadUrl(@NonNull String url) {
super.loadUrl(url);

Log.v(LOG_TAG, "导航到页面或执行脚本:" + url);
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}
dependencies {
classpath 'com.google.gms:google-services:4.3.15'
classpath "io.realm:realm-gradle-plugin:10.15.1"
classpath "io.realm:realm-gradle-plugin:10.16.1"
}
}

Expand All @@ -17,6 +17,6 @@ plugins {
id 'com.android.library' version '8.0.1' apply false
}

task clean(type: Delete) {
tasks.register('clean', Delete) {
delete rootProject.buildDir
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
Expand Down

0 comments on commit 2cbee85

Please sign in to comment.