Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.tutorials;
11

    
12
import android.util.DisplayMetrics;
13

    
14
import com.google.firebase.crashlytics.FirebaseCrashlytics;
15

    
16
import org.distorted.library.message.EffectMessageSender;
17
import org.distorted.objectlib.BuildConfig;
18
import org.distorted.objectlib.helpers.BlockController;
19
import org.distorted.objectlib.helpers.ObjectLibInterface;
20

    
21
import java.lang.ref.WeakReference;
22

    
23
///////////////////////////////////////////////////////////////////////////////////////////////////
24

    
25
public class TutorialObjectLibInterface implements ObjectLibInterface
26
{
27
  private final WeakReference<TutorialActivity> mAct;
28

    
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

    
31
  TutorialObjectLibInterface(TutorialActivity act)
32
    {
33
    mAct = new WeakReference<>(act);
34
    }
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
  public void onWinEffectFinished(long startTime, long endTime, String debug, int scrambleNum) { }
39
  public void onScrambleEffectFinished() { }
40
  public void onBeginRotation() { }
41
  public void onSolved() { }
42
  public void onObjectCreated(long time) { }
43
  public void onReplaceModeDown(int cubit, int face) { }
44
  public void onReplaceModeUp() { }
45
  public void reportJSONError(String error, int ordinal) { }
46

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

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

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

    
74
  private void reportScramblingProblem(int place, long pause, long resume, long time)
75
    {
76
    String error = "SCRAMBLING BLOCK "+place+" blocked for "+time;
77

    
78
    if( BuildConfig.DEBUG )
79
       {
80
       android.util.Log.e("D", error);
81
       }
82
    else
83
      {
84
      Exception ex = new Exception(error);
85
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
86
      crashlytics.setCustomKey("pause" , pause );
87
      crashlytics.setCustomKey("resume", resume );
88
      crashlytics.recordException(ex);
89
      }
90
    }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
  private void reportRotationProblem(int place, long pause, long resume, long time)
95
    {
96
    String error = "ROTATION BLOCK "+place+" blocked for "+time;
97

    
98
    if( BuildConfig.DEBUG )
99
       {
100
       android.util.Log.e("D", error);
101
       }
102
    else
103
      {
104
      Exception ex = new Exception(error);
105
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
106
      crashlytics.setCustomKey("pause" , pause );
107
      crashlytics.setCustomKey("resume", resume);
108
      crashlytics.recordException(ex);
109
      }
110
    }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
  private void reportThreadProblem(int place, long pause, long resume, long time)
115
    {
116
    String error = EffectMessageSender.reportState();
117

    
118
    if( BuildConfig.DEBUG )
119
       {
120
       android.util.Log.e("D", error);
121
       }
122
    else
123
      {
124
      Exception ex = new Exception(error);
125
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
126
      crashlytics.setCustomKey("pause" , pause  );
127
      crashlytics.setCustomKey("resume", resume );
128
      crashlytics.recordException(ex);
129
      }
130
    }
131

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

    
134
  public void reportBlockProblem(int type, int place, long pause, long resume, long time)
135
    {
136
    switch(type)
137
      {
138
      case BlockController.TYPE_SCRAMBLING: reportScramblingProblem(place,pause,resume,time); break;
139
      case BlockController.TYPE_ROTATION  : reportRotationProblem(place,pause,resume,time); break;
140
      case BlockController.TYPE_THREAD    : reportThreadProblem(place,pause,resume,time); break;
141
      }
142
    }
143

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

    
146
  public void onFinishRotation(int axis, int row, int angle)
147
     {
148
     TutorialActivity act = mAct.get();
149
     TutorialScreen state = act.getState();
150
     if( state!=null ) state.addMove(act, axis, row, angle);
151
     }
152

    
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154

    
155
  public void failedToDrag()
156
     {
157
     TutorialActivity act = mAct.get();
158
     TutorialScreen state = act.getState();
159
     state.reddenLock(act);
160
     }
161
}
(3-3/7)