Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogPrivacy.java @ 3f7a4363

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.view.Window;
32
import android.widget.Button;
33
import android.widget.TextView;
34

    
35
import androidx.annotation.NonNull;
36
import androidx.appcompat.app.AlertDialog;
37
import androidx.appcompat.app.AppCompatDialogFragment;
38
import androidx.fragment.app.FragmentActivity;
39

    
40
import org.distorted.main.R;
41
import org.distorted.main.RubikActivity;
42

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

    
45
public class RubikDialogPrivacy extends AppCompatDialogFragment
46
  {
47
  @NonNull
48
  @Override
49
  public Dialog onCreateDialog(Bundle savedInstanceState)
50
    {
51
    final RubikActivity ract = (RubikActivity)getContext();
52

    
53
    FragmentActivity act = getActivity();
54
    LayoutInflater inflater = act.getLayoutInflater();
55
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
56

    
57
    DisplayMetrics displaymetrics = new DisplayMetrics();
58
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
59
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
60
    final float butSize  = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
61

    
62
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
63
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
64
    tv.setText(R.string.privacy_policy);
65
    builder.setCustomTitle(tv);
66

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

    
72
    builder.setCancelable(true);
73

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

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

    
92
    builder.setView(view);
93

    
94
    final Dialog dialog = builder.create();
95
    dialog.setCanceledOnTouchOutside(false);
96
    Window window = dialog.getWindow();
97

    
98
    if( window!=null )
99
      {
100
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
101
      }
102

    
103
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
104
      {
105
      @Override
106
      public void onShow(DialogInterface dialog)
107
        {
108
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
109
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
110
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
111
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
112
        }
113
      });
114

    
115
    return dialog;
116
    }
117
  }
(10-10/19)