Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogSolverError.java @ eaf87d1d

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