Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogPatternListAdapter.java @ 3f7a4363

1 4debbf44 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 5de2c572 Leszek Koltunski
import android.util.TypedValue;
24 4debbf44 Leszek Koltunski
import android.view.LayoutInflater;
25
import android.view.View;
26
import android.view.ViewGroup;
27
import android.widget.BaseExpandableListAdapter;
28
import android.widget.TextView;
29
30 054fbee1 Leszek Koltunski
import org.distorted.main.RubikActivity;
31 4debbf44 Leszek Koltunski
import org.distorted.patterns.RubikPattern;
32
import org.distorted.main.R;
33
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35
36
class RubikDialogPatternListAdapter extends BaseExpandableListAdapter
37
  {
38 3f7a4363 Leszek Koltunski
  private final Context mContext;
39
  private final int mTab, mWidth;
40 4debbf44 Leszek Koltunski
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42
43 054fbee1 Leszek Koltunski
  public RubikDialogPatternListAdapter(Context context, int tab, int width)
44 4debbf44 Leszek Koltunski
    {
45
    mContext = context;
46
    mTab     = tab;
47 054fbee1 Leszek Koltunski
    mWidth   = width;
48 4debbf44 Leszek Koltunski
    }
49
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51
52
  @Override
53
  public Object getChild(int groupPosition, int childPosition)
54
    {
55
    RubikPattern pattern = RubikPattern.getInstance();
56
    return pattern.getPatternName(mTab,groupPosition,childPosition);
57
    }
58
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
61
  @Override
62
  public long getChildId(int groupPosition, int childPosition)
63
    {
64
    return childPosition;
65
    }
66
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68
69
  @Override
70
  public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent)
71
    {
72
    String childName = (String) getChild(groupPosition, childPosition);
73
74
    if (view == null)
75
      {
76
      LayoutInflater infalInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
77
      view = infalInflater.inflate(R.layout.dialog_pattern_child_item, null);
78
      }
79
80 054fbee1 Leszek Koltunski
    int size = (int)(mWidth* RubikActivity.PATTERN_CHILD_TEXT);
81
82
    TextView childItem = view.findViewById(R.id.child);
83 4debbf44 Leszek Koltunski
    childItem.setText(childName);
84 5de2c572 Leszek Koltunski
    childItem.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
85 4debbf44 Leszek Koltunski
86
    return view;
87
    }
88
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90
91
  @Override
92
  public int getChildrenCount(int groupPosition)
93
    {
94
    RubikPattern pattern = RubikPattern.getInstance();
95
    return pattern.getNumPatterns(mTab,groupPosition);
96
    }
97
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99
100
  @Override
101
  public Object getGroup(int groupPosition)
102
    {
103
    RubikPattern pattern = RubikPattern.getInstance();
104
    return pattern.getCategoryName(mTab,groupPosition);
105
    }
106
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108
109
  @Override
110
  public int getGroupCount()
111
    {
112
    RubikPattern pattern = RubikPattern.getInstance();
113
    return pattern.getNumCategories(mTab);
114
    }
115
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117
118
  @Override
119
  public long getGroupId(int groupPosition)
120
    {
121
    return groupPosition;
122
    }
123
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125
126
  @Override
127
  public View getGroupView(int groupPosition, boolean isLastChild, View view, ViewGroup parent)
128
    {
129
    String groupName = (String) getGroup(groupPosition);
130
131
    if (view == null)
132
      {
133
      LayoutInflater inf = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
134
      view = inf.inflate(R.layout.dialog_pattern_group_item, null);
135
      }
136
137 054fbee1 Leszek Koltunski
    int size = (int)(mWidth* RubikActivity.PATTERN_GROUP_TEXT);
138
139 4debbf44 Leszek Koltunski
    TextView heading = view.findViewById(R.id.heading);
140
    heading.setText(groupName);
141 5de2c572 Leszek Koltunski
    heading.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
142 054fbee1 Leszek Koltunski
143
    RubikPattern pattern = RubikPattern.getInstance();
144
    int numPatterns = pattern.getNumPatterns(mTab,groupPosition);
145
    TextView counter = view.findViewById(R.id.counter);
146
    counter.setText(String.format("%d", numPatterns));
147 5de2c572 Leszek Koltunski
    counter.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
148 4debbf44 Leszek Koltunski
149
    return view;
150
    }
151
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153
154
  @Override
155
  public boolean hasStableIds()
156
    {
157
    return true;
158
    }
159
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161
162
  @Override
163
  public boolean isChildSelectable(int groupPosition, int childPosition)
164
    {
165
    return true;
166
    }
167
  }