Project

General

Profile

« Previous | Next » 

Revision 9530f6b0

Added by Leszek Koltunski over 2 years ago

Beginnings of support for UI used to create any bandaged 3x3.

View differences:

src/main/AndroidManifest.xml
30 30

  
31 31
        <activity android:name="org.distorted.tutorials.TutorialActivity" android:exported="true" android:screenOrientation="portrait"/>
32 32
        <activity android:name="org.distorted.config.ConfigActivity" android:exported="true" android:screenOrientation="portrait"/>
33
        <activity android:name="org.distorted.bandaged.BandagedCreatorActivity" android:exported="true" android:screenOrientation="portrait"/>
34
        <activity android:name="org.distorted.bandaged.BandagedPlayActivity" android:exported="true" android:screenOrientation="portrait"/>
33 35
    </application>
34 36
</manifest>
src/main/java/org/distorted/bandaged/BandagedCreatorActivity.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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 android.os.Build;
23
import android.os.Bundle;
24
import android.util.DisplayMetrics;
25
import android.view.View;
26
import android.view.ViewGroup;
27
import android.view.WindowManager;
28
import android.widget.LinearLayout;
29
import android.widget.ScrollView;
30

  
31
import androidx.appcompat.app.AppCompatActivity;
32

  
33
import com.google.firebase.analytics.FirebaseAnalytics;
34

  
35
import org.distorted.dialogs.RubikDialogError;
36
import org.distorted.library.main.DistortedLibrary;
37
import org.distorted.main.R;
38
import org.distorted.objectlib.main.ObjectControl;
39
import org.distorted.objects.RubikObject;
40
import org.distorted.objects.RubikObjectList;
41

  
42
import java.io.InputStream;
43

  
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

  
46
public class BandagedCreatorActivity extends AppCompatActivity
47
{
48
    private static final int ACTIVITY_NUMBER = 3;
49
    private static final float RATIO_BAR   = 0.10f;
50
    private static final float RATIO_SCROLL= 0.30f;
51

  
52
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
53
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
54

  
55
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
56
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
57
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
58
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
59
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
60

  
61
    private FirebaseAnalytics mFirebaseAnalytics;
62
    private static int mScreenWidth, mScreenHeight;
63
    private int mCurrentApiVersion;
64
    private BandagedCreatorScreen mScreen;
65
    private int mObjectOrdinal;
66
    private int mHeightBar;
67

  
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

  
70
    @Override
71
    protected void onCreate(Bundle savedState)
72
      {
73
      super.onCreate(savedState);
74
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
75
      setTheme(R.style.MaterialThemeNoActionBar);
76
      setContentView(R.layout.bandaged);
77

  
78
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
79

  
80
      DisplayMetrics displaymetrics = new DisplayMetrics();
81
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
82
      mScreenWidth =displaymetrics.widthPixels;
83
      mScreenHeight=displaymetrics.heightPixels;
84
      mScreenHeight = (int)(1.07f*mScreenHeight); // add 7% for the upper bar
85
                                                  // which is not yet hidden.
86
                                                  // TODO: figure this out exactly.
87
      hideNavigationBar();
88
      cutoutHack();
89
      computeHeights();
90
      }
91

  
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93
// this does not include possible insets
94

  
95
    private void computeHeights()
96
      {
97
      int barHeight    = (int)(mScreenHeight*RATIO_BAR);
98
      int scrollHeight = (int)(mScreenHeight*RATIO_SCROLL);
99
      int viewHeight   = (int)(mScreenHeight*(1-RATIO_SCROLL));
100
      mHeightBar = barHeight;
101

  
102
      LinearLayout layout = findViewById(R.id.lowerBar);
103
      ViewGroup.LayoutParams paramsL = layout.getLayoutParams();
104
      paramsL.height = barHeight;
105
      layout.setLayoutParams(paramsL);
106

  
107
      ScrollView scroll = findViewById(R.id.bandagedCreatorScrollView);
108
      ViewGroup.LayoutParams paramsS = scroll.getLayoutParams();
109
      paramsS.height = scrollHeight;
110
      scroll.setLayoutParams(paramsS);
111

  
112
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorView);
113
      ViewGroup.LayoutParams paramsV = view.getLayoutParams();
114
      paramsV.height = viewHeight;
115
      view.setLayoutParams(paramsV);
116
      }
117

  
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

  
120
    private void hideNavigationBar()
