Project

General

Profile

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

magiccube / src / main / java / org / distorted / solverui / SolverObjectLibInterface.java @ e9245b7b

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 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.solverui;
11

    
12
import com.google.firebase.crashlytics.FirebaseCrashlytics;
13

    
14
import org.distorted.library.message.EffectMessageSender;
15
import org.distorted.main.BuildConfig;
16
import org.distorted.objectlib.helpers.BlockController;
17
import org.distorted.objectlib.helpers.ObjectLibInterface;
18
import org.distorted.objectlib.main.ObjectControl;
19
import org.distorted.objects.RubikObject;
20
import org.distorted.objects.RubikObjectList;
21
import org.distorted.solvers.SolverMain;
22

    
23
import java.lang.ref.WeakReference;
24

    
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26

    
27
public class SolverObjectLibInterface implements ObjectLibInterface
28
{
29
  private final WeakReference<SolverActivity> mAct;
30
  private int mLastCubitColor, mLastCubit, mLastCubitFace;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

    
34
  SolverObjectLibInterface(SolverActivity act)
35
    {
36
    mAct = new WeakReference<>(act);
37
    mLastCubitColor = -1;
38
    }
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

    
42
  public void onScrambleEffectFinished() { }
43
  public void onFinishRotation(int axis, int row, int angle) { }
44
  public void onBeginRotation() { }
45
  public void failedToDrag() { }
46
  public void onSolved() { }
47
  public void onObjectCreated(long time) { }
48
  public void onWinEffectFinished(long startTime, long endTime, String debug, int scrambleNum) { }
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

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

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

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

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

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

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

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

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

    
117
  private void reportThreadProblem(int place, long pause, long resume, long time)
118
    {
119
    String error = EffectMessageSender.reportState();
120

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

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

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

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148

    
149
  public void reportJSONError(String error, int ordinal)
150
    {
151
    RubikObject object = RubikObjectList.getObject(ordinal);
152
    String name = object==null ? "NULL" : object.getUpperName();
153

    
154
    if( BuildConfig.DEBUG )
155
       {
156
       android.util.Log.e("libInterface", "name="+name+" JSON error: "+error);
157
       }
158
    else
159
      {
160
      Exception ex = new Exception(error);
161
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
162
      crashlytics.setCustomKey("name" , name );
163
      crashlytics.setCustomKey("JSONerror", error );
164
      crashlytics.recordException(ex);
165
      }
166
    }
167

    
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169

    
170
  public void onReplaceModeDown(int cubit, int face)
171
    {
172
    ScreenSolver solver = (ScreenSolver) ScreenList.SVER.getScreenClass();
173
    int color = solver.getCurrentColor();
174
    int currObject = RubikObjectList.getCurrObject();
175
    mLastCubitColor = SolverMain.cubitIsLocked(currObject,cubit);
176
    mLastCubit = cubit;
177
    mLastCubitFace = face;
178
    ObjectControl control = mAct.get().getControl();
179
    control.setTextureMap( cubit, face, color );
180
    }
181

    
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

    
184
  public void onReplaceModeUp()
185
    {
186
    if( mLastCubitColor>=0 )
187
      {
188
      ObjectControl control = mAct.get().getControl();
189
      control.setTextureMap( mLastCubit, mLastCubitFace, mLastCubitColor );
190
      mLastCubitColor = -1;
191
      }
192
    }
193
}
(6-6/8)