Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogNewRecord.java @ acabdd83

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 androidx.annotation.NonNull;
26
import androidx.fragment.app.FragmentActivity;
27
import androidx.appcompat.app.AlertDialog;
28
import androidx.appcompat.app.AppCompatDialogFragment;
29

    
30
import android.util.DisplayMetrics;
31
import android.util.TypedValue;
32
import android.view.LayoutInflater;
33
import android.view.View;
34
import android.view.Window;
35
import android.widget.Button;
36
import android.widget.TextView;
37

    
38
import org.distorted.main.R;
39
import org.distorted.main.RubikActivity;
40
import org.distorted.external.RubikScores;
41
import org.distorted.objects.RubikObjectList;
42
import org.distorted.screens.ScreenList;
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

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

    
56
    DisplayMetrics displaymetrics = new DisplayMetrics();
57
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
58
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
59
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
60
    final float textSize = displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
61

    
62
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
63
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
64
    tv.setText(R.string.new_record);
65
    builder.setCustomTitle(tv);
66
    builder.setCancelable(true);
67

    
68
    builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
69
      {
70
      @Override
71
      public void onClick(DialogInterface dialog, int which)
72
        {
73
        RubikActivity act = (RubikActivity)getActivity();
74
        RubikScores scores = RubikScores.getInstance();
75
        String name = scores.getName();
76
        Bundle bundle = new Bundle();
77
        ScreenList.switchScreen(act, ScreenList.PLAY);
78

    
79
        if( name.length()>0 )
80
          {
81
          int object = RubikObjectList.getCurrObject();
82

    
83
          bundle.putInt("tab", object );
84
          bundle.putBoolean("submitting", true);
85

    
86
          RubikDialogScores scoresDiag = new RubikDialogScores();
87
          scoresDiag.setArguments(bundle);
88
          scoresDiag.show(act.getSupportFragmentManager(), null);
89
          }
90
        else
91
          {
92
          bundle.putString("name", name );
93

    
94
          RubikDialogSetName nameDiag = new RubikDialogSetName();
95
          nameDiag.setArguments(bundle);
96
          nameDiag.show(act.getSupportFragmentManager(), null);
97
          }
98
        }
99
      });
100

    
101
    builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener()
102
      {
103
      @Override
104
      public void onClick(DialogInterface dialog, int which)
105
        {
106
        RubikActivity act = (RubikActivity)getActivity();
107
        ScreenList.switchScreen(act, ScreenList.PLAY);
108
        }
109
      });
110

    
111
    Bundle args = getArguments();
112
    long time;
113

    
114
    try
115
      {
116
      time = args.getLong("time");
117
      }
118
    catch(Exception e)
119
      {
120
      time = 0;
121
      }
122

    
123
    final View view = inflater.inflate(R.layout.dialog_new_record, null);
124
    TextView text = view.findViewById(R.id.new_record_time);
125
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
126
    text.setText(getString(R.string.ti_placeholder, (time/10)/100.0f));
127
    builder.setView(view);
128

    
129
    TextView submit = view.findViewById(R.id.new_record_submit);
130
    submit.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
131

    
132
    Dialog dialog = builder.create();
133
    dialog.setCanceledOnTouchOutside(false);
134
    Window window = dialog.getWindow();
135

    
136
    if( window!=null )
137
      {
138
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
139
      }
140

    
141
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
142
      {
143
      @Override
144
      public void onShow(DialogInterface dialog)
145
        {
146
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
147
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
148
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
149
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
150
        }
151
      });
152

    
153
    return dialog;
154
    }
155

    
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157

    
158
  public static String getDialogTag()
159
    {
160
    return "DialogNewRecord";
161
    }
162
  }
(5-5/21)