Home | History | Annotate | Download | only in expandingcells
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      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 com.example.android.expandingcells;
     18 
     19 /**
     20  * This custom object is used to populate the list adapter. It contains a reference
     21  * to an image, title, and the extra text to be displayed. Furthermore, it keeps track
     22  * of the current state (collapsed/expanded) of the corresponding item in the list,
     23  * as well as store the height of the cell in its collapsed state.
     24  */
     25 public class ExpandableListItem implements OnSizeChangedListener {
     26 
     27     private String mTitle;
     28     private String mText;
     29     private boolean mIsExpanded;
     30     private int mImgResource;
     31     private int mCollapsedHeight;
     32     private int mExpandedHeight;
     33 
     34     public ExpandableListItem(String title, int imgResource, int collapsedHeight, String text) {
     35         mTitle = title;
     36         mImgResource = imgResource;
     37         mCollapsedHeight = collapsedHeight;
     38         mIsExpanded = false;
     39         mText = text;
     40         mExpandedHeight = -1;
     41     }
     42 
     43     public boolean isExpanded() {
     44         return mIsExpanded;
     45     }
     46 
     47     public void setExpanded(boolean isExpanded) {
     48         mIsExpanded = isExpanded;
     49     }
     50 
     51     public String getTitle() {
     52         return mTitle;
     53     }
     54 
     55     public int getImgResource() {
     56         return mImgResource;
     57     }
     58 
     59     public int getCollapsedHeight() {
     60         return mCollapsedHeight;
     61     }
     62 
     63     public void setCollapsedHeight(int collapsedHeight) {
     64         mCollapsedHeight = collapsedHeight;
     65     }
     66 
     67     public String getText() {
     68         return mText;
     69     }
     70 
     71     public void setText(String text) {
     72         mText = text;
     73     }
     74 
     75     public int getExpandedHeight() {
     76         return mExpandedHeight;
     77     }
     78 
     79     public void setExpandedHeight(int expandedHeight) {
     80         mExpandedHeight = expandedHeight;
     81     }
     82 
     83     @Override
     84     public void onSizeChanged(int newHeight) {
     85         setExpandedHeight(newHeight);
     86     }
     87 }
     88