action encrypt to contact in view and multi select

This commit is contained in:
Dominik Schürmann 2014-01-07 22:59:39 +01:00
parent caf3b02042
commit a2f0667593
5 changed files with 77 additions and 17 deletions

View File

@ -113,4 +113,17 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
style="@style/SectionHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:text="@string/section_actions" />
<Button
android:id="@+id/action_encrypt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/key_view_action_encrypt" />
</LinearLayout>

View File

@ -2,7 +2,10 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/delete_entry"
android:id="@+id/menu_key_list_public_multi_encrypt"
android:title="@string/menu_encrypt_to"/>
<item
android:id="@+id/menu_key_list_public_multi_delete"
android:icon="@android:drawable/ic_menu_delete"
android:title="@string/menu_delete_key"/>

View File

@ -55,6 +55,7 @@
<string name="section_defaults">Defaults</string>
<string name="section_advanced">Advanced</string>
<string name="section_master_key">Master Key</string>
<string name="section_actions">Actions</string>
<!-- button -->
<string name="btn_sign_to_clipboard">Sign (Clipboard)</string>
@ -102,7 +103,8 @@
<string name="menu_sign_key">Sign key</string>
<string name="menu_beam_preferences">Beam settings</string>
<string name="menu_key_edit_cancel">Cancel</string>
<string name="menu_encrypt_to">Encrypt to…</string>
<!-- label -->
<string name="label_sign">Sign</string>
<string name="label_message">Message</string>
@ -357,4 +359,7 @@
<item quantity="other">%d keys selected.</item>
</plurals>
<!-- Key view -->
<string name="key_view_action_encrypt">Encrypt to this contact</string>
</resources>

View File

@ -22,6 +22,7 @@ import java.util.Set;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
import org.sufficientlysecure.keychain.ui.adapter.KeyListPublicAdapter;
@ -56,7 +57,7 @@ import android.widget.ListView;
public class KeyListPublicFragment extends Fragment implements AdapterView.OnItemClickListener,
LoaderManager.LoaderCallbacks<Cursor> {
// private KeyListPublicActivity mKeyListPublicActivity;
// private KeyListPublicActivity mKeyListPublicActivity;
private KeyListPublicAdapter mAdapter;
private StickyListHeadersListView mStickyList;
@ -77,7 +78,7 @@ public class KeyListPublicFragment extends Fragment implements AdapterView.OnIte
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// mKeyListPublicActivity = (KeyListPublicActivity) getActivity();
// mKeyListPublicActivity = (KeyListPublicActivity) getActivity();
mStickyList = (StickyListHeadersListView) getActivity().findViewById(R.id.list);
mStickyList.setOnItemClickListener(this);
@ -105,7 +106,7 @@ public class KeyListPublicFragment extends Fragment implements AdapterView.OnIte
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
android.view.MenuInflater inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.key_list_multi_selection, menu);
inflater.inflate(R.menu.key_list_public_multi, menu);
return true;
}
@ -117,20 +118,27 @@ public class KeyListPublicFragment extends Fragment implements AdapterView.OnIte
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
Set<Integer> positions = mAdapter.getCurrentCheckedPosition();
switch (item.getItemId()) {
case R.id.delete_entry:
// get IDs for checked positions as long array
long[] ids = new long[positions.size()];
int i = 0;
for (int pos : positions) {
ids[i] = mAdapter.getItemId(pos);
i++;
}
// get IDs for checked positions as long array
long[] ids = new long[positions.size()];
int i = 0;
for (int pos : positions) {
ids[i] = mAdapter.getItemId(pos);
i++;
}
switch (item.getItemId()) {
case R.id.menu_key_list_public_multi_encrypt: {
encrypt(ids);
break;
}
case R.id.menu_key_list_public_multi_delete: {
showDeleteKeyDialog(ids);
break;
}
}
return false;
}
@ -164,8 +172,7 @@ public class KeyListPublicFragment extends Fragment implements AdapterView.OnIte
// setListShown(false);
// Create an empty adapter we will use to display the loaded data.
mAdapter = new KeyListPublicAdapter(getActivity(), null, Id.type.public_key,
USER_ID_INDEX);
mAdapter = new KeyListPublicAdapter(getActivity(), null, Id.type.public_key, USER_ID_INDEX);
mStickyList.setAdapter(mAdapter);
// Prepare the loader. Either re-connect with an existing one,
@ -227,6 +234,20 @@ public class KeyListPublicFragment extends Fragment implements AdapterView.OnIte
startActivity(detailsIntent);
}
public void encrypt(long[] keyRingRowIds) {
// get master key ids from row ids
long[] keyRingIds = new long[keyRingRowIds.length];
for (int i = 0; i < keyRingRowIds.length; i++) {
keyRingIds[i] = ProviderHelper.getPublicMasterKeyId(getActivity(), keyRingRowIds[i]);
}
Intent intent = new Intent(getActivity(), EncryptActivity.class);
intent.setAction(EncryptActivity.ACTION_ENCRYPT);
intent.putExtra(EncryptActivity.EXTRA_ENCRYPTION_KEY_IDS, keyRingIds);
// used instead of startActivity set actionbar based on callingPackage
startActivityForResult(intent, 0);
}
/**
* Show dialog to delete key
*

View File

@ -50,6 +50,9 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.format.DateFormat;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
@ -67,6 +70,7 @@ public class KeyViewActivity extends KeyActivity implements CreateNdefMessageCal
private TextView mFingerint;
private TextView mExpiry;
private TextView mCreation;
private Button mActionEncrypt;
// NFC
private NfcAdapter mNfcAdapter;
@ -86,6 +90,7 @@ public class KeyViewActivity extends KeyActivity implements CreateNdefMessageCal
mExpiry = (TextView) this.findViewById(R.id.expiry);
mCreation = (TextView) this.findViewById(R.id.creation);
mAlgorithm = (TextView) this.findViewById(R.id.algorithm);
mActionEncrypt = (Button) this.findViewById(R.id.action_encrypt);
Intent intent = getIntent();
mDataUri = intent.getData();
@ -146,7 +151,7 @@ public class KeyViewActivity extends KeyActivity implements CreateNdefMessageCal
}
}
};
deleteKey(mDataUri, Id.type.public_key, returnHandler);
return true;
}
@ -172,6 +177,19 @@ public class KeyViewActivity extends KeyActivity implements CreateNdefMessageCal
mCreation.setText(DateFormat.getDateFormat(getApplicationContext()).format(
PgpKeyHelper.getCreationDate(mPublicKey)));
mAlgorithm.setText(PgpKeyHelper.getAlgorithmInfo(mPublicKey));
mActionEncrypt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
long[] encryptionKeyIds = new long[] { mPublicKey.getKeyID() };
Intent intent = new Intent(KeyViewActivity.this, EncryptActivity.class);
intent.setAction(EncryptActivity.ACTION_ENCRYPT);
intent.putExtra(EncryptActivity.EXTRA_ENCRYPTION_KEY_IDS, encryptionKeyIds);
// used instead of startActivity set actionbar based on callingPackage
startActivityForResult(intent, 0);
}
});
}
/**