Enable search for certificate lists (via SearchView in ActionBar)
This commit is contained in:
parent
4db2d6336e
commit
c8d0c3b03d
|
@ -22,6 +22,7 @@
|
|||
<string name="main_activity_name">strongSwan</string>
|
||||
<string name="reload_trusted_certs">CA-Zertifikate neu laden</string>
|
||||
<string name="show_log">Log anzeigen</string>
|
||||
<string name="search">Suchen</string>
|
||||
|
||||
<!-- Log view -->
|
||||
<string name="log_title">Log</string>
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
<string name="main_activity_name">strongSwan</string>
|
||||
<string name="reload_trusted_certs">Reload CA certificates</string>
|
||||
<string name="show_log">View log</string>
|
||||
<string name="search">Search</string>
|
||||
|
||||
<!-- Log view -->
|
||||
<string name="log_title">Log</string>
|
||||
|
|
|
@ -106,6 +106,20 @@ public class TrustedCertificateEntry implements Comparable<TrustedCertificateEnt
|
|||
return mCert;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{ /* combination of both subject lines, used for filtering lists */
|
||||
if (mString == null)
|
||||
{
|
||||
mString = mSubjectPrimary;
|
||||
if (!mSubjectSecondary.isEmpty())
|
||||
{
|
||||
mString += ", " + mSubjectSecondary;
|
||||
}
|
||||
}
|
||||
return mString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(TrustedCertificateEntry another)
|
||||
{
|
||||
|
|
|
@ -34,10 +34,16 @@ import android.content.AsyncTaskLoader;
|
|||
import android.content.Context;
|
||||
import android.content.Loader;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SearchView;
|
||||
import android.widget.SearchView.OnQueryTextListener;
|
||||
|
||||
public class TrustedCertificateListFragment extends ListFragment implements LoaderCallbacks<List<TrustedCertificateEntry>>
|
||||
public class TrustedCertificateListFragment extends ListFragment implements LoaderCallbacks<List<TrustedCertificateEntry>>, OnQueryTextListener
|
||||
{
|
||||
private OnTrustedCertificateSelectedListener mListener;
|
||||
private TrustedCertificateAdapter mAdapter;
|
||||
|
@ -54,6 +60,7 @@ public class TrustedCertificateListFragment extends ListFragment implements Load
|
|||
public void onActivityCreated(Bundle savedInstanceState)
|
||||
{
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
setEmptyText(getString(R.string.no_certificates));
|
||||
|
||||
|
@ -85,6 +92,32 @@ public class TrustedCertificateListFragment extends ListFragment implements Load
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
|
||||
{
|
||||
MenuItem item = menu.add(R.string.search);
|
||||
item.setIcon(android.R.drawable.ic_menu_search);
|
||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
|
||||
SearchView sv = new SearchView(getActivity());
|
||||
sv.setOnQueryTextListener(this);
|
||||
item.setActionView(sv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query)
|
||||
{ /* already handled when the text changes */
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText)
|
||||
{
|
||||
String search = TextUtils.isEmpty(newText) ? null : newText;
|
||||
mAdapter.getFilter().filter(search);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<List<TrustedCertificateEntry>> onCreateLoader(int id, Bundle args)
|
||||
{ /* we don't need the id as we have only one loader */
|
||||
|
|
Loading…
Reference in New Issue