Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogError.java @ 24cd23dd

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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.dialogs;
11

    
12
import android.app.Dialog;
13
import android.content.DialogInterface;
14
import android.os.Bundle;
15
import android.util.DisplayMetrics;
16
import android.util.TypedValue;
17
import android.view.LayoutInflater;
18
import android.view.View;
19
import android.view.Window;
20
import android.widget.Button;
21
import android.widget.TextView;
22

    
23
import androidx.annotation.NonNull;
24
import androidx.appcompat.app.AlertDialog;
25
import androidx.appcompat.app.AppCompatDialogFragment;
26
import androidx.fragment.app.FragmentActivity;
27

    
28
import org.distorted.main.R;
29
import org.distorted.main.RubikActivity;
30

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

    
33
public class RubikDialogError extends AppCompatDialogFragment
34
  {
35
  @NonNull
36
  @Override
37
  public Dialog onCreateDialog(Bundle savedInstanceState)
38
    {
39
    final FragmentActivity act = getActivity();
40
    LayoutInflater inflater = act.getLayoutInflater();
41
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
42

    
43
    DisplayMetrics displaymetrics = new DisplayMetrics();
44
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
45
    final float titleSize= displaymetrics.widthPixels * RubikActivity.BIG_TEXT_SIZE;
46
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
47

    
48
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
49
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
50
    tv.setText(R.string.opengl_error);
51
    builder.setCustomTitle(tv);
52

    
53
    final View view = inflater.inflate(R.layout.dialog_error, null);
54
    TextView text = view.findViewById(R.id.error_string);
55
    text.setText(R.string.opengl_error_text);
56

    
57
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
58
      {
59
      @Override
60
      public void onClick(DialogInterface dialog, int which)
61
        {
62
        act.finish();
63
        }
64
      });
65

    
66
    builder.setView(view);
67

    
68
    final Dialog dialog = builder.create();
69
    dialog.setCanceledOnTouchOutside(false);
70

    
71
    Window window = dialog.getWindow();
72

    
73
    if( window!=null )
74
      {
75
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
76
      }
77

    
78
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
79
      {
80
      @Override
81
      public void onShow(DialogInterface dialog)
82
        {
83
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
84
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
85
        }
86
      });
87

    
88
    return dialog;
89
    }
90
  }
(6-6/25)