]> rtime.felk.cvut.cz Git - hornmich/skoda-qr-demo.git/blob - BarCodeScanner/mobile/src/main/java/cz/cvut/fel/dce/barcodescanner/history/HistoryItemAdapter.java
Initial commit
[hornmich/skoda-qr-demo.git] / BarCodeScanner / mobile / src / main / java / cz / cvut / fel / dce / barcodescanner / history / HistoryItemAdapter.java
1 /*
2  * Copyright 2012 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.history;
18
19 import android.content.Context;
20 import android.content.res.Resources;
21 import android.view.LayoutInflater;
22 import android.view.View;
23 import android.view.ViewGroup;
24 import android.widget.ArrayAdapter;
25 import android.widget.LinearLayout;
26 import android.widget.TextView;
27
28 import com.google.zxing.Result;
29 import cz.cvut.fel.dce.barcodescanner.R;
30
31 import java.util.ArrayList;
32
33 final class HistoryItemAdapter extends ArrayAdapter<HistoryItem> {
34
35   private final Context activity;
36
37   HistoryItemAdapter(Context activity) {
38     super(activity, R.layout.history_list_item, new ArrayList<HistoryItem>());
39     this.activity = activity;
40   }
41
42   @Override
43   public View getView(int position, View view, ViewGroup viewGroup) {
44     View layout;
45     if (view instanceof LinearLayout) {
46       layout = view;
47     } else {
48       LayoutInflater factory = LayoutInflater.from(activity);
49       layout = factory.inflate(R.layout.history_list_item, viewGroup, false);
50     }
51
52     HistoryItem item = getItem(position);
53     Result result = item.getResult();
54
55     CharSequence title;
56     CharSequence detail;
57     if (result != null) {
58       title = result.getText();
59       detail = item.getDisplayAndDetails();      
60     } else {
61       Resources resources = getContext().getResources();
62       title = resources.getString(R.string.history_empty);
63       detail = resources.getString(R.string.history_empty_detail);
64     }
65
66     ((TextView) layout.findViewById(R.id.history_title)).setText(title);    
67     ((TextView) layout.findViewById(R.id.history_detail)).setText(detail);
68
69     return layout;
70   }
71
72 }