mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-17 07:30:14 -05:00
introduced a general application to handle certain Intents, only to hand them to other APG Activities after looking at the content of the passed data
This commit is contained in:
parent
a85ae5e009
commit
a089dbbb73
@ -96,18 +96,6 @@
|
|||||||
android:label="@string/title_decrypt"
|
android:label="@string/title_decrypt"
|
||||||
android:configChanges="keyboardHidden|orientation|keyboard">
|
android:configChanges="keyboardHidden|orientation|keyboard">
|
||||||
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.VIEW" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
|
||||||
<data android:mimeType="text/*"/>
|
|
||||||
</intent-filter>
|
|
||||||
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.SEND" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
|
||||||
<data android:mimeType="text/*"/>
|
|
||||||
</intent-filter>
|
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="org.thialfihar.android.apg.intent.DECRYPT" />
|
<action android:name="org.thialfihar.android.apg.intent.DECRYPT" />
|
||||||
<action android:name="org.thialfihar.android.apg.intent.DECRYPT_FILE" />
|
<action android:name="org.thialfihar.android.apg.intent.DECRYPT_FILE" />
|
||||||
@ -118,6 +106,20 @@
|
|||||||
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".GeneralActivity"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:configChanges="keyboardHidden|orientation|keyboard"
|
||||||
|
android:theme="@android:style/Theme.Dialog">
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT"/>
|
||||||
|
<data android:mimeType="*/*"/>
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".MailListActivity"
|
android:name=".MailListActivity"
|
||||||
android:label="@string/title_mailInbox"
|
android:label="@string/title_mailInbox"
|
||||||
|
44
res/layout/general.xml
Normal file
44
res/layout/general.xml
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/options"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="0dip"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:padding="5dip"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
style="@android:style/ButtonBar">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:text="dummy"
|
||||||
|
android:layout_width="0dip"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:visibility="invisible"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btn_cancel"
|
||||||
|
android:text="@android:string/cancel"
|
||||||
|
android:layout_width="0dip"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:layout_weight="2"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:text="dummy"
|
||||||
|
android:layout_width="0dip"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:visibility="invisible"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -50,14 +50,14 @@
|
|||||||
<Button
|
<Button
|
||||||
android:id="@+id/btn_encryptFile"
|
android:id="@+id/btn_encryptFile"
|
||||||
android:text="@string/btn_encryptFile"
|
android:text="@string/btn_encryptFile"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dip"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btn_decryptFile"
|
android:id="@+id/btn_decryptFile"
|
||||||
android:text="@string/btn_decryptFile"
|
android:text="@string/btn_decryptFile"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dip"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
@ -71,14 +71,14 @@
|
|||||||
<Button
|
<Button
|
||||||
android:id="@+id/btn_encryptMessage"
|
android:id="@+id/btn_encryptMessage"
|
||||||
android:text="@string/btn_encryptMessage"
|
android:text="@string/btn_encryptMessage"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dip"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btn_decryptMessage"
|
android:id="@+id/btn_decryptMessage"
|
||||||
android:text="@string/btn_decryptMessage"
|
android:text="@string/btn_decryptMessage"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dip"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_height="wrap_content"/>
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
@ -243,5 +243,12 @@
|
|||||||
<string name="permission_read_key_details_label">Read key details from APG.</string>
|
<string name="permission_read_key_details_label">Read key details from APG.</string>
|
||||||
<string name="permission_read_key_details_description">Read of public and secret keys stored in APG, such as key ID and user IDs. The keys themselves can NOT be read.</string>
|
<string name="permission_read_key_details_description">Read of public and secret keys stored in APG, such as key ID and user IDs. The keys themselves can NOT be read.</string>
|
||||||
|
|
||||||
|
<!-- action strings -->
|
||||||
|
<string name="action_encrypt">Encrypt</string>
|
||||||
|
<string name="action_decrypt">Decrypt</string>
|
||||||
|
<string name="action_import_public">Import Public Keys</string>
|
||||||
|
<string name="action_import_secret">Import Secret Keys</string>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
|
141
src/org/thialfihar/android/apg/GeneralActivity.java
Normal file
141
src/org/thialfihar/android/apg/GeneralActivity.java
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
package org.thialfihar.android.apg;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import org.thialfihar.android.apg.utils.Choice;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
|
|
||||||
|
public class GeneralActivity extends BaseActivity {
|
||||||
|
private Intent mIntent;
|
||||||
|
private ArrayAdapter<Choice> mAdapter;
|
||||||
|
private ListView mList;
|
||||||
|
private Button mCancelButton;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
setContentView(R.layout.general);
|
||||||
|
|
||||||
|
mIntent = getIntent();
|
||||||
|
|
||||||
|
boolean isEncrypted = false;
|
||||||
|
boolean containsKeys = false;
|
||||||
|
|
||||||
|
InputStream inStream = null;
|
||||||
|
{
|
||||||
|
byte[] data = mIntent.getByteArrayExtra(Intent.EXTRA_TEXT);
|
||||||
|
if (data != null) {
|
||||||
|
inStream = new ByteArrayInputStream(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inStream == null) {
|
||||||
|
Uri data = mIntent.getData();
|
||||||
|
if (data != null) {
|
||||||
|
try {
|
||||||
|
inStream = getContentResolver().openInputStream(data);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
// didn't work
|
||||||
|
Toast.makeText(this, "failed to open stream", Toast.LENGTH_SHORT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inStream == null) {
|
||||||
|
Toast.makeText(this, "no data found", Toast.LENGTH_SHORT);
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mList = (ListView) findViewById(R.id.options);
|
||||||
|
Vector<Choice> choices = new Vector<Choice>();
|
||||||
|
|
||||||
|
if (containsKeys) {
|
||||||
|
choices.add(new Choice(Id.choice.action.import_public, getString(R.string.action_import_public)));
|
||||||
|
choices.add(new Choice(Id.choice.action.import_secret, getString(R.string.action_import_secret)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isEncrypted) {
|
||||||
|
choices.add(new Choice(Id.choice.action.decrypt, getString(R.string.action_decrypt)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!containsKeys && !isEncrypted) {
|
||||||
|
choices.add(new Choice(Id.choice.action.encrypt, getString(R.string.action_encrypt)));
|
||||||
|
}
|
||||||
|
|
||||||
|
mAdapter = new ArrayAdapter<Choice>(this, android.R.layout.simple_list_item_1, choices);
|
||||||
|
mList.setAdapter(mAdapter);
|
||||||
|
|
||||||
|
mList.setOnItemClickListener(new OnItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
|
||||||
|
clicked(mAdapter.getItem(arg2).getId());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mCancelButton = (Button) findViewById(R.id.btn_cancel);
|
||||||
|
mCancelButton.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
GeneralActivity.this.finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (choices.size() == 1) {
|
||||||
|
clicked(choices.get(0).getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clicked(int id) {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
switch (id) {
|
||||||
|
case Id.choice.action.encrypt: {
|
||||||
|
intent.setClass(this, EncryptActivity.class);
|
||||||
|
if (mIntent.hasExtra(Intent.EXTRA_TEXT)) {
|
||||||
|
intent.putExtra(Intent.EXTRA_TEXT, mIntent.getByteArrayExtra(Intent.EXTRA_TEXT));
|
||||||
|
} else if (mIntent.getData() != null) {
|
||||||
|
intent.setData(mIntent.getData());
|
||||||
|
intent.setType(mIntent.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Id.choice.action.decrypt: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Id.choice.action.import_public: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Id.choice.action.import_secret: {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
// shouldn't happen
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
@ -111,6 +111,13 @@ public final class Id {
|
|||||||
public static final int encrypt_only = 0x21070002;
|
public static final int encrypt_only = 0x21070002;
|
||||||
public static final int sign_and_encrypt = 0x21070003;
|
public static final int sign_and_encrypt = 0x21070003;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final class action {
|
||||||
|
public static final int encrypt = 0x21070001;
|
||||||
|
public static final int decrypt = 0x21070002;
|
||||||
|
public static final int import_public = 0x21070003;
|
||||||
|
public static final int import_secret = 0x21070004;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class return_value {
|
public static final class return_value {
|
||||||
|
Loading…
Reference in New Issue
Block a user