Project

General

Profile

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

magiccube / src / main / java / org / distorted / magic / RubikScoresDownloader.java @ b8b38548

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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
///////////////////////////////////////////////////////////////////////////////////////////////////
23

    
24
class RubikScoresDownloader implements Runnable
25
  {
26
  interface Receiver
27
    {
28
    void receive(String scores);
29
    }
30

    
31
  private static final int DOWNLOAD   = 0;
32
  private static final int SUBMIT     = 1;
33
  private static final int IDLE       = 2;
34

    
35
  private static final String URL  ="http://koltunski.pl/rubik/cgi-bin";
36

    
37
  private static boolean mRunning = false;
38
  private static Thread mNetworkThrd = null;
39
  private static int mMode = IDLE;
40
  private static Receiver mReceiver;
41

    
42
  private static String mScores = "";
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

    
46
  static void onPause()
47
    {
48
    mRunning = false;
49
    mScores = "";
50
    }
51

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

    
54
  private boolean gottaDownload()
55
    {
56
    return ((mScores.length()==0) && !mRunning);
57
    }
58

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

    
61
  void abortNetworkTransaction()
62
    {
63
    mRunning = false;
64
    }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
  void download(Receiver receiver)
69
    {
70
    mReceiver = receiver;
71
    mMode = DOWNLOAD;
72
    mNetworkThrd = new Thread(this);
73
    mNetworkThrd.start();
74
    }
75

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

    
78
  public void run()
79
    {
80
    try
81
      {
82
      if( gottaDownload() )
83
        {
84
        mRunning = true;
85

    
86
        Thread.sleep(2000);
87

    
88
mScores =
89

    
90
"0 0 0 INEED7X7X7 1 rus" + "\n" +
91
"0 0 1 Tilly 1 uk" + "\n" +
92
"0 0 2 ARNOLD 1 rus" + "\n" +
93
"0 0 3 ALBERTO 1 mex" + "\n" +
94
"0 0 4 TO 1 ger" + "\n" +
95
"0 1 0 INEED7X7X7 1 rus" + "\n" +
96
"0 1 1 Tilly 1 uk" + "\n" +
97
"0 1 2 ALBERTO 1 mex" + "\n" +
98
"0 1 3 RINAT 1 rus" + "\n" +
99
"0 1 4 BOOW 1 tha" + "\n" +
100
"0 2 0 Neriel 3 bra" + "\n" +
101
"0 2 1 NPPN 3 vie" + "\n" +
102
"0 2 2 FREDRIK 4 den" + "\n" +
103
"0 2 3 OHIOCUBER 4 usa" + "\n" +
104
"0 2 4 S13 4 usa" + "\n" +
105
"0 3 0 NIKITOS 8 rus" + "\n" +
106
"0 3 1 THISNAVIS 8 usa" + "\n" +
107
"0 3 2 MDR04 9 ita" + "\n" +
108
"0 3 3 ROBERT04 9 unk" + "\n" +
109
"0 3 4 DULCE 10 mex" + "\n" +
110
"1 0 0 INEED7X7X7 1 rus" + "\n" +
111
"1 0 1 Tilly 1 uk" + "\n" +
112
"1 0 2 REBECCA 1 fra" + "\n" +
113
"1 0 3 PRAKOBKRIT 1 tha" + "\n" +
114
"1 0 4 E 1 mex" + "\n" +
115
"1 1 0 BAYLEY 3 usa" + "\n" +
116
"1 1 1 DEMONAIRE 3 uk" + "\n" +
117
"1 1 2 UMMWT 3 ina" + "\n" +
118
"1 1 3 MDR04 4 ita" + "\n" +
119
"1 1 4 FREDRIK 4 den" + "\n" +
120
"1 2 0 HAGER 5 egy" + "\n" +
121
"1 2 1 S13 7 usa" + "\n" +
122
"1 2 2 UTEK 7 ina" + "\n" +
123
"1 2 3 UMMWT 7 ina" + "\n" +
124
"1 2 4 210JITQU 7 ukr" + "\n" +
125
"1 3 0 UTEK 16 ina" + "\n" +
126
"1 3 1 LOLO766 21 fra" + "\n" +
127
"1 3 2 NIKITOS 21 rus" + "\n" +
128
"1 3 3 PYCUK1707 21 rus" + "\n" +
129
"1 3 4 KEDAR 22 ind" + "\n" +
130
"2 0 0 INEED7X7X7 1 rus" + "\n" +
131
"2 0 1 HOMER0815 1 ger" + "\n" +
132
"2 0 2 EIP 1 usa" + "\n" +
133
"2 0 3 THEBIGBOSS 1 fra" + "\n" +
134
"2 0 4 PHONG 1 vie" + "\n" +
135
"2 1 0 SATERNSPY9 3 unk" + "\n" +
136
"2 1 1 S13 4 usa" + "\n" +
137
"2 1 2 ALSOELAN 4 usa" + "\n" +
138
"2 1 3 NIKITOS 4 rus" + "\n" +
139
"2 1 4 SEPIA6MIRA 4 unk" + "\n" +
140
"2 2 0 STEVE123 9 irl" + "\n" +
141
"2 2 1 NIKITOS 9 rus" + "\n" +
142
"2 2 2 SEPIA6MIRA 9 unk" + "\n" +
143
"2 2 3 INEED7X7X7 10 rus" + "\n" +
144
"2 2 4 S13 10 usa" + "\n" +
145
"2 3 0 NIKITOS 22 rus" + "\n" +
146
"2 3 1 RUBIK123 24 lit" + "\n" +
147
"2 3 2 NONAME 24 fin" + "\n" +
148
"2 3 3 ABB0 26 ind" + "\n" +
149
"2 3 4 NOYS 27 mex" + "\n" +
150
"3 0 0 JARO 1 ger" + "\n" +
151
"3 0 1 INEED7X7X7 1 rus" + "\n" +
152
"3 0 2 MDR04 1 ita" + "\n" +
153
"3 0 3 SAMW 1 uk" + "\n" +
154
"3 0 4 MOKAI88 1 den" + "\n" +
155
"3 1 0 MDR04G 3 ita" + "\n" +
156
"3 1 1 INEED7X7X7 4 rus" + "\n" +
157
"3 1 2 S13 4 usa" + "\n" +
158
"3 1 3 KARAVAN 4 rus" + "\n" +
159
"3 1 4 AWSOME897 4 usa" + "\n" +
160
"3 2 0 INEED7X7X7 8 rus" + "\n" +
161
"3 2 1 KARAVAN 8 rus" + "\n" +
162
"3 2 2 S13 9 usa" + "\n" +
163
"3 2 3 ALSOELAN 9 usa" + "\n" +
164
"3 2 4 ROBERT04 9 unk" + "\n" +
165
"3 3 0 NIKITOS 23 rus" + "\n" +
166
"3 3 1 THISNAVIS 23 usa" + "\n" +
167
"3 3 2 INEED7X7X7 24 rus" + "\n" +
168
"3 3 3 RUBIK123 30 lit" + "\n" +
169
"3 3 4 SKY16 31 usa";
170
      }
171
    }
172
  catch( Exception e )
173
    {
174
    android.util.Log.e("downloader", "Exception downloading records: "+e.getMessage() );
175
    }
176

    
177
  mRunning = false;
178
  mReceiver.receive(mScores);
179
  }
180
}
(6-6/11)