Project

General

Profile

« Previous | Next » 

Revision 48e61813

Added by Leszek Koltunski 10 months ago

progress

View differences:

src/main/java/org/distorted/helpers/ObjectGridCreator.java
20 20
import android.view.LayoutInflater;
21 21
import android.view.View;
22 22
import android.view.ViewGroup;
23
import android.widget.FrameLayout;
23 24
import android.widget.GridLayout;
24 25
import android.widget.ImageButton;
25 26
import android.widget.ImageView;
......
40 41
  private static final float TITLE_SIZE     = 0.8f;
41 42
  private static final float TEXT_SIZE      = 0.5f;
42 43
  private static final float TITLE_PADDING  = 0.15f;
44
  private static final float TITLE_MARGIN   = 0.15f;
43 45

  
44 46
  private GridLayout mGrid;
45 47
  private GridLayout[] mCategoryGrids;
......
134 136

  
135 137
      int height = (int)(TITLE_SIZE*mCubeSize);
136 138

  
137
      mROC = new RubikObjectCategories(sortMode);
139
      mROC = RubikObjectCategories.create(sortMode);
138 140
      if( mROC.hasIcons() ) constructIconBasedGrid(act,layout,mROC,height);
139 141
      else                  constructIconlessGrid(act,layout,mROC,height);
140 142
      }
......
181 183
  private View constructTitle(Activity act, int iconID, int height)
182 184
    {
183 185
    ImageView view = new ImageView(act);
184
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,height);
186
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,height);
187
    int m = (int)(TITLE_MARGIN*height);
188
    params.leftMargin = m;
189
    params.rightMargin = m;
185 190
    view.setLayoutParams(params);
191

  
186 192
    view.setBackgroundResource(R.color.dark_grey);
187 193

  
188 194
    int p = (int)(TITLE_PADDING*height);
......
197 203
  private View constructTitle(Activity act, String title, int height)
198 204
    {
199 205
    TextView view = new TextView(act);
200
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,height);
206
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,height);
207
    int m = (int)(TITLE_MARGIN*height);
208
    params.leftMargin = m;
209
    params.rightMargin = m;
201 210
    view.setLayoutParams(params);
202 211
    view.setBackgroundResource(R.color.dark_grey);
203 212
    view.setGravity(Gravity.CENTER);
