From a1be0d302b44e76fcfdb04b2dea20cc4ea6e0e35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Fri, 7 Mar 2014 21:32:24 +0100 Subject: [PATCH] move search view from activity to fragment by setting it as a list header, better reusability! Required for service activites --- .../keychain/ui/KeyListPublicFragment.java | 4 +-- .../keychain/ui/SelectPublicKeyFragment.java | 33 ++++++++++--------- .../res/layout/select_public_key_activity.xml | 8 ----- .../select_public_key_fragment_header.xml | 7 ++++ 4 files changed, 26 insertions(+), 26 deletions(-) create mode 100644 OpenPGP-Keychain/src/main/res/layout/select_public_key_fragment_header.xml diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListPublicFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListPublicFragment.java index 3ee0202ef..f14fadd77 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListPublicFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListPublicFragment.java @@ -227,7 +227,7 @@ public class KeyListPublicFragment extends Fragment implements SearchView.OnQuer // We have a menu item to show in action bar. setHasOptionsMenu(true); - // NOTE: Not supported by StickyListHeader, thus no indicator is shown while loading + // NOTE: Not supported by StickyListHeader, but reimplemented here // Start out with a progress indicator. setListShown(false); @@ -276,7 +276,7 @@ public class KeyListPublicFragment extends Fragment implements SearchView.OnQuer mStickyList.setAdapter(mAdapter); - // NOTE: Not supported by StickyListHeader, thus no indicator is shown while loading + // NOTE: Not supported by StickyListHeader, but reimplemented here // The list should now be shown. if (isResumed()) { setListShown(true); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyFragment.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyFragment.java index 73335c2f9..5e729027d 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyFragment.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/ui/SelectPublicKeyFragment.java @@ -30,7 +30,6 @@ import org.sufficientlysecure.keychain.provider.KeychainDatabase; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; import org.sufficientlysecure.keychain.ui.adapter.SelectKeyCursorAdapter; -import android.app.Activity; import android.database.Cursor; import android.database.DatabaseUtils; import android.net.Uri; @@ -41,6 +40,7 @@ import android.support.v4.content.Loader; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; +import android.view.View; import android.widget.EditText; import android.widget.ListView; @@ -48,9 +48,7 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T LoaderManager.LoaderCallbacks { public static final String ARG_PRESELECTED_KEY_IDS = "preselected_key_ids"; - private Activity mActivity; private SelectKeyCursorAdapter mAdapter; - private ListView mListView; private EditText mSearchView; private long mSelectedMasterKeyIds[]; private String mCurQuery; @@ -72,8 +70,6 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mSearchView = (EditText) getActivity().findViewById(R.id.select_public_key_search); - mSearchView.addTextChangedListener(this); mSelectedMasterKeyIds = getArguments().getLongArray(ARG_PRESELECTED_KEY_IDS); } @@ -84,15 +80,20 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - mActivity = getActivity(); - mListView = getListView(); - - mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); + getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); // Give some text to display if there is no data. In a real // application this would come from a resource. setEmptyText(getString(R.string.list_empty)); - mAdapter = new SelectKeyCursorAdapter(mActivity, null, 0, mListView, Id.type.public_key); + // add header with search field + View headerView = getLayoutInflater(savedInstanceState) + .inflate(R.layout.select_public_key_fragment_header, null); + getListView().addHeaderView(headerView); + + mSearchView = (EditText) getActivity().findViewById(R.id.select_public_key_search); + mSearchView.addTextChangedListener(this); + + mAdapter = new SelectKeyCursorAdapter(getActivity(), null, 0, getListView(), Id.type.public_key); setListAdapter(mAdapter); @@ -111,11 +112,11 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T */ private void preselectMasterKeyIds(long[] masterKeyIds) { if (masterKeyIds != null) { - for (int i = 0; i < mListView.getCount(); ++i) { + for (int i = 0; i < getListView().getCount(); ++i) { long keyId = mAdapter.getMasterKeyId(i); for (int j = 0; j < masterKeyIds.length; ++j) { if (keyId == masterKeyIds[j]) { - mListView.setItemChecked(i, true); + getListView().setItemChecked(i, true); break; } } @@ -132,8 +133,8 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T // mListView.getCheckedItemIds() would give the row ids of the KeyRings not the master key // ids! Vector vector = new Vector(); - for (int i = 0; i < mListView.getCount(); ++i) { - if (mListView.isItemChecked(i)) { + for (int i = 0; i < getListView().getCount(); ++i) { + if (getListView().isItemChecked(i)) { vector.add(mAdapter.getMasterKeyId(i)); } } @@ -154,8 +155,8 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T */ public String[] getSelectedUserIds() { Vector userIds = new Vector(); - for (int i = 0; i < mListView.getCount(); ++i) { - if (mListView.isItemChecked(i)) { + for (int i = 0; i < getListView().getCount(); ++i) { + if (getListView().isItemChecked(i)) { userIds.add((String) mAdapter.getUserId(i)); } } diff --git a/OpenPGP-Keychain/src/main/res/layout/select_public_key_activity.xml b/OpenPGP-Keychain/src/main/res/layout/select_public_key_activity.xml index 5337433c6..a18ce46fc 100644 --- a/OpenPGP-Keychain/src/main/res/layout/select_public_key_activity.xml +++ b/OpenPGP-Keychain/src/main/res/layout/select_public_key_activity.xml @@ -4,16 +4,8 @@ android:layout_height="match_parent" android:layout_centerHorizontal="true" > - - diff --git a/OpenPGP-Keychain/src/main/res/layout/select_public_key_fragment_header.xml b/OpenPGP-Keychain/src/main/res/layout/select_public_key_fragment_header.xml new file mode 100644 index 000000000..e08a63726 --- /dev/null +++ b/OpenPGP-Keychain/src/main/res/layout/select_public_key_fragment_header.xml @@ -0,0 +1,7 @@ + +