1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2021 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.main;
|
21
|
|
22
|
import org.distorted.scores.RubikScoresDownloader;
|
23
|
|
24
|
import java.util.Timer;
|
25
|
import java.util.TimerTask;
|
26
|
|
27
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
28
|
|
29
|
public class RubikDebug
|
30
|
{
|
31
|
private static final int CHECK_INTERVAL = 1000;
|
32
|
|
33
|
private String mDebug;
|
34
|
private long mResumeTime;
|
35
|
private int mNumReturned;
|
36
|
private ActivityChanger mChanger;
|
37
|
|
38
|
public static RubikDebug mThis;
|
39
|
|
40
|
public interface ActivityChanger
|
41
|
{
|
42
|
void change();
|
43
|
void assign();
|
44
|
}
|
45
|
|
46
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47
|
|
48
|
private void initialize()
|
49
|
{
|
50
|
mDebug = "";
|
51
|
mResumeTime = 0;
|
52
|
mNumReturned= 0;
|
53
|
}
|
54
|
|
55
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56
|
|
57
|
private void report(String debug)
|
58
|
{
|
59
|
android.util.Log.e("debug", "Reporting: "+debug);
|
60
|
|
61
|
RubikScoresDownloader downloader = RubikScoresDownloader.getInstance();
|
62
|
downloader.error(debug);
|
63
|
}
|
64
|
|
65
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
66
|
|
67
|
private void check(int loopNum)
|
68
|
{
|
69
|
if( loopNum==1 )
|
70
|
{
|
71
|
mChanger.assign();
|
72
|
}
|
73
|
if( loopNum==4 )
|
74
|
{
|
75
|
if( mNumReturned!=1 )
|
76
|
{
|
77
|
report(mDebug);
|
78
|
}
|
79
|
|
80
|
mChanger.change();
|
81
|
}
|
82
|
}
|
83
|
|
84
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85
|
|
86
|
private RubikDebug()
|
87
|
{
|
88
|
initialize();
|
89
|
}
|
90
|
|
91
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
92
|
|
93
|
public static RubikDebug getInstance()
|
94
|
{
|
95
|
if( mThis==null ) mThis = new RubikDebug();
|
96
|
|
97
|
return mThis;
|
98
|
}
|
99
|
|
100
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
101
|
|
102
|
public static void addDebug(String debug)
|
103
|
{
|
104
|
if( mThis==null ) mThis = new RubikDebug();
|
105
|
|
106
|
mThis.mDebug += (debug + "\n");
|
107
|
}
|
108
|
|
109
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
110
|
|
111
|
public void onResume(ActivityChanger changer)
|
112
|
{
|
113
|
mChanger = changer;
|
114
|
mResumeTime = System.currentTimeMillis();
|
115
|
|
116
|
final Timer timer = new Timer();
|
117
|
|
118
|
timer.scheduleAtFixedRate(new TimerTask()
|
119
|
{
|
120
|
private int mLoopNum = 0;
|
121
|
|
122
|
@Override
|
123
|
public void run()
|
124
|
{
|
125
|
if( mLoopNum==5 )
|
126
|
{
|
127
|
timer.cancel();
|
128
|
}
|
129
|
|
130
|
check(mLoopNum++);
|
131
|
}
|
132
|
} ,CHECK_INTERVAL, CHECK_INTERVAL);
|
133
|
}
|
134
|
|
135
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
136
|
|
137
|
public void onPause()
|
138
|
{
|
139
|
initialize();
|
140
|
}
|
141
|
|
142
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
143
|
|
144
|
public void onReturned()
|
145
|
{
|
146
|
mNumReturned++;
|
147
|
}
|
148
|
}
|