2 * Copyright 2012 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.history;
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;
28 import com.google.zxing.Result;
29 import cz.cvut.fel.dce.barcodescanner.R;
31 import java.util.ArrayList;
33 final class HistoryItemAdapter extends ArrayAdapter<HistoryItem> {
35 private final Context activity;
37 HistoryItemAdapter(Context activity) {
38 super(activity, R.layout.history_list_item, new ArrayList<HistoryItem>());
39 this.activity = activity;
43 public View getView(int position, View view, ViewGroup viewGroup) {
45 if (view instanceof LinearLayout) {
48 LayoutInflater factory = LayoutInflater.from(activity);
49 layout = factory.inflate(R.layout.history_list_item, viewGroup, false);
52 HistoryItem item = getItem(position);
53 Result result = item.getResult();
58 title = result.getText();
59 detail = item.getDisplayAndDetails();
61 Resources resources = getContext().getResources();
62 title = resources.getString(R.string.history_empty);
63 detail = resources.getString(R.string.history_empty_detail);
66 ((TextView) layout.findViewById(R.id.history_title)).setText(title);
67 ((TextView) layout.findViewById(R.id.history_detail)).setText(detail);