Revision 7ee8337b
Added by Leszek Koltunski about 2 years ago
| src/main/AndroidManifest.xml | ||
|---|---|---|
| 32 | 32 |
|
| 33 | 33 |
<activity android:name="org.distorted.tutorials.TutorialActivity" android:exported="false" android:screenOrientation="portrait"/> |
| 34 | 34 |
<activity android:name="org.distorted.config.ConfigActivity" android:exported="false" android:screenOrientation="portrait"/> |
| 35 |
<activity android:name="org.distorted.bandaged.BandagedCreatorActivity" android:exported="false" android:screenOrientation="portrait"/> |
|
| 36 |
<activity android:name="org.distorted.bandaged.BandagedPlayActivity" android:exported="false" android:screenOrientation="portrait"/> |
|
| 35 |
<activity android:name="org.distorted.bandaged.BandagedActivity" android:exported="false" android:screenOrientation="portrait"/> |
|
| 37 | 36 |
<activity android:name="org.distorted.purchase.PurchaseActivity" android:exported="false" android:screenOrientation="portrait"/> |
| 38 | 37 |
<activity android:name="org.distorted.solverui.SolverActivity" android:exported="false" android:screenOrientation="portrait"/> |
| 39 | 38 |
<activity android:name="org.distorted.patternui.PatternActivity" android:exported="false" android:screenOrientation="portrait"/> |
| 39 |
<activity android:name="org.distorted.playui.PlayActivity" android:exported="false" android:screenOrientation="portrait"/> |
|
| 40 | 40 |
|
| 41 | 41 |
<service |
| 42 | 42 |
android:name="org.distorted.messaging.RubikMessagingService" |
| src/main/java/org/distorted/bandaged/BandagedActivity.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2022 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
| 7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
| 8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 9 |
|
|
| 10 |
package org.distorted.bandaged; |
|
| 11 |
|
|
| 12 |
import static android.view.View.LAYOUT_DIRECTION_RTL; |
|
| 13 |
|
|
| 14 |
import java.io.InputStream; |
|
| 15 |
|
|
| 16 |
import android.content.Intent; |
|
| 17 |
import android.content.SharedPreferences; |
|
| 18 |
import android.content.res.Configuration; |
|
| 19 |
import android.graphics.Bitmap; |
|
| 20 |
import android.os.Build; |
|
| 21 |
import android.os.Bundle; |
|
| 22 |
import android.util.DisplayMetrics; |
|
| 23 |
import android.view.View; |
|
| 24 |
import android.view.ViewGroup; |
|
| 25 |
import android.view.WindowManager; |
|
| 26 |
import android.widget.LinearLayout; |
|
| 27 |
|
|
| 28 |
import androidx.appcompat.app.AppCompatActivity; |
|
| 29 |
import androidx.preference.PreferenceManager; |
|
| 30 |
|
|
| 31 |
import org.distorted.dialogs.RubikDialogError; |
|
| 32 |
import org.distorted.external.RubikFiles; |
|
| 33 |
import org.distorted.library.main.DistortedLibrary; |
|
| 34 |
import org.distorted.main.MainActivity; |
|
| 35 |
import org.distorted.main.R; |
|
| 36 |
import org.distorted.objectlib.main.InitAssets; |
|
| 37 |
import org.distorted.objectlib.main.TwistyJson; |
|
| 38 |
import org.distorted.objectlib.main.TwistyObject; |
|
| 39 |
import org.distorted.os.OSInterface; |
|
| 40 |
import org.distorted.playui.PlayActivity; |
|
| 41 |
|
|
| 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 43 |
|
|
| 44 |
public class BandagedActivity extends AppCompatActivity |
|
| 45 |
{
|
|
| 46 |
private static final int ACTIVITY_NUMBER = 3; |
|
| 47 |
private static final float RATIO_BAR = MainActivity.RATIO_BAR; |
|
| 48 |
private static final float RATIO_BUT = 0.07f; |
|
| 49 |
static final float RATIO_SCROLL = 0.30f; |
|
| 50 |
public static final float SPINNER_TEXT_SIZE = 0.03f; |
|
| 51 |
private static final float PADDING = 0.010f; |
|
| 52 |
public static final int FLAGS = MainActivity.FLAGS; |
|
| 53 |
private static final int NUM_SCRAMBLES = 300; |
|
| 54 |
|
|
| 55 |
private static int mScreenWidth, mScreenHeight; |
|
| 56 |
private int mCurrentApiVersion; |
|
| 57 |
private BandagedScreen mScreen; |
|
| 58 |
private boolean mRTL; |
|
| 59 |
private int mObjectOrdinal; |
|
| 60 |
|
|
| 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 62 |
|
|
| 63 |
@Override |
|
| 64 |
protected void onCreate(Bundle savedState) |
|
| 65 |
{
|
|
| 66 |
super.onCreate(savedState); |
|
| 67 |
|
|
| 68 |
Bundle b = getIntent().getExtras(); |
|
| 69 |
mObjectOrdinal = (b != null) ? b.getInt("obj") : 0;
|
|
| 70 |
|
|
| 71 |
DistortedLibrary.onCreate(ACTIVITY_NUMBER); |
|
| 72 |
setTheme(R.style.MaterialThemeNoActionBar); |
|
| 73 |
setContentView(R.layout.bandaged); |
|
| 74 |
|
|
| 75 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
| 76 |
getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics); |
|
| 77 |
mScreenWidth =displaymetrics.widthPixels; |
|
| 78 |
mScreenHeight=displaymetrics.heightPixels; |
|
| 79 |
|
|
| 80 |
final Configuration config = getResources().getConfiguration(); |
|
| 81 |
final int layoutDirection = config.getLayoutDirection(); |
|
| 82 |
mRTL = layoutDirection==LAYOUT_DIRECTION_RTL; |
|
| 83 |
|
|
| 84 |
hideNavigationBar(); |
|
| 85 |
cutoutHack(); |
|
| 86 |
computeHeights(); |
|
| 87 |
} |
|
| 88 |
|
|
| 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 90 |
// this does not include possible insets |
|
| 91 |
|
|
| 92 |
private void computeHeights() |
|
| 93 |
{
|
|
| 94 |
int barHeight = (int)(mScreenHeight*RATIO_BAR); |
|
| 95 |
int butHeight = (int)(mScreenHeight*RATIO_BUT); |
|
| 96 |
int viewHeight = (int)(mScreenHeight*RATIO_SCROLL); |
|
| 97 |
int objectHeight = (int)(mScreenHeight*(1-RATIO_SCROLL+RATIO_BAR)); |
|
| 98 |
int padding = (int)(mScreenHeight*PADDING); |
|
| 99 |
|
|
| 100 |
LinearLayout botLayout = findViewById(R.id.lowerBar); |
|
| 101 |
ViewGroup.LayoutParams paramsL = botLayout.getLayoutParams(); |
|
| 102 |
paramsL.height = barHeight; |
|
| 103 |
botLayout.setLayoutParams(paramsL); |
|
| 104 |
|
|
| 105 |
LinearLayout butLayout = findViewById(R.id.bandagedCreatorButtons); |
|
| 106 |
ViewGroup.LayoutParams paramsB = butLayout.getLayoutParams(); |
|
| 107 |
paramsB.height = butHeight; |
|
| 108 |
butLayout.setPadding(padding,0,padding,padding); |
|
| 109 |
butLayout.setLayoutParams(paramsB); |
|
| 110 |
|
|
| 111 |
LinearLayout topLayout = findViewById(R.id.bandagedCreatorTopView); |
|
| 112 |
ViewGroup.LayoutParams paramsT = topLayout.getLayoutParams(); |
|
| 113 |
paramsT.height = viewHeight; |
|
| 114 |
topLayout.setPadding(padding,padding,padding,padding); |
|
| 115 |
topLayout.setLayoutParams(paramsT); |
|
| 116 |
|
|
| 117 |
BandagedView creator = findViewById(R.id.bandagedCreatorObjectView); |
|
| 118 |
ViewGroup.LayoutParams paramsC = creator.getLayoutParams(); |
|
| 119 |
paramsC.height = objectHeight; |
|
| 120 |
creator.setLayoutParams(paramsC); |
|
| 121 |
} |
|
| 122 |
|
|
| 123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 124 |
|
|
| 125 |
private void hideNavigationBar() |
|
| 126 |
{
|
|
| 127 |
mCurrentApiVersion = Build.VERSION.SDK_INT; |
|
| 128 |
|
|
| 129 |
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT) |
|
| 130 |
{
|
|
| 131 |
final View decorView = getWindow().getDecorView(); |
|
| 132 |
|
|
| 133 |
decorView.setSystemUiVisibility(FLAGS); |
|
| 134 |
|
|
| 135 |
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() |
|
| 136 |
{
|
|
| 137 |
@Override |
|
| 138 |
public void onSystemUiVisibilityChange(int visibility) |
|
| 139 |
{
|
|
| 140 |
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) |
|
| 141 |
{
|
|
| 142 |
decorView.setSystemUiVisibility(FLAGS); |
|
| 143 |
} |
|
| 144 |
} |
|
| 145 |
}); |
|
| 146 |
} |
|
| 147 |
} |
|
| 148 |
|
|
| 149 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 150 |
// do not avoid cutouts |
|
| 151 |
|
|
| 152 |
private void cutoutHack() |
|
| 153 |
{
|
|
| 154 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) |
|
| 155 |
{
|
|
| 156 |
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; |
|
| 157 |
} |
|
| 158 |
} |
|
| 159 |
|
|
| 160 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 161 |
|
|
| 162 |
@Override |
|
| 163 |
public void onWindowFocusChanged(boolean hasFocus) |
|
| 164 |
{
|
|
| 165 |
super.onWindowFocusChanged(hasFocus); |
|
| 166 |
|
|
| 167 |
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus) |
|
| 168 |
{
|
|
| 169 |
getWindow().getDecorView().setSystemUiVisibility(FLAGS); |
|
| 170 |
} |
|
| 171 |
} |
|
| 172 |
|
|
| 173 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 174 |
|
|
| 175 |
@Override |
|
| 176 |
protected void onPause() |
|
| 177 |
{
|
|
| 178 |
super.onPause(); |
|
| 179 |
BandagedView view = findViewById(R.id.bandagedCreatorObjectView); |
|
| 180 |
view.onPause(); |
|
| 181 |
DistortedLibrary.onPause(ACTIVITY_NUMBER); |
|
| 182 |
savePreferences(); |
|
| 183 |
} |
|
| 184 |
|
|
| 185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 186 |
|
|
| 187 |
@Override |
|
| 188 |
protected void onResume() |
|
| 189 |
{
|
|
| 190 |
super.onResume(); |
|
| 191 |
|
|
| 192 |
DistortedLibrary.onResume(ACTIVITY_NUMBER); |
|
| 193 |
BandagedView view = findViewById(R.id.bandagedCreatorObjectView); |
|
| 194 |
view.onResume(); |
|
| 195 |
|
|
| 196 |
if( mScreen==null ) |
|
| 197 |
{
|
|
| 198 |
int ordinal = getObjectOrdinal(); |
|
| 199 |
mScreen = new BandagedScreen(ordinal); |
|
| 200 |
} |
|
| 201 |
|
|
| 202 |
mScreen.onAttachedToWindow(this); |
|
| 203 |
|
|
| 204 |
restorePreferences(); |
|
| 205 |
BandagedWorkerThread.create(this); |
|
| 206 |
} |
|
| 207 |
|
|
| 208 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 209 |
|
|
| 210 |
@Override |
|
| 211 |
protected void onDestroy() |
|
| 212 |
{
|
|
| 213 |
super.onDestroy(); |
|
| 214 |
DistortedLibrary.onDestroy(ACTIVITY_NUMBER); |
|
| 215 |
} |
|
| 216 |
|
|
| 217 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 218 |
|
|
| 219 |
void OpenGLError() |
|
| 220 |
{
|
|
| 221 |
RubikDialogError errDiag = new RubikDialogError(); |
|
| 222 |
errDiag.show(getSupportFragmentManager(), null); |
|
| 223 |
} |
|
| 224 |
|
|
| 225 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 226 |
|
|
| 227 |
private void savePreferences() |
|
| 228 |
{
|
|
| 229 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 230 |
SharedPreferences.Editor editor = preferences.edit(); |
|
| 231 |
mScreen.savePreferences(editor); |
|
| 232 |
editor.apply(); |
|
| 233 |
} |
|
| 234 |
|
|
| 235 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 236 |
|
|
| 237 |
private void restorePreferences() |
|
| 238 |
{
|
|
| 239 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 240 |
mScreen.restorePreferences(this,preferences); |
|
| 241 |
} |
|
| 242 |
|
|
| 243 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 244 |
// PUBLIC API |
|
| 245 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 246 |
|
|
| 247 |
public void changeObject(int x, int y, int z) |
|
| 248 |
{
|
|
| 249 |
BandagedRenderer renderer = getRenderer(); |
|
| 250 |
renderer.changeObject(x,y,z); |
|
| 251 |
} |
|
| 252 |
|
|
| 253 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 254 |
|
|
| 255 |
public boolean isRTL() |
|
| 256 |
{
|
|
| 257 |
return mRTL; |
|
| 258 |
} |
|
| 259 |
|
|
| 260 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 261 |
|
|
| 262 |
public BandagedRenderer getRenderer() |
|
| 263 |
{
|
|
| 264 |
BandagedView view = findViewById(R.id.bandagedCreatorObjectView); |
|
| 265 |
return view.getRenderer(); |
|
| 266 |
} |
|
| 267 |
|
|
| 268 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 269 |
|
|
| 270 |
public boolean objectDoesntExist(String name) |
|
| 271 |
{
|
|
| 272 |
return mScreen.objectDoesntExist(name); |
|
| 273 |
} |
|
| 274 |
|
|
| 275 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 276 |
|
|
| 277 |
public void addObject(String name) |
|
| 278 |
{
|
|
| 279 |
mScreen.addObject(this,name); |
|
| 280 |
} |
|
| 281 |
|
|
| 282 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 283 |
|
|
| 284 |
public void deleteObject(String name) |
|
| 285 |
{
|
|
| 286 |
RubikFiles files = RubikFiles.getInstance(); |
|
| 287 |
InputStream jsonStream = files.openFile(this,name+"_object.json"); |
|
| 288 |
InitAssets assets = new InitAssets(jsonStream,null,null); |
|
| 289 |
|
|
| 290 |
if( !assets.noJsonStream() ) |
|
| 291 |
{
|
|
| 292 |
TwistyObject object = new TwistyJson( TwistyObject.MODE_NORM, null, null, 1.0f, assets); |
|
| 293 |
|
|
| 294 |
if( !object.getError() ) |
|
| 295 |
{
|
|
| 296 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 297 |
SharedPreferences.Editor editor = preferences.edit(); |
|
| 298 |
OSInterface os = new OSInterface(this,null); |
|
| 299 |
os.setEditor(editor); |
|
| 300 |
object.removePreferences(os); |
|
| 301 |
editor.apply(); |
|
| 302 |
} |
|
| 303 |
} |
|
| 304 |
|
|
| 305 |
mScreen.deleteObject(this,name); |
|
| 306 |
files.deleteIcon(this,name); |
|
| 307 |
files.deleteJsonObject(this,name); |
|
| 308 |
} |
|
| 309 |
|
|
| 310 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 311 |
|
|
| 312 |
public void playObject(String name) |
|
| 313 |
{
|
|
| 314 |
Intent intent = new Intent(this, PlayActivity.class); |
|
| 315 |
intent.putExtra("name", name);
|
|
| 316 |
intent.putExtra("scrambles", NUM_SCRAMBLES);
|
|
| 317 |
intent.putExtra("local", true);
|
|
| 318 |
intent.putExtra("ordinal", 0);
|
|
| 319 |
intent.putExtra("free", true);
|
|
| 320 |
startActivity(intent); |
|
| 321 |
} |
|
| 322 |
|
|
| 323 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 324 |
|
|
| 325 |
public void iconCreationDone(Bitmap bmp) |
|
| 326 |
{
|
|
| 327 |
mScreen.iconCreationDone(this,bmp); |
|
| 328 |
} |
|
| 329 |
|
|
| 330 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 331 |
|
|
| 332 |
public int getScreenWidthInPixels() |
|
| 333 |
{
|
|
| 334 |
return mScreenWidth; |
|
| 335 |
} |
|
| 336 |
|
|
| 337 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 338 |
|
|
| 339 |
public int getScreenHeightInPixels() |
|
| 340 |
{
|
|
| 341 |
return mScreenHeight; |
|
| 342 |
} |
|
| 343 |
|
|
| 344 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 345 |
|
|
| 346 |
public int getObjectOrdinal() |
|
| 347 |
{
|
|
| 348 |
return mObjectOrdinal; |
|
| 349 |
} |
|
| 350 |
} |
|
| src/main/java/org/distorted/bandaged/BandagedCreatorActivity.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2022 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
| 7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
| 8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 9 |
|
|
| 10 |
package org.distorted.bandaged; |
|
| 11 |
|
|
| 12 |
import static android.view.View.LAYOUT_DIRECTION_RTL; |
|
| 13 |
|
|
| 14 |
import java.io.InputStream; |
|
| 15 |
|
|
| 16 |
import android.content.Intent; |
|
| 17 |
import android.content.SharedPreferences; |
|
| 18 |
import android.content.res.Configuration; |
|
| 19 |
import android.graphics.Bitmap; |
|
| 20 |
import android.os.Build; |
|
| 21 |
import android.os.Bundle; |
|
| 22 |
import android.util.DisplayMetrics; |
|
| 23 |
import android.view.View; |
|
| 24 |
import android.view.ViewGroup; |
|
| 25 |
import android.view.WindowManager; |
|
| 26 |
import android.widget.LinearLayout; |
|
| 27 |
|
|
| 28 |
import androidx.appcompat.app.AppCompatActivity; |
|
| 29 |
import androidx.preference.PreferenceManager; |
|
| 30 |
|
|
| 31 |
import org.distorted.dialogs.RubikDialogError; |
|
| 32 |
import org.distorted.external.RubikFiles; |
|
| 33 |
import org.distorted.library.main.DistortedLibrary; |
|
| 34 |
import org.distorted.main.MainActivity; |
|
| 35 |
import org.distorted.main.R; |
|
| 36 |
import org.distorted.main_old.RubikActivity; |
|
| 37 |
import org.distorted.objectlib.main.InitAssets; |
|
| 38 |
import org.distorted.objectlib.main.TwistyJson; |
|
| 39 |
import org.distorted.objectlib.main.TwistyObject; |
|
| 40 |
import org.distorted.os.OSInterface; |
|
| 41 |
|
|
| 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 43 |
|
|
| 44 |
public class BandagedCreatorActivity extends AppCompatActivity |
|
| 45 |
{
|
|
| 46 |
private static final int ACTIVITY_NUMBER = 3; |
|
| 47 |
private static final float RATIO_BAR = MainActivity.RATIO_BAR; |
|
| 48 |
private static final float RATIO_BUT = 0.07f; |
|
| 49 |
static final float RATIO_SCROLL = 0.30f; |
|
| 50 |
public static final float SPINNER_TEXT_SIZE = 0.03f; |
|
| 51 |
public static final int FLAGS = RubikActivity.FLAGS; |
|
| 52 |
|
|
| 53 |
private static int mScreenWidth, mScreenHeight; |
|
| 54 |
private int mCurrentApiVersion; |
|
| 55 |
private BandagedCreatorScreen mScreen; |
|
| 56 |
private boolean mRTL; |
|
| 57 |
private int mObjectOrdinal; |
|
| 58 |
|
|
| 59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 60 |
|
|
| 61 |
@Override |
|
| 62 |
protected void onCreate(Bundle savedState) |
|
| 63 |
{
|
|
| 64 |
super.onCreate(savedState); |
|
| 65 |
|
|
| 66 |
Bundle b = getIntent().getExtras(); |
|
| 67 |
mObjectOrdinal = (b != null) ? b.getInt("obj") : 0;
|
|
| 68 |
|
|
| 69 |
DistortedLibrary.onCreate(ACTIVITY_NUMBER); |
|
| 70 |
setTheme(R.style.MaterialThemeNoActionBar); |
|
| 71 |
setContentView(R.layout.bandaged); |
|
| 72 |
|
|
| 73 |
DisplayMetrics displaymetrics = new DisplayMetrics(); |
|
| 74 |
getWindowManager().getDefaultDisplay().getRealMetrics(displaymetrics); |
|
| 75 |
mScreenWidth =displaymetrics.widthPixels; |
|
| 76 |
mScreenHeight=displaymetrics.heightPixels; |
|
| 77 |
|
|
| 78 |
final Configuration config = getResources().getConfiguration(); |
|
| 79 |
final int layoutDirection = config.getLayoutDirection(); |
|
| 80 |
mRTL = layoutDirection==LAYOUT_DIRECTION_RTL; |
|
| 81 |
|
|
| 82 |
hideNavigationBar(); |
|
| 83 |
cutoutHack(); |
|
| 84 |
computeHeights(); |
|
| 85 |
} |
|
| 86 |
|
|
| 87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 88 |
// this does not include possible insets |
|
| 89 |
|
|
| 90 |
private void computeHeights() |
|
| 91 |
{
|
|
| 92 |
int barHeight = (int)(mScreenHeight*RATIO_BAR); |
|
| 93 |
int butHeight = (int)(mScreenHeight*RATIO_BUT); |
|
| 94 |
int viewHeight = (int)(mScreenHeight*RATIO_SCROLL); |
|
| 95 |
int objectHeight = (int)(mScreenHeight*(1-RATIO_SCROLL+RATIO_BAR)); |
|
| 96 |
int padding = (int)(mScreenHeight*RubikActivity.PADDING); |
|
| 97 |
|
|
| 98 |
LinearLayout botLayout = findViewById(R.id.lowerBar); |
|
| 99 |
ViewGroup.LayoutParams paramsL = botLayout.getLayoutParams(); |
|
| 100 |
paramsL.height = barHeight; |
|
| 101 |
botLayout.setLayoutParams(paramsL); |
|
| 102 |
|
|
| 103 |
LinearLayout butLayout = findViewById(R.id.bandagedCreatorButtons); |
|
| 104 |
ViewGroup.LayoutParams paramsB = butLayout.getLayoutParams(); |
|
| 105 |
paramsB.height = butHeight; |
|
| 106 |
butLayout.setPadding(padding,0,padding,padding); |
|
| 107 |
butLayout.setLayoutParams(paramsB); |
|
| 108 |
|
|
| 109 |
LinearLayout topLayout = findViewById(R.id.bandagedCreatorTopView); |
|
| 110 |
ViewGroup.LayoutParams paramsT = topLayout.getLayoutParams(); |
|
| 111 |
paramsT.height = viewHeight; |
|
| 112 |
topLayout.setPadding(padding,padding,padding,padding); |
|
| 113 |
topLayout.setLayoutParams(paramsT); |
|
| 114 |
|
|
| 115 |
BandagedCreatorView creator = findViewById(R.id.bandagedCreatorObjectView); |
|
| 116 |
ViewGroup.LayoutParams paramsC = creator.getLayoutParams(); |
|
| 117 |
paramsC.height = objectHeight; |
|
| 118 |
creator.setLayoutParams(paramsC); |
|
| 119 |
} |
|
| 120 |
|
|
| 121 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 122 |
|
|
| 123 |
private void hideNavigationBar() |
|
| 124 |
{
|
|
| 125 |
mCurrentApiVersion = Build.VERSION.SDK_INT; |
|
| 126 |
|
|
| 127 |
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT) |
|
| 128 |
{
|
|
| 129 |
final View decorView = getWindow().getDecorView(); |
|
| 130 |
|
|
| 131 |
decorView.setSystemUiVisibility(FLAGS); |
|
| 132 |
|
|
| 133 |
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() |
|
| 134 |
{
|
|
| 135 |
@Override |
|
| 136 |
public void onSystemUiVisibilityChange(int visibility) |
|
| 137 |
{
|
|
| 138 |
if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) |
|
| 139 |
{
|
|
| 140 |
decorView.setSystemUiVisibility(FLAGS); |
|
| 141 |
} |
|
| 142 |
} |
|
| 143 |
}); |
|
| 144 |
} |
|
| 145 |
} |
|
| 146 |
|
|
| 147 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 148 |
// do not avoid cutouts |
|
| 149 |
|
|
| 150 |
private void cutoutHack() |
|
| 151 |
{
|
|
| 152 |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) |
|
| 153 |
{
|
|
| 154 |
getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; |
|
| 155 |
} |
|
| 156 |
} |
|
| 157 |
|
|
| 158 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 159 |
|
|
| 160 |
@Override |
|
| 161 |
public void onWindowFocusChanged(boolean hasFocus) |
|
| 162 |
{
|
|
| 163 |
super.onWindowFocusChanged(hasFocus); |
|
| 164 |
|
|
| 165 |
if(mCurrentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus) |
|
| 166 |
{
|
|
| 167 |
getWindow().getDecorView().setSystemUiVisibility(FLAGS); |
|
| 168 |
} |
|
| 169 |
} |
|
| 170 |
|
|
| 171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 172 |
|
|
| 173 |
@Override |
|
| 174 |
protected void onPause() |
|
| 175 |
{
|
|
| 176 |
super.onPause(); |
|
| 177 |
BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView); |
|
| 178 |
view.onPause(); |
|
| 179 |
DistortedLibrary.onPause(ACTIVITY_NUMBER); |
|
| 180 |
savePreferences(); |
|
| 181 |
} |
|
| 182 |
|
|
| 183 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 184 |
|
|
| 185 |
@Override |
|
| 186 |
protected void onResume() |
|
| 187 |
{
|
|
| 188 |
super.onResume(); |
|
| 189 |
|
|
| 190 |
DistortedLibrary.onResume(ACTIVITY_NUMBER); |
|
| 191 |
BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView); |
|
| 192 |
view.onResume(); |
|
| 193 |
|
|
| 194 |
if( mScreen==null ) |
|
| 195 |
{
|
|
| 196 |
int ordinal = getObjectOrdinal(); |
|
| 197 |
mScreen = new BandagedCreatorScreen(ordinal); |
|
| 198 |
} |
|
| 199 |
|
|
| 200 |
mScreen.onAttachedToWindow(this); |
|
| 201 |
|
|
| 202 |
restorePreferences(); |
|
| 203 |
BandagedCreatorWorkerThread.create(this); |
|
| 204 |
} |
|
| 205 |
|
|
| 206 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 207 |
|
|
| 208 |
@Override |
|
| 209 |
protected void onDestroy() |
|
| 210 |
{
|
|
| 211 |
super.onDestroy(); |
|
| 212 |
DistortedLibrary.onDestroy(ACTIVITY_NUMBER); |
|
| 213 |
} |
|
| 214 |
|
|
| 215 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 216 |
|
|
| 217 |
void OpenGLError() |
|
| 218 |
{
|
|
| 219 |
RubikDialogError errDiag = new RubikDialogError(); |
|
| 220 |
errDiag.show(getSupportFragmentManager(), null); |
|
| 221 |
} |
|
| 222 |
|
|
| 223 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 224 |
|
|
| 225 |
private void savePreferences() |
|
| 226 |
{
|
|
| 227 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 228 |
SharedPreferences.Editor editor = preferences.edit(); |
|
| 229 |
mScreen.savePreferences(editor); |
|
| 230 |
editor.apply(); |
|
| 231 |
} |
|
| 232 |
|
|
| 233 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 234 |
|
|
| 235 |
private void restorePreferences() |
|
| 236 |
{
|
|
| 237 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 238 |
mScreen.restorePreferences(this,preferences); |
|
| 239 |
} |
|
| 240 |
|
|
| 241 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 242 |
// PUBLIC API |
|
| 243 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 244 |
|
|
| 245 |
public void changeObject(int x, int y, int z) |
|
| 246 |
{
|
|
| 247 |
BandagedCreatorRenderer renderer = getRenderer(); |
|
| 248 |
renderer.changeObject(x,y,z); |
|
| 249 |
} |
|
| 250 |
|
|
| 251 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 252 |
|
|
| 253 |
public boolean isRTL() |
|
| 254 |
{
|
|
| 255 |
return mRTL; |
|
| 256 |
} |
|
| 257 |
|
|
| 258 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 259 |
|
|
| 260 |
public BandagedCreatorRenderer getRenderer() |
|
| 261 |
{
|
|
| 262 |
BandagedCreatorView view = findViewById(R.id.bandagedCreatorObjectView); |
|
| 263 |
return view.getRenderer(); |
|
| 264 |
} |
|
| 265 |
|
|
| 266 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 267 |
|
|
| 268 |
public boolean objectDoesntExist(String name) |
|
| 269 |
{
|
|
| 270 |
return mScreen.objectDoesntExist(name); |
|
| 271 |
} |
|
| 272 |
|
|
| 273 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 274 |
|
|
| 275 |
public void addObject(String name) |
|
| 276 |
{
|
|
| 277 |
mScreen.addObject(this,name); |
|
| 278 |
} |
|
| 279 |
|
|
| 280 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 281 |
|
|
| 282 |
public void deleteObject(String name) |
|
| 283 |
{
|
|
| 284 |
RubikFiles files = RubikFiles.getInstance(); |
|
| 285 |
InputStream jsonStream = files.openFile(this,name+"_object.json"); |
|
| 286 |
InitAssets assets = new InitAssets(jsonStream,null,null); |
|
| 287 |
|
|
| 288 |
if( !assets.noJsonStream() ) |
|
| 289 |
{
|
|
| 290 |
TwistyObject object = new TwistyJson( TwistyObject.MODE_NORM, null, null, 1.0f, assets); |
|
| 291 |
|
|
| 292 |
if( !object.getError() ) |
|
| 293 |
{
|
|
| 294 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
|
| 295 |
SharedPreferences.Editor editor = preferences.edit(); |
|
| 296 |
OSInterface os = new OSInterface(this,null); |
|
| 297 |
os.setEditor(editor); |
|
| 298 |
object.removePreferences(os); |
|
| 299 |
editor.apply(); |
|
| 300 |
} |
|
| 301 |
} |
|
| 302 |
|
|
| 303 |
mScreen.deleteObject(this,name); |
|
| 304 |
files.deleteIcon(this,name); |
|
| 305 |
files.deleteJsonObject(this,name); |
|
| 306 |
} |
|
| 307 |
|
|
| 308 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 309 |
|
|
| 310 |
public void playObject(String name) |
|
| 311 |
{
|
|
| 312 |
Intent intent = new Intent(this, BandagedPlayActivity.class); |
|
| 313 |
intent.putExtra("name", name);
|
|
| 314 |
startActivity(intent); |
|
| 315 |
} |
|
| 316 |
|
|
| 317 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 318 |
|
|
| 319 |
public void iconCreationDone(Bitmap bmp) |
|
| 320 |
{
|
|
| 321 |
mScreen.iconCreationDone(this,bmp); |
|
| 322 |
} |
|
| 323 |
|
|
| 324 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 325 |
|
|
| 326 |
public int getScreenWidthInPixels() |
|
| 327 |
{
|
|
| 328 |
return mScreenWidth; |
|
| 329 |
} |
|
| 330 |
|
|
| 331 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 332 |
|
|
| 333 |
public int getScreenHeightInPixels() |
|
| 334 |
{
|
|
| 335 |
return mScreenHeight; |
|
| 336 |
} |
|
| 337 |
|
|
| 338 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 339 |
|
|
| 340 |
public int getObjectOrdinal() |
|
| 341 |
{
|
|
| 342 |
return mObjectOrdinal; |
|
| 343 |
} |
|
| 344 |
} |
|
| src/main/java/org/distorted/bandaged/BandagedCreatorObjectView.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2022 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
| 7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
| 8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 9 |
|
|
| 10 |
package org.distorted.bandaged; |
|
| 11 |
|
|
| 12 |
import android.os.Bundle; |
|
| 13 |
import android.view.LayoutInflater; |
|
| 14 |
import android.view.View; |
|
| 15 |
import android.widget.LinearLayout; |
|
| 16 |
|
|
| 17 |
import org.distorted.dialogs.RubikDialogBandagedDelete; |
|
| 18 |
import org.distorted.helpers.TransparentButton; |
|
| 19 |
import org.distorted.helpers.TransparentImageButton; |
|
| 20 |
import org.distorted.main.R; |
|
| 21 |
|
|
| 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 23 |
|
|
| 24 |
public class BandagedCreatorObjectView |
|
| 25 |
{
|
|
| 26 |
private static final float MARGIN = 0.015f; |
|
| 27 |
private static final float TEXT_SIZE = 0.032f; |
|
| 28 |
private static final float RATIO_ICON= 0.15f; |
|
| 29 |
|
|
| 30 |
private final LinearLayout mPane; |
|
| 31 |
private final String mName; |
|
| 32 |
|
|
| 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 34 |
|
|
| 35 |
public BandagedCreatorObjectView(final BandagedCreatorActivity act, String name, boolean leftmost) |
|
| 36 |
{
|
|
| 37 |
mName = name; |
|
| 38 |
LayoutInflater inflater = act.getLayoutInflater(); |
|
| 39 |
mPane = (LinearLayout) inflater.inflate(R.layout.bandaged_pane, null); |
|
| 40 |
|
|
| 41 |
int height = act.getScreenHeightInPixels(); |
|
| 42 |
int textSize = (int)(height*TEXT_SIZE); |
|
| 43 |
|
|
| 44 |
LinearLayout.LayoutParams params = createPaneParams(height,leftmost,act.isRTL()); |
|
| 45 |
mPane.setLayoutParams(params); |
|
| 46 |
|
|
| 47 |
LinearLayout bottom = mPane.findViewById(R.id.bandagedCreatorObjectLayout); |
|
| 48 |
|
|
| 49 |
TransparentButton plaButton = new TransparentButton(act, R.string.play, textSize); |
|
| 50 |
plaButton.setSingleLine(); |
|
| 51 |
|
|
| 52 |
final int icon = R.drawable.ui_trash; |
|
| 53 |
LinearLayout.LayoutParams paramsB = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,3.0f); |
|
| 54 |
TransparentImageButton delButton = new TransparentImageButton(act,icon,paramsB); |
|
| 55 |
|
|
| 56 |
bottom.addView(plaButton); |
|
| 57 |
bottom.addView(delButton); |
|
| 58 |
|
|
| 59 |
plaButton.setOnClickListener( new View.OnClickListener() |
|
| 60 |
{
|
|
| 61 |
@Override |
|
| 62 |
public void onClick(View v) |
|
| 63 |
{
|
|
| 64 |
act.playObject(mName); |
|
| 65 |
} |
|
| 66 |
}); |
|
| 67 |
|
|
| 68 |
delButton.setOnClickListener( new View.OnClickListener() |
|
| 69 |
{
|
|
| 70 |
@Override |
|
| 71 |
public void onClick(View v) |
|
| 72 |
{
|
|
| 73 |
Bundle bundle = new Bundle(); |
|
| 74 |
bundle.putString("argument", mName );
|
|
| 75 |
RubikDialogBandagedDelete dialog = new RubikDialogBandagedDelete(); |
|
| 76 |
dialog.setArguments(bundle); |
|
| 77 |
dialog.show( act.getSupportFragmentManager(), RubikDialogBandagedDelete.getDialogTag() ); |
|
| 78 |
} |
|
| 79 |
}); |
|
| 80 |
} |
|
| 81 |
|
|
| 82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 83 |
|
|
| 84 |
static LinearLayout.LayoutParams createPaneParams(int height, boolean leftmost, boolean rtl) |
|
| 85 |
{
|
|
| 86 |
int margin = (int)(height*MARGIN); |
|
| 87 |
int length = (int)(height*BandagedCreatorActivity.RATIO_SCROLL*0.65f); |
|
| 88 |
|
|
| 89 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( length, LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 90 |
params.bottomMargin = margin; |
|
| 91 |
params.topMargin = margin; |
|
| 92 |
|
|
| 93 |
if( !rtl ) |
|
| 94 |
{
|
|
| 95 |
params.leftMargin = leftmost ? margin : 0; |
|
| 96 |
params.rightMargin = margin; |
|
| 97 |
} |
|
| 98 |
else |
|
| 99 |
{
|
|
| 100 |
params.rightMargin = leftmost ? margin : 0; |
|
| 101 |
params.leftMargin = margin; |
|
| 102 |
} |
|
| 103 |
|
|
| 104 |
return params; |
|
| 105 |
} |
|
| 106 |
|
|
| 107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 108 |
|
|
| 109 |
public LinearLayout getPane() |
|
| 110 |
{
|
|
| 111 |
return mPane; |
|
| 112 |
} |
|
| 113 |
|
|
| 114 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 115 |
|
|
| 116 |
public String getName() |
|
| 117 |
{
|
|
| 118 |
return mName; |
|
| 119 |
} |
|
| 120 |
} |
|
| src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2022 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
| 7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
| 8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 9 |
|
|
| 10 |
package org.distorted.bandaged; |
|
| 11 |
|
|
| 12 |
import java.io.File; |
|
| 13 |
import java.io.FileNotFoundException; |
|
| 14 |
import java.io.IOException; |
|
| 15 |
import java.io.InputStream; |
|
| 16 |
import java.nio.ByteBuffer; |
|
| 17 |
import java.nio.ByteOrder; |
|
| 18 |
|
|
| 19 |
import javax.microedition.khronos.egl.EGLConfig; |
|
| 20 |
import javax.microedition.khronos.opengles.GL10; |
|
| 21 |
|
|
| 22 |
import android.app.Activity; |
|
| 23 |
import android.content.res.Resources; |
|
| 24 |
import android.opengl.GLES31; |
|
| 25 |
import android.opengl.GLSurfaceView; |
|
| 26 |
import android.widget.Toast; |
|
| 27 |
|
|
| 28 |
import org.distorted.dialogs.RubikDialogBandagedSave; |
|
| 29 |
import org.distorted.library.effect.EffectType; |
|
| 30 |
import org.distorted.library.effect.FragmentEffectBrightness; |
|
| 31 |
import org.distorted.library.effect.PostprocessEffectBorder; |
|
| 32 |
import org.distorted.library.main.DistortedEffects; |
|
| 33 |
import org.distorted.library.main.DistortedFramebuffer; |
|
| 34 |
import org.distorted.library.main.DistortedLibrary; |
|
| 35 |
import org.distorted.library.main.DistortedNode; |
|
| 36 |
import org.distorted.library.main.DistortedScreen; |
|
| 37 |
import org.distorted.library.main.InternalOutputSurface; |
|
| 38 |
import org.distorted.library.mesh.MeshBase; |
|
| 39 |
import org.distorted.library.type.Static1D; |
|
| 40 |
import org.distorted.library.type.Static3D; |
|
| 41 |
import org.distorted.library.type.Static4D; |
|
| 42 |
import org.distorted.objectlib.bandaged.BandagedObject; |
|
| 43 |
import org.distorted.objectlib.bandaged.LocallyBandagedList; |
|
| 44 |
import org.distorted.objectlib.json.JsonWriter; |
|
| 45 |
import org.distorted.objectlib.main.ObjectControl; |
|
| 46 |
import org.distorted.objectlib.main.TwistyObject; |
|
| 47 |
|
|
| 48 |
import org.json.JSONException; |
|
| 49 |
|
|
| 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 51 |
|
|
| 52 |
public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser |
|
| 53 |
{
|
|
| 54 |
public static final float BRIGHTNESS = 0.333f; |
|
| 55 |
private static final int RESET_DURATION = 1000; |
|
| 56 |
private static final float MAX_SIZE_CHANGE = 1.70f; |
|
| 57 |
private static final float MIN_SIZE_CHANGE = 0.50f; |
|
| 58 |
|
|
| 59 |
private final BandagedCreatorView mView; |
|
| 60 |
private final Resources mResources; |
|
| 61 |
private final DistortedScreen mScreen; |
|
| 62 |
private final Static3D mScale; |
|
| 63 |
private final Static4D mQuatT, mQuatA; |
|
| 64 |
private final BandagedObject mObject; |
|
| 65 |
private final float mInitRatio; |
|
| 66 |
|
|
| 67 |
private boolean mInitialPhase; |
|
| 68 |
private long mStartTime; |
|
| 69 |
private float mQuatX, mQuatY, mQuatZ, mQuatW; |
|
| 70 |
private boolean mResetQuats, mSetQuatT, mResettingObject, mConnectingCubits, mCreatingCubits, mRescaling; |
|
| 71 |
private int mIndex1, mIndex2; |
|
| 72 |
private int mSaveIcon; |
|
| 73 |
private DistortedFramebuffer mFramebuffer; |
|
| 74 |
private String mPath; |
|
| 75 |
private boolean mCubitsCreated; |
|
| 76 |
private int mWidth, mHeight; |
|
| 77 |
private float mScaleValue, mObjectScreenRatio; |
|
| 78 |
|
|
| 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 80 |
|
|
| 81 |
BandagedCreatorRenderer(BandagedCreatorView v, int ordinal) |
|
| 82 |
{
|
|
| 83 |
mView = v; |
|
| 84 |
mResources = v.getResources(); |
|
| 85 |
|
|
| 86 |
mQuatT = new Static4D(0,0,0,1); |
|
| 87 |
mQuatA = new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f); |
|
| 88 |
|
|
| 89 |
mResetQuats = false; |
|
| 90 |
mSetQuatT = false; |
|
| 91 |
mResettingObject = false; |
|
| 92 |
mConnectingCubits = false; |
|
| 93 |
mCubitsCreated = false; |
|
| 94 |
mCreatingCubits = false; |
|
| 95 |
mRescaling = false; |
|
| 96 |
|
|
| 97 |
mSaveIcon = -1; |
|
| 98 |
|
|
| 99 |
mScreen = new DistortedScreen(); |
|
| 100 |
mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f); |
|
| 101 |
mScale = new Static3D(1,1,1); |
|
| 102 |
mObject= LocallyBandagedList.create(ordinal,mScreen); |
|
| 103 |
|
|
| 104 |
mInitRatio = mObject.getScreenRatio(); |
|
| 105 |
mObjectScreenRatio= mInitRatio; |
|
| 106 |
} |
|
| 107 |
|
|
| 108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 109 |
|
|
| 110 |
@Override |
|
| 111 |
public void onDrawFrame(GL10 glUnused) |
|
| 112 |
{
|
|
| 113 |
long time = System.currentTimeMillis(); |
|
| 114 |
mScreen.render(time); |
|
| 115 |
|
|
| 116 |
if( mSetQuatT ) |
|
| 117 |
{
|
|
| 118 |
mSetQuatT = false; |
|
| 119 |
mQuatT.set(mQuatX,mQuatY,mQuatZ,mQuatW); |
|
| 120 |
} |
|
| 121 |
|
|
| 122 |
if( mResetQuats ) |
|
| 123 |
{
|
|
| 124 |
mResetQuats = false; |
|
| 125 |
|
|
| 126 |
float qx = mQuatT.get0(); |
|
| 127 |
float qy = mQuatT.get1(); |
|
| 128 |
float qz = mQuatT.get2(); |
|
| 129 |
float qw = mQuatT.get3(); |
|
| 130 |
|
|
| 131 |
float rx = mQuatA.get0(); |
|
| 132 |
float ry = mQuatA.get1(); |
|
| 133 |
float rz = mQuatA.get2(); |
|
| 134 |
float rw = mQuatA.get3(); |
|
| 135 |
|
|
| 136 |
float tx = rw*qx - rz*qy + ry*qz + rx*qw; |
|
| 137 |
float ty = rw*qy + rz*qx + ry*qw - rx*qz; |
|
| 138 |
float tz = rw*qz + rz*qw - ry*qx + rx*qy; |
|
| 139 |
float tw = rw*qw - rz*qz - ry*qy - rx*qx; |
|
| 140 |
|
|
| 141 |
mQuatT.set(0f, 0f, 0f, 1f); |
|
| 142 |
mQuatA.set(tx, ty, tz, tw); |
|
| 143 |
} |
|
| 144 |
|
|
| 145 |
if( mResettingObject ) |
|
| 146 |
{
|
|
| 147 |
boolean done = continueResetting(time); |
|
| 148 |
if( done ) mResettingObject = false; |
|
| 149 |
} |
|
| 150 |
|
|
| 151 |
if( mSaveIcon>=0 ) |
|
| 152 |
{
|
|
| 153 |
renderIcon(time); // for some reason we need to call render() twice here, otherwise the |
|
| 154 |
mSaveIcon++; // icon turns out black. Probably some problem with binding the texture. |
|
| 155 |
} |
|
| 156 |
if( mSaveIcon>=2 ) |
|
| 157 |
{
|
|
| 158 |
saveIcon(); |
|
| 159 |
mSaveIcon = -1; |
|
| 160 |
} |
|
| 161 |
|
|
| 162 |
if( mConnectingCubits ) |
|
| 163 |
{
|
|
| 164 |
mObject.tryConnectingCubits(mIndex1,mIndex2,mScaleValue); |
|
| 165 |
mConnectingCubits = false; |
|
| 166 |
} |
|
| 167 |
|
|
| 168 |
if( mCreatingCubits ) |
|
| 169 |
{
|
|
| 170 |
rescaleObject(); |
|
| 171 |
|
|
| 172 |
if( mCubitsCreated ) |
|
| 173 |
{
|
|
| 174 |
mObject.createCubits(mQuatT,mQuatA,mScale); |
|
| 175 |
float[] dist = mObject.getDist3D(); |
|
| 176 |
BandagedCreatorTouchControl control = mView.getTouchControl(); |
|
| 177 |
control.setDist3D(dist); |
|
| 178 |
mScreen.detachAll(); |
|
| 179 |
mView.resetCubits(); |
|
| 180 |
mObject.attachCubits(mScaleValue); |
|
| 181 |
} |
|
| 182 |
|
|
| 183 |
mCreatingCubits = false; |
|
| 184 |
} |
|
| 185 |
|
|
| 186 |
if( mRescaling ) |
|
| 187 |
{
|
|
| 188 |
rescaleObject(); |
|
| 189 |
mObject.scaleCubits(mScaleValue); |
|
| 190 |
BandagedCreatorTouchControl control = mView.getTouchControl(); |
|
| 191 |
control.setObjectRatio(mObjectScreenRatio); |
|
| 192 |
mRescaling = false; |
|
| 193 |
} |
|
| 194 |
} |
|
| 195 |
|
|
| 196 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 197 |
|
|
| 198 |
@Override |
|
| 199 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
| 200 |
{
|
|
| 201 |
if( width!=mWidth || height!=mHeight ) |
|
| 202 |
{
|
|
| 203 |
mWidth = width; |
|
| 204 |
mHeight= height; |
|
| 205 |
rescaleObject(); |
|
| 206 |
mScreen.detachAll(); |
|
| 207 |
int touched = mView.getTouched(); |
|
| 208 |
mObject.attachAndMarkCubits(mScaleValue,touched); |
|
| 209 |
mView.setScreenSize(width,height); |
|
| 210 |
mScreen.resize(width,height); |
|
| 211 |
} |
|
| 212 |
} |
|
| 213 |
|
|
| 214 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 215 |
|
|
| 216 |
@Override |
|
| 217 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
| 218 |
{
|
|
| 219 |
DistortedLibrary.setMax(EffectType.VERTEX,0); |
|
| 220 |
MeshBase.setMaxEffComponents(ObjectControl.MAX_MOVING_PARTS); |
|
| 221 |
FragmentEffectBrightness.enable(); |
|
| 222 |
DistortedLibrary.onSurfaceCreated(this,1); |
|
| 223 |
DistortedLibrary.setCull(true); |
|
| 224 |
mObject.recreateCubits(mQuatT,mQuatA,mScale); |
|
| 225 |
mCubitsCreated = true; |
|
| 226 |
mWidth = 0; |
|
| 227 |
mHeight= 0; |
|
| 228 |
} |
|
| 229 |
|
|
| 230 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 231 |
|
|
| 232 |
public DistortedScreen getScreen() |
|
| 233 |
{
|
|
| 234 |
return mScreen; |
|
| 235 |
} |
|
| 236 |
|
|
| 237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 238 |
|
|
| 239 |
void setConnecting(int index1, int index2) |
|
| 240 |
{
|
|
| 241 |
mIndex1 = index1; |
|
| 242 |
mIndex2 = index2; |
|
| 243 |
mConnectingCubits = true; |
|
| 244 |
} |
|
| 245 |
|
|
| 246 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 247 |
|
|
| 248 |
public Static4D getQuatAccu() |
|
| 249 |
{
|
|
| 250 |
return mQuatA; |
|
| 251 |
} |
|
| 252 |
|
|
| 253 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 254 |
|
|
| 255 |
public void setQuatTemp(float x, float y, float z, float w) |
|
| 256 |
{
|
|
| 257 |
mSetQuatT = false; |
|
| 258 |
|
|
| 259 |
mQuatX = x; |
|
| 260 |
mQuatY = y; |
|
| 261 |
mQuatZ = z; |
|
| 262 |
mQuatW = w; |
|
| 263 |
|
|
| 264 |
mSetQuatT = true; |
|
| 265 |
} |
|
| 266 |
|
|
| 267 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 268 |
|
|
| 269 |
public void resetQuats() |
|
| 270 |
{
|
|
| 271 |
mResetQuats = true; |
|
| 272 |
} |
|
| 273 |
|
|
| 274 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 275 |
|
|
| 276 |
public boolean isBusy() |
|
| 277 |
{
|
|
| 278 |
return (mResettingObject || mCreatingCubits || mConnectingCubits); |
|
| 279 |
} |
|
| 280 |
|
|
| 281 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 282 |
|
|
| 283 |
public void saveObject() |
|
| 284 |
{
|
|
| 285 |
TwistyObject obj = mObject.createObject(TwistyObject.MODE_NORM, 1.0f ); |
|
| 286 |
String name = obj.getShortName(); |
|
| 287 |
BandagedCreatorActivity act = (BandagedCreatorActivity) mView.getContext(); |
|
| 288 |
|
|
| 289 |
if( act.objectDoesntExist(name) && createObjectJson(obj,act) ) |
|
| 290 |
{
|
|
| 291 |
setupIconCreation(act); |
|
| 292 |
act.addObject(obj.getShortName()); |
|
| 293 |
} |
|
| 294 |
} |
|
| 295 |
|
|
| 296 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 297 |
|
|
| 298 |
private boolean createObjectJson(TwistyObject object, Activity act) |
|
| 299 |
{
|
|
| 300 |
final String name = object.getShortName()+"_object.json"; |
|
| 301 |
File file = new File(act.getFilesDir(), name); |
|
| 302 |
String filename = file.getAbsolutePath(); |
|
| 303 |
|
|
| 304 |
try |
|
| 305 |
{
|
|
| 306 |
JsonWriter writer = JsonWriter.getInstance(); |
|
| 307 |
String json = writer.createObjectString(object,24,0); |
|
| 308 |
writer.write(filename,json); |
|
| 309 |
return true; |
|
| 310 |
} |
|
| 311 |
catch(JSONException ex) |
|
| 312 |
{
|
|
| 313 |
act.runOnUiThread(new Runnable() |
|
| 314 |
{
|
|
| 315 |
public void run() |
|
| 316 |
{
|
|
| 317 |
String message = "JSON Exception saving to \n\n"+filename+"\n\n failed:\n\n"+ex.getMessage(); |
|
| 318 |
Toast.makeText(act,message,Toast.LENGTH_LONG).show(); |
|
| 319 |
} |
|
| 320 |
}); |
|
| 321 |
|
|
| 322 |
return false; |
|
| 323 |
} |
|
| 324 |
catch(FileNotFoundException ex) |
|
| 325 |
{
|
|
| 326 |
act.runOnUiThread(new Runnable() |
|
| 327 |
{
|
|
| 328 |
public void run() |
|
| 329 |
{
|
|
| 330 |
String message = "FileNotFound exception saving to \n\n"+filename+"\n\n failed:\n\n"+ex.getMessage(); |
|
| 331 |
Toast.makeText(act,message,Toast.LENGTH_LONG).show(); |
|
| 332 |
} |
|
| 333 |
}); |
|
| 334 |
|
|
| 335 |
return false; |
|
| 336 |
} |
|
| 337 |
catch(IOException ex) |
|
| 338 |
{
|
|
| 339 |
act.runOnUiThread(new Runnable() |
|
| 340 |
{
|
|
| 341 |
public void run() |
|
| 342 |
{
|
|
| 343 |
String message = "IO exception saving to \n\n"+filename+"\n\n failed:\n\n"+ex.getMessage(); |
|
| 344 |
Toast.makeText(act,message,Toast.LENGTH_LONG).show(); |
|
| 345 |
} |
|
| 346 |
}); |
|
| 347 |
|
|
| 348 |
return false; |
|
| 349 |
} |
|
| 350 |
} |
|
| 351 |
|
|
| 352 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 353 |
|
|
| 354 |
private void setupIconCreation(Activity act) |
|
| 355 |
{
|
|
| 356 |
final float R=1.0f; |
|
| 357 |
final int FBO_WIDTH = (int)(R*720); |
|
| 358 |
final int FBO_HEIGHT = (int)(R*1280); |
|
| 359 |
final float OBJECT_SIZE = R*0.60f; |
|
| 360 |
|
|
| 361 |
TwistyObject obj = mObject.createObject(TwistyObject.MODE_ICON, OBJECT_SIZE ); |
|
| 362 |
DistortedEffects effects = obj.getObjectEffects(); |
|
| 363 |
DistortedNode node = obj.getNode(); |
|
| 364 |
|
|
| 365 |
if( mFramebuffer==null ) |
|
| 366 |
{
|
|
| 367 |
mFramebuffer = new DistortedFramebuffer(FBO_WIDTH,FBO_HEIGHT,1, InternalOutputSurface.DEPTH_NO_STENCIL); |
|
| 368 |
mFramebuffer.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f); |
|
| 369 |
} |
|
| 370 |
|
|
| 371 |
mFramebuffer.setProjection( mObject.computeProjectionAngle() ,0.1f); |
|
| 372 |
mFramebuffer.detachAll(); |
|
| 373 |
mFramebuffer.attach(node); |
|
| 374 |
|
|
| 375 |
Static1D halo = new Static1D(5); |
|
| 376 |
Static4D color = new Static4D(0,0,0,1); |
|
| 377 |
PostprocessEffectBorder border = new PostprocessEffectBorder(halo,color); |
|
| 378 |
border.setHaloDepth(false); |
|
| 379 |
effects.apply(border); |
|
| 380 |
|
|
| 381 |
final String name = obj.getShortName()+".png"; |
|
| 382 |
File file = new File(act.getFilesDir(), name); |
|
| 383 |
String filename = file.getAbsolutePath(); |
|
| 384 |
|
|
| 385 |
mSaveIcon = 0; |
|
| 386 |
mPath = filename; |
|
| 387 |
} |
|
| 388 |
|
|
| 389 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 390 |
|
|
| 391 |
private void renderIcon(long time) |
|
| 392 |
{
|
|
| 393 |
mFramebuffer.render(time); |
|
| 394 |
} |
|
| 395 |
|
|
| 396 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 397 |
|
|
| 398 |
private void saveIcon() |
|
| 399 |
{
|
|
| 400 |
int fW = mFramebuffer.getWidth(); |
|
| 401 |
int fH = mFramebuffer.getHeight(); |
|
| 402 |
|
|
| 403 |
ByteBuffer buf = ByteBuffer.allocateDirect(fW*fH*4); |
|
| 404 |
buf.order(ByteOrder.LITTLE_ENDIAN); |
|
| 405 |
|
|
| 406 |
mFramebuffer.setAsReadFramebuffer(0); |
|
| 407 |
GLES31.glReadBuffer(GLES31.GL_COLOR_ATTACHMENT0); |
|
| 408 |
GLES31.glReadPixels( 0, 0, fW, fH, GLES31.GL_RGBA, GLES31.GL_UNSIGNED_BYTE, buf); |
|
| 409 |
BandagedCreatorWorkerThread.newBuffer(buf,fW,fH,6,mPath); |
|
| 410 |
GLES31.glBindFramebuffer(GLES31.GL_READ_FRAMEBUFFER, 0); |
|
| 411 |
|
|
| 412 |
mSaveIcon = -1; |
|
| 413 |
} |
|
| 414 |
|
|
| 415 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 416 |
|
|
| 417 |
void mulObjectRatio(float ratio) |
|
| 418 |
{
|
|
| 419 |
mObjectScreenRatio *= ratio; |
|
| 420 |
|
|
| 421 |
if( mObjectScreenRatio>MAX_SIZE_CHANGE*mInitRatio) mObjectScreenRatio = MAX_SIZE_CHANGE*mInitRatio; |
|
| 422 |
if( mObjectScreenRatio<MIN_SIZE_CHANGE*mInitRatio) mObjectScreenRatio = MIN_SIZE_CHANGE*mInitRatio; |
|
| 423 |
|
|
| 424 |
mRescaling = true; |
|
| 425 |
} |
|
| 426 |
|
|
| 427 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 428 |
|
|
| 429 |
float getObjectRatio() |
|
| 430 |
{
|
|
| 431 |
return mObjectScreenRatio; |
|
| 432 |
} |
|
| 433 |
|
|
| 434 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 435 |
|
|
| 436 |
private void rescaleObject() |
|
| 437 |
{
|
|
| 438 |
float size = mObject.getMaxSize(); |
|
| 439 |
final float Q = mObjectScreenRatio/size; |
|
| 440 |
mScaleValue = mWidth<mHeight ? Q*mWidth : Q*mHeight; |
|
| 441 |
mScale.set( mScaleValue,mScaleValue,mScaleValue ); |
|
| 442 |
} |
|
| 443 |
|
|
| 444 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 445 |
|
|
| 446 |
public void changeObject(int x, int y, int z) |
|
| 447 |
{
|
|
| 448 |
if( mObject.tryChangeObject(x,y,z) ) mCreatingCubits = true; |
|
| 449 |
} |
|
| 450 |
|
|
| 451 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 452 |
|
|
| 453 |
public void displaySavingDialog() |
|
| 454 |
{
|
|
| 455 |
BandagedCreatorActivity act = (BandagedCreatorActivity)mView.getContext(); |
|
| 456 |
RubikDialogBandagedSave saveDiag = new RubikDialogBandagedSave(); |
|
| 457 |
saveDiag.show(act.getSupportFragmentManager(), null); |
|
| 458 |
} |
|
| 459 |
|
|
| 460 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 461 |
|
|
| 462 |
public void setupReset() |
|
| 463 |
{
|
|
| 464 |
mResettingObject = true; |
|
| 465 |
mInitialPhase = true; |
|
| 466 |
mStartTime = System.currentTimeMillis(); |
|
| 467 |
} |
|
| 468 |
|
|
| 469 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 470 |
|
|
| 471 |
public boolean continueResetting(long time) |
|
| 472 |
{
|
|
| 473 |
long diff = time-mStartTime; |
|
| 474 |
float quotient = ((float)diff)/RESET_DURATION; |
|
| 475 |
|
|
| 476 |
if( mInitialPhase && quotient>0.5f ) |
|
| 477 |
{
|
|
| 478 |
mInitialPhase=false; |
|
| 479 |
mView.resetCubits(); |
|
| 480 |
mObject.resetObject(mScaleValue); |
|
| 481 |
} |
|
| 482 |
|
|
| 483 |
double angle = 2*Math.PI*quotient*quotient*(3-2*quotient); |
|
| 484 |
|
|
| 485 |
float sinA = (float)Math.sin(angle); |
|
| 486 |
float cosA = (float)Math.cos(angle); |
|
| 487 |
|
|
| 488 |
mQuatT.set(0, -sinA, 0, cosA); |
|
| 489 |
|
|
| 490 |
return quotient>1.0f; |
|
| 491 |
} |
|
| 492 |
|
|
| 493 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 494 |
|
|
| 495 |
public void touchCubit(int index) |
|
| 496 |
{
|
|
| 497 |
mObject.touchCubit(index); |
|
| 498 |
} |
|
| 499 |
|
|
| 500 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 501 |
|
|
| 502 |
public void untouchCubit(int index) |
|
| 503 |
{
|
|
| 504 |
mObject.untouchCubit(index); |
|
| 505 |
} |
|
| 506 |
|
|
| 507 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 508 |
|
|
| 509 |
public BandagedCreatorTouchControl createTouchControl() |
|
| 510 |
{
|
|
| 511 |
return new BandagedCreatorTouchControl( getObjectRatio() , mScreen.getFOV(), mObject ); |
|
| 512 |
} |
|
| 513 |
|
|
| 514 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 515 |
|
|
| 516 |
public void distortedException(Exception ex) |
|
| 517 |
{
|
|
| 518 |
android.util.Log.e("BandagedCreator", "unexpected exception: "+ex.getMessage() );
|
|
| 519 |
} |
|
| 520 |
|
|
| 521 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 522 |
|
|
| 523 |
public InputStream localFile(int fileID) |
|
| 524 |
{
|
|
| 525 |
return mResources.openRawResource(fileID); |
|
| 526 |
} |
|
| 527 |
|
|
| 528 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 529 |
|
|
| 530 |
public void logMessage(String message) |
|
| 531 |
{
|
|
| 532 |
android.util.Log.e("BandagedCreator", message );
|
|
| 533 |
} |
|
| 534 |
} |
|
| src/main/java/org/distorted/bandaged/BandagedCreatorScreen.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2022 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Magic Cube. // |
|
| 5 |
// // |
|
| 6 |
// Magic Cube is proprietary software licensed under an EULA which you should have received // |
|
| 7 |
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html // |
|
| 8 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 9 |
|
|
| 10 |
package org.distorted.bandaged; |
|
| 11 |
|
|
| 12 |
import java.lang.ref.WeakReference; |
|
| 13 |
import java.util.ArrayList; |
|
| 14 |
|
|
| 15 |
import android.annotation.SuppressLint; |
|
| 16 |
import android.app.Activity; |
|
| 17 |
import android.content.SharedPreferences; |
|
| 18 |
import android.graphics.Bitmap; |
|
| 19 |
import android.util.TypedValue; |
|
| 20 |
import android.view.View; |
|
| 21 |
import android.view.ViewGroup; |
|
| 22 |
import android.widget.AdapterView; |
|
| 23 |
import android.widget.ArrayAdapter; |
|
| 24 |
import android.widget.ImageView; |
|
| 25 |
import android.widget.LinearLayout; |
|
| 26 |
import android.widget.Spinner; |
|
| 27 |
import android.widget.TextView; |
|
| 28 |
|
|
| 29 |
import org.distorted.external.RubikFiles; |
|
| 30 |
import org.distorted.helpers.TransparentImageButton; |
|
| 31 |
import org.distorted.main.R; |
|
| 32 |
import org.distorted.main_old.RubikActivity; |
|
| 33 |
import org.distorted.objectlib.bandaged.LocallyBandagedList; |
|
| 34 |
|
|
| 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 36 |
|
|
| 37 |
public class BandagedCreatorScreen implements AdapterView.OnItemSelectedListener |
|
| 38 |
{
|
|
| 39 |
private WeakReference<BandagedCreatorActivity> mAct; |
|
| 40 |
private TransparentImageButton mBackButton, mResetButton, mDoneButton; |
|
| 41 |
private LinearLayout mObjectView; |
|
| 42 |
private int mNumObjects, mX, mY, mZ; |
|
| 43 |
private final ArrayList<BandagedCreatorObjectView> mViews; |
|
| 44 |
private Spinner mSpinnerX, mSpinnerY, mSpinnerZ; |
|
| 45 |
private boolean mSpinnersReady; |
|
| 46 |
private float mTextSize; |
|
| 47 |
private final int mOrdinal; |
|
| 48 |
private final int mDimension; |
|
| 49 |
private final int mMaxSupported; |
|
| 50 |
private final int mMinSupported; |
|
| 51 |
|
|
| 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 53 |
|
|
| 54 |
public BandagedCreatorScreen(int ordinal) |
|
| 55 |
{
|
|
| 56 |
mOrdinal = ordinal; |
|
| 57 |
mMinSupported = LocallyBandagedList.getMinSupported(ordinal); |
|
| 58 |
mMaxSupported = LocallyBandagedList.getMaxSupported(ordinal); |
|
| 59 |
mDimension = LocallyBandagedList.getDimension(ordinal); |
|
| 60 |
mSpinnersReady= false; |
|
| 61 |
mNumObjects = 0; |
|
| 62 |
mViews = new ArrayList<>(); |
|
| 63 |
} |
|
| 64 |
|
|
| 65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 66 |
|
|
| 67 |
private void setupBackButton(final BandagedCreatorActivity act) |
|
| 68 |
{
|
|
| 69 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 70 |
mBackButton = new TransparentImageButton(act,R.drawable.ui_smallback,params); |
|
| 71 |
|
|
| 72 |
mBackButton.setOnClickListener( new View.OnClickListener() |
|
| 73 |
{
|
|
| 74 |
@Override |
|
| 75 |
public void onClick(View v) |
|
| 76 |
{
|
|
| 77 |
act.finish(); |
|
| 78 |
} |
|
| 79 |
}); |
|
| 80 |
} |
|
| 81 |
|
|
| 82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 83 |
|
|
| 84 |
private void setupDoneButton(final BandagedCreatorActivity act) |
|
| 85 |
{
|
|
| 86 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT); |
|
| 87 |
mDoneButton = new TransparentImageButton(act,R.drawable.ui_done,params); |
|
| 88 |
|
|
| 89 |
mDoneButton.setOnClickListener( new View.OnClickListener() |
|
| 90 |
{
|
|
| 91 |
@Override |
|
| 92 |
public void onClick(View v) |
|
| 93 |
{
|
|
| 94 |
BandagedCreatorRenderer renderer = act.getRenderer(); |
|
| 95 |
if( !renderer.isBusy() ) renderer.displaySavingDialog(); |
|
| 96 |
} |
|
| 97 |
}); |
|
| 98 |
} |
|
| 99 |
|
|
Also available in: Unified diff
Progress with PlayActivity