LicenseTopActivity.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. package com.epson.mobilephone.common.license;
  2. import android.content.Context;
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.Button;
  7. import android.widget.TextView;
  8. import androidx.annotation.NonNull;
  9. import androidx.annotation.Nullable;
  10. import androidx.appcompat.app.AppCompatActivity;
  11. import epson.common.Constants;
  12. import epson.print.R;
  13. /**
  14. * 用户协议
  15. */
  16. public class LicenseTopActivity extends AppCompatActivity implements SimpleMessageDialogFragment.DialogCallback {
  17. private static final String DIALOG_ID = "dialog";
  18. private static final int DIALOG_ID_DISAGREE = 2;
  19. private static final int DIALOG_ID_NEW_LICENSE = 1;
  20. private static final String KEY_LICENSE_INFO = "license_info";
  21. private static final String KEY_USER_SURVEY_INFO = "user_survey_info";
  22. private static final int REQUEST_CODE_USER_SURVEY_INVITATION = 2;
  23. private LicenseInfo mLicenseInfo;
  24. private UserSurveyInfo mUserSurveyInfo;
  25. public void onBackPressed() {
  26. }
  27. protected void onCreate(Bundle bundle) {
  28. super.onCreate(bundle);
  29. setContentView(R.layout.activity_license_top);
  30. findViewById(R.id.licenseViewGroup).setOnClickListener(new View.OnClickListener() {
  31. public void onClick(View view) {
  32. startDocumentDisplayActivity(1);
  33. }
  34. });
  35. findViewById(R.id.privacyStatementViewGroup).setOnClickListener(new View.OnClickListener() {
  36. public void onClick(View view) {
  37. startDocumentDisplayActivity(2);
  38. }
  39. });
  40. ((Button) findViewById(R.id.agreeButton)).setOnClickListener(new View.OnClickListener() {
  41. public void onClick(View view) {
  42. onAgree();
  43. }
  44. });
  45. ((Button) findViewById(R.id.disagreeButton)).setOnClickListener(new View.OnClickListener() {
  46. public void onClick(View view) {
  47. onDisagree();
  48. }
  49. });
  50. if (!initField(getIntent())) {
  51. setResult(0);
  52. finish();
  53. return;
  54. }
  55. ((TextView) findViewById(R.id.appNameText)).setText(mLicenseInfo.getApplicationName(this));
  56. if (bundle == null) {
  57. showLicenseChangeDialogIfNeeded(this, mLicenseInfo, mUserSurveyInfo);
  58. }
  59. }
  60. private boolean initField(Intent intent) {
  61. if (intent == null) {
  62. return false;
  63. }
  64. mLicenseInfo = (LicenseInfo) intent.getSerializableExtra(KEY_LICENSE_INFO);
  65. if (mLicenseInfo == null) {
  66. return false;
  67. }
  68. mUserSurveyInfo = (UserSurveyInfo) intent.getSerializableExtra(KEY_USER_SURVEY_INFO);
  69. return true;
  70. }
  71. private void showLicenseChangeDialogIfNeeded(@NonNull Context context, @NonNull LicenseInfo licenseInfo, UserSurveyInfo userSurveyInfo) {
  72. String str;
  73. switch (licenseInfo.getLicenseAgreement(context)) {
  74. case 0:
  75. str = getString(R.string.EULA_Title) + Constants.BREAK_LINE + getString(R.string.Privacy_Statement_Title);
  76. break;
  77. case 1:
  78. str = getString(R.string.EULA_Title);
  79. break;
  80. case 2:
  81. str = getString(R.string.Privacy_Statement_Title);
  82. break;
  83. case 3:
  84. setResult(-1);
  85. if (userSurveyInfo == null || userSurveyInfo.getResponseStatus(context) >= 2) {
  86. finish();
  87. return;
  88. } else {
  89. startUserSurveyInvitationActivity();
  90. return;
  91. }
  92. default:
  93. return;
  94. }
  95. SimpleMessageDialogFragment.newInstance(getString(R.string.Update_Message) + Constants.BREAK_LINE + str, 1).show(getSupportFragmentManager(), DIALOG_ID);
  96. }
  97. /**
  98. * 同意点击事件
  99. */
  100. private void onAgree() {
  101. LicenseInfo licenseInfo = mLicenseInfo;
  102. if (licenseInfo == null) {
  103. finish();
  104. return;
  105. }
  106. licenseInfo.setLicenceAgreement(this);
  107. setResult(-1);
  108. startUserSurveyInvitationActivity();
  109. }
  110. private void startUserSurveyInvitationActivity() {
  111. if (mLicenseInfo == null) {
  112. finish();
  113. return;
  114. }
  115. UserSurveyInfo userSurveyInfo = mUserSurveyInfo;
  116. if (userSurveyInfo == null) {
  117. finish();
  118. } else if (userSurveyInfo.getResponseStatus(this) >= 2) {
  119. finish();
  120. } else {
  121. startActivityForResult(UserSurveyInvitationActivity.getStartWithDialogIntent(this, mUserSurveyInfo, mLicenseInfo), 2);
  122. }
  123. }
  124. /**
  125. * 不同意则弹框确认
  126. */
  127. private void onDisagree() {
  128. SimpleMessageDialogFragment.newInstance(getString(R.string.Disagree_License_Button_Message), 2).show(getSupportFragmentManager(), DIALOG_ID);
  129. }
  130. /**
  131. * 跳转到 用户协议/隐私协议 页面
  132. *
  133. * @param i
  134. */
  135. private void startDocumentDisplayActivity(int i) {
  136. LicenseInfo licenseInfo = mLicenseInfo;
  137. if (licenseInfo != null) {
  138. startActivity(InfoDisplayActivity.getStartIntent(this, licenseInfo, i));
  139. }
  140. }
  141. /**
  142. * 实现点击事件
  143. *
  144. * @param i
  145. */
  146. @Override
  147. public void onButtonClicked(int i) {
  148. switch (i) {
  149. case 1:
  150. return;
  151. case 2:
  152. setResult(0);
  153. finish(); //不同意退出app
  154. return;
  155. default:
  156. return;
  157. }
  158. }
  159. protected void onActivityResult(int i, int i2, Intent intent) {
  160. super.onActivityResult(i, i2, intent);
  161. if (i == 2) {
  162. setResult(-1);
  163. finish();
  164. }
  165. }
  166. public static Intent getStartIntent(Context context, @NonNull LicenseInfo licenseInfo, @Nullable UserSurveyInfo userSurveyInfo) {
  167. Intent intent = new Intent(context, LicenseTopActivity.class);
  168. intent.putExtra(KEY_LICENSE_INFO, licenseInfo);
  169. intent.putExtra(KEY_USER_SURVEY_INFO, userSurveyInfo);
  170. return intent;
  171. }
  172. }