AdvancedSettings now automatically opens when creating a new profile

pull/41/head
Michael Schättgen 8 years ago
parent b0450cab8b
commit aaf7dbdb85

@ -16,6 +16,7 @@ import android.view.animation.AlphaAnimation;
import android.view.animation.Animation; import android.view.animation.Animation;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ExpandableListAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.Spinner; import android.widget.Spinner;
@ -49,6 +50,9 @@ public class EditProfileActivity extends AegisActivity {
private Spinner _spinnerDigits; private Spinner _spinnerDigits;
private SpinnerItemSelectedListener _selectedListener = new SpinnerItemSelectedListener(); private SpinnerItemSelectedListener _selectedListener = new SpinnerItemSelectedListener();
private RelativeLayout _advancedSettingsHeader;
private RelativeLayout _advancedSettings;
int _dialogStyle = android.R.style.Theme_Material_Light_Dialog_NoActionBar; int _dialogStyle = android.R.style.Theme_Material_Light_Dialog_NoActionBar;
@Override @Override
@ -83,6 +87,9 @@ public class EditProfileActivity extends AegisActivity {
_spinnerDigits = findViewById(R.id.spinner_digits); _spinnerDigits = findViewById(R.id.spinner_digits);
SpinnerHelper.fillSpinner(this, _spinnerDigits, R.array.otp_digits_array); SpinnerHelper.fillSpinner(this, _spinnerDigits, R.array.otp_digits_array);
_advancedSettingsHeader = findViewById(R.id.accordian_header);
_advancedSettings = findViewById(R.id.expandableLayout);
updateFields(); updateFields();
_textName.addTextChangedListener(_textListener); _textName.addTextChangedListener(_textListener);
@ -99,9 +106,13 @@ public class EditProfileActivity extends AegisActivity {
// update the icon if the text changed // update the icon if the text changed
_textName.addTextChangedListener(new TextWatcher() { _textName.addTextChangedListener(new TextWatcher() {
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { } public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
TextDrawable drawable = TextDrawableHelper.generate(s.toString()); TextDrawable drawable = TextDrawableHelper.generate(s.toString());
@ -109,18 +120,56 @@ public class EditProfileActivity extends AegisActivity {
} }
}); });
_advancedSettingsHeader.setOnClickListener(v -> {
OpenAdvancedSettings();
});
// Automatically open advanced settings since 'Secret' is required.
if(_isNew){
OpenAdvancedSettings();
}
}
private void updateFields() {
DatabaseEntry entry = _profile.getEntry();
_iconView.setImageDrawable(_profile.getDrawable());
_textName.setText(entry.getName());
_textIssuer.setText(entry.getInfo().getIssuer());
_textPeriod.setText(Integer.toString(entry.getInfo().getPeriod()));
byte[] secretBytes = entry.getInfo().getSecret();
if (secretBytes != null) {
char[] secretChars = Base32.encode(secretBytes);
_textSecret.setText(secretChars, 0, secretChars.length);
}
RelativeLayout expandableLayout = findViewById(R.id.expandableLayout); String type = entry.getInfo().getType();
RelativeLayout header=(RelativeLayout) findViewById(R.id.accordian_header); _spinnerType.setSelection(getStringResourceIndex(R.array.otp_types_array, type), false);
String algo = entry.getInfo().getAlgorithm(false);
_spinnerAlgo.setSelection(getStringResourceIndex(R.array.otp_algo_array, algo), false);
String digits = Integer.toString(entry.getInfo().getDigits());
_spinnerDigits.setSelection(getStringResourceIndex(R.array.otp_digits_array, digits), false);
}
//to toggle content
header.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { protected void setPreferredTheme(boolean nightMode) {
if (nightMode) {
_dialogStyle = android.R.style.Theme_Material_Dialog_NoActionBar;
setTheme(R.style.AppTheme_Dark_TransparentActionBar);
} else {
_dialogStyle = android.R.style.Theme_Material_Light_Dialog_NoActionBar;
setTheme(R.style.AppTheme_Default_TransparentActionBar);
}
}
private void OpenAdvancedSettings() {
Animation fadeOut = new AlphaAnimation(1, 0); // the 1, 0 here notifies that we want the opacity to go from opaque (1) to transparent (0) Animation fadeOut = new AlphaAnimation(1, 0); // the 1, 0 here notifies that we want the opacity to go from opaque (1) to transparent (0)
fadeOut.setInterpolator(new AccelerateInterpolator()); fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setDuration(220); // Fadeout duration should be 1000 milli seconds fadeOut.setDuration(220); // Fadeout duration should be 1000 milli seconds
header.startAnimation(fadeOut); _advancedSettingsHeader.startAnimation(fadeOut);
Animation fadeIn = new AlphaAnimation(0, 1); // the 1, 0 here notifies that we want the opacity to go from opaque (1) to transparent (0) Animation fadeIn = new AlphaAnimation(0, 1); // the 1, 0 here notifies that we want the opacity to go from opaque (1) to transparent (0)
fadeIn.setInterpolator(new AccelerateInterpolator()); fadeIn.setInterpolator(new AccelerateInterpolator());
@ -134,8 +183,8 @@ public class EditProfileActivity extends AegisActivity {
@Override @Override
public void onAnimationEnd(Animation animation) { public void onAnimationEnd(Animation animation) {
header.setVisibility(View.GONE); _advancedSettingsHeader.setVisibility(View.GONE);
expandableLayout.startAnimation(fadeIn); _advancedSettings.startAnimation(fadeIn);
} }
@Override @Override
@ -152,7 +201,7 @@ public class EditProfileActivity extends AegisActivity {
@Override @Override
public void onAnimationEnd(Animation animation) { public void onAnimationEnd(Animation animation) {
expandableLayout.setVisibility(View.VISIBLE); _advancedSettings.setVisibility(View.VISIBLE);
} }
@Override @Override
@ -161,43 +210,6 @@ public class EditProfileActivity extends AegisActivity {
} }
}); });
} }
});
}
private void updateFields() {
DatabaseEntry entry = _profile.getEntry();
_iconView.setImageDrawable(_profile.getDrawable());
_textName.setText(entry.getName());
_textIssuer.setText(entry.getInfo().getIssuer());
_textPeriod.setText(Integer.toString(entry.getInfo().getPeriod()));
byte[] secretBytes = entry.getInfo().getSecret();
if (secretBytes != null) {
char[] secretChars = Base32.encode(secretBytes);
_textSecret.setText(secretChars, 0, secretChars.length);
}
String type = entry.getInfo().getType();
_spinnerType.setSelection(getStringResourceIndex(R.array.otp_types_array, type), false);
String algo = entry.getInfo().getAlgorithm(false);
_spinnerAlgo.setSelection(getStringResourceIndex(R.array.otp_algo_array, algo), false);
String digits = Integer.toString(entry.getInfo().getDigits());
_spinnerDigits.setSelection(getStringResourceIndex(R.array.otp_digits_array, digits), false);
}
@Override
protected void setPreferredTheme(boolean nightMode) {
if (nightMode) {
_dialogStyle = android.R.style.Theme_Material_Dialog_NoActionBar;
setTheme(R.style.AppTheme_Dark_TransparentActionBar);
} else {
_dialogStyle = android.R.style.Theme_Material_Light_Dialog_NoActionBar;
setTheme(R.style.AppTheme_Default_TransparentActionBar);
}
}
@Override @Override
public void onBackPressed() { public void onBackPressed() {

Loading…
Cancel
Save