Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigScreenPane.java @ 74d088c3

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

    
40
  private LinearLayout mDetailsLayout, mDifficultyLayout, mMeshLayout;
41
  private JsonReader mReader;
42

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

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

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

    
53
    String name = mReader.getObjectName();
54
    String author = mReader.getInventor();
55
    int year = mReader.getYearOfInvention();
56

    
57
    LinearLayout layout = act.findViewById(R.id.configLayout);
58
    TextView view = layout.findViewById(R.id.configDetailsName2);
59
    view.setText(name);
60
    view = layout.findViewById(R.id.configDetailsAuthor2);
61
    view.setText(author+" "+year);
62
    }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

    
66
  ConfigScreenPane(final ConfigActivity act, int objectOrdinal)
67
    {
68
    mDetailsLayout    = (LinearLayout)inflate( act, R.layout.config_details   , null);
69
    mDifficultyLayout = (LinearLayout)inflate( act, R.layout.config_difficulty, null);
70
    mMeshLayout       = (LinearLayout)inflate( act, R.layout.config_mesh      , null);
71

    
72
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.0f);
73
    mDetailsLayout.setLayoutParams(params);
74
    mDifficultyLayout.setLayoutParams(params);
75
    mMeshLayout.setLayoutParams(params);
76

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

    
91
    text = mDifficultyLayout.findViewById(R.id.configDifficultyTitle);
92
    text.setTextSize(textSize);
93
    text = mMeshLayout.findViewById(R.id.configMeshTitle);
94
    text.setTextSize(textSize);
95

    
96
    LinearLayout layout = act.findViewById(R.id.configLayout);
97
    layout.removeAllViews();
98
    layout.addView(mDetailsLayout);
99
    layout.addView(mDifficultyLayout);
100
    layout.addView(mMeshLayout);
101

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