Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogSolved.java @ 05c044a5

1 e41e7dc3 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 68191e7d Leszek Koltunski
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8 e41e7dc3 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10 1f9772f3 Leszek Koltunski
package org.distorted.dialogs;
11 e41e7dc3 Leszek Koltunski
12
import android.app.Dialog;
13
import android.content.DialogInterface;
14
import android.os.Bundle;
15 66e777b0 Leszek Koltunski
import androidx.annotation.NonNull;
16
import androidx.fragment.app.FragmentActivity;
17
import androidx.appcompat.app.AlertDialog;
18
import androidx.appcompat.app.AppCompatDialogFragment;
19 fb37b424 Leszek Koltunski
20
import android.util.DisplayMetrics;
21
import android.util.TypedValue;
22 e41e7dc3 Leszek Koltunski
import android.view.LayoutInflater;
23
import android.view.View;
24
import android.view.Window;
25 fb37b424 Leszek Koltunski
import android.widget.Button;
26 e41e7dc3 Leszek Koltunski
import android.widget.TextView;
27
28 1f9772f3 Leszek Koltunski
import org.distorted.main.R;
29
import org.distorted.main.RubikActivity;
30 fcd5b990 Leszek Koltunski
import org.distorted.screens.ScreenList;
31 e41e7dc3 Leszek Koltunski
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33
34
public class RubikDialogSolved extends AppCompatDialogFragment
35
  {
36
  @NonNull
37
  @Override
38
  public Dialog onCreateDialog(Bundle savedInstanceState)
39
    {
40
    FragmentActivity act = getActivity();
41
    LayoutInflater inflater = act.getLayoutInflater();
42
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
43
44 fb37b424 Leszek Koltunski
    DisplayMetrics displaymetrics = new DisplayMetrics();
45
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
46
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
47 eb376d3a Leszek Koltunski
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
48 fb37b424 Leszek Koltunski
    final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
49
50 e41e7dc3 Leszek Koltunski
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
51 fb37b424 Leszek Koltunski
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
52 e41e7dc3 Leszek Koltunski
    tv.setText(R.string.solved);
53
    builder.setCustomTitle(tv);
54
55
    builder.setCancelable(true);
56
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
57
      {
58
      @Override
59
      public void onClick(DialogInterface dialog, int which)
60
        {
61
        RubikActivity act = (RubikActivity)getActivity();
62 f5da732a Leszek Koltunski
        ScreenList.switchScreen(act, ScreenList.PLAY);
63 e41e7dc3 Leszek Koltunski
        }
64
      });
65
66
    Bundle args = getArguments();
67
    long time;
68
69
    try
70
      {
71
      time = args.getLong("time");
72
      }
73
    catch(Exception e)
74
      {
75
      time = 0;
76
      }
77
78
    final View view = inflater.inflate(R.layout.dialog_solved, null);
79
    TextView text = view.findViewById(R.id.solved_time);
80 fb37b424 Leszek Koltunski
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
81 79e752b3 Leszek Koltunski
    text.setText(getString(R.string.ti_placeholder, (time/10)/100.0f));
82 e41e7dc3 Leszek Koltunski
    builder.setView(view);
83
84 85248b04 Leszek Koltunski
    Dialog dialog = builder.create();
85
    dialog.setCanceledOnTouchOutside(false);
86
    Window window = dialog.getWindow();
87
88
    if( window!=null )
89
      {
90 ffd68f35 Leszek Koltunski
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
91 85248b04 Leszek Koltunski
      }
92
93 fb37b424 Leszek Koltunski
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
94
      {
95
      @Override
96
      public void onShow(DialogInterface dialog)
97
        {
98
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
99
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
100
        }
101
      });
102
103 85248b04 Leszek Koltunski
    return dialog;
104 e41e7dc3 Leszek Koltunski
    }
105 dca3888a Leszek Koltunski
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107
108
  public static String getDialogTag()
109
    {
110
    return "DialogSolved";
111
    }
112 e41e7dc3 Leszek Koltunski
  }