121
      {
122
      mCurrentApiVersion = Build.VERSION.SDK_INT;
123

  
124
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
125
        {
126
        final View decorView = getWindow().getDecorView();
127

  
128
        decorView.setSystemUiVisibility(FLAGS);
129

  
130
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
131
          {
132
          @Override
133
          public void onSystemUiVisibilityChange(int visibility)
134
            {
135
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
136
              {
137
              decorView.setSystemUiVisibility(FLAGS);
138
              }
139
            }
140
          });
141
        }
142
      }
143

  
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145
// do not avoid cutouts
146

  
147
    private void cutoutHack()
148
      {
149
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
150
        {
151
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
152
        }
153
      }
154

  
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

  
157
    @Override
158
    public void onWindowFocusChanged(boolean hasFocus)
159
      {
160
      super.onWindowFocusChanged(hasFocus);
161

  
162
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
163
        {
164
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
165
        }
166
      }
167

  
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169
    
170
    @Override
171
    protected void onPause() 
172
      {
173
      super.onPause();
174
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorView);
175
      view.onPause();
176
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
177
      }
178

  
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180
    
181
    @Override
182
    protected void onResume() 
183
      {
184
      super.onResume();
185
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
186
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorView);
187
      view.onResume();
188

  
189
      if( mScreen==null ) mScreen = new BandagedCreatorScreen();
190
      mScreen.onAttachedToWindow(this,mObjectOrdinal);
191
      }
192

  
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194
    
195
    @Override
196
    protected void onDestroy() 
197
      {
198
      super.onDestroy();
199
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
200
      }
201

  
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203

  
204
    void OpenGLError()
205
      {
206
      RubikDialogError errDiag = new RubikDialogError();
207
      errDiag.show(getSupportFragmentManager(), null);
208
      }
209

  
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211

  
212
    private void changeIfDifferent(RubikObject object,int ordinal,ObjectControl control)
213
      {
214
      if( object!=null )
215
        {
216
        int meshState          = object.getMeshState();
217
        InputStream jsonStream = object.getObjectStream(this);
218
        InputStream meshStream = object.getMeshStream(this);
219
        String name            = object.getUpperName();
220

  
221
        control.changeIfDifferent(ordinal,name,meshState,jsonStream,meshStream);
222
        }
223
      }
224

  
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226
// PUBLIC API
227
///////////////////////////////////////////////////////////////////////////////////////////////////
228

  
229
    public void changeObject(int ordinal)
230
      {
231
      mObjectOrdinal = ordinal;
232
      RubikObject object = RubikObjectList.getObject(ordinal);
233
      BandagedCreatorView view = findViewById(R.id.bandagedCreatorView);
234
      }
235

  
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237

  
238
    public FirebaseAnalytics getAnalytics()
239
      {
240
      return mFirebaseAnalytics;
241
      }
242

  
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

  
245
    public int getHeightBar()
246
      {
247
      return mHeightBar;
248
      }
249

  
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251

  
252
    public int getScreenWidthInPixels()
253
      {
254
      return mScreenWidth;
255
      }
256

  
257
///////////////////////////////////////////////////////////////////////////////////////////////////
258

  
259
    public int getScreenHeightInPixels()
260
      {
261
      return mScreenHeight;
262
      }
263

  
264
///////////////////////////////////////////////////////////////////////////////////////////////////
265

  
266
    public static int getDrawableSize()
267
      {
268
      if( mScreenHeight<1000 )
269
        {
270
        return 0;
271
        }
272
      if( mScreenHeight<1600 )
273
        {
274
        return 1;
275
        }
276
      if( mScreenHeight<1900 )
277
        {
278
        return 2;
279
        }
280

  
281
      return 3;
282
      }
283

  
284
///////////////////////////////////////////////////////////////////////////////////////////////////
285

  
286
    public static int getDrawable(int small, int medium, int big, int huge)
287
      {
288
      int size = getDrawableSize();
289

  
290
      switch(size)
291
        {
292
        case 0 : return small;
293
        case 1 : return medium;
294
        case 2 : return big;
295
        default: return huge;
296
        }
297
      }
