Project

General

Profile

« Previous | Next » 

Revision cd432dd3

Added by Leszek Koltunski over 2 years ago

IAP part 5: new 'Purchase' activity (cont'd)

View differences:

src/main/java/org/distorted/purchase/PurchaseScreenPane.java
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);
src/main/res/layout/purchase.xml
6 6
    android:background="@color/light_grey"
7 7
    android:orientation="vertical">
8 8

  
9
    <RelativeLayout
9
    <LinearLayout
10 10
         android:id="@+id/upperBar"
11 11
         android:layout_width="fill_parent"
12 12
         android:layout_height="100dp"
......
15 15
         android:background="@color/grey"
16 16
         android:orientation="horizontal">
17 17

  
18
         <TextView
19
             android:id="@+id/purchaseDetailsName"
20
             android:layout_width="wrap_content"
18
         <LinearLayout
19
             android:id="@+id/upperBarLeft"
20
             android:layout_width="0dp"
21 21
             android:layout_height="match_parent"
22
             android:layout_alignParentStart="true"
23
             android:paddingStart="5dp"
24
             android:textSize="26sp"
25
             android:singleLine="true"
26
             android:maxLines="1"/>
22
             android:layout_weight="3.0"
23
             android:gravity="center_vertical|start"
24
             android:background="@color/grey"
25
             android:orientation="vertical">
26

  
27
             <TextView
28
                 android:id="@+id/purchaseUpperName"
29
                 android:layout_width="match_parent"
30
                 android:layout_height="wrap_content"
31
                 android:paddingStart="5dp"
32
                 android:textSize="26sp"
33
                 android:singleLine="true"
34
                 android:maxLines="1"/>
35
             <TextView
36
                 android:id="@+id/purchaseUpperAuthor"
37
                 android:layout_width="match_parent"
38
                 android:layout_height="wrap_content"
39
                 android:paddingStart="5dp"
40
                 android:textSize="26sp"
41
                 android:singleLine="true"
42
                 android:maxLines="1"/>
43
         </LinearLayout>
27 44

  
28 45
         <ImageView
29 46
             android:id="@+id/purchaseDifficulty"
30
             android:layout_width="wrap_content"
47
             android:layout_width="0dp"
31 48
             android:layout_height="match_parent"
32
             android:layout_alignParentEnd="true"/>
33
    </RelativeLayout>
49
             android:layout_weight="1.0"/>
50

  
51
    </LinearLayout>
34 52

  
35 53
    <org.distorted.purchase.PurchaseSurfaceView
36 54
        android:id="@+id/purchaseSurfaceView"

Also available in: Unified diff