mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-17 21:02:17 -05:00
integrate share activity in view activity
This commit is contained in:
parent
bc0edfda0b
commit
9576aeabca
@ -351,7 +351,6 @@
|
|||||||
<data android:mimeType="application/pgp-keys" />
|
<data android:mimeType="application/pgp-keys" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name=".ui.ShareActivity" />
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.HelpActivity"
|
android:name=".ui.HelpActivity"
|
||||||
android:label="@string/title_help" />
|
android:label="@string/title_help" />
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui;
|
package org.sufficientlysecure.keychain.ui;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -29,20 +30,21 @@ import org.sufficientlysecure.keychain.Id;
|
|||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.ShareQrCodeDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.ContactsContract.DataUsageFeedback;
|
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockActivity;
|
import com.actionbarsherlock.app.SherlockActivity;
|
||||||
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
import com.actionbarsherlock.view.Menu;
|
import com.actionbarsherlock.view.Menu;
|
||||||
import com.actionbarsherlock.view.MenuItem;
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
|
||||||
public class KeyViewActivity extends SherlockActivity {
|
public class KeyViewActivity extends SherlockFragmentActivity {
|
||||||
private Uri mDataUri;
|
private Uri mDataUri;
|
||||||
|
|
||||||
private PGPPublicKey mPublicKey;
|
private PGPPublicKey mPublicKey;
|
||||||
@ -136,32 +138,19 @@ public class KeyViewActivity extends SherlockActivity {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_key_view_export_file:
|
case R.id.menu_key_view_export_file:
|
||||||
// long masterKeyId = ProviderHelper.getPublicMasterKeyId(mKeyListActivity, keyRingRowId);
|
// long masterKeyId = ProviderHelper.getPublicMasterKeyId(mKeyListActivity,
|
||||||
// if (masterKeyId == -1) {
|
// keyRingRowId);
|
||||||
// masterKeyId = ProviderHelper.getSecretMasterKeyId(mKeyListActivity, keyRingRowId);
|
// if (masterKeyId == -1) {
|
||||||
// }
|
// masterKeyId = ProviderHelper.getSecretMasterKeyId(mKeyListActivity, keyRingRowId);
|
||||||
//
|
// }
|
||||||
// mKeyListActivity.showExportKeysDialog(masterKeyId);
|
//
|
||||||
|
// mKeyListActivity.showExportKeysDialog(masterKeyId);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_key_view_share:
|
case R.id.menu_key_view_share:
|
||||||
// get master key id using row id
|
shareKey();
|
||||||
long masterKeyId3 = ProviderHelper.getPublicMasterKeyId(this, keyRingRowId);
|
|
||||||
|
|
||||||
Intent shareIntent = new Intent(this, ShareActivity.class);
|
|
||||||
shareIntent.setAction(ShareActivity.ACTION_SHARE_KEYRING);
|
|
||||||
shareIntent.putExtra(ShareActivity.EXTRA_MASTER_KEY_ID, masterKeyId3);
|
|
||||||
startActivityForResult(shareIntent, 0);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_key_view_share_qr_code:
|
case R.id.menu_key_view_share_qr_code:
|
||||||
// get master key id using row id
|
shareKeyQrCode();
|
||||||
long masterKeyId = ProviderHelper.getPublicMasterKeyId(this, keyRingRowId);
|
|
||||||
|
|
||||||
Intent qrCodeIntent = new Intent(this, ShareActivity.class);
|
|
||||||
qrCodeIntent.setAction(ShareActivity.ACTION_SHARE_KEYRING_WITH_QR_CODE);
|
|
||||||
qrCodeIntent.putExtra(ShareActivity.EXTRA_MASTER_KEY_ID, masterKeyId);
|
|
||||||
startActivityForResult(qrCodeIntent, 0);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_key_view_share_nfc:
|
case R.id.menu_key_view_share_nfc:
|
||||||
// get master key id using row id
|
// get master key id using row id
|
||||||
@ -174,7 +163,7 @@ public class KeyViewActivity extends SherlockActivity {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_key_view_delete:
|
case R.id.menu_key_view_delete:
|
||||||
// mKeyListActivity.showDeleteKeyDialog(keyRingRowId);
|
// mKeyListActivity.showDeleteKeyDialog(keyRingRowId);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -225,4 +214,34 @@ public class KeyViewActivity extends SherlockActivity {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void shareKey() {
|
||||||
|
// TODO: use data uri!
|
||||||
|
long keyRingRowId = Long.valueOf(mDataUri.getLastPathSegment());
|
||||||
|
long masterKeyId = ProviderHelper.getPublicMasterKeyId(this, keyRingRowId);
|
||||||
|
|
||||||
|
// get public keyring as ascii armored string
|
||||||
|
ArrayList<String> keyringArmored = ProviderHelper.getPublicKeyRingsAsArmoredString(this,
|
||||||
|
new long[] { masterKeyId });
|
||||||
|
|
||||||
|
// let user choose application
|
||||||
|
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
||||||
|
sendIntent.putExtra(Intent.EXTRA_TEXT, keyringArmored.get(0));
|
||||||
|
sendIntent.setType("text/plain");
|
||||||
|
startActivity(Intent.createChooser(sendIntent,
|
||||||
|
getResources().getText(R.string.action_share_key_with)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void shareKeyQrCode() {
|
||||||
|
// TODO: use data uri!
|
||||||
|
long keyRingRowId = Long.valueOf(mDataUri.getLastPathSegment());
|
||||||
|
long masterKeyId = ProviderHelper.getPublicMasterKeyId(this, keyRingRowId);
|
||||||
|
// get public keyring as ascii armored string
|
||||||
|
ArrayList<String> keyringArmored = ProviderHelper.getPublicKeyRingsAsArmoredString(this,
|
||||||
|
new long[] { masterKeyId });
|
||||||
|
|
||||||
|
ShareQrCodeDialogFragment dialog = ShareQrCodeDialogFragment.newInstance(keyringArmored
|
||||||
|
.get(0));
|
||||||
|
dialog.show(getSupportFragmentManager(), "qrCodeShareDialog");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.sufficientlysecure.keychain.ui;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.ShareQrCodeDialogFragment;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
|
||||||
|
|
||||||
public class ShareActivity extends SherlockFragmentActivity {
|
|
||||||
// Actions for internal use only:
|
|
||||||
public static final String ACTION_SHARE_KEYRING = Constants.INTENT_PREFIX + "SHARE_KEYRING";
|
|
||||||
public static final String ACTION_SHARE_KEYRING_WITH_QR_CODE = Constants.INTENT_PREFIX
|
|
||||||
+ "SHARE_KEYRING_WITH_QR_CODE";
|
|
||||||
|
|
||||||
public static final String EXTRA_MASTER_KEY_ID = "master_key_id";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
handleActions(getIntent());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void handleActions(Intent intent) {
|
|
||||||
String action = intent.getAction();
|
|
||||||
Bundle extras = intent.getExtras();
|
|
||||||
|
|
||||||
if (extras == null) {
|
|
||||||
extras = new Bundle();
|
|
||||||
}
|
|
||||||
|
|
||||||
long masterKeyId = extras.getLong(EXTRA_MASTER_KEY_ID);
|
|
||||||
|
|
||||||
// get public keyring as ascii armored string
|
|
||||||
ArrayList<String> keyringArmored = ProviderHelper.getPublicKeyRingsAsArmoredString(this,
|
|
||||||
new long[] { masterKeyId });
|
|
||||||
|
|
||||||
if (ACTION_SHARE_KEYRING.equals(action)) {
|
|
||||||
// let user choose application
|
|
||||||
Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
|
||||||
sendIntent.putExtra(Intent.EXTRA_TEXT, keyringArmored.get(0));
|
|
||||||
sendIntent.setType("text/plain");
|
|
||||||
startActivity(Intent.createChooser(sendIntent,
|
|
||||||
getResources().getText(R.string.action_share_key_with)));
|
|
||||||
} else if (ACTION_SHARE_KEYRING_WITH_QR_CODE.equals(action)) {
|
|
||||||
ShareQrCodeDialogFragment dialog = ShareQrCodeDialogFragment.newInstance(keyringArmored
|
|
||||||
.get(0));
|
|
||||||
dialog.show(getSupportFragmentManager(), "qrCodeShareDialog");
|
|
||||||
}
|
|
||||||
|
|
||||||
// close this activity
|
|
||||||
// TODO: finish() would also close dialog...
|
|
||||||
// integrate this into new KeyViewActivity when ready
|
|
||||||
// finish();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user