Imported Upstream version 1.1.1
[platform/upstream/iotivity.git] / android / examples / DirectPairing / src / main / java / org / iotivity / base / examples / DirectPairing / ExpandableListAdapter.java
1 /*
2  * //******************************************************************
3  * //
4  * // Copyright 2016 Samsung Electronics All Rights Reserved.
5  * //
6  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7  * //
8  * // Licensed under the Apache License, Version 2.0 (the "License");
9  * // you may not use this file except in compliance with the License.
10  * // You may obtain a copy of the License at
11  * //
12  * //      http://www.apache.org/licenses/LICENSE-2.0
13  * //
14  * // Unless required by applicable law or agreed to in writing, software
15  * // distributed under the License is distributed on an "AS IS" BASIS,
16  * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * // See the License for the specific language governing permissions and
18  * // limitations under the License.
19  * //
20  * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21  */
22
23 package org.iotivity.base.examples.DirectPairing;
24
25 import android.content.Context;
26 import android.view.LayoutInflater;
27 import android.view.View;
28 import android.view.ViewGroup;
29 import android.widget.BaseExpandableListAdapter;
30 import android.widget.ImageView;
31 import android.widget.TextView;
32
33 import org.iotivity.base.examples.DirectPairing.Led;
34
35 import java.util.List;
36
37 public class ExpandableListAdapter extends BaseExpandableListAdapter {
38     private List<String> mGroupList;
39     private List<Object> mChilditemsList;
40     private Context mContext;
41
42     public ExpandableListAdapter(List<String> groupList, List<Object> childitemsList,
43                                  Context context) {
44         super();
45         this.mContext = context;
46         this.mGroupList = groupList;
47         this.mChilditemsList = childitemsList;
48     }
49
50     @Override
51     public int getGroupCount() {
52         return mGroupList.size();
53     }
54
55     @Override
56     public int getChildrenCount(int groupPosition) {
57         return 1;
58     }
59
60     @Override
61     public Object getGroup(int groupPosition) {
62         return mGroupList.get(groupPosition);
63     }
64
65     @Override
66     public Object getChild(int groupPosition, int childPosition) {
67         return this.mChilditemsList.get(childPosition);
68     }
69
70     @Override
71     public long getGroupId(int groupPosition) {
72         return groupPosition;
73     }
74
75     @Override
76     public long getChildId(int groupPosition, int childPosition) {
77         return childPosition;
78     }
79
80     @Override
81     public boolean hasStableIds() {
82         return false;
83     }
84
85     @Override
86     public View getGroupView(int groupPosition, boolean isExpanded,
87                              View convertView, ViewGroup parent) {
88
89         String data = (String) getGroup(groupPosition);
90         if (convertView == null) {
91             LayoutInflater infalInflater = (LayoutInflater) this.mContext
92                     .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
93             convertView = infalInflater.inflate(R.layout.list_group, null);
94         }
95
96         ImageView img = (ImageView) convertView.findViewById(R.id.image);
97         if (isExpanded) {
98             img.setImageResource(R.drawable.arrow_down);
99
100         } else {
101             img.setImageResource(R.drawable.arrow_right);
102         }
103
104         TextView groupText = (TextView) convertView.findViewById(R.id.title);
105         groupText.setText(mGroupList.get(groupPosition));
106
107         return convertView;
108     }
109
110     @Override
111     public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
112                              View convertView, ViewGroup parent) {
113         LayoutInflater inflater = (LayoutInflater) mContext
114                 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
115         convertView = inflater.inflate(R.layout.list_item, parent, false);
116
117         Led ledResource = (Led) getChild(groupPosition, childPosition);
118         TextView textItem = (TextView) convertView
119                 .findViewById(R.id.textViewItem);
120         TextView textSource = (TextView) convertView
121                 .findViewById(R.id.textViewSource);
122         TextView textStatus = (TextView) convertView
123                 .findViewById(R.id.textViewStatus);
124         textStatus.setText("URI:" + "/a/led");
125         textItem.setText("State: " + ledResource.getState());
126         textSource.setText("Power: " + ledResource.getPower());
127
128         return convertView;
129
130     }
131
132     @Override
133     public boolean isChildSelectable(int groupPosition, int childPosition) {
134         return true;
135     }
136
137 }