Project

General

Profile

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

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

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

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

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

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

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

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

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

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

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

    
73
    builder.setCancelable(true);
74

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

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

    
93
    builder.setView(view);
94

    
95
    final Dialog dialog = builder.create();
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, butSize);
111
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
112
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
113
        }
114
      });
115

    
116
    return dialog;
117
    }
118
  }
(9-9/18)