src/main/java/org/distorted/objects/RubikObjectCategories.java
13 13

  
14 14
import org.distorted.main.R;
15 15

  
16
import java.util.Arrays;
17

  
18 16
///////////////////////////////////////////////////////////////////////////////////////////////////
19 17

  
20
public class RubikObjectCategories
18
public abstract class RubikObjectCategories
21 19
{
22 20
  public static final int[] DIFF_IDS =
23 21
    {
......
46 44
    R.drawable.difficulty5,
47 45
    };
48 46

  
49
  private final int mNumCategories;
50
  private int[][] mObjectIndices;
51
  private int[] mIconIDs;
52
  private String[] mTitles;
47
  protected final int mNumCategories;
48
  protected int[] mIconIDs;
49
  protected String[] mTitles;
50
  protected int[][] mObjectIndices;
53 51

  
54 52
///////////////////////////////////////////////////////////////////////////////////////////////////
55 53

  
56
  public RubikObjectCategories(int sortMode)
54
  public RubikObjectCategories()
57 55
    {
58
    switch(sortMode)
59
      {
60
      case SORT_CATEGORY  : buildSortCategory(); break;
61
      case SORT_DIFFICULTY: buildSortDifficulty(); break;
62
      case SORT_AUTHOR    : buildSortAuthor(); break;
63
      case SORT_YEAR      : buildSortYear(); break;
64
      }
65

  
56
    buildIndices();
66 57
    mNumCategories = mObjectIndices.length;
67

  
68
    switch(sortMode)
69
      {
70
      case SORT_CATEGORY  : buildIconsCategory(); break;
71
      case SORT_DIFFICULTY: buildIconsDifficulty(); break;
72
      case SORT_AUTHOR    : buildTitleAuthor(); break;
73
      case SORT_YEAR      : buildTitleYear(); break;
74
      }
75
    }
76

  
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

  
79
  private void buildSortStr(String[] data)
80
    {
81
    int numObjects = data.length;
82
    String[] sorted = new String[numObjects];
83
    System.arraycopy(data, 0, sorted, 0, numObjects);
84

  
85
    Arrays.sort(sorted);
86

  
87
    String[] categories = new String[numObjects];
88
    int numCategories = 0;
89

  
90
    for(int o=0; o<numObjects; o++)
91
      if( o==0 || !sorted[o-1].equals(sorted[o]) )
92
        {
93
        categories[numCategories] = sorted[o];
94
        numCategories++;
95
        }
96

  
97
    int lastChange = -1;
98
    int curr = 0;
99
    int[] numInCategory = new int[numCategories];
100

  
101
    for(int o=0; o<numObjects; o++)
102
      if( o==numObjects-1 || !sorted[o].equals(sorted[o+1]) )
103
        {
104
        numInCategory[curr] = o-lastChange;
105
        curr++;
106
        lastChange = o;
107
        }
108

  
109
    mObjectIndices = new int[numCategories][];
110

  
111
    for(int c=0; c<numCategories; c++)
112
      {
113
      mObjectIndices[c] = new int[numInCategory[c]];
114

  
115
      String cat = categories[c];
116
      int index = 0;
117

  
118
      for(int o=0; o<numObjects; o++)
119
        if( data[o].equals(cat) ) mObjectIndices[c][index++] = o;
120
      }
121
    }
122

  
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

  
125
  private void buildSortInt(int[] data)
126
    {
127
    int numObjects = data.length;
128
    int[] sorted = new int[numObjects];
129
    System.arraycopy(data, 0, sorted, 0, numObjects);
130

  
131
    Arrays.sort(sorted);
132

  
133
    int[] categories = new int[numObjects];
134
    int numCategories = 0;
135

  
136
    for(int o=0; o<numObjects; o++)
137
      if( o==0 || sorted[o-1]!=sorted[o] )
138
        {
139
        categories[numCategories] = sorted[o];
140
        numCategories++;
141
        }
142

  
143
    int lastChange = -1;
144
    int curr = 0;
145
    int[] numInCategory = new int[numCategories];
146

  
147
    for(int o=0; o<numObjects; o++)
148
      if( o==numObjects-1 || sorted[o]!=sorted[o+1] )
149
        {
150
        numInCategory[curr] = o-lastChange;
151
        curr++;
152
        lastChange = o;
153
        }
154

  
155
    mObjectIndices = new int[numCategories][];
156

  
157
    for(int c=0; c<numCategories; c++)
158
      {
159
      mObjectIndices[c] = new int[numInCategory[c]];
160

  
161
      int cat = categories[c];
162
      int index = 0;
163

  
164
      for(int o=0; o<numObjects; o++)
165
        if( data[o]==cat ) mObjectIndices[c][index++] = o;
166
      }
167
    }
168

  
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

  
171
  private void buildSortFloat(float[] data)
172
    {
173
    int numObjects = data.length;
174
    float[] sorted = new float[numObjects];
175
    System.arraycopy(data, 0, sorted, 0, numObjects);
176

  
177
    Arrays.sort(sorted);
178

  
179
    float[] categories = new float[numObjects];
180
    int numCategories = 0;
181

  
182
    for(int o=0; o<numObjects; o++)
183
      if( o==0 || sorted[o-1]!=sorted[o] )
184
        {
185
        categories[numCategories] = sorted[o];
186
        numCategories++;
187
        }
188

  
189
    int lastChange = -1;
190
    int curr = 0;
191
    int[] numInCategory = new int[numCategories];
192

  
193
    for(int o=0; o<numObjects; o++)
194
      if( o==numObjects-1 || sorted[o]!=sorted[o+1] )
195
        {
196
        numInCategory[curr] = o-lastChange;
197
        curr++;
198
        lastChange = o;
199
        }
200

  
201
    mObjectIndices = new int[numCategories][];
202

  
203
    for(int c=0; c<numCategories; c++)
204
      {
205
      mObjectIndices[c] = new int[numInCategory[c]];
206

  
207
      float cat = categories[c];
208
      int index = 0;
209

  
210
      for(int o=0; o<numObjects; o++)
211
        if( data[o]==cat ) mObjectIndices[c][index++] = o;
212
      }
213
    }
214

  
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

  
217
  private void buildSortCategory()
218
    {
219
    int numObjects = RubikObjectList.getNumObjects();
220
    int[] cats = new int[numObjects];
221

  
222
    for(int o=0; o<numObjects; o++)
223
      {
224
      RubikObject obj = RubikObjectList.getObject(o);
225
      cats[o] = obj==null ? 0 : obj.getCategory();
226
      }
227

  
228
    buildSortInt(cats);
229
    }
230

  
231
///////////////////////////////////////////////////////////////////////////////////////////////////
232

  
233
  private void buildSortDifficulty()
234
    {
235
    int numObjects = RubikObjectList.getNumObjects();
236
    float[] diffs = new float[numObjects];
237

  
238
    for(int o=0; o<numObjects; o++)
239
      {
240
      RubikObject obj = RubikObjectList.getObject(o);
241
      diffs[o] = obj==null ? 0 : obj.getDifficulty();
242
      }
243

  
244
    buildSortFloat(diffs);
245
    }
246

  
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248

  
249
  private void buildSortAuthor()
250
    {
251
    int numObjects = RubikObjectList.getNumObjects();
252
    String[] auths = new String[numObjects];
253

  
254
    for(int o=0; o<numObjects; o++)
255
      {
256
      RubikObject obj = RubikObjectList.getObject(o);
257
      auths[o] = obj==null ? "" : obj.getAuthor();
258
      }
259

  
260
    buildSortStr(auths);
261
    }
262

  
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264

  
265
  private void buildSortYear()
266
    {
267
    int numObjects = RubikObjectList.getNumObjects();
268
    int[] years = new int[numObjects];
269

  
270
    for(int o=0; o<numObjects; o++)
271
      {
272
      RubikObject obj = RubikObjectList.getObject(o);
273
      years[o] = obj==null ? 0 : obj.getYearOfInvention();
274
      }
275

  
276
    buildSortInt(years);
58
    buildTitle();
277 59
    }
278 60

  
279 61
///////////////////////////////////////////////////////////////////////////////////////////////////
280 62

  
281
  private void buildIconsCategory()
282
    {
283
    mIconIDs = new int[mNumCategories];
284

  
285
    for(int t=0; t<mNumCategories; t++)
286
      {
287
      int obj = mObjectIndices[t][0];
288
      RubikObject object = RubikObjectList.getObject(obj);
289
      int category = object==null ? 0 : object.getCategory();
290
      mIconIDs[t] = CATEGORY_IMAGES[category%5];  //TODO
291
      }
292
    }
63
  abstract void buildIndices();
64
  abstract void buildTitle();
293 65

  
294 66
///////////////////////////////////////////////////////////////////////////////////////////////////
295 67

  
296
  private void buildIconsDifficulty()
68
  public static RubikObjectCategories create(int sortMode)
297 69
    {
298
    mIconIDs = new int[mNumCategories];
299

  
300
    for(int t=0; t<mNumCategories; t++)
301
      {
302
      int obj = mObjectIndices[t][0];
303
      RubikObject object = RubikObjectList.getObject(obj);
304
      int difficulty = object==null ? 0 : (int)object.getDifficulty();
305
      mIconIDs[t] = DIFF_IMAGES[difficulty];
306
      }
307
    }
308

  
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310

  
311
  private void buildTitleAuthor()
312
    {
313
    mTitles = new String[mNumCategories];
314

  
315
    for(int t=0; t<mNumCategories; t++)
70
    switch(sortMode)
316 71
      {
317
      int obj = mObjectIndices[t][0];
318
      RubikObject object = RubikObjectList.getObject(obj);
319
      mTitles[t] = object==null ? "" : object.getAuthor();
72
      case SORT_CATEGORY  : return new RubikObjectCategoriesCat();
73
      case SORT_DIFFICULTY: return new RubikObjectCategoriesDiff();
74
      case SORT_AUTHOR    : return new RubikObjectCategoriesAuthor();
75
      case SORT_YEAR      : return new RubikObjectCategoriesYear();
320 76
      }
321
    }
322 77

  
323
///////////////////////////////////////////////////////////////////////////////////////////////////
324

  
325
  private void buildTitleYear()
326
    {
327
    mTitles = new String[mNumCategories];
328

  
329
    for(int t=0; t<mNumCategories; t++)
330
      {
331
      int obj = mObjectIndices[t][0];
332
      RubikObject object = RubikObjectList.getObject(obj);
333
      int year = object==null ? 0 : object.getYearOfInvention();
334
      mTitles[t] = year==0 ? "Unknown" : String.valueOf(year);
335
      }
78
    android.util.Log.e("D", "sortMode = "+sortMode+" not implemented!");
79
    return null;
336 80
    }
337 81

  
338 82
///////////////////////////////////////////////////////////////////////////////////////////////////
......
394 138
      for(int object : mObjectIndices[c])
395 139
        if( object==objectIndex ) return c;
396 140

  
141
    android.util.Log.e("D", "returning category -1: index: "+objectIndex);
142

  
397 143
    return -1;
398 144
    }
