Revision 8477cf44
Added by Leszek Koltunski 8 days ago
src/main/java/org/distorted/bandaged/BandagedActivity.java | ||
---|---|---|
21 | 21 |
import android.view.ViewGroup; |
22 | 22 |
import android.widget.LinearLayout; |
23 | 23 |
|
24 |
import org.distorted.dialogs.RubikDialogError;
|
|
25 |
import org.distorted.dialogs.RubikDialogMessage;
|
|
24 |
import org.distorted.dialogs.DialogError; |
|
25 |
import org.distorted.dialogs.DialogMessage; |
|
26 | 26 |
import org.distorted.external.RubikFiles; |
27 | 27 |
import org.distorted.helpers.BaseActivity; |
28 | 28 |
import org.distorted.library.main.DistortedLibrary; |
... | ... | |
156 | 156 |
|
157 | 157 |
void OpenGLError() |
158 | 158 |
{ |
159 |
RubikDialogError errDiag = new RubikDialogError();
|
|
159 |
DialogError errDiag = new DialogError();
|
|
160 | 160 |
errDiag.show(getSupportFragmentManager(), null); |
161 | 161 |
} |
162 | 162 |
|
... | ... | |
184 | 184 |
{ |
185 | 185 |
Bundle bundle = new Bundle(); |
186 | 186 |
bundle.putString("argument", getString(R.string.bandage_message) ); |
187 |
RubikDialogMessage diag = new RubikDialogMessage();
|
|
187 |
DialogMessage diag = new DialogMessage();
|
|
188 | 188 |
diag.setArguments(bundle); |
189 |
diag.show( getSupportFragmentManager(), RubikDialogMessage.getDialogTag() );
|
|
189 |
diag.show( getSupportFragmentManager(), DialogMessage.getDialogTag());
|
|
190 | 190 |
} |
191 | 191 |
} |
192 | 192 |
|
src/main/java/org/distorted/bandaged/BandagedObjectView.java | ||
---|---|---|
14 | 14 |
import android.view.View; |
15 | 15 |
import android.widget.LinearLayout; |
16 | 16 |
|
17 |
import org.distorted.dialogs.RubikDialogBandagedDelete;
|
|
17 |
import org.distorted.dialogs.DialogBandagedDelete; |
|
18 | 18 |
import org.distorted.helpers.TransparentButton; |
19 | 19 |
import org.distorted.helpers.TransparentImageButton; |
20 | 20 |
import org.distorted.main.R; |
... | ... | |
71 | 71 |
{ |
72 | 72 |
Bundle bundle = new Bundle(); |
73 | 73 |
bundle.putString("argument", mName ); |
74 |
RubikDialogBandagedDelete dialog = new RubikDialogBandagedDelete();
|
|
74 |
DialogBandagedDelete dialog = new DialogBandagedDelete();
|
|
75 | 75 |
dialog.setArguments(bundle); |
76 |
dialog.show( act.getSupportFragmentManager(), RubikDialogBandagedDelete.getDialogTag() );
|
|
76 |
dialog.show( act.getSupportFragmentManager(), DialogBandagedDelete.getDialogTag());
|
|
77 | 77 |
} |
78 | 78 |
}); |
79 | 79 |
} |
src/main/java/org/distorted/bandaged/BandagedRenderer.java | ||
---|---|---|
45 | 45 |
import org.distorted.objectlib.json.JsonWriter; |
46 | 46 |
import org.distorted.objectlib.main.ObjectControl; |
47 | 47 |
import org.distorted.objectlib.main.TwistyObject; |
48 |
import org.distorted.dialogs.RubikDialogBandagedSave;
|
|
48 |
import org.distorted.dialogs.DialogBandagedSave; |
|
49 | 49 |
|
50 | 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
51 | 51 |
|
... | ... | |
456 | 456 |
public void displaySavingDialog() |
457 | 457 |
{ |
458 | 458 |
BandagedActivity act = (BandagedActivity)mView.getContext(); |
459 |
RubikDialogBandagedSave saveDiag = new RubikDialogBandagedSave();
|
|
459 |
DialogBandagedSave saveDiag = new DialogBandagedSave();
|
|
460 | 460 |
saveDiag.show(act.getSupportFragmentManager(), null); |
461 | 461 |
} |
462 | 462 |
|
src/main/java/org/distorted/bandaged/BandagedScreen.java | ||
---|---|---|
237 | 237 |
|
238 | 238 |
private void addObjects(BandagedActivity act, String objectString) |
239 | 239 |
{ |
240 |
if( objectString.length()>0 )
|
|
240 |
if( !objectString.isEmpty() )
|
|
241 | 241 |
{ |
242 | 242 |
String[] objects = objectString.split(" "); |
243 | 243 |
RubikFiles files = RubikFiles.getInstance(); |
src/main/java/org/distorted/config/ConfigActivity.java | ||
---|---|---|
12 | 12 |
import android.os.Bundle; |
13 | 13 |
import android.content.SharedPreferences; |
14 | 14 |
|
15 |
import org.distorted.dialogs.RubikDialogError;
|
|
16 |
import org.distorted.dialogs.RubikDialogMessage;
|
|
15 |
import org.distorted.dialogs.DialogError; |
|
16 |
import org.distorted.dialogs.DialogMessage; |
|
17 | 17 |
import org.distorted.helpers.BaseActivity; |
18 | 18 |
import org.distorted.library.main.DistortedLibrary; |
19 | 19 |
import org.distorted.main.R; |
... | ... | |
130 | 130 |
|
131 | 131 |
void OpenGLError() |
132 | 132 |
{ |
133 |
RubikDialogError errDiag = new RubikDialogError();
|
|
133 |
DialogError errDiag = new DialogError();
|
|
134 | 134 |
errDiag.show(getSupportFragmentManager(), null); |
135 | 135 |
} |
136 | 136 |
|
... | ... | |
178 | 178 |
{ |
179 | 179 |
Bundle bundle = new Bundle(); |
180 | 180 |
bundle.putString("argument", getString(R.string.config_message) ); |
181 |
RubikDialogMessage diag = new RubikDialogMessage();
|
|
181 |
DialogMessage diag = new DialogMessage();
|
|
182 | 182 |
diag.setArguments(bundle); |
183 |
diag.show( getSupportFragmentManager(), RubikDialogMessage.getDialogTag() );
|
|
183 |
diag.show( getSupportFragmentManager(), DialogMessage.getDialogTag());
|
|
184 | 184 |
} |
185 | 185 |
} |
186 | 186 |
|
src/main/java/org/distorted/dialogs/DialogAbandon.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 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.view.View; |
|
14 |
import android.widget.TextView; |
|
15 |
|
|
16 |
import androidx.fragment.app.FragmentActivity; |
|
17 |
|
|
18 |
import org.distorted.main.R; |
|
19 |
import org.distorted.playui.PlayActivity; |
|
20 |
import org.distorted.playui.ScreenList; |
|
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
|
24 |
public class DialogAbandon extends DialogAbstract |
|
25 |
{ |
|
26 |
public int getResource() { return R.layout.dialog_message; } |
|
27 |
public int getTitleResource() { return -1; } |
|
28 |
public boolean hasArgument() { return false; } |
|
29 |
public int getPositive() { return R.string.yes; } |
|
30 |
public int getNegative() { return R.string.no; } |
|
31 |
public void negativeAction() { } |
|
32 |
|
|
33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
34 |
|
|
35 |
public void positiveAction() |
|
36 |
{ |
|
37 |
final PlayActivity act = (PlayActivity)getContext(); |
|
38 |
ScreenList.goBack(act); |
|
39 |
} |
|
40 |
|
|
41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
42 |
|
|
43 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
44 |
{ |
|
45 |
TextView mess = view.findViewById(R.id.dialog_message); |
|
46 |
mess.setText(R.string.abandon_solve); |
|
47 |
} |
|
48 |
} |
src/main/java/org/distorted/dialogs/DialogAbout.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.Activity; |
|
13 |
import android.app.Dialog; |
|
14 |
import android.content.Intent; |
|
15 |
import android.content.pm.PackageInfo; |
|
16 |
import android.content.pm.PackageManager; |
|
17 |
import android.content.res.Resources; |
|
18 |
import android.net.Uri; |
|
19 |
import android.util.TypedValue; |
|
20 |
import android.view.View; |
|
21 |
import android.view.Window; |
|
22 |
import android.view.WindowManager; |
|
23 |
import android.widget.LinearLayout; |
|
24 |
import android.widget.TextView; |
|
25 |
|
|
26 |
import androidx.fragment.app.FragmentActivity; |
|
27 |
|
|
28 |
import org.distorted.main.BuildConfig; |
|
29 |
import org.distorted.main.R; |
|
30 |
|
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
|
33 |
public class DialogAbout extends DialogAbstract |
|
34 |
{ |
|
35 |
private static final String WHATS_NEW = |
|
36 |
"1. Fix for 4x4 Penrose - now it correctly detects all solved states.\n" + |
|
37 |
"2. Sorry for lack of activity lately - I've been busy with private stuff. Now I'm resuming development! \n\nNext: algorithmic solvers"; |
|
38 |
|
|
39 |
private static final String WHATS_COMING = |
|
40 |
"1. Algorithmic solvers. (sub-optimal solvers for larger puzzles such as the 4x4)\n" + |
|
41 |
"2. Support for sticker modes (Tartan Cube, Shepherd's Cube, etc).\n" + |
|
42 |
"3. iOS version (no time for this, anyone can help? Code is open-source)\n" + |
|
43 |
"4. More objects:\n - Ghost Cubes\n - more Mixups\n - more Barrels\n"; |
|
44 |
|
|
45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
|
|
47 |
@Override |
|
48 |
public void onResume() |
|
49 |
{ |
|
50 |
super.onResume(); |
|
51 |
|
|
52 |
Window window = getDialog().getWindow(); |
|
53 |
|
|
54 |
if( window!=null ) |
|
55 |
{ |
|
56 |
WindowManager.LayoutParams params = window.getAttributes(); |
|
57 |
params.width = (int)Math.min( mHeight*0.60f,mWidth*0.90f ); |
|
58 |
window.setAttributes(params); |
|
59 |
} |
|
60 |
} |
|
61 |
|
|
62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
63 |
|
|
64 |
public int getResource() { return R.layout.dialog_about; } |
|
65 |
public int getTitleResource() { return PARAMETRIC_TITLE; } |
|
66 |
public boolean hasArgument() { return true; } |
|
67 |
public int getPositive() { return R.string.ok; } |
|
68 |
public int getNegative() { return -1; } |
|
69 |
public void positiveAction() { } |
|
70 |
public void negativeAction() { } |
|
71 |
|
|
72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
73 |
|
|
74 |
private String findCurrentVersion(Activity act) |
|
75 |
{ |
|
76 |
String version; |
|
77 |
try |
|
78 |
{ |
|
79 |
PackageInfo pInfo = act.getPackageManager().getPackageInfo( act.getPackageName(), 0); |
|
80 |
version= pInfo.versionName; |
|
81 |
} |
|
82 |
catch (PackageManager.NameNotFoundException e) |
|
83 |
{ |
|
84 |
version= "unknown"; |
|
85 |
} |
|
86 |
|
|
87 |
return version; |
|
88 |
} |
|
89 |
|
|
90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
91 |
|
|
92 |
@Override |
|
93 |
String getTitleString(FragmentActivity fact) |
|
94 |
{ |
|
95 |
Resources res= getResources(); |
|
96 |
Activity act= (Activity) getContext(); |
|
97 |
String version= act!=null ? findCurrentVersion(act) : "unknown"; |
|
98 |
return res.getString(R.string.ab_placeholder,version); |
|
99 |
} |
|
100 |
|
|
101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
102 |
|
|
103 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
104 |
{ |
|
105 |
int width = (int)Math.min( mHeight*0.60f,mWidth*0.90f ); |
|
106 |
int sS= (int)(width*0.043f); |
|
107 |
int bS= (int)(width*0.060f); |
|
108 |
|
|
109 |
TextView shaV = view.findViewById(R.id.about_share_string); |
|
110 |
TextView emaV = view.findViewById(R.id.about_mail_string); |
|
111 |
TextView addV = view.findViewById(R.id.about_mail_address); |
|
112 |
|
|
113 |
TextView newV = view.findViewById(R.id.about_new_message); |
|
114 |
newV.setText(WHATS_NEW); |
|
115 |
TextView comV = view.findViewById(R.id.about_coming_message); |
|
116 |
comV.setText(WHATS_COMING); |
|
117 |
|
|
118 |
LinearLayout layoutShare = view.findViewById(R.id.about_share_layout); |
|
119 |
|
|
120 |
layoutShare.setOnClickListener(new View.OnClickListener() |
|
121 |
{ |
|
122 |
@Override |
|
123 |
public void onClick(View v) |
|
124 |
{ |
|
125 |
share(act); |
|
126 |
} |
|
127 |
}); |
|
128 |
|
|
129 |
LinearLayout layoutEmail = view.findViewById(R.id.about_email_layout); |
|
130 |
|
|
131 |
layoutEmail.setOnClickListener(new View.OnClickListener() |
|
132 |
{ |
|
133 |
@Override |
|
134 |
public void onClick(View v) |
|
135 |
{ |
|
136 |
email(act); |
|
137 |
} |
|
138 |
}); |
|
139 |
|
|
140 |
shaV.setTextSize(TypedValue.COMPLEX_UNIT_PX, bS); |
|
141 |
emaV.setTextSize(TypedValue.COMPLEX_UNIT_PX, bS); |
|
142 |
addV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS); |
|
143 |
newV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS); |
|
144 |
comV.setTextSize(TypedValue.COMPLEX_UNIT_PX, sS); |
|
145 |
} |
|
146 |
|
|
147 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
148 |
|
|
149 |
private void share(FragmentActivity act) |
|
150 |
{ |
|
151 |
Resources res = act.getResources(); |
|
152 |
String name = res.getString(R.string.app_name); |
|
153 |
|
|
154 |
Intent intent = new Intent(); |
|
155 |
intent.setAction(Intent.ACTION_SEND); |
|
156 |
intent.putExtra(Intent.EXTRA_TEXT, |
|
157 |
name+": https://play.google.com/store/apps/details?id=" + BuildConfig.APPLICATION_ID); |
|
158 |
intent.setType("text/plain"); |
|
159 |
|
|
160 |
if (intent.resolveActivity(act.getPackageManager()) != null) |
|
161 |
{ |
|
162 |
startActivity(intent); |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
167 |
|
|
168 |
private void email(FragmentActivity act) |
|
169 |
{ |
|
170 |
Resources res = act.getResources(); |
|
171 |
String[] email = { res.getString(R.string.email_address) }; |
|
172 |
String version = findCurrentVersion((Activity)act); |
|
173 |
String name = res.getString(R.string.app_name); |
|
174 |
|
|
175 |
Intent intent = new Intent(Intent.ACTION_SENDTO); |
|
176 |
intent.setData(Uri.parse("mailto:")); // only email apps should handle this |
|
177 |
intent.putExtra(Intent.EXTRA_EMAIL, email); |
|
178 |
intent.putExtra(Intent.EXTRA_SUBJECT, name+" "+version); |
|
179 |
|
|
180 |
if (intent.resolveActivity(act.getPackageManager()) != null) |
|
181 |
{ |
|
182 |
startActivity(intent); |
|
183 |
} |
|
184 |
} |
|
185 |
|
|
186 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
187 |
|
|
188 |
public static String getDialogTag() |
|
189 |
{ |
|
190 |
return "DialogAbout"; |
|
191 |
} |
|
192 |
} |
src/main/java/org/distorted/dialogs/DialogAbstract.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2023 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 |
import android.widget.TextView; |
|
22 |
|
|
23 |
import androidx.annotation.NonNull; |
|
24 |
import androidx.appcompat.app.AlertDialog; |
|
25 |
import androidx.appcompat.app.AppCompatDialogFragment; |
|
26 |
import androidx.fragment.app.FragmentActivity; |
|
27 |
|
|
28 |
import org.distorted.helpers.BaseActivity; |
|
29 |
import org.distorted.main.MainActivity; |
|
30 |
import org.distorted.main.R; |
|
31 |
|
|
32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
|
34 |
abstract public class DialogAbstract extends AppCompatDialogFragment |
|
35 |
{ |
|
36 |
static final int PARAMETRIC_TITLE = -10000; |
|
37 |
|
|
38 |
protected float mTitleSize, mButSize, mTextSize; |
|
39 |
protected int mWidth, mHeight; |
|
40 |
protected String mArgument; |
|
41 |
|
|
42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
43 |
|
|
44 |
abstract int getResource(); |
|
45 |
abstract int getTitleResource(); |
|
46 |
abstract int getPositive(); |
|
47 |
abstract int getNegative(); |
|
48 |
abstract boolean hasArgument(); |
|
49 |
abstract void positiveAction(); |
|
50 |
abstract void negativeAction(); |
|
51 |
abstract void prepareBody(Dialog dialog, View view, FragmentActivity act, float size); |
|
52 |
|
|
53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 |
|
|
55 |
String getTitleString(FragmentActivity act) |
|
56 |
{ |
|
57 |
return ""; |
|
58 |
} |
|
59 |
|
|
60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
61 |
|
|
62 |
@NonNull |
|
63 |
@Override |
|
64 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
65 |
{ |
|
66 |
FragmentActivity act = getActivity(); |
|
67 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
68 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
69 |
|
|
70 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
71 |
act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); |
|
72 |
mWidth = displaymetrics.widthPixels; |
|
73 |
mHeight = displaymetrics.heightPixels; |
|
74 |
mTitleSize= mHeight*0.032f; |
|
75 |
mButSize = mHeight*0.040f; |
|
76 |
mTextSize = mHeight*0.025f; |
|
77 |
|
|
78 |
if( hasArgument() ) |
|
79 |
{ |
|
80 |
Bundle args = getArguments(); |
|
81 |
|
|
82 |
try |
|
83 |
{ |
|
84 |
mArgument = args!=null ? args.getString("argument") : ""; |
|
85 |
} |
|
86 |
catch(Exception e) |
|
87 |
{ |
|
88 |
mArgument = ""; |
|
89 |
} |
|
90 |
} |
|
91 |
else mArgument = ""; |
|
92 |
|
|
93 |
final View view = inflater.inflate(getResource(), null); |
|
94 |
builder.setView(view); |
|
95 |
builder.setCancelable(true); |
|
96 |
|
|
97 |
int title = getTitleResource(); |
|
98 |
if( title>=0 || title==PARAMETRIC_TITLE ) |
|
99 |
{ |
|
100 |
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); |
|
101 |
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTitleSize); |
|
102 |
|
|
103 |
if( title>=0 ) |
|
104 |
{ |
|
105 |
tv.setText(title); |
|
106 |
} |
|
107 |
else |
|
108 |
{ |
|
109 |
String titleString = getTitleString(act); |
|
110 |
tv.setText(titleString); |
|
111 |
} |
|
112 |
|
|
113 |
builder.setCustomTitle(tv); |
|
114 |
} |
|
115 |
|
|
116 |
int positive = getPositive(); |
|
117 |
if( positive>=0 ) |
|
118 |
{ |
|
119 |
builder.setPositiveButton( positive, new DialogInterface.OnClickListener() |
|
120 |
{ |
|
121 |
@Override |
|
122 |
public void onClick(DialogInterface dialog, int which) |
|
123 |
{ |
|
124 |
positiveAction(); |
|
125 |
} |
|
126 |
}); |
|
127 |
} |
|
128 |
|
|
129 |
int negative = getNegative(); |
|
130 |
if( negative>=0 ) |
|
131 |
{ |
|
132 |
builder.setNegativeButton( negative, new DialogInterface.OnClickListener() |
|
133 |
{ |
|
134 |
@Override |
|
135 |
public void onClick(DialogInterface dialog, int which) |
|
136 |
{ |
|
137 |
negativeAction(); |
|
138 |
} |
|
139 |
}); |
|
140 |
} |
|
141 |
|
|
142 |
Dialog dialog = builder.create(); |
|
143 |
dialog.setCanceledOnTouchOutside(false); |
|
144 |
|
|
145 |
prepareBody(dialog,view,act,mTextSize); |
|
146 |
|
|
147 |
Window window = dialog.getWindow(); |
|
148 |
|
|
149 |
if( window!=null ) |
|
150 |
{ |
|
151 |
BaseActivity bact = (BaseActivity) act; |
|
152 |
int m = bact.getMediumColor(); |
|
153 |
window.setBackgroundDrawableResource(m); |
|
154 |
window.getDecorView().setSystemUiVisibility(MainActivity.FLAGS); |
|
155 |
} |
|
156 |
|
|
157 |
dialog.setOnShowListener(new DialogInterface.OnShowListener() |
|
158 |
{ |
|
159 |
@Override |
|
160 |
public void onShow(DialogInterface dialog) |
|
161 |
{ |
|
162 |
if( positive>=0 ) |
|
163 |
{ |
|
164 |
Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE); |
|
165 |
btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButSize); |
|
166 |
} |
|
167 |
if( negative>=0 ) |
|
168 |
{ |
|
169 |
Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE); |
|
170 |
btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButSize); |
|
171 |
} |
|
172 |
} |
|
173 |
}); |
|
174 |
|
|
175 |
return dialog; |
|
176 |
} |
|
177 |
} |
src/main/java/org/distorted/dialogs/DialogBandagedDelete.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.util.TypedValue; |
|
14 |
import android.view.View; |
|
15 |
import android.widget.TextView; |
|
16 |
|
|
17 |
import androidx.fragment.app.FragmentActivity; |
|
18 |
|
|
19 |
import org.distorted.bandaged.BandagedActivity; |
|
20 |
import org.distorted.main.R; |
|
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
|
24 |
public class DialogBandagedDelete extends DialogAbstract |
|
25 |
{ |
|
26 |
public int getResource() { return R.layout.dialog_delete_object; } |
|
27 |
public int getTitleResource() { return R.string.delete_object; } |
|
28 |
public boolean hasArgument() { return true; } |
|
29 |
public int getPositive() { return R.string.yes; } |
|
30 |
public int getNegative() { return R.string.no; } |
|
31 |
public void negativeAction() { } |
|
32 |
|
|
33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
34 |
|
|
35 |
public void positiveAction() |
|
36 |
{ |
|
37 |
BandagedActivity bact = (BandagedActivity)getContext(); |
|
38 |
if( bact!=null ) bact.deleteObject(mArgument); |
|
39 |
} |
|
40 |
|
|
41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
42 |
|
|
43 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
44 |
{ |
|
45 |
TextView save = view.findViewById(R.id.delete_object_text); |
|
46 |
save.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
47 |
} |
|
48 |
|
|
49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
50 |
|
|
51 |
public static String getDialogTag() |
|
52 |
{ |
|
53 |
return "DialogBandagedDelete"; |
|
54 |
} |
|
55 |
} |
src/main/java/org/distorted/dialogs/DialogBandagedSave.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.util.TypedValue; |
|
14 |
import android.view.View; |
|
15 |
import android.widget.TextView; |
|
16 |
|
|
17 |
import androidx.fragment.app.FragmentActivity; |
|
18 |
|
|
19 |
import org.distorted.bandaged.BandagedActivity; |
|
20 |
import org.distorted.bandaged.BandagedRenderer; |
|
21 |
import org.distorted.main.R; |
|
22 |
|
|
23 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
24 |
|
|
25 |
public class DialogBandagedSave extends DialogAbstract |
|
26 |
{ |
|
27 |
public int getResource() { return R.layout.dialog_save_object; } |
|
28 |
public int getTitleResource() { return R.string.save_object; } |
|
29 |
public boolean hasArgument() { return false; } |
|
30 |
public int getPositive() { return R.string.yes; } |
|
31 |
public int getNegative() { return R.string.no; } |
|
32 |
|
|
33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
34 |
|
|
35 |
public void positiveAction() |
|
36 |
{ |
|
37 |
BandagedActivity bact = (BandagedActivity)getContext(); |
|
38 |
|
|
39 |
if( bact!=null ) |
|
40 |
{ |
|
41 |
BandagedRenderer rend = bact.getRenderer(); |
|
42 |
rend.saveObject(); |
|
43 |
} |
|
44 |
} |
|
45 |
|
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
|
|
48 |
public void negativeAction() |
|
49 |
{ |
|
50 |
|
|
51 |
} |
|
52 |
|
|
53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 |
|
|
55 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
56 |
{ |
|
57 |
TextView save = view.findViewById(R.id.save_object_text); |
|
58 |
save.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
59 |
} |
|
60 |
} |
src/main/java/org/distorted/dialogs/DialogCreatorView.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2023 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.util.TypedValue; |
|
13 |
import android.view.View; |
|
14 |
import android.widget.Button; |
|
15 |
import android.widget.ImageView; |
|
16 |
import android.widget.LinearLayout; |
|
17 |
import android.widget.TextView; |
|
18 |
|
|
19 |
import org.distorted.main.MainActivity; |
|
20 |
import org.distorted.main.R; |
|
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
|
24 |
public class DialogCreatorView |
|
25 |
{ |
|
26 |
private final View mView; |
|
27 |
|
|
28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
|
|
30 |
public DialogCreatorView(final MainActivity act, final DialogCreators dialog, |
|
31 |
final int index, int icon, int title, int desc, int padding, int fontSize, |
|
32 |
LinearLayout.LayoutParams pView, LinearLayout.LayoutParams pText, LinearLayout.LayoutParams pButt) |
|
33 |
{ |
|
34 |
mView = act.getLayoutInflater().inflate(R.layout.dialog_creators_pane, null); |
|
35 |
mView.setLayoutParams(pView); |
|
36 |
mView.setPadding(padding,padding,padding,padding); |
|
37 |
|
|
38 |
TextView titleView = mView.findViewById(R.id.creators_pane_title); |
|
39 |
titleView.setText(title); |
|
40 |
TextView descView = mView.findViewById(R.id.creators_pane_description); |
|
41 |
descView.setText(desc); |
|
42 |
|
|
43 |
titleView.setLayoutParams(pText); |
|
44 |
|
|
45 |
ImageView iconView = mView.findViewById(R.id.creators_pane_image); |
|
46 |
iconView.setImageResource(icon); |
|
47 |
|
|
48 |
Button button = mView.findViewById(R.id.creators_pane_button); |
|
49 |
|
|
50 |
button.setOnClickListener( new View.OnClickListener() |
|
51 |
{ |
|
52 |
@Override |
|
53 |
public void onClick(View v) |
|
54 |
{ |
|
55 |
dialog.dismiss(); |
|
56 |
act.switchToBandagedCreator(index); |
|
57 |
} |
|
58 |
}); |
|
59 |
|
|
60 |
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize); |
|
61 |
button.setLayoutParams(pButt); |
|
62 |
} |
|
63 |
|
|
64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 |
|
|
66 |
public View getView() |
|
67 |
{ |
|
68 |
return mView; |
|
69 |
} |
|
70 |
} |
src/main/java/org/distorted/dialogs/DialogCreators.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2023 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.view.View; |
|
14 |
import android.view.Window; |
|
15 |
import android.view.WindowManager; |
|
16 |
import android.widget.LinearLayout; |
|
17 |
import android.widget.TextView; |
|
18 |
|
|
19 |
import androidx.fragment.app.FragmentActivity; |
|
20 |
|
|
21 |
import org.distorted.main.MainActivity; |
|
22 |
import org.distorted.main.R; |
|
23 |
|
|
24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
25 |
|
|
26 |
public class DialogCreators extends DialogAbstract |
|
27 |
{ |
|
28 |
private enum BandagedObjectDescription |
|
29 |
{ |
|
30 |
CUBOID ( org.distorted.objectlib.R.drawable.cu_232, R.string.creator_cuboid_title , R.string.creator_cuboid_desc ), |
|
31 |
PYRAMINX ( org.distorted.objectlib.R.drawable.pyra_3, R.string.creator_pyraminx_title, R.string.creator_pyraminx_desc ), |
|
32 |
MEGAMINX ( org.distorted.objectlib.R.drawable.mega_3, R.string.creator_megaminx_title, R.string.creator_megaminx_desc ), |
|
33 |
OCTAHEDRON ( org.distorted.objectlib.R.drawable.diam_2, R.string.creator_octahedron_title, R.string.creator_octahedron_desc ), |
|
34 |
SKEWB ( org.distorted.objectlib.R.drawable.skew_2, R.string.creator_skewb_title, R.string.creator_skewb_desc ), |
|
35 |
; |
|
36 |
|
|
37 |
public static final int NUM_OBJECTS = values().length; |
|
38 |
private static final BandagedObjectDescription[] objects; |
|
39 |
|
|
40 |
final int mIcon, mTitle, mDescription; |
|
41 |
|
|
42 |
BandagedObjectDescription(int icon, int title, int descripton) |
|
43 |
{ |
|
44 |
mIcon = icon; |
|
45 |
mTitle = title; |
|
46 |
mDescription = descripton; |
|
47 |
} |
|
48 |
|
|
49 |
static |
|
50 |
{ |
|
51 |
int i=0; |
|
52 |
objects = new BandagedObjectDescription[NUM_OBJECTS]; |
|
53 |
for( BandagedObjectDescription object: BandagedObjectDescription.values() ) objects[i++] = object; |
|
54 |
} |
|
55 |
|
|
56 |
//////////////////////////////////////////////////////////////////////// |
|
57 |
|
|
58 |
static int getIcon(int ordinal) |
|
59 |
{ |
|
60 |
return objects[ordinal].mIcon; |
|
61 |
} |
|
62 |
|
|
63 |
//////////////////////////////////////////////////////////////////////// |
|
64 |
|
|
65 |
static int getTitle(int ordinal) |
|
66 |
{ |
|
67 |
return objects[ordinal].mTitle; |
|
68 |
} |
|
69 |
|
|
70 |
//////////////////////////////////////////////////////////////////////// |
|
71 |
|
|
72 |
static int getDescription(int ordinal) |
|
73 |
{ |
|
74 |
return objects[ordinal].mDescription; |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
79 |
|
|
80 |
@Override |
|
81 |
public void onResume() |
|
82 |
{ |
|
83 |
super.onResume(); |
|
84 |
|
|
85 |
Window window = getDialog().getWindow(); |
|
86 |
|
|
87 |
if( window!=null ) |
|
88 |
{ |
|
89 |
WindowManager.LayoutParams params = window.getAttributes(); |
|
90 |
params.width = (int)Math.min( mHeight*0.65f,mWidth*0.98f ); |
|
91 |
params.height = (int)( mHeight*0.90f); |
|
92 |
window.setAttributes(params); |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
97 |
|
|
98 |
public int getResource() { return R.layout.dialog_scrollable_panes; } |
|
99 |
public int getTitleResource() { return R.string.creators; } |
|
100 |
public boolean hasArgument() { return false; } |
|
101 |
public int getPositive() { return R.string.ok; } |
|
102 |
public int getNegative() { return -1; } |
|
103 |
public void positiveAction() { } |
|
104 |
public void negativeAction() { } |
|
105 |
public static String getDialogTag() { return "DialogCreators"; } |
|
106 |
|
|
107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
108 |
|
|
109 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
110 |
{ |
|
111 |
int margin= (int)(mHeight*0.010f); |
|
112 |
int padd = (int)(mHeight*0.010f); |
|
113 |
int font = (int)(mHeight*0.025f); |
|
114 |
|
|
115 |
LinearLayout layout= view.findViewById(R.id.dialog_scrollable_main_layout); |
|
116 |
TextView text = view.findViewById(R.id.dialog_scrollable_message); |
|
117 |
text.setVisibility(View.GONE); |
|
118 |
|
|
119 |
LinearLayout.LayoutParams pV = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT ); |
|
120 |
pV.setMargins(margin, margin, margin, 0); |
|
121 |
LinearLayout.LayoutParams pL = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT ); |
|
122 |
pL.setMargins(margin, margin, margin, margin); |
|
123 |
LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT ); |
|
124 |
pT.setMargins(0,0,0,2*margin); |
|
125 |
LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT ); |
|
126 |
pB.setMargins(0,2*margin,0,0); |
|
127 |
|
|
128 |
int num = BandagedObjectDescription.NUM_OBJECTS; |
|
129 |
MainActivity ract = (MainActivity) getContext(); |
|
130 |
|
|
131 |
for(int i=0; i<num; i++) |
|
132 |
{ |
|
133 |
int icon = BandagedObjectDescription.getIcon(i); |
|
134 |
int title = BandagedObjectDescription.getTitle(i); |
|
135 |
int description = BandagedObjectDescription.getDescription(i); |
|
136 |
DialogCreatorView pane = new DialogCreatorView(ract,this,i,icon,title,description, padd, font, (i==num-1?pL:pV),pT,pB); |
|
137 |
layout.addView(pane.getView()); |
|
138 |
} |
|
139 |
} |
|
140 |
} |
src/main/java/org/distorted/dialogs/DialogError.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 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.util.TypedValue; |
|
14 |
import android.view.View; |
|
15 |
import android.widget.TextView; |
|
16 |
|
|
17 |
import androidx.fragment.app.FragmentActivity; |
|
18 |
|
|
19 |
import org.distorted.main.R; |
|
20 |
|
|
21 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
22 |
|
|
23 |
public class DialogError extends DialogAbstract |
|
24 |
{ |
|
25 |
public int getResource() { return R.layout.dialog_error; } |
|
26 |
public int getTitleResource() { return R.string.opengl_error; } |
|
27 |
public boolean hasArgument() { return false; } |
|
28 |
public int getPositive() { return R.string.ok; } |
|
29 |
public int getNegative() { return -1; } |
|
30 |
|
|
31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 |
|
|
33 |
public void positiveAction() |
|
34 |
{ |
|
35 |
final FragmentActivity act = getActivity(); |
|
36 |
if( act!=null ) act.finish(); |
|
37 |
} |
|
38 |
|
|
39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
40 |
|
|
41 |
public void negativeAction() |
|
42 |
{ |
|
43 |
|
|
44 |
} |
|
45 |
|
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
|
|
48 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
49 |
{ |
|
50 |
TextView text = view.findViewById(R.id.error_string); |
|
51 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
52 |
text.setText(R.string.opengl_error_text); |
|
53 |
} |
|
54 |
} |
src/main/java/org/distorted/dialogs/DialogExit.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2023 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.Activity; |
|
13 |
import android.app.Dialog; |
|
14 |
import android.view.View; |
|
15 |
|
|
16 |
import androidx.fragment.app.FragmentActivity; |
|
17 |
|
|
18 |
import org.distorted.main.R; |
|
19 |
|
|
20 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
21 |
|
|
22 |
public class DialogExit extends DialogAbstract |
|
23 |
{ |
|
24 |
public int getResource() { return R.layout.exit_app; } |
|
25 |
public int getTitleResource() { return -1; } |
|
26 |
public boolean hasArgument() { return false; } |
|
27 |
public int getPositive() { return R.string.yes; } |
|
28 |
public int getNegative() { return R.string.no; } |
|
29 |
public void negativeAction() { } |
|
30 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) { } |
|
31 |
|
|
32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
|
34 |
public void positiveAction() |
|
35 |
{ |
|
36 |
final Activity act = (Activity)getContext(); |
|
37 |
if( act!=null ) act.finish(); |
|
38 |
} |
|
39 |
} |
src/main/java/org/distorted/dialogs/DialogMessage.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2024 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.view.View; |
|
14 |
import android.widget.TextView; |
|
15 |
|
|
16 |
import androidx.fragment.app.FragmentActivity; |
|
17 |
|
|
18 |
import org.distorted.main.R; |
|
19 |
|
|
20 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
21 |
|
|
22 |
public class DialogMessage extends DialogAbstract |
|
23 |
{ |
|
24 |
public int getResource() { return R.layout.dialog_message; } |
|
25 |
public int getTitleResource() { return -1; } |
|
26 |
public boolean hasArgument() { return true; } |
|
27 |
public int getPositive() { return R.string.ok; } |
|
28 |
public int getNegative() { return -1; } |
|
29 |
public void negativeAction() { } |
|
30 |
public void positiveAction() { } |
|
31 |
|
|
32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
|
34 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
35 |
{ |
|
36 |
TextView mess = view.findViewById(R.id.dialog_message); |
|
37 |
mess.setText(mArgument); |
|
38 |
} |
|
39 |
|
|
40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
41 |
|
|
42 |
public static String getDialogTag() |
|
43 |
{ |
|
44 |
return "DialogBandageMessage"; |
|
45 |
} |
|
46 |
} |
src/main/java/org/distorted/dialogs/DialogNewRecord.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 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.os.Bundle; |
|
14 |
import androidx.fragment.app.FragmentActivity; |
|
15 |
|
|
16 |
import android.util.TypedValue; |
|
17 |
import android.view.View; |
|
18 |
import android.widget.TextView; |
|
19 |
|
|
20 |
import org.distorted.main.R; |
|
21 |
import org.distorted.external.RubikScores; |
|
22 |
import org.distorted.playui.PlayActivity; |
|
23 |
|
|
24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
25 |
|
|
26 |
public class DialogNewRecord extends DialogAbstract |
|
27 |
{ |
|
28 |
public int getResource() { return R.layout.dialog_new_record; } |
|
29 |
public int getTitleResource() { return R.string.new_record; } |
|
30 |
public boolean hasArgument() { return true; } |
|
31 |
public int getPositive() { return R.string.yes; } |
|
32 |
public int getNegative() { return R.string.no; } |
|
33 |
|
|
34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
35 |
|
|
36 |
public void positiveAction() |
|
37 |
{ |
|
38 |
RubikScores scores = RubikScores.getInstance(); |
|
39 |
String name = scores.getName(); |
|
40 |
Bundle bundle = new Bundle(); |
|
41 |
PlayActivity act = (PlayActivity)getActivity(); |
|
42 |
|
|
43 |
if( act!=null ) |
|
44 |
{ |
|
45 |
if(name.length()>0) |
|
46 |
{ |
|
47 |
bundle.putString("argument", "true"); |
|
48 |
DialogScores scoresDiag = new DialogScores(); |
|
49 |
scoresDiag.setArguments(bundle); |
|
50 |
scoresDiag.show(act.getSupportFragmentManager(), null); |
|
51 |
} |
|
52 |
else |
|
53 |
{ |
|
54 |
bundle.putString("argument", name); |
|
55 |
DialogSetName nameDiag = new DialogSetName(); |
|
56 |
nameDiag.setArguments(bundle); |
|
57 |
nameDiag.show(act.getSupportFragmentManager(), null); |
|
58 |
} |
|
59 |
} |
|
60 |
} |
|
61 |
|
|
62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
63 |
|
|
64 |
public void negativeAction() |
|
65 |
{ |
|
66 |
PlayActivity act = (PlayActivity)getActivity(); |
|
67 |
if( act!=null ) act.finish(); |
|
68 |
} |
|
69 |
|
|
70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
71 |
|
|
72 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
73 |
{ |
|
74 |
TextView text = view.findViewById(R.id.new_record_time); |
|
75 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
76 |
text.setText(mArgument); |
|
77 |
TextView submit = view.findViewById(R.id.new_record_submit); |
|
78 |
submit.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
79 |
} |
|
80 |
|
|
81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 |
|
|
83 |
public static String getDialogTag() |
|
84 |
{ |
|
85 |
return "DialogNewRecord"; |
|
86 |
} |
|
87 |
} |
src/main/java/org/distorted/dialogs/DialogPattern.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2023 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.view.View; |
|
14 |
import android.view.Window; |
|
15 |
import android.view.WindowManager; |
|
16 |
import android.widget.ExpandableListView; |
|
17 |
|
|
18 |
import androidx.fragment.app.FragmentActivity; |
|
19 |
|
|
20 |
import org.distorted.main.R; |
|
21 |
import org.distorted.objectlib.main.ObjectControl; |
|
22 |
import org.distorted.objectlib.patterns.RubikPattern; |
|
23 |
import org.distorted.objectlib.patterns.RubikPatternList; |
|
24 |
import org.distorted.objects.RubikObject; |
|
25 |
import org.distorted.objects.RubikObjectList; |
|
26 |
import org.distorted.patternui.PatternActivity; |
|
27 |
import org.distorted.patternui.ScreenList; |
|
28 |
import org.distorted.patternui.ScreenPattern; |
|
29 |
|
|
30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
31 |
|
|
32 |
public class DialogPattern extends DialogAbstract |
|
33 |
{ |
|
34 |
private ExpandableListView mListView; |
|
35 |
private int mPatternOrdinal, mPos; |
|
36 |
private int mExpandedGroup; |
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
@Override |
|
41 |
public void onResume() |
|
42 |
{ |
|
43 |
super.onResume(); |
|
44 |
|
|
45 |
Window window = getDialog().getWindow(); |
|
46 |
|
|
47 |
if( window!=null ) |
|
48 |
{ |
|
49 |
WindowManager.LayoutParams params = window.getAttributes(); |
|
50 |
params.width = (int)Math.min( mHeight*0.65f,mWidth*0.98f ); |
|
51 |
//params.height = (int)Math.min( mHeight*0.80f,mWidth*1.30f ); |
|
52 |
window.setAttributes(params); |
|
53 |
} |
|
54 |
} |
|
55 |
|
|
56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
57 |
|
|
58 |
public int getResource() { return R.layout.dialog_pattern_single; } |
|
59 |
public int getTitleResource() { return R.string.choose_pattern; } |
|
60 |
public boolean hasArgument() { return true; } |
|
61 |
public int getPositive() { return -1; } |
|
62 |
public int getNegative() { return -1; } |
|
63 |
public void positiveAction() { } |
|
64 |
public void negativeAction() { } |
|
65 |
|
|
66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
67 |
|
|
68 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
69 |
{ |
|
70 |
int objectOrdinal = Integer.parseInt(mArgument); |
|
71 |
|
|
72 |
if( objectOrdinal<0 ) |
|
73 |
{ |
|
74 |
android.util.Log.e("D", "object "+mArgument+" not found"); |
|
75 |
return; |
|
76 |
} |
|
77 |
|
|
78 |
RubikObject object = RubikObjectList.getObject(objectOrdinal); |
|
79 |
int objectIndex = object==null ? -1 : object.getIndex(); |
|
80 |
|
|
81 |
mPatternOrdinal = RubikPatternList.getOrdinal(objectIndex); |
|
82 |
|
|
83 |
if( mPatternOrdinal<0 ) |
|
84 |
{ |
|
85 |
android.util.Log.e("D", "patterns for object "+mArgument+" not found"); |
|
86 |
return; |
|
87 |
} |
|
88 |
|
|
89 |
android.util.Log.e("D", "prepareBody: object "+mArgument); |
|
90 |
|
|
91 |
final PatternActivity pact = (PatternActivity)getContext(); |
|
92 |
int width = pact!=null ? pact.getScreenWidthInPixels() : 100; |
|
93 |
final ObjectControl control = pact!=null ? pact.getControl() : null; |
|
94 |
|
|
95 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
96 |
mExpandedGroup = pattern.recallExpanded(mPatternOrdinal); |
|
97 |
|
|
98 |
mListView = view.findViewById(R.id.patternListView); |
|
99 |
DialogPatternListAdapter listAdapter = new DialogPatternListAdapter(act,mPatternOrdinal,width); |
|
100 |
mListView.setAdapter(listAdapter); |
|
101 |
|
|
102 |
if( mExpandedGroup>=0 ) mListView.expandGroup(mExpandedGroup); |
|
103 |
|
|
104 |
int visible = pattern.recallVisiblePos(mPatternOrdinal); |
|
105 |
mListView.setSelectionFromTop(visible,0); |
|
106 |
|
|
107 |
mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() |
|
108 |
{ |
|
109 |
@Override |
|
110 |
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) |
|
111 |
{ |
|
112 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
113 |
int[][] moves = pattern.reInitialize(mPatternOrdinal, groupPosition, childPosition); |
|
114 |
if( control!=null ) control.initializeObject(moves); |
|
115 |
|
|
116 |
ScreenPattern state = (ScreenPattern) ScreenList.PATT.getScreenClass(); |
|
117 |
state.setPattern(pact, mPatternOrdinal, groupPosition, childPosition); |
|
118 |
|
|
119 |
rememberState(); |
|
120 |
dismiss(); |
|
121 |
|
|
122 |
return false; |
|
123 |
} |
|
124 |
}); |
|
125 |
|
|
126 |
mListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() |
|
127 |
{ |
|
128 |
@Override |
|
129 |
public void onGroupExpand(int groupPosition) |
|
130 |
{ |
|
131 |
if(mExpandedGroup!=-1 && groupPosition!=mExpandedGroup) |
|
132 |
{ |
|
133 |
mListView.collapseGroup(mExpandedGroup); |
|
134 |
} |
|
135 |
|
|
136 |
mExpandedGroup = groupPosition; |
|
137 |
} |
|
138 |
}); |
|
139 |
} |
|
140 |
|
|
141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
142 |
|
|
143 |
private void rememberState() |
|
144 |
{ |
|
145 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
146 |
pattern.rememberState(mPatternOrdinal,mPos,mListView.getFirstVisiblePosition(),mExpandedGroup); |
|
147 |
} |
|
148 |
|
|
149 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
150 |
|
|
151 |
public static String getDialogTag() |
|
152 |
{ |
|
153 |
return "DialogPatternSingle"; |
|
154 |
} |
|
155 |
} |
src/main/java/org/distorted/dialogs/DialogPatternListAdapter.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2023 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 |
|
|
11 |
package org.distorted.dialogs; |
|
12 |
|
|
13 |
import android.content.Context; |
|
14 |
import android.util.TypedValue; |
|
15 |
import android.view.LayoutInflater; |
|
16 |
import android.view.View; |
|
17 |
import android.view.ViewGroup; |
|
18 |
import android.widget.BaseExpandableListAdapter; |
|
19 |
import android.widget.TextView; |
|
20 |
import org.distorted.objectlib.patterns.RubikPattern; |
|
21 |
import org.distorted.main.R; |
|
22 |
|
|
23 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
24 |
|
|
25 |
class DialogPatternListAdapter extends BaseExpandableListAdapter |
|
26 |
{ |
|
27 |
private static final float PATTERN_CHILD_TEXT = 0.038f; |
|
28 |
private static final float PATTERN_GROUP_TEXT = 0.060f; |
|
29 |
private final Context mContext; |
|
30 |
private final int mTab, mWidth; |
|
31 |
|
|
32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
33 |
|
|
34 |
public DialogPatternListAdapter(Context context, int tab, int width) |
|
35 |
{ |
|
36 |
mContext = context; |
|
37 |
mTab = tab; |
|
38 |
mWidth = width; |
|
39 |
} |
|
40 |
|
|
41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
42 |
|
|
43 |
@Override |
|
44 |
public Object getChild(int groupPosition, int childPosition) |
|
45 |
{ |
|
46 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
47 |
return pattern.getPatternName(mTab,groupPosition,childPosition); |
|
48 |
} |
|
49 |
|
|
50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
51 |
|
|
52 |
@Override |
|
53 |
public long getChildId(int groupPosition, int childPosition) |
|
54 |
{ |
|
55 |
return childPosition; |
|
56 |
} |
|
57 |
|
|
58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
59 |
|
|
60 |
@Override |
|
61 |
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent) |
|
62 |
{ |
|
63 |
String childName = (String) getChild(groupPosition, childPosition); |
|
64 |
|
|
65 |
if (view == null) |
|
66 |
{ |
|
67 |
LayoutInflater infalInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
|
68 |
view = infalInflater.inflate(R.layout.dialog_pattern_child_item, null); |
|
69 |
} |
|
70 |
|
|
71 |
int size = (int)(mWidth*PATTERN_CHILD_TEXT); |
|
72 |
TextView childItem = view.findViewById(R.id.child); |
|
73 |
childItem.setText(childName); |
|
74 |
childItem.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
75 |
return view; |
|
76 |
} |
|
77 |
|
|
78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
79 |
|
|
80 |
@Override |
|
81 |
public int getChildrenCount(int groupPosition) |
|
82 |
{ |
|
83 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
84 |
return pattern.getNumPatterns(mTab,groupPosition); |
|
85 |
} |
|
86 |
|
|
87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
88 |
|
|
89 |
@Override |
|
90 |
public Object getGroup(int groupPosition) |
|
91 |
{ |
|
92 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
93 |
return pattern.getCategoryName(mTab,groupPosition); |
|
94 |
} |
|
95 |
|
|
96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
97 |
|
|
98 |
@Override |
|
99 |
public int getGroupCount() |
|
100 |
{ |
|
101 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
102 |
return pattern.getNumCategories(mTab); |
|
103 |
} |
|
104 |
|
|
105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
106 |
|
|
107 |
@Override |
|
108 |
public long getGroupId(int groupPosition) |
|
109 |
{ |
|
110 |
return groupPosition; |
|
111 |
} |
|
112 |
|
|
113 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
114 |
|
|
115 |
@Override |
|
116 |
public View getGroupView(int groupPosition, boolean isLastChild, View view, ViewGroup parent) |
|
117 |
{ |
|
118 |
String groupName = (String) getGroup(groupPosition); |
|
119 |
|
|
120 |
if (view == null) |
|
121 |
{ |
|
122 |
LayoutInflater inf = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
|
123 |
view = inf.inflate(R.layout.dialog_pattern_group_item, null); |
|
124 |
} |
|
125 |
|
|
126 |
int size = (int)(mWidth*PATTERN_GROUP_TEXT); |
|
127 |
TextView heading = view.findViewById(R.id.heading); |
|
128 |
heading.setText(groupName); |
|
129 |
heading.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
130 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
131 |
int numPatterns = pattern.getNumPatterns(mTab,groupPosition); |
|
132 |
TextView counter = view.findViewById(R.id.counter); |
|
133 |
counter.setText(String.format("%d", numPatterns)); |
|
134 |
counter.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); |
|
135 |
return view; |
|
136 |
} |
|
137 |
|
|
138 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
139 |
|
|
140 |
@Override |
|
141 |
public boolean hasStableIds() |
|
142 |
{ |
|
143 |
return true; |
|
144 |
} |
|
145 |
|
|
146 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
147 |
|
|
148 |
@Override |
|
149 |
public boolean isChildSelectable(int groupPosition, int childPosition) |
|
150 |
{ |
|
151 |
return true; |
|
152 |
} |
|
153 |
} |
src/main/java/org/distorted/dialogs/DialogScores.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
Also available in: Unified diff
rename dialogs