Project

General

Profile

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

magiccube / src / main / java / org / distorted / main / RubikDebug.java @ b6f7c7f2

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 LOOP_INTERVAL = 500;
32
  private static final int LOOP_NUM1     = 5;
33
  private static final int LOOP_NUM2     = 9;
34

    
35
  private String mDebug;
36
  private int mNumReturned;
37
  private ActivityChanger mChanger;
38

    
39
  public static RubikDebug mThis;
40

    
41
  public interface ActivityChanger
42
    {
43
    void change();
44
    void assign();
45
    }
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
  private void initialize()
50
    {
51
    mDebug      = "";
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==LOOP_NUM1 )
70
      {
71
      mChanger.assign();
72
      }
73
    if( loopNum==LOOP_NUM2 )
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
    }
115

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

    
118
  public void onPause()
119
    {
120
    initialize();
121
    }
122

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

    
125
  public void onFirstDraw()
126
    {
127
    final Timer timer = new Timer();
128

    
129
    timer.scheduleAtFixedRate(new TimerTask()
130
      {
131
      private int mLoopNum = 0;
132

    
133
      @Override
134
      public void run()
135
        {
136
        if( mLoopNum==LOOP_NUM2 )
137
          {
138
          timer.cancel();
139
          }
140

    
141
        check(mLoopNum++);
142
        }
143
      } ,LOOP_INTERVAL, LOOP_INTERVAL);
144
    }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

    
148
  public void onReturned()
149
    {
150
    mNumReturned++;
151
    }
152
  }
(2-2/5)