Project

General

Profile

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

magiccube / src / main / java / org / distorted / solvers / SolverObjectLibInterface.java @ 47f42042

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.solvers;
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.objectlib.metadata.ListObjects;
20
import org.distorted.objects.RubikObject;
21
import org.distorted.objects.RubikObjectList;
22
import org.distorted.objectlib.solvers.verifiers.ImplementedVerifierList;
23

    
24
import java.lang.ref.WeakReference;
25

    
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27

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

    
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34

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

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

    
43
  public void onScrambleEffectFinished() { }
44
  public void onRemoveRotation(int axis, int rowBitmap, int degrees) { }
45
  public void onBeginRotation() { }
46
  public void failedToDrag() { }
47
  public void onSolved() { }
48
  public void onObjectCreated(long time) { }
49
  public void onWinEffectFinished(long startTime, long endTime, int scrambleNum) { }
50

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

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

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

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

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

    
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

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

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

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

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

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

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

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

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

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

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

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

    
171
  public void onStickerTouched(int cubit, int face)
172
    {
173
    SolverActivity act = mAct.get();
174
    ScreenSetupPosition solver = (ScreenSetupPosition) ScreenList.SVER.getScreenClass();
175
    int color = solver.getCurrentColor();
176
    ListObjects currObject = act.getObjectList();
177
    mLastCubitColor = ImplementedVerifierList.cubitIsLocked(currObject,cubit);
178
    mLastCubit = cubit;
179
    mLastCubitFace = face;
180
    ObjectControl control = act.getControl();
181
    control.setTextureMap( cubit, face, color );
182
    }
183

    
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185

    
186
  public void onStickerUntouched()
187
    {
188
    if( mLastCubitColor>=0 )
189
      {
190
      ObjectControl control = mAct.get().getControl();
191
      control.setTextureMap( mLastCubit, mLastCubitFace, mLastCubitColor );
192
      mLastCubitColor = -1;
193
      }
194
    }
195
}
(9-9/11)