399 145

  
src/main/java/org/distorted/objects/RubikObjectCategoriesAuthor.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2024 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.objects;
11

  
12
import java.util.Arrays;
13

  
14
///////////////////////////////////////////////////////////////////////////////////////////////////
15

  
16
public class RubikObjectCategoriesAuthor extends RubikObjectCategories
17
{
18
  private void buildSort(String[] data)
19
    {
20
    int numObjects = data.length;
21
    String[] sorted = new String[numObjects];
22
    System.arraycopy(data, 0, sorted, 0, numObjects);
23

  
24
    Arrays.sort(sorted);
25

  
26
    String[] categories = new String[numObjects];
27
    int numCategories = 0;
28

  
29
    for(int o=0; o<numObjects; o++)
30
      if( o==0 || !sorted[o-1].equals(sorted[o]) )
31
        {
32
        categories[numCategories] = sorted[o];
33
        numCategories++;
34
        }
35

  
36
    int lastChange = -1;
37
    int curr = 0;
38
    int[] numInCategory = new int[numCategories];
39

  
40
    for(int o=0; o<numObjects; o++)
41
      if( o==numObjects-1 || !sorted[o].equals(sorted[o+1]) )
42
        {
43
        numInCategory[curr] = o-lastChange;
44
        curr++;
45
        lastChange = o;
46
        }
47

  
48
    mObjectIndices = new int[numCategories][];
49

  
50
    for(int c=0; c<numCategories; c++)
51
      {
52
      mObjectIndices[c] = new int[numInCategory[c]];
53

  
54
      String cat = categories[c];
55
      int index = 0;
56

  
57
      for(int o=0; o<numObjects; o++)
58
        if( data[o].equals(cat) ) mObjectIndices[c][index++] = o;
59
      }
60
    }
61

  
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

  
64
  void buildIndices()
65
    {
66
    int numObjects = RubikObjectList.getNumObjects();
67
    String[] auths = new String[numObjects];
68

  
69
    for(int o=0; o<numObjects; o++)
70
      {
71
      RubikObject obj = RubikObjectList.getObject(o);
72
      auths[o] = obj==null ? "" : obj.getAuthor();
73
      }
74

  
75
    buildSort(auths);
76
    }
77

  
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

  
80
  void buildTitle()
81
    {
82
    mTitles = new String[mNumCategories];
83

  
84
    for(int t=0; t<mNumCategories; t++)
85
      {
86
      int obj = mObjectIndices[t][0];
87
      RubikObject object = RubikObjectList.getObject(obj);
88
      mTitles[t] = object==null ? "" : object.getAuthor();
89
      }
90
    }
91
}
src/main/java/org/distorted/objects/RubikObjectCategoriesCat.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2024 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.objects;
11

  
12
import java.util.Arrays;
13

  
14
///////////////////////////////////////////////////////////////////////////////////////////////////
15

  
16
public class RubikObjectCategoriesCat extends RubikObjectCategories
17
{
18
  private void buildSort(int[] data)
19
    {
20
    int numObjects = data.length;
21
    int[] sorted = new int[numObjects];
22
    System.arraycopy(data, 0, sorted, 0, numObjects);
23

  
24
    Arrays.sort(sorted);
25

  
26
    int[] categories = new int[numObjects];
27
    int numCategories = 0;
28

  
29
    for(int o=0; o<numObjects; o++)
30
      if( o==0 || sorted[o-1]!=sorted[o] )
31
        {
32
        categories[numCategories] = sorted[o];
33
        numCategories++;
34
        }
35

  
36
    int lastChange = -1;
37
    int curr = 0;
38
    int[] numInCategory = new int[numCategories];
39

  
40
    for(int o=0; o<numObjects; o++)
41
      if( o==numObjects-1 || sorted[o]!=sorted[o+1] )
42
        {
43
        numInCategory[curr] = o-lastChange;
44
        curr++;
45
        lastChange = o;
46
        }
47

  
48
    mObjectIndices = new int[numCategories][];
49

  
50
    for(int c=0; c<numCategories; c++)
51
      {
52
      mObjectIndices[c] = new int[numInCategory[c]];
53

  
54
      int cat = categories[c];
55
      int index = 0;
56

  
57
      for(int o=0; o<numObjects; o++)
58
        if( data[o]==cat ) mObjectIndices[c][index++] = o;
59
      }
60
    }
61

  
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

  
64
  void buildIndices()
65
    {
66
    int numObjects = RubikObjectList.getNumObjects();
67
    int[] cats = new int[numObjects];
68

  
69
    for(int o=0; o<numObjects; o++)
70
      {
71
      RubikObject obj = RubikObjectList.getObject(o);
72
      cats[o] = obj==null ? 0 : obj.getCategory();
73
      }
74

  
75
    buildSort(cats);
76
    }
77

  
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

  
80
  void buildTitle()
81
    {
82
    mIconIDs = new int[mNumCategories];
83

  
84
    for(int t=0; t<mNumCategories; t++)
85
      {
86
      int obj = mObjectIndices[t][0];
87
      RubikObject object = RubikObjectList.getObject(obj);
88
      int category = object==null ? 0 : object.getCategory();
89
      mIconIDs[t] = CATEGORY_IMAGES[category%5];  //TODO
90
      }
91
    }
92
}
src/main/java/org/distorted/objects/RubikObjectCategoriesDiff.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2024 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.objects;
11

  
12
import java.util.Arrays;
13

  
14
///////////////////////////////////////////////////////////////////////////////////////////////////
15

  
16
public class RubikObjectCategoriesDiff extends RubikObjectCategories
17
{
18
  private void buildSort(float[] data)
19
    {
20
    int numObjects = data.length;
21
    float[] sorted = new float[numObjects];
22
    System.arraycopy(data, 0, sorted, 0, numObjects);
23

  
24
    Arrays.sort(sorted);
25

  
26
    int[] categories = new int[numObjects];
27
    int numCategories = 0;
28

  
29
    for(int o=0; o<numObjects; o++)
30
      if( o==0 || (int)sorted[o-1] != (int)sorted[o] )
31
        {
32
        categories[numCategories] = (int)sorted[o];
33
        numCategories++;
34
        }
35

  
36
    int lastChange = -1;
37
    int curr = 0;
38
    int[] numInCategory = new int[numCategories];
39

  
40
    for(int o=0; o<numObjects; o++)
41
      if( o==numObjects-1 || (int)sorted[o] != (int)sorted[o+1] )
42
        {
43
        numInCategory[curr] = o-lastChange;
44
        curr++;
45
        lastChange = o;
46
        }
47

  
48
    mObjectIndices = new int[numCategories][];
49

  
50
    boolean[] taken = new boolean[numObjects];
51
    for(int i=0; i<numObjects; i++) taken[i] = false;
52

  
53
    for(int c=0; c<numCategories; c++)
54
      {
55
      mObjectIndices[c] = new int[numInCategory[c]];
56

  
57
      int cat = categories[c];
58
      int index = 0;
59

  
60
      for(int o=0; o<numObjects; o++)
61
        if( (int)sorted[o]==cat )
62
          for(int n=0; n<numObjects; n++)
63
            if( data[n]==sorted[o] && !taken[n] )
64
              {
65
              taken[n]=true;
66
              mObjectIndices[c][index++] = n;
67
              break;
68
              }
69
      }
70
    }
71

  
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

  
74
  void buildIndices()
75
    {
76
    int numObjects = RubikObjectList.getNumObjects();
77
    float[] diffs = new float[numObjects];
78

  
79
    for(int o=0; o<numObjects; o++)
80
      {
81
      RubikObject obj = RubikObjectList.getObject(o);
82
      diffs[o] = obj==null ? 0 : obj.getDifficulty();
83
      }
84

  
85
    buildSort(diffs);
86
    }
87

  
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

  
90
  void buildTitle()
91
    {
92
    mIconIDs = new int[mNumCategories];
93

  
94
    for(int t=0; t<mNumCategories; t++)
95
      {
96
      int obj = mObjectIndices[t][0];
97
      RubikObject object = RubikObjectList.getObject(obj);
98
      int difficulty = object==null ? 0 : (int)object.getDifficulty();
99
      mIconIDs[t] = DIFF_IMAGES[difficulty];
100
      }
101
    }
102
}
src/main/java/org/distorted/objects/RubikObjectCategoriesYear.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2024 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.objects;
11

  
12
import java.util.Arrays;
13

  
14
///////////////////////////////////////////////////////////////////////////////////////////////////
15

  
16
public class RubikObjectCategoriesYear extends RubikObjectCategories
17
{
18
  private void buildSort(int[] data)
19
    {
20
    int numObjects = data.length;
21
    int[] sorted = new int[numObjects];
22
    System.arraycopy(data, 0, sorted, 0, numObjects);
23

  
24
    Arrays.sort(sorted);
25

  
26
    int[] categories = new int[numObjects];
27
    int numCategories = 0;
28

  
29
    for(int o=0; o<numObjects; o++)
30
      if( o==0 || sorted[o-1]!=sorted[o] )
31
        {
32
        categories[numCategories] = sorted[o];
33
        numCategories++;
34
        }
35

  
36
    int lastChange = -1;
37
    int curr = 0;
38
    int[] numInCategory = new int[numCategories];
39

  
40
    for(int o=0; o<numObjects; o++)
41
      if( o==numObjects-1 || sorted[o]!=sorted[o+1] )
42
        {
43
        numInCategory[curr] = o-lastChange;
44
        curr++;
45
        lastChange = o;
46
        }
47

  
48
    mObjectIndices = new int[numCategories][];
49

  
50
    for(int c=0; c<numCategories; c++)
51
      {
52
      mObjectIndices[c] = new int[numInCategory[c]];
53

  
54
      int cat = categories[c];
55
      int index = 0;
56

  
57
      for(int o=0; o<numObjects; o++)
58
        if( data[o]==cat ) mObjectIndices[c][index++] = o;
59
      }
60
    }
61

  
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

  
64
  void buildIndices()
65
    {
66
    int numObjects = RubikObjectList.getNumObjects();
67
    int[] years = new int[numObjects];
68

  
69
    for(int o=0; o<numObjects; o++)
70
      {
71
      RubikObject obj = RubikObjectList.getObject(o);
72
      years[o] = obj==null ? 0 : obj.getYearOfInvention();
73
      }
74

  
75
    buildSort(years);
76
    }
77

  
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

  
80
  void buildTitle()
81
    {
82
    mTitles = new String[mNumCategories];
83

  
84
    for(int t=0; t<mNumCategories; t++)
85
      {
86
      int obj = mObjectIndices[t][0];
87
      RubikObject object = RubikObjectList.getObject(obj);
88
      int year = object==null ? 0 : object.getYearOfInvention();
89
      mTitles[t] = year==0 ? "Unknown" : String.valueOf(year);
90
      }
91
    }
92
}

Also available in: Unified diff