diff --git a/app/build.gradle b/app/build.gradle index 362457a..4c25437 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,14 +9,15 @@ def releaseTime() { } android { - compileSdkVersion 29 + compileSdkVersion 28 buildToolsVersion "29.0.2" defaultConfig { applicationId "com.info.sn" minSdkVersion 23 - targetSdkVersion 29 - versionCode 5 - versionName "1.0.4" + targetSdkVersion 28 + versionCode 10 + versionName "1.1.0" + multiDexEnabled true testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" ndk { //选择要添加的对应 cpu 类型的 .so 库。 @@ -28,7 +29,7 @@ android { JPUSH_APPKEY : "edf9cec22731b8b2fed56ee6", //JPush 上注册的包名对应的 Appkey. JPUSH_CHANNEL: "developer-default", //暂时填写默认值即可. ] - multiDexEnabled true + } buildTypes { release { @@ -112,6 +113,7 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.1.0' +// implementation 'com.android.support:multidex:1.0.3' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' @@ -127,7 +129,7 @@ dependencies { implementation 'com.lzy.net:okrx:0.1.2' implementation 'com.lzy.net:okserver:2.0.5' implementation 'com.alibaba:fastjson:1.2.21' - implementation 'com.blankj:utilcode:1.26.0' +// implementation 'com.blankj:utilcode:1.26.0' implementation 'com.arialyy.aria:core:3.7.10' annotationProcessor 'com.arialyy.aria:compiler:3.7.10' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6e08ead..6ca27fc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -33,7 +33,7 @@ diff --git a/app/src/main/java/com/info/sn/MainActivity.java b/app/src/main/java/com/info/sn/MainActivity.java index 043d0aa..4254343 100644 --- a/app/src/main/java/com/info/sn/MainActivity.java +++ b/app/src/main/java/com/info/sn/MainActivity.java @@ -1,9 +1,12 @@ package com.info.sn; import androidx.appcompat.app.AppCompatActivity; +import androidx.constraintlayout.widget.ConstraintLayout; +import android.app.AlertDialog; import android.content.BroadcastReceiver; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.ActivityInfo; @@ -14,9 +17,15 @@ import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Message; +import android.os.SystemClock; import android.text.TextUtils; +import android.util.Log; +import android.view.KeyEvent; +import android.view.View; +import android.view.WindowManager; import android.widget.ImageView; import android.widget.TextView; +import android.widget.Toast; import com.hjq.permissions.OnPermission; import com.hjq.permissions.Permission; @@ -27,10 +36,15 @@ import com.info.sn.jpush.LocalBroadcastManager; import com.info.sn.jpush.TagAliasOperatorHelper; import com.info.sn.network.api.HTTPInterface; import com.info.sn.service.MyDownloadService; +import com.info.sn.utils.ApkUtils; import com.info.sn.utils.LogUtils; import com.info.sn.utils.SPUtils; import com.info.sn.utils.ToastUtil; import com.info.sn.utils.Utils; +import com.lzy.okgo.OkGo; +import com.lzy.okgo.callback.FileCallback; +import com.lzy.okgo.model.Progress; +import com.lzy.okgo.model.Response; import java.io.File; import java.util.List; @@ -49,9 +63,12 @@ import static com.info.sn.jpush.TagAliasOperatorHelper.sequence; public class MainActivity extends AppCompatActivity { public static boolean isForeground = false; - private ImageView imageView; + private ImageView imageView, exit; private TextView tv_note, tv_devsn, tv_username, tv_school, tv_grade, tv_version; + private ConstraintLayout layout; + private int DeviceInfo; + private long mExitTime; @Override protected void onCreate(Bundle savedInstanceState) { @@ -78,19 +95,49 @@ public class MainActivity extends AppCompatActivity { initData(); HTTPInterface.checkDevicesInfo(handler); startService(new Intent(MainActivity.this, MyDownloadService.class)); - } private void initView() { - tv_note = (TextView) findViewById(R.id.tv_note); - imageView = (ImageView) findViewById(R.id.imageView); - tv_devsn = (TextView) findViewById(R.id.tv_devsn); - tv_devsn.setText("设备SN:" + Utils.getSerial()); - tv_username = (TextView) findViewById(R.id.tv_username); - tv_school = (TextView) findViewById(R.id.tv_school); - tv_grade = (TextView) findViewById(R.id.tv_grade); + tv_note = findViewById(R.id.tv_note); + imageView = findViewById(R.id.imageView); + exit = findViewById(R.id.iv_exit); + exit.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + exit(); + } + }); + layout = findViewById(R.id.layout); + layout.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + continuousClick(COUNTS, DURATION); + } + }); + tv_devsn = findViewById(R.id.tv_devsn); + tv_devsn.setText(Utils.getSerial()); + tv_username = findViewById(R.id.tv_username); + tv_school = findViewById(R.id.tv_school); + tv_grade = findViewById(R.id.tv_grade); tv_version = findViewById(R.id.version); - tv_version.setText("版本:"+ BuildConfig.VERSION_NAME); + tv_version.setText(BuildConfig.VERSION_NAME); + } + + final static int COUNTS = 4;// 点击次数 + final static long DURATION = 1000;// 规定有效时间 + long[] mHits = new long[COUNTS]; + + private void continuousClick(int count, long time) { + //每次点击时,数组向前移动一位 + System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1); + //为数组最后一位赋值 + mHits[mHits.length - 1] = SystemClock.uptimeMillis(); + if (mHits[0] >= (SystemClock.uptimeMillis() - DURATION)) { + mHits = new long[COUNTS];//重新初始化数组 + Toast.makeText(this, "正在检查更新", Toast.LENGTH_SHORT).show(); + HTTPInterface.checkUpdateByPackage(handler, this.getPackageName(), String.valueOf(BuildConfig.VERSION_CODE)); + + } } private void initData() { @@ -109,6 +156,25 @@ public class MainActivity extends AppCompatActivity { } } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { + exit(); + return true; + } + return super.onKeyDown(keyCode, event); + } + + public void exit() { + if ((System.currentTimeMillis() - mExitTime) > 2000) { + Toast.makeText(MainActivity.this, "再按一次退出程序", Toast.LENGTH_SHORT).show(); + mExitTime = System.currentTimeMillis(); + } else { + finish(); + } + } + private void setImageAndText(ImageView imageView, String text) { Bitmap bitmap = Utils.createQRImage(Utils.getSn(), 250, 250); imageView.setImageBitmap(bitmap); @@ -122,19 +188,25 @@ public class MainActivity extends AppCompatActivity { if (name == null || name.equals("")) { tv_username.setText("用户姓名:未设置"); } else { - tv_username.setText("用户姓名:" + name); + tv_username.setText(name); } if (school == null || school.equals("")) { tv_school.setText("学校:未设置"); } else { - tv_school.setText("学校:" + school); + tv_school.setText(school); } if (grade == null || grade.equals("")) { tv_grade.setText("年级:未设置"); } else { - tv_grade.setText("年级:" + getGrade(grade)); + tv_grade.setText(getGrade(grade)); } + } + private void setUserInfo() { + tv_username.setText("未设置"); + tv_school.setText("未设置"); + tv_grade.setText("未设置"); + tv_grade.setText("未设置"); } private String getGrade(String grade) { @@ -204,9 +276,78 @@ public class MainActivity extends AppCompatActivity { SPUtils.put(MainActivity.this, "isLogined", 2); setImageAndText(imageView, "未经验证的设备,请联系客服"); break; + case 200: + Bundle bundle = (Bundle) msg.obj; + getFile(bundle); + break; + case -200: + ToastUtil.show("已是最新版本"); + break; } } }; + private void getFile(final Bundle bundle) { + final File path = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/"); + path.mkdirs(); + final File file = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/Update" + bundle.getString("versionCode") + ".apk"); + + if (file.exists() && file.isFile()) { + AlertDialog.Builder builder = new AlertDialog.Builder(this) + .setTitle("软件更新") + .setIcon(R.mipmap.ic_launcher) + .setCancelable(false) + .setMessage("发现新版本,点击确定更新\n" + "更新内容:" + bundle.getString("content")) + .setPositiveButton("确定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + ApkUtils.installApk(MainActivity.this, file); + dialogInterface.dismiss(); + } + }); + AlertDialog ad = builder.create(); + ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); + ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失 + ad.show(); + } else { + OkGo.get(bundle.getString("url")) + .execute(new FileCallback("Sninfo/Update" + bundle.getString("versionCode") + ".apk") { + @Override + public void onSuccess(final Response response) { +// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video"); +// ApkUtils.installApkInSilence(response.body().getAbsolutePath(), Launcher.this.getPackageName()); + AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this) + .setTitle("软件更新") + .setIcon(R.mipmap.ic_launcher) + .setCancelable(false) + .setMessage("发现新版本,点击确定更新\n" + "更新内容:" + bundle.getString("content")) + .setPositiveButton("确定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + ApkUtils.installApk(MainActivity.this, response.body()); + dialogInterface.dismiss(); + } + }); + AlertDialog ad = builder.create(); + ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); + ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失 + ad.show(); + Log.e("getFile", "download file successful,now installing"); + } + + @Override + public void onError(Response response) { + super.onError(response); + Log.e("getFile", "File download Failure" + response.getException()); + } + + @Override + public void downloadProgress(Progress progress) { + super.downloadProgress(progress); + Log.e("getFile", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed); + } + }); + } + } private String[] permission = new String[]{ // Permission.SYSTEM_ALERT_WINDOW, diff --git a/app/src/main/java/com/info/sn/MyApplication.java b/app/src/main/java/com/info/sn/MyApplication.java index f653ffa..9de6ab9 100644 --- a/app/src/main/java/com/info/sn/MyApplication.java +++ b/app/src/main/java/com/info/sn/MyApplication.java @@ -15,7 +15,7 @@ import android.util.Log; import com.arialyy.annotations.Download; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.task.DownloadTask; -import com.blankj.utilcode.util.NetworkUtils; +//import com.blankj.utilcode.util.NetworkUtils; import com.info.sn.network.api.HTTPInterface; import com.info.sn.utils.ApkUtils; import com.info.sn.utils.LogUtils; @@ -33,7 +33,8 @@ import java.util.TreeMap; import cn.jpush.android.api.CustomMessage; -public class MyApplication extends Application implements NetworkUtils.OnNetworkStatusChangedListener { +//public class MyApplication extends Application implements NetworkUtils.OnNetworkStatusChangedListener { +public class MyApplication extends Application { public static Context context; private static MyApplication app; @@ -45,17 +46,22 @@ public class MyApplication extends Application implements NetworkUtils.OnNetwork context = getApplicationContext(); ToastUtil.init(this); OkGo.getInstance().init(this); - NetworkUtils.registerNetworkStatusChangedListener(this); +// NetworkUtils.registerNetworkStatusChangedListener(this); Aria.init(this); Aria.download(this).register(); Aria.download(this).resumeAllTask(); } +// protected void attachBaseContext(Context newBase) { +// super.attachBaseContext(newBase); +// MultiDex.install(this); +// } + @Override public void onTerminate() { super.onTerminate(); - NetworkUtils.unregisterNetworkStatusChangedListener(this); +// NetworkUtils.unregisterNetworkStatusChangedListener(this); } @@ -134,7 +140,6 @@ public class MyApplication extends Application implements NetworkUtils.OnNetwork private static final String JIGUANG_FORCE_UNINSTALLAPK = "10"; - synchronized public void manageCustomMessage(CustomMessage customMessage) { String sn_id = (String) SPUtils.get(context, "sn_id", "-1"); String member_id = (String) SPUtils.get(context, "member_id", "-1"); @@ -420,17 +425,17 @@ public class MyApplication extends Application implements NetworkUtils.OnNetwork } } - @Override - public void onDisconnected() { - LogUtils.e("onDisconnected", "网络断开"); - } - - @Override - public void onConnected(NetworkUtils.NetworkType networkType) { - Aria.download(this).resumeAllTask(); - LogUtils.e("onConnected", "网络连接"); - - } +// @Override +// public void onDisconnected() { +// LogUtils.e("onDisconnected", "网络断开"); +// } +// +// @Override +// public void onConnected(NetworkUtils.NetworkType networkType) { +// Aria.download(this).resumeAllTask(); +// LogUtils.e("onConnected", "网络连接"); +// +// } //在这里处理任务执行中的状态,如进度进度条的刷新 diff --git a/app/src/main/java/com/info/sn/network/api/HTTPInterface.java b/app/src/main/java/com/info/sn/network/api/HTTPInterface.java index 1eb9b70..d3d2299 100644 --- a/app/src/main/java/com/info/sn/network/api/HTTPInterface.java +++ b/app/src/main/java/com/info/sn/network/api/HTTPInterface.java @@ -140,12 +140,11 @@ public class HTTPInterface { bundle.putString("versionCode", newversion); bundle.putString("content", content); message.obj = bundle; - } else { - message.what = -200; } handler.sendMessage(message); Log.e("checkUpdateByPackage", msg); } else { + handler.sendEmptyMessage(-200); Log.e("checkUpdateByPackage", msg); } } catch (Exception e) { diff --git a/app/src/main/java/com/info/sn/service/MyDownloadService.java b/app/src/main/java/com/info/sn/service/MyDownloadService.java index 079fee4..b0e7f95 100644 --- a/app/src/main/java/com/info/sn/service/MyDownloadService.java +++ b/app/src/main/java/com/info/sn/service/MyDownloadService.java @@ -101,7 +101,7 @@ public class MyDownloadService extends Service { if (file.exists() && file.isFile()) { AlertDialog.Builder builder = new AlertDialog.Builder(this) .setTitle("软件更新") - .setIcon(R.mipmap.ic_launcher_home) + .setIcon(R.mipmap.ic_launcher) .setCancelable(false) .setMessage("发现新版本,点击确定更新\n" + "更新内容:" + bundle.getString("content")) .setPositiveButton("确定", new DialogInterface.OnClickListener() { @@ -124,7 +124,7 @@ public class MyDownloadService extends Service { // ApkUtils.installApkInSilence(response.body().getAbsolutePath(), Launcher.this.getPackageName()); AlertDialog.Builder builder = new AlertDialog.Builder(MyDownloadService.this) .setTitle("软件更新") - .setIcon(R.mipmap.ic_launcher_home) + .setIcon(R.mipmap.ic_launcher) .setCancelable(false) .setMessage("发现新版本,点击确定更新\n" + "更新内容:" + bundle.getString("content")) .setPositiveButton("确定", new DialogInterface.OnClickListener() { diff --git a/app/src/main/res/drawable/bt_return.png b/app/src/main/res/drawable/bt_return.png new file mode 100644 index 0000000..9418385 Binary files /dev/null and b/app/src/main/res/drawable/bt_return.png differ diff --git a/app/src/main/res/drawable/logo.png b/app/src/main/res/drawable/logo.png new file mode 100644 index 0000000..985e4d2 Binary files /dev/null and b/app/src/main/res/drawable/logo.png differ diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 94c6f1a..92efe09 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -4,21 +4,70 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="#d9d9d9" + android:background="#ffffff" tools:context=".MainActivity"> + + + + + + + + + + + + + app:layout_constraintTop_toBottomOf="@+id/imageView3" + app:layout_constraintVertical_bias="0.02"> @@ -27,20 +76,19 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="请扫描绑定设备" - android:textColor="#8c8b8b" + android:textColor="#4b4b4b" android:textSize="@dimen/sp_12" - android:textStyle="bold" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/imageView" - app:layout_constraintVertical_bias="0.026" /> + app:layout_constraintVertical_bias="0.02" /> - - - + android:text="设备SN" + android:textColor="#4b4b4b" + android:textSize="@dimen/sp_12" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> - + + + + + + + + - - + + - + + + android:gravity="right" + android:text=" " + android:textSize="@dimen/sp_11" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + + + + + + - - - - + + - + android:text="学校" + android:textColor="#4b4b4b" + android:textSize="@dimen/sp_12" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> - + + + + + + + + - - + + - + + + + + + + + + + + + + + + + + android:text="版本" + android:textColor="#4b4b4b" + android:textSize="@dimen/sp_12" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + - - - - - - - + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png index 898f3ed..f847b70 100644 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher.png and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_home.png b/app/src/main/res/mipmap-hdpi/ic_launcher_home.png deleted file mode 100644 index 161402b..0000000 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher_home.png and /dev/null differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png index 64ba76f..f847b70 100644 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher.png and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png index e5ed465..f847b70 100644 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png index b0907ca..f847b70 100644 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png index 2c18de9..f847b70 100644 Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