package com.usai.apex;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

import org.json.JSONException;
import org.json.JSONObject;

import com.usai.util.Network;
import com.usai.util.dbUtil;

import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DownloadManager;
import android.app.AlertDialog.Builder;
import android.app.DownloadManager.Request;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager.NameNotFoundException;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.text.Html;
import android.text.style.URLSpan;
import android.util.Log;
import android.util.SparseArray;
import android.view.ContextMenu;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.view.View.OnCreateContextMenuListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

public class ResultActivity extends Activity
{

	private static final int	REQUEST_LOGINACTIVITY	= 1;
	String						user					= null;
	String						password				= null;
	String						function_name			= null;
	private SearchTask			m_task					= null;

	final int					OFFSET					= 5;

	int							sel						= -1;

	Bundle						searchParms				= null;
	SearchResult				searchresult			= new SearchResult();

	SparseArray<String>			showfieldmap			= new SparseArray<String>();
	// HashMap<Integer, String> showfieldmap = new HashMap<Integer, String>();
	private TextView			mStatusMessageView;
	// private View mSearchFormView;
	private View				footview;
	private View				mStatusView;
	int							actioncount				= 0;

	// private class resultAdapter extends SimpleAdapter
	// {
	//
	//
	// }
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		user = ApexTrackingApplication.get_user();
		password = ApexTrackingApplication.get_pass();
		function_name = getIntent().getStringExtra("function_name");
		if (function_name.equals("Ocean Booking"))
			setTitle("Booking Result");
		else if (function_name.equals("Ocean B/L info."))
			setTitle("B/L info. Result");
		else if (function_name.equals("Container detail"))
			setTitle("Container Result");
		else if (function_name.equals("Download Document"))
			setTitle("Document Result");

