]> rtime.felk.cvut.cz Git - hornmich/skoda-qr-demo.git/blob - BarCodeScanner/mobile/src/main/java/cz/cvut/fel/dce/barcodescanner/book/BrowseBookListener.java
Initial commit
[hornmich/skoda-qr-demo.git] / BarCodeScanner / mobile / src / main / java / cz / cvut / fel / dce / barcodescanner / book / BrowseBookListener.java
1 /*
2  * Copyright (C) 2009 ZXing authors
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package cz.cvut.fel.dce.barcodescanner.book;
18
19 import android.content.Intent;
20 import android.net.Uri;
21 import android.view.View;
22 import android.widget.AdapterView;
23
24 import cz.cvut.fel.dce.barcodescanner.LocaleManager;
25
26 import java.util.List;
27
28 final class BrowseBookListener implements AdapterView.OnItemClickListener {
29
30   private final SearchBookContentsActivity activity;
31   private final List<SearchBookContentsResult> items;
32
33   BrowseBookListener(SearchBookContentsActivity activity, List<SearchBookContentsResult> items) {
34     this.activity = activity;
35     this.items = items;
36   }
37
38   @Override
39   public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
40     if (position < 1) {
41       // Clicked header, ignore it
42       return;
43     }
44     int itemOffset = position - 1;
45     if (itemOffset >= items.size()) {
46       return;
47     }
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);
60     }
61   }
62 }