| 1 |
74d088c3
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
// Copyright 2020 Leszek Koltunski //
|
| 3 |
|
|
// //
|
| 4 |
|
|
// This file is part of Magic Cube. //
|
| 5 |
|
|
// //
|
| 6 |
9d51b9d6
|
Leszek Koltunski
|
// 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 |
74d088c3
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 9 |
|
|
|
| 10 |
|
|
package org.distorted.config;
|
| 11 |
|
|
|
| 12 |
ff4a2a13
|
leszek
|
import static org.distorted.objects.RubikObjectCategories.DIFF_IDS;
|
| 13 |
|
|
import static org.distorted.objects.RubikObjectCategories.DIFF_IMAGES;
|
| 14 |
|
|
|
| 15 |
09cf2a36
|
Leszek Koltunski
|
import java.io.InputStream;
|
| 16 |
|
|
|
| 17 |
8375250f
|
Leszek Koltunski
|
import android.graphics.PorterDuff;
|
| 18 |
2e99ba6a
|
Leszek Koltunski
|
import android.util.TypedValue;
|
| 19 |
2604be3b
|
Leszek Koltunski
|
import android.widget.ImageView;
|
| 20 |
74d088c3
|
Leszek Koltunski
|
import android.widget.LinearLayout;
|
| 21 |
|
|
import android.widget.TextView;
|
| 22 |
|
|
|
| 23 |
|
|
import org.distorted.main.R;
|
| 24 |
|
|
import org.distorted.objectlib.json.JsonReader;
|
| 25 |
a7d8c3cd
|
Leszek Koltunski
|
import org.distorted.objects.RubikObject;
|
| 26 |
|
|
import org.distorted.objects.RubikObjectList;
|
| 27 |
74d088c3
|
Leszek Koltunski
|
|
| 28 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 29 |
|
|
|
| 30 |
|
|
public class ConfigScreenPane
|
| 31 |
|
|
{
|
| 32 |
ff4a2a13
|
leszek
|
private static final int NUM_IDS = DIFF_IDS.length;
|
| 33 |
27401bea
|
Leszek Koltunski
|
private static final float PADDING_RATIO = 0.016f;
|
| 34 |
9c634626
|
leszek
|
private static final float TEXT_RATIO = 0.025f;
|
| 35 |
74d088c3
|
Leszek Koltunski
|
|
| 36 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 37 |
|
|
|
| 38 |
|
|
void updatePane(ConfigActivity act, int objectOrdinal)
|
| 39 |
|
|
{
|
| 40 |
c826d83b
|
Leszek Koltunski
|
RubikObject object = RubikObjectList.getObject(objectOrdinal);
|
| 41 |
74d088c3
|
Leszek Koltunski
|
|
| 42 |
c826d83b
|
Leszek Koltunski
|
if( object!=null )
|
| 43 |
|
|
{
|
| 44 |
|
|
InputStream stream = object.getObjectStream(act);
|
| 45 |
923d267c
|
Leszek Koltunski
|
|
| 46 |
5305fdc8
|
Leszek Koltunski
|
JsonReader reader = new JsonReader();
|
| 47 |
c020555e
|
Leszek Koltunski
|
String name,author;
|
| 48 |
|
|
int year, difficulty;
|
| 49 |
|
|
|
| 50 |
|
|
try
|
| 51 |
|
|
{
|
| 52 |
|
|
reader.parseJsonFileMetadata(stream);
|
| 53 |
|
|
name = reader.getObjectName();
|
| 54 |
ff4a2a13
|
leszek
|
author = reader.getAuthor();
|
| 55 |
c020555e
|
Leszek Koltunski
|
year = reader.getYearOfInvention();
|
| 56 |
ff4a2a13
|
leszek
|
difficulty = (int)reader.getDifficulty();
|
| 57 |
c020555e
|
Leszek Koltunski
|
}
|
| 58 |
|
|
catch(Exception ex)
|
| 59 |
|
|
{
|
| 60 |
|
|
name = "?";
|
| 61 |
|
|
author = "?";
|
| 62 |
|
|
year = 0;
|
| 63 |
|
|
difficulty = 0;
|
| 64 |
|
|
}
|
| 65 |
74d088c3
|
Leszek Koltunski
|
|
| 66 |
c826d83b
|
Leszek Koltunski
|
LinearLayout layout = act.findViewById(R.id.configLayout);
|
| 67 |
|
|
TextView view = layout.findViewById(R.id.configDetailsName2);
|
| 68 |
|
|
view.setText(name);
|
| 69 |
|
|
view = layout.findViewById(R.id.configDetailsAuthor2);
|
| 70 |
b45b986a
|
leszek
|
view.setText(author);
|
| 71 |
|
|
view = layout.findViewById(R.id.configDetailsYear2);
|
| 72 |
|
|
view.setText( year>0 ? String.valueOf(year) : "?" );
|
| 73 |
2604be3b
|
Leszek Koltunski
|
|
| 74 |
71cda061
|
Leszek Koltunski
|
if( difficulty<0 ) difficulty=0;
|
| 75 |
|
|
if( difficulty>=NUM_IDS ) difficulty=NUM_IDS-1;
|
| 76 |
2604be3b
|
Leszek Koltunski
|
|
| 77 |
8375250f
|
Leszek Koltunski
|
for(int i=0; i<NUM_IDS; i++)
|
| 78 |
c826d83b
|
Leszek Koltunski
|
{
|
| 79 |
ff4a2a13
|
leszek
|
ImageView image = layout.findViewById(DIFF_IDS[i]);
|
| 80 |
|
|
image.setImageResource(DIFF_IMAGES[i]);
|
| 81 |
8375250f
|
Leszek Koltunski
|
image.setColorFilter( difficulty==i ? 0xffff0000 : 0xffffffff, PorterDuff.Mode.MULTIPLY );
|
| 82 |
c826d83b
|
Leszek Koltunski
|
}
|
| 83 |
|
|
}
|
| 84 |
74d088c3
|
Leszek Koltunski
|
}
|
| 85 |
|
|
|
| 86 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 87 |
|
|
|
| 88 |
|
|
ConfigScreenPane(final ConfigActivity act, int objectOrdinal)
|
| 89 |
|
|
{
|
| 90 |
27401bea
|
Leszek Koltunski
|
int height = act.getScreenHeightInPixels();
|
| 91 |
|
|
float textSize = height*TEXT_RATIO;
|
| 92 |
|
|
int padding = (int)(height*PADDING_RATIO);
|
| 93 |
2e99ba6a
|
Leszek Koltunski
|
|
| 94 |
21efc7d7
|
Leszek Koltunski
|
LinearLayout configLayout = act.findViewById(R.id.configLayout);
|
| 95 |
|
|
LinearLayout nameLayout = configLayout.findViewById(R.id.configLayoutName);
|
| 96 |
|
|
LinearLayout difficultyLayout= configLayout.findViewById(R.id.configLayoutDifficulty);
|
| 97 |
b45b986a
|
leszek
|
LinearLayout authorLayout = configLayout.findViewById(R.id.configLayoutAuthor);
|
| 98 |
|
|
LinearLayout yearLayout = configLayout.findViewById(R.id.configLayoutYear);
|
| 99 |
21efc7d7
|
Leszek Koltunski
|
|
| 100 |
|
|
nameLayout.setPadding(padding,padding,padding,padding/2);
|
| 101 |
2e99ba6a
|
Leszek Koltunski
|
difficultyLayout.setPadding(padding,padding/2,padding,padding/2);
|
| 102 |
b45b986a
|
leszek
|
authorLayout.setPadding(padding,padding/2,padding,padding/2);
|
| 103 |
df1e5f21
|
leszek
|
yearLayout.setPadding(padding,padding/2,padding,padding/2);
|
| 104 |
|
|
|
| 105 |
|
|
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f);
|
| 106 |
|
|
params1.bottomMargin = 0;
|
| 107 |
|
|
params1.topMargin = padding;
|
| 108 |
|
|
params1.leftMargin = padding;
|
| 109 |
|
|
params1.rightMargin = padding;
|
| 110 |
|
|
|
| 111 |
|
|
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f);
|
| 112 |
|
|
params2.bottomMargin = padding;
|
| 113 |
|
|
params2.topMargin = padding;
|
| 114 |
|
|
params2.leftMargin = padding;
|
| 115 |
|
|
params2.rightMargin = padding;
|
| 116 |
|
|
|
| 117 |
|
|
nameLayout.setLayoutParams(params1);
|
| 118 |
|
|
difficultyLayout.setLayoutParams(params1);
|
| 119 |
|
|
authorLayout.setLayoutParams(params1);
|
| 120 |
|
|
yearLayout.setLayoutParams(params2);
|
| 121 |
74d088c3
|
Leszek Koltunski
|
|
| 122 |
|
|
TextView text;
|
| 123 |
21efc7d7
|
Leszek Koltunski
|
text = nameLayout.findViewById(R.id.configDetailsName1);
|
| 124 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
| 125 |
21efc7d7
|
Leszek Koltunski
|
text = nameLayout.findViewById(R.id.configDetailsName2);
|
| 126 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
| 127 |
21efc7d7
|
Leszek Koltunski
|
text = authorLayout.findViewById(R.id.configDetailsAuthor1);
|
| 128 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
| 129 |
21efc7d7
|
Leszek Koltunski
|
text = authorLayout.findViewById(R.id.configDetailsAuthor2);
|
| 130 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
| 131 |
cc48b275
|
Leszek Koltunski
|
text = difficultyLayout.findViewById(R.id.configDifficultyTitle);
|
| 132 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
| 133 |
b45b986a
|
leszek
|
text = yearLayout.findViewById(R.id.configDetailsYear1);
|
| 134 |
|
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
| 135 |
|
|
text = yearLayout.findViewById(R.id.configDetailsYear2);
|
| 136 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
| 137 |
|
|
|
| 138 |
|
|
LinearLayout layoutDiff = difficultyLayout.findViewById(R.id.configDifficultyLayout);
|
| 139 |
|
|
layoutDiff.setPadding(padding,padding,padding,padding);
|
| 140 |
|
|
|
| 141 |
74d088c3
|
Leszek Koltunski
|
updatePane(act,objectOrdinal);
|
| 142 |
|
|
}
|
| 143 |
|
|
}
|