Basic search implemented, just needs a bit of tidying up (e.g. tell you what you searched for)
This commit is contained in:
parent
45a32f45ba
commit
3d19b7f2c1
@ -11,11 +11,20 @@
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.app.default_searchable"
|
||||
android:value=".SearchResults" />
|
||||
</activity>
|
||||
<activity android:name="ManageRepo" />
|
||||
<activity android:name="Settings" />
|
||||
<activity android:name="AppDetails" />
|
||||
<activity android:name="Preferences" />
|
||||
<activity android:name="SearchResults" android:launchMode="singleTop">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEARCH" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.app.searchable"
|
||||
android:resource="@xml/searchable" />
|
||||
</activity>
|
||||
|
||||
<receiver android:name="StartupReceiver">
|
||||
<intent-filter>
|
||||
|
12
res/layout/searchresults.xml
Normal file
12
res/layout/searchresults.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent" android:layout_height="fill_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView android:id="@+id/description" android:singleLine="false"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content" />
|
||||
|
||||
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" />
|
||||
|
||||
</LinearLayout>
|
@ -85,6 +85,7 @@
|
||||
<string name="menu_manage">Manage Repos</string>
|
||||
<string name="menu_preferences">Preferences</string>
|
||||
<string name="menu_about">About</string>
|
||||
<string name="menu_search">Search</string>
|
||||
<string name="menu_add_repo">New Repository</string>
|
||||
<string name="menu_rem_repo">Remove Repository</string>
|
||||
|
||||
@ -119,4 +120,5 @@
|
||||
<string name="expert">Expert</string>
|
||||
<string name="expert_mode">Enabled expert mode</string>
|
||||
|
||||
<string name="search_hint">Search applications</string>
|
||||
</resources>
|
||||
|
5
res/xml/searchable.xml
Normal file
5
res/xml/searchable.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:label="@string/app_name"
|
||||
android:hint="@string/search_hint" >
|
||||
</searchable>
|
91
src/org/fdroid/fdroid/AppListAdapter.java
Normal file
91
src/org/fdroid/fdroid/AppListAdapter.java
Normal file
@ -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<DB.App> items = new ArrayList<DB.App>();
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -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<DB.App> items = new ArrayList<DB.App>();
|
||||
|
||||
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);
|
||||
|
70
src/org/fdroid/fdroid/SearchResults.java
Normal file
70
src/org/fdroid/fdroid/SearchResults.java
Normal file
@ -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<DB.App> 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);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user