1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2020 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7
|
// it under the terms of the GNU General Public License as published by //
|
8
|
// the Free Software Foundation, either version 2 of the License, or //
|
9
|
// (at your option) any later version. //
|
10
|
// //
|
11
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14
|
// GNU General Public License for more details. //
|
15
|
// //
|
16
|
// You should have received a copy of the GNU General Public License //
|
17
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
package org.distorted.magic;
|
21
|
|
22
|
import android.support.annotation.NonNull;
|
23
|
import android.support.v4.app.FragmentActivity;
|
24
|
import android.support.v4.view.PagerAdapter;
|
25
|
import android.support.v4.view.ViewPager;
|
26
|
import android.view.View;
|
27
|
import android.view.ViewGroup;
|
28
|
|
29
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30
|
|
31
|
class RubikScoresPagerAdapter extends PagerAdapter implements RubikScoresDownloader.Receiver
|
32
|
{
|
33
|
private FragmentActivity mAct;
|
34
|
private RubikScoresView[] mViews;
|
35
|
|
36
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37
|
|
38
|
public void receive(final int[][][] country, final String[][][] name, final String[][][] time)
|
39
|
{
|
40
|
mAct.runOnUiThread(new Runnable()
|
41
|
{
|
42
|
@Override
|
43
|
public void run()
|
44
|
{
|
45
|
for(int i=0; i<RubikSize.LENGTH; i++)
|
46
|
{
|
47
|
mViews[i].prepareView(mAct);
|
48
|
}
|
49
|
}
|
50
|
});
|
51
|
try
|
52
|
{
|
53
|
Thread.sleep(200);
|
54
|
}
|
55
|
catch( InterruptedException ie)
|
56
|
{
|
57
|
|
58
|
}
|
59
|
|
60
|
for(int i=0; i<RubikSize.LENGTH; i++)
|
61
|
{
|
62
|
final RubikScoresView view = mViews[i];
|
63
|
|
64
|
for(int j=0; j<RubikActivity.MAX_SCRAMBLE; j++)
|
65
|
{
|
66
|
final int scramble = j;
|
67
|
final int[] c = country[i][j];
|
68
|
final String[] n = name[i][j];
|
69
|
final String[] t = time[i][j];
|
70
|
|
71
|
mAct.runOnUiThread(new Runnable()
|
72
|
{
|
73
|
@Override
|
74
|
public void run()
|
75
|
{
|
76
|
view.addScramble(mAct, scramble, c, n, t);
|
77
|
}
|
78
|
});
|
79
|
|
80
|
try
|
81
|
{
|
82
|
Thread.sleep(50);
|
83
|
}
|
84
|
catch( InterruptedException ie)
|
85
|
{
|
86
|
|
87
|
}
|
88
|
}
|
89
|
}
|
90
|
}
|
91
|
|
92
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
93
|
|
94
|
public void exception(final String exce)
|
95
|
{
|
96
|
mAct.runOnUiThread(new Runnable()
|
97
|
{
|
98
|
@Override
|
99
|
public void run()
|
100
|
{
|
101
|
for(int i=0; i<RubikSize.LENGTH; i++)
|
102
|
{
|
103
|
mViews[i].exception(exce);
|
104
|
}
|
105
|
}
|
106
|
});
|
107
|
}
|
108
|
|
109
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
110
|
|
111
|
RubikScoresPagerAdapter(FragmentActivity act, ViewPager viewPager)
|
112
|
{
|
113
|
mAct = act;
|
114
|
mViews = new RubikScoresView[RubikSize.LENGTH];
|
115
|
|
116
|
viewPager.setAdapter(this);
|
117
|
viewPager.setOffscreenPageLimit( RubikSize.LENGTH-1 );
|
118
|
}
|
119
|
|
120
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
121
|
|
122
|
@Override
|
123
|
@NonNull
|
124
|
public Object instantiateItem(@NonNull ViewGroup collection, int position)
|
125
|
{
|
126
|
mViews[position] = new RubikScoresView(mAct);
|
127
|
collection.addView(mViews[position]);
|
128
|
|
129
|
boolean allCreated = true;
|
130
|
|
131
|
for(int i=0; i<RubikSize.LENGTH; i++)
|
132
|
{
|
133
|
if( mViews[i]==null )
|
134
|
{
|
135
|
allCreated = false;
|
136
|
break;
|
137
|
}
|
138
|
}
|
139
|
|
140
|
if( allCreated )
|
141
|
{
|
142
|
RubikScoresDownloader downloader = new RubikScoresDownloader();
|
143
|
downloader.download(this, mAct.getResources(), mAct.getPackageName());
|
144
|
}
|
145
|
|
146
|
return mViews[position];
|
147
|
}
|
148
|
|
149
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
150
|
|
151
|
@Override
|
152
|
public void destroyItem(ViewGroup collection, int position, @NonNull Object view)
|
153
|
{
|
154
|
collection.removeView((View) view);
|
155
|
}
|
156
|
|
157
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
158
|
|
159
|
@Override
|
160
|
public int getCount()
|
161
|
{
|
162
|
return RubikSize.LENGTH;
|
163
|
}
|
164
|
|
165
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
166
|
|
167
|
@Override
|
168
|
public boolean isViewFromObject(@NonNull View view, @NonNull Object object)
|
169
|
{
|
170
|
return view == object;
|
171
|
}
|
172
|
}
|