298
}
src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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 android.opengl.GLSurfaceView;
23

  
24
import org.distorted.library.effect.EffectType;
25
import org.distorted.library.effect.VertexEffectQuaternion;
26
import org.distorted.library.effect.VertexEffectRotate;
27
import org.distorted.library.main.DistortedLibrary;
28
import org.distorted.library.main.DistortedScreen;
29

  
30
import javax.microedition.khronos.egl.EGLConfig;
31
import javax.microedition.khronos.opengles.GL10;
32

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

  
35
public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
36
{
37
   private final BandagedCreatorView mView;
38
   private final DistortedScreen mScreen;
39

  
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

  
42
   BandagedCreatorRenderer(BandagedCreatorView v)
43
     {
44
     final float BRIGHTNESS = 0.333f;
45

  
46
     mView = v;
47
     mScreen = new DistortedScreen();
48
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
49
     }
50

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

  
53
   @Override
54
   public void onDrawFrame(GL10 glUnused)
55
     {
56
     long time = System.currentTimeMillis();
57
     mScreen.render(time);
58
     }
59

  
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

  
62
   @Override
63
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
64
      {
65
      mScreen.resize(width,height);
66
      }
67

  
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

  
70
   @Override
71
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
72
      {
73
      DistortedLibrary.setMax(EffectType.VERTEX,25);
74
      VertexEffectRotate.enable();
75
      VertexEffectQuaternion.enable();
76

  
77
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
78
      }
79

  
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

  
82
   public void distortedException(Exception ex)
83
     {
84
     android.util.Log.e("CREATOR", "unexpected exception: "+ex.getMessage() );
85
     }
86

  
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

  
89
   DistortedScreen getScreen()
90
     {
91
     return mScreen;
92
     }
93
}
src/main/java/org/distorted/bandaged/BandagedCreatorScreen.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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 android.view.View;
23
import android.widget.LinearLayout;
24

  
25
import org.distorted.helpers.TransparentImageButton;
26
import org.distorted.main.R;
27
import org.distorted.main.RubikActivity;
28
import org.distorted.objectlib.main.ObjectControl;
29

  
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

  
32
public class BandagedCreatorScreen
33
{
34
  private TransparentImageButton mBackButton, mResetButton, mDoneButton;
35
  private int mObjectOrdinal;
36
  private int mBarHeight;
37
  private float mButtonSize;
38

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

  
41
  public BandagedCreatorScreen()
42
    {
43

  
44
    }
45

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

  
48
  private void setupBackButton(final BandagedCreatorActivity act)
49
    {
50
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
51
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
52
    mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
53

  
54
    mBackButton.setOnClickListener( new View.OnClickListener()
55
      {
56
      @Override
57
      public void onClick(View v)
58
        {
59
        act.finish();
60
        }
61
      });
62
    }
63

  
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

  
66
  private void setupDoneButton(final BandagedCreatorActivity act)
67
    {
68
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
69
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
70
    mDoneButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
71

  
72
    mDoneButton.setOnClickListener( new View.OnClickListener()
73
      {
74
      @Override
75
      public void onClick(View v)
76
        {
77

  
78
        }
79
      });
80
    }
81

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

  
84
  private void setupResetButton(final BandagedCreatorActivity act)
85
    {
86
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
87
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
88
    mResetButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
89

  
90
    mResetButton.setOnClickListener( new View.OnClickListener()
91
      {
92
      @Override
93
      public void onClick(View v)
94
        {
95

  
96
        }
97
      });
98
    }
99

  
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

  
102
  void onAttachedToWindow(final BandagedCreatorActivity act, final int objectOrdinal)
103
    {
104
    int width = act.getScreenWidthInPixels();
105
    mBarHeight = act.getHeightBar();
106
    mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
107

  
108
    mObjectOrdinal = objectOrdinal;
109

  
110
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
111
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
112
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
113

  
114
    LinearLayout layoutLeft = new LinearLayout(act);
115
    layoutLeft.setLayoutParams(paramsL);
116
    LinearLayout layoutMid  = new LinearLayout(act);
117
    layoutMid.setLayoutParams(paramsM);
118
    LinearLayout layoutRight= new LinearLayout(act);
119
    layoutRight.setLayoutParams(paramsR);
120

  
121
    setupBackButton(act);
122
    layoutRight.addView(mBackButton);
123
    setupDoneButton(act);
124
    layoutMid.addView(mDoneButton);
125
    setupResetButton(act);
126
    layoutLeft.addView(mResetButton);
127

  
128
    LinearLayout layout = act.findViewById(R.id.lowerBar);
129
    layout.removeAllViews();
130
    layout.addView(layoutLeft);
131
    layout.addView(layoutMid);
132
    layout.addView(layoutRight);
133
    }
134
}
src/main/java/org/distorted/bandaged/BandagedCreatorView.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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 android.app.ActivityManager;
23
import android.content.Context;
24
import android.content.pm.ConfigurationInfo;
25
import android.opengl.GLES30;
26
import android.opengl.GLSurfaceView;
27
import android.util.AttributeSet;
28

  
29
import com.google.firebase.crashlytics.FirebaseCrashlytics;
30

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

  
33
public class BandagedCreatorView extends GLSurfaceView
34
{
35
    private BandagedCreatorRenderer mRenderer;
36

  
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38
// PUBLIC API
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

  
41
    public BandagedCreatorView(Context context, AttributeSet attrs)
42
      {
43
      super(context,attrs);
44

  
45
      if(!isInEditMode())
46
        {
47
        BandagedCreatorActivity act = (BandagedCreatorActivity)context;
48
        mRenderer = new BandagedCreatorRenderer(this);
49

  
50
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
51

  
52
        try
53
          {
54
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
55
          int esVersion = configurationInfo.reqGlEsVersion>>16;
56
          setEGLContextClientVersion(esVersion);
57
          setRenderer(mRenderer);
58
          }
59
        catch(Exception ex)
60
          {
61
          act.OpenGLError();
62

  
63
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
64
          String version = GLES30.glGetString(GLES30.GL_VERSION);
65
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
66
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
67

  
68
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
69
          crashlytics.setCustomKey("GLSL Version"  , shading );
70
          crashlytics.setCustomKey("GL version"    , version );
71
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
72
          crashlytics.setCustomKey("GLSL renderer" , renderer);
73
          crashlytics.recordException(ex);
74
          }
75
        }
76
      }
77

  
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

  
80
    @Override
81
    public void onPause()
82
      {
83
      super.onPause();
84
      }
85

  
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

  
88
    @Override
89
    public void onResume()
90
      {
91
      super.onResume();
92
      }
93
}
94

  
src/main/java/org/distorted/bandaged/BandagedPlayActivity.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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 android.os.Build;
23
import android.os.Bundle;
24
import android.util.DisplayMetrics;
25
import android.view.View;
26
import android.view.ViewGroup;
27
import android.view.WindowManager;
28
import android.widget.LinearLayout;
29

  
30
import androidx.appcompat.app.AppCompatActivity;
31

  
32
import com.google.firebase.analytics.FirebaseAnalytics;
33

  
34
import org.distorted.config.ConfigSurfaceView;
35
import org.distorted.dialogs.RubikDialogError;
36
import org.distorted.library.main.DistortedLibrary;
37
import org.distorted.main.R;
38
import org.distorted.objectlib.main.ObjectControl;
39
import org.distorted.objects.RubikObject;
40
import org.distorted.objects.RubikObjectList;
41

  
42
import java.io.InputStream;
43

  
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

  
46
public class BandagedPlayActivity extends AppCompatActivity
47
{
48
    private static final int ACTIVITY_NUMBER = 4;
49
    private static final float RATIO_BAR  = 0.10f;
50

  
51
    public static final float DIALOG_BUTTON_SIZE  = 0.06f;
52
    public static final float MENU_BIG_TEXT_SIZE  = 0.05f;
53

  
54
    public static final int FLAGS =  View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
55
                                   | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
56
                                   | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
57
                                   | View.SYSTEM_UI_FLAG_FULLSCREEN
58
                                   | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
59

  
60
    private FirebaseAnalytics mFirebaseAnalytics;
61
    private static int mScreenWidth, mScreenHeight;
62
    private int mCurrentApiVersion;
63
    private BandagedPlayScreen mScreen;
64
    private int mObjectOrdinal;
65
    private int mHeightBar;
66

  
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

  
69
    @Override
70
    protected void onCreate(Bundle savedState)
71
      {
72
      super.onCreate(savedState);
73
      DistortedLibrary.onCreate(ACTIVITY_NUMBER);
74
      setTheme(R.style.MaterialThemeNoActionBar);
75
      setContentView(R.layout.bandaged_play);
76

  
77
      Bundle b = getIntent().getExtras();
78

  
79
      if(b != null) mObjectOrdinal = b.getInt("obj");
80

  
81
      mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
82

  
83
      DisplayMetrics displaymetrics = new DisplayMetrics();
84
      getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
85
      mScreenWidth =displaymetrics.widthPixels;
86
      mScreenHeight=displaymetrics.heightPixels;
87
      mScreenHeight = (int)(1.07f*mScreenHeight); // add 7% for the upper bar
88
                                                  // which is not yet hidden.
89
                                                  // TODO: figure this out exactly.
90
      hideNavigationBar();
91
      cutoutHack();
92
      computeBarHeights();
93
      }
94

  
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
// this does not include possible insets
97

  
98
    private void computeBarHeights()
99
      {
100
      int barHeight = (int)(mScreenHeight*RATIO_BAR);
101
      mHeightBar = barHeight;
102

  
103
      LinearLayout layout = findViewById(R.id.lowerBar);
104
      ViewGroup.LayoutParams params = layout.getLayoutParams();
105
      params.height = barHeight;
106
      layout.setLayoutParams(params);
107
      }
108

  
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

  
111
    private void hideNavigationBar()
112
      {
113
      mCurrentApiVersion = Build.VERSION.SDK_INT;
114

  
115
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT)
116
        {
117
        final View decorView = getWindow().getDecorView();
118

  
119
        decorView.setSystemUiVisibility(FLAGS);
120

  
121
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener()
122
          {
123
          @Override
124
          public void onSystemUiVisibilityChange(int visibility)
125
            {
126
            if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0)
127
              {
128
              decorView.setSystemUiVisibility(FLAGS);
129
              }
130
            }
131
          });
