api: handle passphrase entering correctly

This commit is contained in:
Dominik Schürmann 2013-09-08 18:30:22 +02:00
parent 03d9afffce
commit 11103623c5
3 changed files with 26 additions and 15 deletions

View File

@ -24,7 +24,6 @@ import org.openintents.crypto.CryptoServiceConnection;
import org.openintents.crypto.CryptoSignatureResult;
import org.openintents.crypto.ICryptoCallback;
import org.openintents.crypto.ICryptoService;
import org.sufficientlysecure.keychain.demo.R;
import org.sufficientlysecure.keychain.integration.Constants;
import android.app.Activity;
@ -35,15 +34,14 @@ import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.RemoteException;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.Scroller;
import android.widget.TextView;
import android.widget.Toast;
public class CryptoProviderDemoActivity extends Activity {
Activity mActivity;
@ -83,15 +81,13 @@ public class CryptoProviderDemoActivity extends Activity {
@Override
public void run() {
mCiphertext.setText(new String(outputBytes));
}
});
}
@Override
public void onError(CryptoError error) throws RemoteException {
Log.e(Constants.TAG, "onError getErrorId:" + error.getErrorId());
Log.e(Constants.TAG, "onError getMessage:" + error.getMessage());
handleError(error);
}
};
@ -116,12 +112,18 @@ public class CryptoProviderDemoActivity extends Activity {
@Override
public void onError(CryptoError error) throws RemoteException {
Log.e(Constants.TAG, "onError getErrorId:" + error.getErrorId());
Log.e(Constants.TAG, "onError getMessage:" + error.getMessage());
handleError(error);
}
};
private void handleError(CryptoError error) {
Toast.makeText(mActivity, "onError id:" + error.getErrorId() + "\n\n" + error.getMessage(),
Toast.LENGTH_LONG).show();
Log.e(Constants.TAG, "onError getErrorId:" + error.getErrorId());
Log.e(Constants.TAG, "onError getMessage:" + error.getMessage());
}
public void encryptOnClick(View view) {
byte[] inputBytes = mMessage.getText().toString().getBytes();

View File

@ -161,7 +161,7 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
try {
mServiceCallback.onRegistered(true, packageName);
} catch (RemoteException e) {
Log.e(Constants.TAG, "ServiceActivity");
Log.e(Constants.TAG, "ServiceActivity", e);
}
finish();
}
@ -174,7 +174,7 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
try {
mServiceCallback.onRegistered(false, packageName);
} catch (RemoteException e) {
Log.e(Constants.TAG, "ServiceActivity");
Log.e(Constants.TAG, "ServiceActivity", e);
}
finish();
}
@ -205,7 +205,7 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
mServiceCallback.onSelectedPublicKeys(mSelectFragment
.getSelectedMasterKeyIds());
} catch (RemoteException e) {
Log.e(Constants.TAG, "ServiceActivity");
Log.e(Constants.TAG, "ServiceActivity", e);
}
finish();
}
@ -219,7 +219,7 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
mServiceCallback.onSelectedPublicKeys(mSelectFragment
.getSelectedMasterKeyIds());
} catch (RemoteException e) {
Log.e(Constants.TAG, "ServiceActivity");
Log.e(Constants.TAG, "ServiceActivity", e);
}
finish();
}
@ -266,14 +266,14 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
try {
mServiceCallback.onCachedPassphrase(true);
} catch (RemoteException e) {
Log.e(Constants.TAG, "ServiceActivity");
Log.e(Constants.TAG, "ServiceActivity", e);
}
finish();
} else {
try {
mServiceCallback.onCachedPassphrase(false);
} catch (RemoteException e) {
Log.e(Constants.TAG, "ServiceActivity");
Log.e(Constants.TAG, "ServiceActivity", e);
}
finish();
}

View File

@ -60,6 +60,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
private static final String ARG_SECRET_KEY_ID = "secret_key_id";
public static final int MESSAGE_OKAY = 1;
public static final int MESSAGE_CANCEL = 2;
private Messenger mMessenger;
private EditText mPassphraseEditText;
@ -215,7 +216,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
@Override
public void onClick(DialogInterface dialog, int id) {
dismiss();
dialog.cancel();
}
});
@ -235,6 +236,14 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
}
}
@Override
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
dismiss();
sendMessageToHandler(MESSAGE_CANCEL);
}
/**
* Associate the "done" button on the soft keyboard with the okay button in the view
*/