Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogSolverError.java @ 3f7a4363

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.dialogs;
21

    
22
import android.app.Dialog;
23
import android.content.DialogInterface;
24
import android.os.Bundle;
25
import androidx.annotation.NonNull;
26
import androidx.fragment.app.FragmentActivity;
27
import androidx.appcompat.app.AlertDialog;
28
import androidx.appcompat.app.AppCompatDialogFragment;
29

    
30
import android.util.DisplayMetrics;
31
import android.util.TypedValue;
32
import android.view.LayoutInflater;
33
import android.view.View;
34
import android.view.Window;
35
import android.widget.Button;
36
import android.widget.TextView;
37

    
38
import org.distorted.main.R;
39
import org.distorted.main.RubikActivity;
40

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

    
43
public class RubikDialogSolverError extends AppCompatDialogFragment
44
  {
45
  @NonNull
46
  @Override
47
  public Dialog onCreateDialog(Bundle savedInstanceState)
48
    {
49
    FragmentActivity act = getActivity();
50
    LayoutInflater inflater = act.getLayoutInflater();
51
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
52

    
53
    DisplayMetrics displaymetrics = new DisplayMetrics();
54
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
55
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
56
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
57
    final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
58

    
59
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
60
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
61
    tv.setText(R.string.error);
62
    builder.setCustomTitle(tv);
63

    
64
    builder.setCancelable(true);
65
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
66
      {
67
      @Override
68
      public void onClick(DialogInterface dialog, int which)
69
        {
70

    
71
        }
72
      });
73

    
74
    Bundle args = getArguments();
75
    String errorStr;
76

    
77
    try
78
      {
79
      errorStr = args.getString("error");
80
      }
81
    catch(Exception e)
82
      {
83
      errorStr = "Error";
84
      }
85

    
86
    final View view = inflater.inflate(R.layout.dialog_solver_error, null);
87
    TextView text = view.findViewById(R.id.solver_error);
88
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
89
    text.setText(errorStr);
90
    builder.setView(view);
91

    
92
    Dialog dialog = builder.create();
93
    dialog.setCanceledOnTouchOutside(false);
94
    Window window = dialog.getWindow();
95

    
96
    if( window!=null )
97
      {
98
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
99
      }
100

    
101
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
102
      {
103
      @Override
104
      public void onShow(DialogInterface dialog)
105
        {
106
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
107
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
108
        }
109
      });
110

    
111
    return dialog;
112
    }
113
  }
(16-16/19)