6146d9a00d490cdb9fda1d6ec57ed8be9d532457
[iec.git] / src / type3_AndroidCloud / anbox-master / android / appmgr / src / org / anbox / appmgr / AppListAdapter.java
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright 2016 Arnab Chakraborty. http://arnab.ch
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy of this
7  * software and associated documentation files (the "Software"), to deal in the Software
8  * without restriction, including without limitation the rights to use, copy, modify,
9  * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to the following
11  * conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies
14  * or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
17  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18  * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
21  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23
24 package org.anbox.appmgr;
25
26 import android.annotation.TargetApi;
27 import android.content.Context;
28 import android.os.Build;
29 import android.view.LayoutInflater;
30 import android.view.View;
31 import android.view.ViewGroup;
32 import android.widget.ArrayAdapter;
33 import android.widget.ImageView;
34 import android.widget.TextView;
35
36 import java.util.ArrayList;
37 import java.util.Collection;
38
39 /**
40  * Created by Arnab Chakraborty
41  */
42 public class AppListAdapter extends ArrayAdapter<AppModel> {
43     private final LayoutInflater mInflater;
44
45     public AppListAdapter (Context context) {
46         super(context, android.R.layout.simple_list_item_2);
47
48         mInflater = LayoutInflater.from(context);
49     }
50
51     public void setData(ArrayList<AppModel> data) {
52         clear();
53         if (data != null) {
54             addAll(data);
55         }
56     }
57
58     @Override
59     @TargetApi(Build.VERSION_CODES.HONEYCOMB)
60     public void addAll(Collection<? extends AppModel> items) {
61         //If the platform supports it, use addAll, otherwise add in loop
62         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
63             super.addAll(items);
64         }else{
65             for(AppModel item: items){
66                 super.add(item);
67             }
68         }
69     }
70
71     /**
72      * Populate new items in the list.
73      */
74     @Override public View getView(int position, View convertView, ViewGroup parent) {
75         View view;
76
77         if (convertView == null) {
78             view = mInflater.inflate(R.layout.list_item_icon_text, parent, false);
79         } else {
80             view = convertView;
81         }
82
83         AppModel item = getItem(position);
84         ((ImageView)view.findViewById(R.id.icon)).setImageDrawable(item.getIcon());
85         ((TextView)view.findViewById(R.id.text)).setText(item.getLabel());
86
87         return view;
88     }
89 }