Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogError.java @ b1e9596b

1 2d9fc972 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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.dialogs;
21
22
import android.app.Dialog;
23
import android.content.DialogInterface;
24
import android.os.Bundle;
25 fb37b424 Leszek Koltunski
import android.util.DisplayMetrics;
26
import android.util.TypedValue;
27 2d9fc972 Leszek Koltunski
import android.view.LayoutInflater;
28
import android.view.View;
29 fb37b424 Leszek Koltunski
import android.widget.Button;
30 2d9fc972 Leszek Koltunski
import android.widget.TextView;
31
32
import androidx.annotation.NonNull;
33
import androidx.appcompat.app.AlertDialog;
34
import androidx.appcompat.app.AppCompatDialogFragment;
35
import androidx.fragment.app.FragmentActivity;
36
37
import org.distorted.main.R;
38 fb37b424 Leszek Koltunski
import org.distorted.main.RubikActivity;
39 2d9fc972 Leszek Koltunski
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41
42
public class RubikDialogError extends AppCompatDialogFragment
43
  {
44
  @NonNull
45
  @Override
46
  public Dialog onCreateDialog(Bundle savedInstanceState)
47
    {
48
    FragmentActivity act = getActivity();
49
    LayoutInflater inflater = act.getLayoutInflater();
50
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
51
52 fb37b424 Leszek Koltunski
    DisplayMetrics displaymetrics = new DisplayMetrics();
53
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
54
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
55
    final float okSize   = displaymetrics.widthPixels * RubikActivity.MENU_MEDIUM_TEXT_SIZE;
56
57 2d9fc972 Leszek Koltunski
    Bundle args = getArguments();
58
    String error;
59
60
    try
61
      {
62
      error = args.getString("error");
63
      }
64
    catch(Exception e)
65
      {
66
      error = "Error getting error";
67
      }
68
69
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
70 fb37b424 Leszek Koltunski
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
71 2d9fc972 Leszek Koltunski
    tv.setText(R.string.opengl_error);
72
    builder.setCustomTitle(tv);
73
74
    final View view = inflater.inflate(R.layout.dialog_error, null);
75
    TextView text = view.findViewById(R.id.error_string);
76
    text.setText(error);
77
78
    builder.setCancelable(true);
79
80
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
81
      {
82
      @Override
83
      public void onClick(DialogInterface dialog, int which)
84
        {
85
86
        }
87
      });
88
89
    builder.setView(view);
90
91
    final Dialog dialog = builder.create();
92
    dialog.setCanceledOnTouchOutside(false);
93
94 fb37b424 Leszek Koltunski
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
95
      {
96
      @Override
97
      public void onShow(DialogInterface dialog)
98
        {
99
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
100
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
101
        }
102
      });
103
104 2d9fc972 Leszek Koltunski
    return dialog;
105
    }
106
  }