2 * The MIT License (MIT)
4 * Copyright 2016 Arnab Chakraborty. http://arnab.ch
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
13 * The above copyright notice and this permission notice shall be included in all copies
14 * or substantial portions of the Software.
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.
24 package org.anbox.appmgr;
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;
36 import java.util.ArrayList;
37 import java.util.Collection;
40 * Created by Arnab Chakraborty
42 public class AppListAdapter extends ArrayAdapter<AppModel> {
43 private final LayoutInflater mInflater;
45 public AppListAdapter (Context context) {
46 super(context, android.R.layout.simple_list_item_2);
48 mInflater = LayoutInflater.from(context);
51 public void setData(ArrayList<AppModel> data) {
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) {
65 for(AppModel item: items){
72 * Populate new items in the list.
74 @Override public View getView(int position, View convertView, ViewGroup parent) {
77 if (convertView == null) {
78 view = mInflater.inflate(R.layout.list_item_icon_text, parent, false);
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());