LicenseTopActivity.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. private void onAgree() {
  98. LicenseInfo licenseInfo = mLicenseInfo;
  99. if (licenseInfo == null) {
  100. finish();
  101. return;
  102. }
  103. licenseInfo.setLicenceAgreement(this);
  104. setResult(-1);
  105. startUserSurveyInvitationActivity();
  106. }
  107. private void startUserSurveyInvitationActivity() {
  108. if (mLicenseInfo == null) {
  109. finish();
  110. return;
  111. }
  112. UserSurveyInfo userSurveyInfo = mUserSurveyInfo;
  113. if (userSurveyInfo == null) {
  114. finish();
  115. } else if (userSurveyInfo.getResponseStatus(this) >= 2) {
  116. finish();
  117. } else {
  118. startActivityForResult(UserSurveyInvitationActivity.getStartWithDialogIntent(this, mUserSurveyInfo, mLicenseInfo), 2);
  119. }
  120. }
  121. private void onDisagree() {
  122. SimpleMessageDialogFragment.newInstance(getString(R.string.Disagree_License_Button_Message), 2).show(getSupportFragmentManager(), DIALOG_ID);
  123. }
  124. /**
  125. * 跳转到 用户协议/隐私协议 页面
  126. *
  127. * @param i
  128. */
  129. private void startDocumentDisplayActivity(int i) {
  130. LicenseInfo licenseInfo = mLicenseInfo;
  131. if (licenseInfo != null) {
  132. startActivity(InfoDisplayActivity.getStartIntent(this, licenseInfo, i));
  133. }
  134. }
  135. public void onButtonClicked(int i) {
  136. switch (i) {
  137. case 1:
  138. return;
  139. case 2:
  140. setResult(0);
  141. finish();
  142. return;
  143. default:
  144. return;
  145. }
  146. }
  147. protected void onActivityResult(int i, int i2, Intent intent) {
  148. super.onActivityResult(i, i2, intent);
  149. if (i == 2) {
  150. setResult(-1);
  151. finish();
  152. }
  153. }
  154. public static Intent getStartIntent(Context context, @NonNull LicenseInfo licenseInfo, @Nullable UserSurveyInfo userSurveyInfo) {
  155. Intent intent = new Intent(context, LicenseTopActivity.class);
  156. intent.putExtra(KEY_LICENSE_INFO, licenseInfo);
  157. intent.putExtra(KEY_USER_SURVEY_INFO, userSurveyInfo);
  158. return intent;
  159. }
  160. }