132
        }
133
      }
134

  
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136
// do not avoid cutouts
137

  
138
    private void cutoutHack()
139
      {
140
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
141
        {
142
        getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
143
        }
144
      }
145

  
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

  
148
    @Override
149
    public void onWindowFocusChanged(boolean hasFocus)
150
      {
151
      super.onWindowFocusChanged(hasFocus);
152

  
153
      if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus)
154
        {
155
        getWindow().getDecorView().setSystemUiVisibility(FLAGS);
156
        }
157
      }
158

  
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160
    
161
    @Override
162
    protected void onPause() 
163
      {
164
      super.onPause();
165
      BandagedPlayView view = findViewById(R.id.bandagedPlayView);
166
      view.onPause();
167
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
168
      }
169

  
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171
    
172
    @Override
173
    protected void onResume() 
174
      {
175
      super.onResume();
176
      DistortedLibrary.onResume(ACTIVITY_NUMBER);
177
      BandagedPlayView view = findViewById(R.id.bandagedPlayView);
178
      view.onResume();
179

  
180
      if( mScreen==null ) mScreen = new BandagedPlayScreen();
181
      mScreen.onAttachedToWindow(this,mObjectOrdinal);
182

  
183
      if( mObjectOrdinal>=0 && mObjectOrdinal< RubikObjectList.getNumObjects() )
184
        {
185
        RubikObject object = RubikObjectList.getObject(mObjectOrdinal);
186
        changeIfDifferent(object,mObjectOrdinal,view.getObjectControl());
187
        }
188
      }
