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 |
5b22f901
|
leszek
|
package org.distorted.info;
|
11 |
74d088c3
|
Leszek Koltunski
|
|
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 |
5b22f901
|
leszek
|
public class InfoScreenPane
|
31 |
74d088c3
|
Leszek Koltunski
|
{
|
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 |
5b22f901
|
leszek
|
void updatePane(InfoActivity act, int objectOrdinal)
|
39 |
74d088c3
|
Leszek Koltunski
|
{
|
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 |
5b22f901
|
leszek
|
LinearLayout layout = act.findViewById(R.id.infoLayout);
|
67 |
|
|
TextView view = layout.findViewById(R.id.infoDetailsName2);
|
68 |
c826d83b
|
Leszek Koltunski
|
view.setText(name);
|
69 |
5b22f901
|
leszek
|
view = layout.findViewById(R.id.infoDetailsAuthor2);
|
70 |
b45b986a
|
leszek
|
view.setText(author);
|
71 |
5b22f901
|
leszek
|
view = layout.findViewById(R.id.infoDetailsYear2);
|
72 |
b45b986a
|
leszek
|
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 |
5b22f901
|
leszek
|
InfoScreenPane(final InfoActivity act, int objectOrdinal)
|
89 |
74d088c3
|
Leszek Koltunski
|
{
|
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 |
5b22f901
|
leszek
|
LinearLayout configLayout = act.findViewById(R.id.infoLayout);
|
95 |
|
|
LinearLayout nameLayout = configLayout.findViewById(R.id.infoLayoutName);
|
96 |
|
|
LinearLayout difficultyLayout= configLayout.findViewById(R.id.infoLayoutDifficulty);
|
97 |
|
|
LinearLayout authorLayout = configLayout.findViewById(R.id.infoLayoutAuthor);
|
98 |
|
|
LinearLayout yearLayout = configLayout.findViewById(R.id.infoLayoutYear);
|
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 |
5b22f901
|
leszek
|
text = nameLayout.findViewById(R.id.infoDetailsName1);
|
124 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
125 |
5b22f901
|
leszek
|
text = nameLayout.findViewById(R.id.infoDetailsName2);
|
126 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
127 |
5b22f901
|
leszek
|
text = authorLayout.findViewById(R.id.infoDetailsAuthor1);
|
128 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
129 |
5b22f901
|
leszek
|
text = authorLayout.findViewById(R.id.infoDetailsAuthor2);
|
130 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
131 |
5b22f901
|
leszek
|
text = difficultyLayout.findViewById(R.id.infoDifficultyTitle);
|
132 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
133 |
5b22f901
|
leszek
|
text = yearLayout.findViewById(R.id.infoDetailsYear1);
|
134 |
b45b986a
|
leszek
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
135 |
5b22f901
|
leszek
|
text = yearLayout.findViewById(R.id.infoDetailsYear2);
|
136 |
2e99ba6a
|
Leszek Koltunski
|
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
137 |
|
|
|
138 |
5b22f901
|
leszek
|
LinearLayout layoutDiff = difficultyLayout.findViewById(R.id.infoDifficultyLayout);
|
139 |
2e99ba6a
|
Leszek Koltunski
|
layoutDiff.setPadding(padding,padding,padding,padding);
|
140 |
|
|
|
141 |
74d088c3
|
Leszek Koltunski
|
updatePane(act,objectOrdinal);
|
142 |
|
|
}
|
143 |
|
|
}
|