Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogPatternListAdapter.java @ 4a6b3b53

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// 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
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.dialogs;
11

    
12
import android.content.Context;
13
import android.util.TypedValue;
14
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
import org.distorted.objectlib.patterns.RubikPattern;
21
import org.distorted.main.R;
22

    
23
///////////////////////////////////////////////////////////////////////////////////////////////////
24

    
25
class RubikDialogPatternListAdapter extends BaseExpandableListAdapter
26
  {
27
  private static final float PATTERN_CHILD_TEXT  = 0.038f;
28
  private static final float PATTERN_GROUP_TEXT  = 0.060f;
29

    
30
  private final Context mContext;
31
  private final int mTab, mWidth;
32

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

    
35
  public RubikDialogPatternListAdapter(Context context, int tab, int width)
36
    {
37
    mContext = context;
38
    mTab     = tab;
39
    mWidth   = width;
40
    }
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
    int size = (int)(mWidth*PATTERN_CHILD_TEXT);
73

    
74
    TextView childItem = view.findViewById(R.id.child);
75
    childItem.setText(childName);
76
    childItem.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
77

    
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
    int size = (int)(mWidth*PATTERN_GROUP_TEXT);
130

    
131
    TextView heading = view.findViewById(R.id.heading);
132
    heading.setText(groupName);
133
    heading.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
134

    
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
    counter.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
140

    
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
  }
(12-12/33)