Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogNewRecord.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.external.RubikScores;
31
import org.distorted.objects.RubikObjectList;
32
import org.distorted.screens.ScreenList;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
public class RubikDialogNewRecord extends AppCompatDialogFragment
37
  {
38
  @NonNull
39
  @Override
40
  public Dialog onCreateDialog(Bundle savedInstanceState)
41
    {
42
    FragmentActivity act = getActivity();
43
    LayoutInflater inflater = act.getLayoutInflater();
44
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
45

    
46
    DisplayMetrics displaymetrics = new DisplayMetrics();
47
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
48
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
49
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
50
    final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
51

    
52
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
53
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
54
    tv.setText(R.string.new_record);
55
    builder.setCustomTitle(tv);
56
    builder.setCancelable(true);
57

    
58
    builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
59
      {
60
      @Override
61
      public void onClick(DialogInterface dialog, int which)
62
        {
63
        RubikActivity act = (RubikActivity)getActivity();
64
        RubikScores scores = RubikScores.getInstance();
65
        String name = scores.getName();
66
        Bundle bundle = new Bundle();
67
        ScreenList.switchScreen(act, ScreenList.PLAY);
68

    
69
        if( name.length()>0 )
70
          {
71
          int object = RubikObjectList.getCurrObject();
72

    
73
          bundle.putInt("tab", object );
74
          bundle.putBoolean("submitting", true);
75

    
76
          RubikDialogScores scoresDiag = new RubikDialogScores();
77
          scoresDiag.setArguments(bundle);
78
          scoresDiag.show(act.getSupportFragmentManager(), null);
79
          }
80
        else
81
          {
82
          bundle.putString("name", name );
83

    
84
          RubikDialogSetName nameDiag = new RubikDialogSetName();
85
          nameDiag.setArguments(bundle);
86
          nameDiag.show(act.getSupportFragmentManager(), null);
87
          }
88
        }
89
      });
90

    
91
    builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener()
92
      {
93
      @Override
94
      public void onClick(DialogInterface dialog, int which)
95
        {
96
        RubikActivity act = (RubikActivity)getActivity();
97
        ScreenList.switchScreen(act, ScreenList.PLAY);
98
        }
99
      });
100

    
101
    Bundle args = getArguments();
102
    long time;
103

    
104
    try
105
      {
106
      time = args.getLong("time");
107
      }
108
    catch(Exception e)
109
      {
110
      time = 0;
111
      }
112

    
113
    final View view = inflater.inflate(R.layout.dialog_new_record, null);
114
    TextView text = view.findViewById(R.id.new_record_time);
115
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
116
    text.setText(getString(R.string.ti_placeholder, (time/10)/100.0f));
117
    builder.setView(view);
118

    
119
    TextView submit = view.findViewById(R.id.new_record_submit);
120
    submit.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
121

    
122
    Dialog dialog = builder.create();
123
    dialog.setCanceledOnTouchOutside(false);
124
    Window window = dialog.getWindow();
125

    
126
    if( window!=null )
127
      {
128
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
129
      }
130

    
131
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
132
      {
133
      @Override
134
      public void onShow(DialogInterface dialog)
135
        {
136
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
137
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
138
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
139
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
140
        }
141
      });
142

    
143
    return dialog;
144
    }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

    
148
  public static String getDialogTag()
149
    {
150
    return "DialogNewRecord";
151
    }
152
  }
(7-7/23)