Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogAbandon.java @ 99b8a069

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 android.util.DisplayMetrics;
26
import android.util.TypedValue;
27
import android.view.LayoutInflater;
28
import android.view.View;
29
import android.view.Window;
30
import android.widget.Button;
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
import org.distorted.main.RubikActivity;
39
import org.distorted.screens.ScreenList;
40

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

    
43
public class RubikDialogAbandon extends AppCompatDialogFragment
44
  {
45
  @NonNull
46
  @Override
47
  public Dialog onCreateDialog(Bundle savedInstanceState)
48
    {
49
    final RubikActivity ract = (RubikActivity)getContext();
50

    
51
    FragmentActivity act = getActivity();
52
    LayoutInflater inflater = act.getLayoutInflater();
53
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
54

    
55
    DisplayMetrics displaymetrics = new DisplayMetrics();
56
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
57
    final float butSize  = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
58

    
59
    final View view = inflater.inflate(R.layout.abandon_solve, null);
60
    builder.setView(view);
61
    builder.setCancelable(true);
62

    
63
    builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
64
      {
65
      @Override
66
      public void onClick(DialogInterface dialog, int which)
67
        {
68
        ScreenList.goBack(ract);
69
        }
70
      });
71

    
72
    builder.setNegativeButton( R.string.no, new DialogInterface.OnClickListener()
73
      {
74
      @Override
75
      public void onClick(DialogInterface dialog, int which)
76
        {
77
        // empty
78
        }
79
      });
80

    
81
    final Dialog dialog = builder.create();
82
    dialog.setCanceledOnTouchOutside(false);
83
    Window window = dialog.getWindow();
84

    
85
    if( window!=null )
86
      {
87
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
88
      }
89

    
90
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
91
      {
92
      @Override
93
      public void onShow(DialogInterface dialog)
94
        {
95
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
96
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
97
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
98
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
99
        }
100
      });
101

    
102
    return dialog;
103
    }
104
  }
(1-1/21)