Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogBandagedDelete.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.widget.Button;
31
import android.widget.TextView;
32

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

    
38
import org.distorted.bandaged.BandagedCreatorActivity;
39
import org.distorted.main.R;
40
import org.distorted.main.RubikActivity;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
public class RubikDialogBandagedDelete 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
    DisplayMetrics displaymetrics = new DisplayMetrics();
55
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
56
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
57
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_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.delete_object );
62
    builder.setCustomTitle(tv);
63

    
64
    final View view = inflater.inflate(R.layout.dialog_delete_object, null);
65

    
66
    TextView save = view.findViewById(R.id.delete_object_text);
67
    save.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
68

    
69
    builder.setCancelable(true);
70

    
71
    Bundle args = getArguments();
72
    String name;
73

    
74
    try
75
      {
76
      name = args.getString("name");
77
      }
78
    catch(Exception e)
79
      {
80
      name = "";
81
      }
82
    final String objectName = name;
83

    
84
    builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
85
      {
86
      @Override
87
      public void onClick(DialogInterface dialog, int which)
88
        {
89
        BandagedCreatorActivity bact = (BandagedCreatorActivity)getContext();
90
        if( bact!=null ) bact.deleteObject(objectName);
91
        }
92
      });
93

    
94
    builder.setNegativeButton( R.string.no, new DialogInterface.OnClickListener()
95
      {
96
      @Override
97
      public void onClick(DialogInterface dialog, int which)
98
        {
99
        // empty
100
        }
101
      });
102

    
103
    builder.setView(view);
104
    final Dialog dialog = builder.create();
105

    
106
    dialog.setCanceledOnTouchOutside(false);
107
    Window window = dialog.getWindow();
108

    
109
    if( window!=null )
110
      {
111
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
112
      }
113

    
114
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
115
      {
116
      @Override
117
      public void onShow(DialogInterface dialog)
118
        {
119
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
120
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
121
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
122
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
123
        }
124
      });
125

    
126
    return dialog;
127
    }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  public static String getDialogTag()
132
    {
133
    return "DialogBandagedDelete";
134
    }
135
  }
(3-3/25)