Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogPatternListAdapter.java @ 58990dfd

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