| 12 |
12 |
import android.util.TypedValue;
|
| 13 |
13 |
import android.widget.ImageView;
|
| 14 |
14 |
import android.widget.LinearLayout;
|
| 15 |
|
import android.widget.RelativeLayout;
|
| 16 |
15 |
import android.widget.TextView;
|
| 17 |
16 |
|
| 18 |
17 |
import org.distorted.main.R;
|
| ... | ... | |
| 37 |
36 |
|
| 38 |
37 |
private static final int NUM_IMAGES = IMAGES.length;
|
| 39 |
38 |
public static final float PADDING_RATIO = 0.025f;
|
| 40 |
|
private static final float TEXT_RATIO = 0.042f;
|
|
39 |
private static final float TEXT_RATIO = 0.050f;
|
| 41 |
40 |
|
| 42 |
41 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 43 |
42 |
|
| ... | ... | |
| 49 |
48 |
{
|
| 50 |
49 |
InputStream stream = object.getObjectStream(act);
|
| 51 |
50 |
JsonReader reader = JsonReader.getInstance();
|
| 52 |
|
String name;
|
| 53 |
|
int difficulty;
|
|
51 |
String author, name;
|
|
52 |
int year, difficulty;
|
| 54 |
53 |
|
| 55 |
54 |
try
|
| 56 |
55 |
{
|
| 57 |
56 |
reader.parseJsonFileMetadata(stream);
|
| 58 |
57 |
name = reader.getObjectName();
|
|
58 |
author = reader.getInventor();
|
|
59 |
year = reader.getYearOfInvention();
|
| 59 |
60 |
difficulty = reader.getComplexity();
|
| 60 |
61 |
}
|
| 61 |
62 |
catch(Exception ex)
|
| 62 |
63 |
{
|
| 63 |
64 |
name = "?";
|
|
65 |
author = "?";
|
|
66 |
year = 0;
|
| 64 |
67 |
difficulty = 0;
|
| 65 |
68 |
}
|
| 66 |
69 |
|
| 67 |
70 |
if( difficulty<0 ) difficulty=0;
|
| 68 |
71 |
if( difficulty>=NUM_IMAGES ) difficulty=NUM_IMAGES-1;
|
| 69 |
72 |
|
| 70 |
|
TextView view = act.findViewById(R.id.purchaseDetailsName);
|
| 71 |
|
view.setText(name);
|
|
73 |
String both = year>0 ? author+" "+year : author;
|
|
74 |
|
|
75 |
TextView v1 = act.findViewById(R.id.purchaseUpperName);
|
|
76 |
v1.setText(name);
|
|
77 |
TextView v2 = act.findViewById(R.id.purchaseUpperAuthor);
|
|
78 |
v2.setText(both);
|
| 72 |
79 |
ImageView image = act.findViewById(R.id.purchaseDifficulty);
|
| 73 |
80 |
image.setImageResource(IMAGES[difficulty]);
|
| 74 |
81 |
}
|
| ... | ... | |
| 82 |
89 |
float textSize = width*TEXT_RATIO;
|
| 83 |
90 |
int padding = (int)(width*PADDING_RATIO);
|
| 84 |
91 |
|
| 85 |
|
RelativeLayout upperBar = act.findViewById(R.id.upperBar);
|
| 86 |
|
LinearLayout oneLayout = act.findViewById(R.id.purchaseLayoutOne);
|
| 87 |
|
LinearLayout allLayout = act.findViewById(R.id.purchaseLayoutAll);
|
|
92 |
LinearLayout upperBar = act.findViewById(R.id.upperBar);
|
|
93 |
LinearLayout oneLayout = act.findViewById(R.id.purchaseLayoutOne);
|
|
94 |
LinearLayout allLayout = act.findViewById(R.id.purchaseLayoutAll);
|
| 88 |
95 |
|
| 89 |
|
upperBar.setPadding(padding,padding,padding,padding/2);
|
|
96 |
upperBar.setPadding( padding,padding/2,padding,padding/2);
|
| 90 |
97 |
oneLayout.setPadding(padding,padding/2,padding,padding/2);
|
| 91 |
98 |
allLayout.setPadding(padding,padding/2,padding,padding/2);
|
| 92 |
99 |
|
| 93 |
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f);
|
| 94 |
|
params.bottomMargin = 0;
|
| 95 |
|
params.topMargin = padding;
|
| 96 |
|
params.leftMargin = padding;
|
| 97 |
|
params.rightMargin = padding;
|
|
100 |
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f);
|
|
101 |
params1.bottomMargin = 0;
|
|
102 |
params1.topMargin = padding;
|
|
103 |
params1.leftMargin = padding;
|
|
104 |
params1.rightMargin = padding;
|
|
105 |
|
|
106 |
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f);
|
|
107 |
params2.bottomMargin = padding;
|
|
108 |
params2.topMargin = padding;
|
|
109 |
params2.leftMargin = padding;
|
|
110 |
params2.rightMargin = padding;
|
| 98 |
111 |
|
| 99 |
|
upperBar.setLayoutParams(params);
|
| 100 |
|
oneLayout.setLayoutParams(params);
|
| 101 |
|
allLayout.setLayoutParams(params);
|
|
112 |
upperBar.setLayoutParams(params1);
|
|
113 |
oneLayout.setLayoutParams(params1);
|
|
114 |
allLayout.setLayoutParams(params2);
|
| 102 |
115 |
|
| 103 |
116 |
TextView text;
|
| 104 |
|
text = upperBar.findViewById(R.id.purchaseDetailsName);
|
|
117 |
text = upperBar.findViewById(R.id.purchaseUpperName);
|
|
118 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
|
119 |
text = upperBar.findViewById(R.id.purchaseUpperAuthor);
|
| 105 |
120 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
| 106 |
121 |
text = oneLayout.findViewById(R.id.purchaseTextOne);
|
| 107 |
122 |
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
|
IAP part 5: new 'Purchase' activity (cont'd)