Project

General

Profile

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

magiccube / src / main / java / org / distorted / info / InfoScreenPane.java @ 5b22f901

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.info;
11

    
12
import static org.distorted.objects.RubikObjectCategories.DIFF_IDS;
13
import static org.distorted.objects.RubikObjectCategories.DIFF_IMAGES;
14

    
15
import java.io.InputStream;
16

    
17
import android.graphics.PorterDuff;
18
import android.util.TypedValue;
19
import android.widget.ImageView;
20
import android.widget.LinearLayout;
21
import android.widget.TextView;
22

    
23
import org.distorted.main.R;
24
import org.distorted.objectlib.json.JsonReader;
25
import org.distorted.objects.RubikObject;
26
import org.distorted.objects.RubikObjectList;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

    
30
public class InfoScreenPane
31
{
32
  private static final int NUM_IDS         = DIFF_IDS.length;
33
  private static final float PADDING_RATIO = 0.016f;
34
  private static final float TEXT_RATIO    = 0.025f;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

    
38
  void updatePane(InfoActivity act, int objectOrdinal)
39
    {
40
    RubikObject object = RubikObjectList.getObject(objectOrdinal);
41

    
42
    if( object!=null )
43
      {
44
      InputStream stream = object.getObjectStream(act);
45

    
46
      JsonReader reader = new JsonReader();
47
      String name,author;
48
      int year, difficulty;
49

    
50
      try
51
        {
52
        reader.parseJsonFileMetadata(stream);
53
        name       = reader.getObjectName();
54
        author     = reader.getAuthor();
55
        year       = reader.getYearOfInvention();
56
        difficulty = (int)reader.getDifficulty();
57
        }
58
      catch(Exception ex)
59
        {
60
        name = "?";
61
        author = "?";
62
        year = 0;
63
        difficulty = 0;
64
        }
65

    
66
      LinearLayout layout = act.findViewById(R.id.infoLayout);
67
      TextView view = layout.findViewById(R.id.infoDetailsName2);
68
      view.setText(name);
69
      view = layout.findViewById(R.id.infoDetailsAuthor2);
70
      view.setText(author);
71
      view = layout.findViewById(R.id.infoDetailsYear2);
72
      view.setText( year>0 ? String.valueOf(year) : "?" );
73

    
74
      if( difficulty<0        ) difficulty=0;
75
      if( difficulty>=NUM_IDS ) difficulty=NUM_IDS-1;
76

    
77
      for(int i=0; i<NUM_IDS; i++)
78
        {
79
        ImageView image = layout.findViewById(DIFF_IDS[i]);
80
        image.setImageResource(DIFF_IMAGES[i]);
81
        image.setColorFilter( difficulty==i ? 0xffff0000 : 0xffffffff, PorterDuff.Mode.MULTIPLY );
82
        }
83
      }
84
    }
85

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

    
88
  InfoScreenPane(final InfoActivity act, int objectOrdinal)
89
    {
90
    int height = act.getScreenHeightInPixels();
91
    float textSize = height*TEXT_RATIO;
92
    int padding = (int)(height*PADDING_RATIO);
93

    
94
    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

    
100
    nameLayout.setPadding(padding,padding,padding,padding/2);
101
    difficultyLayout.setPadding(padding,padding/2,padding,padding/2);
102
    authorLayout.setPadding(padding,padding/2,padding,padding/2);
103
    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

    
122
    TextView text;
123
    text = nameLayout.findViewById(R.id.infoDetailsName1);
124
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
125
    text = nameLayout.findViewById(R.id.infoDetailsName2);
126
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
127
    text = authorLayout.findViewById(R.id.infoDetailsAuthor1);
128
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
129
    text = authorLayout.findViewById(R.id.infoDetailsAuthor2);
130
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
131
    text = difficultyLayout.findViewById(R.id.infoDifficultyTitle);
132
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
133
    text = yearLayout.findViewById(R.id.infoDetailsYear1);
134
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
135
    text = yearLayout.findViewById(R.id.infoDetailsYear2);
136
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
137

    
138
    LinearLayout layoutDiff = difficultyLayout.findViewById(R.id.infoDifficultyLayout);
139
    layoutDiff.setPadding(padding,padding,padding,padding);
140

    
141
    updatePane(act,objectOrdinal);
142
    }
143
}
(5-5/6)