Project

General

Profile

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

magiccube / src / main / java / org / distorted / config / ConfigScreenPane.java @ 183d4a34

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.RelativeLayout;
28
import android.widget.TextView;
29

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

    
35
import java.io.InputStream;
36

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

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

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

    
52
  private static final int[] CHECK =
53
    {
54
    R.drawable.diff_check0,
55
    R.drawable.diff_check1,
56
    R.drawable.diff_check2,
57
    R.drawable.diff_check3,
58
    R.drawable.diff_check4,
59
    };
60

    
61
  private static final int[] UNCHECK =
62
    {
63
    R.drawable.diff_uncheck0,
64
    R.drawable.diff_uncheck1,
65
    R.drawable.diff_uncheck2,
66
    R.drawable.diff_uncheck3,
67
    R.drawable.diff_uncheck4,
68
    };
69

    
70
  private static final int NUM_IMAGES = IMAGES.length;
71
  private static final float PADDING_RATIO = 0.015f;
72
  private static final float TEXT_RATIO    = 0.025f;
73
  private static final float RADIO_RATIO   = 0.900f;
74

    
75
  private JsonReader mReader;
76
  private int mObjectOrdinal;
77

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

    
80
  private void switchMesh(ConfigActivity act, boolean simple)
81
    {
82

    
83
    }
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

    
87
  void updatePane(ConfigActivity act, int objectOrdinal)
88
    {
89
    if( mReader==null ) mReader = new JsonReader();
90

    
91
    mObjectOrdinal = objectOrdinal;
92

    
93
    ObjectType type = ObjectType.getObject(objectOrdinal);
94
    InputStream stream = ObjectJson.getStream(type,act);
95
    mReader.parseJsonFileMetadata(stream);
96

    
97
    String name = mReader.getObjectName();
98
    String author = mReader.getInventor();
99
    int year = mReader.getYearOfInvention();
100
    String both = year>0 ? author+" "+year : author;
101

    
102
    LinearLayout layout = act.findViewById(R.id.configLayout);
103
    TextView view = layout.findViewById(R.id.configDetailsName2);
104
    view.setText(name);
105
    view = layout.findViewById(R.id.configDetailsAuthor2);
106
    view.setText(both);
107

    
108
    int difficulty = mReader.getComplexity();
109

    
110
    if( difficulty<0          ) difficulty=0;
111
    if( difficulty>NUM_IMAGES ) difficulty=NUM_IMAGES;
112

    
113
    for(int i=0; i<NUM_IMAGES; i++)
114
      {
115
      ImageView image = layout.findViewById(IMAGES[i]);
116
      image.setImageResource( i==difficulty ? CHECK[i] : UNCHECK[i] );
117
      }
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
  ConfigScreenPane(final ConfigActivity act, int objectOrdinal)
123
    {
124
    int height = act.getScreenHeightInPixels();
125
    float textSize = height*TEXT_RATIO;
126
    int padding = (int)(height*PADDING_RATIO);
127

    
128
    LinearLayout detailsLayout    = (LinearLayout)inflate( act, R.layout.config_details   , null);
129
    LinearLayout difficultyLayout = (LinearLayout)inflate( act, R.layout.config_difficulty, null);
130
    LinearLayout meshLayout       = (LinearLayout)inflate( act, R.layout.config_mesh      , null);
131

    
132
    detailsLayout.setPadding(padding,padding,padding,padding/2);
133
    difficultyLayout.setPadding(padding,padding/2,padding,padding/2);
134
    meshLayout.setPadding(padding,padding/2,padding,padding);
135

    
136
    LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f);
137
    LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.00f);
138
    LinearLayout.LayoutParams params3 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.05f);
139

    
140
    detailsLayout.setLayoutParams(params1);
141
    difficultyLayout.setLayoutParams(params2);
142
    meshLayout.setLayoutParams(params3);
143

    
144
    TextView text;
145
    text = detailsLayout.findViewById(R.id.configDetailsTitle);
146
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
147
    text = detailsLayout.findViewById(R.id.configDetailsName1);
148
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
149
    text = detailsLayout.findViewById(R.id.configDetailsName2);
150
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
151
    text = detailsLayout.findViewById(R.id.configDetailsAuthor1);
152
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
153
    text = detailsLayout.findViewById(R.id.configDetailsAuthor2);
154
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
155

    
156
    text = difficultyLayout.findViewById(R.id.configDifficultyTitle);
157
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
158
    text = meshLayout.findViewById(R.id.configMeshTitle);
159
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
160

    
161
    RadioButton butt1 = meshLayout.findViewById(R.id.meshNice);
162
    butt1.setTextSize(TypedValue.COMPLEX_UNIT_PX, RADIO_RATIO*textSize);
163
    RadioButton butt2 = meshLayout.findViewById(R.id.meshSimple);
164
    butt2.setTextSize(TypedValue.COMPLEX_UNIT_PX, RADIO_RATIO*textSize);
165

    
166
    LinearLayout layoutDiff = difficultyLayout.findViewById(R.id.configDifficultyLayout);
167
    layoutDiff.setPadding(padding,padding,padding,padding);
168

    
169
    RadioGroup radioGroup = meshLayout.findViewById(R.id.meshRadioGroup);
170

    
171
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
172
      {
173
      @Override
174
      public void onCheckedChanged(RadioGroup group, int checkedId)
175
        {
176
        switchMesh( act, checkedId != R.id.meshNice );
177
        }
178
      });
179

    
180
    LinearLayout layout = act.findViewById(R.id.configLayout);
181
    layout.removeAllViews();
182
    layout.addView(detailsLayout);
183
    layout.addView(difficultyLayout);
184
    layout.addView(meshLayout);
185

    
186
    updatePane(act,objectOrdinal);
187
    }
188
}
(5-5/6)