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