Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// 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
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.dialogs;
11

    
12
import android.app.Dialog;
13
import android.content.DialogInterface;
14
import android.os.Bundle;
15
import androidx.annotation.NonNull;
16
import androidx.fragment.app.FragmentActivity;
17
import androidx.appcompat.app.AlertDialog;
18
import androidx.appcompat.app.AppCompatDialogFragment;
19

    
20
import android.util.DisplayMetrics;
21
import android.util.TypedValue;
22
import android.view.LayoutInflater;
23
import android.view.View;
24
import android.view.Window;
25
import android.widget.Button;
26
import android.widget.TextView;
27

    
28
import org.distorted.main.R;
29
import org.distorted.main.RubikActivity;
30
import org.distorted.screens.ScreenList;
31

    
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
    DisplayMetrics displaymetrics = new DisplayMetrics();
45
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
46
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
47
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
48
    final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
49

    
50
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
51
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
52
    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
        ScreenList.switchScreen(act, ScreenList.PLAY);
63
        }
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
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
81
    text.setText(getString(R.string.ti_placeholder, (time/10)/100.0f));
82
    builder.setView(view);
83

    
84
    Dialog dialog = builder.create();
85
    dialog.setCanceledOnTouchOutside(false);
86
    Window window = dialog.getWindow();
87

    
88
    if( window!=null )
89
      {
90
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
91
      }
92

    
93
    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
    return dialog;
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  public static String getDialogTag()
109
    {
110
    return "DialogSolved";
111
    }
112
  }
(17-17/23)