@@ -23,17 +23,19 @@ | |||
* 配置```appName=```App桌面快捷方式名称, 可以直接使用字符串(需要加双引号, 如 "NSGK APP"), 也可以使用国际化字符串配置(不要加双引号, 如 @string/app_name) | |||
* 配置```appIconKey=```图标名称, 不要加双引号, 去掉前后缀(如 yhzl, 图标为ic_launcher_yhzl; 圆角图标为ic_launcher_yhzl_round) | |||
* 使用Android Studio生成签名包 | |||
* 配置```appCopyright=```启动页版权文本, 不要加双引号 | |||
* 配置```appVendor=```启动页厂商名称, 不要加双引号 | |||
* 生成的apk路径为 `/app/release/app-release.apk` | |||
> 使用`gradle`脚本打签名的正式包 | |||
* 执行 ```gradlew assembleRelease``` 将使用`gradle.properties`文件里的配置进行打包 | |||
* 如果需要自定义配置(无需修改`gradle.properties`文件), 执行 ```gradlew assembleRelease -PappHomeUrl="首页地址" -PappName="App桌面快捷方式名称(只能使用字符串)" -PappIconKey="图标名称"``` 将使用命令行里的配置进行打包 | |||
* 如果需要自定义配置(无需修改`gradle.properties`文件), 执行 ```gradlew assembleRelease -PappHomeUrl="首页地址" -PappName="App桌面快捷方式名称(只能使用字符串)" -PappIconKey="图标名称" -PappIconKey="启动页版权文本" -PappCopyright="启动页厂商名称"``` 将使用命令行里的配置进行打包 | |||
* 生成的apk路径为 `/app/build/outputs/apk/release/app-release.apk` | |||
> 帮助脚本 | |||
* `打包-正式.bat`: 构建正式包(直接执行将使用`gradle.properties`文件里的配置进行打包, 完整命令行用法为 ```.\打包-正式.bat App主页链接地址 App名称 App图标```, 此时会使用命令行里的配置进行打包. 生成的路径为`/app/build/outputs/apk/release/app-release.apk`) | |||
* `打包-正式.bat`: 构建正式包(直接执行将使用`gradle.properties`文件里的配置进行打包, 完整命令行用法为 ```.\打包-正式.bat App主页链接地址 App名称 App图标 App启动页版权文本 App启动页厂商名称```, 此时会使用命令行里的配置进行打包. 生成的路径为`/app/build/outputs/apk/release/app-release.apk`) | |||
* `打包-debug.bat`: 构建Debug包(生成的路径为`/app/build/outputs/apk/debug/app-debug.apk`) | |||
* `安装-发布包.bat`: 将已打好的Release包安装至手机(手机需连接到电脑, 并且启用开发者模式) | |||
* `安装-调试包.bat`: 将已打好的Debug包安装至手机(手机需连接到电脑, 并且启用开发者模式) | |||
@@ -17,6 +17,11 @@ android { | |||
// App首页链接地址 | |||
buildConfigField "String", "APP_HOME_URL", "\"${project.properties.appHomeUrl}\"" | |||
// App启动页版权文本 | |||
buildConfigField "String", "APP_COMPYRIGHT", "\"${project.properties.appCopyright}\"" | |||
// App启动页厂商名称 | |||
buildConfigField "String", "APP_VENDOR", "\"${project.properties.appVendor}\"" | |||
// AndroidManifest.xml占位符 | |||
manifestPlaceholders = [ | |||
// App名称 | |||
@@ -44,11 +49,15 @@ android { | |||
minifyEnabled false | |||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | |||
signingConfig signingConfigs.release | |||
//resValue("string", "app_custom_name", "\"${project.properties.appName}\"") | |||
resValue("string", "app_home_url", "\"${project.properties.appHomeUrl}\"") | |||
resValue("string", "app_copyright", "\"${project.properties.appCopyright}\"") | |||
resValue("string", "app_vendor", "\"${project.properties.appVendor}\"") | |||
} | |||
debug { | |||
signingConfig signingConfigs.release | |||
//resValue("string", "app_custom_name", "\"${project.properties.appName}\"") | |||
resValue("string", "app_home_url", "\"${project.properties.appHomeUrl}\"") | |||
resValue("string", "app_copyright", "\"${project.properties.appCopyright}\"") | |||
resValue("string", "app_vendor", "\"${project.properties.appVendor}\"") | |||
} | |||
} | |||
compileOptions { | |||
@@ -11,4 +11,24 @@ public class Constants | |||
{ | |||
return BuildConfig.APP_HOME_URL; | |||
} | |||
/** | |||
* App启动页版权文本 | |||
* 可以在 /gradle.properties 里配置 appCopyright=文本, 不要携带双引号 | |||
* 也可以在命令行添加 -PappCopyright="文本", 双引号可携带也可不携带 | |||
*/ | |||
public static String AppCopyright() | |||
{ | |||
return BuildConfig.APP_COMPYRIGHT; | |||
} | |||
/** | |||
* App启动页厂商文本 | |||
* 可以在 /gradle.properties 里配置 appVendor=文本, 不要携带双引号 | |||
* 也可以在命令行添加 -PappVendor="文本", 双引号可携带也可不携带 | |||
*/ | |||
public static String AppVendor() | |||
{ | |||
return BuildConfig.APP_VENDOR; | |||
} | |||
} |
@@ -6,6 +6,7 @@ import android.os.Bundle; | |||
import android.util.Log; | |||
import android.view.KeyEvent; | |||
import android.view.ViewGroup; | |||
import android.webkit.WebView; | |||
import android.widget.LinearLayout; | |||
import android.widget.RelativeLayout; | |||
@@ -24,6 +25,7 @@ public class FullscreenActivity extends AppCompatActivity { | |||
private AgentWeb mAgentWeb; | |||
private Preference preference; | |||
@SuppressLint("SetJavaScriptEnabled") | |||
@Override | |||
@@ -31,12 +33,23 @@ public class FullscreenActivity extends AppCompatActivity { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_fullscreen); | |||
String appHomeUrl = Constants.AppHomeUrl(); | |||
String appHomeUrl = GetHomeUrl(); | |||
Log.i("NSGK", "App home url: " + appHomeUrl); | |||
// init(); | |||
mAgentWeb = AgentWeb.with(this)// | |||
.setAgentWebParent((RelativeLayout) findViewById(R.id.ll), -1, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))//传入AgentWeb的父控件。 | |||
.useDefaultIndicator(-1, 3)//设置进度条颜色与高度,-1为默认值,高度为2,单位为dp。 | |||
/* .setWebChromeClient(new WebChromeClient() { | |||
@Override | |||
public void onProgressChanged(WebView view, int newProgress) | |||
{ | |||
super.onProgressChanged(view, newProgress); | |||
if(newProgress == 100) | |||
{ | |||
GetPreference().SetString(Preference.LAST_ACCESS_URL, view.getUrl()); | |||
} | |||
} | |||
})*/ | |||
.setWebViewClient(new com.just.agentweb.WebViewClient() { | |||
})//WebViewClient , 与 WebView 使用一致 ,但是请勿获取WebView调用setWebViewClient(xx)方法了,会覆盖AgentWeb DefaultWebClient,同时相应的中间件也会失效。 | |||
@@ -99,4 +112,28 @@ public class FullscreenActivity extends AppCompatActivity { | |||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | |||
super.onActivityResult(requestCode, resultCode, data); | |||
} | |||
private Preference GetPreference() | |||
{ | |||
if(null == preference) | |||
preference = new Preference(this); | |||
return preference; | |||
} | |||
private String GetHomeUrl() | |||
{ | |||
return Constants.AppHomeUrl(); | |||
// return GetPreference().GetString(GetPreference().LAST_ACCESS_URL, Constants.AppHomeUrl()); | |||
} | |||
private void DumpLastUrl() | |||
{ | |||
if(null == mAgentWeb) | |||
return; | |||
WebView webView = mAgentWeb.getWebCreator().getWebView(); | |||
if(null == webView) | |||
return; | |||
String url = webView.getUrl(); | |||
GetPreference().SetString(Preference.LAST_ACCESS_URL, url); | |||
} | |||
} |
@@ -0,0 +1,37 @@ | |||
package com.nsgk.ruralWeb; | |||
import android.content.Context; | |||
import android.content.SharedPreferences; | |||
import android.preference.PreferenceManager; | |||
public final class Preference | |||
{ | |||
public static final String LAST_ACCESS_URL = "last_access_url"; | |||
private final Context context; | |||
public Preference(Context context) | |||
{ | |||
this.context = context; | |||
} | |||
private SharedPreferences Read() | |||
{ | |||
return PreferenceManager.getDefaultSharedPreferences(context); | |||
} | |||
private SharedPreferences.Editor Write() | |||
{ | |||
return PreferenceManager.getDefaultSharedPreferences(context).edit(); | |||
} | |||
public String GetString(String name, String...def) | |||
{ | |||
return Read().getString(name, null != def && def.length > 0 ? def[0] : null); | |||
} | |||
public void SetString(String name, String val) | |||
{ | |||
Write().putString(name, val).commit(); | |||
} | |||
} |
@@ -9,6 +9,7 @@ import android.view.animation.Animation; | |||
import android.view.animation.AnimationUtils; | |||
import android.widget.ImageView; | |||
import android.widget.LinearLayout; | |||
import android.widget.TextView; | |||
import androidx.annotation.NonNull; | |||
import androidx.appcompat.app.AppCompatActivity; | |||
@@ -36,12 +37,38 @@ public class WelcomeActivity extends AppCompatActivity { | |||
} | |||
}; | |||
private String GetTrimString(String str) | |||
{ | |||
if(null == str || str.isEmpty()) | |||
return null; | |||
str = str.trim(); | |||
if(str.isEmpty()) | |||
return null; | |||
return str; | |||
} | |||
@Override | |||
protected void onCreate(Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
this.setContentView(R.layout.activity_welcome); | |||
imageView = findViewById(R.id.imageView); | |||
llcenter = findViewById(R.id.llcenter); | |||
// 动态设置启动页版权信息 | |||
String text = GetTrimString(Constants.AppCopyright()); | |||
if(null != text) | |||
{ | |||
TextView copyrightText = findViewById(R.id.welcome_text_copyright); | |||
copyrightText.setText(text); | |||
} | |||
// 动态设置启动页厂商名称 | |||
text = GetTrimString(Constants.AppVendor()); | |||
if(null != text) | |||
{ | |||
TextView vendorText = findViewById(R.id.welcome_text_vendor); | |||
vendorText.setText(text); | |||
} | |||
Animation animation = AnimationUtils.loadAnimation(this, R.anim.img_anim); | |||
animation.start(); | |||
handler.sendEmptyMessageDelayed(1, 1000); | |||
@@ -32,6 +32,7 @@ | |||
android:layout_marginBottom="8dp"> | |||
<TextView | |||
android:id="@+id/welcome_text_copyright" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_gravity="center" | |||
@@ -39,6 +40,7 @@ | |||
android:text="@string/copyright" /> | |||
<TextView | |||
android:id="@+id/welcome_text_vendor" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_gravity="center" | |||
@@ -23,9 +23,13 @@ keyAlias=nsgk_rural_web | |||
keyPassword=ns61GK32x% | |||
# Command line arguments | |||
# [String] App home url | |||
# [String] App home url, it will save to @string/app_home_url | |||
appHomeUrl=http://218.59.175.43:71/yinnongLogin | |||
# [String] App custom name, it will be set on res/values/strings.xml with key app_custom_name | |||
# [String] App custom name, it will be set on res/values/strings.xml | |||
appName=@string/app_name | |||
# [String] App icon mipmap key name in res/mipmaps, icon = ic_launcher_${appIconKey}, round icon = ic_launcher_${appIconKey}_round | |||
appIconKey=yhzl | |||
appIconKey=yhzl | |||
# [String] App copyright name, it will save to @string/app_copyright. default using @string/copyright | |||
appCopyright= | |||
# [String] App vendor name, it will save to @string/app_vendor. default using @string/company | |||
appVendor= |
@@ -2,24 +2,43 @@ | |||
echo 构建apk(正式) | |||
echo 用法: %0 App主页链接地址 App名称 App图标 | |||
echo 用法: %0 App主页链接地址 App名称 App图标 "App版权信息" App厂商信息 | |||
echo 任意参数不传则使用App项目里gradle.properties的默认配置 | |||
set NUM_ARG=0 | |||
for %%x in (%*) do ( | |||
set /a NUM_ARG+=1 | |||
) | |||
echo %NUM_ARG% | |||
echo 参数数量: %NUM_ARG% | |||
if %NUM_ARG% GEQ 3 ( | |||
call gradlew assembleRelease -PappHomeUrl="%1" -PappName="%2" -PappIconKey="%3" | |||
if %NUM_ARG% GEQ 5 ( | |||
echo App主页链接地址: %1 | |||
echo App名称: %2 | |||
echo App图标: ic_launcher_%3; 圆角图标: ic_launcher_%3_round | |||
echo App版权信息: %4 | |||
echo App厂商信息: %5 | |||
call gradlew assembleRelease -PappHomeUrl=%1 -PappName=%2 -PappIconKey=%3 -PappCopyright=%4 -PappVendor=%5 | |||
) else if %NUM_ARG% GEQ 4 ( | |||
echo App主页链接地址: %1 | |||
echo App名称: %2 | |||
echo App图标: ic_launcher_%3 圆角图标: ic_launcher_%3_round | |||
echo App版权信息: %4 | |||
call gradlew assembleRelease -PappHomeUrl=%1 -PappName=%2 -PappIconKey=%3 -PappCopyright=%4 | |||
) else if %NUM_ARG% GEQ 3 ( | |||
echo App主页链接地址: %1 | |||
echo App名称: %2 | |||
echo App图标: ic_launcher_%3; 圆角图标: ic_launcher_%3_round | |||
call gradlew assembleRelease -PappHomeUrl=%1 -PappName=%2 -PappIconKey=%3 | |||
) else if %NUM_ARG% GEQ 2 ( | |||
call gradlew assembleRelease -PappHomeUrl="%1" -PappName="%2" | |||
echo App主页链接地址: %1 | |||
echo App名称: %2 | |||
call gradlew assembleRelease -PappHomeUrl=%1 -PappName=%2 | |||
) else if %NUM_ARG% GEQ 1 ( | |||
call gradlew assembleRelease -PappHomeUrl="%1" | |||
echo App主页链接地址: %1 | |||
call gradlew assembleRelease -PappHomeUrl=%1 | |||
) else ( | |||
echo 使用gradle.properties默认配置 | |||
call gradlew assembleRelease | |||
) | |||