Project

General

Profile

« Previous | Next » 

Revision bc511ea5

Added by Leszek Koltunski over 4 years ago

Add the 'New Record' dialog.

View differences:

src/main/java/org/distorted/dialog/RubikDialogNewRecord.java
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.dialog;
21

  
22
import android.app.Dialog;
23
import android.content.DialogInterface;
24
import android.os.Bundle;
25
import android.support.annotation.NonNull;
26
import android.support.v4.app.FragmentActivity;
27
import android.support.v7.app.AlertDialog;
28
import android.support.v7.app.AppCompatDialogFragment;
29
import android.view.LayoutInflater;
30
import android.view.View;
31
import android.view.Window;
32
import android.view.WindowManager;
33
import android.widget.TextView;
34

  
35
import org.distorted.magic.R;
36
import org.distorted.magic.RubikActivity;
37
import org.distorted.scores.RubikScoresDownloader;
38
import org.distorted.uistate.RubikState;
39

  
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

  
42
public class RubikDialogNewRecord extends AppCompatDialogFragment
43
  {
44
  @Override
45
  public void onStart()
46
    {
47
    super.onStart();
48

  
49
    Window window = getDialog().getWindow();
50
    window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
51
                    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
52
    window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
53
    }
54

  
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

  
57
  @NonNull
58
  @Override
59
  public Dialog onCreateDialog(Bundle savedInstanceState)
60
    {
61
    FragmentActivity act = getActivity();
62
    LayoutInflater inflater = act.getLayoutInflater();
63
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
64

  
65
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
66
    tv.setText(R.string.new_record);
67
    builder.setCustomTitle(tv);
68

  
69
    builder.setCancelable(true);
70
    builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener()
71
      {
72
      @Override
73
      public void onClick(DialogInterface dialog, int which)
74
        {
75
        RubikScoresDownloader downloader = RubikScoresDownloader.getInstance();
76
        downloader.submit();
77
        RubikActivity act = (RubikActivity)getActivity();
78
        RubikState.switchState(act,RubikState.PLAY);
79
        }
80
      });
81
    builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener()
82
      {
83
      @Override
84
      public void onClick(DialogInterface dialog, int which)
85
        {
86
        RubikActivity act = (RubikActivity)getActivity();
87
        RubikState.switchState(act,RubikState.PLAY);
88
        }
89
      });
90

  
91
    Bundle args = getArguments();
92
    long time;
93

  
94
    try
95
      {
96
      time = args.getLong("time");
97
      }
98
    catch(Exception e)
99
      {
100
      time = 0;
101
      }
102

  
103
    final View view = inflater.inflate(R.layout.dialog_new_record, null);
104
    TextView text = view.findViewById(R.id.new_record_time);
105
    text.setText(getString(R.string.ti_placeholder, (time/100)/10.0f));
106
    builder.setView(view);
107

  
108
    return builder.create();
109
    }
110
  }
src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java
167 167
    if( allCreated )
168 168
      {
169 169
      RubikScores scores = RubikScores.getInstance();
170
      RubikScoresDownloader downloader = new RubikScoresDownloader();
170
      RubikScoresDownloader downloader = RubikScoresDownloader.getInstance();
171 171
      downloader.download( this, scores.getName(), mAct.getString(R.string.app_version), scores.getNumRuns() );
172 172
      }
173 173

  
src/main/java/org/distorted/magic/RubikRenderer.java
23 23
import android.opengl.GLSurfaceView;
24 24
import android.os.Bundle;
25 25

  
26
import org.distorted.dialog.RubikDialogNewRecord;
26 27
import org.distorted.dialog.RubikDialogSolved;
27 28
import org.distorted.effect.BaseEffect;
28 29
import org.distorted.library.effect.VertexEffectSink;
......
403 404
             if( RubikState.getCurrentState()==RubikState.SOLV )
