2019-02-07 22:39:33 +01:00
|
|
|
package com.beemdevelopment.aegis.ui;
|
2016-09-29 12:31:55 +02:00
|
|
|
|
|
|
|
import android.os.Bundle;
|
2018-05-09 15:49:32 +02:00
|
|
|
import android.view.WindowManager;
|
2016-09-29 12:31:55 +02:00
|
|
|
|
2019-10-16 22:16:47 +02:00
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
|
2020-05-02 18:51:12 +02:00
|
|
|
import com.beemdevelopment.aegis.AegisApplication;
|
2019-04-04 14:07:36 +02:00
|
|
|
import com.beemdevelopment.aegis.Preferences;
|
|
|
|
import com.beemdevelopment.aegis.R;
|
2020-06-07 13:54:38 +02:00
|
|
|
import com.beemdevelopment.aegis.ui.slides.SecuritySetupSlide;
|
|
|
|
import com.beemdevelopment.aegis.ui.slides.SecurityPickerSlide;
|
2019-12-25 19:21:34 +01:00
|
|
|
import com.beemdevelopment.aegis.vault.Vault;
|
|
|
|
import com.beemdevelopment.aegis.vault.VaultFile;
|
|
|
|
import com.beemdevelopment.aegis.vault.VaultFileCredentials;
|
|
|
|
import com.beemdevelopment.aegis.vault.VaultFileException;
|
|
|
|
import com.beemdevelopment.aegis.vault.VaultManager;
|
|
|
|
import com.beemdevelopment.aegis.vault.VaultManagerException;
|
2020-05-05 19:14:10 +02:00
|
|
|
import com.github.appintro.AppIntro2;
|
|
|
|
import com.github.appintro.AppIntroFragment;
|
|
|
|
import com.github.appintro.model.SliderPage;
|
2017-08-06 16:03:36 +02:00
|
|
|
|
2018-02-13 22:06:24 +01:00
|
|
|
import org.json.JSONObject;
|
|
|
|
|
2020-05-02 18:51:12 +02:00
|
|
|
public class IntroActivity extends AppIntro2 {
|
2020-06-07 13:54:38 +02:00
|
|
|
private SecuritySetupSlide securitySetupSlide;
|
|
|
|
private SecurityPickerSlide _securityPickerSlide;
|
2017-08-26 21:15:53 +02:00
|
|
|
private Fragment _endSlide;
|
2016-09-29 12:31:55 +02:00
|
|
|
|
2020-05-02 18:51:12 +02:00
|
|
|
private AegisApplication _app;
|
2018-05-11 20:08:51 +02:00
|
|
|
private Preferences _prefs;
|
2017-12-23 22:33:32 +01:00
|
|
|
|
2016-09-29 12:31:55 +02:00
|
|
|
@Override
|
2017-08-13 19:51:54 +02:00
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
2016-09-29 12:31:55 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
2017-12-23 22:33:32 +01:00
|
|
|
|
2020-05-02 18:51:12 +02:00
|
|
|
_app = (AegisApplication) getApplication();
|
2018-05-09 15:49:32 +02:00
|
|
|
// set FLAG_SECURE on the window of every IntroActivity
|
2018-05-11 20:08:51 +02:00
|
|
|
_prefs = new Preferences(this);
|
|
|
|
if (_prefs.isSecureScreenEnabled()) {
|
2018-05-11 19:33:20 +02:00
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
|
|
|
|
}
|
2018-05-09 15:49:32 +02:00
|
|
|
|
2018-06-06 18:01:35 +02:00
|
|
|
setWizardMode(true);
|
2020-05-05 19:14:10 +02:00
|
|
|
setSkipButtonEnabled(false);
|
|
|
|
showStatusBar(true);
|
|
|
|
setSystemBackButtonLocked(true);
|
2018-09-18 23:56:25 +02:00
|
|
|
setBarColor(getResources().getColor(R.color.colorPrimary));
|
2017-08-13 19:51:54 +02:00
|
|
|
|
|
|
|
SliderPage homeSliderPage = new SliderPage();
|
2018-10-09 23:13:51 +02:00
|
|
|
homeSliderPage.setTitle(getString(R.string.welcome));
|
2019-09-06 23:58:04 +02:00
|
|
|
homeSliderPage.setImageDrawable(R.drawable.app_icon);
|
2018-09-18 23:56:25 +02:00
|
|
|
homeSliderPage.setTitleColor(getResources().getColor(R.color.primary_text_dark));
|
2018-10-09 23:13:51 +02:00
|
|
|
homeSliderPage.setDescription(getString(R.string.app_description));
|
2020-05-05 19:14:10 +02:00
|
|
|
homeSliderPage.setDescriptionColor(getResources().getColor(R.color.primary_text_dark));
|
|
|
|
homeSliderPage.setBackgroundColor(getResources().getColor(R.color.colorSecondary));
|
2017-08-13 19:51:54 +02:00
|
|
|
addSlide(AppIntroFragment.newInstance(homeSliderPage));
|
|
|
|
|
2020-06-07 13:54:38 +02:00
|
|
|
_securityPickerSlide = new SecurityPickerSlide();
|
|
|
|
_securityPickerSlide.setBgColor(getResources().getColor(R.color.colorSecondary));
|
|
|
|
addSlide(_securityPickerSlide);
|
|
|
|
securitySetupSlide = new SecuritySetupSlide();
|
|
|
|
securitySetupSlide.setBgColor(getResources().getColor(R.color.colorSecondary));
|
|
|
|
addSlide(securitySetupSlide);
|
2017-08-06 16:03:36 +02:00
|
|
|
|
2017-08-13 19:51:54 +02:00
|
|
|
SliderPage endSliderPage = new SliderPage();
|
2018-10-09 23:13:51 +02:00
|
|
|
endSliderPage.setTitle(getString(R.string.setup_completed));
|
|
|
|
endSliderPage.setDescription(getString(R.string.setup_completed_description));
|
2019-09-06 23:58:04 +02:00
|
|
|
endSliderPage.setImageDrawable(R.drawable.app_icon);
|
2020-05-05 19:14:10 +02:00
|
|
|
endSliderPage.setBackgroundColor(getResources().getColor(R.color.colorSecondary));
|
2017-08-26 21:15:53 +02:00
|
|
|
_endSlide = AppIntroFragment.newInstance(endSliderPage);
|
|
|
|
addSlide(_endSlide);
|
2017-08-13 19:51:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSlideChanged(Fragment oldFragment, Fragment newFragment) {
|
2020-06-07 13:54:38 +02:00
|
|
|
if (oldFragment == _securityPickerSlide && newFragment != _endSlide) {
|
2017-11-27 19:22:10 +01:00
|
|
|
// skip to the last slide if no encryption will be used
|
2020-06-07 13:54:38 +02:00
|
|
|
int cryptType = getIntent().getIntExtra("cryptType", SecurityPickerSlide.CRYPT_TYPE_INVALID);
|
|
|
|
if (cryptType == SecurityPickerSlide.CRYPT_TYPE_NONE) {
|
2017-08-13 19:51:54 +02:00
|
|
|
// TODO: no magic indices
|
2020-05-05 19:14:10 +02:00
|
|
|
goToNextSlide(false);
|
2017-08-13 19:51:54 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-05 19:14:10 +02:00
|
|
|
|
2020-06-07 18:10:56 +02:00
|
|
|
if (newFragment == _endSlide) {
|
|
|
|
setWizardMode(false);
|
|
|
|
}
|
|
|
|
|
2020-05-05 19:14:10 +02:00
|
|
|
setSwipeLock(true);
|
2016-09-29 12:31:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-13 19:51:54 +02:00
|
|
|
public void onDonePressed(Fragment currentFragment) {
|
|
|
|
super.onDonePressed(currentFragment);
|
2017-12-10 19:22:00 +01:00
|
|
|
|
2020-06-07 13:54:38 +02:00
|
|
|
int cryptType = securitySetupSlide.getCryptType();
|
|
|
|
VaultFileCredentials creds = securitySetupSlide.getCredentials();
|
2017-08-06 16:03:36 +02:00
|
|
|
|
2020-05-02 18:51:12 +02:00
|
|
|
Vault vault = new Vault();
|
|
|
|
VaultFile vaultFile = new VaultFile();
|
2017-08-06 16:03:36 +02:00
|
|
|
try {
|
2020-05-02 18:51:12 +02:00
|
|
|
JSONObject obj = vault.toJson();
|
2020-06-07 13:54:38 +02:00
|
|
|
if (cryptType == SecurityPickerSlide.CRYPT_TYPE_NONE) {
|
2020-05-02 18:51:12 +02:00
|
|
|
vaultFile.setContent(obj);
|
2017-08-06 21:45:27 +02:00
|
|
|
} else {
|
2020-05-02 18:51:12 +02:00
|
|
|
vaultFile.setContent(obj, creds);
|
2017-08-06 21:45:27 +02:00
|
|
|
}
|
2020-05-02 18:51:12 +02:00
|
|
|
|
|
|
|
VaultManager.save(getApplicationContext(), vaultFile);
|
2019-12-25 19:21:34 +01:00
|
|
|
} catch (VaultManagerException | VaultFileException e) {
|
2020-05-02 18:51:12 +02:00
|
|
|
e.printStackTrace();
|
|
|
|
Dialogs.showErrorDialog(this, R.string.vault_init_error, e);
|
2017-08-06 16:03:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-07 13:54:38 +02:00
|
|
|
if (cryptType == SecurityPickerSlide.CRYPT_TYPE_NONE) {
|
2020-05-25 16:19:07 +02:00
|
|
|
_app.initVaultManager(vault, null);
|
|
|
|
} else {
|
|
|
|
_app.initVaultManager(vault, creds);
|
|
|
|
}
|
2017-08-06 16:03:36 +02:00
|
|
|
|
|
|
|
// skip the intro from now on
|
2018-05-11 20:08:51 +02:00
|
|
|
_prefs.setIntroDone(true);
|
2020-05-02 18:51:12 +02:00
|
|
|
|
|
|
|
setResult(RESULT_OK);
|
2017-08-13 19:51:54 +02:00
|
|
|
finish();
|
2016-09-29 12:31:55 +02:00
|
|
|
}
|
2017-11-27 19:22:10 +01:00
|
|
|
|
2020-05-02 18:51:12 +02:00
|
|
|
public void goToNextSlide() {
|
|
|
|
super.goToNextSlide(false);
|
2017-11-27 19:22:10 +01:00
|
|
|
}
|
2016-09-29 12:31:55 +02:00
|
|
|
}
|