Project

General

Profile

Download (6.14 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / dialogs / RubikDialogPatternListAdapter.java @ 054fbee1

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.dialogs;
21

    
22
import android.content.Context;
23
import android.view.LayoutInflater;
24
import android.view.View;
25
import android.view.ViewGroup;
26
import android.widget.BaseExpandableListAdapter;
27
import android.widget.TextView;
28

    
29
import org.distorted.main.RubikActivity;
30
import org.distorted.patterns.RubikPattern;
31
import org.distorted.main.R;
32

    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

    
35
class RubikDialogPatternListAdapter extends BaseExpandableListAdapter
36
  {
37
  private Context mContext;
38
  private int mTab, mWidth;
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

    
42
  public RubikDialogPatternListAdapter(Context context, int tab, int width)
43
    {
44
    mContext = context;
45
    mTab     = tab;
46
    mWidth   = width;
47
    }
48

    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

    
51
  @Override
52
  public Object getChild(int groupPosition, int childPosition)
53
    {
54
    RubikPattern pattern = RubikPattern.getInstance();
55
    return pattern.getPatternName(mTab,groupPosition,childPosition);
56
    }
57

    
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

    
60
  @Override
61
  public long getChildId(int groupPosition, int childPosition)
62
    {
63
    return childPosition;
64
    }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
  @Override
69
  public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent)
70
    {
71
    String childName = (String) getChild(groupPosition, childPosition);
72

    
73
    if (view == null)
74
      {
75
      LayoutInflater infalInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
76
      view = infalInflater.inflate(R.layout.dialog_pattern_child_item, null);
77
      }
78

    
79
    int size = (int)(mWidth* RubikActivity.PATTERN_CHILD_TEXT);
80

    
81
    TextView childItem = view.findViewById(R.id.child);
82
    childItem.setText(childName);
83
    childItem.setTextSize(size);
84

    
85
    return view;
86
    }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
  @Override
91
  public int getChildrenCount(int groupPosition)
92
    {
93
    RubikPattern pattern = RubikPattern.getInstance();
94
    return pattern.getNumPatterns(mTab,groupPosition);
95
    }
96

    
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

    
99
  @Override
100
  public Object getGroup(int groupPosition)
101
    {
102
    RubikPattern pattern = RubikPattern.getInstance();
103
    return pattern.getCategoryName(mTab,groupPosition);
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  @Override
109
  public int getGroupCount()
110
    {
111
    RubikPattern pattern = RubikPattern.getInstance();
112
    return pattern.getNumCategories(mTab);
113
    }
114

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

    
117
  @Override
118
  public long getGroupId(int groupPosition)
119
    {
120
    return groupPosition;
121
    }
122

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

    
125
  @Override
126
  public View getGroupView(int groupPosition, boolean isLastChild, View view, ViewGroup parent)
127
    {
128
    String groupName = (String) getGroup(groupPosition);
129

    
130
    if (view == null)
131
      {
132
      LayoutInflater inf = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
133
      view = inf.inflate(R.layout.dialog_pattern_group_item, null);
134
      }
135

    
136
    int size = (int)(mWidth* RubikActivity.PATTERN_GROUP_TEXT);
137

    
138
    TextView heading = view.findViewById(R.id.heading);
139
    heading.setText(groupName);
140
    heading.setTextSize(size);
141

    
142
    RubikPattern pattern = RubikPattern.getInstance();
143
    int numPatterns = pattern.getNumPatterns(mTab,groupPosition);
144
    TextView counter = view.findViewById(R.id.counter);
145
    counter.setText(String.format("%d", numPatterns));
146
    counter.setTextSize(size);
147

    
148
    return view;
149
    }
150

    
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

    
153
  @Override
154
  public boolean hasStableIds()
155
    {
156
    return true;
157
    }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  @Override
162
  public boolean isChildSelectable(int groupPosition, int childPosition)
163
    {
164
    return true;
165
    }
166
  }
(6-6/14)