UserSurveyInvitationActivity.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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.view.ViewGroup;
  7. import android.widget.Button;
  8. import android.widget.TextView;
  9. import androidx.annotation.NonNull;
  10. import androidx.appcompat.app.AppCompatActivity;
  11. import androidx.appcompat.widget.Toolbar;
  12. import epson.common.Constants;
  13. import epson.print.R;
  14. /**
  15. *
  16. */
  17. public class UserSurveyInvitationActivity extends AppCompatActivity implements SimpleMessageDialogFragment.DialogCallback {
  18. private static final int DIALOG_ID_CHANGE_DIALOG = 1;
  19. private static final String PARAM_DISPLAY_CHANGE_DIALOG = "display_change_dialog";
  20. private static final String PARAM_LICENSE_INFO = "license_info";
  21. private static final String PARAM_USER_SURVEY_INFO = "user_survey_info";
  22. private boolean mDisplayChangeDialog;
  23. private LicenseInfo mLicenseInfo;
  24. private UserSurveyInfo mUserSurveyInfo;
  25. public void onButtonClicked(int i) {
  26. }
  27. protected void onCreate(Bundle bundle) {
  28. UserSurveyInfo userSurveyInfo;
  29. super.onCreate(bundle);
  30. setContentView(R.layout.activity_user_survey_invitation);
  31. setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
  32. setTitle(R.string.GALicense);
  33. Button button = findViewById(R.id.disagreeButton);
  34. button.setOnClickListener(new View.OnClickListener() {
  35. public void onClick(View view) {
  36. finishWithStatus(false);
  37. }
  38. });
  39. Button button2 = (Button) findViewById(R.id.agreeButton);
  40. button2.setOnClickListener(new View.OnClickListener() {
  41. public void onClick(View view) {
  42. finishWithStatus(true);
  43. }
  44. });
  45. ((ViewGroup) findViewById(R.id.privacyStatementViewGroup)).setOnClickListener(new View.OnClickListener() {
  46. public void onClick(View view) {
  47. startPrivacyStatementDisplayActivity();
  48. }
  49. });
  50. TextView textView = (TextView) findViewById(R.id.analytics_content);
  51. mDisplayChangeDialog = false;
  52. Intent intent = getIntent();
  53. if (intent != null) {
  54. mUserSurveyInfo = (UserSurveyInfo) intent.getSerializableExtra(PARAM_USER_SURVEY_INFO);
  55. mLicenseInfo = (LicenseInfo) intent.getSerializableExtra(PARAM_LICENSE_INFO);
  56. String str = null;
  57. UserSurveyInfo userSurveyInfo2 = mUserSurveyInfo;
  58. if (userSurveyInfo2 != null) {
  59. str = userSurveyInfo2.getUserSurveyInvitationText(this);
  60. }
  61. if (str == null) {
  62. str = Util.getStringFromRawResource(getApplicationContext(), R.raw.user_survey);
  63. }
  64. textView.setText(str);
  65. changeButtonText(button2, 1, mUserSurveyInfo, this);
  66. changeButtonText(button, 0, mUserSurveyInfo, this);
  67. updateAppNameText(mLicenseInfo);
  68. mDisplayChangeDialog = intent.getBooleanExtra(PARAM_DISPLAY_CHANGE_DIALOG, false);
  69. if (mDisplayChangeDialog && bundle == null && (userSurveyInfo = mUserSurveyInfo) != null && userSurveyInfo.getResponseStatus(this) == 1) {
  70. showUpdateDialog();
  71. }
  72. }
  73. }
  74. /**
  75. * 跳转到用户隐私协议页面
  76. */
  77. private void startPrivacyStatementDisplayActivity() {
  78. LicenseInfo licenseInfo = mLicenseInfo;
  79. if (licenseInfo != null) {
  80. startActivity(InfoDisplayActivity.getStartIntent(this, licenseInfo, 2));
  81. }
  82. }
  83. private void updateAppNameText(LicenseInfo licenseInfo) {
  84. String applicationName;
  85. if (licenseInfo != null && (applicationName = licenseInfo.getApplicationName(this)) != null) {
  86. ((TextView) findViewById(R.id.appNameText)).setText(applicationName);
  87. }
  88. }
  89. private void showUpdateDialog() {
  90. SimpleMessageDialogFragment.newInstance(getString(R.string.Update_Message) + Constants.BREAK_LINE + getString(R.string.GALicense), 1).show(getSupportFragmentManager(), (String) null);
  91. }
  92. private void changeButtonText(Button button, int i, UserSurveyInfo userSurveyInfo, @NonNull Context context) {
  93. String buttonString;
  94. if (userSurveyInfo != null && (buttonString = userSurveyInfo.getButtonString(context, i)) != null) {
  95. button.setText(buttonString);
  96. }
  97. }
  98. private void finishWithStatus(boolean z) {
  99. UserSurveyInfo userSurveyInfo = mUserSurveyInfo;
  100. if (userSurveyInfo != null) {
  101. userSurveyInfo.setUserSurveyAgreement(this, z);
  102. }
  103. setResult(z ? -1 : 0);
  104. finish();
  105. }
  106. public void onBackPressed() {
  107. if (!mDisplayChangeDialog) {
  108. finishWithStatus(false);
  109. }
  110. }
  111. @NonNull
  112. private static Intent getStartIntent(@NonNull Context context, UserSurveyInfo userSurveyInfo, LicenseInfo licenseInfo, boolean z) {
  113. Intent intent = new Intent(context, UserSurveyInvitationActivity.class);
  114. intent.putExtra(PARAM_USER_SURVEY_INFO, userSurveyInfo);
  115. intent.putExtra(PARAM_DISPLAY_CHANGE_DIALOG, z);
  116. intent.putExtra(PARAM_LICENSE_INFO, licenseInfo);
  117. return intent;
  118. }
  119. @NonNull
  120. static Intent getStartWithDialogIntent(@NonNull Context context, UserSurveyInfo userSurveyInfo, LicenseInfo licenseInfo) {
  121. return getStartIntent(context, userSurveyInfo, licenseInfo, true);
  122. }
  123. @NonNull
  124. public static Intent getStartIntent(@NonNull Context context, @NonNull UserSurveyInfo userSurveyInfo, LicenseInfo licenseInfo) {
  125. return getStartIntent(context, userSurveyInfo, licenseInfo, false);
  126. }
  127. }