Project

General

Profile

« Previous | Next » 

Revision e7e0a94d

Added by Leszek Koltunski about 4 years ago

Simplify OpenGL error dialog. Show it only once.

View differences:

build.gradle
36 36
dependencies {
37 37
    implementation fileTree(dir: 'libs', include: ['*.jar'])
38 38
    implementation 'com.google.firebase:firebase-analytics:17.5.0'
39
    implementation 'com.google.firebase:firebase-crashlytics:17.2.1'
39
    implementation 'com.google.firebase:firebase-crashlytics:17.2.2'
40 40

  
41 41
    api project(':distorted-library')
42 42
    implementation 'androidx.appcompat:appcompat:1.2.0'
src/main/java/org/distorted/dialogs/RubikDialogError.java
47 47
  @Override
48 48
  public Dialog onCreateDialog(Bundle savedInstanceState)
49 49
    {
50
    FragmentActivity act = getActivity();
50
    final FragmentActivity act = getActivity();
51 51
    LayoutInflater inflater = act.getLayoutInflater();
52 52
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
53 53

  
......
56 56
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
57 57
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
58 58

  
59
    Bundle args = getArguments();
60
    String error;
61

  
62
    try
63
      {
64
      error = args.getString("error");
65
      }
66
    catch(Exception e)
67
      {
68
      error = "Error getting error";
69
      }
70

  
71 59
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
72 60
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
73 61
    tv.setText(R.string.opengl_error);
......
75 63

  
76 64
    final View view = inflater.inflate(R.layout.dialog_error, null);
77 65
    TextView text = view.findViewById(R.id.error_string);
78
    text.setText(error);
79

  
80
    builder.setCancelable(true);
66
    text.setText(R.string.opengl_error_text);
81 67

  
82 68
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
83 69
      {
84 70
      @Override
85 71
      public void onClick(DialogInterface dialog, int which)
86 72
        {
87

  
73
        act.finish();
88 74
        }
89 75
      });
90 76

  
src/main/java/org/distorted/main/RubikActivity.java
334 334

  
335 335
///////////////////////////////////////////////////////////////////////////////////////////////////
336 336

  
337
    void OpenGLError(String message)
337
    void OpenGLError()
338 338
      {
339
      Bundle bundle = new Bundle();
340
      bundle.putString("error", message );
341

  
342 339
      RubikDialogError errDiag = new RubikDialogError();
343
      errDiag.setArguments(bundle);
344 340
      errDiag.show(getSupportFragmentManager(), null);
345 341
      }
346 342

  
src/main/java/org/distorted/main/RubikRenderer.java
41 41
   private RubikSurfaceView mView;
42 42
   private DistortedScreen mScreen;
43 43
   private Fps mFPS;
44
   private boolean mErrorShown;
44 45

  
45 46
   private static class Fps
46 47
     {
......
86 87
     {
87 88
     final float BRIGHTNESS = 0.30f;
88 89

  
90
     mErrorShown = false;
89 91
     mView = v;
90 92
     mFPS = new Fps();
91 93
     mScreen = new DistortedScreen();
......
161 163

  
162 164
     int glsl = DistortedLibrary.getGLSL();
163 165

  
164
     if( glsl< 300 )
166
     if( glsl< 300 && !mErrorShown )
165 167
       {
168
       mErrorShown = true;
166 169
       RubikActivity act = (RubikActivity)mView.getContext();
167
       act.OpenGLError(message);
170
       act.OpenGLError();
168 171
       }
169 172
     }
170 173

  
src/main/java/org/distorted/main/RubikSurfaceView.java
703 703
        try
704 704
          {
705 705
          final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
706
          setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
706
          int esVersion = configurationInfo.reqGlEsVersion>>16;
707
          setEGLContextClientVersion(esVersion);
707 708
          setRenderer(mRenderer);
708 709
          }
709 710
        catch(Exception ex)
710 711
          {
711
          act.OpenGLError("This device does not support OpenGL ES 3.0");
712
          act.OpenGLError();
712 713

  
713 714
          String shading = GLES30.glGetString(GLES30.GL_SHADING_LANGUAGE_VERSION);
714 715
          String version = GLES30.glGetString(GLES30.GL_VERSION);
src/main/res/values/strings.xml
1 1
<resources>
2 2
    <string name="app_name">Magic Cube</string>
3 3
    <string name="distorted" translatable="false">DISTORTED</string>
4
    <string name="opengl_error" translatable="false">Graphics Error</string>
4
    <string name="opengl_error" translatable="false">Error</string>
5
    <string name="opengl_error_text" translatable="false">This device does not support OpenGL 3.0</string>
5 6
    <string name="scramble">Scramble</string>
6 7
    <string name="solve">Solve</string>
7 8
    <string name="exit">Exit</string>

Also available in: Unified diff