Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialObjectLibInterface.java @ 2cf21fdc

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 com.google.firebase.crashlytics.FirebaseCrashlytics;
13

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

    
19
import java.lang.ref.WeakReference;
20

    
21
///////////////////////////////////////////////////////////////////////////////////////////////////
22

    
23
public class TutorialObjectLibInterface implements ObjectLibInterface
24
{
25
   WeakReference<TutorialActivity> mAct;
26

    
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

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

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

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

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

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

    
70
  private void reportUIProblem(int place, long pause, long resume, long time)
71
    {
72
    String error = "UI BLOCK "+place+" blocked for "+time;
73

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

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

    
90
  private void reportTouchProblem(int place, long pause, long resume, long time)
91
    {
92
    String error = "TOUCH BLOCK "+place+" blocked for "+time;
93

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

    
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

    
110
  private void reportThreadProblem(int place, long pause, long resume, long time)
111
    {
112
    String error = EffectMessageSender.reportState();
113

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

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

    
130
  public void reportBlockProblem(int type, int place, long pause, long resume, long time)
131
    {
132
    switch(type)
133
      {
134
      case BlockController.TYPE_UI    : reportUIProblem(place,pause,resume,time); break;
135
      case BlockController.TYPE_TOUCH : reportTouchProblem(place,pause,resume,time); break;
136
      case BlockController.TYPE_THREAD: reportThreadProblem(place,pause,resume,time); break;
137
      }
138
    }
139

    
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

    
142
   public void onFinishRotation(int axis, int row, int angle)
143
     {
144
     TutorialActivity act = mAct.get();
145
     TutorialScreen state = act.getState();
146
     if( state!=null ) state.addMove(act, axis, row, angle);
147
     }
148

    
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150

    
151
   public void failedToDrag()
152
     {
153
     TutorialActivity act = mAct.get();
154
     TutorialScreen state = act.getState();
155
     state.reddenLock(act);
156
     }
157
}
(2-2/6)