		searchParms = getIntent().getBundleExtra("searchParms");
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_result);

		SQLiteDatabase db = dbUtil.OpenDB(ResultActivity.this, null, false);
		Cursor cursor = db
				.query("actions_info", new String[] { "count(*)" },
						"function_name='" + function_name + "' and user='"
								+ user + "'", null, null, null, "priority",
						null);
		if (cursor.moveToNext())
		{
			actioncount = cursor.getInt(0);
		}

		dbUtil.CloseCursor(cursor);
		dbUtil.CloseDB(db);

		footview = findViewById(R.id.foot);
		// mSearchFormView = findViewById(R.id.search_form);
		Button btnnext = (Button) findViewById(R.id.btn_next);
		btnnext.setOnClickListener(new View.OnClickListener()
		{

			@Override
			public void onClick(View v)
			{
				// TextView tv_head = (TextView) findViewById(R.id.tv_head);

				// searchresult.set_direction(1);
				if (searchresult.get_totalcount() == -1)
					requestdata(true);
				else
				{
					// if (searchresult.get_direction() == -1)
					searchresult.set_offset(searchresult.get_offset() + OFFSET);
					requestdata(false);
				}

			}
		});

		Button btnpre = (Button) findViewById(R.id.btn_pre);
		btnpre.setOnClickListener(new View.OnClickListener()
		{

			@Override
			public void onClick(View v)
			{
				// TextView tv_head = (TextView) findViewById(R.id.tv_head);
				// searchresult.set_direction(-1);
				if (searchresult.get_totalcount() == -1)
					requestdata(true);
				else
				{
					searchresult.set_offset(searchresult.get_offset() - OFFSET);
					requestdata(false);
				}

			}
		});
		mStatusView = findViewById(R.id.status);
		mStatusMessageView = (TextView) findViewById(R.id.status_message);
		LinearLayout ll = (LinearLayout) findViewById(R.id.ll_refresh);
		Button btn_refresh = (Button) ll.findViewById(R.id.btn_refresh);
		btn_refresh.setOnClickListener(new View.OnClickListener()
		{

			@Override
			public void onClick(View v)
			{
				LinearLayout ll = (LinearLayout) findViewById(R.id.ll_refresh);
				ll.setVisibility(View.INVISIBLE);
				if (searchresult.get_totalcount() == -1)
					requestdata(true);
				else
					requestdata(false);

			}
		});

		SharedPreferences RunOnce = getSharedPreferences("Apex", 0);

		String vername;
		try
		{
			vername = getPackageManager().getPackageInfo("com.usai.apex", 0).versionName;
			boolean bFirstRun = RunOnce.getBoolean("FirstRun" + vername
					+ "_result", true);
			if (bFirstRun)
			{
				SharedPreferences.Editor editor = RunOnce.edit();
				editor.putBoolean("FirstRun" + vername + "_result", false);
				// Don't forget to commit your edits!!!
				editor.commit();
				Intent intent = new Intent();
				intent.setClass(this, HelpActivity.class);
				intent.putExtra("caller", "result");
				startActivity(intent);

			}
		}
		catch (NameNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		initTableHeader();
		if (savedInstanceState != null)
		{
			searchresult = (SearchResult) savedInstanceState
					.getSerializable("searchresult");
			if (searchresult.get_totalcount() == -1)
				requestdata(true);
			else
				initTable();
		}
		else
			requestdata(true);

	}

	@Override
	protected void onDestroy()
	{
		if (m_task != null)
			m_task.cancel(false);
		super.onDestroy();
	}

	private void initTable()
	{
		// int loadcount = searchresult.get_count();
		int totalcount = searchresult.get_totalcount();
		TextView tv_head = (TextView) findViewById(R.id.head);
		if (totalcount == 0)
		{
			tv_head.setText(R.string.str_0);

			return;
		}
		else if (searchresult.get_totalcount() > 2000)
		{
			tv_head.setText(R.string.str_2000);
		}
		else
			tv_head.setText(/*
							 * loadcount + "/" + //
							 */searchresult.get_totalcount()
					+ getText(R.string.str_records).toString());
		TableLayout tl = (TableLayout) findViewById(R.id.result_table);

		tl.removeViews(1, tl.getChildCount() - 1);
		// int newcount = loadcount - showcount + 1;// +1 header row
		for (int i = 0; i < searchresult.get_recordscount(); i++)
		{

			TableRow recordRow = new TableRow(ResultActivity.this);
			recordRow.setOnLongClickListener(new View.OnLongClickListener()
			{

				@Override
				public boolean onLongClick(View v)
				{
					// TODO Auto-generated method stub
					// v.setBackgroundColor(Color.GRAY);
					// v.showContextMenu();
					// return true;
					TableRow tr = (TableRow) v;
					TextView tvno = (TextView) tr.getChildAt(0);
					sel = (Integer.parseInt(tvno.getText().toString())-1) % 5 ;
					registerForContextMenu(v);
					openContextMenu(v);
					unregisterForContextMenu(v);
					return true;
				}
			});

			// registerForContextMenu(recordRow);
			// recordRow.setClickable(true);
			// registerForContextMenu(recordRow);
			// recordRow.setOnCreateContextMenuListener(m_tableMenu);
			// recordRow.SETSE

			HashMap<String, String> record = searchresult.get_record(i);
			TextView field = new TextView(ResultActivity.this);
			field.setBackgroundResource(R.drawable.tableitem);
			field.setText(searchresult.get_offset() + i + 1 + "");
			Log.d("offset=" + searchresult.get_offset(), "");
			field.setGravity(Gravity.CENTER);
			field.setPadding(10, 5, 10, 5);
			field.setTextSize(20);
			recordRow.addView(field);
			for (int j = 0; j < showfieldmap.size(); j++)
			{
				TextView field1 = new TextView(ResultActivity.this);
				// Log.d("onPostExecute", showfieldmap.get(j));
				String str = record.get(showfieldmap.get(j));
				field1.setBackgroundResource(R.drawable.tableitem);
				if (str.toLowerCase().trim().equals("null"))
					str = "";

				// field1.setBackgroundColor(0xFFFFFFFF);

				field1.setText(Html.fromHtml(str));

				if (actioncount == 0)
					field1.setOnClickListener(new OnClickListener()
					{

						@Override
						public void onClick(View v)
						{
							// if (true)
							// return;
							URLSpan span[] = ((TextView) v).getUrls();
							if (span.length < 1)
								return;
							span[0].getURL();
							Log.d("Text", span[0].getURL());
							
							TextView tv = (TextView)v;

							final DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);

							Uri uri = Uri.parse(span[0].getURL());
							final Request request = new Request(uri);

							// 设置允许使用的网络类型，这里是移动网络和wifi都可以
							request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE
									| DownloadManager.Request.NETWORK_WIFI);
							
							request.setDestinationInExternalPublicDir("Apex Mobile",tv.getText().toString()); 

							// 禁止发出通知，既后台下载，如果要使用这一句必须声明一个权限：android.permission.DOWNLOAD_WITHOUT_NOTIFICATION
							// request.setShowRunningNotification(false);

							// 不显示下载界面
							request.setVisibleInDownloadsUi(false);
							request.setNotificationVisibility(Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);

							/*
							 * 设置下载后文件存放的位置,如果sdcard不可用，那么设置这个将报错，
							 * 因此最好不设置如果sdcard可用，下载后的文件 在/mnt/sdcard/Android/
							 * data/packageName/files目录下面
							 * ，如果sdcard不可用,设置了下面这个将报错，不设置，下载后的文件在/cache这个 目录下面
							 */
							// request.setDestinationInExternalFilesDir(this,
							// null, "tar.apk");

							AlertDialog.Builder builder = new Builder(
									ResultActivity.this);
							builder.setMessage(getString(R.string.str_downloadmessage));

							builder.setTitle(getString(R.string.str_confirmdownload));

							builder.setPositiveButton(
									getString(R.string.str_download),
									new Dialog.OnClickListener()
									{

										@Override
										public void onClick(
												DialogInterface dialog,
												int which)
										{
											downloadManager.enqueue(request);
											dialog.dismiss();

										}
									});

							builder.setNegativeButton(
									getString(R.string.str_cancel),
									new Dialog.OnClickListener()
									{

										@Override
										public void onClick(
												DialogInterface dialog,
												int which)
										{
											dialog.dismiss();
										}
									});

							builder.create().show();

						}

					});
				// field1.setText(str);
				field1.setGravity(Gravity.LEFT);
				field1.setPadding(10, 5, 10, 5);
				field1.setTextSize(20);
				// field.setTextAppearance(ResultActivity.this,
				// android.R.attr.textAppearanceMedium);
				recordRow.addView(field1);
			}
			tl.addView(recordRow);
		}

		Button btnnext = (Button) findViewById(R.id.btn_next);

		Button btnpre = (Button) findViewById(R.id.btn_pre);
		if (searchresult.get_offset() == 0)
			btnpre.setEnabled(false);
		else
		{
			btnpre.setEnabled(true);
		}
		if ((searchresult.get_totalcount() - searchresult.get_offset() <= OFFSET)
				|| (searchresult.get_totalcount() == 0))
			btnnext.setEnabled(false);
		else
			btnnext.setEnabled(true);
	}

	private OnCreateContextMenuListener	m_tableMenu	= new OnCreateContextMenuListener()
													{

														@Override
														public void onCreateContextMenu(
																ContextMenu contextmenu,
																View view,
																ContextMenuInfo contextmenuinfo)
														{

															contextmenu
																	.add(Menu.NONE,
																			0,
																			0,
																			getString(R.string.str_detail));

														}

													};

	@Override
	public boolean onContextItemSelected(MenuItem item)
	{
		// menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
		// Log.d("table row select", sel+ "");

		Intent intent = new Intent();
		intent.setClass(this, DetailActivity.class);

		SQLiteDatabase db = dbUtil.OpenDB(this, null, false);
		Cursor cursor = db.query("actions_info",
				new String[] { "name", "_id" }, "function_name='"
						+ function_name + "' and user='" + user + "'", null,
				null, null, "priority", null);
		int i = 0;
		while (cursor.moveToNext())
		{
			String name = cursor.getString(0);
			Log.d("actionname", name);
			intent.putExtra("action" + i, name);
			i++;
		}
		intent.putExtra("function_name", function_name);
		intent.putExtra("actions_count", i);
		intent.putExtra("_id", searchresult.get_record(sel).get("_id")
				.toString());
		dbUtil.CloseCursor(cursor);
		dbUtil.CloseDB(db);

		startActivity(intent);

		return super.onContextItemSelected(item);
	}

	// @Override
	// public void onCreateContextMenu(ContextMenu menu, View v,
	// ContextMenuInfo menuInfo)
	// {
	// // // TODO Auto-generated method stub
	// menu.add(Menu.NONE, 0, 0, "Detail");
	// // // contextmenu.add(Menu.NONE, 1, 1, "�༭");
	// super.onCreateContextMenu(menu, v, menuInfo);
	// }

	void initTableHeader()
	{

		TableLayout tl = (TableLayout) findViewById(R.id.result_table);
		tl.setFocusable(true);
		tl.setOnCreateContextMenuListener(m_tableMenu);
		SQLiteDatabase db = dbUtil.OpenDB(this, null, false);
		Cursor cursor = db.query("fields_info", new String[] { "aname", "name",
				"_id" }, "function_name='" + function_name + "' and user='"
				+ user + "' and behavior=" + Network.BEHAVIOR_RESULT
				+ " and show = 1", null, null, null, "priority , aname", null);
		TableRow headerRow = (TableRow) findViewById(R.id.tr_header);
		int pos = 0;
		showfieldmap.clear();
		headerRow.removeAllViews();
		ArrayList<HashMap<String, String>> gridheader = new ArrayList<HashMap<String, String>>();
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("key", "no.");
		gridheader.add(map);
		Button btn = new Button(this);
		btn.setBackgroundResource(R.drawable.tablehead);
		btn.setPadding(0, 0, 0, 0);
		btn.setText("No.");
		headerRow.addView(btn);
		while (cursor.moveToNext())
		{
			String aname = cursor.getString(0);
			Button btn1 = new Button(this);
			btn1.setBackgroundResource(R.drawable.tablehead);
			btn1.setText(aname);
			headerRow.addView(btn1);
			showfieldmap.put(pos, cursor.getString(1));

			map.put("key", "header");
			gridheader.add(map);
			pos++;
		}
		dbUtil.CloseCursor(cursor);
		dbUtil.CloseDB(db);

		// SimpleAdapter adapter = new SimpleAdapter(this,
		// gridheader,// �����Դ
		// R.layout.result_item,//XMLʵ��
		// new String[] { "key" }, // ��̬������ImageItem��Ӧ������
		// new int[] { R.id.tv_value });
		//
		// GridView gridview = (GridView) findViewById(R.id.grid_result);
		// gridview.setNumColumns(2);
		// gridview.setAdapter(adapter);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.result, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item)
	{
		Intent intent = new Intent();
		switch (item.getItemId())
		{
			case R.id.action_custom_fields:

				intent.setClass(this, CustomizeFieldsActivity.class);
				intent.putExtra("user", user);
				// intent.putExtra("password", password);
				intent.putExtra("function_name", function_name);
				intent.putExtra("behavior", Network.BEHAVIOR_RESULT);
				startActivity(intent);
				break;
			case R.id.action_help:
				// Intent intent = new Intent();
				intent.setClass(this, HelpActivity.class);
				intent.putExtra("caller", "result");
				// // intent.putExtra("password", password);
				// intent.putExtra("function_name", function_name);
				// intent.putExtra("behavior", Network.BEHAVIOR_SEARCH);
				startActivity(intent);
				break;
			case R.id.action_save_search:
				// LayoutInflater factory = LayoutInflater.from(this);
				// final View textEntryView =
				// factory.inflate(R.layout.alert_dialog_text_entry, null);
				final View edit = new EditText(this);
				new AlertDialog.Builder(this)
						.setIconAttribute(android.R.attr.alertDialogIcon)
						.setTitle(R.string.str_createname)
						.setView(edit)
						.setPositiveButton(android.R.string.ok,
								new DialogInterface.OnClickListener()
								{
									public void onClick(DialogInterface dialog,
											int whichButton)
									{
										String name = ((EditText) edit)
												.getText().toString();
										String param = getIntent().toUri(0);

										JSONObject obj = new JSONObject();
										Set<String> keys = searchParms.keySet();
										for (String key : keys)
										{

											
											try
											{
												obj.put(key, searchParms.get(key).toString());

											}
											catch (JSONException e)
											{
												// TODO Auto-generated catch block
												e.printStackTrace();
											}

										}
										obj.toString();

										SQLiteDatabase db = dbUtil.OpenDB(
												ApexTrackingApplication.get_instance(), null, true);
										db.execSQL("insert into history(params,name,criterion,module_name,user,create_time) values('"

												+ param
												+ "','"
												+ name
												+ "','"
												+ obj.toString()
												+ "','"
												+ function_name
												+ "','"
												+ ApexTrackingApplication.get_user()
												+ "',"
												+ System.currentTimeMillis() + ")");
										dbUtil.CloseDB(db);

										/* User clicked OK so do some stuff */
									}
								})
						.setNegativeButton(android.R.string.cancel,
								new DialogInterface.OnClickListener()
								{
									public void onClick(DialogInterface dialog,
											int whichButton)
									{

										/* User clicked cancel so do some stuff */
									}
								}).create().show();
				break;
			default:
				break;
		}
		return super.onOptionsItemSelected(item);
	}

	public void requestdata(boolean requestcount)
	{

		if (m_task != null)
		{
			return;
		}
		mStatusMessageView.setText(R.string.str_Loading);
		showProgress(true);
		m_task = new SearchTask();
		m_task.execute(requestcount);

	}

	private void showProgress(final boolean show)
	{
		// On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
		// for very easy animations. If available, use these APIs to fade-in
		// the progress spinner.
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2)
		{
			int shortAnimTime = getResources().getInteger(
					android.R.integer.config_shortAnimTime);

			mStatusView.setVisibility(View.VISIBLE);
			mStatusView.animate().setDuration(shortAnimTime)
					.alpha(show ? 1 : 0)
					.setListener(new AnimatorListenerAdapter()
					{
						@Override
						public void onAnimationEnd(Animator animation)
						{
							mStatusView.setVisibility(show ? View.VISIBLE
									: View.INVISIBLE);
						}
					});

			footview.setVisibility(View.VISIBLE);
			footview.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1)
					.setListener(new AnimatorListenerAdapter()
					{
						@Override
						public void onAnimationEnd(Animator animation)
						{
							footview.setVisibility(show ? View.INVISIBLE
									: View.VISIBLE);
						}
					});
			// mSearchFormView.setVisibility(View.VISIBLE);
			// mSearchFormView.animate().setDuration(shortAnimTime)
			// .alpha(show ? 0 : 1)
			// .setListener(new AnimatorListenerAdapter()
			// {
			// @Override
			// public void onAnimationEnd(Animator animation)
			// {
			// mSearchFormView.setVisibility(show ? View.INVISIBLE
			// : View.VISIBLE);
			// }
			// });
		}
		else
		{
			// The ViewPropertyAnimator APIs are not available, so simply show
			// and hide the relevant UI components.
			mStatusView.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
			footview.setVisibility(show ? View.INVISIBLE : View.VISIBLE);
			// mSearchFormView.setVisibility(show ? View.INVISIBLE :
			// View.VISIBLE);
		}
	}

	public class SearchTask extends AsyncTask<Boolean, Void, Boolean>
	{
		// int err_code = ERR_CODE_NONE;
		int	errorcode;

		@Override
		protected Boolean doInBackground(Boolean... params)
		{

			if (!Network.NetworkIsAvailable())

			{
				errorcode = Network.RESULT_NET_NOTAVAILABLE;
				return false;
			}

			if (params[0])
			{
				int ret = Network.get_recordcount(searchParms);
				if (ret >= 0)
				{
					searchresult.put_totalcount(ret);
					if (ret == 0)
						return true;
				}
				else
				{
					errorcode = ret;
					return false;
				}
			}

			// if (searchresult.get_direction() == -1)
			// searchresult.set_offset(searchresult.get_offset() - 20);
			searchParms.putString("offset", searchresult.get_offset() + "");

			String jstr = Network.get_records(user, password, searchParms);
			if (jstr == null || jstr.length() <= 0)
			{
				// Log.d(TAG, "json is wrong");
				errorcode = Network.RESULT_NET_ERROR;
				return false;
			}

			JSONObject jsobj;
			//
			// array = new JSONArray(json);
			try
			{
				jsobj = new JSONObject(jstr);
				// if (searchresult.get_fieldscount() == 0)
				// {
				// JSONObject objfields = jsobj.getJSONObject("fields");
				// if (objfields != null)
				// searchresult.init_fields(objfields.toString());
				// }
				JSONObject objrecords = jsobj.getJSONObject("records");
				if (objrecords != null)
					searchresult.add_records(objrecords.toString());
				errorcode = Network.RESULT_TRUE;

				return true;

			}
			catch (JSONException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			errorcode = Network.RESULT_NET_ERROR;
			return false;

		}

		@Override
		protected void onPostExecute(final Boolean success)
		{
			Log.d("onPostExecute", "entry");
			m_task = null;
			showProgress(false);
			if (ApexTrackingApplication.get_authorization() == false)
			{
				LinearLayout ll = (LinearLayout) findViewById(R.id.ll_refresh);
				ll.setVisibility(View.VISIBLE);
				Toast toast = Toast.makeText(
						ApexTrackingApplication.get_instance(),
						getText(R.string.msg_net_passwordchangedremote),
						Toast.LENGTH_LONG);
				toast.setGravity(Gravity.CENTER, 0, 0);
				toast.show();
				Intent i = new Intent();
				i.setClass(ResultActivity.this, ApexActivity.class);
				startActivityForResult(i, REQUEST_LOGINACTIVITY);
				return;
			}
			switch (errorcode)
			{
				case Network.RESULT_NET_NOTAVAILABLE:
				{
					Toast toast = Toast.makeText(getApplicationContext(),
							getText(R.string.msg_connection_none),
							Toast.LENGTH_LONG);
					toast.setGravity(Gravity.CENTER, 0, 0);
					toast.show();
					break;
				}
				case Network.RESULT_NET_ERROR:
				{

					Toast toast = Toast.makeText(
							ApexTrackingApplication.get_instance(),
							getText(R.string.msg_net_resulterror) + ":"
									+ errorcode, Toast.LENGTH_LONG);
					toast.setGravity(Gravity.CENTER, 0, 0);
					toast.show();

					break;
				}
				case Network.RESULT_ERROR:
				// case Network.RESULT_RESPONSE_NULL:
				{
					Toast toast = Toast.makeText(getApplicationContext(),
							getText(R.string.msg_net_resulterror),
							Toast.LENGTH_LONG);
					toast.setGravity(Gravity.CENTER, 0, 0);
					toast.show();
					break;
				}

				default:
					break;
			}

			if (success)
			{

				initTable();

			}
			else
			{
				LinearLayout ll = (LinearLayout) findViewById(R.id.ll_refresh);
				ll.setVisibility(View.VISIBLE);
			}
		}

		@Override
		protected void onCancelled()
		{
			m_task = null;
			showProgress(false);
		}
	}

	@Override
	protected void onSaveInstanceState(Bundle outState)
	{
		outState.putSerializable("searchresult", searchresult);
		super.onSaveInstanceState(outState);
	}

}
