Revision c2d85688
Added by Leszek Koltunski over 2 years ago
distorted-sokoban/build.gradle | ||
---|---|---|
26 | 26 |
implementation 'com.google.firebase:firebase-analytics' |
27 | 27 |
implementation 'com.google.firebase:firebase-crashlytics' |
28 | 28 |
implementation 'com.google.firebase:firebase-inappmessaging-display' |
29 |
implementation 'com.google.android.material:material:1.6.1' |
|
29 | 30 |
implementation "androidx.work:work-runtime:2.7.1" |
30 | 31 |
} |
31 | 32 |
|
distorted-sokoban/src/main/AndroidManifest.xml | ||
---|---|---|
8 | 8 |
android:normalScreens="true" |
9 | 9 |
android:largeScreens="true" |
10 | 10 |
android:anyDensity="true"/> |
11 |
|
|
11 |
|
|
12 | 12 |
<uses-permission android:name="android.permission.INTERNET"/> |
13 | 13 |
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> |
14 | 14 |
|
15 | 15 |
<uses-feature android:name="android.hardware.touchscreen"/> |
16 | 16 |
|
17 | 17 |
<application android:icon="@drawable/icon" android:label="@string/app_name"> |
18 |
<activity android:name=".Sokoban" |
|
18 |
<activity android:name=".SokobanSplash"
|
|
19 | 19 |
android:label="@string/app_name" |
20 | 20 |
android:exported="true" |
21 | 21 |
android:screenOrientation="portrait" |
... | ... | |
26 | 26 |
<category android:name="android.intent.category.LAUNCHER" /> |
27 | 27 |
</intent-filter> |
28 | 28 |
</activity> |
29 |
<activity android:name=".SokobanMain"
|
|
29 |
<activity android:name=".SokobanActivity"
|
|
30 | 30 |
android:exported="true" |
31 | 31 |
android:screenOrientation="portrait" |
32 | 32 |
android:label="@string/app_name" |
distorted-sokoban/src/main/java/helpers/TransparentButton.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 helpers; |
|
11 |
|
|
12 |
import android.annotation.SuppressLint; |
|
13 |
import android.content.Context; |
|
14 |
import android.util.TypedValue; |
|
15 |
import android.widget.LinearLayout; |
|
16 |
|
|
17 |
import com.google.android.material.button.MaterialButton; |
|
18 |
|
|
19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
20 |
|
|
21 |
@SuppressLint("ViewConstructor") |
|
22 |
public class TransparentButton extends MaterialButton |
|
23 |
{ |
|
24 |
public TransparentButton(Context context, int resId, float textSize) |
|
25 |
{ |
|
26 |
this(context, resId, textSize, 1.0f); |
|
27 |
} |
|
28 |
|
|
29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
30 |
|
|
31 |
public TransparentButton(Context context, int resId, float textSize, float weight) |
|
32 |
{ |
|
33 |
super(context); |
|
34 |
|
|
35 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, weight); |
|
36 |
|
|
37 |
setLayoutParams(params); |
|
38 |
setPadding(0,0,0,0); |
|
39 |
setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); |
|
40 |
setText(resId); |
|
41 |
|
|
42 |
TypedValue outValue = new TypedValue(); |
|
43 |
context.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true); |
|
44 |
setBackgroundResource(outValue.resourceId); |
|
45 |
} |
|
46 |
} |
distorted-sokoban/src/main/java/helpers/TransparentImageButton.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 helpers; |
|
11 |
|
|
12 |
import android.annotation.SuppressLint; |
|
13 |
import android.content.Context; |
|
14 |
import android.util.TypedValue; |
|
15 |
import android.widget.LinearLayout; |
|
16 |
|
|
17 |
import com.google.android.material.button.MaterialButton; |
|
18 |
|
|
19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
20 |
|
|
21 |
@SuppressLint("ViewConstructor") |
|
22 |
public class TransparentImageButton extends MaterialButton |
|
23 |
{ |
|
24 |
public static final int GRAVITY_START = 0; |
|
25 |
public static final int GRAVITY_MIDDLE = 1; |
|
26 |
public static final int GRAVITY_END = 2; |
|
27 |
|
|
28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
|
|
30 |
public TransparentImageButton(Context context, int icon, int gravity, LinearLayout.LayoutParams params) |
|
31 |
{ |
|
32 |
super(context); |
|
33 |
|
|
34 |
setLayoutParams(params); |
|
35 |
setPadding(0,0,0,0); |
|
36 |
setIconResource(icon); |
|
37 |
setIconTint(null); |
|
38 |
|
|
39 |
switch(gravity) |
|
40 |
{ |
|
41 |
case GRAVITY_START : setIconGravity(MaterialButton.ICON_GRAVITY_START ); break; |
|
42 |
case GRAVITY_MIDDLE: setIconGravity(MaterialButton.ICON_GRAVITY_TEXT_START); break; |
|
43 |
case GRAVITY_END : setIconGravity(MaterialButton.ICON_GRAVITY_END ); break; |
|
44 |
} |
|
45 |
|
|
46 |
TypedValue outValue = new TypedValue(); |
|
47 |
context.getTheme().resolveAttribute(android.R.attr.selectableItemBackgroundBorderless, outValue, true); |
|
48 |
setBackgroundResource(outValue.resourceId); |
|
49 |
} |
|
50 |
} |
distorted-sokoban/src/main/java/org/distorted/keyboard/StringBlock.java | ||
---|---|---|
1 |
package org.distorted.keyboard; |
|
2 |
|
|
3 |
import android.graphics.Canvas; |
|
4 |
import android.graphics.Paint; |
|
5 |
import android.graphics.Paint.Align; |
|
6 |
|
|
7 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
8 |
|
|
9 |
public class StringBlock |
|
10 |
{ |
|
11 |
//private static final String TAG_BLOCK="SokobanStringBlock"; |
|
12 |
|
|
13 |
private String str; |
|
14 |
private int height,length; |
|
15 |
private int realheight; |
|
16 |
private int size, len; |
|
17 |
private Paint mPaint; |
|
18 |
private String buffer; |
|
19 |
|
|
20 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
21 |
|
|
22 |
public StringBlock(String s, int h, int l) |
|
23 |
{ |
|
24 |
str =s; |
|
25 |
length =l; |
|
26 |
height =h; |
|
27 |
len = str.length(); |
|
28 |
|
|
29 |
mPaint = new Paint(); |
|
30 |
buffer = new String(); |
|
31 |
|
|
32 |
mPaint.setTextAlign(Align.LEFT); |
|
33 |
mPaint.setAntiAlias(true); |
|
34 |
mPaint.setFakeBoldText(true); |
|
35 |
|
|
36 |
size = computeOptimalSize(); |
|
37 |
} |
|
38 |
|
|
39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
40 |
|
|
41 |
public void draw(Canvas c, int x,int y, int color) |
|
42 |
{ |
|
43 |
String tmp; |
|
44 |
int begin=0, end=0; |
|
45 |
int delta = (height-realheight)/2; |
|
46 |
|
|
47 |
mPaint.setColor(color); |
|
48 |
mPaint.setTextSize(size); |
|
49 |
|
|
50 |
while( end>=0 && end<len ) |
|
51 |
{ |
|
52 |
end = getLine(str,size,begin,length); |
|
53 |
|
|
54 |
if( end>=0 ) |
|
55 |
{ |
|
56 |
if( str.charAt(begin) == '\n' ) begin++; |
|
57 |
|
|
58 |
if( end>begin ) |
|
59 |
{ |
|
60 |
tmp = str.substring(begin,end); |
|
61 |
|
|
62 |
if( end<len && str.charAt(end+1) != '\n' ) |
|
63 |
displayJustified( tmp, size, x, y+delta, length, c); |
|
64 |
else |
|
65 |
c.drawText( tmp, x, y+delta+size, mPaint); |
|
66 |
} |
|
67 |
|
|
68 |
y += (begin==end ? size/2 : size); |
|
69 |
begin = end; |
|
70 |
} |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
75 |
|
|
76 |
private void displayJustified(String str, int fontHeight, int x, int y, int length, Canvas c) |
|
77 |
{ |
|
78 |
int len = str.length(); |
|
79 |
int numspaces = retNumSpaces(str); |
|
80 |
|
|
81 |
if( str.charAt(len-1) == ' ' ) numspaces--; |
|
82 |
|
|
83 |
float left=x,w = (numspaces>0 ? (float)(length-mPaint.measureText(str))/numspaces : 0); |
|
84 |
String tmp; |
|
85 |
int begin,end=0; |
|
86 |
|
|
87 |
while( end<len ) |
|
88 |
{ |
|
89 |
begin=end; |
|
90 |
end = str.indexOf(' ', begin)+1; |
|
91 |
if( end<=0 ) end = len; |
|
92 |
|
|
93 |
tmp = str.substring(begin,end); |
|
94 |
c.drawText( tmp, left, y+fontHeight, mPaint); |
|
95 |
left+= (mPaint.measureText(tmp)+w); |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
private int retNumSpaces(String str) |
|
102 |
{ |
|
103 |
int begin=0, ret=0; |
|
104 |
|
|
105 |
while( true ) |
|
106 |
{ |
|
107 |
begin = str.indexOf(' ', begin) +1; |
|
108 |
|
|
109 |
if( begin>0 ) ret++; |
|
110 |
else break; |
|
111 |
} |
|
112 |
|
|
113 |
return ret; |
|
114 |
} |
|
115 |
|
|
116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
117 |
|
|
118 |
private int getLine(String text, int fontHeight, int begin, int width) |
|
119 |
{ |
|
120 |
int nearestSpace = text.indexOf(' ' , begin+1); |
|
121 |
int nearestNewline = text.indexOf('\n', begin+1); |
|
122 |
int len=0; |
|
123 |
|
|
124 |
mPaint.setTextSize(fontHeight); |
|
125 |
|
|
126 |
if( nearestNewline>=0 && nearestNewline<nearestSpace ) return nearestNewline; |
|
127 |
if( nearestSpace<0 ) return text.length(); |
|
128 |
|
|
129 |
buffer = text.substring(begin,nearestSpace); |
|
130 |
|
|
131 |
len = (int)mPaint.measureText(buffer); |
|
132 |
|
|
133 |
if( len>=width ) return nearestSpace+1; |
|
134 |
|
|
135 |
int lastSpace = nearestSpace; |
|
136 |
|
|
137 |
while( len<width ) |
|
138 |
{ |
|
139 |
lastSpace = nearestSpace; |
|
140 |
|
|
141 |
nearestNewline = text.indexOf('\n', lastSpace+1); |
|
142 |
nearestSpace = text.indexOf(' ' , lastSpace+1); |
|
143 |
|
|
144 |
if( nearestNewline>=0 && nearestNewline<nearestSpace ) |
|
145 |
{ |
|
146 |
buffer = text.substring(begin,nearestNewline); |
|
147 |
len = (int)mPaint.measureText(buffer); |
|
148 |
return len<width ? nearestNewline : lastSpace+1; |
|
149 |
} |
|
150 |
if( nearestSpace<0 ) |
|
151 |
{ |
|
152 |
buffer = text.substring(begin); |
|
153 |
len= (int)mPaint.measureText(buffer); |
|
154 |
return len<width ? text.length() : lastSpace+1; |
|
155 |
} |
|
156 |
|
|
157 |
buffer = text.substring(begin,nearestSpace); |
|
158 |
len = (int)mPaint.measureText(buffer); |
|
159 |
} |
|
160 |
return lastSpace+1; |
|
161 |
} |
|
162 |
|
|
163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
164 |
|
|
165 |
private int computeOptimalSize() |
|
166 |
{ |
|
167 |
int h=0, trysize=10; |
|
168 |
|
|
169 |
while( h<height ) |
|
170 |
{ |
|
171 |
realheight = h; |
|
172 |
h = height(++trysize); |
|
173 |
} |
|
174 |
|
|
175 |
return trysize-1; |
|
176 |
} |
|
177 |
|
|
178 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
179 |
|
|
180 |
private int height(int trySize) |
|
181 |
{ |
|
182 |
int y=0 , begin=0, end=0; |
|
183 |
|
|
184 |
while( end>=0 && end<len ) |
|
185 |
{ |
|
186 |
end = getLine(str,trySize,begin,length); |
|
187 |
|
|
188 |
if( end>=0 ) |
|
189 |
{ |
|
190 |
if( str.charAt(begin) == '\n' ) begin++; |
|
191 |
y += (begin==end ? trySize/2 : trySize); |
|
192 |
begin = end; |
|
193 |
} |
|
194 |
} |
|
195 |
|
|
196 |
return y; |
|
197 |
} |
|
198 |
|
|
199 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
200 |
// end of RRStringBlock |
|
201 |
} |
distorted-sokoban/src/main/java/org/distorted/keyboard/TextFieldArea.java | ||
---|---|---|
1 |
package org.distorted.sokoban;
|
|
1 |
package org.distorted.keyboard;
|
|
2 | 2 |
|
3 | 3 |
import android.graphics.Canvas; |
4 | 4 |
import android.graphics.Paint; |
distorted-sokoban/src/main/java/org/distorted/keyboard/TouchKeyboard.java | ||
---|---|---|
1 |
package org.distorted.sokoban;
|
|
1 |
package org.distorted.keyboard;
|
|
2 | 2 |
|
3 | 3 |
import android.content.Context; |
4 | 4 |
import android.content.res.Resources; |
... | ... | |
14 | 14 |
import android.view.MotionEvent; |
15 | 15 |
import android.view.View; |
16 | 16 |
|
17 |
import org.distorted.sokoban.R; |
|
18 |
|
|
17 | 19 |
//import android.util.Log; |
18 | 20 |
|
19 | 21 |
//////////////////////////////////////////////////////////////////////////////// |
distorted-sokoban/src/main/java/org/distorted/sokoban/Sokoban.java | ||
---|---|---|
1 |
package org.distorted.sokoban; |
|
2 |
|
|
3 |
import android.app.Activity; |
|
4 |
import android.content.Intent; |
|
5 |
import android.os.Bundle; |
|
6 |
import android.util.Log; |
|
7 |
|
|
8 |
import com.google.firebase.analytics.FirebaseAnalytics; |
|
9 |
import com.google.firebase.inappmessaging.FirebaseInAppMessaging; |
|
10 |
|
|
11 |
import org.distorted.messaging.SokobanInAppMessanging; |
|
12 |
|
|
13 |
/////////////////////////////////////////////////////////////////// |
|
14 |
|
|
15 |
public class Sokoban extends Activity |
|
16 |
{ |
|
17 |
private static final String TAG_SPLASH = "SokobanSplash"; |
|
18 |
private int sleepTime=2000; |
|
19 |
private FirebaseAnalytics mFirebaseAnalytics; |
|
20 |
|
|
21 |
private class SplashThread extends Thread |
|
22 |
{ |
|
23 |
private boolean bootup=true; |
|
24 |
|
|
25 |
public void run() |
|
26 |
{ |
|
27 |
int milis=0; |
|
28 |
|
|
29 |
while(bootup) |
|
30 |
{ |
|
31 |
try |
|
32 |
{ |
|
33 |
milis+=100; |
|
34 |
Thread.sleep(100); |
|
35 |
} |
|
36 |
catch( InterruptedException ex) {} |
|
37 |
} |
|
38 |
|
|
39 |
if( milis<sleepTime ) |
|
40 |
{ |
|
41 |
try |
|
42 |
{ |
|
43 |
Thread.sleep(sleepTime-milis); |
|
44 |
} |
|
45 |
catch( InterruptedException ex) {} |
|
46 |
} |
|
47 |
finish(); |
|
48 |
Intent mainInt = new Intent( getApplicationContext(), SokobanMain.class); |
|
49 |
startActivity(mainInt); |
|
50 |
} |
|
51 |
public void bootupReady() |
|
52 |
{ |
|
53 |
bootup=false; |
|
54 |
} |
|
55 |
}; |
|
56 |
|
|
57 |
/////////////////////////////////////////////////////////////////// |
|
58 |
|
|
59 |
public void onCreate(Bundle savedInstanceState) |
|
60 |
{ |
|
61 |
super.onCreate(savedInstanceState); |
|
62 |
|
|
63 |
setContentView(R.layout.splash); |
|
64 |
sleepTime=2000; |
|
65 |
|
|
66 |
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); |
|
67 |
SokobanInAppMessanging listener = new SokobanInAppMessanging(); |
|
68 |
|
|
69 |
FirebaseInAppMessaging.getInstance().addClickListener(listener); |
|
70 |
} |
|
71 |
|
|
72 |
/////////////////////////////////////////////////////////////////// |
|
73 |
|
|
74 |
public void onStart() |
|
75 |
{ |
|
76 |
Log.d( TAG_SPLASH, "onStart"); |
|
77 |
|
|
78 |
super.onStart(); |
|
79 |
|
|
80 |
SplashThread splashThread = new SplashThread(); |
|
81 |
splashThread.start(); |
|
82 |
|
|
83 |
SokobanLevels.init(this); |
|
84 |
SokobanLevels sl = SokobanLevels.getInstance(); |
|
85 |
|
|
86 |
SokobanCanvas.init(this); |
|
87 |
SokobanCanvas.setActivity(this); |
|
88 |
|
|
89 |
SokobanDatabase.init(this); |
|
90 |
SokobanTimer.init(); |
|
91 |
SokobanCanvas.setLevels(sl); |
|
92 |
SokobanRecords.setLevels(sl); |
|
93 |
|
|
94 |
splashThread.bootupReady(); |
|
95 |
} |
|
96 |
|
|
97 |
/////////////////////////////////////////////////////////////////// |
|
98 |
// end of file |
|
99 |
} |
distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanActivity.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2016 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted 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 |
// Distorted 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 Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.sokoban; |
|
21 |
|
|
22 |
import android.app.ListActivity; |
|
23 |
import android.os.Build; |
|
24 |
import android.os.Bundle; |
|
25 |
import android.util.DisplayMetrics; |
|
26 |
import android.util.TypedValue; |
|
27 |
import android.view.DisplayCutout; |
|
28 |
import android.view.View; |
|
29 |
import android.view.ViewGroup; |
|
30 |
import android.view.WindowManager; |
|
31 |
import android.widget.LinearLayout; |
|
32 |
import android.widget.TextView; |
|
33 |
|
|
34 |
import helpers.TransparentImageButton; |
|
35 |
|
|
36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
37 |
|
|
38 |
public class SokobanActivity extends ListActivity |
|
39 |
{ |
|
40 |
private static final String ITEM_IMAGE = "item_image"; |
|
41 |
private static final String ITEM_TITLE = "item_title"; |
|
42 |
private static final String ITEM_SUBTITLE = "item_subtitle"; |
|
43 |
|
|
44 |
private static final float RATIO_BAR = 0.10f; |
|
45 |
private static final float RATIO_INSET = 0.09f; |
|
46 |
private static final float MENU_SIZE = 0.05f; |
|
47 |
|
|
48 |
public static final int FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
|
49 |
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
|
50 |
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
|
51 |
| View.SYSTEM_UI_FLAG_FULLSCREEN |
|
52 |
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
|
53 |
|
|
54 |
private static int mScreenWidth, mScreenHeight; |
|
55 |
|
|
56 |
private int mHeightUpperBar; |
|
57 |
private int mCurrentApiVersion; |
|
58 |
private TransparentImageButton mRecordsButton, mExitButton; |
|
59 |
private TextView mAppName; |
|
60 |
|
|
61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
62 |
|
|
63 |
@Override |
|
64 |
public void onCreate(Bundle savedInstanceState) |
|
65 |
{ |
|
66 |
super.onCreate(savedInstanceState); |
|
67 |
|
|
68 |
setTheme(R.style.MaterialThemeNoActionBar); |
|
69 |
setContentView(R.layout.main); |
|
70 |
|
|
71 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
72 |
getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics); |
|
73 |
mScreenWidth =displaymetrics.widthPixels; |
|
74 |
mScreenHeight=displaymetrics.heightPixels; |
|
75 |
|
|
76 |
hideNavigationBar(); |
|
77 |
cutoutHack(); |
|
78 |
|
|
79 |
LinearLayout upper = findViewById(R.id.upper_layout); |
|
80 |
createUpperLayout(upper); |
|
81 |
|
|
82 |
/* |
|
83 |
final List<Map<String, Object>> data = new ArrayList<>(); |
|
84 |
final SparseArray<Class<? extends Activity>> activityMapping = new SparseArray<>(); |
|
85 |
|
|
86 |
int index=0; |
|
87 |
|
|
88 |
for( Application app : Application.values() ) |
|
89 |
{ |
|
90 |
final Map<String, Object> item = new HashMap<>(); |
|
91 |
item.put(ITEM_IMAGE, app.icon); |
|
92 |
item.put(ITEM_TITLE, (index+1)+". "+getText(app.title)); |
|
93 |
item.put(ITEM_SUBTITLE, getText(app.subtitle)); |
|
94 |
data.add(item); |
|
95 |
activityMapping.put(index++, app.activity); |
|
96 |
} |
|
97 |
|
|
98 |
final SimpleAdapter dataAdapter = new SimpleAdapter( this, |
|
99 |
data, |
|
100 |
R.layout.toc_item, |
|
101 |
new String[] {ITEM_IMAGE, ITEM_TITLE, ITEM_SUBTITLE}, |
|
102 |
new int[] {R.id.Image, R.id.Title, R.id.SubTitle} ); |
|
103 |
setListAdapter(dataAdapter); |
|
104 |
|
|
105 |
getListView().setOnItemClickListener(new OnItemClickListener() |
|
106 |
{ |
|
107 |
@Override |
|
108 |
public void onItemClick(AdapterView<?> parent, View view, int position, long id) |
|
109 |
{ |
|
110 |
final Class<? extends Activity> activityToLaunch = activityMapping.get(position); |
|
111 |
|
|
112 |
if (activityToLaunch != null) |
|
113 |
{ |
|
114 |
final Intent launchIntent = new Intent(SokobanActivity.this, activityToLaunch); |
|
115 |
startActivity(launchIntent); |
|
116 |
} |
|
117 |
} |
|
118 |
}); |
|
119 |
|
|
120 |
*/ |
|
121 |
} |
|
122 |
|
|
123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
124 |
|
|
125 |
@Override |
|
126 |
public void onAttachedToWindow() |
|
127 |
{ |
|
128 |
super.onAttachedToWindow(); |
|
129 |
|
|
130 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) |
|
131 |
{ |
|
132 |
DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout(); |
|
133 |
int insetHeight = cutout!=null ? cutout.getSafeInsetTop() : 0; |
|
134 |
LinearLayout layoutHid = findViewById(R.id.hiddenBar); |
|
135 |
ViewGroup.LayoutParams paramsHid = layoutHid.getLayoutParams(); |
|
136 |
paramsHid.height = (int)(insetHeight*RATIO_INSET); |
|
137 |
layoutHid.setLayoutParams(paramsHid); |
|
138 |
mHeightUpperBar += paramsHid.height; |
|
139 |
} |
|
140 |
} |
|
141 |
|
|
142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
143 |
|
|
144 |
@Override |
|
145 |
public void onWindowFocusChanged(boolean hasFocus) |
|
146 |
{ |
|
147 |
super.onWindowFocusChanged(hasFocus); |
|
148 |
|
|
149 |
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus) |
|
150 |
{ |
|
151 |
getWindow().getDecorView().setSystemUiVisibility(FLAGS); |
|
152 |
} |
|
153 |
} |
|
154 |
|
|
155 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
156 |
|
|
157 |
private void createUpperLayout(LinearLayout upper) |
|
158 |
{ |
|
159 |
mHeightUpperBar = (int)(mScreenHeight*RATIO_BAR); |
|
160 |
ViewGroup.LayoutParams paramsTop = upper.getLayoutParams(); |
|
161 |
paramsTop.height = mHeightUpperBar; |
|
162 |
upper.setLayoutParams(paramsTop); |
|
163 |
|
|
164 |
setupRecordsButton(); |
|
165 |
upper.addView(mRecordsButton); |
|
166 |
setupAppName(); |
|
167 |
upper.addView(mAppName); |
|
168 |
setupExitButton(); |
|
169 |
upper.addView(mExitButton); |
|
170 |
} |
|
171 |
|
|
172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
173 |
|
|
174 |
private void setupRecordsButton() |
|
175 |
{ |
|
176 |
final int icon = getDrawable(R.drawable.ui_records_s,R.drawable.ui_records_m, R.drawable.ui_records_b, R.drawable.ui_records_h); |
|
177 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
178 |
mRecordsButton = new TransparentImageButton(this, icon, TransparentImageButton.GRAVITY_MIDDLE, params); |
|
179 |
|
|
180 |
mRecordsButton.setOnClickListener( new View.OnClickListener() |
|
181 |
{ |
|
182 |
@Override |
|
183 |
public void onClick(View view) |
|
184 |
{ |
|
185 |
|
|
186 |
} |
|
187 |
}); |
|
188 |
} |
|
189 |
|
|
190 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
191 |
|
|
192 |
private void setupExitButton() |
|
193 |
{ |
|
194 |
final int icon = getDrawable(R.drawable.ui_exit_s,R.drawable.ui_exit_m, R.drawable.ui_exit_b, R.drawable.ui_exit_h); |
|
195 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f); |
|
196 |
mExitButton = new TransparentImageButton(this, icon, TransparentImageButton.GRAVITY_MIDDLE, params); |
|
197 |
|
|
198 |
mExitButton.setOnClickListener( new View.OnClickListener() |
|
199 |
{ |
|
200 |
@Override |
|
201 |
public void onClick(View view) |
|
202 |
{ |
|
203 |
finish(); |
|
204 |
} |
|
205 |
}); |
|
206 |
} |
|
207 |
|
|
208 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
209 |
|
|
210 |
private void setupAppName() |
|
211 |
{ |
|
212 |
int titleSize = (int)(mScreenWidth*MENU_SIZE); |
|
213 |
mAppName = new TextView(this); |
|
214 |
mAppName.setText(R.string.app_name); |
|
215 |
mAppName.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize); |
|
216 |
} |
|
217 |
|
|
218 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
219 |
|
|
220 |
private void hideNavigationBar() |
|
221 |
{ |
|
222 |
mCurrentApiVersion = Build.VERSION.SDK_INT; |
|
223 |
|
|
224 |
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT) |
|
225 |
{ |
|
226 |
final View decorView = getWindow().getDecorView(); |
|
227 |
decorView.setSystemUiVisibility(FLAGS); |
|
228 |
|
|
229 |
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() |
|
230 |
{ |
|
231 |
@Override |
|
232 |
public void onSystemUiVisibilityChange(int visibility) |
|
233 |
{ |
|
234 |
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) |
|
235 |
{ |
|
236 |
decorView.setSystemUiVisibility(FLAGS); |
|
237 |
} |
|
238 |
} |
|
239 |
}); |
|
240 |
} |
|
241 |
} |
|
242 |
|
|
243 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
244 |
// do not avoid cutouts |
|
245 |
|
|
246 |
private void cutoutHack() |
|
247 |
{ |
|
248 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) |
|
249 |
{ |
|
250 |
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; |
|
251 |
} |
|
252 |
} |
|
253 |
|
|
254 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
255 |
|
|
256 |
public int getHeightUpperBar() |
|
257 |
{ |
|
258 |
return mHeightUpperBar; |
|
259 |
} |
|
260 |
|
|
261 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
262 |
|
|
263 |
public int getScreenWidthInPixels() |
|
264 |
{ |
|
265 |
return mScreenWidth; |
|
266 |
} |
|
267 |
|
|
268 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
269 |
|
|
270 |
public int getScreenHeightInPixels() |
|
271 |
{ |
|
272 |
return mScreenHeight; |
|
273 |
} |
|
274 |
|
|
275 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
276 |
|
|
277 |
public static int getDrawableSize() |
|
278 |
{ |
|
279 |
if( mScreenHeight<1000 ) |
|
280 |
{ |
|
281 |
return 0; |
|
282 |
} |
|
283 |
if( mScreenHeight<1600 ) |
|
284 |
{ |
|
285 |
return 1; |
|
286 |
} |
|
287 |
if( mScreenHeight<1900 ) |
|
288 |
{ |
|
289 |
return 2; |
|
290 |
} |
|
291 |
return 3; |
|
292 |
} |
|
293 |
|
|
294 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
295 |
|
|
296 |
public static int getDrawable(int small, int medium, int big, int huge) |
|
297 |
{ |
|
298 |
int size = getDrawableSize(); |
|
299 |
|
|
300 |
switch(size) |
|
301 |
{ |
|
302 |
case 0 : return small; |
|
303 |
case 1 : return medium; |
|
304 |
case 2 : return big; |
|
305 |
default: return huge; |
|
306 |
} |
|
307 |
} |
|
308 |
} |
distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanCanvas.java | ||
---|---|---|
75 | 75 |
private GraphicsThread mThread; |
76 | 76 |
public static String mVersionStr=""; |
77 | 77 |
private Paint mPaint = new Paint(); |
78 |
private static int isKorean; |
|
79 |
|
|
78 |
|
|
80 | 79 |
private class GraphicsThread extends Thread |
81 | 80 |
{ |
82 | 81 |
private SurfaceHolder mSurfaceHolder; |
... | ... | |
191 | 190 |
Log.d(TAG_CANVAS, "init"); |
192 | 191 |
|
193 | 192 |
Resources res = act.getResources(); |
194 |
isKorean = res.getInteger(R.integer.is_korean); |
|
195 |
|
|
196 |
if( scrWidth<=0 || scrHeight<=0 ) |
|
193 |
|
|
194 |
if( scrWidth<=0 || scrHeight<=0 ) |
|
197 | 195 |
{ |
198 | 196 |
DisplayMetrics dm = new DisplayMetrics(); |
199 | 197 |
act.getWindowManager().getDefaultDisplay().getMetrics(dm); |
... | ... | |
453 | 451 |
|
454 | 452 |
public static String getIso() |
455 | 453 |
{ |
456 |
if( isKorean==1 ) |
|
457 |
{ |
|
458 |
return "kr"; |
|
459 |
} |
|
460 |
else |
|
461 |
{ |
|
462 |
String ret=""; |
|
454 |
String ret=""; |
|
463 | 455 |
|
464 | 456 |
TelephonyManager tM =((TelephonyManager) mAct.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE)); |
465 | 457 |
|
... | ... | |
474 | 466 |
} |
475 | 467 |
|
476 | 468 |
return ret; |
477 |
} |
|
478 | 469 |
} |
479 | 470 |
|
480 | 471 |
/////////////////////////////////////////////////////////////////// |
distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanDatabase.java | ||
---|---|---|
6 | 6 |
import android.util.Log; |
7 | 7 |
import android.app.Activity; |
8 | 8 |
|
9 |
import java.lang.ref.WeakReference; |
|
9 | 10 |
import java.util.Map; |
10 | 11 |
|
11 | 12 |
/////////////////////////////////////////////////////////////////// |
... | ... | |
29 | 30 |
private static String iso = null; |
30 | 31 |
|
31 | 32 |
private static SokobanLevels mLevels; |
32 |
private static SokobanDatabase rms =null; |
|
33 |
|
|
34 |
private static Context context; |
|
33 |
private static SokobanDatabase mThis =null; |
|
34 |
private final WeakReference<Context> mContext; |
|
35 | 35 |
|
36 | 36 |
|
37 | 37 |
private static final String[] bl = new String[] |
... | ... | |
631 | 631 |
|
632 | 632 |
private SokobanDatabase( Context co ) |
633 | 633 |
{ |
634 |
context= co;
|
|
634 |
mContext = new WeakReference<>(co);
|
|
635 | 635 |
|
636 | 636 |
mLevels = SokobanLevels.getInstance(); |
637 | 637 |
numrunnings = 0; |
... | ... | |
643 | 643 |
|
644 | 644 |
for(int i=0; i<BUILTIN_LEVELS; i++) |
645 | 645 |
{ |
646 |
int xlen = Integer.valueOf(bl[2*i]).intValue();
|
|
646 |
int xlen = Integer.parseInt(bl[2*i]);
|
|
647 | 647 |
SokobanLevel sl = new SokobanLevel( null, null, INVALID, INVALID, null, false,xlen, bl[2*i+1]); |
648 | 648 |
mLevels.addLevel(sl,i); |
649 | 649 |
} |
... | ... | |
652 | 652 |
|
653 | 653 |
try |
654 | 654 |
{ |
655 |
SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
|
655 |
SharedPreferences settings = co.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); |
|
656 | 656 |
readPreferences(settings); |
657 | 657 |
} |
658 | 658 |
catch( Exception ex ) |
... | ... | |
1012 | 1012 |
|
1013 | 1013 |
try |
1014 | 1014 |
{ |
1015 |
String s = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); |
|
1015 |
Context co = mContext.get(); |
|
1016 |
String s = Secure.getString(co.getContentResolver(), Secure.ANDROID_ID); |
|
1016 | 1017 |
ret = s!=null ? s.hashCode():0; |
1017 | 1018 |
} |
1018 | 1019 |
catch(Exception ex) |
... | ... | |
1026 | 1027 |
|
1027 | 1028 |
/////////////////////////////////////////////////////////////////// |
1028 | 1029 |
|
1029 |
public static boolean saveValues()
|
|
1030 |
public boolean saveValues() |
|
1030 | 1031 |
{ |
1031 | 1032 |
//Log.e(TAG_DB, "saveValues: "+finishedBootup); |
1032 | 1033 |
|
1033 |
if( finishedBootup==false ) return false;
|
|
1034 |
if( !finishedBootup ) return false;
|
|
1034 | 1035 |
|
1035 | 1036 |
boolean ret = false; |
1036 | 1037 |
|
... | ... | |
1040 | 1041 |
|
1041 | 1042 |
try |
1042 | 1043 |
{ |
1043 |
SharedPreferences settings = context.getSharedPreferences(PREFS_NAME,Context.MODE_PRIVATE); |
|
1044 |
Context co = mContext.get(); |
|
1045 |
SharedPreferences settings = co.getSharedPreferences(PREFS_NAME,Context.MODE_PRIVATE); |
|
1044 | 1046 |
SharedPreferences.Editor editor = settings.edit(); |
1045 | 1047 |
|
1046 | 1048 |
editor.putString("1", username); |
... | ... | |
1112 | 1114 |
|
1113 | 1115 |
public static void init(Activity act) |
1114 | 1116 |
{ |
1115 |
rms = new SokobanDatabase((Context)act);
|
|
1117 |
if( mThis==null ) mThis = new SokobanDatabase((Context)act);
|
|
1116 | 1118 |
} |
1117 | 1119 |
|
1118 | 1120 |
/////////////////////////////////////////////////////////////////// |
... | ... | |
1201 | 1203 |
|
1202 | 1204 |
public static SokobanDatabase getInstance() |
1203 | 1205 |
{ |
1204 |
return rms;
|
|
1206 |
return mThis;
|
|
1205 | 1207 |
} |
1206 | 1208 |
|
1207 | 1209 |
/////////////////////////////////////////////////////////////////// |
distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanLevels.java | ||
---|---|---|
133 | 133 |
mPaint = new Paint(); |
134 | 134 |
mPaint.setStyle(Style.FILL); |
135 | 135 |
|
136 |
mLevels = new Vector<SokobanLevel>();
|
|
137 |
mFlags = new Vector<Flag>();
|
|
136 |
mLevels = new Vector<>(); |
|
137 |
mFlags = new Vector<>(); |
|
138 | 138 |
|
139 | 139 |
createImages(); |
140 | 140 |
|
... | ... | |
146 | 146 |
|
147 | 147 |
public static void init(Activity act) |
148 | 148 |
{ |
149 |
if( scrWidth<=0 || scrHeight<=0 )
|
|
149 |
if( scrWidth<=0 || scrHeight<=0 ) |
|
150 | 150 |
{ |
151 | 151 |
DisplayMetrics dm = new DisplayMetrics(); |
152 | 152 |
act.getWindowManager().getDefaultDisplay().getMetrics(dm); |
... | ... | |
155 | 155 |
scrHeight= Math.max(dm.widthPixels,dm.heightPixels); |
156 | 156 |
} |
157 | 157 |
|
158 |
levels = new SokobanLevels((Context)act);
|
|
158 |
levels = new SokobanLevels((Context)act); |
|
159 | 159 |
} |
160 | 160 |
|
161 | 161 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
162 | 162 |
|
163 | 163 |
private void createImages() |
164 | 164 |
{ |
165 |
NinePatchDrawable play,pack,dpck,levl, dpck_small, pack_small, dialog, dlgred;
|
|
165 |
NinePatchDrawable play,pack,dpck,levl, dpck_small, pack_small, dialog, dlgred; |
|
166 | 166 |
Canvas c; |
167 | 167 |
|
168 |
try
|
|
168 |
try |
|
169 | 169 |
{ |
170 | 170 |
play = (NinePatchDrawable)res.getDrawable(R.drawable.play); |
171 | 171 |
pack = (NinePatchDrawable)res.getDrawable(R.drawable.pack); |
... | ... | |
176 | 176 |
dpck_small = (NinePatchDrawable)res.getDrawable(R.drawable.dpck_small); |
177 | 177 |
|
178 | 178 |
dialog = (NinePatchDrawable)res.getDrawable(R.drawable.dialog); |
179 |
dlgred = (NinePatchDrawable)res.getDrawable(R.drawable.dialog_clicked); |
|
180 |
|
|
179 |
dlgred = (NinePatchDrawable)res.getDrawable(R.drawable.dialog_clicked); |
|
181 | 180 |
} |
182 | 181 |
catch( Exception ex ) { Log.e(TAG_LEVELS, "Failed to create 9Patches!"); return; } |
183 | 182 |
|
distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanMain.java | ||
---|---|---|
5 | 5 |
import android.util.Log; |
6 | 6 |
import android.view.ViewGroup; |
7 | 7 |
|
8 |
import com.google.firebase.analytics.FirebaseAnalytics; |
|
9 |
import com.google.firebase.inappmessaging.FirebaseInAppMessaging; |
|
10 |
|
|
11 |
import org.distorted.messaging.SokobanInAppMessanging; |
|
12 |
|
|
8 | 13 |
/////////////////////////////////////////////////////////////////// |
9 | 14 |
|
10 | 15 |
public class SokobanMain extends Activity |
... | ... | |
12 | 17 |
private static final String TAG_MAIN = "SokobanMain"; |
13 | 18 |
private SokobanCanvas rrc=null; |
14 | 19 |
private int runningTime = -1; |
15 |
|
|
20 |
private FirebaseAnalytics mFirebaseAnalytics; |
|
21 |
|
|
16 | 22 |
/////////////////////////////////////////////////////////////////// |
17 | 23 |
|
18 |
public void onCreate(Bundle savedInstanceState)
|
|
24 |
public void onCreate(Bundle savedInstanceState)
|
|
19 | 25 |
{ |
20 |
super.onCreate(savedInstanceState); |
|
21 |
Log.d( TAG_MAIN, "onCreate"); |
|
22 |
initCanvas(); |
|
23 |
} |
|
26 |
super.onCreate(savedInstanceState); |
|
27 |
Log.d( TAG_MAIN, "onCreate"); |
|
28 |
initCanvas(); |
|
29 |
|
|
30 |
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); |
|
31 |
SokobanInAppMessanging listener = new SokobanInAppMessanging(); |
|
32 |
FirebaseInAppMessaging.getInstance().addClickListener(listener); |
|
33 |
} |
|
24 | 34 |
|
25 | 35 |
/////////////////////////////////////////////////////////////////// |
26 | 36 |
|
27 | 37 |
public void onStart() |
28 |
{
|
|
38 |
{
|
|
29 | 39 |
super.onStart(); |
30 | 40 |
Log.d( TAG_MAIN, "onStart"); |
31 | 41 |
if( !SokobanCanvas.isCreated() ) initCanvas(); |
32 | 42 |
if( rrc!=null ) SokobanCanvas.setRepaint(); |
33 |
} |
|
43 |
}
|
|
34 | 44 |
|
35 | 45 |
/////////////////////////////////////////////////////////////////// |
36 | 46 |
|
... | ... | |
40 | 50 |
|
41 | 51 |
if( SokobanCanvas.getDestroy() ) |
42 | 52 |
{ |
43 |
SokobanDatabase.saveValues(); |
|
53 |
SokobanDatabase db = SokobanDatabase.getInstance(); |
|
54 |
db.saveValues(); |
|
44 | 55 |
if( rrc!=null ) rrc.deallocate(); |
45 | 56 |
System.gc(); |
46 | 57 |
} |
... | ... | |
102 | 113 |
} |
103 | 114 |
else setContentView(R.layout.error); |
104 | 115 |
} |
105 |
|
|
116 |
|
|
117 |
/////////////////////////////////////////////////////////////////// |
|
118 |
|
|
119 |
public FirebaseAnalytics getAnalytics() |
|
120 |
{ |
|
121 |
return mFirebaseAnalytics; |
|
122 |
} |
|
123 |
|
|
106 | 124 |
/////////////////////////////////////////////////////////////////// |
107 | 125 |
// end of file |
108 | 126 |
} |
distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanMenu.java | ||
---|---|---|
13 | 13 |
import android.content.Context; |
14 | 14 |
import android.content.res.Resources; |
15 | 15 |
|
16 |
import org.distorted.keyboard.StringBlock; |
|
17 |
import org.distorted.keyboard.TouchKeyboard; |
|
18 |
|
|
16 | 19 |
//import android.util.Log; |
17 | 20 |
|
18 | 21 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
57 | 60 |
private int dialogX,dialogY0,dialogY1,dialogY2,dialogY3,dialogM; |
58 | 61 |
private TouchKeyboard tkb = null; |
59 | 62 |
private static int nameChangeAction =ACTION_NONE; |
60 |
private SokobanStringBlock blockHelptext;
|
|
63 |
private StringBlock blockHelptext; |
|
61 | 64 |
|
62 | 65 |
private int softkeyState = SOFT_NOT; |
63 | 66 |
private int comeBackState=SokobanCanvas.STATE_MAIN; |
... | ... | |
780 | 783 |
if( blockHelptext==null ) |
781 | 784 |
{ |
782 | 785 |
int helpHeight = dialogY0-3*gap-mFontH-sFontH; |
783 |
blockHelptext = new SokobanStringBlock( strHelptxt, helpHeight, len-2*gap);
|
|
786 |
blockHelptext = new StringBlock( strHelptxt, helpHeight, len-2*gap); |
|
784 | 787 |
} |
785 | 788 |
blockHelptext.draw(c,(scrWidth-len)/2+gap,(scrHeight-dialogY0)/2+mFontH+sFontH+2*gap, SokobanCanvas.COLOR_BLACK); |
786 | 789 |
} |
distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanRecords.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
private static boolean mRunning; |
28 | 28 |
private static boolean mDirtyRecords; |
29 |
private static Thread mNetworkThrd = null; |
|
30 | 29 |
private static int mode; |
31 | 30 |
|
32 | 31 |
private static int lv; |
... | ... | |
97 | 96 |
if( !mRunning ) |
98 | 97 |
{ |
99 | 98 |
mRunning = true; |
100 |
mNetworkThrd = new Thread(this); |
|
101 |
mNetworkThrd.start(); |
|
102 |
|
|
99 |
Thread networkThrd = new Thread(this); |
|
100 |
networkThrd.start(); |
|
103 | 101 |
return true; |
104 | 102 |
} |
105 | 103 |
|
... | ... | |
321 | 319 |
private void fillLevelsData( String data ) |
322 | 320 |
{ |
323 | 321 |
int len = data.length(); |
324 |
int begin=-1 ,end = -1;
|
|
322 |
int begin=-1 ,end; |
|
325 | 323 |
|
326 | 324 |
while( begin<len ) |
327 | 325 |
{ |
... | ... | |
348 | 346 |
{ |
349 | 347 |
try |
350 | 348 |
{ |
351 |
int level= Integer.valueOf( row.substring( 0,s1) ).intValue();
|
|
349 |
int level= Integer.parseInt( row.substring( 0,s1) );
|
|
352 | 350 |
String n = row.substring(s1+1,s2); |
353 | 351 |
String c = row.substring(s2+1,s3); |
354 |
// int rows = Integer.valueOf( row.substring(s3+1,s4) ).intValue();
|
|
355 |
int cols = Integer.valueOf( row.substring(s4+1,s5) ).intValue();
|
|
352 |
// int rows = Integer.parseInt( row.substring(s3+1,s4) );
|
|
353 |
int cols = Integer.parseInt( row.substring(s4+1,s5) );
|
|
356 | 354 |
String p = row.substring(s5+1,s6); |
357 | 355 |
|
358 | 356 |
SokobanLevel sl = new SokobanLevel(n,c,SokobanDatabase.INVALID, SokobanDatabase.INVALID,null,false,cols,p); |
... | ... | |
368 | 366 |
private void fillData( String data ) |
369 | 367 |
{ |
370 | 368 |
int len = data.length(); |
371 |
int begin=-1 ,end = -1;
|
|
369 |
int begin=-1 ,end; |
|
372 | 370 |
|
373 | 371 |
while( begin<len ) |
374 | 372 |
{ |
... | ... | |
397 | 395 |
{ |
398 | 396 |
try |
399 | 397 |
{ |
400 |
int l = Integer.valueOf( row.substring( 0,s1) ).intValue();
|
|
401 |
int m = Integer.valueOf( row.substring(s1+1,s2) ).intValue();
|
|
402 |
int t = Integer.valueOf( row.substring(s2+1,s3) ).intValue();
|
|
403 |
int p = Integer.valueOf( row.substring(s3+1,s4) ).intValue();
|
|
398 |
int l = Integer.parseInt(row.substring( 0,s1));
|
|
399 |
int m = Integer.parseInt(row.substring(s1+1,s2));
|
|
400 |
int t = Integer.parseInt(row.substring(s2+1,s3));
|
|
401 |
int p = Integer.parseInt(row.substring(s3+1,s4));
|
|
404 | 402 |
String n = row.substring(s4+1,s5); |
405 | 403 |
String c = row.substring(s5+1,s6); |
406 | 404 |
|
... | ... | |
423 | 421 |
|
424 | 422 |
public void downloadRecords() |
425 | 423 |
{ |
426 |
if( mDirtyRecords==true )
|
|
424 |
if( mDirtyRecords ) |
|
427 | 425 |
{ |
428 | 426 |
mode = DOWNLOADR; |
429 | 427 |
name = SokobanDatabase.getName(); |
... | ... | |
488 | 486 |
{ |
489 | 487 |
if( s==null ) return ""; |
490 | 488 |
|
491 |
StringBuffer sbuf = new StringBuffer();
|
|
489 |
StringBuilder sbuf = new StringBuilder();
|
|
492 | 490 |
int len = s.length(); |
493 | 491 |
|
494 | 492 |
for (int i = 0; i < len; i++) |
distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanSplash.java | ||
---|---|---|
1 |
package org.distorted.sokoban; |
|
2 |
|
|
3 |
import android.app.Activity; |
|
4 |
import android.content.Intent; |
|
5 |
import android.os.Bundle; |
|
6 |
import android.util.Log; |
|
7 |
|
|
8 |
import com.google.firebase.analytics.FirebaseAnalytics; |
|
9 |
import com.google.firebase.inappmessaging.FirebaseInAppMessaging; |
|
10 |
|
|
11 |
import org.distorted.messaging.SokobanInAppMessanging; |
|
12 |
|
|
13 |
/////////////////////////////////////////////////////////////////// |
|
14 |
|
|
15 |
public class SokobanSplash extends Activity |
|
16 |
{ |
|
17 |
private int sleepTime=2000; |
|
18 |
|
|
19 |
private class SplashThread extends Thread |
|
20 |
{ |
|
21 |
private boolean bootup=true; |
|
22 |
|
|
23 |
public void run() |
|
24 |
{ |
|
25 |
int milis=0; |
|
26 |
|
|
27 |
while(bootup) |
|
28 |
{ |
|
29 |
try |
|
30 |
{ |
|
31 |
milis+=100; |
|
32 |
Thread.sleep(100); |
|
33 |
} |
|
34 |
catch( InterruptedException ex) { } |
|
35 |
} |
|
36 |
|
|
37 |
if( milis<sleepTime ) |
|
38 |
{ |
|
39 |
try |
|
40 |
{ |
|
41 |
Thread.sleep(sleepTime-milis); |
|
42 |
} |
|
43 |
catch( InterruptedException ex) { } |
|
44 |
} |
|
45 |
|
|
46 |
finish(); |
|
47 |
Intent mainInt = new Intent( getApplicationContext(), SokobanActivity.class); |
|
48 |
startActivity(mainInt); |
|
49 |
} |
|
50 |
public void bootupReady() |
|
51 |
{ |
|
52 |
bootup=false; |
|
53 |
} |
|
54 |
}; |
|
55 |
|
|
56 |
/////////////////////////////////////////////////////////////////// |
|
57 |
|
|
58 |
public void onCreate(Bundle savedInstanceState) |
|
59 |
{ |
|
60 |
super.onCreate(savedInstanceState); |
|
61 |
setContentView(R.layout.splash); |
|
62 |
sleepTime=2000; |
|
63 |
} |
|
64 |
|
|
65 |
/////////////////////////////////////////////////////////////////// |
|
66 |
|
|
67 |
public void onStart() |
|
68 |
{ |
|
69 |
super.onStart(); |
|
70 |
|
|
71 |
SplashThread splashThread = new SplashThread(); |
|
72 |
splashThread.start(); |
|
73 |
|
|
74 |
SokobanLevels.init(this); |
|
75 |
SokobanLevels sl = SokobanLevels.getInstance(); |
|
76 |
|
|
77 |
SokobanCanvas.init(this); |
|
78 |
SokobanCanvas.setActivity(this); |
|
79 |
|
|
80 |
SokobanDatabase.init(this); |
|
81 |
SokobanTimer.init(); |
|
82 |
SokobanCanvas.setLevels(sl); |
|
83 |
SokobanRecords.setLevels(sl); |
|
84 |
|
|
85 |
splashThread.bootupReady(); |
|
86 |
} |
|
87 |
|
|
88 |
/////////////////////////////////////////////////////////////////// |
|
89 |
// end of file |
|
90 |
} |
distorted-sokoban/src/main/java/org/distorted/sokoban/SokobanStringBlock.java | ||
---|---|---|
1 |
package org.distorted.sokoban; |
|
2 |
|
|
3 |
import android.graphics.Canvas; |
|
4 |
import android.graphics.Paint; |
|
5 |
import android.graphics.Paint.Align; |
|
6 |
|
|
7 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
8 |
|
|
9 |
public class SokobanStringBlock |
|
10 |
{ |
|
11 |
//private static final String TAG_BLOCK="SokobanStringBlock"; |
|
12 |
|
|
13 |
private String str; |
|
14 |
private int height,length; |
|
15 |
private int realheight; |
|
16 |
private int size, len; |
|
17 |
private Paint mPaint; |
|
18 |
private String buffer; |
|
19 |
|
|
20 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
21 |
|
|
22 |
public SokobanStringBlock(String s, int h, int l) |
|
23 |
{ |
|
24 |
str =s; |
|
25 |
length =l; |
|
26 |
height =h; |
|
27 |
len = str.length(); |
|
28 |
|
|
29 |
mPaint = new Paint(); |
|
30 |
buffer = new String(); |
|
31 |
|
|
32 |
mPaint.setTextAlign(Align.LEFT); |
|
33 |
mPaint.setAntiAlias(true); |
|
34 |
mPaint.setFakeBoldText(true); |
|
35 |
|
|
36 |
size = computeOptimalSize(); |
|
37 |
} |
|
38 |
|
|
39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
40 |
|
|
41 |
public void draw(Canvas c, int x,int y, int color) |
|
42 |
{ |
|
43 |
String tmp; |
|
44 |
int begin=0, end=0; |
|
45 |
int delta = (height-realheight)/2; |
|
46 |
|
|
47 |
mPaint.setColor(color); |
|
48 |
mPaint.setTextSize(size); |
|
49 |
|
|
50 |
while( end>=0 && end<len ) |
|
51 |
{ |
|
52 |
end = getLine(str,size,begin,length); |
|
53 |
|
|
54 |
if( end>=0 ) |
|
55 |
{ |
|
56 |
if( str.charAt(begin) == '\n' ) begin++; |
|
57 |
|
|
58 |
if( end>begin ) |
|
59 |
{ |
|
60 |
tmp = str.substring(begin,end); |
|
61 |
|
|
62 |
if( end<len && str.charAt(end+1) != '\n' ) |
|
63 |
displayJustified( tmp, size, x, y+delta, length, c); |
|
64 |
else |
|
65 |
c.drawText( tmp, x, y+delta+size, mPaint); |
|
66 |
} |
|
67 |
|
|
68 |
y += (begin==end ? size/2 : size); |
|
69 |
begin = end; |
|
70 |
} |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
75 |
|
|
76 |
private void displayJustified(String str, int fontHeight, int x, int y, int length, Canvas c) |
|
77 |
{ |
|
78 |
int len = str.length(); |
|
79 |
int numspaces = retNumSpaces(str); |
|
80 |
|
|
81 |
if( str.charAt(len-1) == ' ' ) numspaces--; |
|
82 |
|
|
83 |
float left=x,w = (numspaces>0 ? (float)(length-mPaint.measureText(str))/numspaces : 0); |
|
84 |
String tmp; |
|
85 |
int begin,end=0; |
|
86 |
|
|
87 |
while( end<len ) |
|
88 |
{ |
|
89 |
begin=end; |
|
90 |
end = str.indexOf(' ', begin)+1; |
|
91 |
if( end<=0 ) end = len; |
|
92 |
|
|
93 |
tmp = str.substring(begin,end); |
|
94 |
c.drawText( tmp, left, y+fontHeight, mPaint); |
|
95 |
left+= (mPaint.measureText(tmp)+w); |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
private int retNumSpaces(String str) |
|
102 |
{ |
|
103 |
int begin=0, ret=0; |
|
104 |
|
|
105 |
while( true ) |
|
106 |
{ |
|
107 |
begin = str.indexOf(' ', begin) +1; |
|
108 |
|
|
109 |
if( begin>0 ) ret++; |
|
110 |
else break; |
|
111 |
} |
|
112 |
|
|
113 |
return ret; |
|
114 |
} |
|
115 |
|
|
116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
117 |
|
|
118 |
private int getLine(String text, int fontHeight, int begin, int width) |
|
119 |
{ |
|
120 |
int nearestSpace = text.indexOf(' ' , begin+1); |
|
121 |
int nearestNewline = text.indexOf('\n', begin+1); |
|
122 |
int len=0; |
|
123 |
|
|
124 |
mPaint.setTextSize(fontHeight); |
|
125 |
|
|
126 |
if( nearestNewline>=0 && nearestNewline<nearestSpace ) return nearestNewline; |
|
127 |
if( nearestSpace<0 ) return text.length(); |
|
128 |
|
|
129 |
buffer = text.substring(begin,nearestSpace); |
|
130 |
|
|
131 |
len = (int)mPaint.measureText(buffer); |
|
132 |
|
|
133 |
if( len>=width ) return nearestSpace+1; |
|
134 |
|
|
135 |
int lastSpace = nearestSpace; |
|
136 |
|
|
137 |
while( len<width ) |
|
138 |
{ |
|
139 |
lastSpace = nearestSpace; |
|
140 |
|
|
141 |
nearestNewline = text.indexOf('\n', lastSpace+1); |
|
142 |
nearestSpace = text.indexOf(' ' , lastSpace+1); |
|
143 |
|
|
144 |
if( nearestNewline>=0 && nearestNewline<nearestSpace ) |
|
145 |
{ |
|
146 |
buffer = text.substring(begin,nearestNewline); |
|
147 |
len = (int)mPaint.measureText(buffer); |
|
148 |
return len<width ? nearestNewline : lastSpace+1; |
|
149 |
} |
|
150 |
if( nearestSpace<0 ) |
|
151 |
{ |
|
152 |
buffer = text.substring(begin); |
|
153 |
len= (int)mPaint.measureText(buffer); |
|
154 |
return len<width ? text.length() : lastSpace+1; |
|
155 |
} |
|
156 |
|
|
157 |
buffer = text.substring(begin,nearestSpace); |
|
158 |
len = (int)mPaint.measureText(buffer); |
|
159 |
} |
|
160 |
return lastSpace+1; |
|
161 |
} |
|
162 |
|
|
163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
164 |
|
|
165 |
private int computeOptimalSize() |
|
166 |
{ |
|
167 |
int h=0, trysize=10; |
|
168 |
|
|
169 |
while( h<height ) |
|
170 |
{ |
|
171 |
realheight = h; |
|
172 |
h = height(++trysize); |
|
173 |
} |
|
174 |
|
|
175 |
return trysize-1; |
|
176 |
} |
Also available in: Unified diff
Lots of progress