Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigScreenPane.java @ 2604be3b

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

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

    
34
import java.io.InputStream;
35

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

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
public class ConfigScreenPane
41
{
42
  private static final int[] IMAGES =
43
    {
44
    R.id.configDifficulty0,
45
    R.id.configDifficulty1,
46
    R.id.configDifficulty2,
47
    R.id.configDifficulty3,
48
    R.id.configDifficulty4
49
    };
50

    
51
  private static final int NUM_IMAGES = IMAGES.length;
52
  private static final float PADDING_RATIO = 0.015f;
53
  private static final float TEXT_RATIO    = 0.025f;
54
  private static final float RADIO_RATIO   = 0.900f;
55

    
56
  private JsonReader mReader;
57
  private int mObjectOrdinal;
58

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

    
61
  private void switchMesh(ConfigActivity act, boolean simple)
62
    {
63

    
64
    }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
  void updatePane(ConfigActivity act, int objectOrdinal)
69
    {
70
    if( mReader==null ) mReader = new JsonReader();
71

    
72
    mObjectOrdinal = objectOrdinal;
73

    
74
    ObjectType type = ObjectType.getObject(objectOrdinal);
75
    InputStream stream = ObjectJson.getStream(type,act);
76
    mReader.parseJsonFileMetadata(stream);
77

    
78
    String name = mReader.getObjectName();
79
    String author = mReader.getInventor();
80
    int year = mReader.getYearOfInvention();
81
    String both = year>0 ? author+" "+year : author;
82

    
83
    LinearLayout layout = act.findViewById(R.id.configLayout);
84
    TextView view = layout.findViewById(R.id.configDetailsName2);
85
    view.setText(name);
86
    view = layout.findViewById(R.id.configDetailsAuthor2);
87
    view.setText(both);
88

    
89
    int difficulty = mReader.getComplexity();
90

    
91
    if( difficulty<0          ) difficulty=0;
92
    if( difficulty>NUM_IMAGES ) difficulty=NUM_IMAGES;
93

    
94
    for(int i=0; i<NUM_IMAGES; i++)
95
      {
96
      ImageView image = layout.findViewById(IMAGES[i]);
97
      image.setBackgroundResource( i==difficulty ? R.drawable.difficulty_background : 0 );
98
      }
99
    }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
  ConfigScreenPane(final ConfigActivity act, int objectOrdinal)
104
    {
105
    int height = act.getScreenHeightInPixels();
106
    float textSize = height*TEXT_RATIO;
107
    int padding = (int)(height*PADDING_RATIO);
108

    
109
    LinearLayout detailsLayout    = (LinearLayout)inflate( act, R.layout.config_details   , null);
110
    LinearLayout difficultyLayout = (LinearLayout)inflate( act, R.layout.config_difficulty, null);
111
    LinearLayout meshLayout       = (LinearLayout)inflate( act, R.layout.config_mesh      , null);
112

    
113
    detailsLayout.setPadding(padding,padding,padding,padding/2);
114
    difficultyLayout.setPadding(padding,padding/2,padding,padding/2);
115
    meshLayout.setPadding(padding,padding/2,padding,padding);
116

    
117
    LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.0f);
118
    LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.0f);
119
    LinearLayout.LayoutParams params3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.3f);
120

    
121
    detailsLayout.setLayoutParams(params1);
122
    difficultyLayout.setLayoutParams(params2);
123
    meshLayout.setLayoutParams(params3);
124

    
125
    TextView text;
126
    text = detailsLayout.findViewById(R.id.configDetailsTitle);
127
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
128
    text = detailsLayout.findViewById(R.id.configDetailsName1);
129
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
130
    text = detailsLayout.findViewById(R.id.configDetailsName2);
131
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
132
    text = detailsLayout.findViewById(R.id.configDetailsAuthor1);
133
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
134
    text = detailsLayout.findViewById(R.id.configDetailsAuthor2);
135
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
136

    
137
    text = difficultyLayout.findViewById(R.id.configDifficultyTitle);
138
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
139
    text = meshLayout.findViewById(R.id.configMeshTitle);
140
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
141

    
142
    RadioButton butt1 = meshLayout.findViewById(R.id.meshNice);
143
    butt1.setTextSize(TypedValue.COMPLEX_UNIT_PX, RADIO_RATIO*textSize);
144
    RadioButton butt2 = meshLayout.findViewById(R.id.meshSimple);
145
    butt2.setTextSize(TypedValue.COMPLEX_UNIT_PX, RADIO_RATIO*textSize);
146

    
147
    LinearLayout layoutDiff = difficultyLayout.findViewById(R.id.configDifficultyLayout);
148
    layoutDiff.setPadding(padding,padding,padding,padding);
149

    
150
    RadioGroup radioGroup = meshLayout.findViewById(R.id.meshRadioGroup);
151

    
152
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
153
      {
154
      @Override
155
      public void onCheckedChanged(RadioGroup group, int checkedId)
156
        {
157
        switchMesh( act, checkedId != R.id.meshNice );
158
        }
159
      });
160

    
161
    LinearLayout layout = act.findViewById(R.id.configLayout);
162
    layout.removeAllViews();
163
    layout.addView(detailsLayout);
164
    layout.addView(difficultyLayout);
165
    layout.addView(meshLayout);
166

    
167
    updatePane(act,objectOrdinal);
168
    }
169
}
(5-5/6)