Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogPatternListAdapter.java @ e9397ae9

1 4debbf44 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 68191e7d Leszek Koltunski
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8 4debbf44 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.dialogs;
11
12
import android.content.Context;
13 5de2c572 Leszek Koltunski
import android.util.TypedValue;
14 4debbf44 Leszek Koltunski
import android.view.LayoutInflater;
15
import android.view.View;
16
import android.view.ViewGroup;
17
import android.widget.BaseExpandableListAdapter;
18
import android.widget.TextView;
19
20 71897466 Leszek Koltunski
import org.distorted.objectlib.patterns.RubikPattern;
21 4debbf44 Leszek Koltunski
import org.distorted.main.R;
22
23
///////////////////////////////////////////////////////////////////////////////////////////////////
24
25
class RubikDialogPatternListAdapter extends BaseExpandableListAdapter
26
  {
27 ff07f079 leszek
  private static final float PATTERN_CHILD_TEXT  = 0.038f;
28
  private static final float PATTERN_GROUP_TEXT  = 0.060f;
29
30 3f7a4363 Leszek Koltunski
  private final Context mContext;
31 337f4660 leszek
  private final int mTab, mWidth;
32 4debbf44 Leszek Koltunski
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34
35 337f4660 leszek
  public RubikDialogPatternListAdapter(Context context, int tab, int width)
36 4debbf44 Leszek Koltunski
    {
37
    mContext = context;
38
    mTab     = tab;
39 337f4660 leszek
    mWidth   = width;
40 4debbf44 Leszek Koltunski
    }
41
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43
44
  @Override
45
  public Object getChild(int groupPosition, int childPosition)
46
    {
47
    RubikPattern pattern = RubikPattern.getInstance();
48
    return pattern.getPatternName(mTab,groupPosition,childPosition);
49
    }
50
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52
53
  @Override
54
  public long getChildId(int groupPosition, int childPosition)
55
    {
56
    return childPosition;
57
    }
58
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
61
  @Override
62
  public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent)
63
    {
64
    String childName = (String) getChild(groupPosition, childPosition);
65
66
    if (view == null)
67
      {
68
      LayoutInflater infalInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
69
      view = infalInflater.inflate(R.layout.dialog_pattern_child_item, null);
70
      }
71
72 ff07f079 leszek
    int size = (int)(mWidth*PATTERN_CHILD_TEXT);
73 054fbee1 Leszek Koltunski
74
    TextView childItem = view.findViewById(R.id.child);
75 4debbf44 Leszek Koltunski
    childItem.setText(childName);
76 5de2c572 Leszek Koltunski
    childItem.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
77 4debbf44 Leszek Koltunski
78
    return view;
79
    }
80
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
83
  @Override
84
  public int getChildrenCount(int groupPosition)
85
    {
86
    RubikPattern pattern = RubikPattern.getInstance();
87
    return pattern.getNumPatterns(mTab,groupPosition);
88
    }
89
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91
92
  @Override
93
  public Object getGroup(int groupPosition)
94
    {
95
    RubikPattern pattern = RubikPattern.getInstance();
96
    return pattern.getCategoryName(mTab,groupPosition);
97
    }
98
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100
101
  @Override
102
  public int getGroupCount()
103
    {
104
    RubikPattern pattern = RubikPattern.getInstance();
105
    return pattern.getNumCategories(mTab);
106
    }
107
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109
110
  @Override
111
  public long getGroupId(int groupPosition)
112
    {
113
    return groupPosition;
114
    }
115
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117
118
  @Override
119
  public View getGroupView(int groupPosition, boolean isLastChild, View view, ViewGroup parent)
120
    {
121
    String groupName = (String) getGroup(groupPosition);
122
123
    if (view == null)
124
      {
125
      LayoutInflater inf = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
126
      view = inf.inflate(R.layout.dialog_pattern_group_item, null);
127
      }
128
129 ff07f079 leszek
    int size = (int)(mWidth*PATTERN_GROUP_TEXT);
130 054fbee1 Leszek Koltunski
131 4debbf44 Leszek Koltunski
    TextView heading = view.findViewById(R.id.heading);
132
    heading.setText(groupName);
133 5de2c572 Leszek Koltunski
    heading.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
134 054fbee1 Leszek Koltunski
135
    RubikPattern pattern = RubikPattern.getInstance();
136
    int numPatterns = pattern.getNumPatterns(mTab,groupPosition);
137
    TextView counter = view.findViewById(R.id.counter);
138
    counter.setText(String.format("%d", numPatterns));
139 5de2c572 Leszek Koltunski
    counter.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
140 4debbf44 Leszek Koltunski
141
    return view;
142
    }
143
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145
146
  @Override
147
  public boolean hasStableIds()
148
    {
149
    return true;
150
    }
151
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153
154
  @Override
155
  public boolean isChildSelectable(int groupPosition, int childPosition)
156
    {
157
    return true;
158
    }
159
  }