189

  
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191
    
192
    @Override
193
    protected void onDestroy() 
194
      {
195
      super.onDestroy();
196
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
197
      }
198

  
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

  
201
    void OpenGLError()
202
      {
203
      RubikDialogError errDiag = new RubikDialogError();
204
      errDiag.show(getSupportFragmentManager(), null);
205
      }
206

  
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

  
209
    private void changeIfDifferent(RubikObject object,int ordinal,ObjectControl control)
210
      {
211
      if( object!=null )
212
        {
213
        int meshState          = object.getMeshState();
214
        InputStream jsonStream = object.getObjectStream(this);
215
        InputStream meshStream = object.getMeshStream(this);
216
        String name            = object.getUpperName();
217

  
218
        control.changeIfDifferent(ordinal,name,meshState,jsonStream,meshStream);
219
        }
220
      }
221

  
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223
// PUBLIC API
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

  
226
    public void changeObject(int ordinal)
227
      {
228
      mObjectOrdinal = ordinal;
229
      RubikObject object = RubikObjectList.getObject(ordinal);
230
      BandagedPlayView view = findViewById(R.id.bandagedPlayView);
231
      ObjectControl control = view.getObjectControl();
232
      changeIfDifferent(object,ordinal,control);
233
      }
234

  
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236

  
237
    public FirebaseAnalytics getAnalytics()
238
      {
239
      return mFirebaseAnalytics;
240
      }
241

  
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

  
244
    public int getHeightBar()
245
      {
246
      return mHeightBar;
247
      }
248

  
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250

  
251
    public int getScreenWidthInPixels()
252
      {
253
      return mScreenWidth;
254
      }
255

  
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257

  
258
    public int getScreenHeightInPixels()
259
      {
260
      return mScreenHeight;
261
      }
