Project

General

Profile

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

magiccube / src / main / java / org / distorted / dialogs / RubikDialogNewRecord.java @ 7ac0ee88

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.objectlib.main.ObjectList;
39

    
40
import org.distorted.main.R;
41
import org.distorted.main.RubikActivity;
42
import org.distorted.network.RubikScores;
43
import org.distorted.screens.ScreenList;
44
import org.distorted.screens.RubikScreenPlay;
45

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

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

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

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

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

    
81
        if( name.length()>0 )
82
          {
83
          RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
84
          int object = play.getObject();
85

    
86
          bundle.putInt("tab", object );
87
          bundle.putBoolean("submitting", true);
88

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

    
97
          RubikDialogSetName nameDiag = new RubikDialogSetName();
98
          nameDiag.setArguments(bundle);
99
          nameDiag.show(act.getSupportFragmentManager(), null);
100
          }
101
        }
102
      });
103

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

    
114
    Bundle args = getArguments();
115
    long time;
116

    
117
    try
118
      {
119
      time = args.getLong("time");
120
      }
121
    catch(Exception e)
122
      {
123
      time = 0;
124
      }
125

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

    
132
    TextView submit = view.findViewById(R.id.new_record_submit);
133
    submit.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
134

    
135
    Dialog dialog = builder.create();
136
    dialog.setCanceledOnTouchOutside(false);
137
    Window window = dialog.getWindow();
138

    
139
    if( window!=null )
140
      {
141
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
142
      }
143

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

    
156
    return dialog;
157
    }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  public static String getDialogTag()
162
    {
163
    return "DialogNewRecord";
164
    }
165
  }
(5-5/19)