Project

General

Profile

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

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

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.objects.RubikObject;
33
import org.distorted.objects.RubikObjectList;
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
    RubikObject object = RubikObjectList.getObject(objectOrdinal);
94
    int jsonID = object.getJsonID();
95
    InputStream stream = ObjectJson.getStream(jsonID,act);
96
    mReader.parseJsonFileMetadata(stream);
97

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

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

    
109
    int difficulty = mReader.getComplexity();
110

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

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

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

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

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

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

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

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

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

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

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

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

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

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

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

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