SystemUtils.java 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package org.las2mile.okio.utils;
  2. import java.io.BufferedReader;
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import android.content.Context;
  7. import android.util.Log;
  8. import java.lang.reflect.Method;
  9. import android.os.Handler;
  10. import android.os.Looper;
  11. import android.os.ResultReceiver;
  12. import java.lang.reflect.Field;
  13. import java.text.ParseException;
  14. import java.text.SimpleDateFormat;
  15. import java.util.Date;
  16. import org.las2mile.scrcpy.BuildConfig;
  17. import android.app.AlertDialog;
  18. import android.content.DialogInterface;
  19. import android.widget.CheckBox;
  20. import android.widget.TextView;
  21. import android.app.Activity;
  22. import org.las2mile.scrcpy.R;
  23. import android.view.View;
  24. import android.widget.Button;
  25. public class SystemUtils {
  26. private static final String LOG_TAG = "TelephonyManagerSub";
  27. private static final String PREFERENCE_KEY = "default";
  28. public static boolean isDateValid(){
  29. String buildTime = BuildConfig.BUILD_TIME;
  30. long day = 0;
  31. SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
  32. try {
  33. Date buildDate = format.parse(buildTime);
  34. Date curDate = new Date();
  35. day = (curDate.getTime()-buildDate.getTime())/(24*60*60*1000);
  36. } catch (ParseException e) {
  37. throw new RuntimeException(e);
  38. }
  39. if(day == 0){
  40. day = 1;
  41. }
  42. boolean isValid = false;
  43. if(day < 0){
  44. isValid = false;
  45. } else if(0 <= day && day <=60){
  46. isValid = true;
  47. } else {
  48. isValid = false;
  49. }
  50. Log.d(LOG_TAG,"no need update "+isValid+" "+day);
  51. return isValid;
  52. }
  53. public static void enableStartLegalNotice(Activity activity,Button startButton){
  54. CheckBox checkBox = activity.findViewById(R.id.cb_legal_notice);
  55. checkBox.setClickable(false);
  56. boolean agree = activity.getSharedPreferences(PREFERENCE_KEY, 0).getBoolean("agree notice", false);
  57. checkBox.setChecked(agree);
  58. startButton.setEnabled(agree);
  59. activity.findViewById(R.id.ll_legal_notice).setOnClickListener(new View.OnClickListener() {
  60. @Override
  61. public void onClick(View view) {
  62. Log.d("OkioMain","onClick");
  63. AlertDialog.Builder builder = new AlertDialog.Builder(activity);
  64. builder.setTitle("深圳恺恩科技有限公司法律声明");
  65. builder.setMessage(R.string.legal_notice);
  66. builder.setCancelable(false);
  67. builder.setPositiveButton("同意",new DialogInterface.OnClickListener(){
  68. @Override
  69. public void onClick(DialogInterface dialogInterface, int i) {
  70. activity.getSharedPreferences(PREFERENCE_KEY, 0).edit().putBoolean("agree notice", true).apply();
  71. checkBox.setChecked(true);
  72. startButton.setEnabled(true);
  73. dialogInterface.dismiss();
  74. }
  75. });
  76. builder.setNegativeButton("不同意",new DialogInterface.OnClickListener(){
  77. @Override
  78. public void onClick(DialogInterface dialogInterface, int i) {
  79. activity.getSharedPreferences(PREFERENCE_KEY, 0).edit().putBoolean("agree notice", false).apply();
  80. checkBox.setChecked(false);
  81. startButton.setEnabled(false);
  82. dialogInterface.dismiss();
  83. }
  84. });
  85. AlertDialog dialog = builder.create();
  86. dialog.show();
  87. }
  88. });
  89. }
  90. }