1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2020 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.text.method.LinkMovementMethod;
|
16
|
import android.text.method.MovementMethod;
|
17
|
import android.util.DisplayMetrics;
|
18
|
import android.util.TypedValue;
|
19
|
import android.view.LayoutInflater;
|
20
|
import android.view.View;
|
21
|
import android.view.Window;
|
22
|
import android.widget.Button;
|
23
|
import android.widget.TextView;
|
24
|
|
25
|
import androidx.annotation.NonNull;
|
26
|
import androidx.appcompat.app.AlertDialog;
|
27
|
import androidx.appcompat.app.AppCompatDialogFragment;
|
28
|
import androidx.fragment.app.FragmentActivity;
|
29
|
|
30
|
import org.distorted.main.R;
|
31
|
import org.distorted.main.RubikActivity;
|
32
|
|
33
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34
|
|
35
|
public class RubikDialogPrivacy extends AppCompatDialogFragment
|
36
|
{
|
37
|
@NonNull
|
38
|
@Override
|
39
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
40
|
{
|
41
|
final RubikActivity ract = (RubikActivity)getContext();
|
42
|
|
43
|
FragmentActivity act = getActivity();
|
44
|
LayoutInflater inflater = act.getLayoutInflater();
|
45
|
AlertDialog.Builder builder = new AlertDialog.Builder(act);
|
46
|
|
47
|
DisplayMetrics displaymetrics = new DisplayMetrics();
|
48
|
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
49
|
final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
|
50
|
final float butSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
|
51
|
|
52
|
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
|
53
|
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
|
54
|
tv.setText(R.string.privacy_policy);
|
55
|
builder.setCustomTitle(tv);
|
56
|
|
57
|
MovementMethod mm = LinkMovementMethod.getInstance();
|
58
|
final View view = inflater.inflate(R.layout.dialog_privacy, null);
|
59
|
TextView text = view.findViewById(R.id.privacy_string);
|
60
|
text.setMovementMethod(mm);
|
61
|
|
62
|
builder.setCancelable(true);
|
63
|
|
64
|
builder.setPositiveButton( R.string.accept, new DialogInterface.OnClickListener()
|
65
|
{
|
66
|
@Override
|
67
|
public void onClick(DialogInterface dialog, int which)
|
68
|
{
|
69
|
if( ract!=null ) ract.acceptPrivacy();
|
70
|
}
|
71
|
});
|
72
|
|
73
|
builder.setNegativeButton( R.string.decline, new DialogInterface.OnClickListener()
|
74
|
{
|
75
|
@Override
|
76
|
public void onClick(DialogInterface dialog, int which)
|
77
|
{
|
78
|
if( ract!=null ) ract.declinePrivacy();
|
79
|
}
|
80
|
});
|
81
|
|
82
|
builder.setView(view);
|
83
|
|
84
|
final Dialog dialog = builder.create();
|
85
|
dialog.setCanceledOnTouchOutside(false);
|
86
|
Window window = dialog.getWindow();
|
87
|
|
88
|
if( window!=null )
|
89
|
{
|
90
|
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
|
91
|
}
|
92
|
|
93
|
dialog.setOnShowListener(new DialogInterface.OnShowListener()
|
94
|
{
|
95
|
@Override
|
96
|
public void onShow(DialogInterface dialog)
|
97
|
{
|
98
|
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
|
99
|
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
|
100
|
Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
|
101
|
btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
|
102
|
}
|
103
|
});
|
104
|
|
105
|
return dialog;
|
106
|
}
|
107
|
}
|