Revision 314e9ff0
Added by Leszek Koltunski over 3 years ago
| src/main/java/org/distorted/config/ConfigActivity.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.config; |
| 21 | 21 |
|
| 22 |
import java.io.InputStream; |
|
| 23 |
|
|
| 22 | 24 |
import android.os.Build; |
| 23 | 25 |
import android.os.Bundle; |
| 24 | 26 |
import android.util.DisplayMetrics; |
| ... | ... | |
| 26 | 28 |
import android.view.ViewGroup; |
| 27 | 29 |
import android.view.WindowManager; |
| 28 | 30 |
import android.widget.LinearLayout; |
| 29 |
|
|
| 30 | 31 |
import androidx.appcompat.app.AppCompatActivity; |
| 31 |
|
|
| 32 | 32 |
import com.google.firebase.analytics.FirebaseAnalytics; |
| 33 | 33 |
|
| 34 |
import org.distorted.dialogs.RubikDialogError; |
|
| 35 |
import org.distorted.dmesh.ObjectMesh; |
|
| 36 |
import org.distorted.jsons.ObjectJson; |
|
| 37 | 34 |
import org.distorted.library.main.DistortedLibrary; |
| 38 |
import org.distorted.main.R; |
|
| 39 | 35 |
import org.distorted.objectlib.main.ObjectControl; |
| 36 |
import org.distorted.main.R; |
|
| 37 |
import org.distorted.dialogs.RubikDialogError; |
|
| 40 | 38 |
import org.distorted.objects.RubikObject; |
| 41 | 39 |
import org.distorted.objects.RubikObjectList; |
| 42 | 40 |
|
| 43 |
import java.io.InputStream; |
|
| 44 |
|
|
| 45 | 41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 46 | 42 |
|
| 47 | 43 |
public class ConfigActivity extends AppCompatActivity |
| ... | ... | |
| 211 | 207 |
{
|
| 212 | 208 |
if( object!=null ) |
| 213 | 209 |
{
|
| 214 |
int jsonID = object.getJsonID();
|
|
| 215 |
int meshID = object.getMeshID();
|
|
| 216 |
|
|
| 217 |
int meshState = object.getMeshState();
|
|
| 210 |
int ordinal = object.getOrdinal();
|
|
| 211 |
int meshState = object.getMeshState();
|
|
| 212 |
InputStream jsonStream = object.getObjectStream(this); |
|
| 213 |
InputStream meshStream = object.getMeshStream(this);
|
|
| 218 | 214 |
|
| 219 |
InputStream jsonStream = ObjectJson.getObjectStream(jsonID,this); |
|
| 220 |
InputStream meshStream = ObjectMesh.getMeshStream(meshID,this); |
|
| 221 |
|
|
| 222 |
control.changeIfDifferent(object.getOrdinal(),meshState,jsonStream,meshStream); |
|
| 215 |
control.changeIfDifferent(ordinal,meshState,jsonStream,meshStream); |
|
| 223 | 216 |
} |
| 224 | 217 |
} |
| 225 | 218 |
|
| ... | ... | |
| 245 | 238 |
ConfigSurfaceView view = findViewById(R.id.configSurfaceView); |
| 246 | 239 |
ObjectControl control = view.getObjectControl(); |
| 247 | 240 |
|
| 248 |
int jsonID = object.getJsonID(); |
|
| 249 |
int meshID = object.getMeshID(); |
|
| 250 |
|
|
| 251 |
int meshState = object.getMeshState(); |
|
| 252 |
|
|
| 253 |
InputStream jsonStream = ObjectJson.getObjectStream(jsonID,this); |
|
| 254 |
InputStream meshStream = ObjectMesh.getMeshStream(meshID,this); |
|
| 241 |
int ordinal = object.getOrdinal(); |
|
| 242 |
int meshState = object.getMeshState(); |
|
| 243 |
InputStream jsonStream = object.getObjectStream(this); |
|
| 244 |
InputStream meshStream = object.getMeshStream(this); |
|
| 255 | 245 |
|
| 256 |
control.changeObject(object.getOrdinal(),meshState,jsonStream,meshStream);
|
|
| 246 |
control.changeObject(ordinal,meshState,jsonStream,meshStream);
|
|
| 257 | 247 |
} |
| 258 | 248 |
} |
| 259 | 249 |
|
| src/main/java/org/distorted/config/ConfigScreen.java | ||
|---|---|---|
| 96 | 96 |
for(int object=0; object<numObjects; object++) |
| 97 | 97 |
{
|
| 98 | 98 |
final int ordinal = object; |
| 99 |
RubikObject rubikObject = RubikObjectList.getObject(ordinal); |
|
| 100 |
int icons = rubikObject.getIconID(); |
|
| 99 |
RubikObject rObject = RubikObjectList.getObject(ordinal); |
|
| 101 | 100 |
int row = object/NUM_COLUMNS; |
| 102 |
|
|
| 103 | 101 |
ImageButton button = new ImageButton(act); |
| 104 |
button.setBackgroundResource(icons); |
|
| 102 |
if( rObject!=null ) rObject.setIconTo(button); |
|
| 103 |
|
|
| 105 | 104 |
button.setOnClickListener( new View.OnClickListener() |
| 106 | 105 |
{
|
| 107 | 106 |
@Override |
| src/main/java/org/distorted/config/ConfigScreenPane.java | ||
|---|---|---|
| 28 | 28 |
import android.widget.RadioGroup; |
| 29 | 29 |
import android.widget.TextView; |
| 30 | 30 |
|
| 31 |
import org.distorted.jsons.ObjectJson; |
|
| 32 | 31 |
import org.distorted.main.R; |
| 33 | 32 |
import org.distorted.objectlib.json.JsonReader; |
| 34 | 33 |
import org.distorted.objects.RubikObject; |
| ... | ... | |
| 76 | 75 |
mObjectOrdinal = objectOrdinal; |
| 77 | 76 |
|
| 78 | 77 |
RubikObject object = RubikObjectList.getObject(objectOrdinal); |
| 79 |
int jsonID = object.getJsonID(); |
|
| 80 |
InputStream stream = ObjectJson.getObjectStream(jsonID,act); |
|
| 78 |
InputStream stream = object.getObjectStream(act); |
|
| 81 | 79 |
reader.parseJsonFileMetadata(stream); |
| 82 | 80 |
|
| 83 | 81 |
String name = reader.getObjectName(); |
| src/main/java/org/distorted/dialogs/RubikDialogPattern.java | ||
|---|---|---|
| 103 | 103 |
{
|
| 104 | 104 |
int ordinal = RubikPatternList.getObject(i); |
| 105 | 105 |
RubikObject object = RubikObjectList.getObject(ordinal); |
| 106 |
int iconID = object==null ? 0 : object.getIconID(); |
|
| 107 |
|
|
| 108 | 106 |
ImageView imageView = new ImageView(act); |
| 109 |
imageView.setImageResource(iconID);
|
|
| 107 |
if( object!=null ) object.setIconTo(imageView);
|
|
| 110 | 108 |
imageView.setLayoutParams(paramsView); |
| 111 | 109 |
TabLayout.Tab tab = tabLayout.getTabAt(i); |
| 112 | 110 |
if(tab!=null) tab.setCustomView(imageView); |
| src/main/java/org/distorted/dialogs/RubikDialogScores.java | ||
|---|---|---|
| 115 | 115 |
for (int object=0; object<numObjects; object++) |
| 116 | 116 |
{
|
| 117 | 117 |
RubikObject robject = RubikObjectList.getObject(object); |
| 118 |
int iconID = robject==null ? 0 : robject.getIconID(); |
|
| 119 | 118 |
ImageView imageView = new ImageView(act); |
| 120 |
imageView.setImageResource(iconID);
|
|
| 119 |
if( robject!=null ) robject.setIconTo(imageView);
|
|
| 121 | 120 |
imageView.setLayoutParams(paramsView); |
| 122 | 121 |
TabLayout.Tab tab = tabLayout.getTabAt(object); |
| 123 | 122 |
if(tab!=null) tab.setCustomView(imageView); |
| src/main/java/org/distorted/dialogs/RubikDialogTutorial.java | ||
|---|---|---|
| 101 | 101 |
for(int i=0; i<numObjects; i++) |
| 102 | 102 |
{
|
| 103 | 103 |
RubikObject object = RubikObjectList.getObject(i); |
| 104 |
int iconID = object.getIconID(); |
|
| 105 | 104 |
ImageView imageView = new ImageView(act); |
| 106 | 105 |
imageView.setLayoutParams(paramsView); |
| 107 |
imageView.setImageResource(iconID);
|
|
| 106 |
if( object!=null ) object.setIconTo(imageView);
|
|
| 108 | 107 |
TabLayout.Tab tab = tabLayout.getTabAt(i); |
| 109 | 108 |
if(tab!=null) tab.setCustomView(imageView); |
| 110 | 109 |
} |
| src/main/java/org/distorted/dialogs/RubikDialogTutorialView.java | ||
|---|---|---|
| 70 | 70 |
{
|
| 71 | 71 |
super(act); |
| 72 | 72 |
|
| 73 |
InputStream jsonStream = RubikObjectList.getExtrasStream(position,act); |
|
| 73 |
int objectOrdinal = RubikObjectList.getObjectOrdinal(position); |
|
| 74 |
RubikObject robject = RubikObjectList.getObject(objectOrdinal); |
|
| 75 |
InputStream jsonStream = robject==null ? null : robject.getExtrasStream(act); |
|
| 74 | 76 |
String[][] tutorials=null; |
| 75 | 77 |
|
| 76 | 78 |
if( jsonStream!=null ) |
| ... | ... | |
| 95 | 97 |
int colorB = getResources().getColor(R.color.light_grey); |
| 96 | 98 |
int colorT = getResources().getColor(R.color.white); |
| 97 | 99 |
|
| 98 |
int objectOrdinal = RubikObjectList.getObjectOrdinal(position); |
|
| 99 |
|
|
| 100 | 100 |
for (String[] tutorial : tutorials) |
| 101 | 101 |
{
|
| 102 | 102 |
String coun = tutorial[0]; |
| src/main/java/org/distorted/main/RubikActivity.java | ||
|---|---|---|
| 493 | 493 |
{
|
| 494 | 494 |
RubikObject object = RubikObjectList.getObject(ordinal); |
| 495 | 495 |
int meshState = object!=null ? object.getMeshState() : MESH_NICE; |
| 496 |
InputStream jsonStream = object==null ? null : object.getObjectStream(this); |
|
| 497 |
InputStream meshStream = object==null ? null : object.getMeshStream(this); |
|
| 496 | 498 |
|
| 497 |
InputStream jsonStream = ObjectJson.getObjectStream(this,ordinal); |
|
| 498 |
InputStream meshStream = ObjectMesh.getMeshStream(this,ordinal); |
|
| 499 | 499 |
control.changeIfDifferent(ordinal,meshState,jsonStream,meshStream); |
| 500 | 500 |
} |
| 501 | 501 |
|
| src/main/java/org/distorted/objects/RubikObject.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.objects; |
| 21 | 21 |
|
| 22 |
import java.io.InputStream; |
|
| 23 |
|
|
| 24 |
import android.app.Activity; |
|
| 25 |
import android.content.res.Resources; |
|
| 26 |
import android.widget.ImageButton; |
|
| 27 |
import android.widget.ImageView; |
|
| 28 |
|
|
| 22 | 29 |
import org.distorted.dmesh.ObjectMesh; |
| 23 | 30 |
import org.distorted.jsons.ObjectJson; |
| 24 | 31 |
import org.distorted.objectlib.json.JsonWriter; |
| ... | ... | |
| 37 | 44 |
private final int mJsonID, mMeshID, mExtrasID; |
| 38 | 45 |
private final int mIconID; |
| 39 | 46 |
private final String[][] mPatterns; |
| 47 |
private final int mObjectMinor, mExtrasMinor; |
|
| 40 | 48 |
|
| 41 | 49 |
private int mMeshState; |
| 42 | 50 |
private int mExtrasOrdinal; |
| 43 |
private int mObjectMinor, mExtrasMinor; |
|
| 44 | 51 |
|
| 45 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 46 | 53 |
|
| 47 | 54 |
RubikObject(ObjectType type) |
| 48 | 55 |
{
|
| 49 |
mIconID = type.getIconID(); |
|
| 50 | 56 |
mName = type.name(); |
| 51 | 57 |
mNumScramble = type.getNumScramble(); |
| 52 | 58 |
mOrdinal = type.ordinal(); |
| 59 |
|
|
| 60 |
mIconID = type.getIconID(); |
|
| 53 | 61 |
mJsonID = ObjectJson.getObjectJsonID(mOrdinal); |
| 54 | 62 |
mMeshID = ObjectMesh.getMeshID(mOrdinal); |
| 55 | 63 |
mExtrasID = ObjectJson.getExtrasJsonID(mOrdinal); |
| ... | ... | |
| 63 | 71 |
mObjectMinor = JsonWriter.VERSION_OBJECT_MINOR; |
| 64 | 72 |
mExtrasMinor = JsonWriter.VERSION_EXTRAS_MINOR; |
| 65 | 73 |
} |
| 74 |
/* |
|
| 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 76 |
|
|
| 77 |
RubikObject(RubikObjectList.DownloadedObject object) |
|
| 78 |
{
|
|
| 79 |
mName = object.shortName; |
|
| 80 |
|
|
| 81 |
mNumScramble = type.getNumScramble(); |
|
| 82 |
mOrdinal = type.ordinal(); |
|
| 83 |
|
|
| 84 |
mObjectMinor = ? |
|
| 85 |
mExtrasMinor = ? |
|
| 86 |
|
|
| 87 |
mIconID = type.getIconID(); |
|
| 88 |
mJsonID = ObjectJson.getObjectJsonID(mOrdinal); |
|
| 89 |
mExtrasID = ObjectJson.getExtrasJsonID(mOrdinal); |
|
| 90 |
|
|
| 91 |
mMeshID = 0; |
|
| 92 |
mPatterns = null; |
|
| 93 |
|
|
| 94 |
mMeshState = MESH_NICE; |
|
| 95 |
mExtrasOrdinal = -1; |
|
| 96 |
} |
|
| 66 | 97 |
|
| 98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 99 |
|
|
| 100 |
public void updateObject(RubikObjectList.DownloadedObject object) |
|
| 101 |
{
|
|
| 102 |
|
|
| 103 |
} |
|
| 104 |
*/ |
|
| 67 | 105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 68 | 106 |
|
| 69 | 107 |
public void setExtrasOrdinal(int ordinal) |
| ... | ... | |
| 116 | 154 |
|
| 117 | 155 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 118 | 156 |
|
| 119 |
public int getIconID() |
|
| 157 |
public void setIconTo(ImageButton button) |
|
| 158 |
{
|
|
| 159 |
button.setBackgroundResource(mIconID); |
|
| 160 |
} |
|
| 161 |
|
|
| 162 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 163 |
|
|
| 164 |
public void setIconTo(ImageView view) |
|
| 165 |
{
|
|
| 166 |
view.setImageResource(mIconID); |
|
| 167 |
} |
|
| 168 |
|
|
| 169 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 170 |
|
|
| 171 |
public InputStream getObjectStream(Activity act) |
|
| 120 | 172 |
{
|
| 121 |
return mIconID; |
|
| 173 |
if( mJsonID!=0 ) |
|
| 174 |
{
|
|
| 175 |
Resources res = act.getResources(); |
|
| 176 |
return res.openRawResource(mJsonID); |
|
| 177 |
} |
|
| 178 |
return null; |
|
| 122 | 179 |
} |
| 123 | 180 |
|
| 124 | 181 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 125 | 182 |
|
| 126 |
public int getJsonID()
|
|
| 183 |
public InputStream getMeshStream(Activity act)
|
|
| 127 | 184 |
{
|
| 128 |
return mJsonID; |
|
| 185 |
if( mMeshID!=0 ) |
|
| 186 |
{
|
|
| 187 |
Resources res = act.getResources(); |
|
| 188 |
return res.openRawResource(mMeshID); |
|
| 189 |
} |
|
| 190 |
return null; |
|
| 129 | 191 |
} |
| 130 | 192 |
|
| 131 | 193 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 132 | 194 |
|
| 133 |
public int getMeshID()
|
|
| 195 |
public InputStream getExtrasStream(Activity act)
|
|
| 134 | 196 |
{
|
| 135 |
return mMeshID; |
|
| 197 |
if( mExtrasID!=0 ) |
|
| 198 |
{
|
|
| 199 |
Resources res = act.getResources(); |
|
| 200 |
return res.openRawResource(mExtrasID); |
|
| 201 |
} |
|
| 202 |
return null; |
|
| 136 | 203 |
} |
| 137 | 204 |
|
| 138 | 205 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 139 | 206 |
|
| 140 |
public int getExtrasJsonID()
|
|
| 207 |
public boolean hasExtras()
|
|
| 141 | 208 |
{
|
| 142 |
return mExtrasID; |
|
| 209 |
return mExtrasID!=0;
|
|
| 143 | 210 |
} |
| 144 | 211 |
|
| 145 | 212 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/objects/RubikObjectList.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.objects; |
| 21 | 21 |
|
| 22 |
import java.io.InputStream; |
|
| 23 | 22 |
import java.util.ArrayList; |
| 24 | 23 |
|
| 25 |
import android.app.Activity; |
|
| 26 | 24 |
import android.content.SharedPreferences; |
| 27 | 25 |
|
| 28 |
import org.distorted.jsons.ObjectJson; |
|
| 29 | 26 |
import org.distorted.main.RubikActivity; |
| 30 | 27 |
import org.distorted.objectlib.main.ObjectConstants; |
| 31 | 28 |
import org.distorted.objectlib.main.ObjectType; |
| ... | ... | |
| 48 | 45 |
private static ArrayList<RubikObject> mObjects; |
| 49 | 46 |
private static int mObject = DEF_OBJECT; |
| 50 | 47 |
|
| 51 |
private static class DownloadedObject
|
|
| 48 |
public static class DownloadedObject
|
|
| 52 | 49 |
{
|
| 53 | 50 |
String shortName; |
| 54 | 51 |
boolean icon,object,extras; |
| ... | ... | |
| 101 | 98 |
mObjects.add(obj); |
| 102 | 99 |
mNumObjects++; |
| 103 | 100 |
|
| 104 |
if( obj.getExtrasJsonID()!=0 )
|
|
| 101 |
if( obj.hasExtras() )
|
|
| 105 | 102 |
{
|
| 106 | 103 |
obj.setExtrasOrdinal(mNumExtras); |
| 107 | 104 |
mNumExtras++; |
| ... | ... | |
| 113 | 110 |
|
| 114 | 111 |
private static void internalAddDownloadedObject(DownloadedObject object) |
| 115 | 112 |
{
|
| 113 |
/* |
|
| 114 |
boolean existsAlready = false; |
|
| 115 |
String name = object.shortName; |
|
| 116 |
|
|
| 117 |
for(RubikObject ro : mObjects ) |
|
| 118 |
if( ro.getName().equals(name) ) |
|
| 119 |
{
|
|
| 120 |
ro.updateObject(object); |
|
| 121 |
existsAlready = true; |
|
| 122 |
break; |
|
| 123 |
} |
|
| 124 |
|
|
| 125 |
if( !existsAlready ) |
|
| 126 |
{
|
|
| 127 |
RubikObject obj = new RubikObject(object); |
|
| 128 |
mObjects.add(obj); |
|
| 129 |
mNumObjects++; |
|
| 116 | 130 |
|
| 131 |
if( obj.getExtrasJsonID()!=0 ) |
|
| 132 |
{
|
|
| 133 |
obj.setExtrasOrdinal(mNumExtras); |
|
| 134 |
mNumExtras++; |
|
| 135 |
} |
|
| 136 |
} |
|
| 137 |
*/ |
|
| 117 | 138 |
} |
| 118 | 139 |
|
| 119 | 140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 356 | 377 |
return mNumExtras; |
| 357 | 378 |
} |
| 358 | 379 |
|
| 359 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 360 |
|
|
| 361 |
public static InputStream getExtrasStream(int extrasOrdinal, Activity act) |
|
| 362 |
{
|
|
| 363 |
int objectOrdinal = getObjectOrdinal(extrasOrdinal); |
|
| 364 |
RubikObject object= getObject(objectOrdinal); |
|
| 365 |
|
|
| 366 |
if( object!=null ) |
|
| 367 |
{
|
|
| 368 |
int jsonID = object.getExtrasJsonID(); |
|
| 369 |
return ObjectJson.getExtrasStream(jsonID,act); |
|
| 370 |
} |
|
| 371 |
|
|
| 372 |
return null; |
|
| 373 |
} |
|
| 374 |
|
|
| 375 | 380 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 376 | 381 |
|
| 377 | 382 |
public static int getObjectOrdinal(int extrasOrdinal) |
| src/main/java/org/distorted/screens/RubikScreenPlay.java | ||
|---|---|---|
| 273 | 273 |
|
| 274 | 274 |
for(int object=0; object<numObjects; object++) |
| 275 | 275 |
{
|
| 276 |
final RubikObject robject = RubikObjectList.getObject(object);
|
|
| 277 |
int icons = robject==null ? 0 : robject.getIconID();
|
|
| 276 |
final int ordinal = object;
|
|
| 277 |
final RubikObject rObject = RubikObjectList.getObject(object);
|
|
| 278 | 278 |
int row = object/NUM_COLUMNS; |
| 279 |
final int ordinal = robject==null ? 0 : robject.getOrdinal(); |
|
| 280 |
|
|
| 281 | 279 |
ImageButton button = new ImageButton(act); |
| 282 |
button.setBackgroundResource(icons); |
|
| 280 |
if( rObject!=null ) rObject.setIconTo(button); |
|
| 281 |
|
|
| 283 | 282 |
button.setOnClickListener( new View.OnClickListener() |
| 284 | 283 |
{
|
| 285 | 284 |
@Override |
| src/main/java/org/distorted/tutorials/TutorialActivity.java | ||
|---|---|---|
| 232 | 232 |
{
|
| 233 | 233 |
RubikObject object = RubikObjectList.getObject(ordinal); |
| 234 | 234 |
int meshState = object!=null ? object.getMeshState() : MESH_NICE; |
| 235 |
InputStream jsonStream = object==null ? null : object.getObjectStream(this); |
|
| 236 |
InputStream meshStream = object==null ? null : object.getMeshStream(this); |
|
| 235 | 237 |
|
| 236 |
InputStream jsonStream = ObjectJson.getObjectStream(this,ordinal); |
|
| 237 |
InputStream meshStream = ObjectMesh.getMeshStream(this,ordinal); |
|
| 238 | 238 |
control.changeIfDifferent(ordinal,meshState,jsonStream,meshStream); |
| 239 | 239 |
} |
| 240 | 240 |
|
Also available in: Unified diff
Refactor RubikObject in preparation for creating RubikObjects from DownloadedObjects.