Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayLibInterface.java @ 306aa049

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 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.bandaged;
11

    
12
import java.lang.ref.WeakReference;
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
import org.distorted.objects.RubikObject;
21
import org.distorted.objects.RubikObjectList;
22

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

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

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

    
31
  BandagedPlayLibInterface(BandagedPlayActivity 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

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

    
48
  public void onFinishRotation(int axis, int row, int angle)
49
    {
50
    BandagedPlayActivity act = mAct.get();
51

    
52
    if( act!=null )
53
      {
54
      BandagedPlayScreen play = act.getScreen();
55
      play.addMove(act,axis,row,angle);
56
      }
57
    }
58

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

    
61
  public void failedToDrag()
62
    {
63
    BandagedPlayActivity act = mAct.get();
64

    
65
    if( act!=null )
66
      {
67
      BandagedPlayScreen play = act.getScreen();
68
      play.reddenLock(act);
69
      }
70
    }
71

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

    
74
  public void reportProblem(String problem, boolean reportException)
75
    {
76
    if( BuildConfig.DEBUG )
77
      {
78
      android.util.Log.e("interface", problem);
79
      }
80
    else
81
      {
82
      if( reportException )
83
        {
84
        Exception ex = new Exception(problem);
85
        FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
86
        crashlytics.setCustomKey("problem" , problem);
87
        crashlytics.recordException(ex);
88
        }
89
      else
90
        {
91
        FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
92
        crashlytics.log(problem);
93
        }
94
      }
95
    }
96

    
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

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

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

    
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

    
119
  private void reportTouchProblem(int place, long pause, long resume, long time)
120
    {
121
    String error = "TOUCH BLOCK "+place+" blocked for "+time;
122

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

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
  private void reportThreadProblem(int place, long pause, long resume, long time)
140
    {
141
    String error = EffectMessageSender.reportState();
142

    
143
    if( BuildConfig.DEBUG )
144
       {
145
       android.util.Log.e("D", error);
146
       }
147
    else
148
      {
149
      Exception ex = new Exception(error);
150
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
151
      crashlytics.setCustomKey("pause" , pause  );
152
      crashlytics.setCustomKey("resume", resume );
153
      crashlytics.recordException(ex);
154
      }
155
    }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

    
159
  public void reportBlockProblem(int type, int place, long pause, long resume, long time)
160
    {
161
    switch(type)
162
      {
163
      case BlockController.TYPE_UI    : reportUIProblem(place,pause,resume,time); break;
164
      case BlockController.TYPE_TOUCH : reportTouchProblem(place,pause,resume,time); break;
165
      case BlockController.TYPE_THREAD: reportThreadProblem(place,pause,resume,time); break;
166
      }
167
    }
168

    
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

    
171
  public void reportJSONError(String error, int ordinal)
172
    {
173
    RubikObject object = RubikObjectList.getObject(ordinal);
174
    String name = object==null ? "NULL" : object.getUpperName();
175

    
176
    if( BuildConfig.DEBUG )
177
       {
178
       android.util.Log.e("libInterface", "name="+name+" JSON error: "+error);
179
       }
180
    else
181
      {
182
      Exception ex = new Exception(error);
183
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
184
      crashlytics.setCustomKey("name" , name );
185
      crashlytics.setCustomKey("JSONerror", error );
186
      crashlytics.recordException(ex);
187
      }
188
    }
189

    
190
}
(10-10/13)