Revision 96e67000
Added by Leszek Koltunski about 1 year ago
src/main/java/org/distorted/dialogs/RubikDialogPattern.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.patternui.PatternActivity; |
|
25 |
import org.distorted.patternui.ScreenList; |
|
26 |
import org.distorted.patternui.ScreenPattern; |
|
27 |
|
|
28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
|
|
30 |
public class RubikDialogPattern extends RubikDialogAbstract |
|
31 |
{ |
|
32 |
private ExpandableListView mListView; |
|
33 |
private int mPatternOrdinal, mPos; |
|
34 |
private int mExpandedGroup; |
|
35 |
|
|
36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
37 |
|
|
38 |
@Override |
|
39 |
public void onResume() |
|
40 |
{ |
|
41 |
super.onResume(); |
|
42 |
|
|
43 |
Window window = getDialog().getWindow(); |
|
44 |
|
|
45 |
if( window!=null ) |
|
46 |
{ |
|
47 |
WindowManager.LayoutParams params = window.getAttributes(); |
|
48 |
params.width = (int)Math.min( mHeight*0.65f,mWidth*0.98f ); |
|
49 |
//params.height = (int)Math.min( mHeight*0.80f,mWidth*1.30f ); |
|
50 |
window.setAttributes(params); |
|
51 |
} |
|
52 |
} |
|
53 |
|
|
54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
55 |
|
|
56 |
public int getResource() { return R.layout.dialog_pattern_single; } |
|
57 |
public int getTitleResource() { return R.string.choose_pattern; } |
|
58 |
public boolean hasArgument() { return true; } |
|
59 |
public int getPositive() { return -1; } |
|
60 |
public int getNegative() { return -1; } |
|
61 |
public void positiveAction() { } |
|
62 |
public void negativeAction() { } |
|
63 |
|
|
64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 |
|
|
66 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
67 |
{ |
|
68 |
int objectOrdinal = Integer.parseInt(mArgument); |
|
69 |
|
|
70 |
if( objectOrdinal<0 ) |
|
71 |
{ |
|
72 |
android.util.Log.e("D", "object "+mArgument+" not found"); |
|
73 |
return; |
|
74 |
} |
|
75 |
|
|
76 |
mPatternOrdinal = RubikPatternList.getOrdinal(objectOrdinal); |
|
77 |
|
|
78 |
if( mPatternOrdinal<0 ) |
|
79 |
{ |
|
80 |
android.util.Log.e("D", "patterns for object "+mArgument+" not found"); |
|
81 |
return; |
|
82 |
} |
|
83 |
|
|
84 |
android.util.Log.e("D", "prepareBody: object "+mArgument); |
|
85 |
|
|
86 |
final PatternActivity pact = (PatternActivity)getContext(); |
|
87 |
int width = pact!=null ? pact.getScreenWidthInPixels() : 100; |
|
88 |
final ObjectControl control = pact!=null ? pact.getControl() : null; |
|
89 |
|
|
90 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
91 |
mExpandedGroup = pattern.recallExpanded(mPatternOrdinal); |
|
92 |
|
|
93 |
mListView = view.findViewById(R.id.patternListView); |
|
94 |
RubikDialogPatternListAdapter listAdapter = new RubikDialogPatternListAdapter(act,mPatternOrdinal,width); |
|
95 |
mListView.setAdapter(listAdapter); |
|
96 |
|
|
97 |
if( mExpandedGroup>=0 ) mListView.expandGroup(mExpandedGroup); |
|
98 |
|
|
99 |
int visible = pattern.recallVisiblePos(mPatternOrdinal); |
|
100 |
mListView.setSelectionFromTop(visible,0); |
|
101 |
|
|
102 |
mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() |
|
103 |
{ |
|
104 |
@Override |
|
105 |
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) |
|
106 |
{ |
|
107 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
108 |
int[][] moves = pattern.reInitialize(mPatternOrdinal, groupPosition, childPosition); |
|
109 |
if( control!=null ) control.initializeObject(moves); |
|
110 |
|
|
111 |
ScreenPattern state = (ScreenPattern) ScreenList.PATT.getScreenClass(); |
|
112 |
state.setPattern(pact, mPatternOrdinal, groupPosition, childPosition); |
|
113 |
|
|
114 |
rememberState(); |
|
115 |
dismiss(); |
|
116 |
|
|
117 |
return false; |
|
118 |
} |
|
119 |
}); |
|
120 |
|
|
121 |
mListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() |
|
122 |
{ |
|
123 |
@Override |
|
124 |
public void onGroupExpand(int groupPosition) |
|
125 |
{ |
|
126 |
if(mExpandedGroup!=-1 && groupPosition!=mExpandedGroup) |
|
127 |
{ |
|
128 |
mListView.collapseGroup(mExpandedGroup); |
|
129 |
} |
|
130 |
|
|
131 |
mExpandedGroup = groupPosition; |
|
132 |
} |
|
133 |
}); |
|
134 |
} |
|
135 |
|
|
136 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
137 |
|
|
138 |
private void rememberState() |
|
139 |
{ |
|
140 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
141 |
pattern.rememberState(mPatternOrdinal,mPos,mListView.getFirstVisiblePosition(),mExpandedGroup); |
|
142 |
} |
|
143 |
|
|
144 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
145 |
|
|
146 |
public static String getDialogTag() |
|
147 |
{ |
|
148 |
return "DialogPatternSingle"; |
|
149 |
} |
|
150 |
} |
src/main/java/org/distorted/dialogs/RubikDialogPatternSingle.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.RubikObjectList; |
|
25 |
import org.distorted.patternui.PatternActivity; |
|
26 |
import org.distorted.patternui.ScreenList; |
|
27 |
import org.distorted.patternui.ScreenPattern; |
|
28 |
|
|
29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
30 |
|
|
31 |
public class RubikDialogPatternSingle extends RubikDialogAbstract |
|
32 |
{ |
|
33 |
private ExpandableListView mListView; |
|
34 |
private int mPatternOrdinal, mPos; |
|
35 |
private int mExpandedGroup; |
|
36 |
|
|
37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
38 |
|
|
39 |
@Override |
|
40 |
public void onResume() |
|
41 |
{ |
|
42 |
super.onResume(); |
|
43 |
|
|
44 |
Window window = getDialog().getWindow(); |
|
45 |
|
|
46 |
if( window!=null ) |
|
47 |
{ |
|
48 |
WindowManager.LayoutParams params = window.getAttributes(); |
|
49 |
params.width = (int)Math.min( mHeight*0.65f,mWidth*0.98f ); |
|
50 |
//params.height = (int)Math.min( mHeight*0.80f,mWidth*1.30f ); |
|
51 |
window.setAttributes(params); |
|
52 |
} |
|
53 |
} |
|
54 |
|
|
55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
56 |
|
|
57 |
public int getResource() { return R.layout.dialog_pattern_single; } |
|
58 |
public int getTitleResource() { return R.string.choose_pattern; } |
|
59 |
public boolean hasArgument() { return true; } |
|
60 |
public int getPositive() { return -1; } |
|
61 |
public int getNegative() { return -1; } |
|
62 |
public void positiveAction() { } |
|
63 |
public void negativeAction() { } |
|
64 |
|
|
65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
66 |
|
|
67 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
68 |
{ |
|
69 |
int objectOrdinal = Integer.parseInt(mArgument); |
|
70 |
|
|
71 |
if( objectOrdinal<0 ) |
|
72 |
{ |
|
73 |
android.util.Log.e("D", "object "+mArgument+" not found"); |
|
74 |
return; |
|
75 |
} |
|
76 |
|
|
77 |
mPatternOrdinal = RubikPatternList.getOrdinal(objectOrdinal); |
|
78 |
|
|
79 |
if( mPatternOrdinal<0 ) |
|
80 |
{ |
|
81 |
android.util.Log.e("D", "patterns for object "+mArgument+" not found"); |
|
82 |
return; |
|
83 |
} |
|
84 |
|
|
85 |
android.util.Log.e("D", "prepareBody: object "+mArgument); |
|
86 |
|
|
87 |
final PatternActivity pact = (PatternActivity)getContext(); |
|
88 |
int width = pact!=null ? pact.getScreenWidthInPixels() : 100; |
|
89 |
final ObjectControl control = pact!=null ? pact.getControl() : null; |
|
90 |
|
|
91 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
92 |
mExpandedGroup = pattern.recallExpanded(mPatternOrdinal); |
|
93 |
|
|
94 |
mListView = view.findViewById(R.id.patternListView); |
|
95 |
RubikDialogPatternListAdapter listAdapter = new RubikDialogPatternListAdapter(act,mPatternOrdinal,width); |
|
96 |
mListView.setAdapter(listAdapter); |
|
97 |
|
|
98 |
if( mExpandedGroup>=0 ) mListView.expandGroup(mExpandedGroup); |
|
99 |
|
|
100 |
int visible = pattern.recallVisiblePos(mPatternOrdinal); |
|
101 |
mListView.setSelectionFromTop(visible,0); |
|
102 |
|
|
103 |
mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() |
|
104 |
{ |
|
105 |
@Override |
|
106 |
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) |
|
107 |
{ |
|
108 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
109 |
int[][] moves = pattern.reInitialize(mPatternOrdinal, groupPosition, childPosition); |
|
110 |
if( control!=null ) control.initializeObject(moves); |
|
111 |
|
|
112 |
ScreenPattern state = (ScreenPattern) ScreenList.PATT.getScreenClass(); |
|
113 |
state.setPattern(pact, mPatternOrdinal, groupPosition, childPosition); |
|
114 |
|
|
115 |
rememberState(); |
|
116 |
dismiss(); |
|
117 |
|
|
118 |
return false; |
|
119 |
} |
|
120 |
}); |
|
121 |
|
|
122 |
mListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() |
|
123 |
{ |
|
124 |
@Override |
|
125 |
public void onGroupExpand(int groupPosition) |
|
126 |
{ |
|
127 |
if(mExpandedGroup!=-1 && groupPosition!=mExpandedGroup) |
|
128 |
{ |
|
129 |
mListView.collapseGroup(mExpandedGroup); |
|
130 |
} |
|
131 |
|
|
132 |
mExpandedGroup = groupPosition; |
|
133 |
} |
|
134 |
}); |
|
135 |
} |
|
136 |
|
|
137 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
138 |
|
|
139 |
private void rememberState() |
|
140 |
{ |
|
141 |
RubikPattern pattern = RubikPattern.getInstance(); |
|
142 |
pattern.rememberState(mPatternOrdinal,mPos,mListView.getFirstVisiblePosition(),mExpandedGroup); |
|
143 |
} |
|
144 |
|
|
145 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
146 |
|
|
147 |
public static String getDialogTag() |
|
148 |
{ |
|
149 |
return "DialogPatternSingle"; |
|
150 |
} |
|
151 |
} |
src/main/java/org/distorted/dialogs/RubikDialogTutorial.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 static android.view.View.inflate; |
|
13 |
|
|
14 |
import android.app.Dialog; |
|
15 |
import android.content.Context; |
|
16 |
import android.content.res.Resources; |
|
17 |
import android.util.DisplayMetrics; |
|
18 |
import android.util.TypedValue; |
|
19 |
import android.view.View; |
|
20 |
import android.view.Window; |
|
21 |
import android.view.WindowManager; |
|
22 |
import android.widget.Button; |
|
23 |
import android.widget.ImageView; |
|
24 |
import android.widget.LinearLayout; |
|
25 |
import android.widget.TextView; |
|
26 |
|
|
27 |
import androidx.fragment.app.FragmentActivity; |
|
28 |
|
|
29 |
import org.distorted.main.R; |
|
30 |
import org.distorted.objectlib.json.JsonReader; |
|
31 |
import org.distorted.objects.RubikObject; |
|
32 |
import org.distorted.objects.RubikObjectList; |
|
33 |
import org.distorted.tutorials.TutorialActivity; |
|
34 |
|
|
35 |
import java.io.InputStream; |
|
36 |
|
|
37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
38 |
|
|
39 |
public class RubikDialogTutorial extends RubikDialogAbstract |
|
40 |
{ |
|
41 |
public static final float PANE_HEIGHT= 0.06f; |
|
42 |
public static final float TEXT_SIZE = 0.41f; |
|
43 |
|
|
44 |
private Dialog mDialog; |
|
45 |
|
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
|
|
48 |
@Override |
|
49 |
public void onResume() |
|
50 |
{ |
|
51 |
super.onResume(); |
|
52 |
|
|
53 |
Window window = getDialog().getWindow(); |
|
54 |
|
|
55 |
if( window!=null ) |
|
56 |
{ |
|
57 |
WindowManager.LayoutParams params = window.getAttributes(); |
|
58 |
params.width = (int)Math.min( mHeight*0.67f,mWidth*0.98f ); |
|
59 |
//params.height = (int)Math.min( mHeight*0.85f,mWidth*1.30f ); |
|
60 |
window.setAttributes(params); |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 |
|
|
66 |
public int getResource() { return R.layout.dialog_tutorial_single; } |
|
67 |
public int getTitleResource() { return R.string.tutorials; } |
|
68 |
public boolean hasArgument() { return true; } |
|
69 |
public int getPositive() { return -1; } |
|
70 |
public int getNegative() { return -1; } |
|
71 |
public void positiveAction() { } |
|
72 |
public void negativeAction() { } |
|
73 |
|
|
74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
75 |
|
|
76 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
77 |
{ |
|
78 |
mDialog = dialog; |
|
79 |
|
|
80 |
int objectOrdinal = Integer.parseInt(mArgument); |
|
81 |
|
|
82 |
if( objectOrdinal<0 ) |
|
83 |
{ |
|
84 |
android.util.Log.e("D", "object "+mArgument+" not found"); |
|
85 |
return; |
|
86 |
} |
|
87 |
|
|
88 |
RubikObject robject = RubikObjectList.getObject(objectOrdinal); |
|
89 |
InputStream jsonStream = robject==null ? null : robject.getExtrasStream(act); |
|
90 |
String[][] tutorials=null; |
|
91 |
|
|
92 |
if( jsonStream!=null ) |
|
93 |
{ |
|
94 |
try |
|
95 |
{ |
|
96 |
JsonReader reader = new JsonReader(); |
|
97 |
reader.parseJsonTutorial(jsonStream); |
|
98 |
tutorials = reader.getTutorials(); |
|
99 |
} |
|
100 |
catch(Exception ignored) { } |
|
101 |
} |
|
102 |
|
|
103 |
if( tutorials!=null ) |
|
104 |
{ |
|
105 |
int paneSize = (int)(mHeight*PANE_HEIGHT); |
|
106 |
Resources res = act.getResources(); |
|
107 |
String packageName = act.getPackageName(); |
|
108 |
|
|
109 |
LinearLayout layout = view.findViewById(R.id.tutLayout); |
|
110 |
|
|
111 |
int colorB = getResources().getColor(R.color.light_grey); |
|
112 |
int colorT = getResources().getColor(R.color.white); |
|
113 |
|
|
114 |
int numTuts = tutorials.length; |
|
115 |
|
|
116 |
for( int t=0; t<numTuts; t++) |
|
117 |
{ |
|
118 |
String[] tutorial = tutorials[t]; |
|
119 |
|
|
120 |
String coun = tutorial[0]; |
|
121 |
String url = tutorial[1]; |
|
122 |
String desc = tutorial[2]; |
|
123 |
String auth = tutorial[3]; |
|
124 |
|
|
125 |
int countryID = res.getIdentifier(coun, "drawable", packageName); |
|
126 |
|
|
127 |
View row = createRow(act, countryID, desc, url, auth, paneSize, colorB, colorT, t==(numTuts-1) ); |
|
128 |
layout.addView(row); |
|
129 |
} |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
134 |
|
|
135 |
private View createRow(final FragmentActivity act, int countryID, final String desc, final String url, |
|
136 |
final String auth, int size, int colorB, int colorT, boolean last) |
|
137 |
{ |
|
138 |
float textSize = size*TEXT_SIZE; |
|
139 |
View row = inflate( act, R.layout.dialog_tutorial_row, null); |
|
140 |
|
|
141 |
LinearLayout layout = row.findViewById(R.id.tutorialLayout); |
|
142 |
layout.setMinimumHeight(size); |
|
143 |
|
|
144 |
Button butt = row.findViewById(R.id.tutorialButton); |
|
145 |
butt.setText(R.string.view); |
|
146 |
butt.setTextColor(colorT); |
|
147 |
butt.setBackgroundColor(colorB); |
|
148 |
butt.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
149 |
butt.setHeight(size); |
|
150 |
|
|
151 |
final TutorialActivity tact = (TutorialActivity)getContext(); |
|
152 |
|
|
153 |
butt.setOnClickListener( new View.OnClickListener() |
|
154 |
{ |
|
155 |
@Override |
|
156 |
public void onClick(View v) |
|
157 |
{ |
|
158 |
mDialog.dismiss(); |
|
159 |
if( tact!=null ) tact.loadTutorial(url); |
|
160 |
} |
|
161 |
}); |
|
162 |
|
|
163 |
ImageView image = row.findViewById(R.id.tutorialCountry); |
|
164 |
int id = countryID!=0 ? countryID : org.distorted.flags.R.drawable.unknown; |
|
165 |
image.setImageResource(id); |
|
166 |
|
|
167 |
TextView author = row.findViewById(R.id.tutorialAuthor); |
|
168 |
author.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
169 |
author.setText(auth); |
|
170 |
|
|
171 |
TextView title = row.findViewById(R.id.tutorialTitle); |
|
172 |
title.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
173 |
title.setText(desc); |
|
174 |
|
|
175 |
if( last ) |
|
176 |
{ |
|
177 |
int m = (int)convertDpToPixel(10,act); |
|
178 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT); |
|
179 |
params.bottomMargin = m; |
|
180 |
params.leftMargin = m; |
|
181 |
params.rightMargin = m; |
|
182 |
layout.setLayoutParams(params); |
|
183 |
} |
|
184 |
|
|
185 |
return row; |
|
186 |
} |
|
187 |
|
|
188 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
189 |
|
|
190 |
private static float convertDpToPixel(float dp, Context context) |
|
191 |
{ |
|
192 |
return dp*((float) context.getResources().getDisplayMetrics().densityDpi/DisplayMetrics.DENSITY_DEFAULT); |
|
193 |
} |
|
194 |
|
|
195 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
196 |
|
|
197 |
public static String getDialogTag() |
|
198 |
{ |
|
199 |
return "DialogTutorialSingle"; |
|
200 |
} |
|
201 |
} |
src/main/java/org/distorted/dialogs/RubikDialogTutorialSingle.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 static android.view.View.inflate; |
|
13 |
|
|
14 |
import android.app.Dialog; |
|
15 |
import android.content.Context; |
|
16 |
import android.content.res.Resources; |
|
17 |
import android.util.DisplayMetrics; |
|
18 |
import android.util.TypedValue; |
|
19 |
import android.view.View; |
|
20 |
import android.view.Window; |
|
21 |
import android.view.WindowManager; |
|
22 |
import android.widget.Button; |
|
23 |
import android.widget.ImageView; |
|
24 |
import android.widget.LinearLayout; |
|
25 |
import android.widget.TextView; |
|
26 |
|
|
27 |
import androidx.fragment.app.FragmentActivity; |
|
28 |
|
|
29 |
import org.distorted.main.R; |
|
30 |
import org.distorted.objectlib.json.JsonReader; |
|
31 |
import org.distorted.objects.RubikObject; |
|
32 |
import org.distorted.objects.RubikObjectList; |
|
33 |
import org.distorted.tutorials.TutorialActivity; |
|
34 |
|
|
35 |
import java.io.InputStream; |
|
36 |
|
|
37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
38 |
|
|
39 |
public class RubikDialogTutorialSingle extends RubikDialogAbstract |
|
40 |
{ |
|
41 |
public static final float PANE_HEIGHT= 0.06f; |
|
42 |
public static final float TEXT_SIZE = 0.41f; |
|
43 |
|
|
44 |
private Dialog mDialog; |
|
45 |
|
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
|
|
48 |
@Override |
|
49 |
public void onResume() |
|
50 |
{ |
|
51 |
super.onResume(); |
|
52 |
|
|
53 |
Window window = getDialog().getWindow(); |
|
54 |
|
|
55 |
if( window!=null ) |
|
56 |
{ |
|
57 |
WindowManager.LayoutParams params = window.getAttributes(); |
|
58 |
params.width = (int)Math.min( mHeight*0.67f,mWidth*0.98f ); |
|
59 |
//params.height = (int)Math.min( mHeight*0.85f,mWidth*1.30f ); |
|
60 |
window.setAttributes(params); |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 |
|
|
66 |
public int getResource() { return R.layout.dialog_tutorial_single; } |
|
67 |
public int getTitleResource() { return R.string.tutorials; } |
|
68 |
public boolean hasArgument() { return true; } |
|
69 |
public int getPositive() { return -1; } |
|
70 |
public int getNegative() { return -1; } |
|
71 |
public void positiveAction() { } |
|
72 |
public void negativeAction() { } |
|
73 |
|
|
74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
75 |
|
|
76 |
public void prepareBody(Dialog dialog, View view, FragmentActivity act, float size) |
|
77 |
{ |
|
78 |
mDialog = dialog; |
|
79 |
|
|
80 |
int objectOrdinal = Integer.parseInt(mArgument); |
|
81 |
|
|
82 |
if( objectOrdinal<0 ) |
|
83 |
{ |
|
84 |
android.util.Log.e("D", "object "+mArgument+" not found"); |
|
85 |
return; |
|
86 |
} |
|
87 |
|
|
88 |
RubikObject robject = RubikObjectList.getObject(objectOrdinal); |
|
89 |
InputStream jsonStream = robject==null ? null : robject.getExtrasStream(act); |
|
90 |
String[][] tutorials=null; |
|
91 |
|
|
92 |
if( jsonStream!=null ) |
|
93 |
{ |
|
94 |
try |
|
95 |
{ |
|
96 |
JsonReader reader = new JsonReader(); |
|
97 |
reader.parseJsonTutorial(jsonStream); |
|
98 |
tutorials = reader.getTutorials(); |
|
99 |
} |
|
100 |
catch(Exception ignored) { } |
|
101 |
} |
|
102 |
|
|
103 |
if( tutorials!=null ) |
|
104 |
{ |
|
105 |
int paneSize = (int)(mHeight*PANE_HEIGHT); |
|
106 |
Resources res = act.getResources(); |
|
107 |
String packageName = act.getPackageName(); |
|
108 |
|
|
109 |
LinearLayout layout = view.findViewById(R.id.tutLayout); |
|
110 |
|
|
111 |
int colorB = getResources().getColor(R.color.light_grey); |
|
112 |
int colorT = getResources().getColor(R.color.white); |
|
113 |
|
|
114 |
int numTuts = tutorials.length; |
|
115 |
|
|
116 |
for( int t=0; t<numTuts; t++) |
|
117 |
{ |
|
118 |
String[] tutorial = tutorials[t]; |
|
119 |
|
|
120 |
String coun = tutorial[0]; |
|
121 |
String url = tutorial[1]; |
|
122 |
String desc = tutorial[2]; |
|
123 |
String auth = tutorial[3]; |
|
124 |
|
|
125 |
int countryID = res.getIdentifier(coun, "drawable", packageName); |
|
126 |
|
|
127 |
View row = createRow(act, countryID, desc, url, auth, paneSize, colorB, colorT, t==(numTuts-1) ); |
|
128 |
layout.addView(row); |
|
129 |
} |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
134 |
|
|
135 |
private View createRow(final FragmentActivity act, int countryID, final String desc, final String url, |
|
136 |
final String auth, int size, int colorB, int colorT, boolean last) |
|
137 |
{ |
|
138 |
float textSize = size*TEXT_SIZE; |
|
139 |
View row = inflate( act, R.layout.dialog_tutorial_row, null); |
|
140 |
|
|
141 |
LinearLayout layout = row.findViewById(R.id.tutorialLayout); |
|
142 |
layout.setMinimumHeight(size); |
|
143 |
|
|
144 |
Button butt = row.findViewById(R.id.tutorialButton); |
|
145 |
butt.setText(R.string.view); |
|
146 |
butt.setTextColor(colorT); |
|
147 |
butt.setBackgroundColor(colorB); |
|
148 |
butt.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
149 |
butt.setHeight(size); |
|
150 |
|
|
151 |
final TutorialActivity tact = (TutorialActivity)getContext(); |
|
152 |
|
|
153 |
butt.setOnClickListener( new View.OnClickListener() |
|
154 |
{ |
|
155 |
@Override |
|
156 |
public void onClick(View v) |
|
157 |
{ |
|
158 |
mDialog.dismiss(); |
|
159 |
if( tact!=null ) tact.loadTutorial(url); |
|
160 |
} |
|
161 |
}); |
|
162 |
|
|
163 |
ImageView image = row.findViewById(R.id.tutorialCountry); |
|
164 |
int id = countryID!=0 ? countryID : org.distorted.flags.R.drawable.unknown; |
|
165 |
image.setImageResource(id); |
|
166 |
|
|
167 |
TextView author = row.findViewById(R.id.tutorialAuthor); |
|
168 |
author.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
169 |
author.setText(auth); |
|
170 |
|
|
171 |
TextView title = row.findViewById(R.id.tutorialTitle); |
|
172 |
title.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
173 |
title.setText(desc); |
|
174 |
|
|
175 |
if( last ) |
|
176 |
{ |
|
177 |
int m = (int)convertDpToPixel(10,act); |
|
178 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT); |
|
179 |
params.bottomMargin = m; |
|
180 |
params.leftMargin = m; |
|
181 |
params.rightMargin = m; |
|
182 |
layout.setLayoutParams(params); |
|
183 |
} |
|
184 |
|
|
185 |
return row; |
|
186 |
} |
|
187 |
|
|
188 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
189 |
|
|
190 |
private static float convertDpToPixel(float dp, Context context) |
|
191 |
{ |
|
192 |
return dp*((float) context.getResources().getDisplayMetrics().densityDpi/DisplayMetrics.DENSITY_DEFAULT); |
|
193 |
} |
|
194 |
|
|
195 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
196 |
|
|
197 |
public static String getDialogTag() |
|
198 |
{ |
|
199 |
return "DialogTutorialSingle"; |
|
200 |
} |
|
201 |
} |
src/main/java/org/distorted/dialogs/RubikDialogUpdates.java | ||
---|---|---|
119 | 119 |
{ |
120 | 120 |
RubikUpdates.UpdateInfo info = updates.getCompletedUpdate(i); |
121 | 121 |
RubikDialogUpdateView rubikView = new RubikDialogUpdateView(); |
122 |
View pane = rubikView.createView(act,info,mFontSize,mPadding,pV,pT,pB);
|
|
122 |
View pane = rubikView.createView(act,info,mFontSize,mPadding,( (numS==0 && i==numC-1)?pL:pV),pT,pB);
|
|
123 | 123 |
mLayout.addView(pane); |
124 | 124 |
mPanes.add(rubikView); |
125 | 125 |
} |
src/main/java/org/distorted/patternui/ScreenPattern.java | ||
---|---|---|
17 | 17 |
import android.widget.LinearLayout; |
18 | 18 |
import android.widget.TextView; |
19 | 19 |
|
20 |
import org.distorted.dialogs.RubikDialogPatternSingle;
|
|
20 |
import org.distorted.dialogs.RubikDialogPattern; |
|
21 | 21 |
import org.distorted.helpers.TransparentButton; |
22 | 22 |
import org.distorted.helpers.TransparentImageButton; |
23 | 23 |
import org.distorted.main.R; |
24 | 24 |
import org.distorted.objectlib.main.ObjectControl; |
25 | 25 |
import org.distorted.objectlib.patterns.RubikPattern; |
26 |
import org.distorted.objects.RubikObjectList; |
|
27 | 26 |
|
28 | 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
29 | 28 |
|
... | ... | |
128 | 127 |
int ordinal = act.getObjectOrdinal(); |
129 | 128 |
Bundle bundle = new Bundle(); |
130 | 129 |
bundle.putString("argument", String.valueOf(ordinal) ); |
131 |
RubikDialogPatternSingle diag = new RubikDialogPatternSingle();
|
|
130 |
RubikDialogPattern diag = new RubikDialogPattern();
|
|
132 | 131 |
diag.setArguments(bundle); |
133 |
diag.show( act.getSupportFragmentManager(), RubikDialogPatternSingle.getDialogTag() );
|
|
132 |
diag.show( act.getSupportFragmentManager(), RubikDialogPattern.getDialogTag() ); |
|
134 | 133 |
} |
135 | 134 |
|
136 | 135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/tutorials/TutorialActivity.java | ||
---|---|---|
22 | 22 |
|
23 | 23 |
import androidx.appcompat.app.AppCompatActivity; |
24 | 24 |
|
25 |
import org.distorted.dialogs.RubikDialogTutorialSingle;
|
|
25 |
import org.distorted.dialogs.RubikDialogTutorial; |
|
26 | 26 |
import org.distorted.library.main.DistortedLibrary; |
27 | 27 |
|
28 | 28 |
import org.distorted.main.MainActivity; |
... | ... | |
89 | 89 |
{ |
90 | 90 |
Bundle bundle = new Bundle(); |
91 | 91 |
bundle.putString("argument", String.valueOf(mObjectOrdinal) ); |
92 |
RubikDialogTutorialSingle diag = new RubikDialogTutorialSingle();
|
|
92 |
RubikDialogTutorial diag = new RubikDialogTutorial();
|
|
93 | 93 |
diag.setArguments(bundle); |
94 |
diag.show( getSupportFragmentManager(), RubikDialogTutorialSingle.getDialogTag() );
|
|
94 |
diag.show( getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() ); |
|
95 | 95 |
} |
96 | 96 |
|
97 | 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
minor improvement for the Updates Dialog