2 * Copyright (C) 2009 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package cz.cvut.fel.dce.barcodescanner.book;
19 import android.content.Intent;
20 import android.net.Uri;
21 import android.view.View;
22 import android.widget.AdapterView;
24 import cz.cvut.fel.dce.barcodescanner.LocaleManager;
26 import java.util.List;
28 final class BrowseBookListener implements AdapterView.OnItemClickListener {
30 private final SearchBookContentsActivity activity;
31 private final List<SearchBookContentsResult> items;
33 BrowseBookListener(SearchBookContentsActivity activity, List<SearchBookContentsResult> items) {
34 this.activity = activity;
39 public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
41 // Clicked header, ignore it
44 int itemOffset = position - 1;
45 if (itemOffset >= items.size()) {
48 String pageId = items.get(itemOffset).getPageId();
49 String query = SearchBookContentsResult.getQuery();
50 if (LocaleManager.isBookSearchUrl(activity.getISBN()) && !pageId.isEmpty()) {
51 String uri = activity.getISBN();
52 int equals = uri.indexOf('=');
53 String volumeId = uri.substring(equals + 1);
54 String readBookURI = "http://books.google." +
55 LocaleManager.getBookSearchCountryTLD(activity) +
56 "/books?id=" + volumeId + "&pg=" + pageId + "&vq=" + query;
57 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(readBookURI));
58 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
59 activity.startActivity(intent);