Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogInfo.java @ 80218b07

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.util.DisplayMetrics;
26
import android.util.TypedValue;
27
import android.view.LayoutInflater;
28
import android.view.View;
29
import android.view.Window;
30
import android.widget.Button;
31
import android.widget.TextView;
32

    
33
import androidx.annotation.NonNull;
34
import androidx.appcompat.app.AlertDialog;
35
import androidx.appcompat.app.AppCompatDialogFragment;
36
import androidx.fragment.app.FragmentActivity;
37

    
38
import org.distorted.main.R;
39
import org.distorted.main.RubikActivity;
40
import org.distorted.main.RubikPreRender;
41
import org.distorted.objects.TwistyObject;
42

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

    
45
public class RubikDialogInfo extends AppCompatDialogFragment
46
  {
47
  @NonNull
48
  @Override
49
  public Dialog onCreateDialog(Bundle savedInstanceState)
50
    {
51
    final FragmentActivity act = getActivity();
52
    LayoutInflater inflater = act.getLayoutInflater();
53
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
54

    
55
    DisplayMetrics displaymetrics = new DisplayMetrics();
56
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
57
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
58
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
59
    TwistyObject object = getObject();
60
    int numLayers = object.getNumLayers();
61

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

    
67
    final View view = inflater.inflate(R.layout.dialog_error, null);
68
    TextView text = view.findViewById(R.id.error_string);
69
    text.setText(R.string.tutorial);
70

    
71
    builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
72
      {
73
      @Override
74
      public void onClick(DialogInterface dialog, int which)
75
        {
76

    
77
        }
78
      });
79

    
80
    builder.setNegativeButton( R.string.no, new DialogInterface.OnClickListener()
81
      {
82
      @Override
83
      public void onClick(DialogInterface dialog, int which)
84
        {
85

    
86
        }
87
      });
88

    
89
    builder.setView(view);
90

    
91
    final Dialog dialog = builder.create();
92
    dialog.setCanceledOnTouchOutside(false);
93

    
94
    Window window = dialog.getWindow();
95

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

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

    
113
    return dialog;
114
    }
115

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

    
118
  private TwistyObject getObject()
119
    {
120
    RubikActivity act = (RubikActivity)getContext();
121
    return act.getObject();
122
    }
123
  }
(4-4/16)