Example #1
0
	/**
	 * Starts searching procedure in backend.
	 */
	public void searchClicked() {
		
		// Convert search string to UTF-8.
		String searchString = searchEdit.getText().toString();
		try {
			searchString = URLEncoder.encode(searchString, "UTF-8");
		} catch (UnsupportedEncodingException e) {}

		// Display progress bar.
		setProgressBarVisibility(true);
		
		// No input? No need to search.
		if("".equals(searchString)) {
			listFragment.updateList(new ArrayList<Book>());
			return;
		}
		
		// Create a new callback object, which refers to our searchDone(). 
		Callback c = new Callback() {
			public void handleMessage(Message msg) {
				SearchFragment.this.searchDone(msg);
			}
		};
		
		// Call backend search.
		BackendFactory.getBackend().search(searchString, 0, c);
		listFragment.setLastSearchString(searchString);
	}
Example #2
0
	/**
	 * Is called from a callback object when backend searching is done.
	 * It is different from searchDone since we want to append the search
	 * results to the current list instead of replacing it.
	 * @param msg - Contains the books found by the search job and also
	 * 				an error message if there was an error.
	 */
	public void moreSearchDone(Message msg) {
		// Hide progress bar.
		setProgressBarVisibility(false);
		
		// Did the job fail?
		if (msg.error != null) {
			// Log,
			Log.e("searching", "Searching failed: "+msg.error);
			// And toast user.
			Toast.makeText(getSherlockActivity().getApplicationContext(), "Searching failed: "+msg.error, Toast.LENGTH_LONG).show();
			return;
		}
		// Convert results to List<Book>.  
		@SuppressWarnings("unchecked")
		ArrayList<Book> books = (ArrayList<Book>) msg.obj;
				
		// Did we get no results? 
		if (books.size() == 0) {
			Toast.makeText(getSherlockActivity().getApplicationContext(), "No results found.", Toast.LENGTH_LONG).show();
		}
		
		// Update list with titles (empty or not).
		listFragment.appendList(books);
	}