Revision 45831b78
Added by Leszek Koltunski almost 2 years ago
src/main/java/org/distorted/dialogs/RubikDialogExplainStars.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2022 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 android.util.DisplayMetrics; |
|
16 |
import android.util.TypedValue; |
|
17 |
import android.view.LayoutInflater; |
|
18 |
import android.view.View; |
|
19 |
import android.view.Window; |
|
20 |
import android.widget.Button; |
|
21 |
|
|
22 |
import androidx.annotation.NonNull; |
|
23 |
import androidx.appcompat.app.AlertDialog; |
|
24 |
import androidx.appcompat.app.AppCompatDialogFragment; |
|
25 |
import androidx.fragment.app.FragmentActivity; |
|
26 |
|
|
27 |
import org.distorted.main.R; |
|
28 |
import org.distorted.main.RubikActivity; |
|
29 |
|
|
30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
31 |
|
|
32 |
public class RubikDialogExplainStars extends AppCompatDialogFragment |
|
33 |
{ |
|
34 |
@NonNull |
|
35 |
@Override |
|
36 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
37 |
{ |
|
38 |
FragmentActivity act = getActivity(); |
|
39 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
40 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
41 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
42 |
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); |
|
43 |
final float butSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE; |
|
44 |
final View view = inflater.inflate(R.layout.dialog_explain_stars, null); |
|
45 |
|
|
46 |
builder.setCancelable(true); |
|
47 |
|
|
48 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
49 |
{ |
|
50 |
@Override |
|
51 |
public void onClick(DialogInterface dialog, int which) { } |
|
52 |
}); |
|
53 |
|
|
54 |
builder.setView(view); |
|
55 |
|
|
56 |
final Dialog dialog = builder.create(); |
|
57 |
dialog.setCanceledOnTouchOutside(false); |
|
58 |
Window window = dialog.getWindow(); |
|
59 |
|
|
60 |
if( window!=null ) |
|
61 |
{ |
|
62 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
|
63 |
} |
|
64 |
|
|
65 |
dialog.setOnShowListener(new DialogInterface.OnShowListener() |
|
66 |
{ |
|
67 |
@Override |
|
68 |
public void onShow(DialogInterface dialog) |
|
69 |
{ |
|
70 |
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE); |
|
71 |
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize); |
|
72 |
Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE); |
|
73 |
btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize); |
|
74 |
} |
|
75 |
}); |
|
76 |
|
|
77 |
return dialog; |
|
78 |
} |
|
79 |
} |
src/main/java/org/distorted/dialogs/RubikDialogStarsError.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2022 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 android.util.DisplayMetrics; |
|
16 |
import android.util.TypedValue; |
|
17 |
import android.view.LayoutInflater; |
|
18 |
import android.view.View; |
|
19 |
import android.view.Window; |
|
20 |
import android.widget.Button; |
|
21 |
|
|
22 |
import androidx.annotation.NonNull; |
|
23 |
import androidx.appcompat.app.AlertDialog; |
|
24 |
import androidx.appcompat.app.AppCompatDialogFragment; |
|
25 |
import androidx.fragment.app.FragmentActivity; |
|
26 |
|
|
27 |
import org.distorted.main.R; |
|
28 |
import org.distorted.main.RubikActivity; |
|
29 |
import org.distorted.purchase.PurchaseScreenPane; |
|
30 |
|
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
|
33 |
public class RubikDialogStarsError extends AppCompatDialogFragment |
|
34 |
{ |
|
35 |
@NonNull |
|
36 |
@Override |
|
37 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
38 |
{ |
|
39 |
FragmentActivity act = getActivity(); |
|
40 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
41 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
42 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
43 |
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); |
|
44 |
final float butSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE; |
|
45 |
final View view = inflater.inflate(R.layout.dialog_explain_stars, null); |
|
46 |
|
|
47 |
Bundle args = getArguments(); |
|
48 |
long price; |
|
49 |
|
|
50 |
try |
|
51 |
{ |
|
52 |
price = args.getInt("price"); |
|
53 |
} |
|
54 |
catch(Exception e) |
|
55 |
{ |
|
56 |
price = PurchaseScreenPane.UNLOCK_ALL_PRICE; |
|
57 |
} |
|
58 |
|
|
59 |
builder.setCancelable(true); |
|
60 |
|
|
61 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
62 |
{ |
|
63 |
@Override |
|
64 |
public void onClick(DialogInterface dialog, int which) { } |
|
65 |
}); |
|
66 |
|
|
67 |
builder.setView(view); |
|
68 |
|
|
69 |
final Dialog dialog = builder.create(); |
|
70 |
dialog.setCanceledOnTouchOutside(false); |
|
71 |
Window window = dialog.getWindow(); |
|
72 |
|
|
73 |
if( window!=null ) |
|
74 |
{ |
|
75 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
|
76 |
} |
|
77 |
|
|
78 |
dialog.setOnShowListener(new DialogInterface.OnShowListener() |
|
79 |
{ |
|
80 |
@Override |
|
81 |
public void onShow(DialogInterface dialog) |
|
82 |
{ |
|
83 |
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE); |
|
84 |
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize); |
|
85 |
Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE); |
|
86 |
btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize); |
|
87 |
} |
|
88 |
}); |
|
89 |
|
|
90 |
return dialog; |
|
91 |
} |
|
92 |
} |
src/main/java/org/distorted/dialogs/RubikDialogStarsExplain.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2022 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 android.util.DisplayMetrics; |
|
16 |
import android.util.TypedValue; |
|
17 |
import android.view.LayoutInflater; |
|
18 |
import android.view.View; |
|
19 |
import android.view.Window; |
|
20 |
import android.widget.Button; |
|
21 |
|
|
22 |
import androidx.annotation.NonNull; |
|
23 |
import androidx.appcompat.app.AlertDialog; |
|
24 |
import androidx.appcompat.app.AppCompatDialogFragment; |
|
25 |
import androidx.fragment.app.FragmentActivity; |
|
26 |
|
|
27 |
import org.distorted.main.R; |
|
28 |
import org.distorted.main.RubikActivity; |
|
29 |
|
|
30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
31 |
|
|
32 |
public class RubikDialogStarsExplain extends AppCompatDialogFragment |
|
33 |
{ |
|
34 |
@NonNull |
|
35 |
@Override |
|
36 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
37 |
{ |
|
38 |
FragmentActivity act = getActivity(); |
|
39 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
40 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
41 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
42 |
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); |
|
43 |
final float butSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE; |
|
44 |
final View view = inflater.inflate(R.layout.dialog_explain_stars, null); |
|
45 |
|
|
46 |
builder.setCancelable(true); |
|
47 |
|
|
48 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
49 |
{ |
|
50 |
@Override |
|
51 |
public void onClick(DialogInterface dialog, int which) { } |
|
52 |
}); |
|
53 |
|
|
54 |
builder.setView(view); |
|
55 |
|
|
56 |
final Dialog dialog = builder.create(); |
|
57 |
dialog.setCanceledOnTouchOutside(false); |
|
58 |
Window window = dialog.getWindow(); |
|
59 |
|
|
60 |
if( window!=null ) |
|
61 |
{ |
|
62 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
|
63 |
} |
|
64 |
|
|
65 |
dialog.setOnShowListener(new DialogInterface.OnShowListener() |
|
66 |
{ |
|
67 |
@Override |
|
68 |
public void onShow(DialogInterface dialog) |
|
69 |
{ |
|
70 |
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE); |
|
71 |
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize); |
|
72 |
Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE); |
|
73 |
btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize); |
|
74 |
} |
|
75 |
}); |
|
76 |
|
|
77 |
return dialog; |
|
78 |
} |
|
79 |
} |
src/main/java/org/distorted/dialogs/RubikDialogStarsSuccess.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2022 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 android.util.DisplayMetrics; |
|
16 |
import android.util.TypedValue; |
|
17 |
import android.view.LayoutInflater; |
|
18 |
import android.view.View; |
|
19 |
import android.view.Window; |
|
20 |
import android.widget.Button; |
|
21 |
|
|
22 |
import androidx.annotation.NonNull; |
|
23 |
import androidx.appcompat.app.AlertDialog; |
|
24 |
import androidx.appcompat.app.AppCompatDialogFragment; |
|
25 |
import androidx.fragment.app.FragmentActivity; |
|
26 |
|
|
27 |
import org.distorted.main.R; |
|
28 |
import org.distorted.main.RubikActivity; |
|
29 |
import org.distorted.purchase.PurchaseScreenPane; |
|
30 |
|
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
|
33 |
public class RubikDialogStarsSuccess extends AppCompatDialogFragment |
|
34 |
{ |
|
35 |
@NonNull |
|
36 |
@Override |
|
37 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
38 |
{ |
|
39 |
FragmentActivity act = getActivity(); |
|
40 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
41 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
42 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
43 |
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); |
|
44 |
final float butSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE; |
|
45 |
final View view = inflater.inflate(R.layout.dialog_explain_stars, null); |
|
46 |
|
|
47 |
Bundle args = getArguments(); |
|
48 |
String objectName; |
|
49 |
|
|
50 |
try |
|
51 |
{ |
|
52 |
objectName = args.getString("object"); |
|
53 |
} |
|
54 |
catch(Exception e) |
|
55 |
{ |
|
56 |
objectName = null; |
|
57 |
} |
|
58 |
|
|
59 |
builder.setCancelable(true); |
|
60 |
|
|
61 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
62 |
{ |
|
63 |
@Override |
|
64 |
public void onClick(DialogInterface dialog, int which) { } |
|
65 |
}); |
|
66 |
|
|
67 |
builder.setView(view); |
|
68 |
|
|
69 |
final Dialog dialog = builder.create(); |
|
70 |
dialog.setCanceledOnTouchOutside(false); |
|
71 |
Window window = dialog.getWindow(); |
|
72 |
|
|
73 |
if( window!=null ) |
|
74 |
{ |
|
75 |
window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS); |
|
76 |
} |
|
77 |
|
|
78 |
dialog.setOnShowListener(new DialogInterface.OnShowListener() |
|
79 |
{ |
|
80 |
@Override |
|
81 |
public void onShow(DialogInterface dialog) |
|
82 |
{ |
|
83 |
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE); |
|
84 |
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize); |
|
85 |
Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE); |
|
86 |
btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize); |
|
87 |
} |
|
88 |
}); |
|
89 |
|
|
90 |
return dialog; |
|
91 |
} |
|
92 |
} |
src/main/java/org/distorted/main/RubikActivity.java | ||
---|---|---|
35 | 35 |
|
36 | 36 |
import org.distorted.config.ConfigActivity; |
37 | 37 |
import org.distorted.bandaged.BandagedCreatorActivity; |
38 |
import org.distorted.dialogs.RubikDialogExplainStars;
|
|
38 |
import org.distorted.dialogs.RubikDialogStarsExplain;
|
|
39 | 39 |
import org.distorted.library.main.DistortedLibrary; |
40 | 40 |
|
41 | 41 |
import org.distorted.library.main.DistortedScreen; |
... | ... | |
304 | 304 |
|
305 | 305 |
private void explainStars() |
306 | 306 |
{ |
307 |
RubikDialogExplainStars staDiag = new RubikDialogExplainStars();
|
|
307 |
RubikDialogStarsExplain staDiag = new RubikDialogStarsExplain();
|
|
308 | 308 |
staDiag.show(getSupportFragmentManager(), null); |
309 | 309 |
} |
310 | 310 |
|
src/main/java/org/distorted/purchase/PurchaseScreenPane.java | ||
---|---|---|
10 | 10 |
package org.distorted.purchase; |
11 | 11 |
|
12 | 12 |
import android.graphics.drawable.Drawable; |
13 |
import android.os.Bundle; |
|
13 | 14 |
import android.util.TypedValue; |
14 | 15 |
import android.view.View; |
15 | 16 |
import android.widget.ImageButton; |
... | ... | |
19 | 20 |
|
20 | 21 |
import androidx.core.content.res.ResourcesCompat; |
21 | 22 |
|
23 |
import org.distorted.dialogs.RubikDialogStarsError; |
|
24 |
import org.distorted.external.RubikScores; |
|
22 | 25 |
import org.distorted.main.R; |
23 | 26 |
import org.distorted.objectlib.json.JsonReader; |
24 | 27 |
import org.distorted.objects.RubikObject; |
... | ... | |
30 | 33 |
|
31 | 34 |
public class PurchaseScreenPane |
32 | 35 |
{ |
33 |
private static final int UNLOCK_ALL_PRICE = 500;
|
|
36 |
public static final int UNLOCK_ALL_PRICE = 500;
|
|
34 | 37 |
|
35 | 38 |
private static final int[] IMAGES = |
36 | 39 |
{ |
... | ... | |
48 | 51 |
private RubikObject mObject; |
49 | 52 |
|
50 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
51 |
// TODO: charge the user an amount of stars |
|
52 | 54 |
|
53 |
private boolean chargeUser(RubikObject object)
|
|
55 |
private boolean chargeUser(int amount)
|
|
54 | 56 |
{ |
55 |
return true; |
|
57 |
RubikScores scores = RubikScores.getInstance(); |
|
58 |
int numStars = scores.getNumStars(); |
|
59 |
|
|
60 |
if( numStars>=amount ) |
|
61 |
{ |
|
62 |
scores.changeNumStars(-amount); |
|
63 |
return true; |
|
64 |
} |
|
65 |
|
|
66 |
return false; |
|
56 | 67 |
} |
57 | 68 |
|
58 | 69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
59 |
// TODO: charge the user an amount of stars |
|
60 | 70 |
|
61 |
private boolean chargeUser()
|
|
71 |
private void showError(PurchaseActivity act, int price)
|
|
62 | 72 |
{ |
63 |
return true; |
|
73 |
Bundle bundle = new Bundle(); |
|
74 |
bundle.putInt("price", price ); |
|
75 |
RubikDialogStarsError d = new RubikDialogStarsError(); |
|
76 |
d.setArguments(bundle); |
|
77 |
d.show(act.getSupportFragmentManager(), null); |
|
64 | 78 |
} |
65 | 79 |
|
66 | 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
67 | 81 |
|
68 |
private void oneButtonClicked() |
|
82 |
private void showSuccess(PurchaseActivity act, RubikObject object) |
|
83 |
{ |
|
84 |
Bundle bundle = new Bundle(); |
|
85 |
bundle.putString("object", object.getUpperName() ); |
|
86 |
RubikDialogStarsError d = new RubikDialogStarsError(); |
|
87 |
d.setArguments(bundle); |
|
88 |
d.show(act.getSupportFragmentManager(), null); |
|
89 |
} |
|
90 |
|
|
91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
92 |
|
|
93 |
private void oneButtonClicked(PurchaseActivity act) |
|
69 | 94 |
{ |
70 | 95 |
if( mObject!=null ) |
71 | 96 |
{ |
72 |
if( !RubikObjectList.objectAlreadyBought(mObject) && chargeUser(mObject) ) |
|
97 |
int price = mObject.getPrice(); |
|
98 |
|
|
99 |
if( chargeUser(price) ) |
|
73 | 100 |
{ |
74 |
android.util.Log.e("D", "buying "+mObject.getUpperName()); |
|
75 | 101 |
RubikObjectList.buyObject(mObject); |
102 |
showSuccess(act,mObject); |
|
103 |
} |
|
104 |
else |
|
105 |
{ |
|
106 |
showError(act,price); |
|
76 | 107 |
} |
77 | 108 |
} |
78 | 109 |
} |
79 | 110 |
|
80 | 111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
81 | 112 |
|
82 |
private void allButtonClicked() |
|
113 |
private void allButtonClicked(PurchaseActivity act)
|
|
83 | 114 |
{ |
84 |
if( !RubikObjectList.allAlreadyBought() && chargeUser() ) |
|
115 |
int price = UNLOCK_ALL_PRICE; |
|
116 |
|
|
117 |
if( chargeUser(price) ) |
|
85 | 118 |
{ |
86 | 119 |
RubikObjectList.buyAll(); |
120 |
showSuccess(act,null); |
|
121 |
} |
|
122 |
else |
|
123 |
{ |
|
124 |
showError(act,price); |
|
87 | 125 |
} |
88 | 126 |
} |
89 | 127 |
|
... | ... | |
115 | 153 |
@Override |
116 | 154 |
public void onClick(View v) |
117 | 155 |
{ |
118 |
oneButtonClicked(); |
|
156 |
oneButtonClicked(act);
|
|
119 | 157 |
} |
120 | 158 |
}); |
121 | 159 |
|
... | ... | |
124 | 162 |
@Override |
125 | 163 |
public void onClick(View v) |
126 | 164 |
{ |
127 |
allButtonClicked(); |
|
165 |
allButtonClicked(act);
|
|
128 | 166 |
} |
129 | 167 |
}); |
130 | 168 |
} |
Also available in: Unified diff
Purchase Pane: post-purchase dialogs.