Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogPrivacy.java @ b1e9596b

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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.text.method.LinkMovementMethod;
26
import android.text.method.MovementMethod;
27
import android.util.DisplayMetrics;
28
import android.util.TypedValue;
29
import android.view.LayoutInflater;
30
import android.view.View;
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.main.R;
40
import org.distorted.main.RubikActivity;
41

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

    
44
public class RubikDialogPrivacy extends AppCompatDialogFragment
45
  {
46
  @NonNull
47
  @Override
48
  public Dialog onCreateDialog(Bundle savedInstanceState)
49
    {
50
    final RubikActivity ract = (RubikActivity)getContext();
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 butSize  = displaymetrics.widthPixels * RubikActivity.MENU_MEDIUM_TEXT_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.privacy_policy);
64
    builder.setCustomTitle(tv);
65

    
66
    MovementMethod mm = LinkMovementMethod.getInstance();
67
    final View view = inflater.inflate(R.layout.dialog_privacy, null);
68
    TextView text = view.findViewById(R.id.privacy_string);
69
    text.setMovementMethod(mm);
70

    
71
    builder.setCancelable(true);
72

    
73
    builder.setPositiveButton( R.string.accept, new DialogInterface.OnClickListener()
74
      {
75
      @Override
76
      public void onClick(DialogInterface dialog, int which)
77
        {
78
        if( ract!=null ) ract.acceptPrivacy();
79
        }
80
      });
81

    
82
    builder.setNegativeButton( R.string.decline, new DialogInterface.OnClickListener()
83
      {
84
      @Override
85
      public void onClick(DialogInterface dialog, int which)
86
        {
87
        if( ract!=null ) ract.declinePrivacy();
88
        }
89
      });
90

    
91
    builder.setView(view);
92

    
93
    final Dialog dialog = builder.create();
94
    dialog.setCanceledOnTouchOutside(false);
95

    
96
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
97
      {
98
      @Override
99
      public void onShow(DialogInterface dialog)
100
        {
101
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
102
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
103
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
104
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
105
        }
106
      });
107

    
108
    return dialog;
109
    }
110
  }
(9-9/15)