Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogMain.java @ 2eb74743

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 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.os.Bundle;
24
import androidx.annotation.NonNull;
25
import androidx.fragment.app.FragmentActivity;
26
import androidx.appcompat.app.AlertDialog;
27
import androidx.appcompat.app.AppCompatDialogFragment;
28

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

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

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

    
42
public class RubikDialogMain extends AppCompatDialogFragment
43
  {
44
  @NonNull
45
  @Override
46
  public Dialog onCreateDialog(Bundle savedInstanceState)
47
    {
48
    FragmentActivity act = getActivity();
49
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
50
    LayoutInflater inflater = act.getLayoutInflater();
51
    final View view = inflater.inflate(R.layout.dialog_main, null);
52

    
53
    DisplayMetrics displaymetrics = new DisplayMetrics();
54
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
55
    float textSize = displaymetrics.widthPixels * RubikActivity.MENU_MEDIUM_TEXT_SIZE;
56
    int buttonSize = (int)(2.5f*textSize);
57

    
58
    Button play = view.findViewById(R.id.rubikPlay);
59
    play.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
60
    play.setHeight(buttonSize);
61
    Button scor = view.findViewById(R.id.rubikScores);
62
    scor.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
63
    scor.setHeight(buttonSize);
64
    Button patt = view.findViewById(R.id.rubikPatterns);
65
    patt.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
66
    patt.setHeight(buttonSize);
67
    Button solv = view.findViewById(R.id.rubikSolver);
68
    solv.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
69
    solv.setHeight(buttonSize);
70
    Button abou = view.findViewById(R.id.rubikAbout);
71
    abou.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
72
    abou.setHeight(buttonSize);
73

    
74
    builder.setView(view);
75

    
76
    Dialog dialog = builder.create();
77

    
78
    dialog.setCanceledOnTouchOutside(false);
79

    
80
    Window window = dialog.getWindow();
81

    
82
    if( window!=null )
83
      {
84
      window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
85
                      WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
86
      window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
87
      }
88

    
89
    return dialog;
90
    }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
  public static String getDialogTag()
95
    {
96
    return "DialogMain";
97
    }
98
  }
(4-4/14)