123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- package com.epson.mobilephone.common.license;
- import android.content.Context;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- import androidx.annotation.NonNull;
- import androidx.annotation.Nullable;
- import androidx.appcompat.app.AppCompatActivity;
- import epson.common.Constants;
- import epson.print.R;
- /**
- * 用户协议
- */
- public class LicenseTopActivity extends AppCompatActivity implements SimpleMessageDialogFragment.DialogCallback {
- private static final String DIALOG_ID = "dialog";
- private static final int DIALOG_ID_DISAGREE = 2;
- private static final int DIALOG_ID_NEW_LICENSE = 1;
- private static final String KEY_LICENSE_INFO = "license_info";
- private static final String KEY_USER_SURVEY_INFO = "user_survey_info";
- private static final int REQUEST_CODE_USER_SURVEY_INVITATION = 2;
- private LicenseInfo mLicenseInfo;
- private UserSurveyInfo mUserSurveyInfo;
- public void onBackPressed() {
- }
- protected void onCreate(Bundle bundle) {
- super.onCreate(bundle);
- setContentView(R.layout.activity_license_top);
- findViewById(R.id.licenseViewGroup).setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- startDocumentDisplayActivity(1);
- }
- });
- findViewById(R.id.privacyStatementViewGroup).setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- startDocumentDisplayActivity(2);
- }
- });
- ((Button) findViewById(R.id.agreeButton)).setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- onAgree();
- }
- });
- ((Button) findViewById(R.id.disagreeButton)).setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- onDisagree();
- }
- });
- if (!initField(getIntent())) {
- setResult(0);
- finish();
- return;
- }
- ((TextView) findViewById(R.id.appNameText)).setText(mLicenseInfo.getApplicationName(this));
- if (bundle == null) {
- showLicenseChangeDialogIfNeeded(this, mLicenseInfo, mUserSurveyInfo);
- }
- }
- private boolean initField(Intent intent) {
- if (intent == null) {
- return false;
- }
- mLicenseInfo = (LicenseInfo) intent.getSerializableExtra(KEY_LICENSE_INFO);
- if (mLicenseInfo == null) {
- return false;
- }
- mUserSurveyInfo = (UserSurveyInfo) intent.getSerializableExtra(KEY_USER_SURVEY_INFO);
- return true;
- }
- private void showLicenseChangeDialogIfNeeded(@NonNull Context context, @NonNull LicenseInfo licenseInfo, UserSurveyInfo userSurveyInfo) {
- String str;
- switch (licenseInfo.getLicenseAgreement(context)) {
- case 0:
- str = getString(R.string.EULA_Title) + Constants.BREAK_LINE + getString(R.string.Privacy_Statement_Title);
- break;
- case 1:
- str = getString(R.string.EULA_Title);
- break;
- case 2:
- str = getString(R.string.Privacy_Statement_Title);
- break;
- case 3:
- setResult(-1);
- if (userSurveyInfo == null || userSurveyInfo.getResponseStatus(context) >= 2) {
- finish();
- return;
- } else {
- startUserSurveyInvitationActivity();
- return;
- }
- default:
- return;
- }
- SimpleMessageDialogFragment.newInstance(getString(R.string.Update_Message) + Constants.BREAK_LINE + str, 1).show(getSupportFragmentManager(), DIALOG_ID);
- }
- /**
- * 同意点击事件
- */
- private void onAgree() {
- LicenseInfo licenseInfo = mLicenseInfo;
- if (licenseInfo == null) {
- finish();
- return;
- }
- licenseInfo.setLicenceAgreement(this);
- setResult(-1);
- startUserSurveyInvitationActivity();
- }
- private void startUserSurveyInvitationActivity() {
- if (mLicenseInfo == null) {
- finish();
- return;
- }
- UserSurveyInfo userSurveyInfo = mUserSurveyInfo;
- if (userSurveyInfo == null) {
- finish();
- } else if (userSurveyInfo.getResponseStatus(this) >= 2) {
- finish();
- } else {
- startActivityForResult(UserSurveyInvitationActivity.getStartWithDialogIntent(this, mUserSurveyInfo, mLicenseInfo), 2);
- }
- }
- /**
- * 不同意则弹框确认
- */
- private void onDisagree() {
- SimpleMessageDialogFragment.newInstance(getString(R.string.Disagree_License_Button_Message), 2).show(getSupportFragmentManager(), DIALOG_ID);
- }
- /**
- * 跳转到 用户协议/隐私协议 页面
- *
- * @param i
- */
- private void startDocumentDisplayActivity(int i) {
- LicenseInfo licenseInfo = mLicenseInfo;
- if (licenseInfo != null) {
- startActivity(InfoDisplayActivity.getStartIntent(this, licenseInfo, i));
- }
- }
- /**
- * 实现点击事件
- *
- * @param i
- */
- @Override
- public void onButtonClicked(int i) {
- switch (i) {
- case 1:
- return;
- case 2:
- setResult(0);
- finish(); //不同意退出app
- return;
- default:
- return;
- }
- }
- protected void onActivityResult(int i, int i2, Intent intent) {
- super.onActivityResult(i, i2, intent);
- if (i == 2) {
- setResult(-1);
- finish();
- }
- }
- public static Intent getStartIntent(Context context, @NonNull LicenseInfo licenseInfo, @Nullable UserSurveyInfo userSurveyInfo) {
- Intent intent = new Intent(context, LicenseTopActivity.class);
- intent.putExtra(KEY_LICENSE_INFO, licenseInfo);
- intent.putExtra(KEY_USER_SURVEY_INFO, userSurveyInfo);
- return intent;
- }
- }
|