Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialObjectLibInterface.java @ c020555e

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.tutorials;
21

    
22
import com.google.firebase.crashlytics.FirebaseCrashlytics;
23

    
24
import org.distorted.library.message.EffectMessageSender;
25
import org.distorted.objectlib.BuildConfig;
26
import org.distorted.objectlib.helpers.BlockController;
27
import org.distorted.objectlib.helpers.ObjectLibInterface;
28

    
29
import java.lang.ref.WeakReference;
30

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
public class TutorialObjectLibInterface implements ObjectLibInterface
34
{
35
   WeakReference<TutorialActivity> mAct;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
  TutorialObjectLibInterface(TutorialActivity act)
40
    {
41
    mAct = new WeakReference<>(act);
42
    }
43

    
44
  public void onWinEffectFinished(long startTime, long endTime, String debug, int scrambleNum) { }
45
  public void onScrambleEffectFinished() { }
46
  public void onBeginRotation() { }
47
  public void onSolved() { }
48
  public void onObjectCreated(long time) { }
49
  public void onReplaceModeDown(int cubit, int face) { }
50
  public void onReplaceModeUp() { }
51
  public void reportJSONError(String error, int ordinal) { }
52

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

    
55
  public void reportProblem(String problem, boolean reportException)
56
    {
57
    if( BuildConfig.DEBUG )
58
      {
59
      android.util.Log.e("interface", problem);
60
      }
61
    else
62
      {
63
      if( reportException )
64
        {
65
        Exception ex = new Exception(problem);
66
        FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
67
        crashlytics.setCustomKey("problem" , problem);
68
        crashlytics.recordException(ex);
69
        }
70
      else
71
        {
72
        FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
73
        crashlytics.log(problem);
74
        }
75
      }
76
    }
77

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

    
80
  private void reportUIProblem(int place, long pause, long resume, long time)
81
    {
82
    String error = "UI BLOCK "+place+" blocked for "+time;
83

    
84
    if( BuildConfig.DEBUG )
85
       {
86
       android.util.Log.e("D", error);
87
       }
88
    else
89
      {
90
      Exception ex = new Exception(error);
91
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
92
      crashlytics.setCustomKey("pause" , pause );
93
      crashlytics.setCustomKey("resume", resume );
94
      crashlytics.recordException(ex);
95
      }
96
    }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

    
100
  private void reportTouchProblem(int place, long pause, long resume, long time)
101
    {
102
    String error = "TOUCH BLOCK "+place+" blocked for "+time;
103

    
104
    if( BuildConfig.DEBUG )
105
       {
106
       android.util.Log.e("D", error);
107
       }
108
    else
109
      {
110
      Exception ex = new Exception(error);
111
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
112
      crashlytics.setCustomKey("pause" , pause );
113
      crashlytics.setCustomKey("resume", resume);
114
      crashlytics.recordException(ex);
115
      }
116
    }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

    
120
  private void reportThreadProblem(int place, long pause, long resume, long time)
121
    {
122
    String error = EffectMessageSender.reportState();
123

    
124
    if( BuildConfig.DEBUG )
125
       {
126
       android.util.Log.e("D", error);
127
       }
128
    else
129
      {
130
      Exception ex = new Exception(error);
131
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
132
      crashlytics.setCustomKey("pause" , pause  );
133
      crashlytics.setCustomKey("resume", resume );
134
      crashlytics.recordException(ex);
135
      }
136
    }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
  public void reportBlockProblem(int type, int place, long pause, long resume, long time)
141
    {
142
    switch(type)
143
      {
144
      case BlockController.TYPE_UI    : reportUIProblem(place,pause,resume,time); break;
145
      case BlockController.TYPE_TOUCH : reportTouchProblem(place,pause,resume,time); break;
146
      case BlockController.TYPE_THREAD: reportThreadProblem(place,pause,resume,time); break;
147
      }
148
    }
149

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

    
152
   public void onFinishRotation(int axis, int row, int angle)
153
     {
154
     TutorialActivity act = mAct.get();
155
     TutorialScreen state = act.getState();
156
     if( state!=null ) state.addMove(act, axis, row, angle);
157
     }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
   public void failedToDrag()
162
     {
163
     TutorialActivity act = mAct.get();
164
     TutorialScreen state = act.getState();
165
     state.reddenLock(act);
166
     }
167
}
(2-2/6)