Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigScreenPane.java @ 2e99ba6a

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.util.TypedValue;
23
import android.widget.LinearLayout;
24
import android.widget.RadioButton;
25
import android.widget.RadioGroup;
26
import android.widget.TextView;
27

    
28
import org.distorted.jsons.ObjectJson;
29
import org.distorted.main.R;
30
import org.distorted.objectlib.json.JsonReader;
31
import org.distorted.objectlib.main.ObjectType;
32

    
33
import java.io.InputStream;
34

    
35
import static android.view.View.inflate;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
public class ConfigScreenPane
40
{
41
  private static final float PADDING_RATIO = 0.015f;
42
  private static final float TEXT_RATIO    = 0.025f;
43
  private static final float RADIO_RATIO   = 0.900f;
44

    
45
  private JsonReader mReader;
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48

    
49
  void updatePane(ConfigActivity act, int objectOrdinal)
50
    {
51
    if( mReader==null ) mReader = new JsonReader();
52

    
53
    ObjectType type = ObjectType.getObject(objectOrdinal);
54
    InputStream stream = ObjectJson.getStream(type,act);
55
    mReader.parseJsonFileMetadata(stream);
56

    
57
    String name = mReader.getObjectName();
58
    String author = mReader.getInventor();
59
    int year = mReader.getYearOfInvention();
60
    String both = year>0 ? author+" "+year : author;
61

    
62
    LinearLayout layout = act.findViewById(R.id.configLayout);
63
    TextView view = layout.findViewById(R.id.configDetailsName2);
64
    view.setText(name);
65
    view = layout.findViewById(R.id.configDetailsAuthor2);
66
    view.setText(both);
67
    }
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

    
71
  ConfigScreenPane(final ConfigActivity act, int objectOrdinal)
72
    {
73
    int height = act.getScreenHeightInPixels();
74
    float textSize = height*TEXT_RATIO;
75
    int padding = (int)(height*PADDING_RATIO);
76

    
77
    LinearLayout detailsLayout    = (LinearLayout)inflate( act, R.layout.config_details   , null);
78
    LinearLayout difficultyLayout = (LinearLayout)inflate( act, R.layout.config_difficulty, null);
79
    LinearLayout meshLayout       = (LinearLayout)inflate( act, R.layout.config_mesh      , null);
80

    
81
    detailsLayout.setPadding(padding,padding,padding,padding/2);
82
    difficultyLayout.setPadding(padding,padding/2,padding,padding/2);
83
    meshLayout.setPadding(padding,padding/2,padding,padding);
84

    
85
    LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.0f);
86
    LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.0f);
87
    LinearLayout.LayoutParams params3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.3f);
88

    
89
    detailsLayout.setLayoutParams(params1);
90
    difficultyLayout.setLayoutParams(params2);
91
    meshLayout.setLayoutParams(params3);
92

    
93
    TextView text;
94
    text = detailsLayout.findViewById(R.id.configDetailsTitle);
95
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
96
    text = detailsLayout.findViewById(R.id.configDetailsName1);
97
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
98
    text = detailsLayout.findViewById(R.id.configDetailsName2);
99
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
100
    text = detailsLayout.findViewById(R.id.configDetailsAuthor1);
101
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
102
    text = detailsLayout.findViewById(R.id.configDetailsAuthor2);
103
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
104

    
105
    text = difficultyLayout.findViewById(R.id.configDifficultyTitle);
106
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
107
    text = meshLayout.findViewById(R.id.configMeshTitle);
108
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
109

    
110
    RadioButton butt1 = meshLayout.findViewById(R.id.meshNice);
111
    butt1.setTextSize(TypedValue.COMPLEX_UNIT_PX, RADIO_RATIO*textSize);
112
    RadioButton butt2 = meshLayout.findViewById(R.id.meshSimple);
113
    butt2.setTextSize(TypedValue.COMPLEX_UNIT_PX, RADIO_RATIO*textSize);
114

    
115
    LinearLayout layoutDiff = difficultyLayout.findViewById(R.id.configDifficultyLayout);
116
    layoutDiff.setPadding(padding,padding,padding,padding);
117

    
118
    RadioGroup radioGroup = meshLayout.findViewById(R.id.meshRadioGroup);
119

    
120
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
121
      {
122
      @Override
123
      public void onCheckedChanged(RadioGroup group, int checkedId)
124
        {
125
        if(checkedId == R.id.meshNice)
126
          {
127
          android.util.Log.e("D", "mesh Nice");
128
          }
129
        else
130
          {
131
          android.util.Log.e("D", "mesh Simple");
132
          }
133
        }
134
      });
135

    
136
    LinearLayout layout = act.findViewById(R.id.configLayout);
137
    layout.removeAllViews();
138
    layout.addView(detailsLayout);
139
    layout.addView(difficultyLayout);
140
    layout.addView(meshLayout);
141

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