package fr.neamar.summon.record;

import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;
import fr.neamar.summon.R;
import fr.neamar.summon.holder.SearchHolder;

public class SearchRecord extends Record {
	public SearchHolder searchHolder;

	public SearchRecord(SearchHolder searchHolder) {
		super();
		this.holder = this.searchHolder = searchHolder;
	}

	@Override
	public View display(Context context, View v) {
		if (v == null)
			v = inflateFromId(context, R.layout.item_search);

		TextView appName = (TextView) v.findViewById(R.id.item_search_text);
		appName.setText(enrichText(context.getString(R.string.ui_item_search)
				+ " \"{" + searchHolder.query + "}\""));

		return v;
	}

	@Override
	public void doLaunch(Context context, View v) {
		Intent search = new Intent(Intent.ACTION_WEB_SEARCH);
		search.putExtra(SearchManager.QUERY, searchHolder.query);
		search.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(search);
	}

}

@@ -61,16 +61,66 @@
 anager;%0A
+import android.content.ActivityNotFoundException;%0A
 import a
@@ -174,16 +174,40 @@
 Intent;%0A
+import android.net.Uri;%0A
 import a
@@ -252,24 +252,53 @@
 t.TextView;%0A
+import android.widget.Toast;%0A
 import fr.ne
@@ -1115,16 +1115,28 @@
 ASK);%0A%09%09
+%0A%09%09try %7B%0A%09%09%09
 context.
@@ -1158,14 +1158,339 @@
 earch);%0A
+%09%09%7D catch (ActivityNotFoundException e) %7B%0A%09%09%09//This exception gets thrown if Google Search has been deactivated:%0A%09%09%09Uri uri = Uri.parse(%22http://www.google.com/#q=%22 + searchHolder.query);%0A%09%09%09search = new Intent(Intent.ACTION_VIEW, uri);%0A%09%09%09search.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);%0A%09%09%09context.startActivity(search);%0A%09%09%7D%0A
 %09%7D%0A%0A%7D%0A

Handle missing google search (fix #3)