1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2021 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.config;
|
11
|
|
12
|
import android.util.DisplayMetrics;
|
13
|
|
14
|
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
|
import org.distorted.objectlib.helpers.ObjectLibInterface;
|
20
|
|
21
|
import java.lang.ref.WeakReference;
|
22
|
|
23
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
24
|
|
25
|
public class ConfigObjectLibInterface implements ObjectLibInterface
|
26
|
{
|
27
|
private final WeakReference<ConfigActivity> mAct;
|
28
|
|
29
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30
|
|
31
|
public void onWinEffectFinished(long startTime, long endTime, String debug, int scrambleNum) { }
|
32
|
public void onScrambleEffectFinished() { }
|
33
|
public void onBeginRotation() { }
|
34
|
public void onSolved() { }
|
35
|
public void onObjectCreated(long time) { }
|
36
|
public void onReplaceModeDown(int cubit, int face) { }
|
37
|
public void onReplaceModeUp() { }
|
38
|
public void onFinishRotation(int axis, int row, int angle) { }
|
39
|
public void failedToDrag() { }
|
40
|
public void reportJSONError(String error, int ordinal) { }
|
41
|
|
42
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43
|
|
44
|
public void reportProblem(String problem, boolean reportException)
|
45
|
{
|
46
|
if( BuildConfig.DEBUG )
|
47
|
{
|
48
|
android.util.Log.e("interface", problem);
|
49
|
}
|
50
|
else
|
51
|
{
|
52
|
if( reportException )
|
53
|
{
|
54
|
Exception ex = new Exception(problem);
|
55
|
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
|
56
|
crashlytics.setCustomKey("problem" , problem);
|
57
|
crashlytics.recordException(ex);
|
58
|
}
|
59
|
else
|
60
|
{
|
61
|
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
|
62
|
crashlytics.log(problem);
|
63
|
}
|
64
|
}
|
65
|
}
|
66
|
|
67
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
68
|
|
69
|
private void reportScramblingProblem(int place, long pause, long resume, long time)
|
70
|
{
|
71
|
String error = "SCRAMBLING BLOCK "+place+" blocked for "+time;
|
72
|
|
73
|
if( BuildConfig.DEBUG )
|
74
|
{
|
75
|
android.util.Log.e("D", error);
|
76
|
}
|
77
|
else
|
78
|
{
|
79
|
Exception ex = new Exception(error);
|
80
|
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
|
81
|
crashlytics.setCustomKey("pause" , pause );
|
82
|
crashlytics.setCustomKey("resume", resume );
|
83
|
crashlytics.recordException(ex);
|
84
|
}
|
85
|
}
|
86
|
|
87
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
88
|
|
89
|
private void reportRotationProblem(int place, long pause, long resume, long time)
|
90
|
{
|
91
|
String error = "ROTATION BLOCK "+place+" blocked for "+time;
|
92
|
|
93
|
if( BuildConfig.DEBUG )
|
94
|
{
|
95
|
android.util.Log.e("D", error);
|
96
|
}
|
97
|
else
|
98
|
{
|
99
|
Exception ex = new Exception(error);
|
100
|
FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
|
101
|
crashlytics.setCustomKey("pause" , pause );
|
102
|
crashlytics.setCustomKey("resume", resume);
|
103
|
crashlytics.recordException(ex);
|
104
|
}
|
105
|
}
|
106
|
|
107
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
108
|
|
109
|
private void reportThreadProblem(int place, long pause, long resume, long time)
|
110
|
{
|
111
|
String error = EffectMessageSender.reportState();
|
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
|
public void reportBlockProblem(int type, int place, long pause, long resume, long time)
|
130
|
{
|
131
|
switch(type)
|
132
|
{
|
133
|
case BlockController.TYPE_SCRAMBLING: reportScramblingProblem(place,pause,resume,time); break;
|
134
|
case BlockController.TYPE_ROTATION : reportRotationProblem(place,pause,resume,time); break;
|
135
|
case BlockController.TYPE_THREAD : reportThreadProblem(place,pause,resume,time); break;
|
136
|
}
|
137
|
}
|
138
|
|
139
|
|
140
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
141
|
|
142
|
ConfigObjectLibInterface(ConfigActivity act)
|
143
|
{
|
144
|
mAct = new WeakReference<>(act);
|
145
|
}
|
146
|
|
147
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
148
|
|
149
|
public int getScreenDensity()
|
150
|
{
|
151
|
DisplayMetrics dm = new DisplayMetrics();
|
152
|
mAct.get().getWindowManager().getDefaultDisplay().getMetrics(dm);
|
153
|
return dm.densityDpi;
|
154
|
}
|
155
|
}
|