404 405
               {
405 406
               final RubikActivity act = (RubikActivity)mView.getContext();
407
               Bundle bundle = new Bundle();
408
               bundle.putLong("time", mNewRecord );
406 409

  
407 410
               if( mIsNewRecord )
408 411
                 {
409
                 RubikDialogSolved dialog = new RubikDialogSolved();
410

  
411
                 Bundle bundle = new Bundle();
412
                 bundle.putLong("time", mNewRecord );
412
                 RubikDialogNewRecord dialog = new RubikDialogNewRecord();
413 413
                 dialog.setArguments(bundle);
414 414
                 dialog.show( act.getSupportFragmentManager(), null);
415 415
                 }
416 416
               else
417 417
                 {
418 418
                 RubikDialogSolved dialog = new RubikDialogSolved();
419

  
420
                 Bundle bundle = new Bundle();
421
                 bundle.putLong("time", mNewRecord );
422 419
                 dialog.setArguments(bundle);
423 420
                 dialog.show( act.getSupportFragmentManager(), null);
424 421
                 }
src/main/java/org/distorted/scores/RubikScoresDownloader.java
92 92
  private static  float[][][] mTime    = new  float[mTotal][MAX_SCRAMBLE][MAX_PLACES];
93 93

  
94 94
  private static int[][] mPlaces = new int[mTotal][MAX_SCRAMBLE];
95
  private static RubikScoresDownloader mThis;
95 96

  
96 97
///////////////////////////////////////////////////////////////////////////////////////////////////
97 98

  
......
292 293
      }
293 294
    }
294 295

  
296
///////////////////////////////////////////////////////////////////////////////////////////////////
297

  
298
  private RubikScoresDownloader()
299
    {
300

  
301
    }
302

  
295 303
///////////////////////////////////////////////////////////////////////////////////////////////////
296 304
// PUBLIC API
297 305
///////////////////////////////////////////////////////////////////////////////////////////////////
......
301 309
    mRunning = false;
302 310
    }
303 311

  
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313

  
314
  public static RubikScoresDownloader getInstance()
315
    {
316
    if( mThis==null )
317
      {
318
      mThis = new RubikScoresDownloader();
319
      }
320

  
321
    return mThis;
322
    }
323

  
304 324
///////////////////////////////////////////////////////////////////////////////////////////////////
305 325

  
306 326
  public void download(Receiver receiver, String userName, String version, int numRuns)
......
314 334
    Thread networkThrd = new Thread(this);
315 335
    networkThrd.start();
316 336
    }
337

  
338
///////////////////////////////////////////////////////////////////////////////////////////////////
339

  
340
  public void submit()
341
    {
342
    mMode = SUBMIT;
343

  
344
    android.util.Log.e("downloader", "submitting!");
345
    }
317 346
}
src/main/res/layout/dialog_new_record.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="match_parent"
4
    android:layout_height="match_parent"
5
    android:gravity="center_horizontal"
6
    android:orientation="vertical">
7

  
8
    <LinearLayout
9
        android:layout_width="fill_parent"
10
        android:layout_height="fill_parent"
11
        android:gravity="center|fill_horizontal"
12
        android:layout_marginLeft="10dp"
13
        android:layout_marginRight="10dp"
14
        android:layout_marginTop="0dp"
15
        android:background="@color/grey"
16
        android:orientation="vertical">
17

  
18
        <TextView
19
            android:id="@+id/new_record_time"
20
            android:layout_width="match_parent"
21
            android:layout_height="match_parent"
22
            android:gravity="center"
23
            android:textSize="24sp"
24
            android:layout_marginTop="10dp"
25
            android:layout_marginLeft="10dp"
26
            android:layout_marginRight="10dp"
27
            android:layout_marginBottom="10dp"/>
28

  
29
         <TextView
30
            android:id="@+id/new_record_submit"
31
            android:layout_width="match_parent"
32
            android:layout_height="match_parent"
33
            android:gravity="center"
34
            android:textSize="24sp"
35
            android:layout_marginTop="10dp"
36
            android:layout_marginLeft="10dp"
37
            android:layout_marginRight="10dp"
38
            android:layout_marginBottom="10dp"
39
            android:text="@string/new_record_submit"/>/>
40

  
41
    </LinearLayout>
42
</LinearLayout>
src/main/res/values/strings.xml
10 10
    <string name="scores">High Scores</string>
11 11
    <string name="about">About</string>
12 12
    <string name="solved">Solved</string>
13
    <string name="new_record">New Record</string>
14
    <string name="new_record_submit">Do you want to submit it to High Scores?</string>
13 15
    <string name="back">Back</string>
14 16
    <string name="save">SAVE</string>
15 17
    <string name="ok">OK</string>
18
    <string name="yes">YES</string>
19
    <string name="no">NO</string>
16 20
    <string name="ready">Ready?</string>
17 21
    <string name="sizechange_effect">Size Change Effect</string>
18 22
    <string name="solve_effect">Solve Effect</string>

Also available in: Unified diff