Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.bandaged;
21

    
22
import java.lang.ref.WeakReference;
23

    
24
import com.google.firebase.crashlytics.FirebaseCrashlytics;
25

    
26
import org.distorted.library.message.EffectMessageSender;
27
import org.distorted.objectlib.BuildConfig;
28
import org.distorted.objectlib.helpers.BlockController;
29
import org.distorted.objectlib.helpers.ObjectLibInterface;
30
import org.distorted.objects.RubikObject;
31
import org.distorted.objects.RubikObjectList;
32

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

    
35
public class BandagedPlayLibInterface implements ObjectLibInterface
36
{
37
  private final WeakReference<BandagedPlayActivity> mAct;
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

    
41
  BandagedPlayLibInterface(BandagedPlayActivity act)
42
    {
43
    mAct = new WeakReference<>(act);
44
    }
45

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

    
48
  public void onWinEffectFinished(long startTime, long endTime, String debug, int scrambleNum) { }
49
  public void onScrambleEffectFinished() { }
50
  public void onBeginRotation() { }
51
  public void onSolved() { }
52
  public void onObjectCreated(long time) { }
53
  public void onReplaceModeDown(int cubit, int face) { }
54
  public void onReplaceModeUp() { }
55

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

    
58
  public void onFinishRotation(int axis, int row, int angle)
59
    {
60
    BandagedPlayActivity act = mAct.get();
61

    
62
    if( act!=null )
63
      {
64
      BandagedPlayScreen play = act.getScreen();
65
      play.addMove(act,axis,row,angle);
66
      }
67
    }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

    
71
  public void failedToDrag()
72
    {
73
    BandagedPlayActivity act = mAct.get();
74

    
75
    if( act!=null )
76
      {
77
      BandagedPlayScreen play = act.getScreen();
78
      play.reddenLock(act);
79
      }
80
    }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
  public void reportProblem(String problem, boolean reportException)
85
    {
86
    if( BuildConfig.DEBUG )
87
      {
88
      android.util.Log.e("interface", problem);
89
      }
90
    else
91
      {
92
      if( reportException )
93
        {
94
        Exception ex = new Exception(problem);
95
        FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
96
        crashlytics.setCustomKey("problem" , problem);
97
        crashlytics.recordException(ex);
98
        }
99
      else
100
        {
101
        FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
102
        crashlytics.log(problem);
103
        }
104
      }
105
    }
106

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

    
109
  private void reportUIProblem(int place, long pause, long resume, long time)
110
    {
111
    String error = "UI BLOCK "+place+" blocked for "+time;
112

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

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

    
129
  private void reportTouchProblem(int place, long pause, long resume, long time)
130
    {
131
    String error = "TOUCH BLOCK "+place+" blocked for "+time;
132

    
133
    if( BuildConfig.DEBUG )
134
       {
135
       android.util.Log.e("D", error);
136
       }
137
    else
138
      {
139
      Exception ex = new Exception(error);
140
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
141
      crashlytics.setCustomKey("pause" , pause );
142
      crashlytics.setCustomKey("resume", resume);
143
      crashlytics.recordException(ex);
144
      }
145
    }
146

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

    
149
  private void reportThreadProblem(int place, long pause, long resume, long time)
150
    {
151
    String error = EffectMessageSender.reportState();
152

    
153
    if( BuildConfig.DEBUG )
154
       {
155
       android.util.Log.e("D", error);
156
       }
157
    else
158
      {
159
      Exception ex = new Exception(error);
160
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
161
      crashlytics.setCustomKey("pause" , pause  );
162
      crashlytics.setCustomKey("resume", resume );
163
      crashlytics.recordException(ex);
164
      }
165
    }
166

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168

    
169
  public void reportBlockProblem(int type, int place, long pause, long resume, long time)
170
    {
171
    switch(type)
172
      {
173
      case BlockController.TYPE_UI    : reportUIProblem(place,pause,resume,time); break;
174
      case BlockController.TYPE_TOUCH : reportTouchProblem(place,pause,resume,time); break;
175
      case BlockController.TYPE_THREAD: reportThreadProblem(place,pause,resume,time); break;
176
      }
177
    }
178

    
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180

    
181
  public void reportJSONError(String error, int ordinal)
182
    {
183
    RubikObject object = RubikObjectList.getObject(ordinal);
184
    String name = object==null ? "NULL" : object.getUpperName();
185

    
186
    if( BuildConfig.DEBUG )
187
       {
188
       android.util.Log.e("libInterface", "name="+name+" JSON error: "+error);
189
       }
190
    else
191
      {
192
      Exception ex = new Exception(error);
193
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
194
      crashlytics.setCustomKey("name" , name );
195
      crashlytics.setCustomKey("JSONerror", error );
196
      crashlytics.recordException(ex);
197
      }
198
    }
199

    
200
}
(10-10/13)