diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ade7cb6dd..34a3b88dd 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -11,11 +11,20 @@
+
+
+
+
+
+
+
diff --git a/res/layout/searchresults.xml b/res/layout/searchresults.xml
new file mode 100644
index 000000000..9a50fb949
--- /dev/null
+++ b/res/layout/searchresults.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index bced43756..2714db40b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -85,6 +85,7 @@
Manage Repos
Preferences
About
+ Search
New Repository
Remove Repository
@@ -119,4 +120,5 @@
Expert
Enabled expert mode
+Search applications
diff --git a/res/xml/searchable.xml b/res/xml/searchable.xml
new file mode 100644
index 000000000..76581020d
--- /dev/null
+++ b/res/xml/searchable.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/src/org/fdroid/fdroid/AppListAdapter.java b/src/org/fdroid/fdroid/AppListAdapter.java
new file mode 100644
index 000000000..0ee3d92e9
--- /dev/null
+++ b/src/org/fdroid/fdroid/AppListAdapter.java
@@ -0,0 +1,91 @@
+package org.fdroid.fdroid;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.fdroid.fdroid.R;
+
+import android.content.Context;
+import android.net.Uri;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+public class AppListAdapter extends BaseAdapter {
+
+ private List items = new ArrayList();
+ private Context mContext;
+
+ public AppListAdapter(Context context) {
+ mContext = context;
+ }
+
+ public void addItem(DB.App app) {
+ items.add(app);
+ }
+
+ public void clear() {
+ items.clear();
+ }
+
+ @Override
+ public int getCount() {
+ return items.size();
+ }
+
+ @Override
+ public Object getItem(int position) {
+ return items.get(position);
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ View v = convertView;
+ if (v == null) {
+ LayoutInflater vi = (LayoutInflater) mContext
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ v = vi.inflate(R.layout.applistitem, null);
+ }
+ DB.App app = items.get(position);
+
+ TextView name = (TextView) v.findViewById(R.id.name);
+ name.setText(app.name);
+
+ String vs;
+ int numav = app.apks.size();
+ if (numav == 1)
+ vs = mContext.getString(R.string.n_version_available);
+ else
+ vs = mContext.getString(R.string.n_versions_available);
+ TextView status = (TextView) v.findViewById(R.id.status);
+ status.setText(String.format(vs, numav));
+
+ TextView license = (TextView) v.findViewById(R.id.license);
+ license.setText(app.license);
+
+ TextView summary = (TextView) v.findViewById(R.id.summary);
+ summary.setText(app.summary);
+
+ ImageView icon = (ImageView) v.findViewById(R.id.icon);
+ String iconpath = new String(DB.getIconsPath() + app.icon);
+ File icn = new File(iconpath);
+ if (icn.exists() && icn.length() > 0) {
+ new Uri.Builder().build();
+ icon.setImageURI(Uri.parse(iconpath));
+ } else {
+ icon.setImageResource(android.R.drawable.sym_def_app_icon);
+ }
+
+ return v;
+ }
+
+}
diff --git a/src/org/fdroid/fdroid/FDroid.java b/src/org/fdroid/fdroid/FDroid.java
index 36934d2ac..2d2b5f464 100644
--- a/src/org/fdroid/fdroid/FDroid.java
+++ b/src/org/fdroid/fdroid/FDroid.java
@@ -20,8 +20,6 @@
package org.fdroid.fdroid;
import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Vector;
import org.fdroid.fdroid.R;
@@ -47,10 +45,7 @@ import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import android.view.ViewGroup;
import android.widget.AdapterView;
-import android.widget.BaseAdapter;
-import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TextView;
@@ -60,77 +55,6 @@ import android.widget.TabHost.TabSpec;
public class FDroid extends TabActivity implements OnItemClickListener {
- private class AppListAdapter extends BaseAdapter {
-
- private List items = new ArrayList();
-
- public AppListAdapter(Context context) {
- }
-
- public void addItem(DB.App app) {
- items.add(app);
- }
-
- public void clear() {
- items.clear();
- }
-
- @Override
- public int getCount() {
- return items.size();
- }
-
- @Override
- public Object getItem(int position) {
- return items.get(position);
- }
-
- @Override
- public long getItemId(int position) {
- return position;
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- View v = convertView;
- if (v == null) {
- LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- v = vi.inflate(R.layout.applistitem, null);
- }
- DB.App app = items.get(position);
-
- TextView name = (TextView) v.findViewById(R.id.name);
- name.setText(app.name);
-
- String vs;
- int numav = app.apks.size();
- if (numav == 1)
- vs = getString(R.string.n_version_available);
- else
- vs = getString(R.string.n_versions_available);
- TextView status = (TextView) v.findViewById(R.id.status);
- status.setText(String.format(vs, numav));
-
- TextView license = (TextView) v.findViewById(R.id.license);
- license.setText(app.license);
-
- TextView summary = (TextView) v.findViewById(R.id.summary);
- summary.setText(app.summary);
-
- ImageView icon = (ImageView) v.findViewById(R.id.icon);
- String iconpath = new String(DB.getIconsPath() + app.icon);
- File icn = new File(iconpath);
- if (icn.exists() && icn.length() > 0) {
- new Uri.Builder().build();
- icon.setImageURI(Uri.parse(iconpath));
- } else {
- icon.setImageResource(android.R.drawable.sym_def_app_icon);
- }
-
- return v;
- }
- }
-
private String LOCAL_PATH = "/sdcard/.fdroid";
private static final int REQUEST_APPDETAILS = 0;
@@ -141,6 +65,7 @@ public class FDroid extends TabActivity implements OnItemClickListener {
private static final int MANAGE_REPO = Menu.FIRST + 1;
private static final int PREFERENCES = Menu.FIRST + 2;
private static final int ABOUT = Menu.FIRST + 3;
+ private static final int SEARCH = Menu.FIRST + 4;
private DB db = null;
@@ -216,9 +141,11 @@ public class FDroid extends TabActivity implements OnItemClickListener {
android.R.drawable.ic_menu_rotate);
menu.add(Menu.NONE, MANAGE_REPO, 2, R.string.menu_manage).setIcon(
android.R.drawable.ic_menu_agenda);
- menu.add(Menu.NONE, PREFERENCES, 3, R.string.menu_preferences).setIcon(
+ menu.add(Menu.NONE, SEARCH, 3, R.string.menu_search).setIcon(
+ android.R.drawable.ic_menu_search);
+ menu.add(Menu.NONE, PREFERENCES, 4, R.string.menu_preferences).setIcon(
android.R.drawable.ic_menu_preferences);
- menu.add(Menu.NONE, ABOUT, 4, R.string.menu_about).setIcon(
+ menu.add(Menu.NONE, ABOUT, 5, R.string.menu_about).setIcon(
android.R.drawable.ic_menu_help);
return true;
}
@@ -242,6 +169,10 @@ public class FDroid extends TabActivity implements OnItemClickListener {
startActivityForResult(prefs, REQUEST_PREFS);
return true;
+ case SEARCH:
+ onSearchRequested();
+ return true;
+
case ABOUT:
LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.about, null);
diff --git a/src/org/fdroid/fdroid/SearchResults.java b/src/org/fdroid/fdroid/SearchResults.java
new file mode 100644
index 000000000..ac3fa6a59
--- /dev/null
+++ b/src/org/fdroid/fdroid/SearchResults.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2011 Ciaran Gultnieks, ciaran@ciarang.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.fdroid.fdroid;
+
+import java.util.Vector;
+
+import android.app.ListActivity;
+import android.app.SearchManager;
+import android.content.Intent;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.widget.ListView;
+
+public class SearchResults extends ListActivity {
+
+ private static final int REQUEST_APPDETAILS = 0;
+
+ private AppListAdapter applist = new AppListAdapter(this);
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.searchresults);
+
+ Intent intent = getIntent();
+
+ if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
+ String query = intent.getStringExtra(SearchManager.QUERY);
+ DB db = new DB(this);
+ Vector apps = db.getApps(null, query, false);
+ Log.d("FDroid", "Search for '" + query + "' returned "
+ + apps.size() + " results");
+ for (DB.App app : apps) {
+ applist.addItem(app);
+ }
+ applist.notifyDataSetChanged();
+ setListAdapter(applist);
+ db.close();
+ }
+ }
+
+ @Override
+ protected void onListItemClick(ListView l, View v, int position, long id) {
+ final DB.App app;
+ app = (DB.App) applist.getItem(position);
+
+ Intent intent = new Intent(this, AppDetails.class);
+ intent.putExtra("appid", app.id);
+ startActivityForResult(intent, REQUEST_APPDETAILS);
+ super.onListItemClick(l, v, position, id);
+ }
+
+}