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.
	 * @param msg - Message object that contains all the books that searchJob
	 * 				finds. Also the occasional error message.
	 */
	public void searchDone(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 ArrayList<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.updateList(books);
	}