Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialObjectLibInterface.java @ ce31f774

1 1cd323dd Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2 05c20dad Leszek Koltunski
// Copyright 2021 Leszek Koltunski                                                               //
3 1cd323dd Leszek Koltunski
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 bb62ca3f Leszek Koltunski
// 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 1cd323dd Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.tutorials;
11
12 ce31f774 Leszek Koltunski
import android.util.DisplayMetrics;
13
14 95472aca Leszek Koltunski
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 e019c70b Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectLibInterface;
20 1cd323dd Leszek Koltunski
21 e019c70b Leszek Koltunski
import java.lang.ref.WeakReference;
22
23 1cd323dd Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
24
25 e019c70b Leszek Koltunski
public class TutorialObjectLibInterface implements ObjectLibInterface
26 1cd323dd Leszek Koltunski
{
27 ce31f774 Leszek Koltunski
  private final WeakReference<TutorialActivity> mAct;
28 e019c70b Leszek Koltunski
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30
31
  TutorialObjectLibInterface(TutorialActivity act)
32
    {
33
    mAct = new WeakReference<>(act);
34
    }
35
36 ce31f774 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
37
38 1fa125c2 Leszek Koltunski
  public void onWinEffectFinished(long startTime, long endTime, String debug, int scrambleNum) { }
39 95472aca Leszek Koltunski
  public void onScrambleEffectFinished() { }
40
  public void onBeginRotation() { }
41
  public void onSolved() { }
42
  public void onObjectCreated(long time) { }
43 5c4ed8ed Leszek Koltunski
  public void onReplaceModeDown(int cubit, int face) { }
44
  public void onReplaceModeUp() { }
45 c020555e Leszek Koltunski
  public void reportJSONError(String error, int ordinal) { }
46 95472aca Leszek Koltunski
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48
49 eb647d5e Leszek Koltunski
  public void reportProblem(String problem, boolean reportException)
50 95472aca Leszek Koltunski
    {
51
    if( BuildConfig.DEBUG )
52
      {
53
      android.util.Log.e("interface", problem);
54
      }
55
    else
56
      {
57 eb647d5e Leszek Koltunski
      if( reportException )
58
        {
59
        Exception ex = new Exception(problem);
60
        FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
61
        crashlytics.setCustomKey("problem" , problem);
62
        crashlytics.recordException(ex);
63
        }
64
      else
65
        {
66
        FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
67
        crashlytics.log(problem);
68
        }
69 95472aca Leszek Koltunski
      }
70
    }
71
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73
74 919b830e Leszek Koltunski
  private void reportScramblingProblem(int place, long pause, long resume, long time)
75 95472aca Leszek Koltunski
    {
76 919b830e Leszek Koltunski
    String error = "SCRAMBLING BLOCK "+place+" blocked for "+time;
77 95472aca Leszek Koltunski
78
    if( BuildConfig.DEBUG )
79
       {
80
       android.util.Log.e("D", error);
81
       }
82
    else
83
      {
84
      Exception ex = new Exception(error);
85
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
86
      crashlytics.setCustomKey("pause" , pause );
87
      crashlytics.setCustomKey("resume", resume );
88
      crashlytics.recordException(ex);
89
      }
90
    }
91
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93
94 919b830e Leszek Koltunski
  private void reportRotationProblem(int place, long pause, long resume, long time)
95 95472aca Leszek Koltunski
    {
96 919b830e Leszek Koltunski
    String error = "ROTATION BLOCK "+place+" blocked for "+time;
97 95472aca Leszek Koltunski
98
    if( BuildConfig.DEBUG )
99
       {
100
       android.util.Log.e("D", error);
101
       }
102
    else
103
      {
104
      Exception ex = new Exception(error);
105
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
106
      crashlytics.setCustomKey("pause" , pause );
107
      crashlytics.setCustomKey("resume", resume);
108
      crashlytics.recordException(ex);
109
      }
110
    }
111
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113
114
  private void reportThreadProblem(int place, long pause, long resume, long time)
115
    {
116
    String error = EffectMessageSender.reportState();
117
118
    if( BuildConfig.DEBUG )
119
       {
120
       android.util.Log.e("D", error);
121
       }
122
    else
123
      {
124
      Exception ex = new Exception(error);
125
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
126
      crashlytics.setCustomKey("pause" , pause  );
127
      crashlytics.setCustomKey("resume", resume );
128
      crashlytics.recordException(ex);
129
      }
130
    }
131
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133
134
  public void reportBlockProblem(int type, int place, long pause, long resume, long time)
135
    {
136
    switch(type)
137
      {
138 919b830e Leszek Koltunski
      case BlockController.TYPE_SCRAMBLING: reportScramblingProblem(place,pause,resume,time); break;
139
      case BlockController.TYPE_ROTATION  : reportRotationProblem(place,pause,resume,time); break;
140
      case BlockController.TYPE_THREAD    : reportThreadProblem(place,pause,resume,time); break;
141 95472aca Leszek Koltunski
      }
142
    }
143 dd1a65c1 Leszek Koltunski
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145
146 ce31f774 Leszek Koltunski
  public void onFinishRotation(int axis, int row, int angle)
147 dd1a65c1 Leszek Koltunski
     {
148 e019c70b Leszek Koltunski
     TutorialActivity act = mAct.get();
149
     TutorialScreen state = act.getState();
150 4cad53b4 Leszek Koltunski
     if( state!=null ) state.addMove(act, axis, row, angle);
151 dd1a65c1 Leszek Koltunski
     }
152
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154
155 ce31f774 Leszek Koltunski
  public void failedToDrag()
156 dd1a65c1 Leszek Koltunski
     {
157 e019c70b Leszek Koltunski
     TutorialActivity act = mAct.get();
158
     TutorialScreen state = act.getState();
159 dd1a65c1 Leszek Koltunski
     state.reddenLock(act);
160
     }
161 ce31f774 Leszek Koltunski
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163
164
  public int getScreenDensity()
165
    {
166
    DisplayMetrics dm = new DisplayMetrics();
167
    mAct.get().getWindowManager().getDefaultDisplay().getMetrics(dm);
168
    return dm.densityDpi;
169
    }
170 1cd323dd Leszek Koltunski
}