Project

General

Profile

Download (4.04 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / purchase / PurchaseScreenPane.java @ 71cda061

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// 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
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.purchase;
11

    
12
import android.util.TypedValue;
13
import android.widget.ImageView;
14
import android.widget.LinearLayout;
15
import android.widget.RelativeLayout;
16
import android.widget.TextView;
17

    
18
import org.distorted.main.R;
19
import org.distorted.objectlib.json.JsonReader;
20
import org.distorted.objects.RubikObject;
21
import org.distorted.objects.RubikObjectList;
22

    
23
import java.io.InputStream;
24

    
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26

    
27
public class PurchaseScreenPane
28
{
29
  private static final int[] IMAGES =
30
    {
31
    R.drawable.difficulty1,
32
    R.drawable.difficulty2,
33
    R.drawable.difficulty3,
34
    R.drawable.difficulty4,
35
    R.drawable.difficulty5,
36
    };
37

    
38
  private static final int NUM_IMAGES      = IMAGES.length;
39
  public  static final float PADDING_RATIO = 0.025f;
40
  private static final float TEXT_RATIO    = 0.042f;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
  void updatePane(PurchaseActivity act, int objectOrdinal)
45
    {
46
    RubikObject object = RubikObjectList.getObject(objectOrdinal);
47

    
48
    if( object!=null )
49
      {
50
      InputStream stream = object.getObjectStream(act);
51
      JsonReader reader = JsonReader.getInstance();
52
      String name;
53
      int difficulty;
54

    
55
      try
56
        {
57
        reader.parseJsonFileMetadata(stream);
58
        name       = reader.getObjectName();
59
        difficulty = reader.getComplexity();
60
        }
61
      catch(Exception ex)
62
        {
63
        name = "?";
64
        difficulty = 0;
65
        }
66

    
67
      if( difficulty<0           ) difficulty=0;
68
      if( difficulty>=NUM_IMAGES ) difficulty=NUM_IMAGES-1;
69

    
70
      TextView view = act.findViewById(R.id.purchaseDetailsName);
71
      view.setText(name);
72
      ImageView image = act.findViewById(R.id.purchaseDifficulty);
73
      image.setImageResource(IMAGES[difficulty]);
74
      }
75
    }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

    
79
  PurchaseScreenPane(final PurchaseActivity act)
80
    {
81
    int width = act.getScreenWidthInPixels();
82
    float textSize = width*TEXT_RATIO;
83
    int padding = (int)(width*PADDING_RATIO);
84

    
85
    RelativeLayout upperBar  = act.findViewById(R.id.upperBar);
86
    LinearLayout oneLayout   = act.findViewById(R.id.purchaseLayoutOne);
87
    LinearLayout allLayout   = act.findViewById(R.id.purchaseLayoutAll);
88

    
89
    upperBar.setPadding(padding,padding,padding,padding/2);
90
    oneLayout.setPadding(padding,padding/2,padding,padding/2);
91
    allLayout.setPadding(padding,padding/2,padding,padding/2);
92

    
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;
98

    
99
    upperBar.setLayoutParams(params);
100
    oneLayout.setLayoutParams(params);
101
    allLayout.setLayoutParams(params);
102

    
103
    TextView text;
104
    text = upperBar.findViewById(R.id.purchaseDetailsName);
105
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
106
    text = oneLayout.findViewById(R.id.purchaseTextOne);
107
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
108
    text = allLayout.findViewById(R.id.purchaseTextAll);
109
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
110
    }
111
}
(5-5/6)