2
0

Update Java to match C's internal changes.

This commit is contained in:
Maarten Billemont
2017-09-19 13:45:51 -04:00
parent 70c784db83
commit 35c0431cec
42 changed files with 589 additions and 3034 deletions

View File

@@ -52,10 +52,10 @@ public class EmergencyActivity extends Activity {
private static final int PASSWORD_NOTIFICATION = 0;
public static final int CLIPBOARD_CLEAR_DELAY = 20 /* s */ * MPConstant.MS_PER_S;
private final Preferences preferences = Preferences.get( this );
private final ListeningExecutorService executor = MoreExecutors.listeningDecorator( Executors.newSingleThreadExecutor() );
private final ImmutableList<MPSiteType> allSiteTypes = ImmutableList.copyOf( MPSiteType.forClass( MPSiteTypeClass.Generated ) );
private final ImmutableList<MasterKey.Version> allVersions = ImmutableList.copyOf( MasterKey.Version.values() );
private final Preferences preferences = Preferences.get( this );
private final ListeningExecutorService executor = MoreExecutors.listeningDecorator( Executors.newSingleThreadExecutor() );
private final ImmutableList<MPResultType> allResultTypes = ImmutableList.copyOf( MPResultType.forClass( MPResultTypeClass.Generated ) );
private final ImmutableList<MasterKey.Version> allVersions = ImmutableList.copyOf( MasterKey.Version.values() );
private ListenableFuture<MasterKey> masterKeyFuture;
@@ -71,8 +71,8 @@ public class EmergencyActivity extends Activity {
@BindView(R.id.siteNameField)
EditText siteNameField;
@BindView(R.id.siteTypeButton)
Button siteTypeButton;
@BindView(R.id.resultTypeButton)
Button resultTypeButton;
@BindView(R.id.counterField)
Button siteCounterButton;
@@ -131,15 +131,15 @@ public class EmergencyActivity extends Activity {
updateSitePassword();
}
} );
siteTypeButton.setOnClickListener( new View.OnClickListener() {
resultTypeButton.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(final View v) {
@SuppressWarnings("SuspiciousMethodCalls")
MPSiteType siteType =
allSiteTypes.get( (allSiteTypes.indexOf( siteTypeButton.getTag() ) + 1) % allSiteTypes.size() );
preferences.setDefaultSiteType( siteType );
siteTypeButton.setTag( siteType );
siteTypeButton.setText( siteType.getShortName() );
MPResultType resultType =
allResultTypes.get( (allResultTypes.indexOf( resultTypeButton.getTag() ) + 1) % allResultTypes.size() );
preferences.setDefaultResultType( resultType );
resultTypeButton.setTag( resultType );
resultTypeButton.setText( resultType.getShortName() );
updateSitePassword();
}
} );
@@ -220,9 +220,9 @@ public class EmergencyActivity extends Activity {
forgetPasswordField.setChecked( preferences.isForgetPassword() );
maskPasswordField.setChecked( preferences.isMaskPassword() );
sitePasswordField.setTransformationMethod( preferences.isMaskPassword()? new PasswordTransformationMethod(): null );
MPSiteType defaultSiteType = preferences.getDefaultSiteType();
siteTypeButton.setTag( defaultSiteType );
siteTypeButton.setText( defaultSiteType.getShortName() );
MPResultType defaultResultType = preferences.getDefaultResultType();
resultTypeButton.setTag( defaultResultType );
resultTypeButton.setText( defaultResultType.getShortName() );
MasterKey.Version defaultVersion = preferences.getDefaultVersion();
siteVersionButton.setTag( defaultVersion );
siteVersionButton.setText( defaultVersion.name() );
@@ -313,9 +313,9 @@ public class EmergencyActivity extends Activity {
}
private void updateSitePassword() {
final String siteName = siteNameField.getText().toString();
final MPSiteType type = (MPSiteType) siteTypeButton.getTag();
final UnsignedInteger counter = UnsignedInteger.valueOf( siteCounterButton.getText().toString() );
final String siteName = siteNameField.getText().toString();
final MPResultType type = (MPResultType) resultTypeButton.getTag();
final UnsignedInteger counter = UnsignedInteger.valueOf( siteCounterButton.getText().toString() );
if ((masterKeyFuture == null) || siteName.isEmpty() || (type == null)) {
sitePasswordField.setText( "" );
@@ -332,7 +332,7 @@ public class EmergencyActivity extends Activity {
@Override
public void run() {
try {
sitePassword = masterKeyFuture.get().encode( siteName, type, counter, MPSiteVariant.Password, null );
sitePassword = masterKeyFuture.get().siteResult( siteName, counter, MPKeyPurpose.Password, null, type, null );
runOnUiThread( new Runnable() {
@Override

View File

@@ -38,7 +38,7 @@ public final class Preferences {
private static final String PREF_FORGET_PASSWORD = "forgetPassword";
private static final String PREF_MASK_PASSWORD = "maskPassword";
private static final String PREF_FULL_NAME = "fullName";
private static final String PREF_SITE_TYPE = "siteType";
private static final String PREF_RESULT_TYPE = "resultType";
private static final String PREF_ALGORITHM_VERSION = "algorithmVersion";
private static Preferences instance;
@@ -138,20 +138,20 @@ public final class Preferences {
return prefs().getString( PREF_FULL_NAME, "" );
}
public boolean setDefaultSiteType(@Nonnull final MPSiteType value) {
if (getDefaultSiteType() == value)
public boolean setDefaultResultType(final MPResultType value) {
if (getDefaultResultType() == value)
return false;
prefs().edit().putInt( PREF_SITE_TYPE, value.ordinal() ).apply();
prefs().edit().putInt( PREF_RESULT_TYPE, value.ordinal() ).apply();
return true;
}
@Nonnull
public MPSiteType getDefaultSiteType() {
return MPSiteType.values()[prefs().getInt( PREF_SITE_TYPE, MPSiteType.GeneratedLong.ordinal() )];
public MPResultType getDefaultResultType() {
return MPResultType.values()[prefs().getInt( PREF_RESULT_TYPE, MPResultType.GeneratedLong.ordinal() )];
}
public boolean setDefaultVersion(@Nonnull final MasterKey.Version value) {
public boolean setDefaultVersion(final MasterKey.Version value) {
if (getDefaultVersion() == value)
return false;

View File

@@ -105,7 +105,7 @@
android:id="@id/sitePasswordField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nextFocusForward="@+id/siteTypeButton"
android:nextFocusForward="@+id/resultTypeButton"
android:gravity="center"
android:background="@android:color/transparent"
android:textColor="#FFFFFF"
@@ -157,7 +157,7 @@
android:gravity="center">
<Button
android:id="@id/siteTypeButton"
android:id="@id/resultTypeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
@@ -175,12 +175,12 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:labelFor="@id/siteTypeButton"
android:labelFor="@id/resultTypeButton"
android:gravity="center"
android:background="@android:color/transparent"
android:textSize="12sp"
android:textColor="@android:color/tertiary_text_dark"
android:text="@string/siteType_hint" />
android:text="@string/resultType_hint" />
</LinearLayout>

View File

@@ -8,7 +8,7 @@
<string name="masterPassword_hint">Your master password</string>
<string name="siteName_hint">eg. google.com</string>
<string name="sitePassword_hint">Tap to copy</string>
<string name="siteType_hint">Type</string>
<string name="resultType_hint">Type</string>
<string name="siteCounter_hint">Counter</string>
<string name="siteVersion_hint">Algorithm</string>
<string name="empty" />