Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogBandagedSave.java @ 068f7c2f

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 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.view.WindowManager;
31
import android.widget.Button;
32
import android.widget.TextView;
33

    
34
import androidx.annotation.NonNull;
35
import androidx.appcompat.app.AlertDialog;
36
import androidx.appcompat.app.AppCompatDialogFragment;
37
import androidx.fragment.app.FragmentActivity;
38

    
39
import org.distorted.bandaged.BandagedCreatorActivity;
40
import org.distorted.bandaged.BandagedCreatorRenderer;
41
import org.distorted.main.R;
42
import org.distorted.main.RubikActivity;
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

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

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

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

    
66
    final View view = inflater.inflate(R.layout.dialog_save_object, null);
67

    
68
    TextView save = view.findViewById(R.id.save_object_text);
69
    save.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
70

    
71
    builder.setCancelable(true);
72

    
73
    builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
74
      {
75
      @Override
76
      public void onClick(DialogInterface dialog, int which)
77
        {
78
        BandagedCreatorActivity bact = (BandagedCreatorActivity)getContext();
79

    
80
        if( bact!=null )
81
          {
82
          BandagedCreatorRenderer rend = bact.getRenderer();
83
          rend.saveObject();
84
          }
85
        }
86
      });
87

    
88
    builder.setNegativeButton( R.string.no, new DialogInterface.OnClickListener()
89
      {
90
      @Override
91
      public void onClick(DialogInterface dialog, int which)
92
        {
93
        // empty
94
        }
95
      });
96

    
97
    builder.setView(view);
98
    final Dialog dialog = builder.create();
99

    
100
    dialog.setCanceledOnTouchOutside(false);
101
    Window window = dialog.getWindow();
102

    
103
    if( window!=null )
104
      {
105
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
106
      }
107

    
108
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
109
      {
110
      @Override
111
      public void onShow(DialogInterface dialog)
112
        {
113
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
114
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
115
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
116
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
117
        }
118
      });
119

    
120
    return dialog;
121
    }
122
  }
(4-4/25)