Make select fragments more reusable

This commit is contained in:
Dominik Schürmann 2013-09-08 16:08:36 +02:00
parent a890ba5e4f
commit 6fdae001cc
8 changed files with 134 additions and 49 deletions

View File

@ -4,9 +4,8 @@
android:layout_height="match_parent"
android:layout_centerHorizontal="true" >
<fragment
android:id="@+id/select_public_key_fragment"
android:name="org.sufficientlysecure.keychain.ui.SelectPublicKeyFragment"
<FrameLayout
android:id="@+id/select_public_key_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@ -4,9 +4,8 @@
android:layout_height="match_parent"
android:layout_centerHorizontal="true" >
<fragment
android:id="@+id/select_secret_key_fragment"
android:name="org.sufficientlysecure.keychain.ui.SelectSecretKeyFragment"
<FrameLayout
android:id="@+id/select_secret_key_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View File

@ -22,27 +22,24 @@ import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.prefs.Preferences;
import org.openintents.crypto.CryptoError;
import org.openintents.crypto.CryptoSignatureResult;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.helper.PgpMain;
import org.sufficientlysecure.keychain.util.InputData;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.remote_api.IServiceActivityCallback;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
import org.sufficientlysecure.keychain.util.PausableThreadPoolExecutor;
import org.openintents.crypto.ICryptoCallback;
import org.openintents.crypto.ICryptoService;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.PgpMain;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
import org.sufficientlysecure.keychain.util.InputData;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.PausableThreadPoolExecutor;
import android.app.Service;
import android.content.Context;

View File

