Support fragments in api lib, bug fixes

This commit is contained in:
Dominik Schürmann 2012-12-21 14:19:38 +01:00
parent 07349ad416
commit 0ea0d516a1
6 changed files with 133 additions and 12 deletions

Binary file not shown.

View File

@ -22,7 +22,8 @@ import java.util.Arrays;
public class ApgData implements Serializable { public class ApgData implements Serializable {
private static final long serialVersionUID = 6314045536270848410L; private static final long serialVersionUID = 6314045536270848410L;
protected long mPublicKeyIds[] = null; protected long[] mPublicKeyIds = null;
protected String[] mPublicUserIds = null;
protected long mSecretKeyId = 0; protected long mSecretKeyId = 0;
protected String mSecretKeyUserId = null; protected String mSecretKeyUserId = null;
protected boolean mSignatureSuccess = false; protected boolean mSignatureSuccess = false;
@ -38,7 +39,7 @@ public class ApgData implements Serializable {
return mSecretKeyId; return mSecretKeyId;
} }
public void setPublicKeys(long keyIds[]) { public void setPublicKeyIds(long[] keyIds) {
mPublicKeyIds = keyIds; mPublicKeyIds = keyIds;
} }
@ -46,6 +47,14 @@ public class ApgData implements Serializable {
return mPublicKeyIds; return mPublicKeyIds;
} }
public void setPublicUserIds(String[] userIds) {
mPublicUserIds = userIds;
}
public String[] getPublicUserIds() {
return mPublicUserIds;
}
public boolean hasSecretKey() { public boolean hasSecretKey() {
return mSecretKeyId != 0; return mSecretKeyId != 0;
} }

View File

@ -112,6 +112,22 @@ public class ApgIntentHelper {
this.activity = activity; this.activity = activity;
} }
/**
* Start an activity.<br>
* This method is defined to allow different methods of activity starting for newer versions of
* Android and for compatibility library.
*
* @param intent
* Intent to start.
* @param code
* Request code for the activity
* @see android.app.Activity#startActivityForResult(Intent, int)
* @see android.app.Fragment#startActivityForResult(Intent, int)
*/
protected void startActivityForResult(Intent intent, int code) {
startActivityForResult(intent, code);
}
/** /**
* Open activity to scan qr code and import key in it * Open activity to scan qr code and import key in it
* *
@ -121,7 +137,7 @@ public class ApgIntentHelper {
Intent intent = new Intent(ACTION_SCAN_QR_CODE); Intent intent = new Intent(ACTION_SCAN_QR_CODE);
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION); intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
try { try {
activity.startActivityForResult(intent, -1); startActivityForResult(intent, -1);
return true; return true;
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
activityNotFound(); activityNotFound();
@ -146,7 +162,7 @@ public class ApgIntentHelper {
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION); intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
try { try {
activity.startActivityForResult(intent, CREATE_KEY); startActivityForResult(intent, CREATE_KEY);
return true; return true;
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
activityNotFound(); activityNotFound();
@ -174,7 +190,7 @@ public class ApgIntentHelper {
intent.putExtra(EXTRA_KEY_ID, keyId); intent.putExtra(EXTRA_KEY_ID, keyId);
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION); intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
try { try {
activity.startActivityForResult(intent, EDIT_KEY); startActivityForResult(intent, EDIT_KEY);
return true; return true;
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
activityNotFound(); activityNotFound();
@ -191,7 +207,7 @@ public class ApgIntentHelper {
Intent intent = new Intent(ACTION_SELECT_SECRET_KEY); Intent intent = new Intent(ACTION_SELECT_SECRET_KEY);
intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION); intent.putExtra(EXTRA_INTENT_VERSION, INTENT_VERSION);
try { try {
activity.startActivityForResult(intent, SELECT_SECRET_KEY); startActivityForResult(intent, SELECT_SECRET_KEY);
return true; return true;
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
activityNotFound(); activityNotFound();
@ -225,7 +241,7 @@ public class ApgIntentHelper {
intent.putExtra(EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds); intent.putExtra(EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds);
intent.putExtra(EXTRA_SIGNATURE_KEY_ID, signatureKeyId); intent.putExtra(EXTRA_SIGNATURE_KEY_ID, signatureKeyId);
try { try {
activity.startActivityForResult(intent, ENCRYPT_MESSAGE); startActivityForResult(intent, ENCRYPT_MESSAGE);
return true; return true;
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
activityNotFound(); activityNotFound();
@ -255,7 +271,7 @@ public class ApgIntentHelper {
} }
try { try {
intent.putExtra(EXTRA_TEXT, data); intent.putExtra(EXTRA_TEXT, data);
activity.startActivityForResult(intent, DECRYPT_MESSAGE); startActivityForResult(intent, DECRYPT_MESSAGE);
return true; return true;
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
activityNotFound(); activityNotFound();
@ -294,15 +310,16 @@ public class ApgIntentHelper {
break; break;
case SELECT_PUBLIC_KEYS: case SELECT_PUBLIC_KEYS:
if (resultCode != Activity.RESULT_OK || data == null) { if (resultCode != Activity.RESULT_OK || data == null) {
apgData.setPublicKeys(null); apgData.setPublicKeyIds(null);
break; break;
} }
apgData.setPublicKeys(data.getLongArrayExtra(RESULT_EXTRA_MASTER_KEY_IDS)); apgData.setPublicKeyIds(data.getLongArrayExtra(RESULT_EXTRA_MASTER_KEY_IDS));
apgData.setPublicUserIds(data.getStringArrayExtra(RESULT_EXTRA_USER_IDS));
break; break;
case ENCRYPT_MESSAGE: case ENCRYPT_MESSAGE:
if (resultCode != Activity.RESULT_OK || data == null) { if (resultCode != Activity.RESULT_OK || data == null) {
apgData.setPublicKeys(null); apgData.setPublicKeyIds(null);
break; break;
} }
apgData.setEncryptedData(data.getStringExtra(EXTRA_ENCRYPTED_MESSAGE)); apgData.setEncryptedData(data.getStringExtra(EXTRA_ENCRYPTED_MESSAGE));
@ -363,7 +380,7 @@ public class ApgIntentHelper {
intent.putExtra(EXTRA_SELECTION, initialKeyIds); intent.putExtra(EXTRA_SELECTION, initialKeyIds);
try { try {
activity.startActivityForResult(intent, SELECT_PUBLIC_KEYS); startActivityForResult(intent, SELECT_PUBLIC_KEYS);
return true; return true;
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
activityNotFound(); activityNotFound();

View File

@ -0,0 +1,43 @@
/*
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thialfihar.android.apg.integration;
import android.content.Intent;
import android.support.v4.app.Fragment;
/**
* ApgIntentHelper for the V4 Android compatibility package.
*/
public final class ApgIntentHelperSupportV4 extends ApgIntentHelper {
private final Fragment fragment;
/**
* @param fragment
* Fragment to handle activity response.
*/
public ApgIntentHelperSupportV4(Fragment fragment) {
super(fragment.getActivity());
this.fragment = fragment;
}
@Override
protected void startActivityForResult(Intent intent, int code) {
fragment.startActivityForResult(intent, code);
}
}

