1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2022 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// 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
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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
|
import org.distorted.bandaged.BandagedCreatorActivity;
|
29
|
import org.distorted.main.R;
|
30
|
import org.distorted.main.RubikActivity;
|
31
|
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
|
34
|
public class RubikDialogBandagedDelete extends AppCompatDialogFragment
|
35
|
{
|
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
|
tv.setText( R.string.delete_object );
|
52
|
builder.setCustomTitle(tv);
|
53
|
|
54
|
final View view = inflater.inflate(R.layout.dialog_delete_object, null);
|
55
|
|
56
|
TextView save = view.findViewById(R.id.delete_object_text);
|
57
|
save.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
58
|
|
59
|
builder.setCancelable(true);
|
60
|
|
61
|
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
|
builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
|
75
|
{
|
76
|
@Override
|
77
|
public void onClick(DialogInterface dialog, int which)
|
78
|
{
|
79
|
BandagedCreatorActivity bact = (BandagedCreatorActivity)getContext();
|
80
|
if( bact!=null ) bact.deleteObject(objectName);
|
81
|
}
|
82
|
});
|
83
|
|
84
|
builder.setNegativeButton( R.string.no, new DialogInterface.OnClickListener()
|
85
|
{
|
86
|
@Override
|
87
|
public void onClick(DialogInterface dialog, int which)
|
88
|
{
|
89
|
// empty
|
90
|
}
|
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
|
|
119
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120
|
|
121
|
public static String getDialogTag()
|
122
|
{
|
123
|
return "DialogBandagedDelete";
|
124
|
}
|
125
|
}
|