262

  
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264

  
265
    public ObjectControl getControl()
266
      {
267
      BandagedPlayView view = findViewById(R.id.bandagedPlayView);
268
      return view.getObjectControl();
269
      }
270

  
271
///////////////////////////////////////////////////////////////////////////////////////////////////
272

  
273
    public static int getDrawableSize()
274
      {
275
      if( mScreenHeight<1000 )
276
        {
277
        return 0;
278
        }
279
      if( mScreenHeight<1600 )
280
        {
281
        return 1;
282
        }
283
      if( mScreenHeight<1900 )
284
        {
285
        return 2;
286
        }
287

  
288
      return 3;
289
      }
290

  
291
///////////////////////////////////////////////////////////////////////////////////////////////////
292

  
293
    public static int getDrawable(int small, int medium, int big, int huge)
294
      {
295
      int size = getDrawableSize();
296

  
297
      switch(size)
298
        {
299
        case 0 : return small;
300
        case 1 : return medium;
301
        case 2 : return big;
302
        default: return huge;
303
        }
304
      }
305

  
306
///////////////////////////////////////////////////////////////////////////////////////////////////
307

  
308
    public boolean isVertical()
309
      {
310
      BandagedPlayView view = findViewById(R.id.bandagedPlayView);
311
      return view.isVertical();
312
      }