View File

@ -0,0 +1,46 @@
/*
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thialfihar.android.apg.integration;
import android.annotation.TargetApi;
import android.app.Fragment;
import android.content.Intent;
import android.os.Build;
/**
* ApgIntentHelper for Android version 3.0 and beyond.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public final class ApgIntentHelperV30 extends ApgIntentHelper {
private final Fragment fragment;
/**
* @param fragment
* Fragment to handle activity response.
*/
public ApgIntentHelperV30(Fragment fragment) {
super(fragment.getActivity());
this.fragment = fragment;
}
@Override
protected void startActivityForResult(Intent intent, int code) {
fragment.startActivityForResult(intent, code);
}
}

View File

@ -115,6 +115,9 @@ public class ApgProvider extends ContentProvider {
+ ApgContract.PATH_BY_KEY_ID + "/*", PUBLIC_KEY_RING_BY_KEY_ID); + ApgContract.PATH_BY_KEY_ID + "/*", PUBLIC_KEY_RING_BY_KEY_ID);
matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_PUBLIC + "/" matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_PUBLIC + "/"
+ ApgContract.PATH_BY_EMAILS + "/*", PUBLIC_KEY_RING_BY_EMAILS); + ApgContract.PATH_BY_EMAILS + "/*", PUBLIC_KEY_RING_BY_EMAILS);
matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_PUBLIC + "/"
+ ApgContract.PATH_BY_EMAILS, PUBLIC_KEY_RING_BY_EMAILS); // without emails
// specified
matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_PUBLIC + "/" matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_PUBLIC + "/"
+ ApgContract.PATH_BY_LIKE_EMAIL + "/*", PUBLIC_KEY_RING_BY_LIKE_EMAIL); + ApgContract.PATH_BY_LIKE_EMAIL + "/*", PUBLIC_KEY_RING_BY_LIKE_EMAIL);
@ -167,6 +170,9 @@ public class ApgProvider extends ContentProvider {
+ ApgContract.PATH_BY_KEY_ID + "/*", SECRET_KEY_RING_BY_KEY_ID); + ApgContract.PATH_BY_KEY_ID + "/*", SECRET_KEY_RING_BY_KEY_ID);
matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_SECRET + "/" matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_SECRET + "/"
+ ApgContract.PATH_BY_EMAILS + "/*", SECRET_KEY_RING_BY_EMAILS); + ApgContract.PATH_BY_EMAILS + "/*", SECRET_KEY_RING_BY_EMAILS);
matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_SECRET + "/"
+ ApgContract.PATH_BY_EMAILS, SECRET_KEY_RING_BY_EMAILS); // without emails
// specified
matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_SECRET + "/" matcher.addURI(authority, ApgContract.BASE_KEY_RINGS + "/" + ApgContract.PATH_SECRET + "/"
+ ApgContract.PATH_BY_LIKE_EMAIL + "/*", SECRET_KEY_RING_BY_LIKE_EMAIL); + ApgContract.PATH_BY_LIKE_EMAIL + "/*", SECRET_KEY_RING_BY_LIKE_EMAIL);