Revision f895e77a
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/dialog/RubikDialogNewRecord.java | ||
|---|---|---|
| 35 | 35 |
import org.distorted.magic.R; |
| 36 | 36 |
import org.distorted.magic.RubikActivity; |
| 37 | 37 |
import org.distorted.object.RubikObjectList; |
| 38 |
import org.distorted.scores.RubikScores; |
|
| 38 | 39 |
import org.distorted.uistate.RubikState; |
| 39 | 40 |
import org.distorted.uistate.RubikStatePlay; |
| 40 | 41 |
|
| ... | ... | |
| 66 | 67 |
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); |
| 67 | 68 |
tv.setText(R.string.new_record); |
| 68 | 69 |
builder.setCustomTitle(tv); |
| 69 |
|
|
| 70 | 70 |
builder.setCancelable(true); |
| 71 |
|
|
| 71 | 72 |
builder.setPositiveButton( R.string.yes, new DialogInterface.OnClickListener() |
| 72 | 73 |
{
|
| 73 | 74 |
@Override |
| 74 | 75 |
public void onClick(DialogInterface dialog, int which) |
| 75 | 76 |
{
|
| 76 | 77 |
RubikActivity act = (RubikActivity)getActivity(); |
| 77 |
RubikState.switchState(act,RubikState.PLAY); |
|
| 78 |
|
|
| 79 |
RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass(); |
|
| 80 |
int object = play.getObject(); |
|
| 81 |
int size = play.getSize(); |
|
| 82 |
|
|
| 78 |
RubikScores scores = RubikScores.getInstance(); |
|
| 79 |
String name = scores.getName(); |
|
| 83 | 80 |
Bundle bundle = new Bundle(); |
| 84 |
bundle.putInt("tab", RubikObjectList.pack(object,size) );
|
|
| 85 |
bundle.putBoolean("submitting", true);
|
|
| 81 |
RubikState.switchState(act,RubikState.PLAY); |
|
| 86 | 82 |
|
| 87 |
RubikDialogScores scores = new RubikDialogScores(); |
|
| 88 |
scores.setArguments(bundle); |
|
| 89 |
scores.show(act.getSupportFragmentManager(), null); |
|
| 83 |
if( name.length()>0 ) |
|
| 84 |
{
|
|
| 85 |
RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass(); |
|
| 86 |
int object = play.getObject(); |
|
| 87 |
int size = play.getSize(); |
|
| 88 |
|
|
| 89 |
bundle.putInt("tab", RubikObjectList.pack(object,size) );
|
|
| 90 |
bundle.putBoolean("submitting", true);
|
|
| 91 |
|
|
| 92 |
RubikDialogScores scoresDiag = new RubikDialogScores(); |
|
| 93 |
scoresDiag.setArguments(bundle); |
|
| 94 |
scoresDiag.show(act.getSupportFragmentManager(), null); |
|
| 95 |
} |
|
| 96 |
else |
|
| 97 |
{
|
|
| 98 |
bundle.putString("name", name );
|
|
| 99 |
|
|
| 100 |
RubikDialogSetName nameDiag = new RubikDialogSetName(); |
|
| 101 |
nameDiag.setArguments(bundle); |
|
| 102 |
nameDiag.show(act.getSupportFragmentManager(), null); |
|
| 103 |
} |
|
| 90 | 104 |
} |
| 91 | 105 |
}); |
| 106 |
|
|
| 92 | 107 |
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() |
| 93 | 108 |
{
|
| 94 | 109 |
@Override |
| src/main/java/org/distorted/dialog/RubikDialogScores.java | ||
|---|---|---|
| 102 | 102 |
|
| 103 | 103 |
ViewPager viewPager = view.findViewById(R.id.viewpager); |
| 104 | 104 |
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs); |
| 105 |
mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager,isSubmitting); |
|
| 105 |
mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager,isSubmitting, this);
|
|
| 106 | 106 |
tabLayout.setupWithViewPager(viewPager); |
| 107 | 107 |
|
| 108 | 108 |
viewPager.setCurrentItem(curTab); |
| src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.dialog; |
| 21 | 21 |
|
| 22 |
import android.os.Bundle; |
|
| 22 | 23 |
import android.support.annotation.NonNull; |
| 23 | 24 |
import android.support.v4.app.FragmentActivity; |
| 24 | 25 |
import android.support.v4.view.PagerAdapter; |
| ... | ... | |
| 27 | 28 |
import android.view.ViewGroup; |
| 28 | 29 |
import android.widget.LinearLayout; |
| 29 | 30 |
|
| 31 |
import org.distorted.scores.RubikScores; |
|
| 30 | 32 |
import org.distorted.scores.RubikScoresDownloader; |
| 31 | 33 |
import org.distorted.object.RubikObjectList; |
| 32 | 34 |
|
| ... | ... | |
| 37 | 39 |
class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikScoresDownloader.Receiver |
| 38 | 40 |
{
|
| 39 | 41 |
private FragmentActivity mAct; |
| 42 |
private RubikDialogScores mDialog; |
|
| 40 | 43 |
private RubikDialogScoresView[] mViews; |
| 41 | 44 |
private ViewPager mViewPager; |
| 42 | 45 |
private int mNumTabs; |
| ... | ... | |
| 85 | 88 |
|
| 86 | 89 |
switch(errorNumber) |
| 87 | 90 |
{
|
| 88 |
case '2': message("Name Taken"); // TODO
|
|
| 91 |
case '2': RubikScores scores = RubikScores.getInstance(); |
|
| 92 |
Bundle bundle = new Bundle(); |
|
| 93 |
bundle.putString("name", scores.getName() );
|
|
| 94 |
|
|
| 95 |
RubikDialogSetName nameDiag = new RubikDialogSetName(); |
|
| 96 |
nameDiag.setArguments(bundle); |
|
| 97 |
nameDiag.show(mAct.getSupportFragmentManager(), null); |
|
| 98 |
|
|
| 99 |
mDialog.dismiss(); |
|
| 100 |
|
|
| 89 | 101 |
break; |
| 90 | 102 |
case '3': message("Server error");
|
| 91 | 103 |
break; |
| ... | ... | |
| 147 | 159 |
|
| 148 | 160 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 149 | 161 |
|
| 150 |
RubikDialogScoresPagerAdapter(FragmentActivity act, ViewPager viewPager, boolean isSubmitting) |
|
| 162 |
RubikDialogScoresPagerAdapter(FragmentActivity act, ViewPager viewPager, boolean isSubmitting, RubikDialogScores diag)
|
|
| 151 | 163 |
{
|
| 152 | 164 |
mAct = act; |
| 165 |
mDialog = diag; |
|
| 153 | 166 |
mNumTabs = RubikObjectList.getTotal(); |
| 154 | 167 |
mViews = new RubikDialogScoresView[mNumTabs]; |
| 155 | 168 |
mViewPager = viewPager; |
| src/main/java/org/distorted/dialog/RubikDialogScoresView.java | ||
|---|---|---|
| 87 | 87 |
float myRecordInSeconds = (myRecordInMillis/100)/10.0f; |
| 88 | 88 |
boolean mySubmitted = scores.isSubmitted(object, size, scramble); |
| 89 | 89 |
String myName = scores.getName(); |
| 90 |
if( myName.length()==0 ) myName = act.getString(R.string.you); |
|
| 90 | 91 |
int myCountryID = res.getIdentifier( scores.getCountry(), "drawable", packageName); |
| 91 | 92 |
String myRecord = ( myRecordInMillis<RubikScores.NO_RECORD ) ? Float.toString(myRecordInSeconds) : "??"; |
| 92 | 93 |
String theirTime; |
| src/main/java/org/distorted/dialog/RubikDialogSetName.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.EditText; |
|
| 34 |
import android.widget.TextView; |
|
| 35 |
|
|
| 36 |
import org.distorted.magic.R; |
|
| 37 |
import org.distorted.magic.RubikActivity; |
|
| 38 |
import org.distorted.object.RubikObjectList; |
|
| 39 |
import org.distorted.scores.RubikScores; |
|
| 40 |
import org.distorted.uistate.RubikState; |
|
| 41 |
import org.distorted.uistate.RubikStatePlay; |
|
| 42 |
|
|
| 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 44 |
|
|
| 45 |
public class RubikDialogSetName extends AppCompatDialogFragment |
|
| 46 |
{
|
|
| 47 |
@Override |
|
| 48 |
public void onStart() |
|
| 49 |
{
|
|
| 50 |
super.onStart(); |
|
| 51 |
|
|
| 52 |
Window window = getDialog().getWindow(); |
|
| 53 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
| 54 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
| 55 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
| 56 |
} |
|
| 57 |
|
|
| 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 59 |
|
|
| 60 |
@NonNull |
|
| 61 |
@Override |
|
| 62 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
| 63 |
{
|
|
| 64 |
FragmentActivity act = getActivity(); |
|
| 65 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
| 66 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
| 67 |
|
|
| 68 |
Bundle args = getArguments(); |
|
| 69 |
String name; |
|
| 70 |
|
|
| 71 |
try |
|
| 72 |
{
|
|
| 73 |
name = args.getString("name");
|
|
| 74 |
} |
|
| 75 |
catch(Exception e) |
|
| 76 |
{
|
|
| 77 |
name = ""; |
|
| 78 |
} |
|
| 79 |
|
|
| 80 |
boolean first = name.length()==0; |
|
| 81 |
|
|
| 82 |
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); |
|
| 83 |
tv.setText( first ? R.string.choose_name : R.string.name_taken); |
|
| 84 |
builder.setCustomTitle(tv); |
|
| 85 |
|
|
| 86 |
final View view = inflater.inflate(R.layout.dialog_set_name, null); |
|
| 87 |
TextView text = view.findViewById(R.id.set_name_message); |
|
| 88 |
|
|
| 89 |
if( first ) |
|
| 90 |
{
|
|
| 91 |
text.setText(R.string.new_name); |
|
| 92 |
} |
|
| 93 |
else |
|
| 94 |
{
|
|
| 95 |
text.setText(act.getString(R.string.new_name_try_again, name)); |
|
| 96 |
} |
|
| 97 |
|
|
| 98 |
builder.setCancelable(true); |
|
| 99 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
| 100 |
{
|
|
| 101 |
@Override |
|
| 102 |
public void onClick(DialogInterface dialog, int which) |
|
| 103 |
{
|
|
| 104 |
RubikActivity act = (RubikActivity)getActivity(); |
|
| 105 |
RubikState.switchState(act,RubikState.PLAY); |
|
| 106 |
|
|
| 107 |
EditText edit = view.findViewById(R.id.set_name); |
|
| 108 |
String name = edit.getText().toString(); |
|
| 109 |
RubikScores.getInstance().setName(name); |
|
| 110 |
|
|
| 111 |
RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass(); |
|
| 112 |
int object = play.getObject(); |
|
| 113 |
int size = play.getSize(); |
|
| 114 |
|
|
| 115 |
Bundle bundle = new Bundle(); |
|
| 116 |
bundle.putInt("tab", RubikObjectList.pack(object,size) );
|
|
| 117 |
bundle.putBoolean("submitting", true);
|
|
| 118 |
|
|
| 119 |
RubikDialogScores scores = new RubikDialogScores(); |
|
| 120 |
scores.setArguments(bundle); |
|
| 121 |
scores.show(act.getSupportFragmentManager(), null); |
|
| 122 |
} |
|
| 123 |
}); |
|
| 124 |
|
|
| 125 |
builder.setView(view); |
|
| 126 |
|
|
| 127 |
return builder.create(); |
|
| 128 |
} |
|
| 129 |
} |
|
| src/main/java/org/distorted/scores/RubikScores.java | ||
|---|---|---|
| 63 | 63 |
mSubmitted[i][j][k] = 0; |
| 64 | 64 |
} |
| 65 | 65 |
|
| 66 |
mName = "YOU";
|
|
| 66 |
mName = ""; |
|
| 67 | 67 |
mCountry = "un"; |
| 68 | 68 |
|
| 69 | 69 |
mNameIsVerified = false; |
| ... | ... | |
| 251 | 251 |
} |
| 252 | 252 |
} |
| 253 | 253 |
|
| 254 |
mName = preferences.getString("scores_name" , "YOU" );
|
|
| 254 |
mName = preferences.getString("scores_name" , "" );
|
|
| 255 | 255 |
mNameIsVerified = preferences.getBoolean("scores_isVerified", false);
|
| 256 | 256 |
mNumPlays = preferences.getInt("scores_numPlays", 0);
|
| 257 | 257 |
mNumRuns = preferences.getInt("scores_numRuns" , 0);
|
| src/main/res/layout/dialog_set_name.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/set_name_message" |
|
| 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 |
<EditText |
|
| 30 |
android:id="@+id/set_name" |
|
| 31 |
android:layout_width="match_parent" |
|
| 32 |
android:layout_height="wrap_content"/> |
|
| 33 |
|
|
| 34 |
</LinearLayout> |
|
| 35 |
</LinearLayout> |
|
| src/main/res/values/strings.xml | ||
|---|---|---|
| 17 | 17 |
<string name="ok">OK</string> |
| 18 | 18 |
<string name="yes">YES</string> |
| 19 | 19 |
<string name="no">NO</string> |
| 20 |
<string name="you">YOU</string> |
|
| 20 | 21 |
<string name="ready">Ready?</string> |
| 21 | 22 |
<string name="sizechange_effect">Size Change Effect</string> |
| 22 | 23 |
<string name="solve_effect">Solve Effect</string> |
| ... | ... | |
| 24 | 25 |
<string name="win_effect">Win Effect</string> |
| 25 | 26 |
<string name="duration">Duration:</string> |
| 26 | 27 |
<string name="type">Type:</string> |
| 28 |
<string name="choose_name">Choose a Name</string> |
|
| 29 |
<string name="name_taken">Name Taken</string> |
|
| 30 |
<string name="new_name">Before your first submit, you need to choose a name:</string> |
|
| 31 |
<string name="new_name_try_again">The name you have chosen, %s, is already taken. Try again:</string> |
|
| 27 | 32 |
<string name="downloading">Downloading…</string> |
| 28 | 33 |
<string name="submitting">Submitting…</string> |
| 29 | 34 |
<string name="credits1">Open Source app developed using the Distorted graphics library. </string> |
Also available in: Unified diff
Implement a new Dialog, SetName.