@ -171,6 +171,7 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
@Override
public void onClick(View v) {
// Disallow
try {
mServiceCallback.onRegistered(false, packageName);
} catch (RemoteException e) {
@ -210,9 +211,23 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
showPassphraseDialog(secretKeyId);
} else if (ACTION_SELECT_PUB_KEYS.equals(action)) {
long secretKeyId = extras.getLong(EXTRA_SECRET_KEY_ID);
showPassphraseDialog(secretKeyId);
// Inflate a "Done"/"Cancel" custom action bar view
ActionBarHelper.setDoneCancelView(getSupportActionBar(), R.string.btn_okay,
new View.OnClickListener() {
@Override
public void onClick(View v) {
// ok
}
}, R.string.btn_doNotSave, new View.OnClickListener() {
@Override
public void onClick(View v) {
// cancel
}
});
} else {
Log.e(Constants.TAG, "Wrong action!");
finish();

View File

@ -66,8 +66,26 @@ public class SelectPublicKeyActivity extends SherlockFragmentActivity {
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
mSelectFragment = (SelectPublicKeyFragment) getSupportFragmentManager().findFragmentById(
R.id.select_public_key_fragment);
handleIntent(getIntent());
// Check that the activity is using the layout version with
// the fragment_container FrameLayout
if (findViewById(R.id.select_public_key_fragment_container) != null) {
// However, if we're being restored from a previous state,
// then we don't need to do anything and should return or else
// we could end up with overlapping fragments.
if (savedInstanceState != null) {
return;
}
// Create an instance of the fragment
mSelectFragment = SelectPublicKeyFragment.newInstance(selectedMasterKeyIds);
// Add the fragment to the 'fragment_container' FrameLayout
getSupportFragmentManager().beginTransaction()
.add(R.id.select_public_key_fragment_container, mSelectFragment).commit();
}
// TODO: reimplement!
// mFilterLayout = findViewById(R.id.layout_filter);
@ -80,7 +98,6 @@ public class SelectPublicKeyActivity extends SherlockFragmentActivity {
// }
// });
handleIntent(getIntent());
}
@Override
@ -90,7 +107,7 @@ public class SelectPublicKeyActivity extends SherlockFragmentActivity {
}
private void handleIntent(Intent intent) {
// TODO: reimplement!
// TODO: reimplement search!
// String searchString = null;
// if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
@ -111,15 +128,6 @@ public class SelectPublicKeyActivity extends SherlockFragmentActivity {
selectedMasterKeyIds = intent.getLongArrayExtra(EXTRA_SELECTED_MASTER_KEY_IDS);
}
/**
* returns preselected key ids, this is used in the fragment
*
* @return
*/
public long[] getSelectedMasterKeyIds() {
return selectedMasterKeyIds;
}
private void cancelClicked() {
setResult(RESULT_CANCELED, null);
finish();

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
* Copyright (C) 2012-2013 Dominik Schürmann <dominik@dominikschuermann.de>
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -21,33 +21,57 @@ import java.util.Date;
import java.util.Vector;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.ListFragmentWorkaround;
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.Keys;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
import org.sufficientlysecure.keychain.ui.widget.SelectKeyCursorAdapter;
import org.sufficientlysecure.keychain.R;
import android.app.Activity;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.app.LoaderManager;
import android.widget.ListView;
public class SelectPublicKeyFragment extends ListFragmentWorkaround implements
LoaderManager.LoaderCallbacks<Cursor> {
private SelectPublicKeyActivity mActivity;
private Activity mActivity;
private SelectKeyCursorAdapter mAdapter;
private ListView mListView;
private long mSelectedMasterKeyIds[];
private static final String ARG_PRESELECTED_KEY_IDS = "preselected_key_ids";
/**
* Creates new instance of this fragment
*/
public static SelectPublicKeyFragment newInstance(long[] preselectedKeyIds) {
SelectPublicKeyFragment frag = new SelectPublicKeyFragment();
Bundle args = new Bundle();
args.putLongArray(ARG_PRESELECTED_KEY_IDS, preselectedKeyIds);
frag.setArguments(args);
return frag;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSelectedMasterKeyIds = getArguments().getLongArray(ARG_PRESELECTED_KEY_IDS);
}
/**
* Define Adapter and Loader on create of Activity
*/
@ -55,12 +79,9 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mActivity = (SelectPublicKeyActivity) getSherlockActivity();
mActivity = getSherlockActivity();
mListView = getListView();
// get selected master key ids, which are given to activity by intent
mSelectedMasterKeyIds = mActivity.getSelectedMasterKeyIds();
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
// Give some text to display if there is no data. In a real

View File

@ -38,7 +38,9 @@ public class SelectSecretKeyActivity extends SherlockFragmentActivity {
public static final String RESULT_EXTRA_MASTER_KEY_ID = "masterKeyId";
public static final String RESULT_EXTRA_USER_ID = "userId";
public static boolean filterCertify = false;
private boolean mFilterCertify = false;
private SelectSecretKeyFragment mSelectFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -64,9 +66,28 @@ public class SelectSecretKeyActivity extends SherlockFragmentActivity {
// }
// });
filterCertify = getIntent().getBooleanExtra(EXTRA_FILTER_CERTIFY, false);
mFilterCertify = getIntent().getBooleanExtra(EXTRA_FILTER_CERTIFY, false);
handleIntent(getIntent());
// Check that the activity is using the layout version with
// the fragment_container FrameLayout
if (findViewById(R.id.select_secret_key_fragment_container) != null) {
// However, if we're being restored from a previous state,
// then we don't need to do anything and should return or else
// we could end up with overlapping fragments.
if (savedInstanceState != null) {
return;
}
// Create an instance of the fragment
mSelectFragment = SelectSecretKeyFragment.newInstance(mFilterCertify);
// Add the fragment to the 'fragment_container' FrameLayout
getSupportFragmentManager().beginTransaction()
.add(R.id.select_secret_key_fragment_container, mSelectFragment).commit();
}
}
/**

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
* Copyright (C) 2012-2013 Dominik Schürmann <dominik@dominikschuermann.de>
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -48,6 +48,31 @@ public class SelectSecretKeyFragment extends SherlockListFragment implements
private SelectKeyCursorAdapter mAdapter;
private ListView mListView;
private boolean mFilterCertify;
private static final String ARG_FILTER_CERTIFY = "filter_certify";
/**
* Creates new instance of this fragment
*/
public static SelectSecretKeyFragment newInstance(boolean filterCertify) {
SelectSecretKeyFragment frag = new SelectSecretKeyFragment();
Bundle args = new Bundle();
args.putBoolean(ARG_FILTER_CERTIFY, filterCertify);
frag.setArguments(args);
return frag;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mFilterCertify = getArguments().getBoolean(ARG_FILTER_CERTIFY);
}
/**
* Define Adapter and Loader on create of Activity
*/
@ -92,8 +117,8 @@ public class SelectSecretKeyFragment extends SherlockListFragment implements
Uri baseUri = KeyRings.buildSecretKeyRingsUri();
String CapFilter = null;
if (((SelectSecretKeyActivity)getActivity()).filterCertify == true) {
CapFilter = "(cert>0)";
if (mFilterCertify) {
CapFilter = "(cert > 0)";
}
// These are the rows that we will retrieve.