Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogBandagedDelete.java @ fad10885

1 61a7b812 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 68191e7d Leszek Koltunski
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8 61a7b812 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.dialogs;
11
12
import android.app.Dialog;
13
import android.content.DialogInterface;
14
import android.os.Bundle;
15
import android.util.DisplayMetrics;
16
import android.util.TypedValue;
17
import android.view.LayoutInflater;
18
import android.view.View;
19
import android.view.Window;
20
import android.widget.Button;
21
import android.widget.TextView;
22
23
import androidx.annotation.NonNull;
24
import androidx.appcompat.app.AlertDialog;
25
import androidx.appcompat.app.AppCompatDialogFragment;
26
import androidx.fragment.app.FragmentActivity;
27
28 72e386ef Leszek Koltunski
import org.distorted.bandaged.BandagedCreatorActivity;
29 61a7b812 Leszek Koltunski
import org.distorted.main.R;
30
import org.distorted.main.RubikActivity;
31
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33
34 6647b730 Leszek Koltunski
public class RubikDialogBandagedDelete extends AppCompatDialogFragment
35 61a7b812 Leszek Koltunski
  {
36
  @NonNull
37
  @Override
38
  public Dialog onCreateDialog(Bundle savedInstanceState)
39
    {
40
    FragmentActivity act = getActivity();
41
    LayoutInflater inflater = act.getLayoutInflater();
42
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
43
44
    DisplayMetrics displaymetrics = new DisplayMetrics();
45
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
46
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
47
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
48
49
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
50
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
51 6647b730 Leszek Koltunski
    tv.setText( R.string.delete_object );
52 61a7b812 Leszek Koltunski
    builder.setCustomTitle(tv);
53
54 6647b730 Leszek Koltunski
    final View view = inflater.inflate(R.layout.dialog_delete_object, null);
55 61a7b812 Leszek Koltunski
56 6647b730 Leszek Koltunski
    TextView save = view.findViewById(R.id.delete_object_text);
57 fa52fe5d Leszek Koltunski
    save.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
58
59 61a7b812 Leszek Koltunski
    builder.setCancelable(true);
60
61 6647b730 Leszek Koltunski
    Bundle args = getArguments();
62
    String name;
63
64
    try
65
      {
66
      name = args.getString("name");
67
      }
68
    catch(Exception e)
69
      {
70
      name = "";
71
      }
72
    final String objectName = name;
73
74 61a7b812 Leszek Koltunski
    builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
75
      {
76
      @Override
77
      public void onClick(DialogInterface dialog, int which)
78
        {
79 72e386ef Leszek Koltunski
        BandagedCreatorActivity bact = (BandagedCreatorActivity)getContext();
80 85770de9 Leszek Koltunski
        if( bact!=null ) bact.deleteObject(objectName);
81 61a7b812 Leszek Koltunski
        }
82
      });
83
84
    builder.setNegativeButton( R.string.no, new DialogInterface.OnClickListener()
85
      {
86
      @Override
87
      public void onClick(DialogInterface dialog, int which)
88
        {
89 72e386ef Leszek Koltunski
        // empty
90 61a7b812 Leszek Koltunski
        }
91
      });
92
93
    builder.setView(view);
94
    final Dialog dialog = builder.create();
95
96
    dialog.setCanceledOnTouchOutside(false);
97
    Window window = dialog.getWindow();
98
99
    if( window!=null )
100
      {
101
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
102
      }
103
104
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
105
      {
106
      @Override
107
      public void onShow(DialogInterface dialog)
108
        {
109
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
110
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
111
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
112
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
113
        }
114
      });
115
116
    return dialog;
117
    }
118 6647b730 Leszek Koltunski
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120
121
  public static String getDialogTag()
122
    {
123
    return "DialogBandagedDelete";
124
    }
125 61a7b812 Leszek Koltunski
  }