Revision 211b48f2
Added by Leszek Koltunski almost 5 years ago
src/main/java/org/distorted/dialog/RubikDialogAbout.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.dialog; |
|
21 |
|
|
22 |
import android.app.Dialog; |
|
23 |
import android.content.DialogInterface; |
|
24 |
import android.os.Bundle; |
|
25 |
import android.support.annotation.NonNull; |
|
26 |
import android.support.v4.app.FragmentActivity; |
|
27 |
import android.support.v7.app.AlertDialog; |
|
28 |
import android.support.v7.app.AppCompatDialogFragment; |
|
29 |
import android.view.LayoutInflater; |
|
30 |
import android.view.View; |
|
31 |
import android.view.Window; |
|
32 |
import android.view.WindowManager; |
|
33 |
import android.widget.TextView; |
|
34 |
|
|
35 |
import org.distorted.magic.R; |
|
36 |
|
|
37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
38 |
|
|
39 |
public class RubikDialogAbout extends AppCompatDialogFragment |
|
40 |
{ |
|
41 |
@Override |
|
42 |
public void onStart() |
|
43 |
{ |
|
44 |
super.onStart(); |
|
45 |
|
|
46 |
Window window = getDialog().getWindow(); |
|
47 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
48 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
49 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
50 |
} |
|
51 |
|
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
|
|
54 |
@NonNull |
|
55 |
@Override |
|
56 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
57 |
{ |
|
58 |
FragmentActivity act = getActivity(); |
|
59 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
60 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
61 |
|
|
62 |
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); |
|
63 |
tv.setText(R.string.about); |
|
64 |
builder.setCustomTitle(tv); |
|
65 |
|
|
66 |
builder.setCancelable(true); |
|
67 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
68 |
{ |
|
69 |
@Override |
|
70 |
public void onClick(DialogInterface dialog, int which) |
|
71 |
{ |
|
72 |
|
|
73 |
} |
|
74 |
}); |
|
75 |
|
|
76 |
final View view = inflater.inflate(R.layout.dialog_about, null); |
|
77 |
TextView text = view.findViewById(R.id.about_version); |
|
78 |
text.setText(R.string.app_version); |
|
79 |
builder.setView(view); |
|
80 |
|
|
81 |
return builder.create(); |
|
82 |
} |
|
83 |
} |
src/main/java/org/distorted/dialog/RubikDialogMain.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.dialog; |
|
21 |
|
|
22 |
import android.app.Dialog; |
|
23 |
import android.os.Bundle; |
|
24 |
import android.support.annotation.NonNull; |
|
25 |
import android.support.v4.app.FragmentActivity; |
|
26 |
import android.support.v7.app.AlertDialog; |
|
27 |
import android.support.v7.app.AppCompatDialogFragment; |
|
28 |
import android.view.LayoutInflater; |
|
29 |
import android.view.View; |
|
30 |
import android.view.Window; |
|
31 |
import android.view.WindowManager; |
|
32 |
|
|
33 |
import org.distorted.magic.R; |
|
34 |
|
|
35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
36 |
|
|
37 |
public class RubikDialogMain extends AppCompatDialogFragment |
|
38 |
{ |
|
39 |
@Override |
|
40 |
public void onStart() |
|
41 |
{ |
|
42 |
super.onStart(); |
|
43 |
|
|
44 |
Window window = getDialog().getWindow(); |
|
45 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
46 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
47 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
48 |
} |
|
49 |
|
|
50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
51 |
|
|
52 |
@NonNull |
|
53 |
@Override |
|
54 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
55 |
{ |
|
56 |
FragmentActivity act = getActivity(); |
|
57 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
58 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
59 |
final View view = inflater.inflate(R.layout.dialog_main, null); |
|
60 |
builder.setView(view); |
|
61 |
|
|
62 |
return builder.create(); |
|
63 |
} |
|
64 |
|
|
65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
66 |
|
|
67 |
public static String getDialogTag() |
|
68 |
{ |
|
69 |
return "DialogMain"; |
|
70 |
} |
|
71 |
} |
src/main/java/org/distorted/dialog/RubikDialogScores.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.dialog; |
|
21 |
|
|
22 |
import android.app.Dialog; |
|
23 |
import android.content.DialogInterface; |
|
24 |
import android.os.Bundle; |
|
25 |
import android.support.annotation.NonNull; |
|
26 |
import android.support.v4.app.FragmentActivity; |
|
27 |
import android.support.v4.view.ViewPager; |
|
28 |
import android.support.v7.app.AlertDialog; |
|
29 |
import android.support.v7.app.AppCompatDialogFragment; |
|
30 |
import android.support.design.widget.TabLayout; |
|
31 |
import android.view.LayoutInflater; |
|
32 |
import android.view.View; |
|
33 |
import android.view.Window; |
|
34 |
import android.view.WindowManager; |
|
35 |
import android.widget.ImageView; |
|
36 |
import android.widget.TextView; |
|
37 |
|
|
38 |
import org.distorted.magic.R; |
|
39 |
import org.distorted.magic.RubikSize; |
|
40 |
|
|
41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
42 |
|
|
43 |
public class RubikDialogScores extends AppCompatDialogFragment |
|
44 |
{ |
|
45 |
RubikDialogScoresPagerAdapter mPagerAdapter; |
|
46 |
|
|
47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
48 |
|
|
49 |
@Override |
|
50 |
public void onStart() |
|
51 |
{ |
|
52 |
super.onStart(); |
|
53 |
|
|
54 |
Window window = getDialog().getWindow(); |
|
55 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
56 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
57 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
58 |
} |
|
59 |
|
|
60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
61 |
|
|
62 |
@NonNull |
|
63 |
@Override |
|
64 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
65 |
{ |
|
66 |
FragmentActivity act = getActivity(); |
|
67 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
68 |
|
|
69 |
LayoutInflater layoutInflater = act.getLayoutInflater(); |
|
70 |
TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null); |
|
71 |
tv.setText(R.string.scores); |
|
72 |
builder.setCustomTitle(tv); |
|
73 |
|
|
74 |
builder.setCancelable(true); |
|
75 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
76 |
{ |
|
77 |
@Override |
|
78 |
public void onClick(DialogInterface dialog, int which) |
|
79 |
{ |
|
80 |
|
|
81 |
} |
|
82 |
}); |
|
83 |
|
|
84 |
Bundle args = getArguments(); |
|
85 |
int curTab; |
|
86 |
|
|
87 |
try |
|
88 |
{ |
|
89 |
curTab = args.getInt("tab"); |
|
90 |
} |
|
91 |
catch(Exception e) |
|
92 |
{ |
|
93 |
curTab = 0; |
|
94 |
} |
|
95 |
|
|
96 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
97 |
final View view = inflater.inflate(R.layout.dialog_scores, null); |
|
98 |
builder.setView(view); |
|
99 |
|
|
100 |
ViewPager viewPager = view.findViewById(R.id.viewpager); |
|
101 |
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs); |
|
102 |
mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager); |
|
103 |
tabLayout.setupWithViewPager(viewPager); |
|
104 |
|
|
105 |
viewPager.setCurrentItem(curTab); |
|
106 |
|
|
107 |
for (int i = 0; i< RubikSize.LENGTH; i++) |
|
108 |
{ |
|
109 |
ImageView imageView = new ImageView(act); |
|
110 |
imageView.setImageResource(RubikSize.getSize(i).getIconID()); |
|
111 |
TabLayout.Tab tab = tabLayout.getTabAt(i); |
|
112 |
if(tab!=null) tab.setCustomView(imageView); |
|
113 |
} |
|
114 |
|
|
115 |
return builder.create(); |
|
116 |
} |
|
117 |
} |
src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.dialog; |
|
21 |
|
|
22 |
import android.support.annotation.NonNull; |
|
23 |
import android.support.v4.app.FragmentActivity; |
|
24 |
import android.support.v4.view.PagerAdapter; |
|
25 |
import android.support.v4.view.ViewPager; |
|
26 |
import android.view.View; |
|
27 |
import android.view.ViewGroup; |
|
28 |
|
|
29 |
import org.distorted.magic.RubikScoresDownloader; |
|
30 |
import org.distorted.magic.RubikSize; |
|
31 |
import org.distorted.uistate.RubikStatePlay; |
|
32 |
|
|
33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
34 |
|
|
35 |
class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikScoresDownloader.Receiver |
|
36 |
{ |
|
37 |
private FragmentActivity mAct; |
|
38 |
private RubikDialogScoresView[] mViews; |
|
39 |
private ViewPager mViewPager; |
|
40 |
|
|
41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
42 |
|
|
43 |
public void receive(final int[][][] country, final String[][][] name, final String[][][] time) |
|
44 |
{ |
|
45 |
prepareView(); |
|
46 |
|
|
47 |
int c = mViewPager.getCurrentItem(); |
|
48 |
|
|
49 |
addPage(mViews[c],country[c],name[c],time[c]); |
|
50 |
|
|
51 |
for(int i = 0; i< RubikSize.LENGTH; i++) |
|
52 |
{ |
|
53 |
if( i==c ) continue; |
|
54 |
|
|
55 |
addPage(mViews[i],country[i],name[i],time[i]); |
|
56 |
} |
|
57 |
} |
|
58 |
|
|
59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
60 |
|
|
61 |
private void prepareView() |
|
62 |
{ |
|
63 |
mAct.runOnUiThread(new Runnable() |
|
64 |
{ |
|
65 |
@Override |
|
66 |
public void run() |
|
67 |
{ |
|
68 |
for(int i=0; i<RubikSize.LENGTH; i++) |
|
69 |
{ |
|
70 |
mViews[i].prepareView(mAct); |
|
71 |
} |
|
72 |
} |
|
73 |
}); |
|
74 |
try |
|
75 |
{ |
|
76 |
Thread.sleep(200); |
|
77 |
} |
|
78 |
catch( InterruptedException ie) |
|
79 |
{ |
|
80 |
|
|
81 |
} |
|
82 |
} |
|
83 |
|
|
84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
85 |
|
|
86 |
private void addPage(final RubikDialogScoresView view, final int[][] country, final String[][] name, final String[][] time) |
|
87 |
{ |
|
88 |
for(int section = 0; section< RubikStatePlay.MAX_SCRAMBLE; section++) |
|
89 |
{ |
|
90 |
final int sec = section; |
|
91 |
final int[] c = country[section]; |
|
92 |
final String[] n = name[section]; |
|
93 |
final String[] t = time[section]; |
|
94 |
|
|
95 |
mAct.runOnUiThread(new Runnable() |
|
96 |
{ |
|
97 |
@Override |
|
98 |
public void run() |
|
99 |
{ |
|
100 |
view.addSection(mAct, sec, c, n, t); |
|
101 |
} |
|
102 |
}); |
|
103 |
|
|
104 |
try |
|
105 |
{ |
|
106 |
Thread.sleep(60); |
|
107 |
} |
|
108 |
catch( InterruptedException ie) |
|
109 |
{ |
|
110 |
|
|
111 |
} |
|
112 |
} |
|
113 |
} |
|
114 |
|
|
115 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
116 |
|
|
117 |
public void exception(final String exce) |
|
118 |
{ |
|
119 |
mAct.runOnUiThread(new Runnable() |
|
120 |
{ |
|
121 |
@Override |
|
122 |
public void run() |
|
123 |
{ |
|
124 |
for(int i=0; i<RubikSize.LENGTH; i++) |
|
125 |
{ |
|
126 |
mViews[i].exception(exce); |
|
127 |
} |
|
128 |
} |
|
129 |
}); |
|
130 |
} |
|
131 |
|
|
132 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
133 |
|
|
134 |
RubikDialogScoresPagerAdapter(FragmentActivity act, ViewPager viewPager) |
|
135 |
{ |
|
136 |
mAct = act; |
|
137 |
mViews = new RubikDialogScoresView[RubikSize.LENGTH]; |
|
138 |
mViewPager = viewPager; |
|
139 |
|
|
140 |
viewPager.setAdapter(this); |
|
141 |
viewPager.setOffscreenPageLimit( RubikSize.LENGTH-1 ); |
|
142 |
} |
|
143 |
|
|
144 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
145 |
|
|
146 |
@Override |
|
147 |
@NonNull |
|
148 |
public Object instantiateItem(@NonNull ViewGroup collection, int position) |
|
149 |
{ |
|
150 |
mViews[position] = new RubikDialogScoresView(mAct); |
|
151 |
collection.addView(mViews[position]); |
|
152 |
|
|
153 |
boolean allCreated = true; |
|
154 |
|
|
155 |
for(int i=0; i<RubikSize.LENGTH; i++) |
|
156 |
{ |
|
157 |
if( mViews[i]==null ) |
|
158 |
{ |
|
159 |
allCreated = false; |
|
160 |
break; |
|
161 |
} |
|
162 |
} |
|
163 |
|
|
164 |
if( allCreated ) |
|
165 |
{ |
|
166 |
RubikScoresDownloader downloader = new RubikScoresDownloader(); |
|
167 |
downloader.download(this, mAct.getResources(), mAct.getPackageName()); |
|
168 |
} |
|
169 |
|
|
170 |
return mViews[position]; |
|
171 |
} |
|
172 |
|
|
173 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
174 |
|
|
175 |
@Override |
|
176 |
public void destroyItem(ViewGroup collection, int position, @NonNull Object view) |
|
177 |
{ |
|
178 |
collection.removeView((View) view); |
|
179 |
} |
|
180 |
|
|
181 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
182 |
|
|
183 |
@Override |
|
184 |
public int getCount() |
|
185 |
{ |
|
186 |
return RubikSize.LENGTH; |
|
187 |
} |
|
188 |
|
|
189 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
190 |
|
|
191 |
@Override |
|
192 |
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) |
|
193 |
{ |
|
194 |
return view == object; |
|
195 |
} |
|
196 |
} |
src/main/java/org/distorted/dialog/RubikDialogScoresView.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.dialog; |
|
21 |
|
|
22 |
import android.content.Context; |
|
23 |
import android.support.v4.app.FragmentActivity; |
|
24 |
import android.util.AttributeSet; |
|
25 |
import android.view.View; |
|
26 |
import android.widget.FrameLayout; |
|
27 |
import android.widget.ImageView; |
|
28 |
import android.widget.LinearLayout; |
|
29 |
import android.widget.TextView; |
|
30 |
|
|
31 |
import org.distorted.magic.R; |
|
32 |
import org.distorted.magic.RubikScoresDownloader; |
|
33 |
|
|
34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
35 |
|
|
36 |
public class RubikDialogScoresView extends FrameLayout |
|
37 |
{ |
|
38 |
LinearLayout mLayout; |
|
39 |
|
|
40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
41 |
|
|
42 |
public RubikDialogScoresView(Context context, AttributeSet attrs, int defStyle) |
|
43 |
{ |
|
44 |
super(context, attrs, defStyle); |
|
45 |
} |
|
46 |
|
|
47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
48 |
|
|
49 |
public RubikDialogScoresView(Context context, AttributeSet attrs) |
|
50 |
{ |
|
51 |
super(context, attrs); |
|
52 |
} |
|
53 |
|
|
54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
55 |
|
|
56 |
public RubikDialogScoresView(Context context) |
|
57 |
{ |
|
58 |
super(context); |
|
59 |
|
|
60 |
View view = inflate(context, R.layout.dialog_scores_downloading, null); |
|
61 |
addView(view); |
|
62 |
} |
|
63 |
|
|
64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 |
|
|
66 |
void exception(final String exce) |
|
67 |
{ |
|
68 |
TextView text = findViewById(R.id.downloading_text); |
|
69 |
text.setText(exce); |
|
70 |
} |
|
71 |
|
|
72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
73 |
|
|
74 |
void prepareView(FragmentActivity act) |
|
75 |
{ |
|
76 |
removeAllViews(); |
|
77 |
|
|
78 |
View tab = inflate(act, R.layout.dialog_scores_tab, null); |
|
79 |
mLayout = tab.findViewById(R.id.tabLayout); |
|
80 |
addView(tab); |
|
81 |
} |
|
82 |
|
|
83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
84 |
|
|
85 |
void addSection(FragmentActivity act, int scramble, final int[] country, final String[] name, final String[] time) |
|
86 |
{ |
|
87 |
LinearLayout level = (LinearLayout)inflate(act, R.layout.dialog_scores_scramble_title, null); |
|
88 |
TextView text = level.findViewById(R.id.scoresScrambleTitle); |
|
89 |
text.setText(act.getString(R.string.sc_placeholder,(scramble+1))); |
|
90 |
|
|
91 |
for(int j = 0; j< RubikScoresDownloader.MAX_PLACES; j++) |
|
92 |
{ |
|
93 |
if( name[j] != null ) |
|
94 |
{ |
|
95 |
View row = inflate(act, R.layout.dialog_scores_scramble_row, null); |
|
96 |
|
|
97 |
ImageView imgCoun = row.findViewById(R.id.scoresScrambleRowCountry); |
|
98 |
TextView textName = row.findViewById(R.id.scoresScrambleRowName); |
|
99 |
TextView textTime = row.findViewById(R.id.scoresScrambleRowTime); |
|
100 |
|
|
101 |
imgCoun.setImageResource(country[j]); |
|
102 |
textName.setText(name[j]); |
|
103 |
textTime.setText(time[j]); |
|
104 |
|
|
105 |
level.addView(row); |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
mLayout.addView(level); |
|
110 |
} |
|
111 |
} |
src/main/java/org/distorted/dialog/RubikDialogSettings.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.dialog; |
|
21 |
|
|
22 |
import android.app.Dialog; |
|
23 |
import android.content.DialogInterface; |
|
24 |
import android.os.Bundle; |
|
25 |
import android.support.annotation.NonNull; |
|
26 |
import android.support.v4.app.FragmentActivity; |
|
27 |
import android.support.v4.content.ContextCompat; |
|
28 |
import android.support.v7.app.AlertDialog; |
|
29 |
import android.support.v7.app.AppCompatDialogFragment; |
|
30 |
import android.util.DisplayMetrics; |
|
31 |
import android.view.Gravity; |
|
32 |
import android.view.LayoutInflater; |
|
33 |
import android.view.View; |
|
34 |
import android.view.Window; |
|
35 |
import android.view.WindowManager; |
|
36 |
import android.widget.AdapterView; |
|
37 |
import android.widget.ArrayAdapter; |
|
38 |
import android.widget.LinearLayout; |
|
39 |
import android.widget.SeekBar; |
|
40 |
import android.widget.Spinner; |
|
41 |
import android.widget.TextView; |
|
42 |
|
|
43 |
import org.distorted.effect.BaseEffect; |
|
44 |
import org.distorted.magic.R; |
|
45 |
|
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
|
|
48 |
public class RubikDialogSettings extends AppCompatDialogFragment implements SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener |
|
49 |
{ |
|
50 |
private TextView[] mDurationText; |
|
51 |
|
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
|
|
54 |
private void addSettingsSection(FragmentActivity act, LinearLayout layout, int index) |
|
55 |
{ |
|
56 |
BaseEffect.Type beType = BaseEffect.Type.getType(index); |
|
57 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
|
58 |
float scale = metrics.density; |
|
59 |
|
|
60 |
int textH=32; |
|
61 |
int layoH=36; |
|
62 |
int margH=10; |
|
63 |
|
|
64 |
///// OUTER LAYOUT /////////////////////////////////////////////////////////////////// |
|
65 |
|
|
66 |
int margin = (int)(scale*margH + 0.5f); |
|
67 |
int color = ContextCompat.getColor(act, R.color.grey); |
|
68 |
LinearLayout outerLayout = new LinearLayout(act); |
|
69 |
LinearLayout.LayoutParams outerLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 0.5f); |
|
70 |
outerLayoutParams.topMargin = margin; |
|
71 |
outerLayoutParams.bottomMargin = 0; |
|
72 |
outerLayoutParams.leftMargin = margin; |
|
73 |
outerLayoutParams.rightMargin = margin; |
|
74 |
|
|
75 |
outerLayout.setLayoutParams(outerLayoutParams); |
|
76 |
outerLayout.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
77 |
outerLayout.setBackgroundColor(color); |
|
78 |
outerLayout.setOrientation(LinearLayout.VERTICAL); |
|
79 |
layout.addView(outerLayout); |
|
80 |
|
|
81 |
///// TEXT /////////////////////////////////////////////////////////////////////////// |
|
82 |
|
|
83 |
int layoutHeight = (int)(scale*textH + 0.5f); |
|
84 |
int padding = (int)(scale*10 + 0.5f); |
|
85 |
|
|
86 |
LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,layoutHeight); |
|
87 |
|
|
88 |
TextView textView = new TextView(act); |
|
89 |
textView.setText(beType.getText()); |
|
90 |
textView.setLayoutParams(textParams); |
|
91 |
textView.setGravity(Gravity.CENTER); |
|
92 |
textView.setPadding(padding,0,padding,0); |
|
93 |
textView.setTextAppearance(android.R.style.TextAppearance_Small); |
|
94 |
outerLayout.addView(textView); |
|
95 |
|
|
96 |
///// INNER LAYOUT1 ////////////////////////////////////////////////////////////////// |
|
97 |
|
|
98 |
int innerLayout1Height = (int)(scale*layoH + 0.5f); |
|
99 |
LinearLayout innerLayout1 = new LinearLayout(act); |
|
100 |
LinearLayout.LayoutParams innerLayout1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout1Height); |
|
101 |
|
|
102 |
innerLayout1.setLayoutParams(innerLayout1Params); |
|
103 |
innerLayout1.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
104 |
innerLayout1.setOrientation(LinearLayout.HORIZONTAL); |
|
105 |
outerLayout.addView(innerLayout1); |
|
106 |
|
|
107 |
///// STUFF INSIDE INNER LAYOUT1 ///////////////////////////////////////////////////// |
|
108 |
|
|
109 |
int text1Padding = (int)(scale*5 + 0.5f); |
|
110 |
LinearLayout.LayoutParams text1LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f); |
|
111 |
|
|
112 |
TextView text1View = new TextView(act); |
|
113 |
text1View.setText(R.string.duration); |
|
114 |
text1View.setLayoutParams(text1LayoutParams); |
|
115 |
text1View.setGravity(Gravity.START|Gravity.CENTER); |
|
116 |
text1View.setPadding(text1Padding,0,text1Padding,0); |
|
117 |
text1View.setTextAppearance(android.R.style.TextAppearance_Small); |
|
118 |
innerLayout1.addView(text1View); |
|
119 |
////////////////////////////////////////////////////////////////// |
|
120 |
int text2Padding = (int)(scale*5 + 0.5f); |
|
121 |
LinearLayout.LayoutParams text2LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f); |
|
122 |
|
|
123 |
mDurationText[index] = new TextView(act); |
|
124 |
mDurationText[index].setLayoutParams(text2LayoutParams); |
|
125 |
mDurationText[index].setGravity(Gravity.END|Gravity.CENTER); |
|
126 |
mDurationText[index].setPadding(text2Padding,0,text2Padding,0); |
|
127 |
mDurationText[index].setTextAppearance(android.R.style.TextAppearance_Small); |
|
128 |
innerLayout1.addView(mDurationText[index]); |
|
129 |
////////////////////////////////////////////////////////////////// |
|
130 |
int seekPadding = (int)(scale*10 + 0.5f); |
|
131 |
LinearLayout.LayoutParams seekLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f); |
|
132 |
|
|
133 |
SeekBar seekBar = new SeekBar(act); |
|
134 |
seekBar.setLayoutParams(seekLayoutParams); |
|
135 |
seekBar.setPadding(seekPadding,0,seekPadding,0); |
|
136 |
seekBar.setId(index); |
|
137 |
innerLayout1.addView(seekBar); |
|
138 |
|
|
139 |
seekBar.setOnSeekBarChangeListener(this); |
|
140 |
seekBar.setProgress(beType.getCurrentPos()); |
|
141 |
|
|
142 |
///// INNER LAYOUT2 ////////////////////////////////////////////////////////////////// |
|
143 |
|
|
144 |
int innerLayout2Height = (int)(scale*layoH + 0.5f); |
|
145 |
LinearLayout innerLayout2 = new LinearLayout(act); |
|
146 |
LinearLayout.LayoutParams innerLayout2Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout2Height); |
|
147 |
|
|
148 |
innerLayout2.setLayoutParams(innerLayout2Params); |
|
149 |
innerLayout2.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); |
|
150 |
innerLayout2.setOrientation(LinearLayout.HORIZONTAL); |
|
151 |
outerLayout.addView(innerLayout2); |
|
152 |
|
|
153 |
///// STUFF INSIDE INNER LAYOUT2 ///////////////////////////////////////////////////// |
|
154 |
|
|
155 |
int text3Padding = (int)(scale*5 + 0.5f); |
|
156 |
LinearLayout.LayoutParams text3LayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.4f); |
|
157 |
|
|
158 |
TextView text3View = new TextView(act); |
|
159 |
text3View.setText(R.string.type); |
|
160 |
text3View.setLayoutParams(text3LayoutParams); |
|
161 |
text3View.setGravity(Gravity.START|Gravity.CENTER); |
|
162 |
text3View.setPadding(text3Padding,0,text3Padding,0); |
|
163 |
text3View.setTextAppearance(android.R.style.TextAppearance_Small); |
|
164 |
innerLayout2.addView(text3View); |
|
165 |
////////////////////////////////////////////////////////////////// |
|
166 |
int spinnerPadding = (int)(scale*10 + 0.5f); |
|
167 |
LinearLayout.LayoutParams spinnerLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f); |
|
168 |
|
|
169 |
Spinner spinner = new Spinner(act); |
|
170 |
spinner.setLayoutParams(spinnerLayoutParams); |
|
171 |
spinner.setPadding(spinnerPadding,0,spinnerPadding,0); |
|
172 |
spinner.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); |
|
173 |
spinner.setId(index+BaseEffect.Type.LENGTH); |
|
174 |
innerLayout2.addView(spinner); |
|
175 |
|
|
176 |
spinner.setOnItemSelectedListener(this); |
|
177 |
String[] appear = BaseEffect.Type.getType(index).getNames(); |
|
178 |
|
|
179 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, appear); |
|
180 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
181 |
spinner.setAdapter(adapterType); |
|
182 |
spinner.setSelection(beType.getCurrentType()); |
|
183 |
} |
|
184 |
|
|
185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
186 |
// PUBLIC API |
|
187 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
188 |
|
|
189 |
public RubikDialogSettings() |
|
190 |
{ |
|
191 |
mDurationText = new TextView[BaseEffect.Type.LENGTH]; |
|
192 |
} |
|
193 |
|
|
194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
195 |
|
|
196 |
@Override |
|
197 |
public void onStart() |
|
198 |
{ |
|
199 |
super.onStart(); |
|
200 |
|
|
201 |
Window window = getDialog().getWindow(); |
|
202 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
203 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
204 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
205 |
} |
|
206 |
|
|
207 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
208 |
|
|
209 |
@NonNull |
|
210 |
@Override |
|
211 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
212 |
{ |
|
213 |
FragmentActivity act = getActivity(); |
|
214 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
215 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
216 |
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); |
|
217 |
tv.setText(R.string.settings); |
|
218 |
builder.setCustomTitle(tv); |
|
219 |
|
|
220 |
builder.setCancelable(true); |
|
221 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
222 |
{ |
|
223 |
@Override |
|
224 |
public void onClick(DialogInterface dialog, int which) |
|
225 |
{ |
|
226 |
|
|
227 |
} |
|
228 |
}); |
|
229 |
|
|
230 |
final View view = inflater.inflate(R.layout.dialog_settings, null); |
|
231 |
builder.setView(view); |
|
232 |
|
|
233 |
LinearLayout linearLayout = view.findViewById(R.id.settingsLayout); |
|
234 |
|
|
235 |
if( linearLayout!=null ) |
|
236 |
{ |
|
237 |
for (int i=0; i< BaseEffect.Type.LENGTH; i++) |
|
238 |
{ |
|
239 |
addSettingsSection(act,linearLayout,i); |
|
240 |
} |
|
241 |
} |
|
242 |
else |
|
243 |
{ |
|
244 |
android.util.Log.e("dialog_settings", "linearLayout NULL!"); |
|
245 |
} |
|
246 |
|
|
247 |
return builder.create(); |
|
248 |
} |
|
249 |
|
|
250 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
251 |
|
|
252 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) |
|
253 |
{ |
|
254 |
int parentID = parent.getId(); |
|
255 |
int len = BaseEffect.Type.LENGTH; |
|
256 |
|
|
257 |
if( parentID>=len && parentID< 2*len) // ith spinner's ID is equal to i+LENGTH (see createSettingSection) |
|
258 |
{ |
|
259 |
BaseEffect.Type.getType(parentID-len).setCurrentType(pos); |
|
260 |
} |
|
261 |
} |
|
262 |
|
|
263 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
264 |
|
|
265 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
266 |
{ |
|
267 |
int barID = bar.getId(); |
|
268 |
|
|
269 |
if( barID>=0 && barID< BaseEffect.Type.LENGTH) // ith seekbar's ID is equal to i (see createSettingSection) |
|
270 |
{ |
|
271 |
BaseEffect.Type.getType(barID).setCurrentPos(progress); |
|
272 |
int ms = BaseEffect.Type.translatePos(progress); |
|
273 |
mDurationText[barID].setText(getString(R.string.ms_placeholder,ms)); |
|
274 |
} |
|
275 |
} |
|
276 |
|
|
277 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
278 |
|
|
279 |
public void onNothingSelected(AdapterView<?> parent) { } |
|
280 |
public void onStartTrackingTouch(SeekBar bar) { } |
|
281 |
public void onStopTrackingTouch(SeekBar bar) { } |
|
282 |
} |
src/main/java/org/distorted/magic/RubikActivity.java | ||
---|---|---|
25 | 25 |
import android.support.v7.app.AppCompatActivity; |
26 | 26 |
import android.view.View; |
27 | 27 |
|
28 |
import org.distorted.dialog.RubikDialogAbout; |
|
29 |
import org.distorted.dialog.RubikDialogScores; |
|
30 |
import org.distorted.dialog.RubikDialogSettings; |
|
28 | 31 |
import org.distorted.effect.BaseEffect; |
29 | 32 |
import org.distorted.library.main.DistortedLibrary; |
30 | 33 |
|
34 |
import org.distorted.uistate.RubikState; |
|
35 |
import org.distorted.uistate.RubikStateAbstract; |
|
36 |
import org.distorted.uistate.RubikStatePlay; |
|
37 |
|
|
31 | 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
32 | 39 |
|
33 | 40 |
public class RubikActivity extends AppCompatActivity implements View.OnClickListener |
34 | 41 |
{ |
35 |
RubikState mCurrentState; |
|
36 |
|
|
37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
38 |
|
|
39 | 42 |
@Override |
40 | 43 |
protected void onCreate(Bundle savedState) |
41 | 44 |
{ |
... | ... | |
66 | 69 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
67 | 70 |
view.onResume(); |
68 | 71 |
restorePreferences(); |
69 |
view.switchState(this, mCurrentState);
|
|
72 |
RubikState.setState(this);
|
|
70 | 73 |
} |
71 | 74 |
|
72 | 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
94 | 97 |
|
95 | 98 |
if( success ) |
96 | 99 |
{ |
97 |
view.markButton(id); |
|
100 |
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass(); |
|
101 |
play.markButton(this,id); |
|
98 | 102 |
} |
99 | 103 |
} |
100 | 104 |
|
101 |
if( id == RubikSurfaceView.BUTTON_ID_BACK )
|
|
105 |
if( id == RubikStateAbstract.BUTTON_ID_BACK )
|
|
102 | 106 |
{ |
103 |
mCurrentState = mCurrentState.getBack(); |
|
104 |
|
|
105 |
if( mCurrentState!=null ) |
|
106 |
{ |
|
107 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
108 |
view.switchState(this, mCurrentState); |
|
109 |
} |
|
110 |
else |
|
111 |
{ |
|
112 |
mCurrentState = RubikState.MAIN; |
|
113 |
finish(); |
|
114 |
} |
|
107 |
RubikState.goBack(this); |
|
115 | 108 |
} |
116 | 109 |
} |
117 | 110 |
|
... | ... | |
122 | 115 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
123 | 116 |
SharedPreferences.Editor editor = preferences.edit(); |
124 | 117 |
|
125 |
for (int i = 0; i< BaseEffect.Type.LENGTH; i++)
|
|
118 |
for (int i=0; i<BaseEffect.Type.LENGTH; i++)
|
|
126 | 119 |
{ |
127 | 120 |
BaseEffect.Type.getType(i).savePreferences(editor); |
128 | 121 |
} |
129 | 122 |
|
130 |
editor.putInt("state", mCurrentState.ordinal() );
|
|
131 |
|
|
132 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
|
|
133 |
view.savePreferences(editor);
|
|
123 |
for (int i=0; i<RubikState.LENGTH; i++)
|
|
124 |
{ |
|
125 |
RubikState.getState(i).getStateClass().savePreferences(editor);
|
|
126 |
}
|
|
134 | 127 |
|
128 |
RubikState.savePreferences(editor); |
|
135 | 129 |
editor.apply(); |
136 | 130 |
} |
137 | 131 |
|
... | ... | |
146 | 140 |
BaseEffect.Type.getType(i).restorePreferences(preferences); |
147 | 141 |
} |
148 | 142 |
|
149 |
int stateOrdinal = preferences.getInt("state", RubikState.MAIN.ordinal() ); |
|
150 |
mCurrentState = RubikState.getState(stateOrdinal); |
|
143 |
for (int i=0; i< RubikState.LENGTH; i++) |
|
144 |
{ |
|
145 |
RubikState.getState(i).getStateClass().restorePreferences(preferences); |
|
146 |
} |
|
151 | 147 |
|
152 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
153 |
view.restorePreferences(preferences); |
|
148 |
RubikState.restorePreferences(preferences); |
|
154 | 149 |
} |
155 | 150 |
|
156 | 151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
159 | 154 |
|
160 | 155 |
public void Play(View v) |
161 | 156 |
{ |
162 |
mCurrentState = RubikState.PLAY; |
|
163 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
|
164 |
view.switchState(this,mCurrentState); |
|
157 |
RubikState.switchState(this,RubikState.PLAY); |
|
165 | 158 |
} |
166 | 159 |
|
167 | 160 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
176 | 169 |
|
177 | 170 |
public void Scores(View v) |
178 | 171 |
{ |
172 |
RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass(); |
|
173 |
int tab = play.getButton(); |
|
174 |
|
|
179 | 175 |
Bundle bundle = new Bundle(); |
180 |
bundle.putInt("tab", RubikSurfaceView.getRedButton());
|
|
176 |
bundle.putInt("tab", tab);
|
|
181 | 177 |
|
182 | 178 |
RubikDialogScores scores = new RubikDialogScores(); |
183 | 179 |
scores.setArguments(bundle); |
... | ... | |
197 | 193 |
public void Scramble(View v) |
198 | 194 |
{ |
199 | 195 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
200 |
view.scramble(); |
|
196 |
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass(); |
|
197 |
int scramble = play.getPicker(); |
|
198 |
view.getRenderer().scrambleCube(scramble); |
|
201 | 199 |
} |
202 | 200 |
|
203 | 201 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/magic/RubikDialogAbout.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.magic; |
|
21 |
|
|
22 |
import android.app.Dialog; |
|
23 |
import android.content.DialogInterface; |
|
24 |
import android.os.Bundle; |
|
25 |
import android.support.annotation.NonNull; |
|
26 |
import android.support.v4.app.FragmentActivity; |
|
27 |
import android.support.v7.app.AlertDialog; |
|
28 |
import android.support.v7.app.AppCompatDialogFragment; |
|
29 |
import android.view.LayoutInflater; |
|
30 |
import android.view.View; |
|
31 |
import android.view.Window; |
|
32 |
import android.view.WindowManager; |
|
33 |
import android.widget.TextView; |
|
34 |
|
|
35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
36 |
|
|
37 |
public class RubikDialogAbout extends AppCompatDialogFragment |
|
38 |
{ |
|
39 |
@Override |
|
40 |
public void onStart() |
|
41 |
{ |
|
42 |
super.onStart(); |
|
43 |
|
|
44 |
Window window = getDialog().getWindow(); |
|
45 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
46 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
47 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
48 |
} |
|
49 |
|
|
50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
51 |
|
|
52 |
@NonNull |
|
53 |
@Override |
|
54 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
55 |
{ |
|
56 |
FragmentActivity act = getActivity(); |
|
57 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
58 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
59 |
|
|
60 |
TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); |
|
61 |
tv.setText(R.string.about); |
|
62 |
builder.setCustomTitle(tv); |
|
63 |
|
|
64 |
builder.setCancelable(true); |
|
65 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
66 |
{ |
|
67 |
@Override |
|
68 |
public void onClick(DialogInterface dialog, int which) |
|
69 |
{ |
|
70 |
|
|
71 |
} |
|
72 |
}); |
|
73 |
|
|
74 |
final View view = inflater.inflate(R.layout.dialog_about, null); |
|
75 |
TextView text = view.findViewById(R.id.about_version); |
|
76 |
text.setText(R.string.app_version); |
|
77 |
builder.setView(view); |
|
78 |
|
|
79 |
return builder.create(); |
|
80 |
} |
|
81 |
} |
src/main/java/org/distorted/magic/RubikDialogMain.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.magic; |
|
21 |
|
|
22 |
import android.app.Dialog; |
|
23 |
import android.os.Bundle; |
|
24 |
import android.support.annotation.NonNull; |
|
25 |
import android.support.v4.app.FragmentActivity; |
|
26 |
import android.support.v7.app.AlertDialog; |
|
27 |
import android.support.v7.app.AppCompatDialogFragment; |
|
28 |
import android.view.LayoutInflater; |
|
29 |
import android.view.View; |
|
30 |
import android.view.Window; |
|
31 |
import android.view.WindowManager; |
|
32 |
|
|
33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
34 |
|
|
35 |
public class RubikDialogMain extends AppCompatDialogFragment |
|
36 |
{ |
|
37 |
@Override |
|
38 |
public void onStart() |
|
39 |
{ |
|
40 |
super.onStart(); |
|
41 |
|
|
42 |
Window window = getDialog().getWindow(); |
|
43 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
44 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
45 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
46 |
} |
|
47 |
|
|
48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
49 |
|
|
50 |
@NonNull |
|
51 |
@Override |
|
52 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
53 |
{ |
|
54 |
FragmentActivity act = getActivity(); |
|
55 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
56 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
57 |
final View view = inflater.inflate(R.layout.dialog_main, null); |
|
58 |
builder.setView(view); |
|
59 |
|
|
60 |
return builder.create(); |
|
61 |
} |
|
62 |
|
|
63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
64 |
|
|
65 |
static String getDialogTag() |
|
66 |
{ |
|
67 |
return "DialogMain"; |
|
68 |
} |
|
69 |
} |
src/main/java/org/distorted/magic/RubikDialogScores.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2019 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.magic; |
|
21 |
|
|
22 |
import android.app.Dialog; |
|
23 |
import android.content.DialogInterface; |
|
24 |
import android.os.Bundle; |
|
25 |
import android.support.annotation.NonNull; |
|
26 |
import android.support.v4.app.FragmentActivity; |
|
27 |
import android.support.v4.view.ViewPager; |
|
28 |
import android.support.v7.app.AlertDialog; |
|
29 |
import android.support.v7.app.AppCompatDialogFragment; |
|
30 |
import android.support.design.widget.TabLayout; |
|
31 |
import android.view.LayoutInflater; |
|
32 |
import android.view.View; |
|
33 |
import android.view.Window; |
|
34 |
import android.view.WindowManager; |
|
35 |
import android.widget.ImageView; |
|
36 |
import android.widget.TextView; |
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
public class RubikDialogScores extends AppCompatDialogFragment |
|
41 |
{ |
|
42 |
RubikDialogScoresPagerAdapter mPagerAdapter; |
|
43 |
|
|
44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
45 |
|
|
46 |
@Override |
|
47 |
public void onStart() |
|
48 |
{ |
|
49 |
super.onStart(); |
|
50 |
|
|
51 |
Window window = getDialog().getWindow(); |
|
52 |
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, |
|
53 |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); |
|
54 |
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
|
55 |
} |
|
56 |
|
|
57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
58 |
|
|
59 |
@NonNull |
|
60 |
@Override |
|
61 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
|
62 |
{ |
|
63 |
FragmentActivity act = getActivity(); |
|
64 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
|
65 |
|
|
66 |
LayoutInflater layoutInflater = act.getLayoutInflater(); |
|
67 |
TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null); |
|
68 |
tv.setText(R.string.scores); |
|
69 |
builder.setCustomTitle(tv); |
|
70 |
|
|
71 |
builder.setCancelable(true); |
|
72 |
builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() |
|
73 |
{ |
|
74 |
@Override |
|
75 |
public void onClick(DialogInterface dialog, int which) |
|
76 |
{ |
|
77 |
|
|
78 |
} |
|
79 |
}); |
|
80 |
|
|
81 |
Bundle args = getArguments(); |
|
82 |
int curTab; |
|
83 |
|
|
84 |
try |
|
85 |
{ |
|
86 |
curTab = args.getInt("tab"); |
|
87 |
} |
|
88 |
catch(Exception e) |
|
89 |
{ |
|
90 |
curTab = 0; |
|
91 |
} |
|
92 |
|
|
93 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
94 |
final View view = inflater.inflate(R.layout.dialog_scores, null); |
|
95 |
builder.setView(view); |
|
96 |
|
|
97 |
ViewPager viewPager = view.findViewById(R.id.viewpager); |
|
98 |
TabLayout tabLayout = view.findViewById(R.id.sliding_tabs); |
|
99 |
mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager); |
|
100 |
tabLayout.setupWithViewPager(viewPager); |
|
101 |
|
|
102 |
viewPager.setCurrentItem(curTab); |
|
103 |
|
|
104 |
for (int i = 0; i< RubikSize.LENGTH; i++) |
|
105 |
{ |
|
106 |
ImageView imageView = new ImageView(act); |
|
107 |
imageView.setImageResource(RubikSize.getSize(i).getIconID()); |
|
108 |
TabLayout.Tab tab = tabLayout.getTabAt(i); |
|
109 |
if(tab!=null) tab.setCustomView(imageView); |
|
110 |
} |
|
111 |
|
|
112 |
return builder.create(); |
|
113 |
} |
|
114 |
} |
src/main/java/org/distorted/magic/RubikDialogScoresPagerAdapter.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Magic Cube. // |
|
5 |
// // |
|
6 |
// Magic Cube is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Magic Cube is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.magic; |
|
21 |
|
|
22 |
import android.support.annotation.NonNull; |
|
23 |
import android.support.v4.app.FragmentActivity; |
|
24 |
import android.support.v4.view.PagerAdapter; |
|
25 |
import android.support.v4.view.ViewPager; |
|
26 |
import android.view.View; |
|
27 |
import android.view.ViewGroup; |
|
28 |
|
|
29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
30 |
|
|
31 |
class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikScoresDownloader.Receiver |
|
32 |
{ |
|
33 |
private FragmentActivity mAct; |
|
34 |
private RubikDialogScoresView[] mViews; |
|
35 |
private ViewPager mViewPager; |
|
36 |
|
|
37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
38 |
|
|
39 |
public void receive(final int[][][] country, final String[][][] name, final String[][][] time) |
|
40 |
{ |
|
41 |
prepareView(); |
|
42 |
|
|
43 |
int c = mViewPager.getCurrentItem(); |
|
44 |
|
|
45 |
addPage(mViews[c],country[c],name[c],time[c]); |
|
46 |
|
|
47 |
for(int i=0; i<RubikSize.LENGTH; i++) |
|
48 |
{ |
|
49 |
if( i==c ) continue; |
|
50 |
|
|
51 |
addPage(mViews[i],country[i],name[i],time[i]); |
|
52 |
} |
|
53 |
} |
|
54 |
|
|
55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
56 |
|
|
57 |
private void prepareView() |
|
58 |
{ |
|
59 |
mAct.runOnUiThread(new Runnable() |
|
60 |
{ |
|
61 |
@Override |
|
62 |
public void run() |
|
63 |
{ |
|
64 |
for(int i=0; i<RubikSize.LENGTH; i++) |
|
65 |
{ |
|
66 |
mViews[i].prepareView(mAct); |
|
67 |
} |
|
68 |
} |
|
69 |
}); |
|
70 |
try |
|
71 |
{ |
|
72 |
Thread.sleep(200); |
|
73 |
} |
|
74 |
catch( InterruptedException ie) |
|
75 |
{ |
|
76 |
|
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
81 |
|
|
82 |
private void addPage(final RubikDialogScoresView view, final int[][] country, final String[][] name, final String[][] time) |
|
83 |
{ |
|
84 |
for(int section=0; section<RubikSurfaceView.MAX_SCRAMBLE; section++) |
|
85 |
{ |
|
86 |
final int sec = section; |
|
87 |
final int[] c = country[section]; |
|
88 |
final String[] n = name[section]; |
|
89 |
final String[] t = time[section]; |
|
90 |
|
|
91 |
mAct.runOnUiThread(new Runnable() |
|
92 |
{ |
|
93 |
@Override |
|
94 |
public void run() |
|
95 |
{ |
|
96 |
view.addSection(mAct, sec, c, n, t); |
|
97 |
} |
|
98 |
}); |
|
99 |
|
|
100 |
try |
|
101 |
{ |
|
102 |
Thread.sleep(60); |
|
103 |
} |
|
104 |
catch( InterruptedException ie) |
|
105 |
{ |
|
106 |
|
|
107 |
} |
|
108 |
} |
|
109 |
} |
|
110 |
|
|
111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
112 |
|
|
113 |
public void exception(final String exce) |
|
114 |
{ |
|
115 |
mAct.runOnUiThread(new Runnable() |
|
116 |
{ |
|
117 |
@Override |
|
118 |
public void run() |
|
119 |
{ |
|
120 |
for(int i=0; i<RubikSize.LENGTH; i++) |
|
121 |
{ |
|
122 |
mViews[i].exception(exce); |
|
123 |
} |
|
124 |
} |
|
125 |
}); |
|
126 |
} |
|
127 |
|
|
128 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
129 |
|
|
130 |
RubikDialogScoresPagerAdapter(FragmentActivity act, ViewPager viewPager) |
|
131 |
{ |
|
132 |
mAct = act; |
|
133 |
mViews = new RubikDialogScoresView[RubikSize.LENGTH]; |
|
134 |
mViewPager = viewPager; |
|
135 |
|
|
136 |
viewPager.setAdapter(this); |
|
137 |
viewPager.setOffscreenPageLimit( RubikSize.LENGTH-1 ); |
|
138 |
} |
|
139 |
|
|
140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
141 |
|
|
142 |
@Override |
|
143 |
@NonNull |
|
144 |
public Object instantiateItem(@NonNull ViewGroup collection, int position) |
|
145 |
{ |
|
146 |
mViews[position] = new RubikDialogScoresView(mAct); |
|
147 |
collection.addView(mViews[position]); |
|
148 |
|
|
149 |
boolean allCreated = true; |
|
150 |
|
|
151 |
for(int i=0; i<RubikSize.LENGTH; i++) |
|
152 |
{ |
|
153 |
if( mViews[i]==null ) |
|
154 |
{ |
|
155 |
allCreated = false; |
|
156 |
break; |
|
157 |
} |
|
158 |
} |
|
159 |
|
|
160 |
if( allCreated ) |
|
161 |
{ |
|
162 |
RubikScoresDownloader downloader = new RubikScoresDownloader(); |
|
163 |
downloader.download(this, mAct.getResources(), mAct.getPackageName()); |
|
164 |
} |
|
165 |
|
|
166 |
return mViews[position]; |
|
167 |
} |
Also available in: Unified diff
Separate the States (and also Dialogues) into their own package.