Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigScreenPane.java @ cc48b275

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.config;
21

    
22
import android.widget.LinearLayout;
23
import android.widget.TextView;
24

    
25
import org.distorted.jsons.ObjectJson;
26
import org.distorted.main.R;
27
import org.distorted.objectlib.json.JsonReader;
28
import org.distorted.objectlib.main.ObjectType;
29

    
30
import java.io.InputStream;
31

    
32
import static android.view.View.inflate;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
public class ConfigScreenPane
37
{
38
  private static final float TEXT_RATIO = 0.015f;
39
  private JsonReader mReader;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

    
43
  void updatePane(ConfigActivity act, int objectOrdinal)
44
    {
45
    if( mReader==null ) mReader = new JsonReader();
46

    
47
    ObjectType type = ObjectType.getObject(objectOrdinal);
48
    InputStream stream = ObjectJson.getStream(type,act);
49
    mReader.parseJsonFileMetadata(stream);
50

    
51
    String name = mReader.getObjectName();
52
    String author = mReader.getInventor();
53
    int year = mReader.getYearOfInvention();
54
    String both = year>0 ? author+" "+year : author;
55

    
56
    LinearLayout layout = act.findViewById(R.id.configLayout);
57
    TextView view = layout.findViewById(R.id.configDetailsName2);
58
    view.setText(name);
59
    view = layout.findViewById(R.id.configDetailsAuthor2);
60
    view.setText(both);
61
    }
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

    
65
  ConfigScreenPane(final ConfigActivity act, int objectOrdinal)
66
    {
67
    LinearLayout detailsLayout    = (LinearLayout)inflate( act, R.layout.config_details   , null);
68
    LinearLayout difficultyLayout = (LinearLayout)inflate( act, R.layout.config_difficulty, null);
69
    LinearLayout meshLayout       = (LinearLayout)inflate( act, R.layout.config_mesh      , null);
70

    
71
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.0f);
72
    detailsLayout.setLayoutParams(params);
73
    difficultyLayout.setLayoutParams(params);
74
    meshLayout.setLayoutParams(params);
75

    
76
    int height = act.getScreenHeightInPixels();
77
    float textSize = height*TEXT_RATIO;
78
    TextView text;
79
    text = detailsLayout.findViewById(R.id.configDetailsTitle);
80
    text.setTextSize(textSize);
81
    text = detailsLayout.findViewById(R.id.configDetailsName1);
82
    text.setTextSize(textSize);
83
    text = detailsLayout.findViewById(R.id.configDetailsName2);
84
    text.setTextSize(textSize);
85
    text = detailsLayout.findViewById(R.id.configDetailsAuthor1);
86
    text.setTextSize(textSize);
87
    text = detailsLayout.findViewById(R.id.configDetailsAuthor2);
88
    text.setTextSize(textSize);
89

    
90
    text = difficultyLayout.findViewById(R.id.configDifficultyTitle);
91
    text.setTextSize(textSize);
92
    text = meshLayout.findViewById(R.id.configMeshTitle);
93
    text.setTextSize(textSize);
94

    
95
    LinearLayout layout = act.findViewById(R.id.configLayout);
96
    layout.removeAllViews();
97
    layout.addView(detailsLayout);
98
    layout.addView(difficultyLayout);
99
    layout.addView(meshLayout);
100

    
101
    updatePane(act,objectOrdinal);
102
    }
103
}
(5-5/6)