Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogSolved.java @ f5da732a

1 e41e7dc3 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 1f9772f3 Leszek Koltunski
package org.distorted.dialogs;
21 e41e7dc3 Leszek Koltunski
22
import android.app.Dialog;
23
import android.content.DialogInterface;
24
import android.os.Bundle;
25 66e777b0 Leszek Koltunski
import androidx.annotation.NonNull;
26
import androidx.fragment.app.FragmentActivity;
27
import androidx.appcompat.app.AlertDialog;
28
import androidx.appcompat.app.AppCompatDialogFragment;
29 fb37b424 Leszek Koltunski
30
import android.util.DisplayMetrics;
31
import android.util.TypedValue;
32 e41e7dc3 Leszek Koltunski
import android.view.LayoutInflater;
33
import android.view.View;
34
import android.view.Window;
35 fb37b424 Leszek Koltunski
import android.widget.Button;
36 e41e7dc3 Leszek Koltunski
import android.widget.TextView;
37
38 1f9772f3 Leszek Koltunski
import org.distorted.main.R;
39
import org.distorted.main.RubikActivity;
40 fcd5b990 Leszek Koltunski
import org.distorted.screens.ScreenList;
41 e41e7dc3 Leszek Koltunski
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43
44
public class RubikDialogSolved extends AppCompatDialogFragment
45
  {
46
  @NonNull
47
  @Override
48
  public Dialog onCreateDialog(Bundle savedInstanceState)
49
    {
50
    FragmentActivity act = getActivity();
51
    LayoutInflater inflater = act.getLayoutInflater();
52
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
53
54 fb37b424 Leszek Koltunski
    DisplayMetrics displaymetrics = new DisplayMetrics();
55
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
56
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
57 eb376d3a Leszek Koltunski
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
58 fb37b424 Leszek Koltunski
    final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
59
60 e41e7dc3 Leszek Koltunski
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
61 fb37b424 Leszek Koltunski
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
62 e41e7dc3 Leszek Koltunski
    tv.setText(R.string.solved);
63
    builder.setCustomTitle(tv);
64
65
    builder.setCancelable(true);
66
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
67
      {
68
      @Override
69
      public void onClick(DialogInterface dialog, int which)
70
        {
71
        RubikActivity act = (RubikActivity)getActivity();
72 f5da732a Leszek Koltunski
        ScreenList.switchScreen(act, ScreenList.PLAY);
73 e41e7dc3 Leszek Koltunski
        }
74
      });
75
76
    Bundle args = getArguments();
77
    long time;
78
79
    try
80
      {
81
      time = args.getLong("time");
82
      }
83
    catch(Exception e)
84
      {
85
      time = 0;
86
      }
87
88
    final View view = inflater.inflate(R.layout.dialog_solved, null);
89
    TextView text = view.findViewById(R.id.solved_time);
90 fb37b424 Leszek Koltunski
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
91 79e752b3 Leszek Koltunski
    text.setText(getString(R.string.ti_placeholder, (time/10)/100.0f));
92 e41e7dc3 Leszek Koltunski
    builder.setView(view);
93
94 85248b04 Leszek Koltunski
    Dialog dialog = builder.create();
95
    dialog.setCanceledOnTouchOutside(false);
96
    Window window = dialog.getWindow();
97
98
    if( window!=null )
99
      {
100 ffd68f35 Leszek Koltunski
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
101 85248b04 Leszek Koltunski
      }
102
103 fb37b424 Leszek Koltunski
    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, okSize);
110
        }
111
      });
112
113 85248b04 Leszek Koltunski
    return dialog;
114 e41e7dc3 Leszek Koltunski
    }
115 dca3888a Leszek Koltunski
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117
118
  public static String getDialogTag()
119
    {
120
    return "DialogSolved";
121
    }
122 e41e7dc3 Leszek Koltunski
  }