313
}
src/main/java/org/distorted/bandaged/BandagedPlayLibInterface.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 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 com.google.firebase.crashlytics.FirebaseCrashlytics;
23

  
24
import org.distorted.library.message.EffectMessageSender;
25
import org.distorted.objectlib.BuildConfig;
26
import org.distorted.objectlib.helpers.BlockController;
27
import org.distorted.objectlib.helpers.ObjectLibInterface;
28

  
29
///////////////////////////////////////////////////////////////////////////////////////////////////
30

  
31
public class BandagedPlayLibInterface implements ObjectLibInterface
32
{
33
  public void onWinEffectFinished(long startTime, long endTime, String debug, int scrambleNum) { }
34
  public void onScrambleEffectFinished() { }
35
  public void onBeginRotation() { }
36
  public void onSolved() { }
37
  public void onObjectCreated(long time) { }
38
  public void onReplaceModeDown(int cubit, int face) { }
39
  public void onReplaceModeUp() { }
40
  public void onFinishRotation(int axis, int row, int angle) { }
41
  public void failedToDrag() { }
42

  
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

  
45
  public void reportProblem(String problem, boolean reportException)
46
    {
47
    if( BuildConfig.DEBUG )
48
      {
49
      android.util.Log.e("interface", problem);
50
      }
51
    else
52
      {
53
      if( reportException )
54
        {
55
        Exception ex = new Exception(problem);
56
        FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
57
        crashlytics.setCustomKey("problem" , problem);
58
        crashlytics.recordException(ex);
59
        }
60
      else
61
        {
62
        FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
63
        crashlytics.log(problem);
64
        }
65
      }
66
    }
67

  
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

  
70
  private void reportUIProblem(int place, long pause, long resume, long time)
71
    {
72
    String error = "UI BLOCK "+place+" blocked for "+time;
73

  
74
    if( BuildConfig.DEBUG )
75
       {
76
       android.util.Log.e("D", error);
77
       }
78
    else
79
      {
80
      Exception ex = new Exception(error);
81
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
82
      crashlytics.setCustomKey("pause" , pause );
83
      crashlytics.setCustomKey("resume", resume );
84
      crashlytics.recordException(ex);
85
      }
86
    }
87

  
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

  
90
  private void reportTouchProblem(int place, long pause, long resume, long time)
91
    {
92
    String error = "TOUCH BLOCK "+place+" blocked for "+time;
93

  
94
    if( BuildConfig.DEBUG )
95
       {
96
       android.util.Log.e("D", error);
97
       }
98
    else
99
      {
100
      Exception ex = new Exception(error);
101
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
102
      crashlytics.setCustomKey("pause" , pause );
103
      crashlytics.setCustomKey("resume", resume);
104
      crashlytics.recordException(ex);
105
      }
106
    }
107

  
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

  
110
  private void reportThreadProblem(int place, long pause, long resume, long time)
111
    {
112
    String error = EffectMessageSender.reportState();
113

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

  
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

  
130
  public void reportBlockProblem(int type, int place, long pause, long resume, long time)
131
    {
132
    switch(type)
133
      {
134
      case BlockController.TYPE_UI    : reportUIProblem(place,pause,resume,time); break;
135
      case BlockController.TYPE_TOUCH : reportTouchProblem(place,pause,resume,time); break;
136
      case BlockController.TYPE_THREAD: reportThreadProblem(place,pause,resume,time); break;
137
      }
138
    }
139
}
src/main/java/org/distorted/bandaged/BandagedPlayRenderer.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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 android.opengl.GLSurfaceView;
23

  
24
import org.distorted.library.effect.EffectType;
25
import org.distorted.library.effect.VertexEffectQuaternion;
26
import org.distorted.library.effect.VertexEffectRotate;
27
import org.distorted.library.main.DistortedLibrary;
28
import org.distorted.library.main.DistortedScreen;
29
import org.distorted.objectlib.effects.BaseEffect;
30

  
31
import javax.microedition.khronos.egl.EGLConfig;
32
import javax.microedition.khronos.opengles.GL10;
33

  
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

  
36
public class BandagedPlayRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
37
{
38
   private final BandagedPlayView mView;
39
   private final DistortedScreen mScreen;
40

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

  
43
   BandagedPlayRenderer(BandagedPlayView v)
44
     {
45
     final float BRIGHTNESS = 0.333f;
46

  
47
     mView = v;
48
     mScreen = new DistortedScreen();
49
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
50
     }
51

  
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

  
54
   @Override
55
   public void onDrawFrame(GL10 glUnused)
56
     {
57
     long time = System.currentTimeMillis();
58
     mView.getObjectControl().preRender();
59
     mScreen.render(time);
60
     }
61

  
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

  
64
   @Override
65
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
66
      {
67
      mScreen.resize(width,height);
68
      mView.setScreenSize(width,height);
69
      }
70

  
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

  
73
   @Override
74
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
75
      {
76
      DistortedLibrary.setMax(EffectType.VERTEX,25);
77
      VertexEffectRotate.enable();
78
      VertexEffectQuaternion.enable();
79
      BaseEffect.Type.enableEffects();
80

  
81
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
82
      }
83

  
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

  
86
   public void distortedException(Exception ex)
87
     {
88
     android.util.Log.e("BandagedPlay", "unexpected exception: "+ex.getMessage() );
89
     }
90

  
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

  
93
   DistortedScreen getScreen()
94
     {
95
     return mScreen;
96
     }
97
}
src/main/java/org/distorted/bandaged/BandagedPlayScreen.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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 android.view.View;
23
import android.widget.LinearLayout;
24

  
25
import org.distorted.helpers.LockController;
26
import org.distorted.helpers.MovesController;
27
import org.distorted.helpers.TransparentImageButton;
28
import org.distorted.main.R;
29
import org.distorted.main.RubikActivity;
30
import org.distorted.objectlib.main.ObjectControl;
31

  
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

  
34
public class BandagedPlayScreen
35
{
36
  private TransparentImageButton mBackButton, mScrambleButton, mSolveButton;
37
  private final LockController mLockController;
38
  protected MovesController mMovesController;
39
  private int mObjectOrdinal;
40
  private int mBarHeight;
41
  private float mButtonSize;
42

  
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

  
45
  public BandagedPlayScreen()
46
    {
47
    mLockController = new LockController();
48
    mMovesController= new MovesController();
49
    }
50

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

  
53
  private void setupBackButton(final BandagedPlayActivity act)
54
    {
55
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
56
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
57
    mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
58

  
59
    mBackButton.setOnClickListener( new View.OnClickListener()
60
      {
61
      @Override
62
      public void onClick(View v)
63
        {
64
        ObjectControl control = act.getControl();
65
        if( control!=null ) control.unblockEverything();
66
        act.finish();
67
        }
68
      });
69
    }
70

  
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

  
73
  void onAttachedToWindow(final BandagedPlayActivity act, final int objectOrdinal)
74
    {
75
    int width = act.getScreenWidthInPixels();
76
    mBarHeight = act.getHeightBar();
77
    mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
78

  
79
    mObjectOrdinal = objectOrdinal;
80

  
81
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
82
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
83
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
84

  
85
    LinearLayout layoutLeft = new LinearLayout(act);
86
    layoutLeft.setLayoutParams(paramsL);
87
    LinearLayout layoutMid  = new LinearLayout(act);
88
    layoutMid.setLayoutParams(paramsM);
89
    LinearLayout layoutRight= new LinearLayout(act);
90
    layoutRight.setLayoutParams(paramsR);
91

  
92
    setupBackButton(act);
93
    ObjectControl control = act.getControl();
94
    mMovesController.setupButton(act,control);
95
    layoutLeft.addView(mMovesController.getButton());
96
    mLockController.setupButton(act,control);
97
    layoutMid.addView(mLockController.getButton());
98

  
99
    layoutRight.addView(mBackButton);
100

  
101
    LinearLayout layout = act.findViewById(R.id.lowerBar);
102
    layout.removeAllViews();
103
    layout.addView(layoutLeft);
104
    layout.addView(layoutMid);
105
    layout.addView(layoutRight);
106

  
107
    }
108

  
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

  
111
  public void setLockState(final RubikActivity act)
112
    {
113
    boolean locked = act.getControl().retLocked();
114
    mLockController.setState(act,locked);
115
    }
116

  
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

  
119
  public void reddenLock(final RubikActivity act)
120
    {
121
    ObjectControl control = act.getControl();
122
    mLockController.reddenLock(act,control);
123
    }
124
}
src/main/java/org/distorted/bandaged/BandagedPlayView.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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 android.app.ActivityManager;
23
import android.content.Context;
24
import android.content.pm.ConfigurationInfo;
25
import android.opengl.GLES30;
26
import android.opengl.GLSurfaceView;
27
import android.util.AttributeSet;
28

  
29
import com.google.firebase.crashlytics.FirebaseCrashlytics;
30

  
31
import org.distorted.objectlib.main.ObjectControl;
32
import org.distorted.objectlib.main.TwistyObjectNode;
33

  
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

  
36
public class BandagedPlayView extends GLSurfaceView
37
{
38
    private ObjectControl mObjectController;
39
    private BandagedPlayRenderer mRenderer;
40
    private int mScreenWidth, mScreenHeight;
41
    private boolean mCreated;
42

  
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

  
45
    void setScreenSize(int width, int height)
46
      {
47
      mScreenWidth = width;
48
      mScreenHeight= height;
49
      mObjectController.setScreenSize(width,height);
50
      mObjectController.setObjectScale(1.00f);
51

  
52
      if( !mCreated )
53
        {
54
        mCreated = true;
55
        mObjectController.createNode(width,height);
56
        TwistyObjectNode objectNode = mObjectController.getNode();
57
        mRenderer.getScreen().attach(objectNode);
58
        }
59
      }
60

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

  
63
    boolean isVertical()
64
      {
65
      return mScreenHeight>mScreenWidth;
66
      }
67

  
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

  
70
    ObjectControl getObjectControl()
71
      {
72
      return mObjectController;
73
      }
74

  
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76
// PUBLIC API
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

  
79
    public BandagedPlayView(Context context, AttributeSet attrs)
80
      {
81
      super(context,attrs);
82

  
83
      mCreated = false;
84

  
85
      if(!isInEditMode())
86
        {
87
        BandagedPlayActivity act = (BandagedPlayActivity)context;
88
        BandagedPlayLibInterface ref = new BandagedPlayLibInterface();
89
        mObjectController = new ObjectControl(act,ref);
90
        mObjectController.setRotateOnCreation(true);
91
        mRenderer = new BandagedPlayRenderer(this);
92

  
93
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
94

  
95
        try
96
          {
97
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
98
          int esVersion = configurationInfo.reqGlEsVersion>>16;
99
          setEGLContextClientVersion(esVersion);
100
          setRenderer(mRenderer);
101
          }
102
        catch(Exception ex)
103
          {
104
          act.OpenGLError();
105

  
106
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
107
          String version = GLES30.glGetString(GLES30.GL_VERSION);
108
          String vendor  = GLES30.glGetString(GLES30.GL_VENDOR);
109
          String renderer= GLES30.glGetString(GLES30.GL_RENDERER);
110

  
111
          FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
112
          crashlytics.setCustomKey("GLSL Version"  , shading );
113
          crashlytics.setCustomKey("GL version"    , version );
114
          crashlytics.setCustomKey("GL Vendor "    , vendor  );
115
          crashlytics.setCustomKey("GLSL renderer" , renderer);
116
          crashlytics.recordException(ex);
117
          }
118
        }
119
      }
120

  
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

  
123
    @Override
124
    public void onPause()
125
      {
126
      super.onPause();
127
      mObjectController.onPause();
128
      }
129

  
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

  
132
    @Override
133
    public void onResume()
134
      {
135
      super.onResume();
136
      mObjectController.onResume();
137
      }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff