Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayLibInterface.java @ f404152d

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 android.util.DisplayMetrics;
13

    
14
import java.lang.ref.WeakReference;
15

    
16
import com.google.firebase.crashlytics.FirebaseCrashlytics;
17

    
18
import org.distorted.library.message.EffectMessageSender;
19
import org.distorted.objectlib.BuildConfig;
20
import org.distorted.objectlib.helpers.BlockController;
21
import org.distorted.objectlib.helpers.ObjectLibInterface;
22
import org.distorted.objects.RubikObject;
23
import org.distorted.objects.RubikObjectList;
24

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

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

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
  BandagedPlayLibInterface(BandagedPlayActivity act)
34
    {
35
    mAct = new WeakReference<>(act);
36
    }
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

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

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

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

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

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
  public void failedToDrag()
64
    {
65
    BandagedPlayActivity act = mAct.get();
66

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

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

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

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  private void reportScramblingProblem(int place, long pause, long resume, long time)
102
    {
103
    String error = "SCRAMBLING BLOCK "+place+" blocked for "+time;
104

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

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

    
121
  private void reportRotationProblem(int place, long pause, long resume, long time)
122
    {
123
    String error = "ROTATION BLOCK "+place+" blocked for "+time;
124

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

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

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

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

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  public void reportBlockProblem(int type, int place, long pause, long resume, long time)
162
    {
163
    switch(type)
164
      {
165
      case BlockController.TYPE_SCRAMBLING: reportScramblingProblem(place,pause,resume,time); break;
166
      case BlockController.TYPE_ROTATION  : reportRotationProblem(place,pause,resume,time); break;
167
      case BlockController.TYPE_THREAD    : reportThreadProblem(place,pause,resume,time); break;
168
      }
169
    }
170

    
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

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

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

    
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

    
194
  public int getScreenDensity()
195
    {
196
    DisplayMetrics dm = new DisplayMetrics();
197
    mAct.get().getWindowManager().getDefaultDisplay().getMetrics(dm);
198
    return dm.densityDpi;
199
    }
200
}
(11-11/14)